Java Code Examples for org.codehaus.plexus.util.xml.Xpp3Dom#getValue()

The following examples show how to use org.codehaus.plexus.util.xml.Xpp3Dom#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginPropertyUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static @NonNull ConfigurationBuilder<String[]> listProperty(final @NonNull String multiProperty, final @NonNull String singleProperty) {
    return new ConfigurationBuilder<String[]>() {
        @Override
        public String[] build(Xpp3Dom conf, ExpressionEvaluator eval) {
            if (conf != null) {
                Xpp3Dom dom = (Xpp3Dom) conf; // MNG-4862
                Xpp3Dom source = dom.getChild(multiProperty);
                if (source != null) {
                    List<String> toRet = new ArrayList<String>();
                    Xpp3Dom[] childs = source.getChildren(singleProperty);
                    for (Xpp3Dom ch : childs) {
                        String chvalue = ch.getValue() == null ? "" : ch.getValue().trim();  //NOI18N
                        toRet.add(chvalue);  //NOI18N
                    }
                    return toRet.toArray(new String[toRet.size()]);
                }
            }
            return null;
        }
    };
}
 
Example 2
Source File: ReportAggregateMojo.java    From revapi with Apache License 2.0 6 votes vote down vote up
protected static String[] getArtifacts(Xpp3Dom config, String artifactTag) {
    Xpp3Dom oldArtifactsXml = config == null ? null : config.getChild(artifactTag);

    if (oldArtifactsXml == null) {
        return new String[0];
    }

    if (oldArtifactsXml.getChildCount() == 0) {
        String artifact = oldArtifactsXml.getValue();
        return new String[]{artifact};
    } else {
        String[] ret = new String[oldArtifactsXml.getChildCount()];
        for (int i = 0; i < oldArtifactsXml.getChildCount(); ++i) {
            ret[i] = oldArtifactsXml.getChild(i).getValue();
        }

        return ret;
    }
}
 
Example 3
Source File: ModelIO.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * Recursively process the DOM elements to inline any property values from the model.
 */
private void processChildren( Properties userProperties, Model model, Xpp3Dom parent )
{
    for ( int i = 0; i < parent.getChildCount(); i++ )
    {
        Xpp3Dom child = parent.getChild( i );

        if ( child.getChildCount() > 0 )
        {
            processChildren( userProperties, model, child );
        }
        if ( child.getValue() != null && child.getValue().startsWith( "${" ) )
        {
            String replacement = resolveProperty( userProperties, model.getProperties(), child.getValue() );

            if ( replacement != null && !replacement.isEmpty() )
            {
                logger.debug( "Replacing child value {} with {}", child.getValue(), replacement );
                child.setValue( replacement );
            }
        }

    }
}
 
Example 4
Source File: ByteBuddyMojo.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Makes a best effort of locating the configured Java target version.
 *
 * @param project The relevant Maven project.
 * @return The Java version string of the configured build target version or {@code null} if no explicit configuration was detected.
 */
private static String findJavaVersionString(MavenProject project) {
    while (project != null) {
        String target = project.getProperties().getProperty("maven.compiler.target");
        if (target != null) {
            return target;
        }
        for (org.apache.maven.model.Plugin plugin : CompoundList.of(project.getBuildPlugins(), project.getPluginManagement().getPlugins())) {
            if ("maven-compiler-plugin".equals(plugin.getArtifactId())) {
                if (plugin.getConfiguration() instanceof Xpp3Dom) {
                    Xpp3Dom node = ((Xpp3Dom) plugin.getConfiguration()).getChild("target");
                    if (node != null) {
                        return node.getValue();
                    }
                }
            }
        }
        project = project.getParent();
    }
    return null;
}
 
Example 5
Source File: Utils.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
/**
 * Method findAndReplaceXpp3DOM.
 * 
 * @param counter
 * @param dom
 * @param name
 * @param parent
 * @return Element
 */
public static Element findAndReplaceXpp3DOM( final IndentationCounter counter, final Element parent,
                                             final String name, final Xpp3Dom dom )
{
    final boolean shouldExist = ( dom != null ) && ( dom.getChildCount() > 0 || dom.getValue() != null );
    final Element element = updateElement( counter, parent, name, shouldExist );
    if ( shouldExist )
    {
        replaceXpp3DOM( element, dom, new IndentationCounter( counter.getDepth() + 1 ) );
    }
    return element;
}
 
Example 6
Source File: IteratorMojo.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * This will copy the configuration from <b>src</b> to the result whereas the placeholder will be replaced with the
 * current value.
 */
private PlexusConfiguration copyConfiguration( Xpp3Dom src, String iteratorName, String value )
{

    XmlPlexusConfiguration dom = new XmlPlexusConfiguration( src.getName() );

    if ( src.getValue() == null )
    {
        dom.setValue( src.getValue() );
    }
    else
    {
        if ( src.getValue().contains( iteratorName ) )
        {
            dom.setValue( src.getValue().replaceAll( iteratorName, value ) );
        }
        else
        {
            dom.setValue( src.getValue() );
        }
    }

    for ( String attributeName : src.getAttributeNames() )
    {
        dom.setAttribute( attributeName, src.getAttribute( attributeName ) );
    }

    for ( Xpp3Dom child : src.getChildren() )
    {
        dom.addChild( copyConfiguration( child, iteratorName, value ) );
    }

    return dom;
}
 
Example 7
Source File: CloudSdkMojo.java    From app-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the Java compiler target version by inspecting the project's maven-compiler-plugin
 * configuration.
 *
 * @return The Java compiler target version.
 */
public String getCompileTargetVersion() {
  // TODO: Add support for maven.compiler.release
  // maven-plugin-compiler default is 1.5
  String javaVersion = "1.5";
  if (mavenProject != null) {
    // check the maven.compiler.target property first
    String mavenCompilerTargetProperty =
        mavenProject.getProperties().getProperty("maven.compiler.target");
    if (mavenCompilerTargetProperty != null) {
      javaVersion = mavenCompilerTargetProperty;
    } else {
      Plugin compilerPlugin =
          mavenProject.getPlugin("org.apache.maven.plugins:maven-compiler-plugin");
      if (compilerPlugin != null) {
        Xpp3Dom config = (Xpp3Dom) compilerPlugin.getConfiguration();
        if (config != null) {
          Xpp3Dom domVersion = config.getChild("target");
          if (domVersion != null) {
            javaVersion = domVersion.getValue();
          }
        }
      }
    }
  }
  return javaVersion;
}
 
Example 8
Source File: LocationAwareMavenXpp3Writer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void writeXpp3DOM(XmlSerializer serializer, Xpp3Dom root, InputLocationTracker rootTracker) throws IOException {
    StringBuffer b = b(serializer);
    serializer.startTag(NAMESPACE, root.getName());
    //need to flush the inner writer, flush on serializer closes tag
    flush(serializer);
    int start = b.length() - root.getName().length() - 2;
    
    String[] attributeNames = root.getAttributeNames();
    for ( int i = 0; i < attributeNames.length; i++ )
    {
        String attributeName = attributeNames[i];
        serializer.attribute(NAMESPACE, attributeName, root.getAttribute( attributeName ));
    }
    
    boolean config = rootTracker != null ? rootTracker.getLocation(root.getName()) != null : true;
    
    Xpp3Dom[] children = root.getChildren();
    for ( int i = 0; i < children.length; i++ )
    {
        writeXpp3DOM(serializer, children[i], rootTracker != null ? rootTracker.getLocation(config ? root.getName() : root) : null);
    }

    String value = root.getValue();
    if ( value != null )
    {
        serializer.text( value );
    }

    serializer.endTag(NAMESPACE, root.getName()).flush();
    logLocation(rootTracker, config ? root.getName() : root, start, b.length());
    
}
 
Example 9
Source File: MavenProjectUtil.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
/**
 * Get a configuration value from an execution of a plugin
 * @param proj the Maven project
 * @param pluginGroupId the plugin group id
 * @param pluginArtifactId the plugin artifact id
 * @param executionId the plugin execution id
 * @param key the configuration key to get from
 * @return the value corresponding to the configuration key
 */
public static String getPluginExecutionConfiguration(MavenProject proj, String pluginGroupId, String pluginArtifactId, String executionId, String key) {
    Xpp3Dom dom = proj.getGoalConfiguration(pluginGroupId, pluginArtifactId, executionId, null);
    if (dom != null) {
        Xpp3Dom val = dom.getChild(key);
        if (val != null) {
            return val.getValue();
        }
    }
    return null;
}
 
Example 10
Source File: MavenSourceLevelImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String build(Xpp3Dom configRoot, ExpressionEvaluator eval) {
    if (configRoot != null) {
        Xpp3Dom args = configRoot.getChild("compilerArguments");
        if (args != null) {
            Xpp3Dom prof = args.getChild("profile");
            if (prof != null) {
                return prof.getValue();
            }
        }
    }
    return null;
}
 
Example 11
Source File: PluginPropertyUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static @NonNull ConfigurationBuilder<Properties> propertiesBuilder(final @NonNull String propertyParameter) {
    return new ConfigurationBuilder<Properties>() {
        @Override
        public Properties build(Xpp3Dom conf, ExpressionEvaluator eval) {
            if (conf != null) {

                Xpp3Dom source = conf.getChild(propertyParameter);
                if (source != null) {
                    Properties toRet = new Properties();
                    Xpp3Dom[] childs = source.getChildren();
                    for (Xpp3Dom ch : childs) {
                            String val = ch.getValue();
                            if (val == null) {
                                //#168036
                                //we have the "property" named element now.
                                if (ch.getChildCount() == 2) {
                                    Xpp3Dom nameDom = ch.getChild("name"); //NOI18N
                                    Xpp3Dom valueDom = ch.getChild("value"); //NOI18N
                                    if (nameDom != null && valueDom != null) {
                                        String name = nameDom.getValue();
                                        String value = valueDom.getValue();
                                        if (name != null && value != null) {
                                            toRet.put(name, value);  //NOI18N
                                        }
                                    }
                                }
                                // #153063, #187648
                                toRet.put(ch.getName(), "");
                                continue;
                            }
                            toRet.put(ch.getName(), val.trim());  //NOI18N
                    }
                    return toRet;
                }
            }
            return null;
        }
    };
}
 
Example 12
Source File: EarImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private MavenModule[] checkConfiguration(MavenProject prj, Object conf) {
    List<MavenModule> toRet = new ArrayList<MavenModule>();
    if (conf != null && conf instanceof Xpp3Dom) {
        ExpressionEvaluator eval = PluginPropertyUtils.createEvaluator(project);
        Xpp3Dom dom = (Xpp3Dom) conf;
        Xpp3Dom modules = dom.getChild("modules"); //NOI18N
        if (modules != null) {
            int index = 0;
            for (Xpp3Dom module : modules.getChildren()) {
                MavenModule mm = new MavenModule();
                mm.type = module.getName();
                if (module.getChildren() != null) {
                    for (Xpp3Dom param : module.getChildren()) {
                        String value = param.getValue();
                        if (value == null) {
                            continue;
                        }
                        try {
                            Object evaluated = eval.evaluate(value.trim());
                            value = evaluated != null ? ("" + evaluated) : value.trim();  //NOI18N
                        } catch (ExpressionEvaluationException e) {
                            //log silently
                        }
                        if ("groupId".equals(param.getName())) { //NOI18N
                            mm.groupId = value;
                        } else if ("artifactId".equals(param.getName())) { //NOI18N
                            mm.artifactId = value;
                        } else if ("classifier".equals(param.getName())) { //NOI18N
                            mm.classifier = value;
                        } else if ("uri".equals(param.getName())) { //NOI18N
                            mm.uri = value;
                        } else if ("bundleDir".equals(param.getName())) { //NOI18N
                            mm.bundleDir = value;
                        } else if ("bundleFileName".equals(param.getName())) { //NOI18N
                            mm.bundleFileName = value;
                        } else if ("excluded".equals(param.getName())) { //NOI18N
                            mm.excluded = Boolean.valueOf(value);
                        }
                    }
                }
                mm.pomIndex = index;
                index++;
                toRet.add(mm);
            }
        }
    }
    return toRet.toArray(new MavenModule[0]);
}
 
Example 13
Source File: ModelRunConfig.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public String build(Xpp3Dom configRoot, ExpressionEvaluator eval) {
    if (configRoot != null) {
        Xpp3Dom domArgs = configRoot.getChild("arguments"); // NOI18N
        if (domArgs != null) {
            Xpp3Dom[] children = domArgs.getChildren();
            if(children == null || children.length == 0) {
                return null;
            }
            Iterator<Xpp3Dom> it = Arrays.asList(children).iterator();
            StringBuilder sb = new StringBuilder();
            try {
                while(it.hasNext()) {
                    Xpp3Dom xpp3Dom = it.next();                            
                    String val = null;
                    if ("argument".equals(xpp3Dom.getName())) { // NOI18N
                        val = xpp3Dom.getValue();
                        if (val == null || val.trim().isEmpty()) {
                            continue;
                        }
                        val = val.trim();
                        if(val.contains("${")) {                                    
                            // not evaluated prop? 
                            LOG.log(Level.FINE, "skipping not evaluated property: {0}", val); // NOI18N
                            val = null;
                        }
                        if ("-cp".equals(val) || "-classpath".equals(val)) { // NOI18N
                            val = null;
                            // the -cp/-classpath parameter is already in exec.args
                            // lets assume that the following accords to
                            // -cp/-classpath %classpath mainClass 
                            // 1.) the classpath tag
                            Xpp3Dom dom = it.next();                                    
                            if (dom != null && "classpath".equals(dom.getName())) { // NOI18N
                                Xpp3Dom[] deps = dom.getChildren("dependency"); // NOI18N
                                if (deps == null || deps.length == 0) {
                                    // the classpath argument results to '-classpath %classpath'
                                    // and that is already part of exec.args -> set them in the right 
                                    // position as given by pom
                                    val = CP_PLACEHOLDER;
                                } else {
                                    for (Xpp3Dom dep : deps) {
                                        if(dep != null) {
                                            String d = dep.getValue();
                                            if(d != null && !d.trim().isEmpty()) {
                                                // explicitely declared deps - skip the whole thing.
                                                // would need to be resolved and we do not want 
                                                // to reimplement the whole exec plugin 
                                                LOG.log(Level.FINE, "skipping whole args evaluation due to explicitely declared deps"); // NOI18N
                                                return null;                                                                                                    
                                            }
                                        }
                                    }
                                }
                            }
                            // 2.) the main class
                            // doesn't necessaryli have to be after "-cp %classpath", so do not skip.
                            // it.next(); 
                        }
                    }
                    if (val != null && !val.isEmpty()) {
                        if (sb.length() > 0) {
                            sb.append(" "); // NOI18N
                        }
                        sb.append(val);
                    }                            
                }  
            } catch (NoSuchElementException e) {
                // ignore and return what you got
            }
            return sb.length() > 0 ? sb.toString() : null;
        }
    }
    return null;
}
 
Example 14
Source File: PathsToolchainFactory.java    From exec-maven-plugin with Apache License 2.0 4 votes vote down vote up
public ToolchainPrivate createToolchain( final ToolchainModel model )
    throws MisconfiguredToolchainException
{
    if ( model == null )
        return null;

    final PathsToolchain pathsToolchain = new PathsToolchain( model, this.logger );
    final Properties provides = this.getProvidesProperties( model );
    for ( final Map.Entry<Object, Object> provide : provides.entrySet() )
    {
        final String key = (String) provide.getKey();
        final String value = (String) provide.getValue();
        if ( value == null )
            throw new MisconfiguredToolchainException( "Provides token '" + key
                + "' doesn't have any value configured." );

        pathsToolchain.addProvideToken( key, RequirementMatcherFactory.createExactMatcher( value ) );
    }

    final Xpp3Dom config = (Xpp3Dom) model.getConfiguration();
    if ( config == null )
        return pathsToolchain;

    final Xpp3Dom pathDom = config.getChild( "paths" );
    if ( pathDom == null )
        return pathsToolchain;

    final Xpp3Dom[] pathDoms = pathDom.getChildren( "path" );
    if ( pathDoms == null || pathDoms.length == 0 )
        return pathsToolchain;

    final List<String> paths = new ArrayList<String>( pathDoms.length );
    for ( final Xpp3Dom pathdom : pathDoms )
    {
        final String pathString = pathdom.getValue();

        if ( pathString == null )
            throw new MisconfiguredToolchainException( "path element is empty" );

        final String normalizedPath = FileUtils.normalize( pathString );
        final File file = new File( normalizedPath );
        if ( !file.exists() )
            throw new MisconfiguredToolchainException( "Non-existing path '" + file.getAbsolutePath() + "'" );

        paths.add( normalizedPath );
    }

    pathsToolchain.setPaths( paths );

    return pathsToolchain;
}
 
Example 15
Source File: SiteLogHandlerDeserializer.java    From asciidoctor-maven-plugin with Apache License 2.0 4 votes vote down vote up
private String sanitizeString(Xpp3Dom severity) {
    String value = severity.getValue();
    return value == null ? "" : value.trim();
}
 
Example 16
Source File: ReportAggregateMojo.java    From revapi with Apache License 2.0 4 votes vote down vote up
private static String getValueOfChild(Xpp3Dom element, String childName) {
    Xpp3Dom child = element == null ? null : element.getChild(childName);
    return child == null ? null : child.getValue();
}
 
Example 17
Source File: ClasspathWorkspaceReader.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
private List<File> createFoundModules(final File pomFile)
{
   try
   {
      List<File> result = new ArrayList<>();
      if (log.isLoggable(Level.FINE))
      {
         log.fine("Processing " + pomFile.getAbsolutePath() + " for classpath module resolution");
      }
      Xpp3Dom dom = null;
      try (FileReader reader = new FileReader(pomFile))
      {
         dom = Xpp3DomBuilder.build(reader);
      }
      Xpp3Dom modules = dom.getChild("modules");
      if (modules != null)
      {
         for (Xpp3Dom module : modules.getChildren())
         {
            result.add(new File(pomFile.getParent(), module.getValue()));
         }
      }

      if (result.isEmpty())
      {
         Xpp3Dom parent = dom.getChild("parent");
         if (parent != null)
         {
            Xpp3Dom relativePathNode = parent.getChild("relativePath");
            String relativePath = (relativePathNode == null) ? "../pom.xml" : relativePathNode.getValue();
            if (relativePath != null)
            {
                File parentPom = pomFile.getParentFile().toPath().resolve(relativePath).toFile();
                if (parentPom.isFile())
                    result = createFoundModules(parentPom);
            }
         }
      }

      return result;
   }
   catch (final Exception e)
   {
      throw new RuntimeException("Could not parse pom.xml: " + pomFile, e);
   }
}
 
Example 18
Source File: AbstractDockerMojo.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Get the email from the server configuration in <code>~/.m2/settings.xml</code>.
 *
 * <pre>{@code
 * <servers>
 *   <server>
 *     <id>my-private-docker-registry</id>
 *     [...]
 *     <configuration>
 *       <email>[email protected]</email>
 *     </configuration>
 *   </server>
 * </servers>
 * }</pre>
 *
 * The above <code>settings.xml</code> would return "[email protected]".
 * @param server {@link Server}
 * @return email, or {@code null} if not set
 */
private String getEmail(final Server server) {
  String email = null;

  final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration();

  if (configuration != null) {
    final Xpp3Dom emailNode = configuration.getChild("email");

    if (emailNode != null) {
      email = emailNode.getValue();
    }
  }

  return email;
}
 
Example 19
Source File: AbstractDockerMojo.java    From docker-maven-plugin with Apache License 2.0 3 votes vote down vote up
/**
 * <pre>
 * <servers>
 *   <server>
 *     <id>docker-private-registry</id>
 *     [...]
 *     <configuration>
 *       <email>[email protected]</email>
 *     </configuration>
 *   </server>
 * </servers>
 * </pre>
 */
private String getEmail(Server server) {
    Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration();
    if (configuration != null) {
        Xpp3Dom emailNode = configuration.getChild("email");
        if (emailNode != null) {
            return emailNode.getValue();
        }
    }
    return null;
}
 
Example 20
Source File: MavenCompilerUtils.java    From pgpverify-maven-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Extract child value if child is present, or return empty string if absent.
 *
 * @param node the parent node
 * @param name the child node name
 * @return Returns child value if child node present or otherwise empty string.
 */
private static String extractChildValue(Xpp3Dom node, String name) {
    final Xpp3Dom child = node.getChild(name);
    return child == null ? "" : child.getValue();
}