use of org.eclipse.aether.artifact.Artifact in project kie-wb-common by kiegroup.
the class MavenDependencyConfigExecutorTest method installArtifactLocally.
private void installArtifactLocally(final String groupId, final String artifactId, final String version) throws Exception {
Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "pom", version);
final Path pom = getPom(groupId, artifactId, version);
pomArtifact = pomArtifact.setFile(pom.toFile());
final InstallRequest installRequest = new InstallRequest();
installRequest.addArtifact(pomArtifact);
final DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
RepositorySystem system = locator.getService(RepositorySystem.class);
final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
final LocalRepository localRepo = new LocalRepository(m2Folder);
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
system.install(session, installRequest);
}
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;
}
use of org.eclipse.aether.artifact.Artifact in project drools by kiegroup.
the class KieRepositoryScannerImpl method indexArtifacts.
private Map<ReleaseId, DependencyDescriptor> indexArtifacts() {
Map<ReleaseId, DependencyDescriptor> depsMap = new HashMap<ReleaseId, DependencyDescriptor>();
for (DependencyDescriptor dep : artifactResolver.getAllDependecies()) {
if (!"test".equals(dep.getScope()) && !"provided".equals(dep.getScope()) && !"system".equals(dep.getScope())) {
Artifact artifact = artifactResolver.resolveArtifact(dep.getReleaseId());
log.debug(artifact + " resolved to " + artifact.getFile());
if (isKJar(artifact.getFile())) {
depsMap.put(adapt(dep.getReleaseIdWithoutVersion()), new DependencyDescriptor(artifact));
}
} else {
log.debug("{} does not need to be resolved because in scope {}", dep, dep.getScope());
}
}
return depsMap;
}
use of org.eclipse.aether.artifact.Artifact in project BIMserver by opensourceBIM.
the class MavenPluginLocation method getAllVersions.
@Override
public List<MavenPluginVersion> getAllVersions() {
List<MavenPluginVersion> pluginVersions = new ArrayList<>();
Artifact artifact = new DefaultArtifact(groupId, artifactId, null, "[0,)");
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(mavenPluginRepository.getRepositories());
// RemoteRepository centralRepo = newCentralRepository();
try {
VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
List<Version> versions = rangeResult.getVersions();
if (!versions.isEmpty()) {
for (int i = versions.size() - 1; i >= Math.max(0, versions.size() - 3); i--) {
Version version = versions.get(i);
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
descriptorRequest.setArtifact(versionArtifact);
descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(descriptorResult.getArtifact());
request.setRepositories(mavenPluginRepository.getRepositories());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
File pomFile = resolveArtifact.getArtifact().getFile();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try (FileReader fileReader = new FileReader(pomFile)) {
Model model = mavenreader.read(fileReader);
mavenPluginVersion.setModel(model);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
}
pluginVersions.add(0, mavenPluginVersion);
}
}
} catch (VersionRangeResolutionException e) {
e.printStackTrace();
} catch (ArtifactDescriptorException e) {
e.printStackTrace();
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
return pluginVersions;
}
Aggregations