Search in sources :

Example 31 with CompilationRequest

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

the class KieDefaultMavenCompilerTest method buildWithAllDecoratorsTest.

@Test
@Ignore("https://issues.redhat.com/browse/AF-2892")
public void buildWithAllDecoratorsTest() throws Exception {
    String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
    String MAIN_BRANCH = "master";
    // 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");
        }
    });
    assertThat(origin).isNotNull();
    ioService.startBatch(origin);
    ioService.write(origin.getPath("/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/pom.xml").toPath())));
    ioService.write(origin.getPath("/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java").toPath())));
    ioService.write(origin.getPath("/src/main/resources/AllResourceTypes/simple-rules.drl"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl").toPath())));
    ioService.write(origin.getPath("/src/main/resources/META-INF/kmodule.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml").toPath())));
    ioService.endBatch();
    RevCommit lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
    assertThat(lastCommit).isNotNull();
    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone.git"));
    final Git cloned = Git.cloneRepository().setURI(origin.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(tmpCloned.toFile()).call();
    assertThat(cloned).isNotNull();
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.UPDATE_JGIT_BEFORE_BUILD, KieDecorator.ENABLE_LOGGING));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmpCloned + "/"));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpCloned, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
    assertThat(lastCommit).isNotNull();
    // change one file and commit on the origin repo
    ioService.write(origin.getPath("/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/Person.java").toPath())));
    RevCommit commitBefore = origin.getGit().resolveRevCommit(origin.getGit().getRef(MAIN_BRANCH).getObjectId());
    assertThat(commitBefore).isNotNull();
    assertThat(lastCommit.getId().toString()).isNotEqualTo(commitBefore.getId().toString());
    // recompile
    res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tmpCloned, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    TestUtil.rm(tmpRootCloned.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) HashMap(java.util.HashMap) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) URI(java.net.URI) 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) 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) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with CompilationRequest

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

the class JGITCompilerBeforeDecoratorTest method compileTestTwo.

@Test
public void compileTestTwo() throws Exception {
    final FileSystem fileSystem = createFileSystem("myrepodecorator");
    // Compile the repo
    JGITCompilerBeforeDecorator compiler = new JGITCompilerBeforeDecorator(new BaseMavenCompiler(true, false));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(fileSystem.getPath("/"));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    final java.nio.file.Path tempPath = ((Git) compiler.getGitMap().get(fileSystem)).getRepository().getDirectory().toPath().getParent();
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tempPath, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    final Path incrementalConfiguration = Paths.get(tempPath.toUri() + TARGET_TAKARI_PLUGIN);
    assertThat(incrementalConfiguration.toFile()).exists();
    TestUtil.rm(tempPath.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) FileSystem(org.uberfire.java.nio.file.FileSystem) 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) Path(org.uberfire.java.nio.file.Path) 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 33 with CompilationRequest

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

the class JGITCompilerBeforeDecoratorTest method compileWithOverrideTest.

@Test
public void compileWithOverrideTest() throws Exception {
    final FileSystem fileSystem = createFileSystem("myrepo");
    // Compile the repo
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(fileSystem.getPath("/"));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);
    Map<Path, InputStream> override = new HashMap<>();
    org.uberfire.java.nio.file.Path path = fileSystem.getPath("/", "/dummyA/src/main/java/dummy/Person.java");
    InputStream input = new FileInputStream(new File("target/test-classes/kjar-2-single-resources_override/src/main/java/dummy/PersonOverride.java"));
    override.put(path, input);
    JGITCompilerBeforeDecorator compiler = new JGITCompilerBeforeDecorator(new BaseMavenCompiler(true, false));
    CompilationResponse res = compiler.compile(req, override);
    final java.nio.file.Path tempPath = ((Git) compiler.getGitMap().get(fileSystem)).getRepository().getDirectory().toPath().getParent();
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(tempPath, res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    final Path incrementalConfiguration = Paths.get(tempPath.toUri() + TARGET_TAKARI_PLUGIN);
    assertThat(incrementalConfiguration.toFile().exists()).isTrue();
    TestUtil.rm(tempPath.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) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) FileSystem(org.uberfire.java.nio.file.FileSystem) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) File(java.io.File) BaseMavenCompiler(org.kie.workbench.common.services.backend.compiler.impl.BaseMavenCompiler) Path(org.uberfire.java.nio.file.Path) 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 34 with CompilationRequest

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

the class KieMetadataTest method compileAndLoadKieJarMetadataAllResourcesPackagedJar.

@Ignore("https://issues.redhat.com/browse/AF-2741\n" + "https://issues.redhat.com/browse/AF-2892")
// AF-1459 it tooks 30% of the time of the time spent by all module's test (108), alone it took 30 sec
@Test
public void compileAndLoadKieJarMetadataAllResourcesPackagedJar() throws Exception {
    /**
     * If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
     */
    Path temp = TestUtil.createAndCopyToDirectory(tmpRoot, "dummy", ResourcesConstants.KJAR_2_ALL_RESOURCES);
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.STORE_KIE_OBJECTS, KieDecorator.STORE_BUILD_CLASSPATH, KieDecorator.ENABLE_INCREMENTAL_BUILD));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
    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(temp, 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();
    Map<String, Set<String>> rulesBP = kieModuleMetaInfo.getRulesByPackage();
    assertThat(rulesBP).hasSize(6);
    Map<String, TypeMetaInfo> typesMI = kieModuleMetaInfo.getTypeMetaInfos();
    // This is a "magic number" test and may or may not be valid since changes
    // to the mechanism for generating classes, especially in PMML processing,
    // may cause this value to change.
    assertThat(typesMI).hasSize(22);
    Optional<KieModule> kieModuleOptional = res.getKieModule();
    assertThat(kieModuleOptional).isPresent();
    assertThat(res.getDependenciesAsURI()).hasSize(4);
    KieModule kModule = kieModuleOptional.get();
    KieModuleMetaData kieModuleMetaData = new KieModuleMetaDataImpl((InternalKieModule) kModule, res.getDependenciesAsURI());
    assertThat(kieModuleMetaData).isNotNull();
}
Also used : Path(org.uberfire.java.nio.file.Path) EnumSet(java.util.EnumSet) Set(java.util.Set) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) KieModuleMetaDataImpl(org.kie.scanner.KieModuleMetaDataImpl) TypeMetaInfo(org.drools.core.rule.TypeMetaInfo) 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) 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) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with CompilationRequest

use of org.kie.workbench.common.services.backend.compiler.CompilationRequest 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)

Aggregations

CompilationRequest (org.kie.workbench.common.services.backend.compiler.CompilationRequest)43 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)43 Test (org.junit.Test)34 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)30 AFCompiler (org.kie.workbench.common.services.backend.compiler.AFCompiler)24 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)23 Path (org.uberfire.java.nio.file.Path)19 BaseCompilerTest (org.kie.workbench.common.services.backend.compiler.BaseCompilerTest)16 BaseMavenCompiler (org.kie.workbench.common.services.backend.compiler.impl.BaseMavenCompiler)12 KieCompilationResponse (org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse)12 HashMap (java.util.HashMap)10 Ignore (org.junit.Ignore)10 File (java.io.File)9 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)8 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 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