use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.
the class MavenProxyResolutionTest method releaseIsAvailableInRemoteRepositoryNotUpdatingRelease.
@Test
public void releaseIsAvailableInRemoteRepositoryNotUpdatingRelease() throws IOException, InvalidMavenArtifactRequest {
File remoteRepository = initFileRepository("rr");
MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.singletonList(remoteRepository)).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS).build();
MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("10:00"), "a");
File file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
// first resolution
assertThat(FileUtils.readFileToString(file), equalTo("a"));
// don't do that, it's not proper use of maven. But sometimes we just have another deployment to public repository...
mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("11:00"), "b");
// second resolution
file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
assertThat("Artifact won't be updated for release version", FileUtils.readFileToString(file), equalTo("a"));
}
use of io.fabric8.patch.management.Artifact 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 io.fabric8.patch.management.Artifact 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 io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.
the class VerifyFeatureResolutionMojo method getSystemBundleResource.
private FakeSystemBundle getSystemBundleResource(Map<String, Map<VersionRange, Map<String, String>>> metadata) throws Exception {
Artifact karafDistro = pluginDescriptor.getArtifactMap().get(distribution);
String dir = distDir;
if (dir == null) {
dir = karafDistro.getArtifactId() + "-" + karafDistro.getBaseVersion();
}
URL configPropURL = new URL("jar:file:" + karafDistro.getFile() + "!/" + dir + "/etc/config.properties");
org.apache.felix.utils.properties.Properties configProps = PropertiesLoader.loadPropertiesFile(configPropURL, true);
// copySystemProperties(configProps);
if (javase == null) {
configProps.put("java.specification.version", System.getProperty("java.specification.version"));
} else {
configProps.put("java.specification.version", javase);
}
configProps.substitute();
Hashtable<String, String> headers = new Hashtable<>();
headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
headers.put(Constants.BUNDLE_SYMBOLICNAME, "system-bundle");
headers.put(Constants.BUNDLE_VERSION, "0.0.0");
String exportPackages = configProps.getProperty("org.osgi.framework.system.packages");
if (configProps.containsKey("org.osgi.framework.system.packages.extra")) {
if (!"".equals(configProps.getProperty("org.osgi.framework.system.packages.extra").trim())) {
exportPackages += "," + configProps.getProperty("org.osgi.framework.system.packages.extra");
}
}
headers.put(Constants.EXPORT_PACKAGE, exportPackages);
String systemCaps = configProps.getProperty("org.osgi.framework.system.capabilities");
headers.put(Constants.PROVIDE_CAPABILITY, systemCaps);
new MetadataBuilder(metadata).overrideHeaders(headers);
return new FakeSystemBundle(headers);
}
use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.
the class AbstractProfileMojo method buildFrom.
private DependencyDTO buildFrom(DependencyNode node) {
Artifact artifact = node.getArtifact();
if (artifact != null) {
DependencyDTO answer = new DependencyDTO();
answer.setGroupId(artifact.getGroupId());
answer.setArtifactId(artifact.getArtifactId());
if (artifact.isSnapshot() && !uniqueVersion) {
answer.setVersion(artifact.getBaseVersion());
} else {
answer.setVersion(artifact.getVersion());
}
answer.setClassifier(artifact.getClassifier());
String scope = artifact.getScope();
answer.setScope(scope);
answer.setType(artifact.getType());
// so lets ignore this for the maven project's artifact
if (artifact.getClassifier() == null && "jar".equals(artifact.getType())) {
if (project.getArtifact().equals(artifact)) {
getLog().debug("Ignoring bundle check on the maven project artifact: " + artifact + " as this causes issues with the maven-install-plugin and we can assume the project packaging is accurate");
} else {
try {
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setRemoteRepositories(remoteRepositories);
request.setLocalRepository(localRepository);
resolver.resolve(request);
JarInputStream jis = new JarInputStream(new FileInputStream(artifact.getFile()));
Manifest man = jis.getManifest();
String bsn = man.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
if (bsn != null) {
answer.setType("bundle");
} else {
// Try to find a matching servicemix bundle for it
/*
Map<String, String> bundles = getAllServiceMixBundles();
getLog().debug("Trying to find a matching bundle for " + artifact);
String match = bundles.get(artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion());
if (match != null) {
String[] parts = match.split(":");
answer.setGroupId(parts[0]);
answer.setArtifactId(parts[1]);
answer.setVersion(parts[2]);
getLog().info("Replacing artifact " + artifact + " with servicemix bundle " + match);
}
*/
}
} catch (Exception e) {
getLog().debug("Error checking artifact type for " + artifact, e);
}
}
}
answer.setOptional(artifact.isOptional());
String type = answer.getType();
if (type != null && type.equals("pom")) {
getLog().debug("Ignoring pom.xml for " + answer);
return null;
}
int state = node.getState();
if (state != DependencyNode.INCLUDED) {
getLog().debug("Ignoring " + node);
return null;
}
if (isWarProject()) {
if (scope != null && !scope.equals("provided")) {
getLog().debug("WAR packaging so ignoring non-provided scope " + scope + " for " + node);
return null;
}
}
List children = node.getChildren();
for (Object child : children) {
if (child instanceof DependencyNode) {
DependencyNode childNode = (DependencyNode) child;
if (childNode.getState() == DependencyNode.INCLUDED) {
String childScope = childNode.getArtifact().getScope();
if (!"test".equals(childScope) && !"provided".equals(childScope)) {
DependencyDTO childDTO = buildFrom(childNode);
if (childDTO != null) {
answer.addChild(childDTO);
}
} else {
getLog().debug("Ignoring artifact " + childNode.getArtifact() + " with scope " + childScope);
}
}
}
}
return answer;
}
return null;
}
Aggregations