Search in sources :

Example 21 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem in project kie-wb-common by kiegroup.

the class MavenRestHandlerTest method get.

@Test
public void get() {
    // Start preparation FS
    try {
        fileSystemTestingUtils.setup();
        ioService = fileSystemTestingUtils.getIoService();
        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);
        String pom = "target/test-classes/kjar-2-single-resources/pom.xml";
        if (!runIntoMavenCLI) {
            pom = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/pom.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File(pom).toPath())));
        String personDotJava = "target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        if (!runIntoMavenCLI) {
            personDotJava = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File(personDotJava).toPath())));
        String simpleRulesDotDRL = "target/test-classes/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl";
        if (!runIntoMavenCLI) {
            simpleRulesDotDRL = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl"), new String(java.nio.file.Files.readAllBytes(new File(simpleRulesDotDRL).toPath())));
        String kmodule = "target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        if (!runIntoMavenCLI) {
            kmodule = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml"), new String(java.nio.file.Files.readAllBytes(new File(kmodule).toPath())));
        ioService.endBatch();
        java.nio.file.Path tmpRootCloned = java.nio.file.Files.createTempDirectory("cloned");
        java.nio.file.Path tmpCloned = java.nio.file.Files.createDirectories(java.nio.file.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();
        mavenRepoPath = java.nio.file.Paths.get(System.getProperty("user.home"), ".m2", "repository");
        tmpRoot = java.nio.file.Paths.get(gitClonedFolder + "/dummy/");
        // END preparation FS
        // Test
        Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
        POJOResourceFactory noDefaults = new POJOResourceFactory(MavenRestHandler.class);
        dispatcher.getRegistry().addResourceFactory(noDefaults);
        MockHttpRequest request = MockHttpRequest.get("build/maven/");
        MockHttpResponse response = new MockHttpResponse();
        dispatcher.invoke(request, response);
        assertThat(response.getStatus()).isEqualTo(200);
        assertThat(response.getContentAsString()).isEqualTo("Apache Maven");
        // end test
        tearDown();
    } catch (Exception e) {
        logger.error(e.getMessage());
    } finally {
        fileSystemTestingUtils.cleanup();
    }
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) HashMap(java.util.HashMap) SynchronousDispatcher(org.jboss.resteasy.core.SynchronousDispatcher) AsynchronousDispatcher(org.jboss.resteasy.core.AsynchronousDispatcher) Dispatcher(org.jboss.resteasy.core.Dispatcher) POJOResourceFactory(org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory) Git(org.eclipse.jgit.api.Git) File(java.io.File) Path(java.nio.file.Path) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) Test(org.junit.Test)

Example 22 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem in project kie-wb-common by kiegroup.

the class JGITCompilerBeforeDecorator method handleMap.

private Map<Path, InputStream> handleMap(final Git git, final Map<Path, InputStream> override) {
    final Map<Path, InputStream> result = new HashMap<>(override.size());
    for (Map.Entry<Path, InputStream> entry : override.entrySet()) {
        if (entry.getKey().getFileSystem() instanceof JGitFileSystem) {
            final Path convertedToCheckedPath = Paths.get(git.getRepository().getDirectory().toPath().getParent().resolve(entry.getKey().toString().substring(1)).toUri());
            result.put(convertedToCheckedPath, entry.getValue());
        }
    }
    return result;
}
Also used : Path(org.uberfire.java.nio.file.Path) HashMap(java.util.HashMap) InputStream(java.io.InputStream) HashMap(java.util.HashMap) Map(java.util.Map) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem)

Example 23 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem 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)

Example 24 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem in project kie-wb-common by kiegroup.

the class KieDefaultMavenCompilerTest method buildWithJGitDecoratorTest.

@Test
public void buildWithJGitDecoratorTest() throws Exception {
    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("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();
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.UPDATE_JGIT_BEFORE_BUILD));
    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());
    // 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) CompilationResponse(org.kie.workbench.common.services.backend.compiler.CompilationResponse) URI(java.net.URI) 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) Test(org.junit.Test)

Example 25 with JGitFileSystem

use of org.uberfire.java.nio.fs.jgit.JGitFileSystem in project kie-wb-common by kiegroup.

the class KieDefaultMavenCompilerTest method buildCompileWithOverrideOnGitVFS.

@Test
public void buildCompileWithOverrideOnGitVFS() throws Exception {
    final String alternateSettingsAbsPath = TestUtilMaven.getSettingsFile();
    final URI originRepo = URI.create("git://buildCompileWithOverrideOnGitVFS");
    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);
    // git://buildCompileWithOverrideOnGitVFS/dummy/pom.xml
    ioService.write(// git://buildCompileWithOverrideOnGitVFS/dummy/pom.xml
    origin.getPath("master", "/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy_override/pom.xml").toPath())));
    // git://buildCompileWithOverrideOnGitVFS/dummy/src/main/java/dummy/Dummy.java
    ioService.write(// git://buildCompileWithOverrideOnGitVFS/dummy/src/main/java/dummy/Dummy.java
    origin.getPath("master", "/src/main/java/dummy/Dummy.java"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/dummy/src/main/java/dummy/Dummy.java").toPath())));
    ioService.endBatch();
    byte[] encoded = ioService.readAllBytes(origin.getPath("master", "/src/main/java/dummy/Dummy.java"));
    String dummyAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(dummyAsAstring).doesNotContain("public Dummy(Integer age) {\n" + "        this.age = age;\n" + "    }");
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.UPDATE_JGIT_BEFORE_BUILD, KieDecorator.ENABLE_LOGGING));
    // git://buildCompileWithOverrideOnGitVFS/dummy/
    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(origin.getPath("master", "/"));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, Boolean.TRUE);
    CompilationResponse res = compiler.compile(req);
    TestUtil.saveMavenLogIfCompilationResponseNotSuccessfull(res.getWorkingDir().get(), res, this.getClass(), testName);
    assertThat(res.isSuccessful()).isTrue();
    // /file:///User/temp8998876986179/dummy//target/classes/dummy/DummyOverride.class
    assertThat(new File(res.getWorkingDir().get() + "/target/classes/dummy/DummyOverride.class")).doesNotExist();
    // change some files
    Map<org.uberfire.java.nio.file.Path, InputStream> override = new HashMap<>();
    org.uberfire.java.nio.file.Path path = origin.getPath("master", "/src/main/java/dummy/DummyOverride.java");
    InputStream input = new FileInputStream(new File("target/test-classes/dummy_override/src/main/java/dummy/DummyOverride.java"));
    override.put(path, input);
    org.uberfire.java.nio.file.Path pathTwo = origin.getPath("master", "/src/main/java/dummy/Dummy.java");
    InputStream inputTwo = new FileInputStream(new File("target/test-classes/dummy_override/src/main/java/dummy/Dummy.java"));
    override.put(pathTwo, inputTwo);
    // recompile
    res = compiler.compile(req, override);
    assertThat(res.isSuccessful()).isTrue();
    assertThat(new File(res.getWorkingDir().get() + "/target/classes/dummy/Dummy.class")).doesNotExist();
    assertThat(new File(res.getWorkingDir().get() + "/target/classes/dummy/DummyOverride.class")).exists();
    encoded = Files.readAllBytes(Paths.get(res.getWorkingDir().get().toString(), "/src/main/java/dummy/Dummy.java"));
    dummyAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(dummyAsAstring).contains("public Dummy(String name) {\n" + "        this.name = name;\n" + "    }");
    compiler.cleanInternalCache();
    TestUtil.rm(origin.getGit().getRepository().getDirectory());
}
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) URI(java.net.URI) FileInputStream(java.io.FileInputStream) 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) Test(org.junit.Test)

Aggregations

JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)30 Test (org.junit.Test)27 HashMap (java.util.HashMap)26 File (java.io.File)25 Git (org.eclipse.jgit.api.Git)19 Path (org.uberfire.java.nio.file.Path)16 URI (java.net.URI)15 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)13 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest)10 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.impl.WorkspaceCompilationInfo)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9 DefaultCompilationRequest (org.kie.workbench.common.services.backend.compiler.nio.impl.DefaultCompilationRequest)9 PullCommand (org.eclipse.jgit.api.PullCommand)5 PullResult (org.eclipse.jgit.api.PullResult)5 RebaseCommand (org.eclipse.jgit.api.RebaseCommand)5 RebaseResult (org.eclipse.jgit.api.RebaseResult)5 AFCompiler (org.kie.workbench.common.services.backend.compiler.AFCompiler)4 CompilationRequest (org.kie.workbench.common.services.backend.compiler.CompilationRequest)4 CompilationRequest (org.kie.workbench.common.services.backend.compiler.nio.CompilationRequest)4 WorkspaceCompilationInfo (org.kie.workbench.common.services.backend.compiler.nio.WorkspaceCompilationInfo)4