Search in sources :

Example 41 with MavenXpp3Reader

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

the class Maven2RepositoryStorage method applyServerSideRelocation.

@Override
public void applyServerSideRelocation(ManagedRepositoryContent managedRepository, ArtifactReference artifact) throws ProxyDownloadException {
    if ("pom".equals(artifact.getType())) {
        return;
    }
    // Build the artifact POM reference
    ArtifactReference pomReference = new ArtifactReference();
    pomReference.setGroupId(artifact.getGroupId());
    pomReference.setArtifactId(artifact.getArtifactId());
    pomReference.setVersion(artifact.getVersion());
    pomReference.setType("pom");
    RepositoryProxyConnectors connectors = applicationContext.getBean("repositoryProxyConnectors#default", RepositoryProxyConnectors.class);
    // Get the artifact POM from proxied repositories if needed
    connectors.fetchFromProxies(managedRepository, pomReference);
    // Open and read the POM from the managed repo
    Path pom = managedRepository.toFile(pomReference);
    if (!Files.exists(pom)) {
        return;
    }
    try {
        // MavenXpp3Reader leaves the file open, so we need to close it ourselves.
        Model model = null;
        try (Reader reader = Files.newBufferedReader(pom, Charset.defaultCharset())) {
            model = MAVEN_XPP_3_READER.read(reader);
        }
        DistributionManagement dist = model.getDistributionManagement();
        if (dist != null) {
            Relocation relocation = dist.getRelocation();
            if (relocation != null) {
                // artifact is relocated : update the repositoryPath
                if (relocation.getGroupId() != null) {
                    artifact.setGroupId(relocation.getGroupId());
                }
                if (relocation.getArtifactId() != null) {
                    artifact.setArtifactId(relocation.getArtifactId());
                }
                if (relocation.getVersion() != null) {
                    artifact.setVersion(relocation.getVersion());
                }
            }
        }
    } catch (IOException e) {
    // Unable to read POM : ignore.
    } catch (XmlPullParserException e) {
    // Invalid POM : ignore
    }
}
Also used : Path(java.nio.file.Path) Model(org.apache.maven.model.Model) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenMetadataReader(org.apache.archiva.maven2.metadata.MavenMetadataReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) RepositoryProxyConnectors(org.apache.archiva.proxy.model.RepositoryProxyConnectors) IOException(java.io.IOException) DistributionManagement(org.apache.maven.model.DistributionManagement) ArtifactReference(org.apache.archiva.model.ArtifactReference) Relocation(org.apache.maven.model.Relocation)

Example 42 with MavenXpp3Reader

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

the class PomInformation method parsePom.

public void parsePom(InputStream inputStream) {
    try {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        Model model = reader.read(inputStream);
        if (dependencies == null) {
            dependencies = new LinkedList<>();
        }
        if (repositories == null) {
            repositories = new LinkedList<>();
        }
        parent = model.getParent();
        setPropertiesFromModel(this, model);
        for (org.apache.maven.model.Dependency dependency : model.getDependencies()) {
            if (!"test".equalsIgnoreCase(dependency.getScope())) {
                dependencies.add(new Dependency(new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), "jar", dependency.getVersion()), JavaScopes.RUNTIME));
            }
        }
        for (Repository remoteRepository : model.getRepositories()) {
            repositories.add(new RemoteRepository(remoteRepository.getId(), "default", remoteRepository.getUrl()));
        }
    } catch (Exception ex) {
        LOGGER.error("Error while reading POM file", ex);
    }
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Repository(org.apache.maven.model.Repository) Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) IOException(java.io.IOException)

Example 43 with MavenXpp3Reader

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

the class PomInformation method parseParentPom.

public void parseParentPom(InputStream inputStream) {
    try {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        Model model = reader.read(inputStream);
        PomInformation parentPom = new PomInformation();
        setPropertiesFromModel(parentPom, model);
        parentPom.setParent(model.getParent());
        this.parentPomInformation = parentPom;
    } catch (Exception ex) {
        LOGGER.error("Error while reading parent POM file", ex);
    }
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException)

Example 44 with MavenXpp3Reader

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

the class HelperFunctions method loadRobotLibraryVersion.

public static String loadRobotLibraryVersion() {
    try {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        Model model = reader.read(new FileReader("pom.xml"));
        return model.getVersion();
    } catch (Exception e) {
        return "unknown";
    }
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) TimeoutException(java.util.concurrent.TimeoutException) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException)

Example 45 with MavenXpp3Reader

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

the class PomTransformer method loadNextProperties.

// The nextPomToLoad point to the next pom hierarchy
// load the next pom in chain and his properties
private boolean loadNextProperties() {
    if (nextPomToLoad == null) {
        return false;
    }
    Model model;
    FileReader reader = null;
    MavenXpp3Reader mavenReader = new MavenXpp3Reader();
    try {
        reader = new FileReader(nextPomToLoad);
        model = mavenReader.read(reader);
        Properties properties = model.getProperties();
        for (String key : properties.stringPropertyNames()) {
            if (pomProperties.get(key) == null) {
                pomProperties.put(key, properties.getProperty(key));
            }
        }
        if (model.getParent() != null) {
            nextPomToLoad = StringUtils.substringBeforeLast(nextPomToLoad, java.io.File.separator) + java.io.File.separator + model.getParent().getRelativePath();
        } else {
            nextPomToLoad = null;
        }
    } catch (Exception e) {
        Logger.getLogger(PomTransformer.class.getName()).info("couldn't load pom file at: " + nextPomToLoad);
        return false;
    } finally {
        IOUtils.closeQuietly(reader);
    }
    return true;
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) Properties(java.util.Properties) JDOMException(org.jdom.JDOMException)

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