Search in sources :

Example 11 with PullCommand

use of org.eclipse.jgit.api.PullCommand in project kie-wb-common by kiegroup.

the class DefaultMavenCompilerTest method buildWithPullRebaseUberfireTest.

@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>() {

        {
            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();
    // nothing changed yet
    assertThat(pullRes.getRebaseResult().getStatus()).isEqualTo(RebaseResult.Status.UP_TO_DATE);
    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());
}
Also used : Path(org.uberfire.java.nio.file.Path) PullCommand(org.eclipse.jgit.api.PullCommand) HashMap(java.util.HashMap) RebaseCommand(org.eclipse.jgit.api.RebaseCommand) URI(java.net.URI) PullResult(org.eclipse.jgit.api.PullResult) 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) RebaseResult(org.eclipse.jgit.api.RebaseResult) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) DefaultCompilationRequest(org.kie.workbench.common.services.backend.compiler.impl.DefaultCompilationRequest) Test(org.junit.Test)

Example 12 with PullCommand

use of org.eclipse.jgit.api.PullCommand in project winery by eclipse.

the class GitBasedRepository method pull.

public void pull() throws GitAPIException {
    try (Git git = getGit()) {
        PullCommand pull = git.pull();
        if (Environments.getInstance().getGitConfig().getAccessToken() != null) {
            pull.setCredentialsProvider(new UsernamePasswordCredentialsProvider(Environments.getInstance().getGitConfig().getAccessToken(), ""));
        }
        pull.call();
        pull.getRepository().close();
    } catch (IOException e) {
        LOGGER.error("Error pulling Repository.", e);
    }
}
Also used : PullCommand(org.eclipse.jgit.api.PullCommand) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) IOException(java.io.IOException)

Example 13 with PullCommand

use of org.eclipse.jgit.api.PullCommand in project zeppelin by apache.

the class GitHubNotebookRepo method pullFromRemoteStream.

private void pullFromRemoteStream() {
    try {
        LOG.debug("Pulling latest changes from remote stream");
        PullCommand pullCommand = git.pull();
        pullCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(zeppelinConfiguration.getZeppelinNotebookGitUsername(), zeppelinConfiguration.getZeppelinNotebookGitAccessToken()));
        pullCommand.call();
    } catch (GitAPIException e) {
        LOG.error("Error when pulling latest changes from remote repository", e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) PullCommand(org.eclipse.jgit.api.PullCommand) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)

Example 14 with PullCommand

use of org.eclipse.jgit.api.PullCommand in project archi-modelrepository-plugin by archi-contribs.

the class ArchiRepository method pullFromRemote.

@Override
public PullResult pullFromRemote(UsernamePassword npw, ProgressMonitor monitor) throws IOException, GitAPIException {
    try (Git git = Git.open(getLocalRepositoryFolder())) {
        PullCommand pullCommand = git.pull();
        pullCommand.setTransportConfigCallback(CredentialsAuthenticator.getTransportConfigCallback(getOnlineRepositoryURL(), npw));
        // Merge, not rebase
        pullCommand.setRebase(false);
        pullCommand.setProgressMonitor(monitor);
        return pullCommand.call();
    }
}
Also used : PullCommand(org.eclipse.jgit.api.PullCommand) Git(org.eclipse.jgit.api.Git)

Aggregations

PullCommand (org.eclipse.jgit.api.PullCommand)14 Git (org.eclipse.jgit.api.Git)12 PullResult (org.eclipse.jgit.api.PullResult)7 RebaseResult (org.eclipse.jgit.api.RebaseResult)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 File (java.io.File)5 HashMap (java.util.HashMap)5 RebaseCommand (org.eclipse.jgit.api.RebaseCommand)5 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)5 Test (org.junit.Test)5 URI (java.net.URI)4 Path (org.uberfire.java.nio.file.Path)4 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)4 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)3 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 InvalidPathException (java.nio.file.InvalidPathException)2 ArrayList (java.util.ArrayList)2 DiffEntry (org.eclipse.jgit.diff.DiffEntry)2 FileRepository (org.eclipse.jgit.internal.storage.file.FileRepository)2 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)2