Search in sources :

Example 36 with Artifact

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

the class AetherRepository method versions.

@Override
public SortedSet<Version> versions(String bsn) throws Exception {
    init();
    // Use the index by preference
    if (indexedRepo != null)
        return indexedRepo.versions(ConversionUtils.maybeMavenCoordsToBsn(bsn));
    Artifact artifact = null;
    try {
        artifact = new DefaultArtifact(bsn + ":[0,)");
    } catch (Exception e) {
    // ignore non-GAV style dependencies
    }
    if (artifact == null)
        return null;
    // Setup the Aether repo session and create the range request
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.setRepositories(Collections.singletonList(remoteRepo));
    // Resolve the range
    VersionRangeResult rangeResult = repoSystem.resolveVersionRange(session, rangeRequest);
    // Add to the result
    SortedSet<Version> versions = new TreeSet<Version>();
    for (org.eclipse.aether.version.Version version : rangeResult.getVersions()) {
        try {
            versions.add(MavenVersion.parseString(version.toString()).getOSGiVersion());
        } catch (IllegalArgumentException e) {
        // ignore version
        }
    }
    return versions;
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) 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) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion) TreeSet(java.util.TreeSet) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 37 with Artifact

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

the class ConversionUtilsTest method testGuessGroupId.

public void testGuessGroupId() throws Exception {
    Jar jar = new Jar(IO.getFile("testdata/1.jar"));
    Artifact artifact = ConversionUtils.fromBundleJar(jar);
    assertEquals("org.example", artifact.getGroupId());
    assertEquals("api", artifact.getArtifactId());
}
Also used : Jar(aQute.bnd.osgi.Jar) Artifact(org.eclipse.aether.artifact.Artifact)

Example 38 with Artifact

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

the class BaselineMojo method searchForBaseVersion.

private void searchForBaseVersion(Artifact artifact, List<RemoteRepository> aetherRepos) throws VersionRangeResolutionException {
    logger.info("Automatically determining the baseline version for {} using repositories {}", artifact, aetherRepos);
    Artifact toFind = new DefaultArtifact(base.getGroupId(), base.getArtifactId(), base.getClassifier(), base.getExtension(), base.getVersion());
    Artifact toCheck = toFind.setVersion("(," + artifact.getVersion() + ")");
    VersionRangeRequest request = new VersionRangeRequest(toCheck, aetherRepos, "baseline");
    VersionRangeResult versions = system.resolveVersionRange(session, request);
    logger.debug("Found versions {}", versions.getVersions());
    base.setVersion(versions.getHighestVersion() != null ? versions.getHighestVersion().toString() : null);
    logger.info("The baseline version was found to be {}", base.getVersion());
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) 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 39 with Artifact

use of org.eclipse.aether.artifact.Artifact in project drools by kiegroup.

the class MavenClassLoaderResolver method getClassLoader.

@Override
public ClassLoader getClassLoader(KieModule kmodule) {
    ClassLoader parent = Thread.currentThread().getContextClassLoader();
    if (parent == null) {
        parent = ClassLoader.getSystemClassLoader();
    }
    if (parent == null) {
        parent = MavenClassLoaderResolver.class.getClassLoader();
    }
    InternalKieModule internalKModule = (InternalKieModule) kmodule;
    Collection<ReleaseId> jarDependencies = internalKModule.getJarDependencies(DependencyFilter.COMPILE_FILTER);
    if (jarDependencies.isEmpty()) {
        return parent;
    }
    ArtifactResolver resolver = ArtifactResolver.getResolverFor(internalKModule.getPomModel());
    List<URL> urls = new ArrayList<URL>();
    List<ReleaseId> unresolvedDeps = new ArrayList<ReleaseId>();
    for (ReleaseId rid : jarDependencies) {
        try {
            Artifact artifact = resolver.resolveArtifact(rid);
            if (artifact != null) {
                File jar = artifact.getFile();
                urls.add(jar.toURI().toURL());
            } else {
                logger.error("Dependency artifact not found for: " + rid);
                unresolvedDeps.add(rid);
            }
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }
    internalKModule.setUnresolvedDependencies(unresolvedDeps);
    return new URLClassLoader(urls.toArray(new URL[urls.size()]), parent);
}
Also used : MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) ReleaseId(org.kie.api.builder.ReleaseId) ArtifactResolver(org.appformer.maven.integration.ArtifactResolver) URL(java.net.URL) Artifact(org.eclipse.aether.artifact.Artifact) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 40 with Artifact

use of org.eclipse.aether.artifact.Artifact in project drools by kiegroup.

the class KieRepositoryScannerImpl method scanForUpdates.

private Map<DependencyDescriptor, Artifact> scanForUpdates() {
    artifactResolver = getResolverFor(kieContainer, true);
    if (!kieProjectDescr.getReleaseId().equals(this.kieContainer.getReleaseId())) {
        kieProjectDescr = new DependencyDescriptor(this.kieContainer.getReleaseId(), this.kieContainer.getCreationTimestamp());
    }
    Map<DependencyDescriptor, Artifact> newArtifacts = new HashMap<DependencyDescriptor, Artifact>();
    Artifact newArtifact = artifactResolver.resolveArtifact(this.kieContainer.getConfiguredReleaseId());
    if (newArtifact != null) {
        DependencyDescriptor resolvedDep = new DependencyDescriptor(newArtifact);
        if (resolvedDep.isNewerThan(kieProjectDescr)) {
            newArtifacts.put(kieProjectDescr, newArtifact);
            kieProjectDescr = new DependencyDescriptor(newArtifact);
        }
    }
    for (DependencyDescriptor dep : artifactResolver.getAllDependecies()) {
        ReleaseId artifactId = adapt(dep.getReleaseIdWithoutVersion());
        DependencyDescriptor oldDep = usedDependencies.get(artifactId);
        if (oldDep != null) {
            newArtifact = artifactResolver.resolveArtifact(dep.getReleaseId());
            if (newArtifact != null) {
                DependencyDescriptor newDep = new DependencyDescriptor(newArtifact);
                if (newDep.isNewerThan(oldDep)) {
                    newArtifacts.put(oldDep, newArtifact);
                    usedDependencies.put(artifactId, newDep);
                }
            }
        }
    }
    return newArtifacts;
}
Also used : DependencyDescriptor(org.appformer.maven.integration.DependencyDescriptor) HashMap(java.util.HashMap) ReleaseId(org.kie.api.builder.ReleaseId) Artifact(org.eclipse.aether.artifact.Artifact)

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