private String extractFromServerConfiguration(Object configuration, String prop) { if (configuration != null) { Xpp3Dom dom = (Xpp3Dom) configuration; Xpp3Dom element = dom.getChild(prop); if (element != null) { return element.getValue(); } } return null; }
private List<String> parseStrings( Xpp3Dom dom ) { List<String> strings = null; if ( dom != null ) { strings = new ArrayList<>(); for ( Xpp3Dom child : dom.getChildren() ) { String string = child.getValue(); if ( string != null ) { string = string.trim(); if ( string.length() > 0 ) { strings.add( string ); } } } } return strings; }
public static String getPluginConfigParameter ( MavenProject project, String parameter, String defaultValue ) { String value = null; for ( Plugin plugin : project.getBuild().getPlugins() ) { if ( plugin.getArtifactId().equals( PluginInfo.getArtifactId() ) ) { Xpp3Dom configuration = getMojoConfiguration( plugin ); if ( configuration != null && configuration.getChild( parameter ) != null ) { value = configuration.getChild( parameter ).getValue() ; } } } // if we got nothing, fall back to the default value return ( StringUtils.isEmpty( value ) ) ? defaultValue : value; }
/** * 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 ) ) ); } }
public static void write( XMLWriter xmlWriter, Xpp3Dom dom, boolean escape ) { // TODO: move to XMLWriter? xmlWriter.startElement( dom.getName() ); String[] attributeNames = dom.getAttributeNames(); for ( String attributeName : attributeNames ) { xmlWriter.addAttribute( attributeName, dom.getAttribute( attributeName ) ); } Xpp3Dom[] children = dom.getChildren(); for ( Xpp3Dom aChildren : children ) { write( xmlWriter, aChildren, escape ); } String value = dom.getValue(); if ( value != null ) { if ( escape ) { xmlWriter.writeText( value ); } else { xmlWriter.writeMarkup( value ); } } xmlWriter.endElement(); }
private List<String> extractStrings(String element, Xpp3Dom configuration) { Xpp3Dom groups = configuration.getChild(element); if (groups != null) { String[] parts = groups.getValue().split(" "); return Arrays.asList(parts); } else { return Collections.emptyList(); } }
private List<String> extract(String childname, Xpp3Dom config) { final Xpp3Dom subelement = config.getChild(childname); if (subelement != null) { List<String> result = new LinkedList<>(); final Xpp3Dom[] children = subelement.getChildren(); for (Xpp3Dom child : children) { result.add(child.getValue()); } return result; } return Collections.emptyList(); }
private void convertTestFailureIgnore(ReportOptions option, Xpp3Dom configuration) { Xpp3Dom testFailureIgnore = configuration.getChild("testFailureIgnore"); if (testFailureIgnore != null) { option.setSkipFailingTests(Boolean.parseBoolean(testFailureIgnore.getValue())); } } }
protected String getAttribute(Xpp3Dom tag, String attributeName) { Xpp3Dom attributeDom = tag.getChild(attributeName); checkState(attributeDom != null, format("'%s' element not declared at '%s' in the pom file of the artifact '%s'", attributeName, tag.toString(), artifactFolder.getName())); String attributeValue = attributeDom.getValue().trim(); checkState(!isEmpty(attributeValue), format("'%s' was defined but has an empty value at '%s' declared in the pom file of the artifact %s", attributeName, tag.toString(), artifactFolder.getName())); return attributeValue; }
private List<Object> toList(Xpp3Dom node, String childName) { List<Object> list = new ArrayList<>(); int n = node.getChildCount(); for (int i = 0; i < n; i++) { Xpp3Dom child = node.getChild(i); if (!childName.equals(child.getName())) { throw new YAMLException(format("child name: '%s' does not match expected name: '%s' at node %s", child.getName(), childName, node)); } Object childValue = child.getValue(); if (childValue == null) { childValue = toMap(child); } list.add(childValue); } return list; } }
private String getSourceVersion(BuildBase build) { for (Plugin plugin : build.getPlugins()) { if (!"maven-compiler-plugin".equals(plugin.getArtifactId())) { continue; } Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); if (configuration != null) { Xpp3Dom source = configuration.getChild("source"); if (source != null) { return source.getValue(); } } break; } return null; }
/** * Lookup the mojo leveraging the actual subprojects pom * * @param goal * @param pom * @return a Mojo instance * @throws Exception */ protected Mojo lookupEmptyMojo( String goal, File pom ) throws Exception { File pluginPom = new File( getBasedir(), "pom.xml" ); Xpp3Dom pluginPomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( pluginPom ) ); String artifactId = pluginPomDom.getChild( "artifactId" ).getValue(); String groupId = resolveFromRootThenParent( pluginPomDom, "groupId" ); String version = resolveFromRootThenParent( pluginPomDom, "version" ); return lookupMojo( groupId, artifactId, version, goal, null ); }
private void generateConfig(Xpp3Dom node, StringBuilder sb, String indent) { String tagName = node.getName(); String tagValue = node.getValue(); if (node.getParent() == null) { sb.append(indent + ".tag(\"" + tagName + "\", " + tagName + " -> {" + br); } if (tagValue != null) { sb.append(indent + " " + calculateXMLIndent(node) + tagName + ".content(\"" + tagValue + "\");" + br); } String[] attributeNames = node.getAttributeNames(); for (int i = 0; i < attributeNames.length; i++) { String attributeName = attributeNames[i]; sb.append(indent + calculateXMLIndent(node) + " " + tagName + ".attribute(\"" + attributeName + "\", \"" + node.getAttribute(attributeName) + "\");" + br); } Xpp3Dom[] children = node.getChildren(); for (int i = 0; i < children.length; i++) { Xpp3Dom child = children[i]; sb.append(indent + calculateXMLIndent(child) + child.getParent().getName() + ".child(\"" + child.getName() + "\"," + child.getName() + " -> {" + br); generateConfig(child, sb, indent); sb.append(indent + calculateXMLIndent(child) + "});" + br); } if (node.getParent() == null) { sb.append(indent + calculateXMLIndent(node) + "})" + br); } }
/** * Lookup the mojo leveraging the actual subprojects pom * * @param goal * @param pom * @return a Mojo instance * @throws Exception */ protected Mojo lookupMojo( String goal, File pom ) throws Exception { File pluginPom = new File( getBasedir(), "pom.xml" ); Xpp3Dom pluginPomDom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( pluginPom ) ); String artifactId = pluginPomDom.getChild( "artifactId" ).getValue(); String groupId = resolveFromRootThenParent( pluginPomDom, "groupId" ); String version = resolveFromRootThenParent( pluginPomDom, "version" ); PlexusConfiguration pluginConfiguration = extractPluginConfiguration( artifactId, pom ); return lookupMojo( groupId, artifactId, version, goal, pluginConfiguration ); }
public XmlPlexusConfiguration( Xpp3Dom dom ) { super( dom.getName(), dom.getValue() ); // attrs String[] attributes = dom.getAttributeNames(); for (String attribute : attributes) { setAttribute(attribute, dom.getAttribute(attribute)); } // children int childCount = dom.getChildCount(); for ( int i = 0; i < childCount; i++ ) { addChild( new XmlPlexusConfiguration( dom.getChild( i ) ) ); } }
void visit( Node node ) { for( String name: node.base.getAttributeNames() ) { new Leaf( "@" + name, node.base.getAttribute( name ) .replaceAll( "'", "\\\\'" ) ).accept( this ); } for ( Xpp3Dom child : node.base.getChildren() ) { if ( child.getChildCount() == 0 && child.getAttributeNames().length == 0 ) { new Leaf( child.getName(), child.getValue() ).accept( this ); } else if ( ( child.getChildCount() > 1 && child.getChild(0).getName().equals( child.getChild( 1 ).getName() ) ) || ( child.getChildCount() == 1 && child.getName().equals( child.getChild( 0 ).getName() + "s" ) ) ) { new ListNode( child ).accept( this ); } else { new Node( child ).accept( this ); } } } }