Search in sources :

Example 1 with PomModel

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

the class DependentScopeNamedBeanTest method testPlexusBeanScanning.

@Test
public void testPlexusBeanScanning() {
    // This is the shortest way I can find a root to com.google.inject.internal.Scoping#makeInjectable()
    // where the @Dependent scoped bean on the classpath causes guice to fail. The below call goes through
    // the following classes:-
    // 
    // - MavenPomModelGenerator#parse()
    // - MavenProjectLoader#parseMavenPom()
    // - MavenEmbedder#constructor
    // - MavenEmbedderUtils#buildPlexusContainer()
    // 
    // This builds a PlexusContainer with classpath scanning enabled (to detect classes needing guice injection)
    final InputStream is = getClass().getResourceAsStream("/kjar/pom-kjar.xml");
    final PomModelGenerator generator = new MavenPomModelGenerator();
    try {
        final PomModel pom = generator.parse("pom.xml", is);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        fail("This should not fail");
    }
}
Also used : MavenPomModelGenerator(org.kie.maven.integration.MavenPomModelGenerator) MavenPomModelGenerator(org.kie.maven.integration.MavenPomModelGenerator) PomModelGenerator(org.kie.util.maven.support.PomModelGenerator) InputStream(java.io.InputStream) PomModel(org.kie.util.maven.support.PomModel) Test(org.junit.Test)

Example 2 with PomModel

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

the class KieBuilderImpl method init.

private PomModel init(PomModel projectPomModel) {
    results = new ResultsImpl();
    final PomModel actualPomModel;
    if (projectPomModel == null) {
        // if pomModel is null it will generate one from pom.xml
        // if pomXml is invalid, it assigns pomModel to null
        actualPomModel = buildPomModel();
    } else {
        actualPomModel = projectPomModel;
    }
    KieServices ks = KieServices.Factory.get();
    // if kModuleModelXML is null or invalid it will generate a default kModule, with a default kbase name
    buildKieModuleModel();
    if (actualPomModel != null) {
        // creates ReleaseId from build pom
        // If the pom was generated, it will be the same as teh default ReleaseId
        releaseId = actualPomModel.getReleaseId();
        // add all the pom dependencies to this builder ... not sure this is a good idea (?)
        KieRepositoryImpl repository = (KieRepositoryImpl) ks.getRepository();
        for (ReleaseId dep : actualPomModel.getDependencies(DependencyFilter.COMPILE_FILTER)) {
            KieModule depModule = repository.getKieModule(dep, actualPomModel);
            if (depModule != null) {
                addKieDependency(depModule);
            }
        }
    } else {
        // if the pomModel is null it means that the provided pom.xml is invalid so use the default releaseId
        releaseId = KieServices.Factory.get().getRepository().getDefaultReleaseId();
    }
    return actualPomModel;
}
Also used : PomModel(org.kie.util.maven.support.PomModel) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule)

Example 3 with PomModel

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

the class KieBuilderImpl method buildAll.

public KieBuilder buildAll(BiFunction<InternalKieModule, ClassLoader, KieModuleKieProject> kprojectSupplier, Predicate<String> classFilter) {
    final PomModel currentProjectPomModel = init(pomModel);
    // kModuleModel will be null if a provided pom.xml or kmodule.xml is invalid
    if (!isBuilt() && kModuleModel != null) {
        trgMfs = new MemoryFileSystem();
        writePomAndKModule();
        addKBasesFilesToTrg();
        markSource();
        MemoryKieModule memoryKieModule = new MemoryKieModule(releaseId, kModuleModel, trgMfs);
        if (kieDependencies != null && !kieDependencies.isEmpty()) {
            for (KieModule kieModule : kieDependencies) {
                memoryKieModule.addKieDependency((InternalKieModule) kieModule);
            }
        }
        if (currentProjectPomModel != null) {
            memoryKieModule.setPomModel(currentProjectPomModel);
        }
        KieModuleKieProject kProject = kprojectSupplier.apply(memoryKieModule, classLoader);
        for (ReleaseId unresolvedDep : memoryKieModule.getUnresolvedDependencies()) {
            results.addMessage(Level.ERROR, "pom.xml", "Unresolved dependency " + unresolvedDep);
        }
        compileJavaClasses(kProject.getClassLoader(), classFilter);
        buildKieProject(kProject.createBuildContext(results), kProject, trgMfs);
        kModule = kProject.getInternalKieModule();
    }
    return this;
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) PomModel(org.kie.util.maven.support.PomModel) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule)

Example 4 with PomModel

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

the class KieBuilderImpl method buildPomModel.

private PomModel buildPomModel() {
    pomXml = getOrGeneratePomXml(srcMfs);
    if (pomXml == null) {
        // will be null if the provided pom is invalid
        return null;
    }
    try {
        PomModel tempPomModel = PomModel.Parser.parse("pom.xml", new ByteArrayInputStream(pomXml));
        // throws an exception if invalid
        validatePomModel(tempPomModel);
        return tempPomModel;
    } catch (Exception e) {
        results.addMessage(Level.ERROR, "pom.xml", "maven pom.xml found, but unable to read\n" + e.getMessage());
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PomModel(org.kie.util.maven.support.PomModel)

Example 5 with PomModel

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

the class AbstractKieModule method getPomModel.

public PomModel getPomModel() {
    if (pomModel == null) {
        try {
            byte[] pomXml = getPomXml();
            if (pomXml != null) {
                PomModel tempPomModel = PomModel.Parser.parse("pom.xml", new ByteArrayInputStream(pomXml));
                // throws an exception if invalid
                validatePomModel(tempPomModel);
                pomModel = tempPomModel;
            }
        } catch (Exception e) {
        // nothing to do as it was not possible to retrieve pom.xml
        }
    }
    return pomModel;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PomModel(org.kie.util.maven.support.PomModel) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

PomModel (org.kie.util.maven.support.PomModel)7 ReleaseId (org.kie.api.builder.ReleaseId)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 KieModule (org.kie.api.builder.KieModule)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 ZipFile (java.util.zip.ZipFile)1 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 KieBuilderImpl (org.drools.compiler.kie.builder.impl.KieBuilderImpl)1 KieServices (org.kie.api.KieServices)1 KieBuilder (org.kie.api.builder.KieBuilder)1 KieFileSystem (org.kie.api.builder.KieFileSystem)1 MavenPomModelGenerator (org.kie.maven.integration.MavenPomModelGenerator)1