Class ToolchainsEditor
java.lang.Object
eu.maveniverse.domtrip.Editor
eu.maveniverse.domtrip.maven.AbstractMavenEditor
eu.maveniverse.domtrip.maven.ToolchainsEditor
Specialized editor for Maven toolchains.xml files.
The ToolchainsEditor extends the base Editor class with Maven toolchains-specific functionality,
including automatic element ordering according to Maven conventions, intelligent blank line insertion,
and convenience methods for common toolchain operations.
Key features:
- Toolchains-aware element ordering - Automatically orders elements according to Maven toolchains 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 JDK and other toolchains
Example usage:
// Create a new toolchains document
ToolchainsEditor editor = new ToolchainsEditor();
editor.createToolchainsDocument();
Element root = editor.root();
// Add JDK toolchains with convenience methods
editor.addJdkToolchain(root, "17", "openjdk", "/path/to/jdk/17");
editor.addJdkToolchain(root, "11", "adoptium", "/path/to/jdk/11");
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 ToolchainsEditor with default configuration.ToolchainsEditor(eu.maveniverse.domtrip.Document document) Creates a new ToolchainsEditor for the specified document.ToolchainsEditor(eu.maveniverse.domtrip.Document document, eu.maveniverse.domtrip.DomTripConfig config) Creates a new ToolchainsEditor for the specified document with the given configuration.ToolchainsEditor(eu.maveniverse.domtrip.DomTripConfig config) Creates a new ToolchainsEditor with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptioneu.maveniverse.domtrip.ElementaddConfiguration(eu.maveniverse.domtrip.Element toolchainElement, String key, String value) Adds a configuration element to a toolchain.eu.maveniverse.domtrip.ElementaddJdkToolchain(eu.maveniverse.domtrip.Element toolchainsElement, String version, String vendor, String jdkHome) Adds a JDK toolchain with the specified version, vendor, and JDK home.eu.maveniverse.domtrip.ElementaddNetBeansToolchain(eu.maveniverse.domtrip.Element toolchainsElement, String version, String installDir) Adds a NetBeans toolchain with the specified version and installation directory.eu.maveniverse.domtrip.ElementaddProvides(eu.maveniverse.domtrip.Element toolchainElement, String key, String value) Adds a provides element to a toolchain.eu.maveniverse.domtrip.ElementaddToolchain(eu.maveniverse.domtrip.Element toolchainsElement, String type) Adds a generic toolchain with the specified type.voidCreates a new Maven toolchains document with proper namespace.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.ElementinsertToolchainsElement(eu.maveniverse.domtrip.Element parent, String elementName) Inserts an element with toolchains-aware ordering and formatting.eu.maveniverse.domtrip.ElementinsertToolchainsElement(eu.maveniverse.domtrip.Element parent, String elementName, String textContent) Inserts an element with toolchains-aware ordering, formatting, and text content.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
-
ToolchainsEditor
public ToolchainsEditor()Creates a new ToolchainsEditor with default configuration. -
ToolchainsEditor
public ToolchainsEditor(eu.maveniverse.domtrip.DomTripConfig config) Creates a new ToolchainsEditor with the specified configuration.- Parameters:
config- the configuration to use
-
ToolchainsEditor
public ToolchainsEditor(eu.maveniverse.domtrip.Document document) Creates a new ToolchainsEditor for the specified document.- Parameters:
document- the document to edit
-
ToolchainsEditor
public ToolchainsEditor(eu.maveniverse.domtrip.Document document, eu.maveniverse.domtrip.DomTripConfig config) Creates a new ToolchainsEditor for the specified document with the given configuration.- Parameters:
document- the document to editconfig- the configuration to use
-
-
Method Details
-
createToolchainsDocument
public void createToolchainsDocument() throws eu.maveniverse.domtrip.DomTripExceptionCreates a new Maven toolchains document with proper namespace.This method creates a new document with the toolchains root element and sets up the appropriate Maven toolchains namespace.
- Throws:
eu.maveniverse.domtrip.DomTripException
-
insertToolchainsElement
public eu.maveniverse.domtrip.Element insertToolchainsElement(eu.maveniverse.domtrip.Element parent, String elementName) throws eu.maveniverse.domtrip.DomTripException Inserts an element with toolchains-aware ordering and formatting.This method automatically determines the correct position for the element based on Maven toolchains 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
-
insertToolchainsElement
public eu.maveniverse.domtrip.Element insertToolchainsElement(eu.maveniverse.domtrip.Element parent, String elementName, String textContent) throws eu.maveniverse.domtrip.DomTripException Inserts an element with toolchains-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
-
addJdkToolchain
public eu.maveniverse.domtrip.Element addJdkToolchain(eu.maveniverse.domtrip.Element toolchainsElement, String version, String vendor, String jdkHome) throws eu.maveniverse.domtrip.DomTripException Adds a JDK toolchain with the specified version, vendor, and JDK home.- Parameters:
toolchainsElement- the toolchains parent element (root element)version- the JDK version (e.g., "17", "11", "1.8")vendor- the JDK vendor (e.g., "openjdk", "adoptium", "azul")jdkHome- the path to the JDK installation- Returns:
- the newly created toolchain element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addToolchain
public eu.maveniverse.domtrip.Element addToolchain(eu.maveniverse.domtrip.Element toolchainsElement, String type) throws eu.maveniverse.domtrip.DomTripException Adds a generic toolchain with the specified type.- Parameters:
toolchainsElement- the toolchains parent element (root element)type- the toolchain type (e.g., "jdk", "netbeans", "protobuf")- Returns:
- the newly created toolchain element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addNetBeansToolchain
public eu.maveniverse.domtrip.Element addNetBeansToolchain(eu.maveniverse.domtrip.Element toolchainsElement, String version, String installDir) throws eu.maveniverse.domtrip.DomTripException Adds a NetBeans toolchain with the specified version and installation directory.- Parameters:
toolchainsElement- the toolchains parent element (root element)version- the NetBeans versioninstallDir- the path to the NetBeans installation- Returns:
- the newly created toolchain element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addProvides
public eu.maveniverse.domtrip.Element addProvides(eu.maveniverse.domtrip.Element toolchainElement, String key, String value) throws eu.maveniverse.domtrip.DomTripException Adds a provides element to a toolchain.- Parameters:
toolchainElement- the toolchain elementkey- the provides keyvalue- the provides value- Returns:
- the provides element (created if it doesn't exist)
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addConfiguration
public eu.maveniverse.domtrip.Element addConfiguration(eu.maveniverse.domtrip.Element toolchainElement, String key, String value) throws eu.maveniverse.domtrip.DomTripException Adds a configuration element to a toolchain.- Parameters:
toolchainElement- the toolchain elementkey- the configuration keyvalue- the configuration value- Returns:
- the configuration element (created if it doesn't exist)
- 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
-
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
-