Search in sources :

Example 26 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.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 27 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.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 28 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project kie-wb-common by kiegroup.

the class MavenUtils method resolveDependenciesFromMultimodulePrj.

public static List<Artifact> resolveDependenciesFromMultimodulePrj(List<String> pomsPaths) {
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Set<Artifact> deps = new HashSet<>();
    try {
        for (String pomx : pomsPaths) {
            Path pom = Paths.get(URI.create("default:///" + pomx));
            Model model = reader.read(new ByteArrayInputStream(Files.readAllBytes(pom)));
            if (model.getDependencyManagement() != null && model.getDependencyManagement().getDependencies() != null) {
                createArtifacts(model.getDependencyManagement().getDependencies(), deps);
            }
            if (model.getDependencies() != null) {
                createArtifacts(model.getDependencies(), deps);
            }
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        return Collections.emptyList();
    }
    return new ArrayList<>(deps);
}
Also used : Path(org.uberfire.java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.apache.maven.model.Model) ArrayList(java.util.ArrayList) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet)

Example 29 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project acs-community-packaging by Alfresco.

the class CheckDistributionZipContents method getPomValues.

private Model getPomValues() throws Exception {
    String parentPom = Paths.get("").toAbsolutePath().getParent().getParent().toString() + "/pom.xml";
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader(parentPom));
    return model;
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader)

Example 30 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.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)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