Search in sources :

Example 6 with Artifact

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"));
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) File(java.io.File) Test(org.junit.Test)

Example 7 with Artifact

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"));
}
Also used : SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 8 with Artifact

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"));
}
Also used : SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 9 with Artifact

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);
}
Also used : MetadataBuilder(io.fabric8.agent.service.MetadataBuilder) Hashtable(java.util.Hashtable) Artifact(org.apache.maven.artifact.Artifact) URL(java.net.URL)

Example 10 with Artifact

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;
}
Also used : JarInputStream(java.util.jar.JarInputStream) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) List(java.util.List) ArrayList(java.util.ArrayList) Manifest(java.util.jar.Manifest) Artifact(org.apache.maven.artifact.Artifact) FileInputStream(java.io.FileInputStream) DependencyTreeBuilderException(org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

File (java.io.File)22 Artifact (io.fabric8.patch.management.Artifact)11 Test (org.junit.Test)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)8 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)8 FileInputStream (java.io.FileInputStream)6 MavenResolver (io.fabric8.maven.MavenResolver)5 PatchException (io.fabric8.patch.management.PatchException)5 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)5 FileOutputStream (java.io.FileOutputStream)4 MalformedURLException (java.net.MalformedURLException)4 Git (org.eclipse.jgit.api.Git)4 Version (org.osgi.framework.Version)4 DeployResults (io.fabric8.deployer.dto.DeployResults)3 Artifact.isSameButVersion (io.fabric8.patch.management.Artifact.isSameButVersion)3 Patch (io.fabric8.patch.management.Patch)3 Utils.mvnurlToArtifact (io.fabric8.patch.management.Utils.mvnurlToArtifact)3 HashSet (java.util.HashSet)3