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

The following examples show how to use org.codehaus.plexus.util.xml.Xpp3Dom#getChild() . 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> simpleProperty(final @NonNull String property) {
    return new ConfigurationBuilder<String>() {

        @Override
        public String build(Xpp3Dom configRoot, ExpressionEvaluator eval) {
            if (configRoot != null) {
                Xpp3Dom source = configRoot.getChild(property);
                if (source != null) {
                    String value = source.getValue();
                    if (value == null) {
                        return null;
                    }
                    return value.trim();
                }
            }
            return null;
        }
    };
}
 
Example 2
Source File: AbstracMavenProjectConfigurator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Searches the Maven pom.xml for the given project nature.
 *
 * @param mavenProject a description of the Maven project
 * @param natureId the nature to check
 * @return {@code true} if the project
 */
protected boolean hasProjectNature(MavenProject mavenProject, String natureId) {
  if (natureId == GWTNature.NATURE_ID || getGwtMavenPlugin(mavenProject) != null) {
    return true;
  }
  // The use of the maven-eclipse-plugin is deprecated. The following code is
  // only for backward compatibility.
  Plugin plugin = getEclipsePlugin(mavenProject);
  if (plugin != null) {
    Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
    if (configuration != null) {
      Xpp3Dom additionalBuildCommands = configuration.getChild("additionalProjectnatures");
      if (additionalBuildCommands != null) {
        for (Xpp3Dom projectNature : additionalBuildCommands.getChildren("projectnature")) {
          if (projectNature != null && natureId.equals(projectNature.getValue())) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
 
Example 3
Source File: AbstractGcloudMojo.java    From gcloud-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * @return the java version used the pom (target) and 1.7 if not present.
 */
protected String getJavaVersion() {
  String javaVersion = "1.7";
  Plugin p = maven_project.getPlugin("org.apache.maven.plugins:maven-compiler-plugin");
  if (p != null) {
    Xpp3Dom config = (Xpp3Dom) p.getConfiguration();
    if (config == null) {
      return javaVersion;
    }
    Xpp3Dom domVersion = config.getChild("target");
    if (domVersion != null) {
      javaVersion = domVersion.getValue();
    }
  }
  return javaVersion;
}
 
Example 4
Source File: MavenProjectUtil.java    From ci.maven with Apache License 2.0 6 votes vote down vote up
/**
 * Get directory and targetPath configuration values from the Maven WAR plugin
 * @param proj the Maven project
 * @return a Map of source and target directories corresponding to the configuration keys
 * or null if the war plugin or its webResources or resource elements are not used. 
 * The map will be empty if the directory element is not used. The value field of the 
 * map is null when the targetPath element is not used.
 */
public static Map<String,String> getWebResourcesConfiguration(MavenProject proj) {
    Xpp3Dom dom = proj.getGoalConfiguration("org.apache.maven.plugins", "maven-war-plugin", null, null);
    if (dom != null) {
        Xpp3Dom web = dom.getChild("webResources");
        if (web != null) {
            Xpp3Dom resources[] = web.getChildren("resource");
            if (resources != null) {
                Map<String, String> result = new HashMap<String, String>();
                for (int i = 0; i < resources.length; i++) {
                    Xpp3Dom dir = resources[i].getChild("directory");
                    if (dir != null) {
                        Xpp3Dom target = resources[i].getChild("targetPath");
                        if (target != null) {
                            result.put(dir.getValue(), target.getValue());
                        } else {
                            result.put(dir.getValue(), null);
                        }
                    }
                }
                return result;
            }
        }
    }
    return null;
}
 
Example 5
Source File: ExecuteMojoUtil.java    From ci.maven with Apache License 2.0 6 votes vote down vote up
private static Xpp3Dom convertLibertyAlias(Xpp3Dom config) {
    // convert alias parameter key to actual parameter key
    Xpp3Dom alias;
    for (String key : LIBERTY_ALIAS_MAP.keySet()) {
        alias = config.getChild(key);
        if (alias != null) {
            if ("runtimeArtifact".contentEquals(key)) {
                Xpp3Dom artifact = new Xpp3Dom(LIBERTY_ALIAS_MAP.get(key));
                for (Xpp3Dom child : alias.getChildren()) {
                    artifact.addChild(child);
                }
                config.addChild(artifact);
            } else {
                Element e = (element(name(LIBERTY_ALIAS_MAP.get(key)), alias.getValue()));
                config.addChild(e.toDom());
            }
        }
    }
    return config;
}
 
Example 6
Source File: AuthConfigFactory.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: RequiredMavenVersionFinder.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private ArtifactVersion getEnforcerMavenVersion() {
    List<Plugin> buildPlugins = mavenProject.getBuildPlugins();
    if (null == buildPlugins) {
        return null;
    }

    Plugin mavenEnforcerPlugin = getMavenEnforcerPlugin(buildPlugins);
    if (null == mavenEnforcerPlugin) {
        return null;
    }

    List<PluginExecution> pluginExecutions = mavenEnforcerPlugin.getExecutions();
    if (null == pluginExecutions) {
        return null;
    }

    List<PluginExecution> pluginExecutionsWithEnforceGoal = getPluginExecutionsWithEnforceGoal(pluginExecutions);
    if (pluginExecutionsWithEnforceGoal.isEmpty()) {
        return null;
    }
    
    Xpp3Dom requireMavenVersionTag = getRequireMavenVersionTag(pluginExecutionsWithEnforceGoal);
    if (null == requireMavenVersionTag) {
        return null;
    }

    Xpp3Dom versionTag = requireMavenVersionTag.getChild("version");
    if (null == versionTag) {
        return null;
    }

    String versionTagValue = versionTag.getValue();
    if (null == versionTagValue || "".equals(versionTagValue)) {
        return null;
    }

    return processMavenVersionRange(versionTagValue);
}
 
Example 8
Source File: SurefireConfigConverter.java    From pitest with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 9
Source File: OrientMetadataRebuilder.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Helper method to get node's immediate child or default.
 */
private String getChildValue(final Xpp3Dom doc, final String childName, final String defaultValue) {
  Xpp3Dom child = doc.getChild(childName);
  if (child == null) {
    return defaultValue;
  }
  return child.getValue();
}
 
Example 10
Source File: AbstractXtendCompilerMojo.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private String getBootClassPath() {
	Toolchain toolchain = toolchainManager.getToolchainFromBuildContext("jdk", session);
	if (toolchain instanceof DefaultJavaToolChain) {
		DefaultJavaToolChain javaToolChain = (DefaultJavaToolChain) toolchain;
		getLog().info("Using toolchain " + javaToolChain);

		if (javaSourceVersion != null) {
			JavaVersion version = JavaVersion.fromQualifier(javaSourceVersion);
			if (version.isAtLeast(JavaVersion.JAVA9)) {
				return ""; // bootclasspath only supported on Java8 and older
			}
		}

		String[] includes = { "jre/lib/*", "jre/lib/ext/*", "jre/lib/endorsed/*" };
		String[] excludes = new String[0];
		Xpp3Dom config = (Xpp3Dom) javaToolChain.getModel().getConfiguration();
		if (config != null) {
			Xpp3Dom bootClassPath = config.getChild("bootClassPath");
			if (bootClassPath != null) {
				Xpp3Dom includeParent = bootClassPath.getChild("includes");
				if (includeParent != null) {
					includes = getValues(includeParent.getChildren("include"));
				}
				Xpp3Dom excludeParent = bootClassPath.getChild("excludes");
				if (excludeParent != null) {
					excludes = getValues(excludeParent.getChildren("exclude"));
				}
			}
		}

		return scanBootclasspath(javaToolChain.getJavaHome(), includes, excludes);
	}
	return "";
}
 
Example 11
Source File: SkipModuleChecker.java    From smart-testing with Apache License 2.0 5 votes vote down vote up
private boolean isPropertySetInPluginConfiguration(Xpp3Dom pluginConfiguration, String property) {
    Xpp3Dom propertyKey = pluginConfiguration.getChild(property);
    if (propertyKey == null) {
        if (property.equals(SKIP)) {
            return isPropertyInPom(MAVEN_TEST_SKIP);
        }
        return isPropertyInPom(property);
    }
    return Boolean.valueOf(propertyKey.getValue());
}
 
Example 12
Source File: SiteLogHandlerDeserializer.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Boolean getBoolean(Xpp3Dom node, String name) {
    final Xpp3Dom child = node.getChild(name);
    if (child == null) {
        return Boolean.TRUE;
    } else {
        if (child.getValue() == null) {
            return Boolean.TRUE;
        }
        return Boolean.valueOf(child.getValue());
    }
}
 
Example 13
Source File: PluginConfigSupport.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
private String getPluginConfiguration(MavenProject proj, String pluginGroupId, String pluginArtifactId,
        String key) {
    Xpp3Dom dom = proj.getGoalConfiguration(pluginGroupId, pluginArtifactId, null, null);
    if (dom != null) {
        Xpp3Dom val = dom.getChild(key);
        if (val != null) {
            return val.getValue();
        }
    }
    return null;
}
 
Example 14
Source File: DevMojo.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
/**
 * Force change a property so that the checksum calculated by
 * AbstractSurefireMojo is different every time.
 *
 * @param config
 *            The configuration element
 */
private void injectTestId(Xpp3Dom config) {
    Xpp3Dom properties = config.getChild("properties");
    if (properties == null || properties.getChild(TEST_RUN_ID_PROPERTY_NAME) == null) {
        Element e = element(name("properties"), element(name(TEST_RUN_ID_PROPERTY_NAME), String.valueOf(runId++)));
        config.addChild(e.toDom());
    } else {
        properties.getChild(TEST_RUN_ID_PROPERTY_NAME).setValue(String.valueOf(runId++));
    }
}
 
Example 15
Source File: SurefireConfigConverter.java    From pitest with Apache License 2.0 5 votes vote down vote up
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();
  }
}
 
Example 16
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 17
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 18
Source File: AsciidoctorDoxiaParser.java    From asciidoctor-maven-plugin with Apache License 2.0 4 votes vote down vote up
private LogHandler getLogHandlerConfig(Xpp3Dom siteConfig) {
    Xpp3Dom asciidoc = siteConfig == null ? null : siteConfig.getChild("asciidoc");
    return new SiteLogHandlerDeserializer().deserialize(asciidoc);
}
 
Example 19
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 20
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;
}