Search in sources :

Example 11 with CompilationResponse

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

the class KieDefaultMavenIncrementalCompilerTest method testIncrementalWithPluginEnabled.

@Test
public void testIncrementalWithPluginEnabled() throws Exception {
    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"), temp);
    // end NIO
    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.NONE);
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.FALSE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenIncrementalCompilerTest.testIncrementalWithPluginEnabled");
    }
    Assert.assertTrue(res.isSuccessful());
    Path incrementalConfiguration = Paths.get(temp.toAbsolutePath().toString(), "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile");
    Assert.assertTrue(incrementalConfiguration.toFile().exists());
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) AFCompiler(org.kie.workbench.common.services.backend.compiler.nio.AFCompiler) CompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 12 with CompilationResponse

use of org.kie.workbench.common.services.backend.compiler.CompilationResponse 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 = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
    TestUtil.copyTree(Paths.get("src/test/projects/dummy"), tmpNio);
    Path tmp = Paths.get(tmpNio.toAbsolutePath().toString());
    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.LOG_OUTPUT_AFTER);
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.TRUE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieMavenOutputTest.testOutputWithTakari");
    }
    assertTrue(res.isSuccessful());
    assertTrue(res.getMavenOutput().isPresent());
    assertTrue(res.getMavenOutput().get().size() > 0);
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) AFCompiler(org.kie.workbench.common.services.backend.compiler.nio.AFCompiler) CompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 13 with CompilationResponse

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

the class KieDefaultMavenIncrementalCompilerTest method testIsValidMavenHome.

@Test
public void testIsValidMavenHome() throws Exception {
    CompilationResponse res = compileProjectInRepo(MavenCLIArgs.VERSION);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
}
Also used : CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) Test(org.junit.Test)

Example 14 with CompilationResponse

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

the class KieDefaultMavenIncrementalCompilerTest method testIncrementalWithPluginEnabled.

@Test
public void testIncrementalWithPluginEnabled() throws Exception {
    CompilationResponse res = compileProjectInRepo(MavenCLIArgs.COMPILE);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(temp, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    Path incrementalConfiguration = Paths.get(temp.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) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) Test(org.junit.Test)

Example 15 with CompilationResponse

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

Aggregations

CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)53 Test (org.junit.Test)51 Path (org.uberfire.java.nio.file.Path)38 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest)24 CompilationRequest (org.kie.workbench.common.services.backend.compiler.CompilationRequest)23 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)23 File (java.io.File)18 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)18 HashMap (java.util.HashMap)17 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)16 AFCompiler (org.kie.workbench.common.services.backend.compiler.AFCompiler)13 AFCompiler (org.kie.workbench.common.services.backend.compiler.nio.AFCompiler)13 CompilationRequest (org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest)13 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo)13 URLClassLoader (java.net.URLClassLoader)11 URI (java.net.URI)10 Git (org.eclipse.jgit.api.Git)9 BaseCompilerTest (org.kie.workbench.common.services.backend.compiler.BaseCompilerTest)8 BaseMavenCompiler (org.kie.workbench.common.services.backend.compiler.impl.BaseMavenCompiler)8 ArrayList (java.util.ArrayList)7