Search in sources :

Example 21 with WorkspaceCompilationInfo

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

the class DefaultLocalExecutor method setupCompileInfo.

private CompilerAggregateEntryCache setupCompileInfo(Path workingDir) {
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.UPDATE_JGIT_BEFORE_BUILD, KieDecorator.STORE_KIE_OBJECTS, KieDecorator.STORE_BUILD_CLASSPATH, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(workingDir);
    return new CompilerAggregateEntryCache(compiler, info);
}
Also used : WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) AFCompiler(org.kie.workbench.common.services.backend.compiler.AFCompiler)

Example 22 with WorkspaceCompilationInfo

use of org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo 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) {
    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)), 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 23 with WorkspaceCompilationInfo

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

the class ClassLoaderProviderTest method getResourcesFromADroolsPRJ.

@Test
// https://issues.redhat.com/browse/AF-2892
@Ignore
public void getResourcesFromADroolsPRJ() throws Exception {
    /**
     * If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
     */
    String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
    Path tmpRoot = Files.createTempDirectory("repo");
    Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_SINGLE_RESOURCES);
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_KIE_OBJECTS, KieDecorator.STORE_BUILD_CLASSPATH, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.FALSE);
    KieCompilationResponse res = (KieCompilationResponse) compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmp, res, this.getClass(), testName);
    if (!res.isSuccessful()) {
        List<String> msgs = res.getMavenOutput();
        for (String msg : msgs) {
            logger.info(msg);
        }
    }
    assertThat(res.isSuccessful()).isTrue();
    Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
    assertThat(metaDataOptional).isPresent();
    KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
    assertThat(kieModuleMetaInfo).isNotNull();
    Optional<KieModule> kieModuleOptional = res.getKieModule();
    assertThat(kieModuleOptional).isPresent();
    KieModule kModule = kieModuleOptional.get();
    assertThat(res.getDependenciesAsURI()).hasSize(4);
    KieModuleMetaData kieModuleMetaData = new KieModuleMetaDataImpl((InternalKieModule) kModule, res.getDependenciesAsURI());
    assertThat(kieModuleMetaData).isNotNull();
    List<String> resources = CompilerClassloaderUtils.getStringFromTargets(tmpRoot);
    assertThat(resources).hasSize(3);
}
Also used : Path(org.uberfire.java.nio.file.Path) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) KieModuleMetaDataImpl(org.kie.scanner.KieModuleMetaDataImpl) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) KieModuleMetaInfo(org.drools.core.rule.KieModuleMetaInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with WorkspaceCompilationInfo

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

the class ClassLoaderProviderTest method getResourcesFromADroolsPRJWithErrorWithMavenSkip.

@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void getResourcesFromADroolsPRJWithErrorWithMavenSkip() throws Exception {
    System.setProperty(MAVEN_MAIN_SKIP, Boolean.TRUE.toString());
    /**
     * If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
     */
    Path tmpRoot = Files.createTempDirectory("repo");
    Path tmp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_SINGLE_RESOURCES_WITH_ERROR);
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_KIE_OBJECTS, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + TestUtilMaven.getSettingsFile() }, Boolean.FALSE);
    KieCompilationResponse res = (KieCompilationResponse) compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmp, res, this.getClass(), testName);
    if (!res.isSuccessful()) {
        List<String> msgs = res.getMavenOutput();
        for (String msg : msgs) {
            logger.info(msg);
        }
    }
    assertThat(res.isSuccessful()).isTrue();
    Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
    assertThat(metaDataOptional).isPresent();
    KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
    assertThat(kieModuleMetaInfo).isNotNull();
    Optional<KieModule> kieModuleOptional = res.getKieModule();
    assertThat(kieModuleOptional).isPresent();
    List<String> classloaderOptional = CompilerClassloaderUtils.getStringFromTargets(tmpRoot);
    assertThat(classloaderOptional).hasSize(3);
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) KieModuleMetaInfo(org.drools.core.rule.KieModuleMetaInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 25 with WorkspaceCompilationInfo

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

the class DefaultIncrementalCompilerEnablerTest method testReadKiePluginTest.

@Test
public void testReadKiePluginTest() 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_kie_multimodule_untouched"), temp);
    // end NIO
    Path tmp = Paths.get(tmpRoot.toAbsolutePath().toString(), "dummy");
    Path mainPom = Paths.get(tmp.toAbsolutePath().toString(), "pom.xml");
    byte[] encoded = Files.readAllBytes(Paths.get(tmp.toAbsolutePath().toString(), "pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);
    assertThat(pomAsAstring).doesNotContain("<packaging>kjar</packaging>");
    byte[] encodedDummyB = Files.readAllBytes(Paths.get(tmp.toAbsolutePath().toString(), "/dummyB/pom.xml"));
    String pomAsAstringDummyB = new String(encodedDummyB, StandardCharsets.UTF_8);
    assertThat(pomAsAstringDummyB).contains("<packaging>kjar</packaging>");
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.FALSE);
    DefaultIncrementalCompilerEnabler enabler = new DefaultIncrementalCompilerEnabler();
    assertThat(enabler.process(req).getResult()).isTrue();
    assertThat(info.isKiePluginPresent()).isTrue();
    encoded = Files.readAllBytes(Paths.get(mainPom.toString()));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).contains("kie-takari-plugin");
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) DefaultIncrementalCompilerEnabler(org.kie.workbench.common.services.backend.compiler.impl.incrementalenabler.DefaultIncrementalCompilerEnabler) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

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