Search in sources :

Example 21 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project java-chassis by ServiceComb.

the class Deploys method initPomVersion.

private void initPomVersion() throws Throwable {
    // already set manually
    if (pomVersion != null) {
        return;
    }
    // already package to jar
    pomVersion = Deploys.class.getPackage().getImplementationVersion();
    if (pomVersion != null) {
        return;
    }
    // run in ide
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader("pom.xml"));
    pomVersion = model.getVersion();
    if (pomVersion != null) {
        return;
    }
    if (model.getParent() == null) {
        throw new IllegalStateException("can not find pom ServiceComb version");
    }
    pomVersion = model.getParent().getVersion();
    if (pomVersion != null) {
        return;
    }
    throw new IllegalStateException("can not find pom ServiceComb version");
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader)

Example 22 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-plugins by apache.

the class InstallFileMojoTest method testInstallFileWithGeneratePom.

public void testInstallFileWithGeneratePom() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/install-file-test-generatePom/plugin-config.xml");
    InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
    assertNotNull(mojo);
    setVariableValueToObject(mojo, "session", createMavenSession());
    assignValuesForParameter(mojo);
    mojo.execute();
    File installedArtifact = new File(getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "." + packaging);
    assertTrue((Boolean) getVariableValueFromObject(mojo, "generatePom"));
    assertTrue(installedArtifact.exists());
    File installedPom = new File(getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "." + "pom");
    Model model;
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(installedPom);
        model = new MavenXpp3Reader().read(reader);
        reader.close();
        reader = null;
    } finally {
        IOUtil.close(reader);
    }
    assertEquals("4.0.0", model.getModelVersion());
    assertEquals((String) getVariableValueFromObject(mojo, "groupId"), model.getGroupId());
    assertEquals(artifactId, model.getArtifactId());
    assertEquals(version, model.getVersion());
    assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
Also used : InstallFileMojo(org.apache.maven.plugins.install.InstallFileMojo) Model(org.apache.maven.model.Model) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) File(java.io.File)

Example 23 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-plugins by apache.

the class DeployFileMojo method readModel.

/**
 * Extract the model from the specified POM file.
 *
 * @param pomFile The path of the POM file to parse, must not be <code>null</code>.
 * @return The model from the POM file, never <code>null</code>.
 * @throws MojoExecutionException If the file doesn't exist of cannot be read.
 */
Model readModel(File pomFile) throws MojoExecutionException {
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(pomFile);
        final Model model = new MavenXpp3Reader().read(reader);
        reader.close();
        reader = null;
        return model;
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("POM not found " + pomFile, e);
    } catch (IOException e) {
        throw new MojoExecutionException("Error reading POM " + pomFile, e);
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Error parsing POM " + pomFile, e);
    } finally {
        IOUtil.close(reader);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 24 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-plugins by apache.

the class ProcessRemoteResourcesMojo method getSupplement.

protected Model getSupplement(Xpp3Dom supplementModelXml) throws MojoExecutionException {
    MavenXpp3Reader modelReader = new MavenXpp3Reader();
    Model model = null;
    try {
        model = modelReader.read(new StringReader(supplementModelXml.toString()));
        String groupId = model.getGroupId();
        String artifactId = model.getArtifactId();
        if (groupId == null || groupId.trim().equals("")) {
            throw new MojoExecutionException("Supplemental project XML " + "requires that a <groupId> element be present.");
        }
        if (artifactId == null || artifactId.trim().equals("")) {
            throw new MojoExecutionException("Supplemental project XML " + "requires that a <artifactId> element be present.");
        }
    } catch (IOException e) {
        getLog().warn("Unable to read supplemental XML: " + e.getMessage(), e);
    } catch (XmlPullParserException e) {
        getLog().warn("Unable to parse supplemental XML: " + e.getMessage(), e);
    }
    return model;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) StringReader(java.io.StringReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 25 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project camel by apache.

the class BomGeneratorMojo method loadExternalProjectPom.

private MavenProject loadExternalProjectPom(File pomFile) throws Exception {
    try (FileReader reader = new FileReader(pomFile)) {
        MavenXpp3Reader mavenReader = new MavenXpp3Reader();
        Model model = mavenReader.read(reader);
        MavenProject project = new MavenProject(model);
        project.setFile(pomFile);
        return project;
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) FileReader(java.io.FileReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader)

Aggregations

MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)55 Model (org.apache.maven.model.Model)50 IOException (java.io.IOException)35 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)30 FileReader (java.io.FileReader)23 File (java.io.File)15 Reader (java.io.Reader)15 FileNotFoundException (java.io.FileNotFoundException)14 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 Path (java.nio.file.Path)7 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)7 MavenXpp3Writer (org.apache.maven.model.io.xpp3.MavenXpp3Writer)6 PluginException (org.bimserver.shared.exceptions.PluginException)6 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)6 InputStream (java.io.InputStream)5 StringReader (java.io.StringReader)5 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)5 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)5 FileInputStream (java.io.FileInputStream)4 DelegatingClassLoader (org.bimserver.plugins.classloaders.DelegatingClassLoader)4