use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.
the class MavenMetadataMergerTest method mergeWhenOneTransferIsInvalidXml.
@Test
public void mergeWhenOneTransferIsInvalidXml() throws Exception {
String path = "org/foo/bar/maven-metadata.xml";
HostedRepository h1 = new HostedRepository("test-hosted-1");
HostedRepository h2 = new HostedRepository("test-hosted-2");
Transfer t1 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h1), path));
initTestData(t1, VERSION_META + "simple-1.xml");
Transfer t2 = cacheProvider.getTransfer(new ConcreteResource(LocationUtils.toLocation(h2), path));
initTestData(t2, VERSION_META + "invalid.xml");
Group g = new Group("test-group", h1.getKey(), h2.getKey());
List<Transfer> sources = Arrays.asList(t1, t2);
byte[] output = new MavenMetadataMerger(Collections.emptyList()).merge(sources, g, path);
Metadata merged = new MetadataXpp3Reader().read(new ByteArrayInputStream(output));
assertThat(merged.getGroupId(), equalTo("org.foo"));
assertThat(merged.getArtifactId(), equalTo("bar"));
Versioning versioning = merged.getVersioning();
assertThat(versioning, notNullValue());
List<String> versions = versioning.getVersions();
assertThat(versions, notNullValue());
assertThat(versions.size(), equalTo(1));
assertThat(versioning.getRelease(), equalTo("1.0"));
assertThat(versioning.getLatest(), equalTo("1.0"));
int idx = 0;
assertThat(versions.get(idx), equalTo("1.0"));
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project bnd by bndtools.
the class RemotePostProcessor method postProcessRelease.
private ArtifactResult postProcessRelease(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
for (RemoteRepository repository : request.getRepositories()) {
if (!repository.getPolicy(false).isEnabled()) {
// Skip the repo if it isn't enabled for releases
continue;
}
// Remove the workspace from the session so that we don't use it
DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
newSession.setWorkspaceReader(null);
// Find the snapshot metadata for the module
MetadataRequest mr = new MetadataRequest().setRepository(repository).setMetadata(new DefaultMetadata(artifact.getGroupId(), artifact.getArtifactId(), null, "maven-metadata.xml", RELEASE));
for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
if (metadataResult.isResolved()) {
try {
Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
Versioning versioning = read.getVersioning();
if (versioning == null || versioning.getVersions() == null || versioning.getVersions().isEmpty()) {
continue;
} else if (versioning.getVersions().contains(artifact.getVersion())) {
ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(artifact).addRepository(repository));
if (result.isResolved()) {
File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForLocalArtifact(artifact));
if (!toUse.exists()) {
logger.warn("The resolved artifact {} does not exist at {}", artifact, toUse);
continue;
} else {
logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
}
result.getArtifact().setFile(toUse);
return result;
}
}
} catch (Exception e) {
throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
}
}
}
}
logger.debug("Unable to resolve a remote repository containing {}", artifact);
return null;
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project pom-manipulation-ext by release-engineering.
the class VersioningCalculatorTest method setupMetadataVersions.
private byte[] setupMetadataVersions(final String... versions) throws IOException {
final Metadata md = new Metadata();
final Versioning v = new Versioning();
md.setVersioning(v);
v.setVersions(Arrays.asList(versions));
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
new MetadataXpp3Writer().write(baos, md);
return baos.toByteArray();
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project fabric8 by jboss-fuse.
the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInTwoDefaultRepositories.
@Test
public void snapshotIsAvailableInTwoDefaultRepositories() throws IOException, InvalidMavenArtifactRequest {
File defaultRepository1 = initFileRepository("dr1");
File defaultRepository2 = initFileRepository("dr2");
MavenResolver resolver = new ResolverBuilder().withDefaultRepositories(Arrays.asList(defaultRepository1, defaultRepository2)).build();
MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
servlet.start();
mvnInstall(defaultRepository1, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
mvnInstall(defaultRepository2, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
Metadata metadata = readMetadata(file);
assertThat("Resolution done in first default repository, even if second one has newer artifact", metadata.getVersioning().getSnapshotVersions().get(0).getUpdated(), is("20170101100000"));
}
use of org.apache.maven.artifact.repository.metadata.Metadata in project fabric8 by jboss-fuse.
the class AetherResolutionSupport method mvnDeploy.
/**
* <p>Simulation of <code>mvn deploy</code> in remote (even if <code>file://</code>-based) repository</p>
* <p>Like <code>mvn clean deploy -DskipTests -Dmaven.repo.local=_repo -DaltDeploymentRepository=id::default::file:_remote-repo</code></p>
* @param localRepository repository where the artifact is first <code>mvn install</code>ed
* @param remoteRepository repository where the artifact is <code>mvn deploy</code>ed fom <code>localRepository</code>
* @param groupId
* @param artifactId
* @param version
* @param timestamp
* @param content
* @throws IOException
*/
protected void mvnDeploy(File localRepository, File remoteRepository, String groupId, String artifactId, String version, Date timestamp, String content) throws IOException {
mvnInstall(localRepository, groupId, artifactId, version, timestamp, content);
Metadata gamd = getOrCreateMetadata(remoteRepository, groupId, artifactId);
Metadata gavmd = getOrCreateMetadata(remoteRepository, groupId, artifactId, version);
File from = new File(localRepository, String.format("%s/%s/%s", groupId.replaceAll("\\.", "/"), artifactId, version));
File location = new File(remoteRepository, String.format("%s/%s/%s", groupId.replaceAll("\\.", "/"), artifactId, version));
location.mkdirs();
String transformedVersion = version;
if (!gamd.getVersioning().getVersions().contains(version)) {
gamd.getVersioning().addVersion(version);
}
if (!version.endsWith("-SNAPSHOT")) {
} else {
if (gavmd.getVersioning().getSnapshot() == null) {
gavmd.getVersioning().setSnapshot(new Snapshot());
gavmd.getVersioning().getSnapshot().setBuildNumber(1);
} else {
gavmd.getVersioning().getSnapshot().setBuildNumber(gavmd.getVersioning().getSnapshot().getBuildNumber() + 1);
}
transformedVersion = version.replaceFirst("SNAPSHOT$", HM2.format(timestamp) + "-" + gavmd.getVersioning().getSnapshot().getBuildNumber());
gavmd.getVersioning().getSnapshot().setTimestamp(HM2.format(timestamp));
gavmd.getVersioning().setLastUpdatedTimestamp(timestamp);
gavmd.getVersioning().getSnapshotVersions().clear();
SnapshotVersion sv1 = new SnapshotVersion();
sv1.setUpdated(gavmd.getVersioning().getLastUpdated());
sv1.setVersion(transformedVersion);
sv1.setExtension("jar");
gavmd.getVersioning().getSnapshotVersions().add(sv1);
SnapshotVersion sv2 = new SnapshotVersion();
sv2.setUpdated(gavmd.getVersioning().getLastUpdated());
sv2.setVersion(transformedVersion);
sv2.setExtension("pom");
gavmd.getVersioning().getSnapshotVersions().add(sv2);
gavmd.getVersioning().setLastUpdatedTimestamp(timestamp);
File gavmdFile = new File(location, "maven-metadata.xml");
new MetadataXpp3Writer().write(new FileWriter(gavmdFile), gavmd);
gavmdFile.setLastModified(timestamp.getTime());
FileUtils.copyFile(new File(location, "maven-metadata.xml"), new File(from, String.format("maven-metadata-%s.xml", remoteRepository.getName())));
}
String jar = String.format("%s-%s.jar", artifactId, version);
String pom = String.format("%s-%s.pom", artifactId, version);
String rjar = String.format("%s-%s.jar", artifactId, transformedVersion);
String rpom = String.format("%s-%s.pom", artifactId, transformedVersion);
FileUtils.copyFile(new File(from, jar), new File(location, rjar));
FileUtils.copyFile(new File(from, pom), new File(location, rpom));
gamd.getVersioning().setLastUpdatedTimestamp(timestamp);
File gamdFile = new File(location.getParentFile(), "maven-metadata.xml");
new MetadataXpp3Writer().write(new FileWriter(gamdFile), gamd);
gamdFile.setLastModified(timestamp.getTime());
FileUtils.copyFile(new File(location.getParentFile(), "maven-metadata.xml"), new File(from.getParentFile(), String.format("maven-metadata-%s.xml", remoteRepository.getName())));
}
Aggregations