Search in sources :

Example 31 with Artifact

use of org.eclipse.aether.artifact.Artifact in project pinpoint by naver.

the class DependencyResolver method getNewestVersion.

public String getNewestVersion(String groupId, String artifactId) throws VersionRangeResolutionException {
    Artifact artifact = new DefaultArtifact(groupId, artifactId, "jar", "[0,)");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.setRepositories(repositories);
    VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
    Version newestVersion = rangeResult.getHighestVersion();
    return newestVersion.toString();
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) Version(org.eclipse.aether.version.Version) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 32 with Artifact

use of org.eclipse.aether.artifact.Artifact in project pinpoint by naver.

the class DependencyResolver method resolveArtifactsAndDependencies.

public List<File> resolveArtifactsAndDependencies(List<Artifact> artifacts) throws ArtifactResolutionException, DependencyResolutionException {
    List<Dependency> dependencies = new ArrayList<Dependency>();
    for (Artifact artifact : artifacts) {
        dependencies.add(new Dependency(artifact, JavaScopes.RUNTIME));
    }
    CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, repositories);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter);
    DependencyResult result = system.resolveDependencies(session, dependencyRequest);
    List<File> files = new ArrayList<File>();
    for (ArtifactResult artifactResult : result.getArtifactResults()) {
        files.add(artifactResult.getArtifact().getFile());
    }
    return files;
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 33 with Artifact

use of org.eclipse.aether.artifact.Artifact in project pinpoint by naver.

the class DependencyResolver method combination.

private Map<String, List<Artifact>> combination(List<List<List<Artifact>>> groups) {
    if (groups.size() == 1) {
        Map<String, List<Artifact>> result = new HashMap<String, List<Artifact>>();
        List<List<Artifact>> group = groups.get(0);
        if (group.size() == 1) {
            result.put("", group.get(0));
        } else {
            for (List<Artifact> aCase : group) {
                Artifact representative = aCase.get(0);
                result.put(representative.getArtifactId() + "-" + representative.getVersion(), aCase);
            }
        }
        return result;
    }
    List<List<Artifact>> thisGroup = groups.get(0);
    Map<String, List<Artifact>> sub = combination(groups.subList(1, groups.size()));
    Map<String, List<Artifact>> result = new HashMap<String, List<Artifact>>();
    if (thisGroup.size() == 1) {
        List<Artifact> thisArtifacts = thisGroup.get(0);
        for (Entry<String, List<Artifact>> subEntry : sub.entrySet()) {
            List<Artifact> subArtifacts = subEntry.getValue();
            List<Artifact> t = new ArrayList<Artifact>(thisArtifacts.size() + subArtifacts.size());
            t.addAll(thisArtifacts);
            t.addAll(subArtifacts);
            result.put(subEntry.getKey(), t);
        }
    } else {
        for (List<Artifact> thisArtifacts : thisGroup) {
            Artifact representative = thisArtifacts.get(0);
            String thisKey = representative.getArtifactId() + "-" + representative.getVersion();
            for (Entry<String, List<Artifact>> subEntry : sub.entrySet()) {
                List<Artifact> subArtifacts = subEntry.getValue();
                List<Artifact> t = new ArrayList<Artifact>(thisArtifacts.size() + subArtifacts.size());
                t.addAll(thisArtifacts);
                t.addAll(subArtifacts);
                String subKey = subEntry.getKey();
                String key = subKey.isEmpty() ? thisKey : thisKey + ", " + subKey;
                result.put(key, t);
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 34 with Artifact

use of org.eclipse.aether.artifact.Artifact in project karaf by apache.

the class Dependency31Helper method artifactToMvn.

@Override
public String artifactToMvn(Object _artifact, String versionOrRange) {
    Artifact artifact = (Artifact) _artifact;
    String bundleName;
    if (artifact.getExtension().equals("jar") && MavenUtil.isEmpty(artifact.getClassifier())) {
        bundleName = String.format("mvn:%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), versionOrRange);
    } else {
        if (MavenUtil.isEmpty(artifact.getClassifier())) {
            bundleName = String.format("mvn:%s/%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), versionOrRange, artifact.getExtension());
        } else {
            bundleName = String.format("mvn:%s/%s/%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), versionOrRange, artifact.getExtension(), artifact.getClassifier());
        }
    }
    return bundleName;
}
Also used : String(java.lang.String) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 35 with Artifact

use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.

the class AetherRepository method put.

@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
    init();
    DigestInputStream digestStream = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"));
    final File tmpFile = IO.createTempFile(cacheDir, "put", ".bnd");
    try {
        IO.copy(digestStream, tmpFile);
        byte[] digest = digestStream.getMessageDigest().digest();
        if (options.digest != null && !Arrays.equals(options.digest, digest))
            throw new IOException("Retrieved artifact digest doesn't match specified digest");
        // Get basic info about the bundle we're deploying
        Jar jar = new Jar(tmpFile);
        Artifact artifact = ConversionUtils.fromBundleJar(jar);
        artifact = artifact.setFile(tmpFile);
        // Setup the Aether repo session and create the deployment request
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
        session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
        final DeployRequest request = new DeployRequest();
        request.addArtifact(artifact);
        request.setRepository(remoteRepo);
        // Capture the result including remote resource URI
        final ResultHolder resultHolder = new ResultHolder();
        session.setTransferListener(new AbstractTransferListener() {

            @Override
            public void transferSucceeded(TransferEvent event) {
                TransferResource resource = event.getResource();
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(resource.getFile())) {
                    PutResult result = new PutResult();
                    result.artifact = URI.create(resource.getRepositoryUrl() + resource.getResourceName());
                    resultHolder.result = result;
                    System.out.println("UPLOADED to: " + URI.create(resource.getRepositoryUrl() + resource.getResourceName()));
                }
            }

            @Override
            public void transferFailed(TransferEvent event) {
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
                    resultHolder.error = event.getException();
            }

            @Override
            public void transferCorrupted(TransferEvent event) throws TransferCancelledException {
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
                    resultHolder.error = event.getException();
            }
        });
        // Do the deploy and report results
        repoSystem.deploy(session, request);
        if (resultHolder.result != null) {
            if (indexedRepo != null)
                indexedRepo.reset();
            return resultHolder.result;
        } else if (resultHolder.error != null) {
            throw new Exception("Error during artifact upload", resultHolder.error);
        } else {
            throw new Exception("Artifact was not uploaded");
        }
    } finally {
        if (tmpFile != null && tmpFile.isFile())
            IO.delete(tmpFile);
    }
}
Also used : DigestInputStream(java.security.DigestInputStream) DeployRequest(org.eclipse.aether.deployment.DeployRequest) AbstractTransferListener(org.eclipse.aether.transfer.AbstractTransferListener) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) TransferEvent(org.eclipse.aether.transfer.TransferEvent) IOException(java.io.IOException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) URISyntaxException(java.net.URISyntaxException) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) TransferResource(org.eclipse.aether.transfer.TransferResource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Aggregations

Artifact (org.eclipse.aether.artifact.Artifact)41 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)30 File (java.io.File)11 Dependency (org.eclipse.aether.graph.Dependency)9 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)9 IOException (java.io.IOException)8 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)8 ArrayList (java.util.ArrayList)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)7 Path (java.nio.file.Path)6 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)6 CollectRequest (org.eclipse.aether.collection.CollectRequest)6 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 STGroupString (org.stringtemplate.v4.STGroupString)5 Jar (aQute.bnd.osgi.Jar)4 URISyntaxException (java.net.URISyntaxException)4 URL (java.net.URL)4 List (java.util.List)4 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)4