Search in sources :

Example 1 with KieCompilationResponse

use of org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse in project kie-wb-common by kiegroup.

the class ClassLoaderProviderTest method getResourcesFromADroolsPRJWithError.

@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void getResourcesFromADroolsPRJWithError() throws Exception {
    /**
     * If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
     */
    Path tmpRoot = Files.createTempDirectory("repo");
    Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_SINGLE_RESOURCES_WITH_ERROR);
    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_KIE_OBJECTS, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.INSTALL, MavenCLIArgs.ALTERNATE_USER_SETTINGS + TestUtilMaven.getSettingsFile() }, Boolean.FALSE);
    KieCompilationResponse res = (KieCompilationResponse) compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmp, res, this.getClass(), testName);
    if (!res.isSuccessful()) {
        List<String> msgs = res.getMavenOutput();
        for (String msg : msgs) {
            logger.info(msg);
        }
    }
    assertThat(res.isSuccessful()).isTrue();
    Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
    assertThat(metaDataOptional).isPresent();
    KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
    assertThat(kieModuleMetaInfo).isNotNull();
    Optional<KieModule> kieModuleOptional = res.getKieModule();
    assertThat(kieModuleOptional).isPresent();
    List<String> classloaderOptional = CompilerClassloaderUtils.getStringFromTargets(tmpRoot);
    assertThat(classloaderOptional).hasSize(3);
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) KieModuleMetaInfo(org.drools.core.rule.KieModuleMetaInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with KieCompilationResponse

use of org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse in project kie-wb-common by kiegroup.

the class KieAfterDecoratorTest method compileWithFailedResponse.

@Test
public void compileWithFailedResponse() throws Exception {
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, createdNewPrjInRepo("kjar-2-fail", ResourcesConstants.KJAR_2_SINGLE_FAIL_RESOURCES), new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
    KieAfterDecorator decorator = new KieAfterDecorator(new BaseMavenCompiler(true, false));
    KieCompilationResponse kieRes = (KieCompilationResponse) decorator.compile(req);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(kieRes.isSuccessful()).isFalse();
        softly.assertThat(kieRes.getMavenOutput()).isNotEmpty();
        softly.assertThat(kieRes.getKieModule()).isEmpty();
        softly.assertThat(kieRes.getKieModuleMetaInfo()).isEmpty();
    });
}
Also used : DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) BaseMavenCompiler(org.kie.workbench.common.services.backend.compiler.impl.BaseMavenCompiler) CompilationRequest(org.kie.workbench.common.services.backend.compiler.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) BaseCompilerTest(org.kie.workbench.common.services.backend.compiler.BaseCompilerTest) Test(org.junit.Test)

Example 3 with KieCompilationResponse

use of org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse in project kie-wb-common by kiegroup.

the class ConcurrentBuildTest method compileAndloadKieJarSingleMetadataWithPackagedJar.

private KieCompilationResponse compileAndloadKieJarSingleMetadataWithPackagedJar() {
    String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
    Path tmpRoot = Files.createTempDirectory("repo_" + UUID.randomUUID().toString());
    Path tmp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
    try {
        TestUtil.copyTree(Paths.get(ResourcesConstants.KJAR_2_SINGLE_RESOURCES), tmp);
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_KIE_OBJECTS, KieDecorator.ENABLE_LOGGING));
    final KieCompilationResponse res;
    try {
        final WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
        final CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
        res = (KieCompilationResponse) compiler.compile(req);
        logger.info("\nFinished " + res.isSuccessful() + " Single metadata tmp:{} UUID:{} res.getMavenOutput().isEmpty():", tmp, req.getRequestUUID(), res.getMavenOutput().isEmpty());
        if (!res.isSuccessful()) {
            try {
                logger.error(" Fail, writing output on target folder:{}  UUID:", tmp, req.getRequestUUID());
                TestUtil.writeMavenOutputIntoTargetFolder(tmp, res.getMavenOutput(), "ConcurrentBuildTest.compileAndloadKieJarSingleMetadataWithPackagedJar_" + req.getRequestUUID());
            } catch (Exception e) {
                logger.error(e.getMessage());
            }
        }
    } finally {
        latch.countDown();
    }
    return res;
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) ExecutionException(java.util.concurrent.ExecutionException) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)

Example 4 with KieCompilationResponse

use of org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse in project kie-wb-common by kiegroup.

the class ConcurrentBuildTest method buildFourProjectsInTheSameThread.

// https://issues.redhat.com/browse/AF-2742
@Ignore
@Test
public void buildFourProjectsInTheSameThread() throws Exception {
    latch = new CountDownLatch(4);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    try {
        Callable<Map<Integer, KieCompilationResponse>> task1 = () -> {
            Map<Integer, KieCompilationResponse> map = new ConcurrentHashMap<>(2);
            KieCompilationResponse r1 = compileAndloadKieJarSingleMetadataWithPackagedJar();
            KieCompilationResponse r2 = compileAndLoadKieJarMetadataAllResourcesPackagedJar();
            KieCompilationResponse r3 = compileAndloadKieJarSingleMetadataWithPackagedJar();
            KieCompilationResponse r4 = compileAndLoadKieJarMetadataAllResourcesPackagedJar();
            map.put(1, r1);
            map.put(2, r2);
            map.put(3, r3);
            map.put(4, r4);
            return map;
        };
        Future<Map<Integer, KieCompilationResponse>> future = executor.submit(task1);
        latch.await();
        // blocking call
        Map<Integer, KieCompilationResponse> result = future.get();
        assertThat(result.get(1).isSuccessful()).isTrue();
        assertThat(result.get(2).isSuccessful()).isTrue();
        assertThat(result.get(3).isSuccessful()).isTrue();
        assertThat(result.get(4).isSuccessful()).isTrue();
        logger.info("\nFinished all threads");
    } catch (InterruptedException e) {
        logger.error("tasks interrupted");
    } finally {
        if (!executor.isTerminated()) {
            logger.error("cancel non-finished tasks");
        }
        executor.shutdownNow();
        logger.info("shutdown finished");
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with KieCompilationResponse

use of org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse in project kie-wb-common by kiegroup.

the class KieMetadataTest method compileAndloadKieJarSingleMetadataWithPackagedJar.

@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void compileAndloadKieJarSingleMetadataWithPackagedJar() throws Exception {
    /**
     * If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
     */
    Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_SINGLE_RESOURCES);
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_KIE_OBJECTS, KieDecorator.STORE_BUILD_CLASSPATH, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
    KieCompilationResponse res = (KieCompilationResponse) compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmp, res, this.getClass(), testName);
    if (!res.isSuccessful()) {
        List<String> msgs = res.getMavenOutput();
        for (String msg : msgs) {
            logger.info(msg);
        }
    }
    assertThat(res.isSuccessful()).isTrue();
    Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
    assertThat(metaDataOptional).isPresent();
    KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
    assertThat(kieModuleMetaInfo).isNotNull();
    Optional<KieModule> kieModuleOptional = res.getKieModule();
    assertThat(kieModuleOptional).isPresent();
    KieModule kModule = kieModuleOptional.get();
    assertThat(res.getDependenciesAsURI()).hasSize(4);
    KieModuleMetaData kieModuleMetaData = new KieModuleMetaDataImpl((InternalKieModule) kModule, res.getDependenciesAsURI());
    assertThat(kieModuleMetaData).isNotNull();
// comment if you want read the log file after the test run
}
Also used : Path(org.uberfire.java.nio.file.Path) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) KieModuleMetaDataImpl(org.kie.scanner.KieModuleMetaDataImpl) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) KieModuleMetaInfo(org.drools.core.rule.KieModuleMetaInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) AFCompiler(org.kie.workbench.common.services.backend.compiler.AFCompiler) CompilationRequest(org.kie.workbench.common.services.backend.compiler.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

KieCompilationResponse (org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse)65 Test (org.junit.Test)58 BaseCompilerTest (org.kie.workbench.common.services.backend.compiler.BaseCompilerTest)48 Ignore (org.junit.Ignore)30 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)17 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)13 CompilationRequest (org.kie.workbench.common.services.backend.compiler.CompilationRequest)12 Path (org.uberfire.java.nio.file.Path)11 AFCompiler (org.kie.workbench.common.services.backend.compiler.AFCompiler)7 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)6 KieModuleMetaInfo (org.drools.core.rule.KieModuleMetaInfo)6 KieModule (org.kie.api.builder.KieModule)6 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 InputStream (java.io.InputStream)5 HashMap (java.util.HashMap)5 BaseMavenCompiler (org.kie.workbench.common.services.backend.compiler.impl.BaseMavenCompiler)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3