Example usage for org.eclipse.jgit.api PullResult getRebaseResult

List of usage examples for org.eclipse.jgit.api PullResult getRebaseResult

Introduction

In this page you can find the example usage for org.eclipse.jgit.api PullResult getRebaseResult.

Prototype

public RebaseResult getRebaseResult() 

Source Link

Document

Get rebase result

Usage

From source file:eu.cloud4soa.cli.roo.addon.commands.GitManager.java

License:Apache License

public void pull() throws GitAPIException, IOException {
    pullCommand = git.pull();//from w ww.  j  ava 2  s.  co m
    logger.info("Performing the git pull/merge command");
    PullResult pullResult = pullCommand.call();
    logger.info("Fetched From: " + pullResult.getFetchedFrom());
    logger.info("Fetch Result: " + pullResult.getFetchResult().getMessages());
    logger.info("Merge Result:" + pullResult.getMergeResult());
    logger.info("Rebase Result:" + pullResult.getRebaseResult());
    logger.info(pullResult.isSuccessful() ? "Pull/Merge success" : "Failed to Pull/Merge");
}

From source file:io.vertx.config.git.GitConfigStore.java

License:Apache License

private Future<Void> update() {
    Promise<Void> result = Promise.promise();
    vertx.executeBlocking(future -> {
        PullResult call;
        try {/*ww  w .j  a v a  2 s  .  c o m*/
            call = git.pull().setRemote(remote).setRemoteBranchName(branch)
                    .setCredentialsProvider(credentialProvider).call();
        } catch (GitAPIException e) {
            future.fail(e);
            return;
        }
        if (call.isSuccessful()) {
            future.complete();
        } else {
            if (call.getMergeResult() != null) {
                future.fail("Unable to merge repository - Conflicts: "
                        + call.getMergeResult().getCheckoutConflicts());
            } else {
                future.fail(
                        "Unable to rebase repository - Conflicts: " + call.getRebaseResult().getConflicts());
            }
        }
    }, result);
    return result.future();
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitBranchTest.java

License:Open Source License

@Test
public void testCreateTrackingBranch() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
    IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();

    JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
    IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID))
            .append("folder").makeAbsolute();

    IPath[] clonePaths = new IPath[] { clonePathTop, clonePathFolder };

    for (IPath clonePath : clonePaths) {
        // clone a  repo
        JSONObject clone = clone(clonePath);
        String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
        String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);

        // get project/folder metadata
        WebRequest request = getGetFilesRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject project = new JSONObject(response.getText());

        String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION);
        JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
        String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
        String gitRemoteUri = gitSection.optString(GitConstants.KEY_REMOTE);

        // create local branch tracking origin/master
        final String BRANCH_NAME = "a";
        final String REMOTE_BRANCH = Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER;

        branch(branchesLocation, BRANCH_NAME, REMOTE_BRANCH);

        // modify
        request = getPutFileRequest(projectLocation + "test.txt", "some change");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // add/*ww  w . ja  v a2s.co  m*/
        request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // commit
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit1", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // push
        ServerStatus pushStatus = push(gitRemoteUri, 1, 0, Constants.MASTER, Constants.HEAD, false);
        assertEquals(true, pushStatus.isOK());

        // TODO: replace with RESTful API for git pull when available
        // try to pull - up to date status is expected
        Git git = new Git(getRepositoryForContentLocation(cloneContentLocation));
        PullResult pullResults = git.pull().call();
        assertEquals(Constants.DEFAULT_REMOTE_NAME, pullResults.getFetchedFrom());
        assertEquals(MergeStatus.ALREADY_UP_TO_DATE, pullResults.getMergeResult().getMergeStatus());
        assertNull(pullResults.getRebaseResult());

        // checkout branch which was created a moment ago
        response = checkoutBranch(cloneLocation, BRANCH_NAME);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // TODO: replace with RESTful API for git pull when available
        // try to pull again - now fast forward update is expected
        pullResults = git.pull().call();
        assertEquals(Constants.DEFAULT_REMOTE_NAME, pullResults.getFetchedFrom());
        assertEquals(MergeStatus.FAST_FORWARD, pullResults.getMergeResult().getMergeStatus());
        assertNull(pullResults.getRebaseResult());
    }
}

From source file:org.exist.git.xquery.Pull.java

License:Open Source License

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {//from  www  .  j  ava2s . c  om
        String localPath = args[0].getStringValue();
        if (!(localPath.endsWith("/")))
            localPath += File.separator;

        Git git = Git.open(new Resource(localPath), FS);

        PullResult answer = git.pull().setCredentialsProvider(
                new UsernamePasswordCredentialsProvider(args[1].getStringValue(), args[2].getStringValue()))
                .call();

        MemTreeBuilder builder = getContext().getDocumentBuilder();

        int nodeNr = builder.startElement(PULL, null);
        builder.addAttribute(IS_SUCCESSFUL, Boolean.toString(answer.isSuccessful()));

        MergeResult merge = answer.getMergeResult();

        if (merge != null) {
            builder.startElement(MERGE, null);
            builder.addAttribute(STATUS, merge.getMergeStatus().toString());
            builder.addAttribute(IS_SUCCESSFUL, Boolean.toString(merge.getMergeStatus().isSuccessful()));

            for (ObjectId commit : merge.getMergedCommits()) {
                builder.startElement(COMMIT, null);

                builder.addAttribute(ID, commit.name());

                builder.endElement();
            }
            builder.endElement();

            if (merge.getConflicts() != null) {
                for (Entry<String, int[][]> entry : merge.getConflicts().entrySet()) {
                    builder.startElement(CHECKOUT_CONFLICT, null);
                    builder.addAttribute(PATH, entry.getKey());

                    builder.endElement();
                }

            }

            if (merge.getCheckoutConflicts() != null) {
                for (String path : merge.getCheckoutConflicts()) {
                    builder.startElement(CHECKOUT_CONFLICT, null);
                    builder.addAttribute(PATH, path);

                    builder.endElement();
                }
            }

            if (merge.getFailingPaths() != null) {
                for (Entry<String, MergeFailureReason> entry : merge.getFailingPaths().entrySet()) {
                    builder.startElement(FAILING_PATH, null);
                    builder.addAttribute(PATH, entry.getKey());
                    builder.addAttribute(REASON, entry.getValue().name());

                    builder.endElement();
                }
            }
        }

        RebaseResult rebase = answer.getRebaseResult();

        if (rebase != null) {
            builder.startElement(REBASE, null);
            builder.addAttribute(STATUS, rebase.getStatus().toString());
            builder.addAttribute(IS_SUCCESSFUL, Boolean.toString(rebase.getStatus().isSuccessful()));

            //rebase.getConflicts()

            if (rebase.getFailingPaths() != null) {
                for (Entry<String, MergeFailureReason> entry : rebase.getFailingPaths().entrySet()) {
                    builder.startElement(FAILING_PATH, null);
                    builder.addAttribute(PATH, entry.getKey());
                    builder.addAttribute(REASON, entry.getValue().name());

                    builder.endElement();
                }
            }
            builder.endElement();
        }

        return builder.getDocument().getNode(nodeNr);
    } catch (Throwable e) {
        e.printStackTrace();
        throw new XPathException(this, Module.EXGIT001, e);
    }
}

From source file:org.kie.workbench.common.project.migration.cli.maven.PomEditorWithGitTest.java

License:Apache License

@Test
public void testPomEditor() throws Exception {
    final String repoName = "myrepoxxxx";
    HashMap<String, Object> env = new HashMap<>();
    env.put("init", Boolean.TRUE);
    env.put("internal", Boolean.TRUE);
    final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName), env);

    ioService.startBatch(fs);/*from www  . j a va  2  s  .  c  o m*/
    ioService.write(fs.getPath("/pom.xml"), new String(
            java.nio.file.Files.readAllBytes(new File("src/test/projects/generic/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();

    assertNotNull(cloned);

    Path pomPath = Paths.get("file://" + gitClonedFolder.toString() + "/pom.xml");
    byte[] encoded = Files.readAllBytes(pomPath);
    String pomOriginal = new String(encoded, StandardCharsets.UTF_8);

    Model model = editor.updatePom(pomPath, cdiWrapper);
    assertNotNull(model);

    PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
    PullResult pullRes = pc.call();
    assertEquals(pullRes.getRebaseResult().getStatus(), RebaseResult.Status.UP_TO_DATE);

    RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
    RebaseResult rbResult = rb.setPreserveMerges(true).call();
    assertTrue(rbResult.getStatus().isSuccessful());

    pomPath = Paths.get("file://" + gitClonedFolder.toString() + "/pom.xml");
    encoded = Files.readAllBytes(pomPath);
    String pomUpdated = new String(encoded, StandardCharsets.UTF_8);

    assertFalse(pomOriginal.equals(pomUpdated));
}

From source file:org.kie.workbench.common.services.backend.compiler.DefaultMavenCompilerTest.java

License:Apache License

@Test
public void buildWithPullRebaseUberfireTest() throws Exception {

    //Setup origin in memory
    final URI originRepo = URI.create("git://repo");
    final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo,
            new HashMap<String, Object>() {
                {//from  ww w  .ja v a 2 s.  co m
                    put("init", Boolean.TRUE);
                    put("internal", Boolean.TRUE);
                    put("listMode", "ALL");
                }
            });
    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();

    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone"));

    final Git cloned = Git.cloneRepository()
            .setURI(origin.getGit().getRepository().getDirectory().toURI().toString()).setBare(false)
            .setDirectory(tmpCloned.toFile()).call();

    assertThat(cloned).isNotNull();

    PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
    PullResult pullRes = pc.call();
    assertThat(pullRes.getRebaseResult().getStatus()).isEqualTo(RebaseResult.Status.UP_TO_DATE);// nothing changed yet

    RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
    RebaseResult rbResult = rb.setPreserveMerges(true).call();
    assertThat(rbResult.getStatus().isSuccessful()).isTrue();

    //Compile the repo
    final AFCompiler compiler = KieMavenCompilerFactory
            .getCompiler(EnumSet.of(KieDecorator.ENABLE_LOGGING, KieDecorator.ENABLE_INCREMENTAL_BUILD));

    byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);

    Path prjFolder = Paths.get(tmpCloned + "/");

    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info,
            new String[] { MavenCLIArgs.COMPILE }, Boolean.TRUE);

    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(tmpRootCloned.toFile());
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.JGitUtils.java

License:Apache License

public static Boolean applyBefore(final Git git) {
    Boolean result = Boolean.FALSE;
    try {/* w ww .  j a  va  2 s  . c om*/
        PullCommand pc = git.pull().setRemote(REMOTE).setRebase(Boolean.TRUE);
        PullResult pullRes = pc.call();
        RebaseResult rr = pullRes.getRebaseResult();

        if (rr.getStatus().equals(RebaseResult.Status.UP_TO_DATE)
                || rr.getStatus().equals(RebaseResult.Status.FAST_FORWARD)) {
            result = Boolean.TRUE;
        }
        if (rr.getStatus().equals(RebaseResult.Status.UNCOMMITTED_CHANGES)) {
            PullResult pr = git.pull().call();
            if (pr.isSuccessful()) {
                result = Boolean.TRUE;
            } else {
                result = Boolean.FALSE;
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    return result;
}

From source file:org.kie.workbench.common.services.backend.compiler.kie.KieDefaultMavenCompilerTest.java

License:Apache License

@Test
public void buildWithPullRebaseUberfireTest() throws Exception {

    //Setup origin in memory
    final URI originRepo = URI.create("git://repo");
    final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo,
            new HashMap<String, Object>() {
                {/*  w w w.j  av a2 s  .com*/
                    put("init", Boolean.TRUE);
                    put("internal", Boolean.TRUE);
                    put("listMode", "ALL");
                }
            });
    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();

    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone"));

    final Git cloned = Git.cloneRepository()
            .setURI(origin.getGit().getRepository().getDirectory().toURI().toString()).setBare(false)
            .setDirectory(tmpCloned.toFile()).call();

    assertThat(cloned).isNotNull();

    PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
    PullResult pullRes = pc.call();
    assertThat(pullRes.getRebaseResult().getStatus()).isEqualTo(RebaseResult.Status.UP_TO_DATE);// nothing changed yet

    RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
    RebaseResult rbResult = rb.setPreserveMerges(true).call();
    assertThat(rbResult.getStatus().isSuccessful()).isTrue();

    //Compile the repo
    byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    assertThat(pomAsAstring).doesNotContain(TestConstants.TAKARI_LIFECYCLE_ARTIFACT);

    Path prjFolder = Paths.get(tmpCloned + "/");

    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.TRUE);
    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(tmpRootCloned.toFile());
}

From source file:org.kie.workbench.common.services.backend.compiler.nio.DefaultMavenCompilerTest.java

License:Apache License

@Test
public void buildWithPullRebaseUberfireTest() throws Exception {

    //Setup origin in memory
    final URI originRepo = URI.create("git://repo");
    final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo,
            new HashMap<String, Object>() {
                {//from w  w  w . j a  v  a2 s .  c o  m
                    put("init", Boolean.TRUE);
                    put("internal", Boolean.TRUE);
                    put("listMode", "ALL");
                }
            });
    ioService.startBatch(origin);

    ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files
            .readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(origin.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(origin.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(origin.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(origin.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();

    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone"));

    final Git cloned = Git.cloneRepository().setURI("git://localhost:9418/repo").setBare(false)
            .setDirectory(tmpCloned.toFile()).call();

    assertNotNull(cloned);

    PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
    PullResult pullRes = pc.call();
    assertTrue(pullRes.getRebaseResult().getStatus().equals(RebaseResult.Status.UP_TO_DATE));// nothing changed yet

    RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
    RebaseResult rbResult = rb.setPreserveMerges(true).call();
    assertTrue(rbResult.getStatus().isSuccessful());

    //Compile the repo
    AFCompiler compiler = MavenCompilerFactory.getCompiler(Decorator.LOG_OUTPUT_AFTER);

    byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/dummy/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    Assert.assertFalse(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));

    Path prjFolder = Paths.get(tmpCloned + "/dummy/");

    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
    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(),
                "KieDefaultMavenCompilerOnInMemoryFSTest.buildWithPullRebaseUberfireTest");
    }

    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());
}

From source file:org.kie.workbench.common.services.backend.compiler.nio.kie.KieDefaultMavenCompilerTest.java

License:Apache License

@Test
public void buildWithPullRebaseUberfireTest() throws Exception {

    //Setup origin in memory
    final URI originRepo = URI.create("git://repo");
    final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo,
            new HashMap<String, Object>() {
                {//from  www.ja  v  a 2s . c  om
                    put("init", Boolean.TRUE);
                    put("internal", Boolean.TRUE);
                    put("listMode", "ALL");
                }
            });
    ioService.startBatch(origin);

    ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files
            .readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
    ioService.write(origin.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(origin.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(origin.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(origin.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();

    // clone into a regularfs
    Path tmpRootCloned = Files.createTempDirectory("cloned");
    Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone"));

    final Git cloned = Git.cloneRepository().setURI("git://localhost:9418/repo").setBare(false)
            .setDirectory(tmpCloned.toFile()).call();

    assertNotNull(cloned);

    PullCommand pc = cloned.pull().setRemote("origin").setRebase(Boolean.TRUE);
    PullResult pullRes = pc.call();
    assertTrue(pullRes.getRebaseResult().getStatus().equals(RebaseResult.Status.UP_TO_DATE));// nothing changed yet

    RebaseCommand rb = cloned.rebase().setUpstream("origin/master");
    RebaseResult rbResult = rb.setPreserveMerges(true).call();
    assertTrue(rbResult.getStatus().isSuccessful());

    //Compile the repo
    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.LOG_OUTPUT_AFTER);

    byte[] encoded = Files.readAllBytes(Paths.get(tmpCloned + "/dummy/pom.xml"));
    String pomAsAstring = new String(encoded, StandardCharsets.UTF_8);
    Assert.assertFalse(pomAsAstring.contains("<artifactId>takari-lifecycle-plugin</artifactId>"));

    Path prjFolder = Paths.get(tmpCloned + "/dummy/");

    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(prjFolder);
    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(),
                "KieDefaultMavenCompilerTest.buildWithPullRebaseUberfireTest");
    }

    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());
}