Search in sources :

Example 21 with AFCompiler

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

the class DefaultLocalExecutor method internalBuild.

private CompletableFuture<KieCompilationResponse> internalBuild(Path projectPath, String mavenRepoPath, String settingXML, boolean skipProjectDepCreation, String goal, Map<Path, InputStream> override) {
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(projectPath);
    AFCompiler compiler = getCompiler(projectPath);
    CompilationRequest req;
    if (settingXML != null) {
        req = getDefaultRequest(mavenRepoPath, info, skipProjectDepCreation, new String[] { MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingXML, goal });
    } else {
        req = getDefaultRequest(mavenRepoPath, info, skipProjectDepCreation, new String[] { goal });
    }
    return CompletableFuture.supplyAsync(() -> ((KieCompilationResponse) compiler.compile(req, override)), executor);
}
Also used : WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) 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) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse)

Example 22 with AFCompiler

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

the class DefaultRemoteExecutor method internalBuild.

private CompletableFuture<KieCompilationResponse> internalBuild(String projectPath, String mavenRepoPath, boolean skipProjectDepCreation, String[] args) {
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(projectPath));
    AFCompiler compiler = getCompiler(projectPath);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, args, 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)

Example 23 with AFCompiler

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

the class DefaultRemoteExecutor method setupCompileInfo.

private CompilerAggregateEntryCache setupCompileInfo(String workingDir) {
    AFCompiler compiler = new KieAfterDecorator(new OutputLogAfterDecorator(new ClasspathDepsAfterDecorator(new BaseMavenCompiler(true, true))));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(workingDir));
    return new CompilerAggregateEntryCache(compiler, info);
}
Also used : KieAfterDecorator(org.kie.workbench.common.services.backend.compiler.impl.decorators.KieAfterDecorator) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) ClasspathDepsAfterDecorator(org.kie.workbench.common.services.backend.compiler.impl.decorators.ClasspathDepsAfterDecorator) OutputLogAfterDecorator(org.kie.workbench.common.services.backend.compiler.impl.decorators.OutputLogAfterDecorator) BaseMavenCompiler(org.kie.workbench.common.services.backend.compiler.impl.BaseMavenCompiler) AFCompiler(org.kie.workbench.common.services.backend.compiler.AFCompiler)

Example 24 with AFCompiler

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

the class CompilerClassloaderUtils method getClassloaderFromAllDependencies.

/**
 * It run a maven build-classpath in memory and return a classloader with only this deps
 * @param prjPath
 * @param localRepo
 * @return
 */
public static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath, String localRepo, String settingsXmlPath) {
    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(URI.create(CommonConstants.FILE_URI + prjPath)));
    CompilationRequest req;
    if (settingsXmlPath != null) {
        req = new DefaultCompilationRequest(localRepo, info, new String[] { MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH, MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingsXmlPath }, Boolean.FALSE);
    } else {
        req = new DefaultCompilationRequest(localRepo, info, new String[] { MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH }, Boolean.FALSE);
    }
    CompilationResponse res = compiler.compile(req);
    if (res.isSuccessful()) {
        /**
         * Maven dependency plugin is not able to append the modules classpath using an absolute path in -Dmdep.outputFile,
         *             it override each time and at the end only the last writted is present in  the file,
         *             for this reason we use a relative path and then we read each file present in each module to build a unique classpath file
         */
        if (!res.getDependencies().isEmpty()) {
            Optional<ClassLoader> urlClassLoader = CompilerClassloaderUtils.createClassloaderFromStringDeps(res.getDependencies());
            if (urlClassLoader.isPresent()) {
                return urlClassLoader;
            }
        }
    }
    return Optional.empty();
}
Also used : WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) URLClassLoader(java.net.URLClassLoader) 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)

Example 25 with AFCompiler

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

the class KieDefaultMavenCompilerTest method buildWithCloneTest.

@Test
public void buildWithCloneTest() throws Exception {
    final String repoName = "myrepoxxxx";
    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("target/test-classes/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("target/test-classes/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("target/test-classes/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("target/test-classes/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
    ioService.write(fs.getPath("/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
    ioService.endBatch();
    Path tmpCloned = Files.createTempDirectory("cloned");
    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.FALSE);
    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(tmpCloned.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) 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) HashMap(java.util.HashMap) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) File(java.io.File) 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)

Aggregations

AFCompiler (org.kie.workbench.common.services.backend.compiler.AFCompiler)39 Test (org.junit.Test)27 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)26 CompilationRequest (org.kie.workbench.common.services.backend.compiler.CompilationRequest)24 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)24 Path (org.uberfire.java.nio.file.Path)14 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)13 KieAfterDecorator (org.kie.workbench.common.services.backend.compiler.impl.decorators.KieAfterDecorator)8 OutputLogAfterDecorator (org.kie.workbench.common.services.backend.compiler.impl.decorators.OutputLogAfterDecorator)7 KieCompilationResponse (org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse)7 File (java.io.File)6 HashMap (java.util.HashMap)6 Ignore (org.junit.Ignore)5 ClasspathDepsAfterDecorator (org.kie.workbench.common.services.backend.compiler.impl.decorators.ClasspathDepsAfterDecorator)5 JGITCompilerBeforeDecorator (org.kie.workbench.common.services.backend.compiler.impl.decorators.JGITCompilerBeforeDecorator)5 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)5 URI (java.net.URI)4 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)3 KieModuleMetaInfo (org.drools.core.rule.KieModuleMetaInfo)3 Git (org.eclipse.jgit.api.Git)3