Search in sources :

Example 6 with PomModel

use of org.appformer.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.appformer.maven.integration.MavenPomModelGenerator) MavenPomModelGenerator(org.appformer.maven.integration.MavenPomModelGenerator) PomModelGenerator(org.appformer.maven.support.PomModelGenerator) InputStream(java.io.InputStream) PomModel(org.appformer.maven.support.PomModel) Test(org.junit.Test)

Example 7 with PomModel

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

the class ClasspathKieProject method generatePomPropertiesFromPom.

private static String generatePomPropertiesFromPom(String rootPath) {
    // recurse until we reach root or find a pom.xml
    File file = null;
    for (File folder = new File(rootPath); folder.getParent() != null; folder = new File(folder.getParent())) {
        file = new File(folder, "pom.xml");
        if (file.exists()) {
            break;
        }
        file = null;
    }
    if (file != null) {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(file);
            PomModel pomModel = PomModel.Parser.parse(rootPath + "/pom.xml", fis);
            // throws an exception if invalid
            KieBuilderImpl.validatePomModel(pomModel);
            org.appformer.maven.support.AFReleaseId gav = pomModel.getReleaseId();
            String str = KieBuilderImpl.generatePomProperties(gav);
            log.info("Recursed up folders, found and used pom.xml " + file);
            return str;
        } catch (Exception e) {
            log.error("As folder project tried to fall back to pom.xml " + file + "\nbut failed with exception:\n" + e.getMessage());
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    log.error("Error when closing InputStream to " + file + "\n" + e.getMessage());
                }
            }
        }
    } else {
        log.warn("As folder project tried to fall back to pom.xml, but could not find one");
    }
    return null;
}
Also used : PomModel(org.appformer.maven.support.PomModel) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

PomModel (org.appformer.maven.support.PomModel)7 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 AFReleaseId (org.appformer.maven.support.AFReleaseId)2 Test (org.junit.Test)2 KieModule (org.kie.api.builder.KieModule)2 ReleaseId (org.kie.api.builder.ReleaseId)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 MavenPomModelGenerator (org.appformer.maven.integration.MavenPomModelGenerator)1 PomModelGenerator (org.appformer.maven.support.PomModelGenerator)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