maven_rs::pom::editor

Struct PomEditor

Source
pub struct PomEditor {
    pub ident_level: usize,
    /* private fields */
}
Expand description

A struct that allows editing and creating pom files A pom file is an xml file that follows the maven pom schema

Fields§

§ident_level: usize

Implementations§

Source§

impl PomEditor

Source

pub fn get_or_create_build_element(&mut self) -> BuildEditor<'_>

Creates a new build editor

If no build element is present, it will create one

§Note.

This function will hold a mutable reference to the PomEditor. I would recommend using this function within a scope. To prevent borrowing issues.

Source

pub fn get_build_element_or_none(&mut self) -> Option<BuildEditor<'_>>

Checks if the build element is present in the pom file

If the build element is present, it will return Some(BuildEditor) else it will return None

Source

pub fn has_build(&self) -> bool

Source

pub fn delete_build(&mut self) -> Result<bool, XMLEditorError>

Source§

impl PomEditor

Source

pub fn get_or_create_dependency_management_element( &mut self, ) -> DependencyManagementEditor<'_>

Creates a new DependencyManagementEditor

If no dependencyManagement element is present, it will create one

§Note.

This function will hold a mutable reference to the PomEditor. I would recommend using this function within a scope. To prevent borrowing issues.

Source

pub fn get_dependency_management_element_or_none( &mut self, ) -> Option<DependencyManagementEditor<'_>>

Checks if the dependencyManagement element is present in the pom file

If the element is present, it will return Some(BuildEditor) else it will return None

Source

pub fn has_dependency_management(&self) -> bool

Checks if the dependencyManagement element is present in the pom file

If the dependencyManagement element is present, it will return true else it will return false

Source

pub fn delete_dependency_management(&mut self) -> Result<bool, XMLEditorError>

Deletes the dependencyManagement element from the pom file

If the dependencyManagement element is present, it will delete it and return true else it will return false

Source§

impl PomEditor

Source

pub fn get_or_create_distribution_management_element( &mut self, ) -> DistributionManagementEditor<'_>

Creates a new build editor

If no build element is present, it will create one

§Note.

This function will hold a mutable reference to the PomEditor. I would recommend using this function within a scope. To prevent borrowing issues.

Source

pub fn get_distribution_management_element_or_none( &mut self, ) -> Option<DistributionManagementEditor<'_>>

Checks if the build element is present in the pom file

If the build element is present, it will return Some(BuildEditor) else it will return None

Source

pub fn has_distribution_management(&self) -> bool

Source

pub fn delete_distribution_management(&mut self) -> Result<bool, XMLEditorError>

Source§

impl PomEditor

Source

pub fn new_with_group_and_artifact(group_id: &str, artifact_id: &str) -> Self

Creates a new PomEditor with the group id and artifact id set

Source

pub fn get_parent(&self) -> Result<Option<Parent>, XMLEditorError>

Gets the parent of the pom file

Source

pub fn set_parent<U>(&mut self, value: U) -> Result<(), XMLEditorError>
where U: Into<Option<Parent>>,

Sets the parent of the pom file

If None is passed in. The parent element will be removed

Source

pub fn get_scm(&self) -> Result<Option<Scm>, XMLEditorError>

Gets the scm of the pom file

Source

pub fn set_scm<U>(&mut self, value: U) -> Result<(), XMLEditorError>
where U: Into<Option<Scm>>,

Sets the scm of the pom file

If None is passed in. The scm element will be removed

Source

pub fn set_group_id<S, O>(&mut self, value: O)
where S: Into<String>, O: Into<Option<S>>,

Sets the group Id in the pom file. For the maven project The group id of the pom

More Info Example Usage:

use maven_rs::pom::editor::PomEditor;
let mut editor = PomEditor::default();
editor.set_group_id("dev.wyatt-herkamp");
assert_eq!(editor.get_group_id(), Some("dev.wyatt-herkamp".to_string()));
Source

pub fn get_group_id(&self) -> Option<String>

The group id of the pom

More Info Example Usage:

use maven_rs::pom::editor::PomEditor;
let mut editor = PomEditor::default();
editor.set_group_id("dev.wyatt-herkamp");
assert_eq!(editor.get_group_id(), Some("dev.wyatt-herkamp".to_string()));
Source

pub fn set_artifact_id<S, O>(&mut self, value: O)
where S: Into<String>, O: Into<Option<S>>,

The artifact id of the pom More Info

Example Usage:

use maven_rs::pom::editor::PomEditor;
let mut editor = PomEditor::default();
editor.set_artifact_id("test");
assert_eq!(editor.get_artifact_id(), Some("test".to_string()));
Source

pub fn get_artifact_id(&self) -> Option<String>

The artifact id of the pom More Info

Example Usage:

use maven_rs::pom::editor::PomEditor;
let mut editor = PomEditor::default();
editor.set_artifact_id("test");
assert_eq!(editor.get_artifact_id(), Some("test".to_string()));
Source

pub fn set_version<S, O>(&mut self, value: O)
where S: Into<String>, O: Into<Option<S>>,

The version of the project file More Info

Example Usage:

use maven_rs::pom::editor::PomEditor;
let mut editor = PomEditor::default();
editor.set_version("1.0.0");
assert_eq!(editor.get_version(), Some("1.0.0".to_string()));
Source

pub fn get_version(&self) -> Option<String>

The version of the project file More Info

Example Usage:

use maven_rs::pom::editor::PomEditor;
let mut editor = PomEditor::default();
editor.set_version("1.0.0");
assert_eq!(editor.get_version(), Some("1.0.0".to_string()));
Source

pub fn set_name<S, O>(&mut self, value: O)
where S: Into<String>, O: Into<Option<S>>,

The name of the maven project

More Info

Source

pub fn get_name(&self) -> Option<String>

The name of the maven project

More Info

Source

pub fn set_description<S, O>(&mut self, value: O)
where S: Into<String>, O: Into<Option<S>>,

The description of the maven project

More Info

Source

pub fn get_description(&self) -> Option<String>

The description of the maven project

More Info

Source

pub fn set_url<S, O>(&mut self, value: O)
where S: Into<String>, O: Into<Option<S>>,

Source

pub fn get_url(&self) -> Option<String>

Source

pub fn set_inception_year<S, O>(&mut self, value: O)
where S: Into<String>, O: Into<Option<S>>,

The inception year of the project

Source

pub fn get_inception_year(&self) -> Option<String>

The inception year of the project

Source

pub fn set_model_version<S, O>(&mut self, value: O)
where S: Into<String>, O: Into<Option<S>>,

Sets the model version of the pom file Sets the model version of the pom file

The model version is currently always 4.0.0

Source

pub fn get_model_version(&self) -> Option<String>

Gets the model version of the pom file Sets the model version of the pom file

The model version is currently always 4.0.0

Source

pub fn set_packaging<S, O>(&mut self, value: O)
where S: Into<String>, O: Into<Option<S>>,

Source

pub fn get_packaging(&self) -> Option<String>

Source

pub fn get_repositories(&self) -> Result<Vec<Repository>, XMLEditorError>

Gets all the repositories in the pom file

use maven_rs::pom::editor::PomEditor;
use maven_rs::pom::Repository;
let xml = r#"
<project>
  <repositories>
   <repository>
     <id>central</id>
     <name>Maven Central Repository</name>
     <url>https://repo.maven.apache.org/maven2</url>
  </repository>
</repositories>
</project>
"#;
let editor = PomEditor::load_from_str(xml).unwrap();
let repositories = editor.get_repositories().unwrap();
assert_eq!(repositories.len(), 1);
assert_eq!(repositories[0].id, Some("central".to_string()));
Source

pub fn add_or_update_repository( &mut self, value: Repository, ) -> Result<Option<Repository>, XMLEditorError>

Adds or Updates a repository in the pom file

use maven_rs::pom::editor::PomEditor;
use maven_rs::pom::Repository;
let mut editor = PomEditor::default();
editor.add_or_update_repository(Repository {
  id: Some("central".to_string()),
  name: Some("Maven Central Repository".to_string()),
  url: "https://repo.maven.apache.org/maven2".to_string(),
  ..Default::default()
}).unwrap();
let repositories = editor.get_repositories().unwrap();
assert_eq!(repositories.len(), 1);
assert_eq!(repositories[0].id, Some("central".to_string()));
Source

pub fn clear_repositories(&mut self) -> Result<(), XMLEditorError>

Clears all the repositories in the pom file

Source

pub fn get_developers(&self) -> Result<Vec<Developer>, XMLEditorError>

Gets all the developers in the pom file

use maven_rs::pom::editor::PomEditor;
use maven_rs::pom::Developer;
let xml = r#"
<project>
   <developers>
      <developer>
        <id>dev.wyatt-herkamp</id>
        <name>Wyatt Herkamp</name>
       </developer>
  </developers>
</project>
"#;
let editor = PomEditor::load_from_str(xml).unwrap();
let developers = editor.get_developers().unwrap();
assert_eq!(developers.len(), 1);
assert_eq!(developers[0].id, Some("dev.wyatt-herkamp".to_string()));
Source

pub fn add_or_update_developer( &mut self, value: Developer, ) -> Result<Option<Developer>, XMLEditorError>

Adds or Updates a developer in the pom file

use maven_rs::pom::editor::PomEditor;
use maven_rs::pom::Developer;
let mut editor = PomEditor::default();
editor.add_or_update_developer(Developer {
   id: Some("dev.wyatt-herkamp".to_string()),
   name: Some("Wyatt Herkamp".to_string()),
   ..Default::default()
}).unwrap();
let developers = editor.get_developers().unwrap();
assert_eq!(developers.len(), 1);
assert_eq!(developers[0].id, Some("dev.wyatt-herkamp".to_string()));
Source

pub fn clear_developers(&mut self) -> Result<(), XMLEditorError>

Clears all the developers in the pom file

Source

pub fn get_dependencies(&self) -> Result<Vec<Dependency>, XMLEditorError>

Gets all the dependencies in the pom file

use maven_rs::pom::editor::PomEditor;
use maven_rs::pom::Dependency;
let xml = r#"
<project>
 <dependencies>
  <dependency>
   <groupId>com.google.guava</groupId>
   <artifactId>guava</artifactId>
   <version>30.1-jre</version>
</dependency>
</dependencies>
</project>
"#;
let editor = PomEditor::load_from_str(xml).unwrap();
let dependencies = editor.get_dependencies().unwrap();
assert_eq!(dependencies.len(), 1);
assert_eq!(dependencies[0].group_id, "com.google.guava".to_string());
Source

pub fn add_or_update_dependency( &mut self, value: Dependency, ) -> Result<Option<Dependency>, XMLEditorError>

Adds or Updates a dependency in the pom file

use maven_rs::pom::editor::PomEditor;
use maven_rs::pom::Dependency;
let mut editor = PomEditor::default();
editor.add_or_update_dependency(Dependency {
 group_id: "com.google.guava".to_string(),
artifact_id: "guava".to_string(),
version: Some("30.1-jre".parse().unwrap()),
..Default::default()
}).unwrap();
let dependencies = editor.get_dependencies().unwrap();
assert_eq!(dependencies.len(), 1);
assert_eq!(dependencies[0].group_id, "com.google.guava".to_string());
Source

pub fn clear_dependencies(&mut self) -> Result<(), XMLEditorError>

Clears all the dependencies in the pom file

Source

pub fn load_from_str(value: &str) -> Result<Self, XMLEditorError>

Source

pub fn load_from_reader<R: Read>(reader: R) -> Result<Self, XMLEditorError>

Loads a pom from a reader

§Errors

If the xml is not a valid pom file

Source

pub fn write_to_str(&self) -> Result<String, XMLEditorError>

Source

pub fn write<W: Write>(&self, writer: &mut W) -> Result<(), XMLEditorError>

Trait Implementations§

Source§

impl Debug for PomEditor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PomEditor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more