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
impl PomEditor
Sourcepub fn get_or_create_build_element(&mut self) -> BuildEditor<'_>
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.
Sourcepub fn get_build_element_or_none(&mut self) -> Option<BuildEditor<'_>>
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
pub fn has_build(&self) -> bool
pub fn delete_build(&mut self) -> Result<bool, XMLEditorError>
Source§impl PomEditor
impl PomEditor
Sourcepub fn get_or_create_dependency_management_element(
&mut self,
) -> DependencyManagementEditor<'_>
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.
Sourcepub fn get_dependency_management_element_or_none(
&mut self,
) -> Option<DependencyManagementEditor<'_>>
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
Sourcepub fn has_dependency_management(&self) -> bool
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
Sourcepub fn delete_dependency_management(&mut self) -> Result<bool, XMLEditorError>
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
impl PomEditor
Sourcepub fn get_or_create_distribution_management_element(
&mut self,
) -> DistributionManagementEditor<'_>
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.
Sourcepub fn get_distribution_management_element_or_none(
&mut self,
) -> Option<DistributionManagementEditor<'_>>
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
pub fn has_distribution_management(&self) -> bool
pub fn delete_distribution_management(&mut self) -> Result<bool, XMLEditorError>
Source§impl PomEditor
impl PomEditor
Sourcepub fn new_with_group_and_artifact(group_id: &str, artifact_id: &str) -> Self
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
Sourcepub fn get_parent(&self) -> Result<Option<Parent>, XMLEditorError>
pub fn get_parent(&self) -> Result<Option<Parent>, XMLEditorError>
Gets the parent of the pom file
Sourcepub fn set_parent<U>(&mut self, value: U) -> Result<(), XMLEditorError>
pub fn set_parent<U>(&mut self, value: U) -> Result<(), XMLEditorError>
Sets the parent of the pom file
If None is passed in. The parent element will be removed
Sourcepub fn set_scm<U>(&mut self, value: U) -> Result<(), XMLEditorError>
pub fn set_scm<U>(&mut self, value: U) -> Result<(), XMLEditorError>
Sets the scm of the pom file
If None is passed in. The scm element will be removed
Sourcepub fn set_group_id<S, O>(&mut self, value: O)
pub fn set_group_id<S, O>(&mut self, value: O)
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()));
Sourcepub fn get_group_id(&self) -> Option<String>
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()));
Sourcepub fn set_artifact_id<S, O>(&mut self, value: O)
pub fn set_artifact_id<S, O>(&mut self, value: O)
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()));
Sourcepub fn get_artifact_id(&self) -> Option<String>
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()));
Sourcepub fn set_version<S, O>(&mut self, value: O)
pub fn set_version<S, O>(&mut self, value: O)
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()));
Sourcepub fn get_version(&self) -> Option<String>
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()));
Sourcepub fn set_description<S, O>(&mut self, value: O)
pub fn set_description<S, O>(&mut self, value: O)
The description of the maven project
Sourcepub fn get_description(&self) -> Option<String>
pub fn get_description(&self) -> Option<String>
The description of the maven project
Sourcepub fn set_inception_year<S, O>(&mut self, value: O)
pub fn set_inception_year<S, O>(&mut self, value: O)
The inception year of the project
Sourcepub fn get_inception_year(&self) -> Option<String>
pub fn get_inception_year(&self) -> Option<String>
The inception year of the project
Sourcepub fn set_model_version<S, O>(&mut self, value: O)
pub fn set_model_version<S, O>(&mut self, value: O)
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
Sourcepub fn get_model_version(&self) -> Option<String>
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
Sourcepub fn set_packaging<S, O>(&mut self, value: O)
pub fn set_packaging<S, O>(&mut self, value: O)
Sourcepub fn get_packaging(&self) -> Option<String>
pub fn get_packaging(&self) -> Option<String>
Sourcepub fn get_repositories(&self) -> Result<Vec<Repository>, XMLEditorError>
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()));
Sourcepub fn add_or_update_repository(
&mut self,
value: Repository,
) -> Result<Option<Repository>, XMLEditorError>
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()));
Sourcepub fn clear_repositories(&mut self) -> Result<(), XMLEditorError>
pub fn clear_repositories(&mut self) -> Result<(), XMLEditorError>
Clears all the repositories in the pom file
Sourcepub fn get_developers(&self) -> Result<Vec<Developer>, XMLEditorError>
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()));
Sourcepub fn add_or_update_developer(
&mut self,
value: Developer,
) -> Result<Option<Developer>, XMLEditorError>
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()));
Sourcepub fn clear_developers(&mut self) -> Result<(), XMLEditorError>
pub fn clear_developers(&mut self) -> Result<(), XMLEditorError>
Clears all the developers in the pom file
Sourcepub fn get_dependencies(&self) -> Result<Vec<Dependency>, XMLEditorError>
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());
Sourcepub fn add_or_update_dependency(
&mut self,
value: Dependency,
) -> Result<Option<Dependency>, XMLEditorError>
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());
Sourcepub fn clear_dependencies(&mut self) -> Result<(), XMLEditorError>
pub fn clear_dependencies(&mut self) -> Result<(), XMLEditorError>
Clears all the dependencies in the pom file