Search in sources :

Example 56 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project build-info by JFrogDev.

the class ProjectReader method readModel.

/**
 * @return Construct a Maven {@link Model} from the pom.
 */
private Model readModel(File pom) throws IOException {
    MavenXpp3Reader reader = new MavenXpp3Reader();
    StringReader stringReader = null;
    try {
        stringReader = new StringReader(Files.toString(pom, Charset.forName("UTF-8")));
        return reader.read(stringReader);
    } catch (XmlPullParserException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(stringReader);
    }
}
Also used : 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 57 with MavenXpp3Reader

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

the class TychoVersionsPluginCompatibilityTest method invokeVersionsPluginOnTycho0120Project.

/**
 * <p>
 * This test verifies that current and future versions of the tycho-versions-plugin can be
 * executed on a project that is built with Tycho 0.12.0. With this assertion it's possible to
 * call the plugin without version on the commandline:
 * </p>
 * <p>
 * <code>mvn org.eclipse.tycho:tycho-versions-plugin:set-version</code>
 * </p>
 * <p>
 * Background: The tycho-versions-plugin 0.12.0 can't handle projects that are built with Tycho
 * 0.11.0 or older, see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=363791">Bug
 * 363791</a>.
 * </p>
 */
@Test
public void invokeVersionsPluginOnTycho0120Project() throws Exception {
    String expectedNewVersion = "1.2.3";
    Verifier verifier = getVerifier("TychoVersionsPluginTest", true);
    verifier.getCliOptions().add("-DnewVersion=" + expectedNewVersion);
    verifier.executeGoal("org.eclipse.tycho:tycho-versions-plugin:" + TychoVersion.getTychoVersion() + ":set-version");
    verifier.verifyErrorFreeLog();
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    Model pomModel = pomReader.read(new FileReader(new File(verifier.getBasedir(), "pom.xml")));
    assertEquals("<version> in pom.xml has not been changed!", expectedNewVersion, pomModel.getVersion());
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) Verifier(org.apache.maven.it.Verifier) File(java.io.File) Test(org.junit.Test) AbstractTychoIntegrationTest(org.eclipse.tycho.test.AbstractTychoIntegrationTest)

Example 58 with MavenXpp3Reader

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

the class TestPlugin method before.

@Override
protected void before() throws IOException, XmlPullParserException, VerificationException {
    // Installs the plugin for use in tests.
    Verifier verifier = new Verifier(".", true);
    verifier.setAutoclean(false);
    verifier.addCliOption("-DskipTests");
    verifier.executeGoal("install");
    // Reads the project version.
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(Files.newBufferedReader(Paths.get("pom.xml"), StandardCharsets.UTF_8));
    pluginVersion = model.getVersion();
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) Verifier(org.apache.maven.it.Verifier)

Example 59 with MavenXpp3Reader

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

the class MavenModelFactory method createMavenProject.

/**
 * Creates a {@link Model} by reading the {@code pom.xml} file.
 *
 * @param pomFile to parse and read the model
 * @return {@link Model} representing the Maven project from pom file.
 */
public static Model createMavenProject(File pomFile) {
    MavenXpp3Reader mavenReader = new MavenXpp3Reader();
    if (pomFile != null && pomFile.exists()) {
        try (FileReader reader = new FileReader(pomFile)) {
            Model model = mavenReader.read(reader);
            model.setPomFile(pomFile);
            return model;
        } catch (Exception e) {
            throw new RuntimeException("Couldn't get Maven Artifact from pom: " + pomFile);
        }
    }
    throw new IllegalArgumentException("pom file doesn't exits for path: " + pomFile);
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader)

Example 60 with MavenXpp3Reader

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

the class AetherResolverImpl method findExtension.

private String findExtension(File pomFile) {
    if (pomFile != null && pomFile.exists()) {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        Model model;
        try (FileReader fileReader = new FileReader(pomFile)) {
            model = reader.read(fileReader);
            return model.getPackaging();
        } catch (XmlPullParserException | IOException e) {
            return null;
        }
    }
    ;
    return null;
}
Also used : Model(org.eclipse.ceylon.aether.apache.maven.model.Model) MavenXpp3Reader(org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) XmlPullParserException(org.eclipse.ceylon.aether.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Aggregations

MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)66 Model (org.apache.maven.model.Model)61 IOException (java.io.IOException)40 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)34 FileReader (java.io.FileReader)28 File (java.io.File)18 FileNotFoundException (java.io.FileNotFoundException)17 Reader (java.io.Reader)15 Path (java.nio.file.Path)12 PluginException (org.bimserver.shared.exceptions.PluginException)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)10 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)9 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)9 DelegatingClassLoader (org.bimserver.plugins.classloaders.DelegatingClassLoader)8 InputStream (java.io.InputStream)7 FileInputStream (java.io.FileInputStream)6 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)6 MavenXpp3Writer (org.apache.maven.model.io.xpp3.MavenXpp3Writer)6 StringReader (java.io.StringReader)5