Search in sources :

Example 1 with DependencyFilter

use of org.kie.util.maven.support.DependencyFilter in project drools by kiegroup.

the class InJarArtifactResolver method buildPomParser.

private PomParser buildPomParser(ReleaseId releaseId) {
    List<URL> url = effectivePoms.stream().filter(e -> e.getFile().endsWith(toFile(releaseId, "pom"))).collect(toList());
    if (url.isEmpty()) {
        return null;
    }
    String path = url.get(0).toExternalForm();
    URL pomFile = classLoader.getResource(path);
    if (pomFile == null) {
        log.warn("Maven pom not found in path {}", path);
        return null;
    }
    try (InputStream pomStream = pomFile.openStream()) {
        DefaultModelReader reader = new DefaultModelReader();
        Model model = reader.read(pomStream, Collections.emptyMap());
        // dependencies were resolved already creating the effective pom during kjar creation
        return new PomParser() {

            @Override
            public List<DependencyDescriptor> getPomDirectDependencies(DependencyFilter filter) {
                List<DependencyDescriptor> deps = new ArrayList<DependencyDescriptor>();
                for (Dependency dep : model.getDependencies()) {
                    DependencyDescriptor depDescr = new DependencyDescriptor(dep);
                    if (depDescr.isValid() && filter.accept(depDescr.getReleaseId(), depDescr.getScope())) {
                        deps.add(depDescr);
                    }
                }
                return deps;
            }
        };
    } catch (Exception e) {
        log.error("Could not read pom in jar {}", pomFile);
        return null;
    }
}
Also used : DefaultModelReader(org.apache.maven.model.io.DefaultModelReader) ZipInputStream(java.util.zip.ZipInputStream) Logger(org.slf4j.Logger) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) URL(java.net.URL) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Dependency(org.apache.maven.model.Dependency) LoggerFactory(org.slf4j.LoggerFactory) Artifact(org.eclipse.aether.artifact.Artifact) IOException(java.io.IOException) File(java.io.File) ArrayList(java.util.ArrayList) ReleaseId(org.kie.api.builder.ReleaseId) DependencyFilter(org.kie.util.maven.support.DependencyFilter) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ReleaseIdImpl(org.kie.util.maven.support.ReleaseIdImpl) Optional(java.util.Optional) Collections(java.util.Collections) ZipEntry(java.util.zip.ZipEntry) InputStream(java.io.InputStream) Model(org.apache.maven.model.Model) DefaultModelReader(org.apache.maven.model.io.DefaultModelReader) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DependencyFilter(org.kie.util.maven.support.DependencyFilter) Dependency(org.apache.maven.model.Dependency) URL(java.net.URL) IOException(java.io.IOException) Model(org.apache.maven.model.Model)

Example 2 with DependencyFilter

use of org.kie.util.maven.support.DependencyFilter 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)

Aggregations

IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 ReleaseId (org.kie.api.builder.ReleaseId)2 DependencyFilter (org.kie.util.maven.support.DependencyFilter)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.enumeration (java.util.Collections.enumeration)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1