Search in sources :

Example 1 with Relocation

use of org.apache.maven.model.Relocation in project archiva by apache.

the class LegacyToDefaultConverter method writeRelocationPom.

private void writeRelocationPom(String groupId, String artifactId, String version, String newGroupId, String newArtifactId, String newVersion, String message, ArtifactRepository repository, FileTransaction transaction) throws IOException {
    Model pom = new Model();
    pom.setGroupId(groupId);
    pom.setArtifactId(artifactId);
    pom.setVersion(version);
    DistributionManagement dMngt = new DistributionManagement();
    Relocation relocation = new Relocation();
    relocation.setGroupId(newGroupId);
    relocation.setArtifactId(newArtifactId);
    relocation.setVersion(newVersion);
    if (message != null && message.length() > 0) {
        relocation.setMessage(message);
    }
    dMngt.setRelocation(relocation);
    pom.setDistributionManagement(dMngt);
    // $NON-NLS-1$
    Artifact artifact = artifactFactory.createBuildArtifact(groupId, artifactId, version, "pom");
    Path pomFile = Paths.get(repository.getBasedir(), repository.pathOf(artifact));
    StringWriter strWriter = new StringWriter();
    MavenXpp3Writer pomWriter = new MavenXpp3Writer();
    pomWriter.write(strWriter, pom);
    transaction.createFile(strWriter.toString(), pomFile, digesters);
}
Also used : Path(java.nio.file.Path) StringWriter(java.io.StringWriter) Model(org.apache.maven.model.Model) DistributionManagement(org.apache.maven.model.DistributionManagement) Relocation(org.apache.maven.model.Relocation) Artifact(org.apache.maven.artifact.Artifact) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Example 2 with Relocation

use of org.apache.maven.model.Relocation 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 3 with Relocation

use of org.apache.maven.model.Relocation in project gradle by gradle.

the class MavenPomFileGenerator method convertRelocation.

private Relocation convertRelocation(MavenPomRelocation source) {
    Relocation target = new Relocation();
    target.setGroupId(source.getGroupId().getOrNull());
    target.setArtifactId(source.getArtifactId().getOrNull());
    target.setVersion(source.getVersion().getOrNull());
    target.setMessage(source.getMessage().getOrNull());
    return target;
}
Also used : MavenPomRelocation(org.gradle.api.publish.maven.MavenPomRelocation) Relocation(org.apache.maven.model.Relocation)

Aggregations

Relocation (org.apache.maven.model.Relocation)3 Path (java.nio.file.Path)2 DistributionManagement (org.apache.maven.model.DistributionManagement)2 Model (org.apache.maven.model.Model)2 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1 MavenMetadataReader (org.apache.archiva.maven2.metadata.MavenMetadataReader)1 ArtifactReference (org.apache.archiva.model.ArtifactReference)1 RepositoryProxyConnectors (org.apache.archiva.proxy.model.RepositoryProxyConnectors)1 Artifact (org.apache.maven.artifact.Artifact)1 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)1 MavenXpp3Writer (org.apache.maven.model.io.xpp3.MavenXpp3Writer)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1 MavenPomRelocation (org.gradle.api.publish.maven.MavenPomRelocation)1