Example usage for org.eclipse.jgit.lib TextProgressMonitor TextProgressMonitor

List of usage examples for org.eclipse.jgit.lib TextProgressMonitor TextProgressMonitor

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib TextProgressMonitor TextProgressMonitor.

Prototype

public TextProgressMonitor(Writer out) 

Source Link

Document

Initialize a new progress monitor.

Usage

From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java

License:Apache License

/**
 * In lieu of sparse checkout since it's not yet supported in JGit:
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772
 *//*from  w ww.  j  ava  2 s .co m*/
public void cloneNoCheckout(boolean withProgress) throws Exception {
    CloneCommand clone = Git.cloneRepository().setURI(repositoryUrl)
            .setDirectory(localRepo.getDirectory().getParentFile()).setNoCheckout(true);
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=442029
    if (credentialsProvider != null)
        clone.setCredentialsProvider(credentialsProvider);
    if (withProgress)
        clone.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)));
    clone.call();
}

From source file:com.fanniemae.ezpie.common.GitOperations.java

License:Open Source License

public String cloneHTTP(String repo_url, String destination, String userID, String password, String branch)
        throws InvalidRemoteException, TransportException, GitAPIException, URISyntaxException {

    _repositoryHost = getHost(repo_url);
    setupProxy();//from   w  w w . j a  v a  2  s  .c o m

    File localDir = new File(destination);
    CloneCommand cloneCommand = Git.cloneRepository();
    cloneCommand.setURI(repo_url);
    cloneCommand.setDirectory(localDir);

    if (StringUtilities.isNotNullOrEmpty(branch))
        cloneCommand.setBranch(branch);

    if (StringUtilities.isNotNullOrEmpty(userID))
        cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userID, password));

    try (Writer writer = new StringWriter()) {
        TextProgressMonitor tpm = new TextProgressMonitor(writer);
        cloneCommand.setProgressMonitor(tpm);
        try (Git result = cloneCommand.call()) {
        }
        clearProxyAuthenticatorCache();
        writer.flush();
        return writer.toString();
    } catch (IOException e) {
        throw new PieException("Error while trying to clone the git repository. " + e.getMessage(), e);
    }
}

From source file:com.fanniemae.ezpie.common.GitOperations.java

License:Open Source License

public String cloneSSH(String repo_url, String destination, String privateKey, String password, String branch) {
    if (_useProxy) {
        throw new PieException(
                "Network proxies do not support SSH, please use an http url to clone this repository.");
    }//from  w ww .j  av  a 2s  . c  o  m

    final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(Host host, Session session) {
            // This still checks existing host keys and will disable "unsafe"
            // authentication mechanisms if the host key doesn't match.
            session.setConfig("StrictHostKeyChecking", "no");
        }

        @Override
        protected JSch createDefaultJSch(FS fs) throws JSchException {
            JSch defaultJSch = super.createDefaultJSch(fs);
            defaultJSch.addIdentity(privateKey, password);
            return defaultJSch;
        }
    };

    CloneCommand cloneCommand = Git.cloneRepository();
    cloneCommand.setURI(repo_url);
    File dir = new File(destination);
    cloneCommand.setDirectory(dir);

    if (StringUtilities.isNotNullOrEmpty(branch))
        cloneCommand.setBranch(branch);

    cloneCommand.setTransportConfigCallback(new TransportConfigCallback() {
        public void configure(Transport transport) {
            SshTransport sshTransport = (SshTransport) transport;
            sshTransport.setSshSessionFactory(sshSessionFactory);
        }
    });

    try (Writer writer = new StringWriter()) {
        TextProgressMonitor tpm = new TextProgressMonitor(writer);
        cloneCommand.setProgressMonitor(tpm);
        try (Git result = cloneCommand.call()) {
        }
        writer.flush();
        return writer.toString();
    } catch (IOException | GitAPIException e) {
        throw new PieException("Error while trying to clone the git repository. " + e.getMessage(), e);
    }
}

From source file:com.google.gerrit.server.git.GarbageCollection.java

License:Apache License

public GarbageCollectionResult run(List<Project.NameKey> projectNames, boolean aggressive, PrintWriter writer) {
    GarbageCollectionResult result = new GarbageCollectionResult();
    Set<Project.NameKey> projectsToGc = gcQueue.addAll(projectNames);
    for (Project.NameKey projectName : Sets.difference(Sets.newHashSet(projectNames), projectsToGc)) {
        result.addError(new GarbageCollectionResult.Error(
                GarbageCollectionResult.Error.Type.GC_ALREADY_SCHEDULED, projectName));
    }/*from  www.  j a  v a2  s  .  c  o  m*/
    for (Project.NameKey p : projectsToGc) {
        try (Repository repo = repoManager.openRepository(p)) {
            logGcConfiguration(p, repo, aggressive);
            print(writer, "collecting garbage for \"" + p + "\":\n");
            GarbageCollectCommand gc = Git.wrap(repo).gc();
            gc.setAggressive(aggressive);
            logGcInfo(p, "before:", gc.getStatistics());
            gc.setProgressMonitor(
                    writer != null ? new TextProgressMonitor(writer) : NullProgressMonitor.INSTANCE);
            Properties statistics = gc.call();
            logGcInfo(p, "after: ", statistics);
            print(writer, "done.\n\n");
            fire(p, statistics);
        } catch (RepositoryNotFoundException e) {
            logGcError(writer, p, e);
            result.addError(new GarbageCollectionResult.Error(
                    GarbageCollectionResult.Error.Type.REPOSITORY_NOT_FOUND, p));
        } catch (Exception e) {
            logGcError(writer, p, e);
            result.addError(new GarbageCollectionResult.Error(GarbageCollectionResult.Error.Type.GC_FAILED, p));
        } finally {
            gcQueue.gcFinished(p);
        }
    }
    return result;
}

From source file:com.google.gerrit.server.index.account.AllAccountsIndexer.java

License:Apache License

@Override
public SiteIndexer.Result indexAll(final AccountIndex index) {
    ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
    progress.start(2);//from  ww w.j  a va 2s  . co m
    Stopwatch sw = Stopwatch.createStarted();
    List<Account.Id> ids;
    try {
        ids = collectAccounts(progress);
    } catch (OrmException e) {
        log.error("Error collecting accounts", e);
        return new Result(sw, false, 0, 0);
    }
    return reindexAccounts(index, ids, progress);
}

From source file:com.google.gerrit.server.index.group.AllGroupsIndexer.java

License:Apache License

@Override
public SiteIndexer.Result indexAll(GroupIndex index) {
    ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
    progress.start(2);// w  w w  .  j  av a2 s.  com
    Stopwatch sw = Stopwatch.createStarted();
    List<AccountGroup.UUID> uuids;
    try {
        uuids = collectGroups(progress);
    } catch (OrmException e) {
        log.error("Error collecting groups", e);
        return new SiteIndexer.Result(sw, false, 0, 0);
    }
    return reindexGroups(index, uuids, progress);
}

From source file:com.google.gerrit.server.notedb.ChangeRebuilderImpl.java

License:Apache License

@Override
public boolean rebuildProject(ReviewDb db, ImmutableMultimap<Project.NameKey, Change.Id> allChanges,
        Project.NameKey project, Repository allUsersRepo)
        throws NoSuchChangeException, IOException, OrmException, ConfigInvalidException {
    checkArgument(allChanges.containsKey(project));
    boolean ok = true;
    ProgressMonitor pm = new TextProgressMonitor(new PrintWriter(System.out));
    NoteDbUpdateManager manager = updateManagerFactory.create(project);
    pm.beginTask(FormatUtil.elide(project.get(), 50), allChanges.get(project).size());
    try (ObjectInserter allUsersInserter = allUsersRepo.newObjectInserter();
            RevWalk allUsersRw = new RevWalk(allUsersInserter.newReader())) {
        manager.setAllUsersRepo(allUsersRepo, allUsersRw, allUsersInserter, new ChainedReceiveCommands());
        for (Change.Id changeId : allChanges.get(project)) {
            try {
                buildUpdates(manager, ChangeBundle.fromReviewDb(db, changeId));
            } catch (Throwable t) {
                log.error("Failed to rebuild change " + changeId, t);
                ok = false;//from   w  w w  . j a v a  2s.  c  o m
            }
            pm.update(1);
        }
        manager.execute();
    } finally {
        pm.endTask();
    }
    return ok;
}

From source file:eu.numberfour.n4js.utils.git.GitUtils.java

License:Open Source License

private static TextProgressMonitor createMonitor() {
    return new TextProgressMonitor(new OutputStreamWriter(System.out));
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.FetchSettings.java

License:Apache License

@NotNull
public ProgressMonitor createProgressMonitor() {
    if (myProgress == GitProgress.NO_OP)
        return NullProgressMonitor.INSTANCE;
    Writer w = new Writer() {
        @Override/*  w w w  .  j a  va  2  s . c o  m*/
        public void write(final String str) throws IOException {
            myProgress.reportProgress(str.trim());
        }

        @Override
        public void write(final char[] cbuf, final int off, final int len) throws IOException {
        }

        @Override
        public void flush() throws IOException {
        }

        @Override
        public void close() throws IOException {
        }
    };

    return new TextProgressMonitor(w);
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitGcProcess.java

License:Apache License

public static void main(String... args) throws Exception {
    GitServerUtil.configureExternalProcessLogger(false);
    try {//  w  ww  .  ja  v a 2  s  . co m
        String gitDir = args[0];
        System.out.println("run gc in " + gitDir);
        Repository r = new RepositoryBuilder().setBare().setGitDir(new File(gitDir)).build();
        Git git = new Git(r);
        GarbageCollectCommand gc = git.gc();
        gc.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)));
        gc.call();
    } catch (Throwable t) {
        if (isImportant(t)) {
            t.printStackTrace(System.err);
        } else {
            System.err.println(t.getMessage());
        }
        System.exit(1);
    }
}