use of org.kie.maven.integration.ArtifactResolver in project drools by kiegroup.
the class KieRepositoryScannerImpl method loadPomArtifact.
private KieModule loadPomArtifact(ReleaseId releaseId) {
ArtifactResolver resolver = ArtifactResolver.getResolverFor(releaseId, false);
if (resolver == null) {
return null;
}
MemoryKieModule kieModule = new MemoryKieModule(releaseId);
addDependencies(kieModule, resolver, resolver.getPomDirectDependencies(DependencyFilter.COMPILE_FILTER));
return kieModule;
}
use of org.kie.maven.integration.ArtifactResolver in project drools by kiegroup.
the class KieInJarModuleMetaDataImpl method init.
private void init(ArtifactResolver artifactResolver) {
if (artifactResolver == null) {
return;
}
List<ReleaseId> releasesId = new ArrayList<>();
if (releaseId != null) {
releasesId.add(releaseId);
}
if (kieModule != null && kieModule.getPomModel() != null) {
releasesId.addAll(kieModule.getPomModel().getDependencies(dependencyFilter));
} else {
List<ReleaseId> dependencies = artifactResolver.getAllDependecies(dependencyFilter).stream().map(e -> e.getReleaseId()).collect(toList());
releasesId.addAll(dependencies);
}
for (ReleaseId rId : releasesId) {
ArtifactResolver.ArtifactLocation artifactLocation = artifactResolver.resolveArtifactLocation(rId);
addArtifact(artifactLocation);
}
packages.addAll(classes.keySet());
packages.addAll(rulesByPackage.keySet());
}
use of org.kie.maven.integration.ArtifactResolver 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;
ArtifactResolver resolver = null;
if (internalKModule.getPomModel() == null) {
// if the kmodule doesn't have a pom try to determine its dependencies through maven
resolver = ArtifactResolver.getResolverFor(internalKModule.getPomModel());
jarDependencies = getJarDependencies(resolver, kmodule.getReleaseId(), DependencyFilter.COMPILE_FILTER);
} else {
jarDependencies = internalKModule.getJarDependencies(DependencyFilter.COMPILE_FILTER);
}
if (jarDependencies.isEmpty()) {
return parent;
}
if (resolver == null) {
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 KieURLClassLoader(urls.toArray(new URL[urls.size()]), parent);
}
Aggregations