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

The following examples show how to use org.codehaus.plexus.configuration.PlexusConfiguration#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: OptionallyConfigurableComponentConverter.java    From jdmn with Apache License 2.0 6 votes vote down vote up
private OptionallyConfigurableMojoComponent configureCompoundComponent(OptionallyConfigurableMojoComponent component,
                                                                       PlexusConfiguration configuration) throws ComponentConfigurationException {

    PlexusConfiguration name = configuration.getChild(OptionallyConfigurableMojoComponent.ELEMENT_NAME, false);
    if (name == null || name.getValue() == null) {
        throw new ComponentConfigurationException(String.format(
                "Cannot configure component; \"%s\" property must be provided", OptionallyConfigurableMojoComponent.ELEMENT_NAME));
    }

    component.setName(name.getValue());

    PlexusConfiguration config = configuration.getChild(OptionallyConfigurableMojoComponent.ELEMENT_CONFIGURATION, false);
    if (config != null) {
        component.setConfiguration(generateConfigurationMap(config));
    }

    return component;
}
 
Example 2
Source File: AntXmlPlexusConfigurationWriter.java    From was-maven-plugin with Apache License 2.0 6 votes vote down vote up
private void write(PlexusConfiguration c, XMLWriter w, int depth) throws IOException {
  int count = c.getChildCount();

  if (count == 0) {
    writeTag(c, w, depth);
  } else {
    w.startElement(c.getName());
    writeAttributes(c, w);

    for (int i = 0; i < count; i++) {
      PlexusConfiguration child = c.getChild(i);

      write(child, w, depth + 1);
    }

    w.endElement();
  }
}
 
Example 3
Source File: SchemaDrivenJSONToXmlConverterTest.java    From revapi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedSchemasConverted() throws Exception {
    ModelNode topSchema = json("{\"type\": \"object\", \"properties\": {\"a\": {\"type\": \"string\"}}}");
    ModelNode nestedSchema = json("{\"type\": \"boolean\"}");

    Map<String, ModelNode> extensionSchemas = new HashMap<>();
    extensionSchemas.put("top", topSchema);
    extensionSchemas.put("top.nested", nestedSchema);

    ModelNode config = json("{\"top\": {\"a\": \"kachny\", \"nested\": true}}");

    PlexusConfiguration xml = SchemaDrivenJSONToXmlConverter.convertToXml(extensionSchemas, config);
    assertEquals(2, xml.getChildCount());

    PlexusConfiguration topXml = xml.getChild("top");
    assertNotNull(topXml);
    assertEquals("top", topXml.getName());
    assertEquals(1, topXml.getChildCount());
    assertEquals("a", topXml.getChild(0).getName());
    assertEquals("kachny", topXml.getChild("a").getValue());

    PlexusConfiguration nested = xml.getChild("top.nested");
    assertNotNull(nested);
    assertEquals(0, nested.getChildCount());
    assertEquals("true", nested.getValue());
}
 
Example 4
Source File: Analyzer.java    From revapi with Apache License 2.0 5 votes vote down vote up
private void parseIncludeExclude(PlexusConfiguration parent, Consumer<String> handleInclude,
        Consumer<String> handleExclude) {

    PlexusConfiguration include = parent.getChild("include");
    PlexusConfiguration exclude = parent.getChild("exclude");

    if (include != null) {
        Stream.of(include.getChildren()).forEach(c -> handleInclude.accept(c.getValue()));
    }

    if (exclude != null) {
        Stream.of(exclude.getChildren()).forEach(c -> handleExclude.accept(c.getValue()));
    }
}
 
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));
        }
    }
}