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;
}
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());
}
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());
}
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);
}
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;
}
Aggregations