Search in sources :

Example 11 with JGitFileSystem

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

the class DefaultMavenCompilerTest method cleanInternalTest.

@Test
public void cleanInternalTest() throws Exception {
    final AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.UPDATE_JGIT_BEFORE_BUILD));
    String MAIN_BRANCH = "master";
    // Setup origin in memory
    final URI originRepo = URI.create("git://xxsddsrepo");
    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();
    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());
    assertThat(compiler.cleanInternalCache()).isTrue();
    // 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) URI(java.net.URI) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 12 with JGitFileSystem

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

the class MavenRestHandlerTest method post.

@Test
public void post() {
    // 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
        Dispatcher dispatcher = new AsynchronousDispatcher(new ResteasyProviderFactory());
        ResteasyProviderFactory.setInstance(dispatcher.getProviderFactory());
        RegisterBuiltin.register(dispatcher.getProviderFactory());
        POJOResourceFactory noDefaults = new POJOResourceFactory(MavenRestHandler.class);
        dispatcher.getRegistry().addResourceFactory(noDefaults);
        MockHttpRequest request = MockHttpRequest.create("POST", "build/maven/");
        request.header("project", tmpRoot.toAbsolutePath().toString() + "/dummy").header("mavenrepo", mavenRepoPath.toAbsolutePath().toString());
        MockHttpResponse response = new MockHttpResponse();
        SynchronousExecutionContext synchronousExecutionContext = new SynchronousExecutionContext((SynchronousDispatcher) dispatcher, request, response);
        request.setAsynchronousContext(synchronousExecutionContext);
        dispatcher.invoke(request, response);
        assertThat(response.getStatus()).isEqualTo(200);
        byte[] serializedCompilationResponse = response.getOutput();
        HttpCompilationResponse res = RestUtils.readDefaultCompilationResponseFromBytes(serializedCompilationResponse);
        assertThat(res).isNotNull();
        assertThat(res.getDependencies()).hasSize(4);
        assertThat(res.getTargetContent()).hasSize(3);
        tearDown();
    } catch (Exception e) {
        logger.error(e.getMessage());
    } finally {
        fileSystemTestingUtils.cleanup();
    }
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) HttpCompilationResponse(org.kie.workbench.common.services.backend.compiler.HttpCompilationResponse) HashMap(java.util.HashMap) SynchronousDispatcher(org.jboss.resteasy.core.SynchronousDispatcher) AsynchronousDispatcher(org.jboss.resteasy.core.AsynchronousDispatcher) Dispatcher(org.jboss.resteasy.core.Dispatcher) SynchronousExecutionContext(org.jboss.resteasy.core.SynchronousExecutionContext) POJOResourceFactory(org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory) Git(org.eclipse.jgit.api.Git) AsynchronousDispatcher(org.jboss.resteasy.core.AsynchronousDispatcher) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) 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 13 with JGitFileSystem

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

the class MavenRestClientTest method postTest.

@Test
public void postTest() {
    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();
        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();
        assertThat(cloned).isNotNull();
        mavenRepoPath = Paths.get(System.getProperty("user.home"), ".m2", "repository");
        tmpRoot = Paths.get(gitClonedFolder + "/dummy/");
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(deploymentUrl.toString() + "rest/maven/");
        MultivaluedMap headersMap = new MultivaluedHashMap();
        headersMap.add("project", tmpRoot.toAbsolutePath().toString() + "/dummy");
        headersMap.add("mavenrepo", mavenRepoPath.toAbsolutePath().toString());
        headersMap.add("settings_xml", mavenSettingsPath);
        Future<Response> responseFuture = target.request().headers(headersMap).async().post(Entity.entity(String.class, MediaType.TEXT_PLAIN));
        Response response = responseFuture.get();
        assertThat(response.getStatusInfo().getStatusCode()).isEqualTo(200);
        InputStream is = response.readEntity(InputStream.class);
        byte[] serializedCompilationResponse = IOUtils.toByteArray(is);
        HttpCompilationResponse res = RestUtils.readDefaultCompilationResponseFromBytes(serializedCompilationResponse);
        assertThat(res).isNotNull();
        assertThat(res.getDependencies()).hasSize(4);
        assertThat(res.getTargetContent()).hasSize(3);
        tearDown();
    } catch (Exception e) {
        logger.error(e.getMessage());
    } finally {
        fileSystemTestingUtils.cleanup();
    }
}
Also used : Path(java.nio.file.Path) HttpCompilationResponse(org.kie.workbench.common.services.backend.compiler.HttpCompilationResponse) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) InputStream(java.io.InputStream) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) HttpCompilationResponse(org.kie.workbench.common.services.backend.compiler.HttpCompilationResponse) Response(javax.ws.rs.core.Response) Git(org.eclipse.jgit.api.Git) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) File(java.io.File) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) Test(org.junit.Test)

Example 14 with JGitFileSystem

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

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

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