private void addDom( Xpp3Dom parent, String childName, String childValue ) { if ( StringUtils.isNotEmpty( childValue ) ) { parent.addChild( newDom( childName, childValue ) ); } }
parent.addChild( childConfiguration );
private Xpp3Dom convert( ReportSet reportSet ) { Xpp3Dom dom = new Xpp3Dom( "reportSet" ); addDom( dom, "id", reportSet.getId() ); Xpp3Dom configuration = (Xpp3Dom) reportSet.getConfiguration(); if ( configuration != null ) { configuration = new Xpp3Dom( configuration ); dom.addChild( configuration ); } if ( !reportSet.getReports().isEmpty() ) { Xpp3Dom reports = new Xpp3Dom( "reports" ); for ( String report : reportSet.getReports() ) { addDom( reports, "report", report ); } dom.addChild( reports ); } return dom; }
private Xpp3Dom convert( ReportPlugin plugin ) { Xpp3Dom dom = new Xpp3Dom( "reportPlugin" ); addDom( dom, "groupId", plugin.getGroupId() ); addDom( dom, "artifactId", plugin.getArtifactId() ); addDom( dom, "version", plugin.getVersion() ); Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); if ( configuration != null ) { configuration = new Xpp3Dom( configuration ); dom.addChild( configuration ); } if ( !plugin.getReportSets().isEmpty() ) { Xpp3Dom reportSets = new Xpp3Dom( "reportSets" ); for ( ReportSet reportSet : plugin.getReportSets() ) { Xpp3Dom rs = convert( reportSet ); reportSets.addChild( rs ); } dom.addChild( reportSets ); } return dom; }
/** * Copy constructor with alternative name. */ public Xpp3Dom( Xpp3Dom src, String name ) { this.name = name; int childCount = src.getChildCount(); childList = new ArrayList<Xpp3Dom>( childCount ); childMap = new HashMap<String, Xpp3Dom>( childCount << 1 ); setValue( src.getValue() ); String[] attributeNames = src.getAttributeNames(); for ( String attributeName : attributeNames ) { setAttribute( attributeName, src.getAttribute( attributeName ) ); } for ( int i = 0; i < childCount; i++ ) { addChild( new Xpp3Dom( src.getChild( i ) ) ); } }
private Xpp3Dom toXpp3Dom(PlexusConfiguration config) { Xpp3Dom result = new Xpp3Dom(config.getName()); result.setValue(config.getValue(null)); for (String name : config.getAttributeNames()) { result.setAttribute(name, config.getAttribute(name)); } for (PlexusConfiguration child : config.getChildren()) { result.addChild(toXpp3Dom(child)); } return result; }
public static Xpp3Dom convert( MojoDescriptor mojoDescriptor ) { Xpp3Dom dom = new Xpp3Dom( "configuration" ); PlexusConfiguration c = mojoDescriptor.getMojoConfiguration(); PlexusConfiguration[] ces = c.getChildren(); if ( ces != null ) { for ( PlexusConfiguration ce : ces ) { String value = ce.getValue( null ); String defaultValue = ce.getAttribute( "default-value", null ); if ( value != null || defaultValue != null ) { Xpp3Dom e = new Xpp3Dom( ce.getName() ); e.setValue( value ); if ( defaultValue != null ) { e.setAttribute( "default-value", defaultValue ); } dom.addChild( e ); } } } return dom; }
dominant.addChild( new Xpp3Dom( recessiveChild ) );
finalConfiguration.addChild( parameterConfiguration );
private Xpp3Dom toXpp3DomTree(String name, Map<String, Object> config) { Xpp3Dom xConfig = new Xpp3Dom(name); for (Entry<String, Object> entry : config.entrySet()) { if (entry.getValue() instanceof String) { Xpp3Dom node = new Xpp3Dom(entry.getKey()); node.setValue(entry.getValue().toString()); xConfig.addChild(node); } else { @SuppressWarnings("unchecked") // Guaranteed by #configurationMap() Map<String, Object> childMap = (Map<String, Object>) entry.getValue(); // Recurse. Xpp3Dom child = toXpp3DomTree(entry.getKey(), childMap); xConfig.addChild(child); } } return xConfig; }
private Xpp3Dom toDom(Xpp3Dom parent, Map<Object, Object> map) { for (Map.Entry<Object, Object> entry : map.entrySet()) { String key = entry.getKey().toString(); Object entryValue = entry.getValue(); Xpp3Dom child = new Xpp3Dom(key); if (key.startsWith(ATTRIBUTE_PREFIX)) { toAttribute(parent, key.replace(ATTRIBUTE_PREFIX, ""), entryValue); continue; } // lists need the insertion of intermediate XML DOM nodes which hold the actual values if (entryValue instanceof List && !((List) entryValue).isEmpty()) { toDom(child, key, (List) entryValue); } else if (entryValue instanceof Map) { //noinspection unchecked child = toDom(child, (Map) entryValue); } else { // if not a list or map then copy the string value child.setValue(entryValue.toString()); } parent.addChild(child); } return parent; }
/** * @since 3.2.0 */ public void executeMojo( MavenSession session, MavenProject project, String goal, Xpp3Dom... parameters ) throws Exception { MojoExecution execution = newMojoExecution( goal ); if ( parameters != null ) { Xpp3Dom configuration = execution.getConfiguration(); for ( Xpp3Dom parameter : parameters ) { configuration.addChild( parameter ); } } executeMojo( session, project, execution ); }
private Xpp3Dom nodeToXpp3(final Node node) { Xpp3Dom dom = new Xpp3Dom((String) node.name()); Object value = node.value(); if (value instanceof String) { dom.setValue(String.valueOf(value)); } Map attrs = node.attributes(); for (Object key : attrs.keySet()) { dom.setAttribute(String.valueOf(key), String.valueOf(attrs.get(key))); } for (Object child : node.children()) { if (child instanceof Node) { dom.addChild(nodeToXpp3((Node) child)); } } return dom; } }
if (sharedLibrariesDom == null) { sharedLibrariesDom = new Xpp3Dom(SHARED_LIBRARIES_ELEMENT); configuration.addChild(sharedLibrariesDom); sharedLibrariesDom.addChild(sharedLibraryDom); Xpp3Dom groupIdDom = new Xpp3Dom("groupId"); groupIdDom.setValue(dependency.getGroupId()); sharedLibraryDom.addChild(groupIdDom); Xpp3Dom artifactIdDom = new Xpp3Dom("artifactId"); artifactIdDom.setValue(dependency.getArtifactId()); sharedLibraryDom.addChild(artifactIdDom);
@Override public boolean onNodeChildren(FactoryBuilderSupport builder, Object node, Closure content) { Xpp3Dom dom = (Xpp3Dom) node; NodeBuilder nodes = new NodeBuilder() { @Override protected void setClosureDelegate(final Closure c, final Object o) { c.setDelegate(this); c.setResolveStrategy(Closure.DELEGATE_FIRST); } @Override public void setProperty(final String name, final Object value) { this.invokeMethod(name, value); } }; content.setDelegate(nodes); content.setResolveStrategy(Closure.DELEGATE_FIRST); Node root = (Node) nodes.invokeMethod(getName(), content); for (Node child : (List<Node>) root.children()) { dom.addChild(nodeToXpp3(child)); } return false; }
private Plugin createMuleMavenPlugin() { Plugin plugin = new Plugin(); plugin.setGroupId(MULE_MAVEN_PLUGIN_GROUP_ID); plugin.setArtifactId(MULE_MAVEN_PLUGIN_ARTIFACT_ID); plugin.setVersion(MULE_MAVEN_PLUGIN_VERSION); Xpp3Dom configuration = new Xpp3Dom("configuration"); plugin.setConfiguration(configuration); Xpp3Dom sharedLibrariesDom = new Xpp3Dom("sharedLibraries"); configuration.addChild(sharedLibrariesDom); dependencies.stream().filter(sharedLibraries::contains) .forEach(sharedLibrary -> { Xpp3Dom sharedLibraryDom = new Xpp3Dom("sharedLibrary"); sharedLibrariesDom.addChild(sharedLibraryDom); Xpp3Dom groupIdDom = new Xpp3Dom("groupId"); groupIdDom.setValue(sharedLibrary.getGroupId()); sharedLibraryDom.addChild(groupIdDom); Xpp3Dom artifactIdDom = new Xpp3Dom("artifactId"); artifactIdDom.setValue(sharedLibrary.getArtifactId()); sharedLibraryDom.addChild(artifactIdDom); }); return plugin; }
finalConfiguration.addChild( parameterConfiguration );