Class SettingsEditor
java.lang.Object
eu.maveniverse.domtrip.Editor
eu.maveniverse.domtrip.maven.AbstractMavenEditor
eu.maveniverse.domtrip.maven.SettingsEditor
Specialized editor for Maven settings.xml files.
The SettingsEditor extends the base Editor class with Maven settings-specific functionality,
including automatic element ordering according to Maven conventions, intelligent blank line insertion,
and convenience methods for common settings operations.
Key features:
- Settings-aware element ordering - Automatically orders elements according to Maven settings 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 servers, mirrors, proxies, and profiles
Example usage:
// Create a new settings document
SettingsEditor editor = new SettingsEditor();
editor.createSettingsDocument();
Element root = editor.root();
// Add elements with automatic ordering
editor.insertSettingsElement(root, LOCAL_REPOSITORY, "/custom/repo");
editor.insertSettingsElement(root, OFFLINE, "false");
// Add servers with convenience methods
Element servers = editor.insertSettingsElement(root, SERVERS);
editor.addServer(servers, "my-server", "username", "password");
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 SettingsEditor with default configuration.SettingsEditor(eu.maveniverse.domtrip.Document document) Creates a new SettingsEditor for the specified document.SettingsEditor(eu.maveniverse.domtrip.Document document, eu.maveniverse.domtrip.DomTripConfig config) Creates a new SettingsEditor for the specified document with the given configuration.SettingsEditor(eu.maveniverse.domtrip.DomTripConfig config) Creates a new SettingsEditor with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptioneu.maveniverse.domtrip.ElementaddMirror(eu.maveniverse.domtrip.Element mirrorsElement, String id, String name, String url, String mirrorOf) Adds a mirror configuration.eu.maveniverse.domtrip.ElementaddProfile(eu.maveniverse.domtrip.Element profilesElement, String id) Adds a profile configuration.eu.maveniverse.domtrip.ElementaddProperty(eu.maveniverse.domtrip.Element propertiesElement, String propertyName, String propertyValue) Adds a property to a properties element.eu.maveniverse.domtrip.ElementaddProxy(eu.maveniverse.domtrip.Element proxiesElement, String id, String protocol, String host, int port) Adds a proxy configuration.eu.maveniverse.domtrip.ElementaddServer(eu.maveniverse.domtrip.Element serversElement, String id, String username, String password) Adds a server configuration.voidCreates a new Maven settings 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.ElementinsertSettingsElement(eu.maveniverse.domtrip.Element parent, String elementName) Inserts an element with settings-aware ordering and formatting.eu.maveniverse.domtrip.ElementinsertSettingsElement(eu.maveniverse.domtrip.Element parent, String elementName, String textContent) Inserts an element with settings-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
-
SettingsEditor
public SettingsEditor()Creates a new SettingsEditor with default configuration. -
SettingsEditor
public SettingsEditor(eu.maveniverse.domtrip.DomTripConfig config) Creates a new SettingsEditor with the specified configuration.- Parameters:
config- the configuration to use
-
SettingsEditor
public SettingsEditor(eu.maveniverse.domtrip.Document document) Creates a new SettingsEditor for the specified document.- Parameters:
document- the document to edit
-
SettingsEditor
public SettingsEditor(eu.maveniverse.domtrip.Document document, eu.maveniverse.domtrip.DomTripConfig config) Creates a new SettingsEditor for the specified document with the given configuration.- Parameters:
document- the document to editconfig- the configuration to use
-
-
Method Details
-
createSettingsDocument
public void createSettingsDocument() throws eu.maveniverse.domtrip.DomTripExceptionCreates a new Maven settings document with proper namespace.This method creates a new document with the settings root element and sets up the appropriate Maven settings namespace.
- Throws:
eu.maveniverse.domtrip.DomTripException
-
insertSettingsElement
public eu.maveniverse.domtrip.Element insertSettingsElement(eu.maveniverse.domtrip.Element parent, String elementName) throws eu.maveniverse.domtrip.DomTripException Inserts an element with settings-aware ordering and formatting.This method automatically determines the correct position for the element based on Maven settings 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
-
insertSettingsElement
public eu.maveniverse.domtrip.Element insertSettingsElement(eu.maveniverse.domtrip.Element parent, String elementName, String textContent) throws eu.maveniverse.domtrip.DomTripException Inserts an element with settings-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
-
addServer
public eu.maveniverse.domtrip.Element addServer(eu.maveniverse.domtrip.Element serversElement, String id, String username, String password) throws eu.maveniverse.domtrip.DomTripException Adds a server configuration.- Parameters:
serversElement- the servers parent elementid- the server IDusername- the username (can be null)password- the password (can be null)- Returns:
- the newly created server element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addMirror
public eu.maveniverse.domtrip.Element addMirror(eu.maveniverse.domtrip.Element mirrorsElement, String id, String name, String url, String mirrorOf) throws eu.maveniverse.domtrip.DomTripException Adds a mirror configuration.- Parameters:
mirrorsElement- the mirrors parent elementid- the mirror IDname- the mirror nameurl- the mirror URLmirrorOf- the repositories this mirror serves- Returns:
- the newly created mirror element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addProxy
public eu.maveniverse.domtrip.Element addProxy(eu.maveniverse.domtrip.Element proxiesElement, String id, String protocol, String host, int port) throws eu.maveniverse.domtrip.DomTripException Adds a proxy configuration.- Parameters:
proxiesElement- the proxies parent elementid- the proxy IDprotocol- the proxy protocolhost- the proxy hostport- the proxy port- Returns:
- the newly created proxy element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addProfile
public eu.maveniverse.domtrip.Element addProfile(eu.maveniverse.domtrip.Element profilesElement, String id) throws eu.maveniverse.domtrip.DomTripException Adds a profile configuration.- Parameters:
profilesElement- the profiles parent elementid- the profile ID- Returns:
- the newly created profile element
- Throws:
eu.maveniverse.domtrip.DomTripException
-
addProperty
public eu.maveniverse.domtrip.Element addProperty(eu.maveniverse.domtrip.Element propertiesElement, String propertyName, String propertyValue) throws eu.maveniverse.domtrip.DomTripException Adds a property to a properties element.- Parameters:
propertiesElement- the properties parent elementpropertyName- the property namepropertyValue- the property value- Returns:
- the newly created property 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
-
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
-