Search in sources :

Example 36 with CompilationResponse

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

the class KieDefaultMavenIncrementalCompilerTest method testIncrementalWithPluginEnabledThreeTime.

@Test
public void testIncrementalWithPluginEnabledThreeTime() 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.testIncrementalWithPluginEnabledThreeTime");
    }
    Assert.assertTrue(res.isSuccessful());
    res = compiler.compileSync(req);
    Assert.assertTrue(res.isSuccessful());
    res = compiler.compileSync(req);
    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 37 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 {
    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.VERSION }, new HashMap<>(), Boolean.FALSE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenIncrementalCompilerTest.testIsValidMavenHome");
    }
    Assert.assertTrue(res.isSuccessful());
    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 38 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
public void testCheckIncrementalWithChanges() throws Exception {
    String alternateSettingsAbsPath = new File("src/test/settings.xml").getAbsolutePath();
    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_kie_incremental"), temp);
    // end NIO
    // compiler
    AFCompiler compiler = MavenCompilerFactory.getCompiler(Decorator.LOG_OUTPUT_AFTER);
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, new HashMap<>(), Boolean.TRUE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenIncrementalCompilerTest.testCheckIncrementalWithChanges");
    }
    // checks
    Assert.assertTrue(res.isSuccessful());
    List<String> fileNames = new ArrayList<>();
    // nio
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/target/classes/dummy"))) {
        for (Path path : directoryStream) {
            fileNames.add(path.toString());
        }
    }
    Assert.assertTrue(fileNames.size() == 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();
    Assert.assertTrue(res.getMavenOutput().isPresent());
    List<String> output = res.getMavenOutput().get();
    Assert.assertTrue(isPresent(output, "Previous incremental build state does not exist, performing full build"));
    Assert.assertTrue(isPresent(output, "Compiled 2 out of 2 sources "));
    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.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenIncrementalCompilerTest.testCheckIncrementalWithChanges");
    }
    // checks
    Assert.assertTrue(res.isSuccessful());
    fileNames = new ArrayList<>();
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(temp + "/target/classes/dummy"))) {
        for (Path path : directoryStream) {
            fileNames.add(path.toString());
        }
    }
    Assert.assertTrue(fileNames.size() == 1);
    Assert.assertTrue(fileNames.get(0).endsWith("Dummy.class"));
    long dummyJavaSizeAfterChanges = Paths.get(dummyJava).toFile().length();
    Assert.assertTrue(dummyJavaSize < dummyJavaSizeAfterChanges);
    Assert.assertTrue(res.getMavenOutput().isPresent());
    output = res.getMavenOutput().get();
    Assert.assertTrue(isPresent(output, "Performing incremental build"));
    Assert.assertTrue(isPresent(output, "Compiled 1 out of 1 sources "));
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) ArrayList(java.util.ArrayList) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) File(java.io.File) 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 39 with CompilationResponse

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

the class ClasspathDepsAfterDecoratorTest method compileTest.

@Test
public void compileTest() {
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
    ClasspathDepsAfterDecorator decorator = new ClasspathDepsAfterDecorator(new BaseMavenCompiler(true, false));
    CompilationResponse res = decorator.compile(req);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(res.isSuccessful()).isTrue();
        softly.assertThat(res.getDependencies()).hasSize(4);
    });
}
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 40 with CompilationResponse

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

the class OutputLogAfterDecoratorTest method compileFailedTest.

@Test
public void compileFailedTest() throws Exception {
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, createdNewPrjInRepo("dummy-fail", ResourcesConstants.DUMMY_FAIL_DEPS_SIMPLE), new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
    OutputLogAfterDecorator decorator = new OutputLogAfterDecorator(new BaseMavenCompiler(true, true));
    CompilationResponse res = decorator.compile(req);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(res.isSuccessful()).isFalse();
        softly.assertThat(res.getMavenOutput().size()).isGreaterThan(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)

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