Search in sources :

Example 6 with WorkspaceCompilationInfo

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

the class KieDefaultMavenCompilerTest method buildCompileWithOverrideOnRegularFSTest.

@Test
public void buildCompileWithOverrideOnRegularFSTest() throws Exception {
    String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
    Path tmpRoot = Files.createTempDirectory("repo");
    // NIO creation and copy content
    Path temp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
    TestUtil.copyTree(Paths.get("target/test-classes/dummy"), temp);
    // end NIO
    byte[] pomOverride = Files.readAllBytes(Paths.get("target/test-classes/dummy_override/pom.xml"));
    Files.write(Paths.get(temp.toString(), "pom.xml"), pomOverride);
    byte[] encoded = Files.readAllBytes(Paths.get(temp.toString(), "/src/main/java/dummy/Dummy.java"));
    String dummyAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(dummyAsAstring).doesNotContain("public Dummy(Integer age).isFalse() {\n" + "        this.age = age;\n" + "    }");
    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);
    assertThat(res.isSuccessful()).isTrue();
    assertThat(new File(req.getInfo().getPrjPath() + "/target/classes/dummy/DummyOverride.class")).doesNotExist();
    // change some files
    Map<org.uberfire.java.nio.file.Path, InputStream> override = new HashMap<>();
    org.uberfire.java.nio.file.Path path = org.uberfire.java.nio.file.Paths.get(req.getInfo().getPrjPath() + "/src/main/java/dummy/DummyOverride.java");
    InputStream input = new FileInputStream(new File(ResourcesConstants.DUMMY_OVERRIDE + "/src/main/java/dummy/DummyOverride.java"));
    override.put(path, input);
    org.uberfire.java.nio.file.Path pathTwo = org.uberfire.java.nio.file.Paths.get(req.getInfo().getPrjPath() + "/src/main/java/dummy/Dummy.java");
    InputStream inputTwo = new FileInputStream(new File(ResourcesConstants.DUMMY_OVERRIDE + "/src/main/java/dummy/Dummy.java"));
    override.put(pathTwo, inputTwo);
    // recompile
    res = compiler.compile(req, override);
    assertThat(res.isSuccessful()).isTrue();
    assertThat(new File(req.getInfo().getPrjPath() + "/target/classes/dummy/Dummy.class").exists()).isFalse();
    assertThat(new File(req.getInfo().getPrjPath() + "/target/classes/dummy/DummyOverride.class")).exists();
    encoded = Files.readAllBytes(Paths.get(req.getInfo().getPrjPath().toString(), "/src/main/java/dummy/Dummy.java"));
    dummyAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(dummyAsAstring).contains("public Dummy(String name) {\n" + "        this.name = name;\n" + "    }");
    TestUtil.rm(temp.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Path(org.uberfire.java.nio.file.Path) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) FileInputStream(java.io.FileInputStream) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) File(java.io.File) 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 7 with WorkspaceCompilationInfo

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

the class KieMavenOutputTest method testOutputWithTakari.

@Test
public void testOutputWithTakari() throws Exception {
    Path tmpRoot = Files.createTempDirectory("repo");
    Path tmpNio = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_DIR);
    Path tmp = Paths.get(tmpNio.toAbsolutePath().toString());
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING));
    // final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.LOG_AFTER);
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmp, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    assertThat(res.getMavenOutput().size()).isGreaterThan(0);
    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 8 with WorkspaceCompilationInfo

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

the class KieDefaultMavenIncrementalCompilerTest method testIncrementalWithPluginEnabledThreeTime.

@Test
public void testIncrementalWithPluginEnabledThreeTime() throws Exception {
    tmpRoot = Files.createTempDirectory("repo");
    // NIO creation and copy content
    Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_DIR);
    // end NIO
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.FALSE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmp, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    res = compiler.compile(req);
    assertThat(res.isSuccessful()).isTrue();
    res = compiler.compile(req);
    assertThat(res.isSuccessful()).isTrue();
    Path incrementalConfiguration = Paths.get(tmp.toAbsolutePath().toString(), "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile");
    assertThat(incrementalConfiguration.toFile()).exists();
}
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 9 with WorkspaceCompilationInfo

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

the class DefaultMavenIncrementalCompilerTest method testIsValidMavenHome.

@Test
public void testIsValidMavenHome() throws Exception {
    Path temp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_DIR);
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(new HashSet<>());
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.VERSION }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
}
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) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 10 with WorkspaceCompilationInfo

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

the class DefaultMavenIncrementalCompilerTest method testError.

@Test
public void testError() throws Exception {
    Path temp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.DUMMY_KIE_MULTIMODULE_UNTOUCHED_WITH_ERROR_DIR);
    // compiler
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE, MavenCLIArgs.FAIL_NEVER }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
    // checks
    assertThat(res.isSuccessful()).isTrue();
    List<String> fileNames = new ArrayList<>();
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/dummyA/target/classes/dummy"))) {
        for (Path path : directoryStream) {
            fileNames.add(path.toString());
        }
    }
    assertThat(fileNames).hasSize(1);
    String dummyAJava = null;
    if (fileNames.get(0).endsWith("DummyA.class")) {
        dummyAJava = fileNames.get(0);
    }
    assertThat(dummyAJava).isNotNull();
    fileNames = new ArrayList<>();
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/dummyB/target/classes/dummy"))) {
        for (Path path : directoryStream) {
            fileNames.add(path.toString());
        }
    }
    assertThat(fileNames).hasSize(1);
    String dummyBJava = null;
    if (fileNames.get(0).endsWith("DummyB.class")) {
        dummyBJava = fileNames.get(0);
    }
    assertThat(dummyBJava).isNotNull();
    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();
    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) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Aggregations

WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)52 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)50 Test (org.junit.Test)38 Path (org.uberfire.java.nio.file.Path)34 CompilationRequest (org.kie.workbench.common.services.backend.compiler.CompilationRequest)30 AFCompiler (org.kie.workbench.common.services.backend.compiler.AFCompiler)26 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)18 HashMap (java.util.HashMap)13 KieCompilationResponse (org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse)13 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)13 File (java.io.File)12 Ignore (org.junit.Ignore)12 URI (java.net.URI)8 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)6 KieModuleMetaInfo (org.drools.core.rule.KieModuleMetaInfo)6 Git (org.eclipse.jgit.api.Git)6 KieModule (org.kie.api.builder.KieModule)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4