Search in sources :

Example 41 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project BIMserver by opensourceBIM.

the class PluginManager method extractPluginBundleVersionFromJar.

public SPluginBundleVersion extractPluginBundleVersionFromJar(Path jarFilePath, boolean isLocal) throws PluginException {
    String filename = jarFilePath.getFileName().toString();
    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename);
    PluginBundleIdentifier pluginBundleIdentifier = pluginBundleVersionIdentifier.getPluginBundleIdentifier();
    try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
        ZipEntry pomEntry = jarFile.getEntry("META-INF/maven/" + pluginBundleIdentifier.getGroupId() + "/" + pluginBundleIdentifier.getArtifactId() + "/" + "pom.xml");
        if (pomEntry == null) {
            throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString());
        }
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = mavenreader.read(jarFile.getInputStream(pomEntry));
        SPluginBundleVersion sPluginBundleVersion = createPluginBundleVersionFromMavenModel(model, isLocal);
        return sPluginBundleVersion;
    } catch (IOException e) {
        throw new PluginException(e);
    } catch (XmlPullParserException e) {
        throw new PluginException(e);
    }
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) ZipEntry(java.util.zip.ZipEntry) PluginException(org.bimserver.shared.exceptions.PluginException) Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile)

Example 42 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project pom-manipulation-ext by release-engineering.

the class PomIO method readModelsForManipulation.

/**
 * Read {@link Model} instances by parsing the POM directly. This is useful to escape some post-processing that happens when the
 * {@link MavenProject#getOriginalModel()} instance is set.
 *
 * @param executionRoot the top level pom file.
 * @param peeked a collection of poms resolved from the top level file.
 * @return a collection of Projects
 * @throws ManipulationException if an error occurs.
 */
private List<Project> readModelsForManipulation(File executionRoot, final List<PomPeek> peeked) throws ManipulationException {
    final List<Project> projects = new ArrayList<>();
    final HashMap<Project, ProjectVersionRef> projectToParent = new HashMap<>();
    for (final PomPeek peek : peeked) {
        final File pom = peek.getPom();
        // Sucks, but we have to brute-force reading in the raw model.
        // The effective-model building, below, has a tantalizing getRawModel()
        // method on the result, BUT this seems to return models that have
        // the plugin versions set inside profiles...so they're not entirely
        // raw.
        Model raw = null;
        InputStream in = null;
        try {
            in = new FileInputStream(pom);
            raw = new MavenXpp3Reader().read(in);
        } catch (final IOException | XmlPullParserException e) {
            throw new ManipulationException("Failed to build model for POM: %s.\n--> %s", e, pom, e.getMessage());
        } finally {
            closeQuietly(in);
        }
        if (raw == null) {
            continue;
        }
        final Project project = new Project(pom, raw);
        projectToParent.put(project, peek.getParentKey());
        project.setInheritanceRoot(peek.isInheritanceRoot());
        if (executionRoot.equals(pom)) {
            logger.debug("Setting execution root to {} with file {}" + (project.isInheritanceRoot() ? " and is the inheritance root. " : ""), project, pom);
            project.setExecutionRoot();
            try {
                if (FileUtils.readFileToString(pom).contains(MODIFIED_BY)) {
                    project.setIncrementalPME(true);
                }
            } catch (final IOException e) {
                throw new ManipulationException("Failed to read POM: %s", e, pom);
            }
        }
        projects.add(project);
    }
    // Fill out inheritance info for every project we have created.
    for (Project p : projects) {
        ProjectVersionRef pvr = projectToParent.get(p);
        p.setProjectParent(getParent(projects, pvr));
    }
    return projects;
}
Also used : HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) MavenProject(org.apache.maven.project.MavenProject) Project(org.commonjava.maven.ext.common.model.Project) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) Model(org.apache.maven.model.Model) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) File(java.io.File)

Example 43 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project pom-manipulation-ext by release-engineering.

the class ModelIO method resolveRawModel.

/**
 * Read the raw model (equivalent to the pom file on disk) from a given GAV.
 *
 * @param ref the ProjectVersion to read.
 * @return the Maven Model for the GAV
 * @throws ManipulationException if an error occurs.
 */
public Model resolveRawModel(final ProjectVersionRef ref) throws ManipulationException {
    Transfer transfer;
    try {
        transfer = galleyWrapper.resolveArtifact(ref.asPomArtifact());
    } catch (final TransferException e) {
        throw new ManipulationException("Failed to resolve POM: %s.\n--> %s", e, ref, e.getMessage());
    }
    if (transfer == null) {
        throw new ManipulationException("Failed to resolve POM: " + ref.asPomArtifact());
    }
    InputStream in = null;
    try {
        in = transfer.openInputStream();
        return new MavenXpp3Reader().read(in);
    } catch (final IOException | XmlPullParserException e) {
        throw new ManipulationException("Failed to build model for POM: %s.\n--> %s", e, ref, e.getMessage());
    } finally {
        closeQuietly(in);
    }
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) InputStream(java.io.InputStream) Transfer(org.commonjava.maven.galley.model.Transfer) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 44 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project fabric8 by jboss-fuse.

the class AetherResolutionSupport method getOrCreateMetadata.

private Metadata getOrCreateMetadata(File repository, String groupId, String artifactId, String version, String repoId) throws IOException {
    File metadata;
    if (version == null) {
        metadata = new File(repository, String.format("%s/%s/maven-metadata%s.xml", groupId.replaceAll("\\.", "/"), artifactId, repoId == null ? "" : "-" + repoId));
    } else {
        metadata = new File(repository, String.format("%s/%s/%s/maven-metadata%s.xml", groupId.replaceAll("\\.", "/"), artifactId, version, repoId == null ? "" : "-" + repoId));
    }
    Metadata md;
    if (metadata.isFile()) {
        try {
            md = new MetadataXpp3Reader().read(new FileReader(metadata));
        } catch (XmlPullParserException e) {
            throw new IOException(e.getMessage(), e);
        }
    } else {
        md = new Metadata();
        md.setGroupId(groupId);
        md.setArtifactId(artifactId);
        if (version != null) {
            md.setVersion(version);
        }
        md.setVersioning(new Versioning());
    }
    return md;
}
Also used : Versioning(org.apache.maven.artifact.repository.metadata.Versioning) MetadataXpp3Reader(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

Example 45 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project fabric8 by jboss-fuse.

the class PomDetails method getModel.

public Model getModel() throws IOException {
    try {
        Model model = new MavenXpp3Reader().read(new FileInputStream(file));
        model.setGroupId(properties.getProperty("groupId", model.getGroupId()));
        model.setArtifactId(properties.getProperty("artifactId", model.getArtifactId()));
        model.setVersion(properties.getProperty("version", model.getVersion()));
        return model;
    } catch (XmlPullParserException e) {
        throw new IOException("Error parsing maven pom " + file, e);
    }
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)79 IOException (java.io.IOException)73 File (java.io.File)37 Model (org.apache.maven.model.Model)32 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)30 FileNotFoundException (java.io.FileNotFoundException)20 Reader (java.io.Reader)20 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)19 FileReader (java.io.FileReader)15 FileInputStream (java.io.FileInputStream)12 ArrayList (java.util.ArrayList)12 InputStream (java.io.InputStream)11 StringReader (java.io.StringReader)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)10 Path (java.nio.file.Path)7 Artifact (org.eclipse.aether.artifact.Artifact)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)7 PluginException (org.bimserver.shared.exceptions.PluginException)6 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)6 HashMap (java.util.HashMap)5