Class ExtensionsEditor


  • public class ExtensionsEditor
    extends AbstractMavenEditor
    Specialized editor for Maven extensions.xml files.

    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

      Constructors 
      Constructor Description
      ExtensionsEditor()
      Creates 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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      eu.maveniverse.domtrip.Element addExtension​(eu.maveniverse.domtrip.Element extensionsElement, java.lang.String groupId, java.lang.String artifactId, java.lang.String version)
      Adds an extension with the specified coordinates.
      eu.maveniverse.domtrip.Element addExtension​(eu.maveniverse.domtrip.Element extensionsElement, java.lang.String groupId, java.lang.String artifactId, java.lang.String version, java.lang.String classifier, java.lang.String type)
      Adds an extension with the specified coordinates and optional classifier and type.
      void createExtensionsDocument()
      Creates a new Maven extensions document with proper namespace.
      boolean deleteExtension​(Coordinates coordinates)
      Removes an extension.
      eu.maveniverse.domtrip.Element findChildElement​(eu.maveniverse.domtrip.Element parent, java.lang.String elementName)
      Finds a direct child element by name.
      protected java.util.List<java.lang.String> getOrderListForParent​(eu.maveniverse.domtrip.Element parent)
      Gets the appropriate element order list for the given parent element.
      eu.maveniverse.domtrip.Element insertExtensionsElement​(eu.maveniverse.domtrip.Element parent, java.lang.String elementName)
      Inserts an element with extensions-aware ordering and formatting.
      eu.maveniverse.domtrip.Element insertExtensionsElement​(eu.maveniverse.domtrip.Element parent, java.lang.String elementName, java.lang.String textContent)
      Inserts an element with extensions-aware ordering, formatting, and text content.
      java.util.List<Coordinates> listExtensions()
      Lists all extensions as Coordinates objects.
      boolean updateExtension​(boolean upsert, Coordinates coordinates)
      Updates an existing extension or inserts a new one (if upsert is true).
      • Methods 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • 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 edit
        config - the configuration to use
    • Method Detail

      • createExtensionsDocument

        public void createExtensionsDocument()
                                      throws eu.maveniverse.domtrip.DomTripException
        Creates 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,
                                                                      java.lang.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 element
        elementName - 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,
                                                                      java.lang.String elementName,
                                                                      java.lang.String textContent)
                                                               throws eu.maveniverse.domtrip.DomTripException
        Inserts an element with extensions-aware ordering, formatting, and text content.
        Parameters:
        parent - the parent element
        elementName - the name of the element to insert
        textContent - 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,
                                                           java.lang.String groupId,
                                                           java.lang.String artifactId,
                                                           java.lang.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 ID
        artifactId - the extension artifact ID
        version - 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,
                                                           java.lang.String groupId,
                                                           java.lang.String artifactId,
                                                           java.lang.String version,
                                                           java.lang.String classifier,
                                                           java.lang.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 ID
        artifactId - the extension artifact ID
        version - the extension version
        classifier - 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,
                                                               java.lang.String elementName)
        Finds a direct child element by name.
        Parameters:
        parent - the parent element
        elementName - the name of the child element to find
        Returns:
        the child element if found, null otherwise
      • listExtensions

        public java.util.List<Coordinates> listExtensions()
                                                   throws eu.maveniverse.domtrip.DomTripException
        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 exist
        coordinates - 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

        protected java.util.List<java.lang.String> getOrderListForParent​(eu.maveniverse.domtrip.Element parent)
        Gets the appropriate element order list for the given parent element.
        Specified by:
        getOrderListForParent in class AbstractMavenEditor
        Parameters:
        parent - the parent element
        Returns:
        the ordered list of element names, or null if no specific ordering is defined