Search in sources :

Example 16 with CompilationResponse

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

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

the class KieDefaultMavenCompilerTest method buildWithPullRebaseUberfireTest.

@Test
public void buildWithPullRebaseUberfireTest() throws Exception {
    // Setup origin in memory
    final URI originRepo = URI.create("git://repo");
    final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo, new HashMap<String, Object>() {

        {
            put("init", Boolean.TRUE);
            put("internal", Boolean.TRUE);
            put("listMode", "ALL");
        }
    });
    ioService.startBatch(origin);
    ioService.write(origin.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(origin.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/src/main/java/dummy/DummyA.java").toPath())));
    ioService.write(origin.getPath("/dummyB/src/main/java/dummy/DummyB.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/src/main/java/dummy/DummyB.java").toPath())));
    ioService.write(origin.getPath("/dummyA/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
    ioService.write(origin.getPath("/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
    ioService.endBatch();
    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone"));
    final Git cloned = Git.cloneRepository().setURI(origin.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(tmpCloned.toFile()).call();
    assertThat(cloned).isNotNull();
    PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
    PullResult pullRes = pc.call();
    // nothing changed yet
    assertThat(pullRes.getRebaseResult().getStatus()).isEqualTo(RebaseResult.Status.UP_TO_DATE);
    RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
    RebaseResult rbResult = rb.setPreserveMerges(true).call();
    assertThat(rbResult.getStatus().isSuccessful()).isTrue();
    // Compile the repo
    byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);
    Path prjFolder = Paths.get(tmpCloned + "/");
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpCloned, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    Path incrementalConfiguration = Paths.get(prjFolder + TestConstants.TARGET_TAKARI_PLUGIN);
    assertThat(incrementalConfiguration.toFile()).exists();
    encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).contains(TestConstants.KIE_TAKARI_LIFECYCLE_ARTIFACT);
    TestUtil.rm(tmpRootCloned.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) PullCommand(org.eclipse.jgit.api.PullCommand) HashMap(java.util.HashMap) RebaseCommand(org.eclipse.jgit.api.RebaseCommand) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) URI(java.net.URI) PullResult(org.eclipse.jgit.api.PullResult) TestUtilGit(org.kie.workbench.common.services.backend.compiler.TestUtilGit) Git(org.eclipse.jgit.api.Git) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) File(java.io.File) RebaseResult(org.eclipse.jgit.api.RebaseResult) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) 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 18 with CompilationResponse

use of org.kie.workbench.common.services.backend.compiler.CompilationResponse 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 19 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 = 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 20 with CompilationResponse

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

the class OutputLogAfterDecoratorTest method compileTest.

@Test
public void compileTest() {
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, 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()).isTrue();
        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