org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration Java Examples

The following examples show how to use org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration. 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: SchemaDrivenJSONToXmlConverter.java    From revapi with Apache License 2.0 6 votes vote down vote up
private static PlexusConfiguration convertArray(ModelNode configuration, ConversionContext ctx) {
    ModelNode itemsSchema = ctx.currentSchema.get("items");
    if (!itemsSchema.isDefined()) {
        throw new IllegalArgumentException(
                "No schema found for items of a list. Cannot continue with XML-to-JSON conversion.");
    }
    PlexusConfiguration list = new XmlPlexusConfiguration(ctx.tagName);
    if (ctx.id != null) {
        list.setAttribute("id", ctx.id);
    }

    for (ModelNode childConfig : configuration.asList()) {
        ctx.tagName = "item";
        ctx.currentSchema = itemsSchema;
        ctx.id = null;
        ctx.currentPath.push("[]");
        PlexusConfiguration child = convert(childConfig, ctx);
        ctx.currentPath.pop();
        list.addChild(child);
    }
    return list;
}
 
Example #2
Source File: MultiStartMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin");

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get("swarm-process");

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get("swarm-process");

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put("swarm-process", procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}
 
Example #3
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 #4
Source File: MojoConfigurationProcessor.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Extract the Mojo specific configuration from the incoming plugin configuration from Maven by looking at an enclosing element with the goal name. Use this and merge it with the default Mojo
 * configuration and use this to apply values to the Mojo.
 * 
 * @param goal
 * @param pluginConfigurationFromMaven
 * @param defaultMojoConfiguration
 * @return
 * @throws ComponentConfigurationException
 */
PlexusConfiguration extractAndMerge(String goal, PlexusConfiguration pluginConfigurationFromMaven, PlexusConfiguration defaultMojoConfiguration) throws ComponentConfigurationException {
  //
  // We need to extract the specific configuration for this goal out of the POM configuration
  //
  PlexusConfiguration mojoConfigurationFromPom = new XmlPlexusConfiguration("configuration");
  for (PlexusConfiguration element : pluginConfigurationFromMaven.getChildren()) {
    if (element.getName().equals(goal)) {
      for (PlexusConfiguration goalConfigurationElements : element.getChildren()) {
        mojoConfigurationFromPom.addChild(goalConfigurationElements);
      }
    }
  }
  return new XmlPlexusConfiguration(Xpp3Dom.mergeXpp3Dom(convert(mojoConfigurationFromPom), convert(defaultMojoConfiguration)));
}
 
Example #5
Source File: Analyzer.java    From revapi with Apache License 2.0 5 votes vote down vote up
private void mergeXmlConfigFile(AnalysisContext.Builder ctxBld, ConfigurationFile configFile, Reader rdr)
        throws IOException, XmlPullParserException {
    XmlToJson<PlexusConfiguration> conv = new XmlToJson<>(revapi, PlexusConfiguration::getName,
            PlexusConfiguration::getValue, PlexusConfiguration::getAttribute, x -> Arrays.asList(x.getChildren()));

    PlexusConfiguration xml = new XmlPlexusConfiguration(Xpp3DomBuilder.build(rdr));

    String[] roots = configFile.getRoots();

    if (roots == null) {
        ctxBld.mergeConfiguration(conv.convert(xml));
    } else {
        roots:
        for (String r : roots) {
            PlexusConfiguration root = xml;
            boolean first = true;
            String[] rootPath = r.split("/");
            for (String name : rootPath) {
                if (first) {
                    first = false;
                    if (!name.equals(root.getName())) {
                        continue roots;
                    }
                } else {
                    root = root.getChild(name);
                    if (root == null) {
                        continue roots;
                    }
                }
            }

            ctxBld.mergeConfiguration(conv.convert(root));
        }
    }
}
 
Example #6
Source File: SchemaDrivenJSONToXmlConverter.java    From revapi with Apache License 2.0 5 votes vote down vote up
private static PlexusConfiguration
convertNewStyleConfigToXml(Map<String, ModelNode> extensionSchemas, ModelNode jsonConfig) throws IOException {
    PlexusConfiguration xmlConfig = new XmlPlexusConfiguration("analysisConfiguration");

    for (ModelNode extConfig : jsonConfig.asList()) {
        String extensionId = extConfig.get("extension").asString();
        ModelNode configuration = extConfig.get("configuration");
        String id = extConfig.hasDefined("id") ? extConfig.get("id").asString() : null;

        ModelNode schema = extensionSchemas.get(extensionId);
        if (schema == null) {
            continue;
        }

        ConversionContext ctx = new ConversionContext();
        ctx.rootSchema = schema;
        ctx.currentSchema = schema;
        ctx.pushTag(extensionId);
        ctx.id = id;
        //we don't assign the ignorable paths, because this must not be tracked in a new-style configuration
        PlexusConfiguration extXml = convert(configuration, ctx);
        ctx.currentPath.pop();
        xmlConfig.addChild(extXml);
    }

    return xmlConfig;
}
 
Example #7
Source File: SchemaDrivenJSONToXmlConverter.java    From revapi with Apache License 2.0 5 votes vote down vote up
private static PlexusConfiguration convertOldStyleConfigToXml(Map<String, ModelNode> extensionSchemas,
                                                              ModelNode jsonConfig) {
    PlexusConfiguration xmlConfig = new XmlPlexusConfiguration("analysisConfiguration");

    extensionCheck: for (Map.Entry<String, ModelNode> e : extensionSchemas.entrySet()) {
        String extensionId = e.getKey();
        ModelNode schema = e.getValue();

        String[] extensionPath = extensionId.split("\\.");

        ModelNode config = jsonConfig;
        for (String segment : extensionPath) {
            if (!config.has(segment)) {
                continue extensionCheck;
            } else {
                config = config.get(segment);
            }
        }

        ConversionContext ctx = new ConversionContext();
        ctx.rootSchema = schema;
        ctx.currentSchema = schema;
        ctx.pushTag(extensionId);
        ctx.id = null;
        ctx.ignorablePaths = extensionSchemas.keySet().stream()
                .filter(id -> !extensionId.equals(id) && id.startsWith(extensionId))
                .collect(Collectors.toList());
        PlexusConfiguration extXml = convert(config, ctx);
        ctx.currentPath.pop();
        xmlConfig.addChild(extXml);
    }

    return xmlConfig;
}
 
Example #8
Source File: SchemaDrivenJSONToXmlConverter.java    From revapi with Apache License 2.0 5 votes vote down vote up
private static PlexusConfiguration convertSimple(String tagName, String id, String value) {
    XmlPlexusConfiguration ret = new XmlPlexusConfiguration(tagName);
    if (id != null) {
        ret.setAttribute("id", id);
    }

    ret.setValue(value);
    return ret;
}
 
Example #9
Source File: SchemaDrivenJSONToXmlConverter.java    From revapi with Apache License 2.0 5 votes vote down vote up
private static PlexusConfiguration convertObject(ModelNode configuration, ConversionContext ctx) {
    XmlPlexusConfiguration object = new XmlPlexusConfiguration(ctx.tagName);
    if (ctx.id != null) {
        object.setAttribute("id", ctx.id);
    }

    ModelNode propertySchemas = ctx.currentSchema.get("properties");
    ModelNode additionalPropSchemas = ctx.currentSchema.get("additionalProperties");
    for (String key : configuration.keys()) {
        ModelNode childConfig = configuration.get(key);
        ModelNode childSchema = propertySchemas.get(key);
        if (!childSchema.isDefined()) {
            if (additionalPropSchemas.getType() == ModelType.BOOLEAN) {
                throw new IllegalArgumentException("Cannot determine the format for the '" + key +
                        "' JSON value during the JSON-to-XML conversion.");
            }
            childSchema = additionalPropSchemas;
        }

        ctx.currentSchema = childSchema;
        ctx.pushTag(key);
        ctx.id = null;

        if (!childSchema.isDefined()) {
            //check if this is an ignorable path
            if (ctx.ignorablePaths.contains(ctx.getCurrentPathString())) {
                ctx.currentPath.pop();
                continue;
            }
            throw new IllegalArgumentException("Could not determine the format for the '" + key +
                    "' JSON value during the JSON-to-XML conversion.");
        }

        PlexusConfiguration xmlChild = convert(childConfig, ctx);
        ctx.currentPath.pop();
        object.addChild(xmlChild);
    }
    return object;
}
 
Example #10
Source File: MultiStartMojo.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
protected Xpp3Dom getProcessConfiguration(XmlPlexusConfiguration process) {
    Xpp3Dom config = new Xpp3Dom("configuration");

    config.addChild(convert(process.getChild("properties")));
    config.addChild(convert(process.getChild("environment")));

    return config;
}
 
Example #11
Source File: MultiStartMojo.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin");

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get("swarm-process");

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get("swarm-process");

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put("swarm-process", procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}
 
Example #12
Source File: MultiStartMojo.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    initProperties(true);
    initEnvironment();

    for (XmlPlexusConfiguration process : this.processes) {
        try {
            start(process);
        } catch (Exception e) {
            throw new MojoFailureException("Unable to start", e);
        }
    }
}
 
Example #13
Source File: MultiStartMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected Xpp3Dom getProcessConfiguration(XmlPlexusConfiguration process) {
    Xpp3Dom config = new Xpp3Dom("configuration");

    config.addChild(convert(process.getChild("properties")));
    config.addChild(convert(process.getChild("environment")));
    config.addChild(convert(process.getChild("jvmArguments")));

    return config;
}
 
Example #14
Source File: MultiStartMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin(THORNTAIL_MAVEN_PLUGIN);

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get(THORNTAIL_PROCESS);

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get(THORNTAIL_PROCESS);

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put(THORNTAIL_PROCESS, procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}
 
Example #15
Source File: MultiStartMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void executeSpecific() throws MojoExecutionException, MojoFailureException {

    initProperties(true);
    initEnvironment();

    for (XmlPlexusConfiguration process : this.processes) {
        try {
            start(process);
        } catch (Exception e) {
            throw new MojoFailureException("Unable to start", e);
        }
    }
}
 
Example #16
Source File: MultiStartMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
protected Xpp3Dom getProcessConfiguration(XmlPlexusConfiguration process) {
    Xpp3Dom config = new Xpp3Dom("configuration");

    config.addChild(convert(process.getChild("properties")));
    config.addChild(convert(process.getChild("environment")));
    config.addChild(convert(process.getChild("jvmArguments")));

    return config;
}
 
Example #17
Source File: MultiStartMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    initProperties(true);
    initEnvironment();

    for (XmlPlexusConfiguration process : this.processes) {
        try {
            start(process);
        } catch (Exception e) {
            throw new MojoFailureException("Unable to start", e);
        }
    }
}
 
Example #18
Source File: MojoExecutionServiceTest.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
private MojoDescriptor createPluginDescriptor() throws XmlPullParserException, IOException {
    MojoDescriptor descriptor = new MojoDescriptor();
    PlexusConfiguration config = new XmlPlexusConfiguration(Xpp3DomBuilder.build(new StringReader("<config name='test'><test>1</test></config>")));
    descriptor.setMojoConfiguration(config);
    return descriptor;
}
 
Example #19
Source File: MojoConfigurationProcessor.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
PlexusConfiguration mergePlexusConfiguration(PlexusConfiguration dominant, PlexusConfiguration recessive) throws ComponentConfigurationException {
  return new XmlPlexusConfiguration(Xpp3Dom.mergeXpp3Dom(convert(dominant), convert(recessive)));
}
 
Example #20
Source File: MojoConfigurationMergerTest.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
public PlexusConfiguration buildPlexusConfiguration() {
  if (!stack.empty()) {
    throw new IllegalStateException("You have unclosed elements.");
  }
  return new XmlPlexusConfiguration(configuration);
}
 
Example #21
Source File: PluginExecutor.java    From iterator-maven-plugin with Apache License 2.0 4 votes vote down vote up
public XmlPlexusConfiguration getConfiguration()
{
    return configuration;
}
 
Example #22
Source File: PluginExecutor.java    From iterator-maven-plugin with Apache License 2.0 4 votes vote down vote up
public void setConfiguration( XmlPlexusConfiguration configuration )
{
    this.configuration = configuration;
}
 
Example #23
Source File: XmlUtilTest.java    From revapi with Apache License 2.0 3 votes vote down vote up
@Test
public void testPrettyPrintingXml() throws Exception {
    String text = "<a><b><c>asdf</c><d/></b></a>";

    XmlPlexusConfiguration xml = new XmlPlexusConfiguration(Xpp3DomBuilder.build(new StringReader(text)));

    StringWriter wrt = new StringWriter();

    XmlUtil.toIndentedString(xml, 2, 0, wrt);

    String pretty = wrt.toString();

    assertEquals("<a>\n  <b>\n    <c>asdf</c>\n    <d/>\n  </b>\n</a>", pretty);
}