Search in sources :

Example 6 with XmlPlexusConfiguration

use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.

the class SchemaDrivenJSONToXmlConverter method convertSimple.

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;
}
Also used : XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)

Example 7 with XmlPlexusConfiguration

use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.

the class SchemaDrivenJSONToXmlConverter method convertObject.

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;
}
Also used : XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) ModelNode(org.jboss.dmr.ModelNode)

Example 8 with XmlPlexusConfiguration

use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.

the class SchemaDrivenJSONToXmlConverter method convertNewStyleConfigToXml.

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;
}
Also used : XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) ModelNode(org.jboss.dmr.ModelNode)

Example 9 with XmlPlexusConfiguration

use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.

the class Analyzer method mergeXmlConfigFile.

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));
        }
    }
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) XmlToJson(org.revapi.configuration.XmlToJson) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)

Example 10 with XmlPlexusConfiguration

use of org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration in project revapi by revapi.

the class XmlUtilTest method testPrettyPrintingXml.

@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);
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) Test(org.junit.Test)

Aggregations

XmlPlexusConfiguration (org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)23 PlexusConfiguration (org.codehaus.plexus.configuration.PlexusConfiguration)11 EarPluginException (org.apache.maven.plugins.ear.EarPluginException)6 ArtifactTypeMappingService (org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)6 PlexusConfigurationException (org.codehaus.plexus.configuration.PlexusConfigurationException)6 PluginParameterExpressionEvaluator (org.apache.maven.plugin.PluginParameterExpressionEvaluator)4 ExpressionEvaluator (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 ComponentConfigurationException (org.codehaus.plexus.component.configurator.ComponentConfigurationException)3 ComponentConfigurator (org.codehaus.plexus.component.configurator.ComponentConfigurator)3 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)3 ModelNode (org.jboss.dmr.ModelNode)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)2 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1