Search in sources :

Example 61 with MavenXpp3Reader

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

the class MorphiaVersionTest method testVersion.

@Test
public void testVersion() throws Exception {
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader("../pom.xml"));
    Version version = Version.valueOf(model.getVersion());
    String minorVersion = format("%s%s", version.getMajorVersion(), version.getMinorVersion());
    // noinspection MisorderedAssertEqualsArguments
    assertEquals(MorphiaVersion23.class.getSimpleName().replaceAll("\\D", ""), minorVersion);
}
Also used : Version(com.github.zafarkhaja.semver.Version) Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) Test(org.testng.annotations.Test)

Example 62 with MavenXpp3Reader

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

the class AnalyzeDuplicateMojo method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping plugin execution");
        return;
    }
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    Model model = null;
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(project.getFile());
        model = pomReader.read(reader);
        reader.close();
        reader = null;
    } catch (Exception e) {
        throw new MojoExecutionException("IOException: " + e.getMessage(), e);
    } finally {
        IOUtil.close(reader);
    }
    Set<String> duplicateDependencies = Collections.emptySet();
    if (model.getDependencies() != null) {
        duplicateDependencies = findDuplicateDependencies(model.getDependencies());
    }
    Set<String> duplicateDependenciesManagement = Collections.emptySet();
    if (model.getDependencyManagement() != null && model.getDependencyManagement().getDependencies() != null) {
        duplicateDependenciesManagement = findDuplicateDependencies(model.getDependencyManagement().getDependencies());
    }
    if (getLog().isInfoEnabled()) {
        StringBuilder sb = new StringBuilder();
        if (!duplicateDependencies.isEmpty()) {
            sb.append("List of duplicate dependencies defined in <dependencies/> in your pom.xml:\n");
            for (Iterator<String> it = duplicateDependencies.iterator(); it.hasNext(); ) {
                String dup = it.next();
                sb.append("\to ").append(dup);
                if (it.hasNext()) {
                    sb.append("\n");
                }
            }
        }
        if (!duplicateDependenciesManagement.isEmpty()) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append("List of duplicate dependencies defined in <dependencyManagement/> in your pom.xml:\n");
            for (Iterator<String> it = duplicateDependenciesManagement.iterator(); it.hasNext(); ) {
                String dup = it.next();
                sb.append("\to ").append(dup);
                if (it.hasNext()) {
                    sb.append("\n");
                }
            }
        }
        if (sb.length() > 0) {
            getLog().info(sb.toString());
        } else {
            getLog().info("No duplicate dependencies found in <dependencies/> or in <dependencyManagement/>");
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) 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) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 63 with MavenXpp3Reader

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

the class PomUtils method loadPom.

/**
 * Loads the (raw) model from the specified POM file.
 *
 * @param pomFile The path to the POM file to load, must not be <code>null</code>.
 * @return The raw model, never <code>null</code>.
 * @throws MojoExecutionException If the POM file could not be loaded.
 */
public static Model loadPom(File pomFile) throws MojoExecutionException {
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(pomFile);
        final Model model = new MavenXpp3Reader().read(reader, false);
        reader.close();
        reader = null;
        return model;
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Failed to parse POM: " + pomFile, e);
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to read POM: " + pomFile, e);
    } finally {
        IOUtil.close(reader);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) 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) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 64 with MavenXpp3Reader

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

the class Project001Stub method readModelFromFile.

static Model readModelFromFile(File file) throws IOException, XmlPullParserException {
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    XmlStreamReader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(file);
        final Model model = pomReader.read(reader);
        reader.close();
        reader = null;
        return model;
    } finally {
        IOUtil.close(reader);
    }
}
Also used : Model(org.apache.maven.model.Model) XmlStreamReader(org.codehaus.plexus.util.xml.XmlStreamReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader)

Example 65 with MavenXpp3Reader

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

the class SignAndDeployFileMojo 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.
 */
private 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)

Aggregations

MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)65 Model (org.apache.maven.model.Model)59 IOException (java.io.IOException)39 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)33 FileReader (java.io.FileReader)27 File (java.io.File)18 FileNotFoundException (java.io.FileNotFoundException)17 Reader (java.io.Reader)15 Path (java.nio.file.Path)11 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 ArrayList (java.util.ArrayList)5 JarFile (java.util.jar.JarFile)5