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);
}
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
}
}
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;
}
Aggregations