Search in sources :

Example 46 with Xpp3Dom

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

the class ComponentsXmlArchiverFileFilterTest method testAddComponentsXml_ShouldAddComponentWithoutRoleHint.

public void testAddComponentsXml_ShouldAddComponentWithoutRoleHint() throws IOException, XmlPullParserException {
    final Reader reader = writeComponentsXml(Collections.singletonList(new ComponentDef("role", null, "org.apache.maven.Impl")));
    filter.addComponentsXml(reader);
    assertFalse(filter.components.isEmpty());
    final Xpp3Dom componentDom = filter.components.get("role");
    assertEquals("role", componentDom.getChild("role").getValue());
    assertNull(componentDom.getChild("role-hint"));
    assertEquals("org.apache.maven.Impl", componentDom.getChild("implementation").getValue());
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Reader(java.io.Reader) StringReader(java.io.StringReader)

Example 47 with Xpp3Dom

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

the class ComponentsXmlArchiverFileFilterTest method createComponentDom.

private Xpp3Dom createComponentDom(final ComponentDef def) {
    final Xpp3Dom dom = new Xpp3Dom("component");
    final Xpp3Dom role = new Xpp3Dom("role");
    role.setValue(def.role);
    dom.addChild(role);
    final String hint = def.roleHint;
    if (hint != null) {
        final Xpp3Dom roleHint = new Xpp3Dom("role-hint");
        roleHint.setValue(hint);
        dom.addChild(roleHint);
    }
    final Xpp3Dom impl = new Xpp3Dom("implementation");
    impl.setValue(def.implementation);
    dom.addChild(impl);
    return dom;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom)

Example 48 with Xpp3Dom

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

the class MetadataUtils method createMetadata.

/**
 * Creates local metadata files for the specified artifact. The goal is to simulate the installation of the artifact
 * by a local build, thereby decoupling the forked builds from the inderministic collection of remote repositories
 * that are available to the main build and from which the artifact was originally resolved.
 *
 * @param file The artifact's file in the local test repository, must not be <code>null</code>.
 * @param artifact The artifact to create metadata for, must not be <code>null</code>.
 * @throws IOException If the metadata could not be created.
 */
public static void createMetadata(File file, Artifact artifact) throws IOException {
    TimeZone tz = java.util.TimeZone.getTimeZone("UTC");
    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss");
    fmt.setTimeZone(tz);
    String timestamp = fmt.format(new Date());
    if (artifact.isSnapshot()) {
        File metadataFile = new File(file.getParentFile(), "maven-metadata-local.xml");
        Xpp3Dom metadata = new Xpp3Dom("metadata");
        addChild(metadata, "groupId", artifact.getGroupId());
        addChild(metadata, "artifactId", artifact.getArtifactId());
        addChild(metadata, "version", artifact.getBaseVersion());
        Xpp3Dom versioning = new Xpp3Dom("versioning");
        versioning.addChild(addChild(new Xpp3Dom("snapshot"), "localCopy", "true"));
        addChild(versioning, "lastUpdated", timestamp);
        metadata.addChild(versioning);
        writeMetadata(metadataFile, metadata);
    }
    File metadataFile = new File(file.getParentFile().getParentFile(), "maven-metadata-local.xml");
    Set<String> allVersions = new LinkedHashSet<String>();
    Xpp3Dom metadata = readMetadata(metadataFile);
    if (metadata != null) {
        Xpp3Dom versioning = metadata.getChild("versioning");
        if (versioning != null) {
            Xpp3Dom versions = versioning.getChild("versions");
            if (versions != null) {
                Xpp3Dom[] children = versions.getChildren("version");
                for (Xpp3Dom aChildren : children) {
                    allVersions.add(aChildren.getValue());
                }
            }
        }
    }
    allVersions.add(artifact.getBaseVersion());
    metadata = new Xpp3Dom("metadata");
    addChild(metadata, "groupId", artifact.getGroupId());
    addChild(metadata, "artifactId", artifact.getArtifactId());
    Xpp3Dom versioning = new Xpp3Dom("versioning");
    versioning.addChild(addChildren(new Xpp3Dom("versions"), "version", allVersions));
    addChild(versioning, "lastUpdated", timestamp);
    metadata.addChild(versioning);
    metadata = Xpp3DomUtils.mergeXpp3Dom(metadata, readMetadata(metadataFile));
    writeMetadata(metadataFile, metadata);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TimeZone(java.util.TimeZone) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date)

Example 49 with Xpp3Dom

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

the class MetadataUtils method readMetadata.

private static Xpp3Dom readMetadata(File metadataFile) throws IOException {
    if (!metadataFile.isFile()) {
        return null;
    }
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(metadataFile);
        final Xpp3Dom xpp3Dom = Xpp3DomBuilder.build(reader);
        reader.close();
        reader = null;
        return xpp3Dom;
    } catch (XmlPullParserException e) {
        throw (IOException) new IOException(e.getMessage()).initCause(e);
    } finally {
        IOUtil.close(reader);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Reader(java.io.Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 50 with Xpp3Dom

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

the class MetadataUtils method addChild.

private static Xpp3Dom addChild(Xpp3Dom parent, String childName, String childValue) {
    Xpp3Dom child = new Xpp3Dom(childName);
    child.setValue(childValue);
    parent.addChild(child);
    return parent;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom)

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