Search in sources :

Example 1 with CompilationRequest

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

the class KieDefaultMavenIncrementalCompilerTest method testCheckIncrementalWithChanges.

@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void testCheckIncrementalWithChanges() throws Exception {
    String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
    tmpRoot = Files.createTempDirectory("repo");
    // NIO creation and copy content
    Path temp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_KIE_INCREMENTAL);
    // end NIO
    // compiler
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
    // checks
    assertThat(res.isSuccessful()).isTrue();
    List<String> fileNames = new ArrayList<>();
    // impl
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/target/classes/dummy"))) {
        for (Path path : directoryStream) {
            fileNames.add(path.toString());
        }
    }
    assertThat(fileNames).hasSize(2);
    String dummyJava;
    if (fileNames.get(0).endsWith("Dummy.class")) {
        dummyJava = fileNames.get(0);
    } else {
        dummyJava = fileNames.get(1);
    }
    long dummyJavaSize = Paths.get(dummyJava).toFile().length();
    List<String> output = res.getMavenOutput();
    assertThat(isTextPresent(output, "Previous incremental build state does not exist, performing full build")).isTrue();
    assertThat(isTextPresent(output, "Compiled 2 out of 2 sources ")).isTrue();
    Files.delete(Paths.get(temp + "/src/main/java/dummy/DummyA.java"));
    // overwrite the class with a new version with two additional methods and one int variable
    Files.write(Paths.get(temp + "/src/main/java/dummy/Dummy.java"), Files.readAllBytes(Paths.get("src/test/projects/Dummy.java")));
    // second compilation
    res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
    // checks
    assertThat(res.isSuccessful()).isTrue();
    fileNames = new ArrayList<>();
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/target/classes/dummy"))) {
        for (Path path : directoryStream) {
            fileNames.add(path.toString());
        }
    }
    assertThat(fileNames).hasSize(1);
    assertThat(fileNames.get(0)).endsWith("Dummy.class");
    long dummyJavaSizeAfterChanges = Paths.get(dummyJava).toFile().length();
    assertThat(dummyJavaSize).isLessThan(dummyJavaSizeAfterChanges);
    output = res.getMavenOutput();
    assertThat(isTextPresent(output, "Performing incremental build")).isTrue();
    assertThat(isTextPresent(output, "Compiled 1 out of 1 sources ")).isTrue();
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) ArrayList(java.util.ArrayList) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with CompilationRequest

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

Example 3 with CompilationRequest

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

the class KieMetadataTest method compileAndloadKieJarSingleMetadata.

@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void compileAndloadKieJarSingleMetadata() {
    /**
     * If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
     */
    try {
        Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_SINGLE_RESOURCES);
        final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, 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();
        assertThat(res.getDependenciesAsURI()).hasSize(4);
    // comment if you want read the log file after the test run
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) 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)

Example 4 with CompilationRequest

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

the class ArchetypeTest method testArchetypeGenerate.

@Test
public void testArchetypeGenerate() throws Exception {
    Path tmpRoot = Files.createTempDirectory("repo");
    Path tmp = Paths.get(tmpRoot.toAbsolutePath().toString());
    assertThat(isDirEmpty(tmpRoot)).isTrue();
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath.toAbsolutePath().toString(), info, new String[] { MavenConfig.ARCHETYPE_GENERATE, MavenConfig.ARCHETYPE_GENERATE_BLANK, MavenConfig.GROUP_ID + groupId, MavenConfig.ARTIFACT_ID + artifactId, MavenConfig.ARCHETYPE_ARTIFACT_ID + archetypeArtifactId }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpRoot, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    assertThat(res.getMavenOutput().size()).isGreaterThan(0);
    assertThat(isDirEmpty(tmpRoot)).isFalse();
    Path prj = Paths.get(tmpRoot.toAbsolutePath().toString(), artifactId);
    assertThat(isDirEmpty(prj)).isFalse();
    Path appDir = Paths.get(prj.toAbsolutePath().toString(), "/src/main/java/" + (groupId.replace(".", "/")));
    assertThat(isDirEmpty(appDir)).isFalse();
    Path testDir = Paths.get(prj.toAbsolutePath().toString(), "/src/test/java/" + (groupId.replace(".", "/")));
    assertThat(isDirEmpty(testDir)).isFalse();
    Path pom = Paths.get(tmpRoot.toAbsolutePath().toString(), artifactId + "/pom.xml");
    assertThat(Files.exists(pom)).isTrue();
    TestUtil.rm(tmpRoot.toFile());
}
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) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) 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) Test(org.junit.Test)

Example 5 with CompilationRequest

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

the class DefaultPomEditorTest method cleanHistoryTest.

@Test
public void cleanHistoryTest() {
    assertThat(editor.getHistory()).isEmpty();
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
    editor.write(Paths.get(tmpRoot.toAbsolutePath() + "/dummy/pom.xml"), req);
    assertThat(editor.getHistory()).isNotEmpty();
    editor.cleanHistory();
    assertThat(editor.getHistory()).isEmpty();
}
Also used : DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) 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)

Aggregations

CompilationRequest (org.kie.workbench.common.services.backend.compiler.CompilationRequest)43 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)43 Test (org.junit.Test)34 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)30 AFCompiler (org.kie.workbench.common.services.backend.compiler.AFCompiler)24 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)23 Path (org.uberfire.java.nio.file.Path)19 BaseCompilerTest (org.kie.workbench.common.services.backend.compiler.BaseCompilerTest)16 BaseMavenCompiler (org.kie.workbench.common.services.backend.compiler.impl.BaseMavenCompiler)12 KieCompilationResponse (org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse)12 HashMap (java.util.HashMap)10 Ignore (org.junit.Ignore)10 File (java.io.File)9 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)8 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 URI (java.net.URI)4 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)3 KieModuleMetaInfo (org.drools.core.rule.KieModuleMetaInfo)3 Git (org.eclipse.jgit.api.Git)3