Search in sources :

Example 16 with WorkspaceCompilationInfo

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

the class ConcurrentBuildTest method compileAndloadKieJarSingleMetadataWithPackagedJar.

private KieCompilationResponse compileAndloadKieJarSingleMetadataWithPackagedJar() {
    String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
    Path tmpRoot = Files.createTempDirectory("repo_" + UUID.randomUUID().toString());
    Path tmp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
    try {
        TestUtil.copyTree(Paths.get(ResourcesConstants.KJAR_2_SINGLE_RESOURCES), tmp);
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_KIE_OBJECTS, KieDecorator.ENABLE_LOGGING));
    final KieCompilationResponse res;
    try {
        final WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
        final CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
        res = (KieCompilationResponse) compiler.compile(req);
        logger.info("\nFinished " + res.isSuccessful() + " Single metadata tmp:{} UUID:{} res.getMavenOutput().isEmpty():", tmp, req.getRequestUUID(), res.getMavenOutput().isEmpty());
        if (!res.isSuccessful()) {
            try {
                logger.error(" Fail, writing output on target folder:{}  UUID:", tmp, req.getRequestUUID());
                TestUtil.writeMavenOutputIntoTargetFolder(tmp, res.getMavenOutput(), "ConcurrentBuildTest.compileAndloadKieJarSingleMetadataWithPackagedJar_" + req.getRequestUUID());
            } catch (Exception e) {
                logger.error(e.getMessage());
            }
        }
    } finally {
        latch.countDown();
    }
    return res;
}
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) ExecutionException(java.util.concurrent.ExecutionException) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)

Example 17 with WorkspaceCompilationInfo

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

the class DefaultMavenCompilerTest method buildWithCloneTest.

@Test
public void buildWithCloneTest() throws Exception {
    final String repoName = "myrepo";
    final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName), new HashMap<String, Object>() {

        {
            put("init", Boolean.TRUE);
            put("internal", Boolean.TRUE);
        }
    });
    ioService.startBatch(fs);
    ioService.write(fs.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(fs.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(fs.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(fs.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(fs.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();
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), "dummy"));
    final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git");
    final Git cloned = Git.cloneRepository().setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(gitClonedFolder).call();
    assertThat(cloned).isNotNull();
    // Compile the repo
    Path prjFolder = Paths.get(gitClonedFolder + "/");
    byte[] encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);
    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) Git(org.eclipse.jgit.api.Git) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) HashMap(java.util.HashMap) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 18 with WorkspaceCompilationInfo

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

the class DefaultMavenCompilerTest method cleanInternalTest.

@Test
public void cleanInternalTest() throws Exception {
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.UPDATE_JGIT_BEFORE_BUILD));
    String MAIN_BRANCH = "master";
    // Setup origin in memory
    final URI originRepo = URI.create("git://xxsddsrepo");
    final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo, new HashMap<String, Object>() {

        {
            put("init", Boolean.TRUE);
            put("internal", Boolean.TRUE);
            put("listMode", "ALL");
        }
    });
    assertThat(origin).isNotNull();
    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();
    RevCommit lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
    assertThat(lastCommit).isNotNull();
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(origin.getPath("/"));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.FALSE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(origin.getPath("/"), res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
    assertThat(lastCommit).isNotNull();
    ioService.write(origin.getPath("/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/DummyA.java").toPath())));
    RevCommit commitBefore = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
    assertThat(commitBefore).isNotNull();
    assertThat(lastCommit.getId().toString()).isNotEqualTo(commitBefore.getId().toString());
    assertThat(compiler.cleanInternalCache()).isTrue();
    // recompile
    res = compiler.compile(req);
    // assert commits
    assertThat(res.isSuccessful()).isTrue();
}
Also used : WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) HashMap(java.util.HashMap) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) URI(java.net.URI) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 19 with WorkspaceCompilationInfo

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

the class MavenOutputTest 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(ResourcesConstants.DUMMY_DIR), tmpNio);
    Path tmp = Paths.get(tmpNio.toAbsolutePath().toString());
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpNio, 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) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 20 with WorkspaceCompilationInfo

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

the class DefaultRemoteExecutor method internalBuild.

private CompletableFuture<KieCompilationResponse> internalBuild(String projectPath, String mavenRepoPath, String settingsXmlPath, boolean skipProjectDepCreation, String goal) {
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(projectPath));
    AFCompiler compiler = getCompiler(projectPath);
    CompilationRequest req;
    if (settingsXmlPath != null) {
        req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingsXmlPath, goal }, skipProjectDepCreation);
    } else {
        req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { goal }, skipProjectDepCreation);
    }
    return runInItsOwnThread(compiler, req);
}
Also used : WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) 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)

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