Search in sources :

Example 51 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project maven-plugins by apache.

the class IntegrationTestUtils method initPluginInfo.

private static void initPluginInfo() throws IOException {
    URL resource = Thread.currentThread().getContextClassLoader().getResource("META-INF/maven/plugin.xml");
    Reader reader = null;
    try {
        reader = new InputStreamReader(resource.openStream());
        Xpp3Dom pluginDom;
        pluginDom = Xpp3DomBuilder.build(reader);
        reader.close();
        reader = null;
        pluginArtifactId = pluginDom.getChild("artifactId").getValue();
        pluginGroupId = pluginDom.getChild("groupId").getValue();
        pluginVersion = pluginDom.getChild("version").getValue();
        cliPluginPrefix = pluginGroupId + ":" + pluginArtifactId + ":" + pluginVersion + ":";
    } catch (XmlPullParserException e) {
        throw (IOException) new IOException("Failed to parse plugin descriptor for groupId:artifactId:version prefix.").initCause(e);
    } finally {
        close(reader);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) URL(java.net.URL)

Example 52 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project maven-plugins by apache.

the class PluginXmlResourceTransformer method processResource.

public void processResource(String resource, InputStream is, List<Relocator> relocators) throws IOException {
    Xpp3Dom newDom;
    try {
        BufferedInputStream bis = new BufferedInputStream(is) {

            public void close() throws IOException {
            // leave ZIP open
            }
        };
        Reader reader = ReaderFactory.newXmlReader(bis);
        newDom = Xpp3DomBuilder.build(reader);
    } catch (Exception e) {
        throw (IOException) new IOException("Error parsing plugin.xml in " + is).initCause(e);
    }
    // Only try to merge in mojos if there are some elements in the plugin
    if (newDom.getChild("mojos") == null) {
        return;
    }
    for (Xpp3Dom mojo : newDom.getChild("mojos").getChildren("mojo")) {
        String impl = getValue(mojo, "implementation");
        impl = getRelocatedClass(impl, relocators);
        setValue(mojo, "implementation", impl);
        Xpp3Dom parameters = mojo.getChild("parameters");
        if (parameters != null) {
            for (Xpp3Dom parameter : parameters.getChildren()) {
                String type = getValue(parameter, "type");
                type = getRelocatedClass(type, relocators);
                setValue(parameter, "type", type);
            }
        }
        Xpp3Dom configuration = mojo.getChild("configuration");
        if (configuration != null) {
            for (Xpp3Dom configurationEntry : configuration.getChildren()) {
                String implementation = getAttribute(configurationEntry, "implementation");
                implementation = getRelocatedClass(implementation, relocators);
                setAttribute(configurationEntry, "implementation", implementation);
            }
        }
        Xpp3Dom requirements = mojo.getChild("requirements");
        if (requirements != null && requirements.getChildCount() > 0) {
            for (Xpp3Dom requirement : requirements.getChildren()) {
                String requiredRole = getValue(requirement, "role");
                requiredRole = getRelocatedClass(requiredRole, relocators);
                setValue(requirement, "role", requiredRole);
            }
        }
        mojos.add(mojo);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) BufferedInputStream(java.io.BufferedInputStream) Reader(java.io.Reader) IOException(java.io.IOException) IOException(java.io.IOException)

Example 53 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project maven-plugins by apache.

the class PluginXmlResourceTransformer method setValue.

private static void setValue(Xpp3Dom dom, String element, String value) {
    Xpp3Dom child = dom.getChild(element);
    if (child == null || value == null || value.length() <= 0) {
        return;
    }
    child.setValue(value);
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom)

Example 54 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project maven-plugins by apache.

the class ComponentsXmlArchiverFileFilter method addComponentsXml.

void addComponentsXml(final Reader componentsReader) throws XmlPullParserException, IOException {
    Xpp3Dom newDom = Xpp3DomBuilder.build(componentsReader);
    if (newDom != null) {
        newDom = newDom.getChild("components");
    }
    if (newDom != null) {
        final Xpp3Dom[] children = newDom.getChildren();
        for (final Xpp3Dom component : children) {
            if (components == null) {
                components = new LinkedHashMap<String, Xpp3Dom>();
            }
            final String role = component.getChild("role").getValue();
            final Xpp3Dom child = component.getChild("role-hint");
            final String roleHint = child != null ? child.getValue() : "";
            final String key = role + roleHint;
            if (!components.containsKey(key)) {
                components.put(key, component);
            }
        }
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom)

Example 55 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project bndtools by bndtools.

the class MavenWorkspaceRepository method getBundleFile.

private File getBundleFile(final MavenProject mavenProject) {
    String finalName = null;
    // first check maven-jar-plugin config first, if it is empty use project.build.finalName
    Plugin jarPlugin = mavenProject.getPlugin("org.apache.maven.plugins:maven-jar-plugin");
    if (jarPlugin != null) {
        Object config = jarPlugin.getConfiguration();
        if (config instanceof Xpp3Dom) {
            Xpp3Dom dom = (Xpp3Dom) config;
            Xpp3Dom finalNameNode = dom.getChild("finalName");
            if (finalNameNode != null) {
                finalName = finalNameNode.getValue();
            }
        }
    }
    if (finalName == null) {
        finalName = mavenProject.getBuild().getFinalName();
    }
    return new File(mavenProject.getBuild().getDirectory(), finalName + ".jar");
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) File(java.io.File) Plugin(org.apache.maven.model.Plugin)

Aggregations

Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)156 Plugin (org.apache.maven.model.Plugin)39 File (java.io.File)26 ArrayList (java.util.ArrayList)18 PluginExecution (org.apache.maven.model.PluginExecution)18 IOException (java.io.IOException)13 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 MavenSession (org.apache.maven.execution.MavenSession)10 MavenProject (org.apache.maven.project.MavenProject)10 Model (org.apache.maven.model.Model)9 Reader (java.io.Reader)8 Build (org.apache.maven.model.Build)8 TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)8 BuildFailureException (org.eclipse.tycho.core.shared.BuildFailureException)8 MojoExecution (org.apache.maven.plugin.MojoExecution)7 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)7 Map (java.util.Map)6 Dependency (org.apache.maven.model.Dependency)6 StringReader (java.io.StringReader)5