Search in sources :

Example 1 with XmlToJson

use of org.revapi.configuration.XmlToJson 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)

Aggregations

PlexusConfiguration (org.codehaus.plexus.configuration.PlexusConfiguration)1 XmlPlexusConfiguration (org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration)1 XmlToJson (org.revapi.configuration.XmlToJson)1