Search in sources :

Example 16 with DefaultCompilationRequest

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

the class ClassLoaderProviderTest method compileProjectInRepo.

private CompilationResponse compileProjectInRepo(String... mavenPhases) throws IOException {
    // we use NIO for this part of the test because Uberfire lack the implementation to copy a tree
    tmpRoot = Files.createTempDirectory("repo");
    tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_KIE_MULTIMODULE_CLASSLOADER_DIR);
    uberfireTmp = Paths.get(tmp.toAbsolutePath().toString());
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(new HashSet<>());
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(uberfireTmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, mavenPhases, Boolean.FALSE);
    return compiler.compile(req);
}
Also used : WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)

Example 17 with DefaultCompilationRequest

use of org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest 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 18 with DefaultCompilationRequest

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

the class DefaultIncrementalCompilerEnablerTest method testReadPomsInaPrjTest.

@Test
public void testReadPomsInaPrjTest() throws Exception {
    FileSystemProvider fs = FileSystemProviders.getDefaultProvider();
    Path tmpRoot = Files.createTempDirectory("repo");
    // NIO creation and copy content
    Path temp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
    TestUtil.copyTree(Paths.get("src/test/projects/dummy_multimodule_untouched"), temp);
    // end NIO
    Path tmp = Paths.get(tmpRoot.toAbsolutePath().toString(), "dummy");
    Path mainPom = Paths.get(temp.toAbsolutePath().toString(), "pom.xml");
    byte[] encoded = Files.readAllBytes(Paths.get(temp.toAbsolutePath().toString(), "pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.FALSE);
    DefaultIncrementalCompilerEnabler enabler = new DefaultIncrementalCompilerEnabler();
    assertThat(enabler.process(req).getResult()).isTrue();
    encoded = Files.readAllBytes(Paths.get(mainPom.toString()));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).contains(TestConstants.KIE_TAKARI_LIFECYCLE_ARTIFACT);
    assertThat(pomAsAstring.contains("kie-takari-plugin")).isFalse();
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) FileSystemProvider(org.uberfire.java.nio.file.spi.FileSystemProvider) DefaultIncrementalCompilerEnabler(org.kie.workbench.common.services.backend.compiler.impl.incrementalenabler.DefaultIncrementalCompilerEnabler) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 19 with DefaultCompilationRequest

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

the class ClasspathDepsAfterDecoratorTest method failCompileTest.

@Test
public void failCompileTest() throws IOException {
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, createdNewPrjInRepo("dummy-fail", ResourcesConstants.DUMMY_FAIL_DEPS_SIMPLE), new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
    ClasspathDepsAfterDecorator decorator = new ClasspathDepsAfterDecorator(new BaseMavenCompiler(false, false));
    CompilationResponse res = decorator.compile(req);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(res.isSuccessful()).isFalse();
        softly.assertThat(res.getDependencies()).hasSize(0);
    });
}
Also used : DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) 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) BaseCompilerTest(org.kie.workbench.common.services.backend.compiler.BaseCompilerTest) Test(org.junit.Test)

Example 20 with DefaultCompilationRequest

use of org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest 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)

Aggregations

DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)60 Test (org.junit.Test)51 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)47 CompilationRequest (org.kie.workbench.common.services.backend.compiler.CompilationRequest)40 Path (org.uberfire.java.nio.file.Path)36 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)23 AFCompiler (org.kie.workbench.common.services.backend.compiler.AFCompiler)21 BaseCompilerTest (org.kie.workbench.common.services.backend.compiler.BaseCompilerTest)16 HashMap (java.util.HashMap)15 File (java.io.File)14 Ignore (org.junit.Ignore)14 KieCompilationResponse (org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse)14 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)13 BaseMavenCompiler (org.kie.workbench.common.services.backend.compiler.impl.BaseMavenCompiler)12 URI (java.net.URI)8 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)6 KieModuleMetaInfo (org.drools.core.rule.KieModuleMetaInfo)6 Git (org.eclipse.jgit.api.Git)6