Search in sources :

Example 1 with ArtifactResolver

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

Example 2 with ArtifactResolver

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());
}
Also used : InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Enumeration(java.util.Enumeration) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArtifactResolver.getResolverFor(org.kie.maven.integration.ArtifactResolver.getResolverFor) ArrayList(java.util.ArrayList) ReleaseId(org.kie.api.builder.ReleaseId) DependencyFilter(org.kie.util.maven.support.DependencyFilter) HashSet(java.util.HashSet) IoUtils(org.drools.core.util.IoUtils) Map(java.util.Map) ZipEntry(java.util.zip.ZipEntry) KieModuleMetaInfo(org.drools.core.rule.KieModuleMetaInfo) KieModuleModelImpl(org.drools.compiler.kproject.models.KieModuleModelImpl) Logger(org.slf4j.Logger) ClassUtils(org.drools.core.util.ClassUtils) Collection(java.util.Collection) UTF8_CHARSET(org.drools.core.util.IoUtils.UTF8_CHARSET) Collections.enumeration(java.util.Collections.enumeration) Set(java.util.Set) IOException(java.io.IOException) TypeMetaInfo(org.drools.core.rule.TypeMetaInfo) ArtifactResolver(org.kie.maven.integration.ArtifactResolver) Collectors(java.util.stream.Collectors) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) ClassUtils.convertResourceToClassName(org.drools.core.util.ClassUtils.convertResourceToClassName) Collections(java.util.Collections) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ReleaseId(org.kie.api.builder.ReleaseId) ArtifactResolver(org.kie.maven.integration.ArtifactResolver)

Example 3 with ArtifactResolver

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) ReleaseId(org.kie.api.builder.ReleaseId) ArtifactResolver(org.kie.maven.integration.ArtifactResolver) URL(java.net.URL) Artifact(org.eclipse.aether.artifact.Artifact) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

ArtifactResolver (org.kie.maven.integration.ArtifactResolver)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)2 ReleaseId (org.kie.api.builder.ReleaseId)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.enumeration (java.util.Collections.enumeration)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1