Search in sources :

Example 11 with DefaultCompilationRequest

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

the class KieDefaultMavenIncrementalCompilerTest method testIncrementalWithPluginEnabled.

@Test
public void testIncrementalWithPluginEnabled() 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"), temp);
    // end NIO
    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.NONE);
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.FALSE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenIncrementalCompilerTest.testIncrementalWithPluginEnabled");
    }
    Assert.assertTrue(res.isSuccessful());
    Path incrementalConfiguration = Paths.get(temp.toAbsolutePath().toString(), "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile");
    Assert.assertTrue(incrementalConfiguration.toFile().exists());
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) AFCompiler(org.kie.workbench.common.services.backend.compiler.nio.AFCompiler) CompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 12 with DefaultCompilationRequest

use of org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest 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 = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
    TestUtil.copyTree(Paths.get("src/test/projects/dummy"), tmpNio);
    Path tmp = Paths.get(tmpNio.toAbsolutePath().toString());
    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.LOG_OUTPUT_AFTER);
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.TRUE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieMavenOutputTest.testOutputWithTakari");
    }
    assertTrue(res.isSuccessful());
    assertTrue(res.getMavenOutput().isPresent());
    assertTrue(res.getMavenOutput().get().size() > 0);
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) AFCompiler(org.kie.workbench.common.services.backend.compiler.nio.AFCompiler) CompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 13 with DefaultCompilationRequest

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

the class JGITCompilerBeforeDecorator method compileSync.

@Override
public T compileSync(CompilationRequest _req) {
    final Path path = _req.getInfo().getPrjPath();
    final CompilationRequest req;
    Git repo;
    if (path.getFileSystem() instanceof JGitFileSystem) {
        final JGitFileSystem fs = (JGitFileSystem) path.getFileSystem();
        if (!gitMap.containsKey(fs)) {
            repo = JGitUtils.tempClone(fs, _req.getRequestUUID());
            gitMap.put(fs, repo);
        }
        repo = gitMap.get(fs);
        JGitUtils.applyBefore(repo);
        req = new DefaultCompilationRequest(_req.getMavenRepo(), new WorkspaceCompilationInfo(Paths.get(repo.getRepository().getDirectory().toPath().getParent().resolve(path.getFileName().toString()).normalize().toUri())), _req.getOriginalArgs(), _req.getMap(), _req.getLogRequested());
    } else {
        req = _req;
    }
    return compiler.compileSync(req);
}
Also used : Path(org.uberfire.java.nio.file.Path) Git(org.eclipse.jgit.api.Git) WorkspaceCompilationInfo(org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) CompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem)

Example 14 with DefaultCompilationRequest

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

the class DefaultIncrementalCompilerEnablerTest method testReadPomsInaPrjTest.

@Test
public void testReadPomsInaPrjTest() throws Exception {
    FileSystemProvider fs = FileSystemProviders.getDefaultProvider();
    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_multimodule_untouched"), temp);
    // end NIO
    Path tmp = Paths.get(tmpRoot.toAbsolutePath().toString(), "dummy");
    Path mainPom = Paths.get(temp.toAbsolutePath().toString(), "pom.xml");
    byte[] encoded = Files.readAllBytes(Paths.get(temp.toAbsolutePath().toString(), "pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertFalse(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(tmp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.FALSE);
    DefaultIncrementalCompilerEnabler enabler = new DefaultIncrementalCompilerEnabler(Compilers.JAVAC);
    Assert.assertTrue(enabler.process(req).getResult());
    encoded = Files.readAllBytes(Paths.get(mainPom.toString()));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    Assert.assertTrue(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));
    assertFalse(pomAsAstring.contains("kie-takari-plugin"));
    TestUtil.rm(tmpRoot.toFile());
}
Also used : Path(org.uberfire.java.nio.file.Path) FileSystemProvider(org.uberfire.java.nio.file.spi.FileSystemProvider) DefaultIncrementalCompilerEnabler(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultIncrementalCompilerEnabler) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 15 with DefaultCompilationRequest

use of org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest 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("/dummy/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(fs.getPath("/dummy/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("/dummy/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("/dummy/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("/dummy/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();
    assertNotNull(cloned);
    // Compile the repo
    AFCompiler compiler = MavenCompilerFactory.getCompiler(Decorator.LOG_OUTPUT_AFTER);
    Path prjFolder = Paths.get(gitClonedFolder + "/dummy/");
    byte[] encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    Assert.assertFalse(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.TRUE);
    CompilationResponse res = compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerOnInMemoryFSTest.buildWithCloneTest");
    }
    assertTrue(res.getMavenOutput().isPresent());
    assertTrue(res.isSuccessful());
    Path incrementalConfiguration = Paths.get(prjFolder + "/target/incremental/io.takari.maven.plugins_takari-lifecycle-plugin_compile_compile");
    assertTrue(incrementalConfiguration.toFile().exists());
    encoded = Files.readAllBytes(Paths.get(prjFolder + "/pom.xml"));
    pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertTrue(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));
    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) Git(org.eclipse.jgit.api.Git) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest) Test(org.junit.Test)

Aggregations

DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest)27 Test (org.junit.Test)26 Path (org.uberfire.java.nio.file.Path)25 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)24 CompilationRequest (org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest)13 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo)13 AFCompiler (org.kie.workbench.common.services.backend.compiler.nio.AFCompiler)12 File (java.io.File)10 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)9 HashMap (java.util.HashMap)8 Git (org.eclipse.jgit.api.Git)7 Method (java.lang.reflect.Method)6 URI (java.net.URI)6 URLClassLoader (java.net.URLClassLoader)6 ArrayList (java.util.ArrayList)6 AFClassLoaderProvider (org.kie.workbench.common.services.backend.compiler.AFClassLoaderProvider)6 ClassLoaderProviderImpl (org.kie.workbench.common.services.backend.compiler.nio.impl.ClassLoaderProviderImpl)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 Logger (org.slf4j.Logger)4 PullCommand (org.eclipse.jgit.api.PullCommand)2