Java Code Examples for org.codehaus.plexus.configuration.PlexusConfiguration#addChild()

The following examples show how to use org.codehaus.plexus.configuration.PlexusConfiguration#addChild() . 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: DMNTransformerComponentConfigurationTest.java    From jdmn with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedConfiguration() throws Exception {
    PlexusConfiguration inner = new DefaultPlexusConfiguration("innerConfig");
    inner.addChild("innerKey1", "innerValue1");

    PlexusConfiguration intermediate = new DefaultPlexusConfiguration("intermediateConfig");
    intermediate.addChild("intermediateKey1", "intermediateValue1");
    intermediate.addChild(inner);

    PlexusConfiguration config = new DefaultPlexusConfiguration(OptionallyConfigurableMojoComponent.ELEMENT_CONFIGURATION);
    config.addChild("key1", "value1");
    config.addChild(intermediate);

    PlexusConfiguration configuration = generateComponentConfiguration("componentName", ELEMENT_NAME, config);
    OptionallyConfigurableMojoComponent component = parseConfiguration(configuration, DMNTransformerComponent.class);

    assertEquivalentConfiguration(component, "{\n" +
            "  \"key1\": \"value1\",\n" +
            "  \"intermediateConfig\": {\n" +
            "    \"intermediateKey1\": \"intermediateValue1\",\n" +
            "    \"innerConfig\": {\n" +
            "      \"innerKey1\": \"innerValue1\" \n" +
            "    }\n" +
            "  }\n" +
            "}");
}
 
Example 2
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 3
Source File: AbstractMojoConfigurationTest.java    From jdmn with Apache License 2.0 5 votes vote down vote up
protected PlexusConfiguration generateComponentConfiguration(String componentName, String elementName, PlexusConfiguration configuration) {
    PlexusConfiguration componentConfig = new DefaultPlexusConfiguration(elementName);

    if (componentName != null) {
        componentConfig.addChild(OptionallyConfigurableMojoComponent.ELEMENT_NAME, componentName);
    }

    if (configuration != null) {
        componentConfig.addChild(configuration);
    }

    return componentConfig;
}
 
Example 4
Source File: DMNTransformerComponentConfigurationTest.java    From jdmn with Apache License 2.0 5 votes vote down vote up
@Test
public void testMixedCompoundListConfiguration() throws Exception {
    PlexusConfiguration inner = new DefaultPlexusConfiguration("nestedList");
    inner.addChild("innerKey1", "innerValue1");
    inner.addChild("innerKey1", "innerValue2");

    PlexusConfiguration nestedData = new DefaultPlexusConfiguration("key2");
    nestedData.addChild("nestedValue1", "value1");
    nestedData.addChild("nestedValue2", "value2");
    nestedData.addChild(inner);

    PlexusConfiguration config = new DefaultPlexusConfiguration(OptionallyConfigurableMojoComponent.ELEMENT_CONFIGURATION);
    config.addChild("key1", "value1");
    config.addChild("key2", "singleValue");
    config.addChild(nestedData);

    PlexusConfiguration configuration = generateComponentConfiguration("componentName", ELEMENT_NAME, config);
    OptionallyConfigurableMojoComponent component = parseConfiguration(configuration, DMNTransformerComponent.class);

    assertEquivalentConfiguration(component, "{\n" +
            "  \"key1\": \"value1\",\n" +
            "  \"key2\": [\n" +
            "    \"singleValue\",\n" +
            "    {\n" +
            "      \"nestedList\": { \"innerKey1\": [ \"innerValue1\", \"innerValue2\" ] },\n" +
            "      \"nestedValue1\": \"value1\",\n" +
            "      \"nestedValue2\": \"value2\"\n" +
            "    }\n" +
            "  ]\n" +
            "}");
}
 
Example 5
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 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: 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)));
}