Class ExtensionsEditor
The ExtensionsEditor extends the base Editor class with Maven core extensions-specific functionality,
including automatic element ordering according to Maven conventions, intelligent blank line insertion,
and convenience methods for common extensions operations.
Key features:
- Extensions-aware element ordering - Automatically orders elements according to Maven extensions conventions
- Formatting preservation - Maintains original formatting, whitespace, and comments
- Intelligent blank lines - Adds appropriate blank lines between element groups
- Convenience methods - Easy-to-use methods for adding extensions
Example usage:
// Create a new extensions document
ExtensionsEditor editor = new ExtensionsEditor();
editor.createExtensionsDocument();
Element root = editor.root();
// Add extensions with convenience methods
editor.addExtension(root, "org.apache.maven.wagon", "wagon-ssh", "3.5.1");
editor.addExtension(root, "io.takari.maven", "takari-smart-builder", "0.6.1");
String result = editor.toXml();
- Since:
- 0.1
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.maveniverse.domtrip.Editor
eu.maveniverse.domtrip.Editor.EditorCommentBuilder, eu.maveniverse.domtrip.Editor.EditorElementBuilder, eu.maveniverse.domtrip.Editor.EditorTextBuilder, eu.maveniverse.domtrip.Editor.NodeBuilder -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ExtensionsEditor with default configuration.ExtensionsEditor(eu.maveniverse.domtrip.Document document) Creates a new ExtensionsEditor for the specified document.ExtensionsEditor(eu.maveniverse.domtrip.Document document, eu.maveniverse.domtrip.DomTripConfig config) Creates a new ExtensionsEditor for the specified document with the given configuration.ExtensionsEditor(eu.maveniverse.domtrip.DomTripConfig config) Creates a new ExtensionsEditor with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptioneu.maveniverse.domtrip.ElementaddExtension(eu.maveniverse.domtrip.Element extensionsElement, String groupId, String artifactId, String version) Adds an extension with the specified coordinates.eu.maveniverse.domtrip.ElementaddExtension(eu.maveniverse.domtrip.Element extensionsElement, String groupId, String artifactId, String version, String classifier, String type) Adds an extension with the specified coordinates and optional classifier and type.voidCreates a new Maven extensions document with proper namespace.booleandeleteExtension(Coordinates coordinates) Removes an extension.eu.maveniverse.domtrip.ElementfindChildElement(eu.maveniverse.domtrip.Element parent, String elementName) Finds a direct child element by name.getOrderListForParent(eu.maveniverse.domtrip.Element parent) Gets the appropriate element order list for the given parent element.eu.maveniverse.domtrip.ElementinsertExtensionsElement(eu.maveniverse.domtrip.Element parent, String elementName) Inserts an element with extensions-aware ordering and formatting.eu.maveniverse.domtrip.ElementinsertExtensionsElement(eu.maveniverse.domtrip.Element parent, String elementName, String textContent) Inserts an element with extensions-aware ordering, formatting, and text content.Lists all extensions as Coordinates objects.booleanupdateExtension(boolean upsert, Coordinates coordinates) Updates an existing extension or inserts a new one (if upsert is true).Methods inherited from class AbstractMavenEditor
insertElementAtCorrectPosition, insertElementAtCorrectPosition, insertElementAtPosition, shouldSkipInOrdering, toCoordinates, toGA, toGATC, toJarCoordinates, toPluginGA, toPomCoordinatesMethods inherited from class eu.maveniverse.domtrip.Editor
add, addBlankLineAfter, addBlankLineBefore, addComment, addElement, addElement, addElement, addElement, addElements, addQNameElements, commentOutElement, commentOutElements, config, createDocument, document, documentStats, insertElementAfter, insertElementAfter, insertElementAt, insertElementAt, insertElementBefore, insertElementBefore, isWellFormed, removeAttribute, removeElement, root, select, selectFirst, setAttribute, setAttributes, setTextContent, toXml, toXml, toXmlPretty, uncommentElement, walk
-
Constructor Details
-
ExtensionsEditor
public ExtensionsEditor()Creates a new ExtensionsEditor with default configuration. -
ExtensionsEditor
public ExtensionsEditor(eu.maveniverse.domtrip.DomTripConfig config) Creates a new ExtensionsEditor with the specified configuration.- Parameters:
config- the configuration to use
-
ExtensionsEditor
public ExtensionsEditor(eu.maveniverse.domtrip.Document document) Creates a new ExtensionsEditor for the specified document.- Parameters:
document- the document to edit
-
ExtensionsEditor
public ExtensionsEditor(eu.maveniverse.domtrip.Document document, eu.maveniverse.domtrip.DomTripConfig config) Creates a new ExtensionsEditor for the specified document with the given configuration.- Parameters:
document- the document to editconfig- the configuration to use
-
-
Method Details
-
createExtensionsDocument
public void createExtensionsDocument() throws eu.maveniverse.domtrip.DomTripExceptionCreates a new Maven extensions document with proper namespace.This method creates a new document with the extensions root element and sets up the appropriate Maven extensions namespace.
- Throws:
eu.maveniverse.domtrip.DomTripException
-
insertExtensionsElement
public eu.maveniverse.domtrip.Element insertExtensionsElement(eu.maveniverse.domtrip.Element parent, String elementName) throws eu.maveniverse.domtrip.DomTripException Inserts an element with extensions-aware ordering and formatting.This method automatically determines the correct position for the element based on Maven extensions conventions and adds appropriate blank lines.
- Parameters:
parent- the parent elementelementName- the name of the element to insert- Returns:
- the newly created element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
insertExtensionsElement
public eu.maveniverse.domtrip.Element insertExtensionsElement(eu.maveniverse.domtrip.Element parent, String elementName, String textContent) throws eu.maveniverse.domtrip.DomTripException Inserts an element with extensions-aware ordering, formatting, and text content.- Parameters:
parent- the parent elementelementName- the name of the element to inserttextContent- the text content for the element (can be null)- Returns:
- the newly created element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addExtension
public eu.maveniverse.domtrip.Element addExtension(eu.maveniverse.domtrip.Element extensionsElement, String groupId, String artifactId, String version) throws eu.maveniverse.domtrip.DomTripException Adds an extension with the specified coordinates.- Parameters:
extensionsElement- the extensions parent element (root element)groupId- the extension group IDartifactId- the extension artifact IDversion- the extension version- Returns:
- the newly created extension element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addExtension
public eu.maveniverse.domtrip.Element addExtension(eu.maveniverse.domtrip.Element extensionsElement, String groupId, String artifactId, String version, String classifier, String type) throws eu.maveniverse.domtrip.DomTripException Adds an extension with the specified coordinates and optional classifier and type.- Parameters:
extensionsElement- the extensions parent element (root element)groupId- the extension group IDartifactId- the extension artifact IDversion- the extension versionclassifier- the extension classifier (can be null)type- the extension type (can be null, defaults to "jar")- Returns:
- the newly created extension element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
findChildElement
public eu.maveniverse.domtrip.Element findChildElement(eu.maveniverse.domtrip.Element parent, String elementName) Finds a direct child element by name.- Parameters:
parent- the parent elementelementName- the name of the child element to find- Returns:
- the child element if found, null otherwise
-
listExtensions
Lists all extensions as Coordinates objects.Extensions are always JARs without classifiers.
- Returns:
- list of Coordinates objects representing the extensions
- Throws:
eu.maveniverse.domtrip.DomTripException
-
updateExtension
public boolean updateExtension(boolean upsert, Coordinates coordinates) throws eu.maveniverse.domtrip.DomTripException Updates an existing extension or inserts a new one (if upsert is true).Existence is checked by GA (groupId:artifactId) matching only, as extensions are JAR artifacts without classifiers.
- Parameters:
upsert- whether to insert the extension if it doesn't existcoordinates- the extension coordinates- Returns:
- true if the extension was updated or inserted, false otherwise
- Throws:
eu.maveniverse.domtrip.DomTripException
-
deleteExtension
public boolean deleteExtension(Coordinates coordinates) throws eu.maveniverse.domtrip.DomTripException Removes an extension.Existence is checked by GA (groupId:artifactId) matching only, as extensions are JAR artifacts without classifiers.
- Parameters:
coordinates- the extension artifact to remove- Returns:
- true if the extension was removed, false if it didn't exist
- Throws:
eu.maveniverse.domtrip.DomTripException
-
getOrderListForParent
Gets the appropriate element order list for the given parent element.- Specified by:
getOrderListForParentin classAbstractMavenEditor- Parameters:
parent- the parent element- Returns:
- the ordered list of element names, or null if no specific ordering is defined
-