use of org.apache.maven.artifact.repository.metadata.SnapshotVersion in project karaf by apache.
the class MavenUtil method generateMavenMetadata.
/**
* Generate the maven-metadata-local.xml for the given Maven <code>Artifact</code>.
*
* @param artifact the Maven <code>Artifact</code>.
* @param target the target maven-metadata-local.xml file to generate.
* @throws IOException if the maven-metadata-local.xml can't be generated.
*/
public static void generateMavenMetadata(Artifact artifact, File target) throws IOException {
target.getParentFile().mkdirs();
Metadata metadata = new Metadata();
metadata.setGroupId(artifact.getGroupId());
metadata.setArtifactId(artifact.getArtifactId());
metadata.setVersion(artifact.getVersion());
metadata.setModelVersion("1.1.0");
Versioning versioning = new Versioning();
versioning.setLastUpdatedTimestamp(new Date(System.currentTimeMillis()));
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy(true);
versioning.setSnapshot(snapshot);
SnapshotVersion snapshotVersion = new SnapshotVersion();
snapshotVersion.setClassifier(artifact.getClassifier());
snapshotVersion.setVersion(artifact.getVersion());
snapshotVersion.setExtension(artifact.getType());
snapshotVersion.setUpdated(versioning.getLastUpdated());
versioning.addSnapshotVersion(snapshotVersion);
metadata.setVersioning(versioning);
MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer();
Writer writer = new FileWriter(target);
metadataWriter.write(writer, metadata);
}
use of org.apache.maven.artifact.repository.metadata.SnapshotVersion in project fabric8 by jboss-fuse.
the class AetherResolutionSupport method mvnInstall.
/**
* <p>Simulation of <code>mvn clean install</code> inside local repository</p>
* <p>Like <code>mvn clean install -DskipTests -Dmaven.repo.local=_repo</code></p>
* @param repository
* @param groupId
* @param artifactId
* @param version
* @param content
*/
protected void mvnInstall(File repository, String groupId, String artifactId, String version, Date timestamp, String content) throws IOException {
File location = new File(repository, String.format("%s/%s/%s", groupId.replaceAll("\\.", "/"), artifactId, version));
String name = String.format("%s-%s", artifactId, version);
File jar = new File(location, name + ".jar");
FileUtils.write(jar, content);
jar.setLastModified(timestamp.getTime());
File pom = new File(location, name + ".pom");
FileUtils.touch(pom);
pom.setLastModified(timestamp.getTime());
String remoteRepositoriesConfig = "";
remoteRepositoriesConfig += name + ".jar>=\n";
remoteRepositoriesConfig += name + ".pom>=\n";
File remoteRepositories = new File(location, "_remote.repositories");
FileUtils.write(remoteRepositories, remoteRepositoriesConfig);
remoteRepositories.setLastModified(timestamp.getTime());
Metadata gamd = getOrCreateLocalMetadata(repository, groupId, artifactId);
if (!gamd.getVersioning().getVersions().contains(version)) {
gamd.getVersioning().addVersion(version);
}
if (!version.endsWith("-SNAPSHOT")) {
gamd.getVersioning().setRelease(version);
} else {
Metadata gavmd = getOrCreateLocalMetadata(repository, groupId, artifactId, version);
gavmd.getVersioning().setSnapshot(new Snapshot());
gavmd.getVersioning().getSnapshot().setLocalCopy(true);
gavmd.getVersioning().setLastUpdatedTimestamp(timestamp);
gavmd.getVersioning().getSnapshotVersions().clear();
SnapshotVersion sv1 = new SnapshotVersion();
sv1.setUpdated(gavmd.getVersioning().getLastUpdated());
sv1.setVersion(version);
sv1.setExtension("jar");
gavmd.getVersioning().getSnapshotVersions().add(sv1);
SnapshotVersion sv2 = new SnapshotVersion();
sv2.setUpdated(gavmd.getVersioning().getLastUpdated());
sv2.setVersion(version);
sv2.setExtension("pom");
gavmd.getVersioning().getSnapshotVersions().add(sv2);
gavmd.getVersioning().setLastUpdatedTimestamp(timestamp);
File gavmdFile = new File(location, "maven-metadata-local.xml");
new MetadataXpp3Writer().write(new FileWriter(gavmdFile), gavmd);
gavmdFile.setLastModified(timestamp.getTime());
}
gamd.getVersioning().setLastUpdatedTimestamp(timestamp);
File gamdFile = new File(location.getParentFile(), "maven-metadata-local.xml");
new MetadataXpp3Writer().write(new FileWriter(gamdFile), gamd);
gamdFile.setLastModified(timestamp.getTime());
}
use of org.apache.maven.artifact.repository.metadata.SnapshotVersion in project fabric8 by jboss-fuse.
the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInDefaultRepositoryActingAsRemote.
@Test
public void snapshotIsAvailableInDefaultRepositoryActingAsRemote() throws IOException, InvalidMavenArtifactRequest {
File differentLocalRepository = initFileRepository("dlr");
File defaultRepository = initFileRepository("dr");
MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.<File>emptyList()).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER).withDefaultRepositories(Collections.singletonList(defaultRepository)).build();
MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
servlet.start();
mvnDeploy(differentLocalRepository, defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
// Here's expected state of repository where SNAPSHOT was `mvn deploy`ed
assertFalse(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata-local.xml").isFile());
assertTrue(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml").isFile());
File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
Metadata metadata = readMetadata(file);
boolean checked = false;
assertThat(metadata.getVersioning().getSnapshot().isLocalCopy(), is(false));
for (SnapshotVersion snapshotVersion : metadata.getVersioning().getSnapshotVersions()) {
if ("jar".equals(snapshotVersion.getExtension())) {
assertThat(snapshotVersion.getVersion(), is("0.1.0-20170101.100000-1"));
checked = true;
}
}
assertTrue("We should find snapshot metadata", checked);
// download artifact using version from metadata
file = servlet.download("io/fabric8/test/universalis-api/0.1.0-20170101.100000-1/universalis-api-0.1.0-20170101.100000-1.jar");
assertThat(FileUtils.readFileToString(file), equalTo("a"));
mvnDeploy(differentLocalRepository, defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
metadata = readMetadata(file);
assertThat("No policy should prevent us from seeing newer snapshot from defaultRepository", metadata.getVersioning().getSnapshotVersions().get(0).getVersion(), is("0.1.0-20170101.110000-2"));
}
use of org.apache.maven.artifact.repository.metadata.SnapshotVersion in project fabric8 by jboss-fuse.
the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInDefaultRepository.
@Test
public void snapshotIsAvailableInDefaultRepository() throws IOException, InvalidMavenArtifactRequest {
File defaultRepository = initFileRepository("dr");
MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.<File>emptyList()).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER).withDefaultRepositories(Collections.singletonList(defaultRepository)).build();
MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
servlet.start();
mvnInstall(defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
// Here's expected state of repository where SNAPSHOT was `mvn install`ed
assertFalse(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml").isFile());
assertTrue(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata-local.xml").isFile());
File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
Metadata metadata = readMetadata(file);
boolean checked = false;
assertThat(metadata.getVersioning().getSnapshot().isLocalCopy(), is(true));
for (SnapshotVersion snapshotVersion : metadata.getVersioning().getSnapshotVersions()) {
if ("jar".equals(snapshotVersion.getExtension())) {
assertThat(snapshotVersion.getVersion(), is("0.1.0-SNAPSHOT"));
checked = true;
}
}
assertTrue("We should find snapshot metadata", checked);
// if metadata says it's "0.1.0-SNAPSHOT", we should have no problem downloading this artifact without
// version transformation
file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-SNAPSHOT.jar");
assertThat(FileUtils.readFileToString(file), equalTo("a"));
mvnInstall(defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-SNAPSHOT.jar");
assertThat("No policy should prevent us from seeing newer snapshot from defaultRepository", FileUtils.readFileToString(file), equalTo("b"));
}
use of org.apache.maven.artifact.repository.metadata.SnapshotVersion in project indy by Commonjava.
the class MavenMetadataMerger method merge.
public Metadata merge(final Metadata master, final Metadata src, final Group group, final String path) {
if (src == null) {
return master;
}
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Merge metadata, group: {}, path: {}, src: {}", group.getKey(), path, src);
// there is a lot of junk in here to make up for Metadata's anemic merge() method.
if (src.getGroupId() != null) {
master.setGroupId(src.getGroupId());
}
if (src.getArtifactId() != null) {
master.setArtifactId(src.getArtifactId());
}
if (src.getVersion() != null) {
master.setVersion(src.getVersion());
}
master.merge(src);
Versioning versioning = master.getVersioning();
Versioning srcVersioning = src.getVersioning();
if (srcVersioning != null && srcVersioning.getSnapshot() != null) {
logger.trace("INCLUDING snapshot information from: {} in: {}:{}", src, group.getKey(), path);
versioning.setSnapshot(srcVersioning.getSnapshot());
final List<SnapshotVersion> snapshotVersions = versioning.getSnapshotVersions();
boolean added = false;
for (final SnapshotVersion snap : srcVersioning.getSnapshotVersions()) {
if (!snapshotVersions.contains(snap)) {
snapshotVersions.add(snap);
added = true;
}
}
if (added) {
snapshotVersions.sort(new SnapshotVersionComparator());
}
} else {
logger.warn("SKIPPING snapshot information from: {} in: {}:{})", src, group.getKey(), path);
}
return master;
}
Aggregations