Package eu.maveniverse.domtrip.maven
Class SettingsEditor
- java.lang.Object
-
- eu.maveniverse.domtrip.Editor
-
- eu.maveniverse.domtrip.maven.AbstractMavenEditor
-
- eu.maveniverse.domtrip.maven.SettingsEditor
-
public class SettingsEditor extends AbstractMavenEditor
Specialized editor for Maven settings.xml files.The SettingsEditor extends the base
Editorclass 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
-
-
Constructor Summary
Constructors Constructor Description SettingsEditor()Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description eu.maveniverse.domtrip.ElementaddMirror(eu.maveniverse.domtrip.Element mirrorsElement, java.lang.String id, java.lang.String name, java.lang.String url, java.lang.String mirrorOf)Adds a mirror configuration.eu.maveniverse.domtrip.ElementaddProfile(eu.maveniverse.domtrip.Element profilesElement, java.lang.String id)Adds a profile configuration.eu.maveniverse.domtrip.ElementaddProperty(eu.maveniverse.domtrip.Element propertiesElement, java.lang.String propertyName, java.lang.String propertyValue)Adds a property to a properties element.eu.maveniverse.domtrip.ElementaddProxy(eu.maveniverse.domtrip.Element proxiesElement, java.lang.String id, java.lang.String protocol, java.lang.String host, int port)Adds a proxy configuration.eu.maveniverse.domtrip.ElementaddServer(eu.maveniverse.domtrip.Element serversElement, java.lang.String id, java.lang.String username, java.lang.String password)Adds a server configuration.voidcreateSettingsDocument()Creates a new Maven settings document with proper namespace.eu.maveniverse.domtrip.ElementfindChildElement(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.ElementinsertSettingsElement(eu.maveniverse.domtrip.Element parent, java.lang.String elementName)Inserts an element with settings-aware ordering and formatting.eu.maveniverse.domtrip.ElementinsertSettingsElement(eu.maveniverse.domtrip.Element parent, java.lang.String elementName, java.lang.String textContent)Inserts an element with settings-aware ordering, formatting, and text content.-
Methods inherited from class eu.maveniverse.domtrip.maven.AbstractMavenEditor
insertElementAtCorrectPosition, insertElementAtCorrectPosition, insertElementAtPosition, shouldSkipInOrdering, toCoordinates, toGA, toGATC, toJarCoordinates, toPluginGA, toPomCoordinates
-
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
-
-
-
-
Constructor Detail
-
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 Detail
-
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, java.lang.String elementName) throws eu.maveniverse.domtrip.DomTripExceptionInserts 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, java.lang.String elementName, java.lang.String textContent) throws eu.maveniverse.domtrip.DomTripExceptionInserts 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, java.lang.String id, java.lang.String username, java.lang.String password) throws eu.maveniverse.domtrip.DomTripExceptionAdds 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, java.lang.String id, java.lang.String name, java.lang.String url, java.lang.String mirrorOf) throws eu.maveniverse.domtrip.DomTripExceptionAdds 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, java.lang.String id, java.lang.String protocol, java.lang.String host, int port) throws eu.maveniverse.domtrip.DomTripExceptionAdds 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, java.lang.String id) throws eu.maveniverse.domtrip.DomTripExceptionAdds 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, java.lang.String propertyName, java.lang.String propertyValue) throws eu.maveniverse.domtrip.DomTripExceptionAdds 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, java.lang.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
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:
getOrderListForParentin classAbstractMavenEditor- Parameters:
parent- the parent element- Returns:
- the ordered list of element names, or null if no specific ordering is defined
-
-