Search in sources :

Example 1 with ArtifactResolver

use of org.appformer.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));
    kieModule.build();
    return kieModule;
}
Also used : MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) ArtifactResolver(org.appformer.maven.integration.ArtifactResolver)

Example 2 with ArtifactResolver

use of org.appformer.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 = 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)

Aggregations

ArtifactResolver (org.appformer.maven.integration.ArtifactResolver)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 MemoryKieModule (org.drools.compiler.kie.builder.impl.MemoryKieModule)1 Artifact (org.eclipse.aether.artifact.Artifact)1 ReleaseId (org.kie.api.builder.ReleaseId)1