Java 类org.eclipse.jgit.lib.TextProgressMonitor 实例源码

项目:gerrit    文件:AllChangesIndexer.java   
@Override
public Result indexAll(ChangeIndex index) {
  ProgressMonitor pm = new TextProgressMonitor();
  pm.beginTask("Collecting projects", ProgressMonitor.UNKNOWN);
  SortedSet<ProjectHolder> projects = new TreeSet<>();
  int changeCount = 0;
  Stopwatch sw = Stopwatch.createStarted();
  for (Project.NameKey name : projectCache.all()) {
    try (Repository repo = repoManager.openRepository(name)) {
      long size = estimateSize(repo);
      changeCount += size;
      projects.add(new ProjectHolder(name, size));
    } catch (IOException e) {
      log.error("Error collecting projects", e);
      return new Result(sw, false, 0, 0);
    }
    pm.update(1);
  }
  pm.endTask();
  setTotalWork(changeCount);

  return indexAll(index, projects);
}
项目:gerrit    文件:Schema_154.java   
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
  try {
    try (Repository repo = repoManager.openRepository(allUsersName)) {
      ProgressMonitor pm = new TextProgressMonitor();
      pm.beginTask("Collecting accounts", ProgressMonitor.UNKNOWN);
      Set<Account> accounts = scanAccounts(db, pm);
      pm.endTask();
      pm.beginTask("Migrating accounts to NoteDb", accounts.size());
      for (Account account : accounts) {
        updateAccountInNoteDb(repo, account);
        pm.update(1);
      }
      pm.endTask();
    }
  } catch (IOException | ConfigInvalidException e) {
    throw new OrmException("Migrating accounts to NoteDb failed", e);
  }
}
项目:gerrit    文件:Schema_160.java   
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
  try {
    try (Repository repo = repoManager.openRepository(allUsersName)) {
      ProgressMonitor pm = new TextProgressMonitor();
      pm.beginTask("Removing \"My Drafts\" menu items", ProgressMonitor.UNKNOWN);
      for (Account.Id id : (Iterable<Account.Id>) Accounts.readUserRefs(repo)::iterator) {
        if (removeMyDrafts(repo, id)) {
          pm.update(1);
        }
      }
      pm.endTask();
    }
  } catch (IOException | ConfigInvalidException e) {
    throw new OrmException("Removing \"My Drafts\" menu items failed", e);
  }
}
项目:serverwiz    文件:GithubRepository.java   
public void cloneRepository() throws Exception {
    if (!passwordValidated) {
        this.getPassword();
    }
    if (isCloned()) {
        return;
    }
    ServerWizard2.LOGGER.info("Cloning " + this.remoteUrl + " into " + this.getRootDirectory().getAbsolutePath());
    cloned = false;
    try {
        //TODO: determine MacOS hang issue with the progress monitor
        //ProgressMonitor pim = new ProgressMonitor(null, "Cloning...", "", 0, 1);
        //GitProgressMonitor gpim = new GitProgressMonitor(pim);
        Git result = Git.cloneRepository()
                .setCredentialsProvider(credentials)
                .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
                .setURI(this.getRemoteUrl()).setDirectory(this.getRootDirectory()).call();

        cloned = true;
        result.close();
    } catch (Exception e1) {
        passwordValidated = false;
        this.betterError(e1);
    }
}
项目:VanillaBuild    文件:VanillaBuildMain.java   
private static boolean cloneRepo(TargetCommit cloneCommit, String customCommit) {
    CloneCommand cloneCommand = new CloneCommand()
            .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
            .setDirectory(new File(ROOT_DIR))
            .setURI("https://github.com/SpongePowered/SpongeVanilla.git")
            .setBranchesToClone(Collections.singleton("refs/heads/master"))
            .setBranch("refs/heads/master")
            .setCloneSubmodules(true);
    try {
        Git git = cloneCommand.call();

        if (cloneCommit == TargetCommit.CUSTOM) {
            git.checkout().setName(customCommit).call();

            git.submoduleInit().call();
            git.submoduleUpdate().setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))).call();
        }

        return true;
    } catch (GitAPIException e) {
        e.printStackTrace();
    }
    return false;
}
项目:get.me    文件:GitCloneCommand.java   
@Override
public void to(Path path) throws Git.Err {
    LOG.info(() -> String.format("Cloning %s into %s...", url, path.toString()));
    CloneCommand cloner = org.eclipse.jgit.api.Git.cloneRepository()
            .setURI(url)
            .setCredentialsProvider(new GitCredentialsProvider(
                    CredentialHandlers.handlerMap()
            ))
            .setProgressMonitor(
                    enableOutput
                            ? new TextProgressMonitor()
                            : NullProgressMonitor.INSTANCE
            )
            .setDirectory(path.toFile());
    branchName.ifPresent(cloner::setBranch);
    try {
        cloner.call();
    } catch (GitAPIException e) {
        throw new Git.Err(url, path.toString(), e);
    }
}
项目:neembuu-uploader    文件:UpdaterGenerator.java   
/**
 * Clone GIT repository from sourceforge.
 *
 * @param gitDirectory The directory of Git.
 */
private void gitClone(File gitDirectory) {
    try {
        git = Git.cloneRepository()
                .setDirectory(gitDirectory)
                .setURI("http://git.code.sf.net/p/neembuuuploader/gitcode")
                .setProgressMonitor(new TextProgressMonitor()).call();

        for (Ref f : git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call()) {
            git.checkout().setName(f.getName()).call();
            System.out.println("checked out branch " + f.getName()
                    + ". HEAD: " + git.getRepository().getRef("HEAD"));
        }
        // try to checkout branches by specifying abbreviated names
        git.checkout().setName("master").call();
    } catch (GitAPIException | IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:neembuu-uploader    文件:UpdaterGenerator.java   
/**
 * Clone GIT repository from sourceforge.
 *
 * @param gitDirectory The directory of Git.
 */
private void gitClone(File gitDirectory) {
    try {
        git = Git.cloneRepository()
                .setDirectory(gitDirectory)
                .setURI(env.gitURI())
                //.setURI("http://git.code.sf.net/p/neembuuuploader/gitcode")
                .setProgressMonitor(new TextProgressMonitor()).call();

        for (Ref f : git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call()) {
            git.checkout().setName(f.getName()).call();
            System.out.println("checked out branch " + f.getName()
                    + ". HEAD: " + git.getRepository().getRef("HEAD"));
        }
        // try to checkout branches by specifying abbreviated names
        git.checkout().setName("master").call();
    } catch (GitAPIException | IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:csap-core    文件:SourceControlManager.java   
private ProgressMonitor gitMonitor ( Writer w ) {
    return new TextProgressMonitor( w ) {

    };
    // return new ProgressMonitor() {
    //
    // @Override
    // public void update ( int completed ) {
    // // TODO Auto-generated method stub
    // logger.info( "items completed: {}", completed );
    // }
    //
    // @Override
    // public void start ( int totalTasks ) {
    // // TODO Auto-generated method stub
    //
    // }
    //
    // @Override
    // public boolean isCancelled () {
    // // TODO Auto-generated method stub
    // return false;
    // }
    //
    // @Override
    // public void endTask () {
    // // TODO Auto-generated method stub
    //
    // }
    //
    // @Override
    // public void beginTask ( String title, int totalWork ) {
    // // TODO Auto-generated method stub
    // logger.info( "progress: {}, items remaining: {}", title, totalWork );
    //
    // }
    // } ;
}
项目:mdw    文件:VersionControlGit.java   
/**
 * In lieu of sparse checkout since it's not yet supported in JGit:
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772
 */
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();
}
项目:gitdep-maven-plugin    文件:DownloaderMojo.java   
private Git clone(Pom pom, GitDependency dependency) throws MojoExecutionException {
    final CloneCommand c = new CloneCommand();
    final String location = dependency.getLocation();

    c.setURI(location);
    c.setCloneAllBranches(true);
    c.setProgressMonitor(new TextProgressMonitor());

    final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency);
    final String version = dependencyHandler.getDependencyVersion(pom);
    final String tempDirectory = Directory.getTempDirectoryString(location, version);

    c.setDirectory(new File(tempDirectory));
    return c.call();
}
项目:github-integration-plugin    文件:GHRule.java   
public void pushAll() throws GitAPIException {
    git.push()
            .setPushAll()
            .setProgressMonitor(new TextProgressMonitor())
            .setCredentialsProvider(new UsernamePasswordCredentialsProvider(GH_TOKEN, ""))
            .call();
}
项目:github-integration-plugin    文件:GHRule.java   
public void commitFileToBranch(String branch, String fileName, String content, String commitMessage)
        throws IOException, GitAPIException {
    final String beforeBranch = git.getRepository().getBranch();
    final List<Ref> refList = git.branchList().call();
    boolean exist = false;
    for (Ref ref : refList) {
        if (ref.getName().endsWith(branch)) {
            exist = true;
            break;
        }
    }
    if (!exist) {
        git.branchCreate().setName(branch).call();
    }

    git.checkout().setName(branch).call();

    writeStringToFile(new File(gitRootDir, fileName), content);
    git.add().addFilepattern(".").call();
    git.commit().setAll(true).setMessage(commitMessage).call();
    git.push()
            .setPushAll()
            .setProgressMonitor(new TextProgressMonitor())
            .setCredentialsProvider(new UsernamePasswordCredentialsProvider(GH_TOKEN, ""))
            .call();
    git.checkout().setName(beforeBranch).call();

    await().pollInterval(3, SECONDS)
            .timeout(120, SECONDS)
            .until(ghBranchAppeared(getGhRepo(), branch));
}
项目:gerrit    文件:ProtobufImport.java   
@Override
public int run() throws Exception {
  mustHaveValidSite();

  Injector dbInjector = createDbInjector(SINGLE_USER);
  manager.add(dbInjector);
  manager.start();
  RuntimeShutdown.add(manager::stop);
  dbInjector.injectMembers(this);

  ProgressMonitor progress = new TextProgressMonitor();
  progress.beginTask("Importing entities", ProgressMonitor.UNKNOWN);
  try (ReviewDb db = schemaFactory.open()) {
    for (RelationModel model : new JavaSchemaModel(ReviewDb.class).getRelations()) {
      relations.put(model.getRelationID(), Relation.create(model, db));
    }

    Parser<UnknownFieldSet> parser = UnknownFieldSet.getDefaultInstance().getParserForType();
    try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
      UnknownFieldSet msg;
      while ((msg = parser.parseDelimitedFrom(in)) != null) {
        Map.Entry<Integer, UnknownFieldSet.Field> e =
            Iterables.getOnlyElement(msg.asMap().entrySet());
        Relation rel =
            checkNotNull(
                relations.get(e.getKey()),
                "unknown relation ID %s in message: %s",
                e.getKey(),
                msg);
        List<ByteString> values = e.getValue().getLengthDelimitedList();
        checkState(values.size() == 1, "expected one string field in message: %s", msg);
        upsert(rel, values.get(0));
        progress.update(1);
      }
    }
    progress.endTask();
  }

  return 0;
}
项目:gerrit    文件:AllProjectsIndexer.java   
@Override
public SiteIndexer.Result indexAll(final ProjectIndex index) {
  ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
  progress.start(2);
  List<Project.NameKey> names = collectProjects(progress);
  return reindexProjects(index, names, progress);
}
项目:gerrit    文件:AllGroupsIndexer.java   
@Override
public SiteIndexer.Result indexAll(GroupIndex index) {
  ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
  progress.start(2);
  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);
}
项目:gerrit    文件:AllAccountsIndexer.java   
@Override
public SiteIndexer.Result indexAll(AccountIndex index) {
  ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
  progress.start(2);
  Stopwatch sw = Stopwatch.createStarted();
  List<Account.Id> ids;
  try {
    ids = collectAccounts(progress);
  } catch (IOException e) {
    log.error("Error collecting accounts", e);
    return new SiteIndexer.Result(sw, false, 0, 0);
  }
  return reindexAccounts(index, ids, progress);
}
项目:gerrit    文件:Schema_123.java   
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
  ListMultimap<Account.Id, Change.Id> imports =
      MultimapBuilder.hashKeys().arrayListValues().build();
  try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
      ResultSet rs = stmt.executeQuery("SELECT account_id, change_id FROM starred_changes")) {
    while (rs.next()) {
      Account.Id accountId = new Account.Id(rs.getInt(1));
      Change.Id changeId = new Change.Id(rs.getInt(2));
      imports.put(accountId, changeId);
    }
  }

  if (imports.isEmpty()) {
    return;
  }

  try (Repository git = repoManager.openRepository(allUsersName);
      RevWalk rw = new RevWalk(git)) {
    BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
    ObjectId id = StarredChangesUtil.writeLabels(git, StarredChangesUtil.DEFAULT_LABELS);
    for (Map.Entry<Account.Id, Change.Id> e : imports.entries()) {
      bru.addCommand(
          new ReceiveCommand(
              ObjectId.zeroId(), id, RefNames.refsStarredChanges(e.getValue(), e.getKey())));
    }
    bru.execute(rw, new TextProgressMonitor());
  } catch (IOException | IllegalLabelException ex) {
    throw new OrmException(ex);
  }
}
项目:editor-de-servicos    文件:RepositorioGitTest.java   
@SneakyThrows
private static void clone(String from, File to) {
    Git.cloneRepository()
            .setURI(from)
            .setDirectory(to)
            .setProgressMonitor(new TextProgressMonitor())
            .call();
}
项目:editor-de-servicos    文件:RepositorioGitTest.java   
@SneakyThrows
private static void cloneBare(String from, File to) {
    Git.cloneRepository()
            .setURI(from)
            .setDirectory(to)
            .setBare(true)
            .setProgressMonitor(new TextProgressMonitor())
            .call();
}
项目:n4js    文件:GitUtils.java   
private static TextProgressMonitor createMonitor() {
    return new TextProgressMonitor(new OutputStreamWriter(System.out));
}
项目:maven-gitdep-plugin    文件:DownloaderMojo.java   
private Git clone(POM pom, GitDependency dependency) {
    final CloneCommand c = new CloneCommand();

    c.setURI(dependency.getLocation());
    c.setCloneAllBranches(true);
    c.setProgressMonitor(new TextProgressMonitor());

    final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency);

    String version = "";

    version = dependencyHandler.getDependencyVersion(pom);

    final String tempDirectory = Directory.getTempDirectoryString(dependency.getLocation(), version);
    c.setDirectory(new File(tempDirectory));

    return c.call();
}
项目:gerrit    文件:Schema_161.java   
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
  try (Repository git = repoManager.openRepository(allUsersName);
      RevWalk rw = new RevWalk(git)) {
    BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
    bru.setAllowNonFastForwards(true);

    for (Ref ref : git.getRefDatabase().getRefs(RefNames.REFS_STARRED_CHANGES).values()) {
      StarRef starRef = StarredChangesUtil.readLabels(git, ref.getName());

      Set<Integer> mutedPatchSets =
          StarredChangesUtil.getStarredPatchSets(starRef.labels(), MUTE_LABEL);
      if (mutedPatchSets.isEmpty()) {
        continue;
      }

      Set<Integer> reviewedPatchSets =
          StarredChangesUtil.getStarredPatchSets(
              starRef.labels(), StarredChangesUtil.REVIEWED_LABEL);
      Set<Integer> unreviewedPatchSets =
          StarredChangesUtil.getStarredPatchSets(
              starRef.labels(), StarredChangesUtil.UNREVIEWED_LABEL);

      List<String> newLabels =
          starRef
              .labels()
              .stream()
              .map(
                  l -> {
                    if (l.startsWith(MUTE_LABEL)) {
                      Integer mutedPatchSet = Ints.tryParse(l.substring(MUTE_LABEL.length() + 1));
                      if (mutedPatchSet == null) {
                        // unexpected format of mute label, must be a label that was manually
                        // set, just leave it alone
                        return l;
                      }
                      if (!reviewedPatchSets.contains(mutedPatchSet)
                          && !unreviewedPatchSets.contains(mutedPatchSet)) {
                        // convert mute label to reviewed label
                        return StarredChangesUtil.REVIEWED_LABEL + "/" + mutedPatchSet;
                      }
                      // else patch set is muted but has either reviewed or unreviewed label
                      // -> just drop the mute label
                      return null;
                    }
                    return l;
                  })
              .filter(Objects::nonNull)
              .collect(toList());

      ObjectId id = StarredChangesUtil.writeLabels(git, newLabels);
      bru.addCommand(new ReceiveCommand(ref.getTarget().getObjectId(), id, ref.getName()));
    }
    bru.execute(rw, new TextProgressMonitor());
  } catch (IOException | IllegalLabelException ex) {
    throw new OrmException(ex);
  }
}
项目:bluemarlin    文件:TakeDown.java   
public TakeDown(String localPath, String remotePath, PrintStream ps) {
    this.ps = ps;
    monitor = new TextProgressMonitor(new PrintWriter(ps, true));
    this.remotePath = remotePath;
    this.localPath = localPath;
}
项目:j-git-backup    文件:JGitTester.java   
@Test
public void test() throws IOException, GitAPIException {


    String user = "";
    String passwd = "";
    String hostPath = "/git";
    String backupRoot = "/tmp/test";
    String gitRoot = "/mnt";
    String bundlePath = "/tmp";
    boolean keepOld = false;

    List<org.jdamico.jgitbkp.entities.RepoImpl> repos = new ArrayList<org.jdamico.jgitbkp.entities.RepoImpl>();

    File fGitRoot = new File(gitRoot);
    String[] fRepos = fGitRoot.list();
    for (String itemRepo : fRepos) {
        File fItemRepo = new File(gitRoot+"/"+itemRepo);
        if(fItemRepo.isDirectory() && itemRepo.contains(".git") && !itemRepo.equals(".git")){
            repos.add(new org.jdamico.jgitbkp.entities.RepoImpl(itemRepo, null, backupRoot+"/"+itemRepo));
        }
    }

    for(int i=0; i<repos.size(); i++){

        File f = new File(repos.get(i).getClonedPath());

        if(f.mkdir()){

            Git.cloneRepository()
            .setCloneAllBranches(true)
            .setURI("http://"+hostPath+"/"+repos.get(i).getName())
            .setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, passwd))
            .setDirectory(new File(repos.get(i).getClonedPath()))
            .setProgressMonitor(new TextProgressMonitor()).call();

        }

        File gitWorkDir = new File(repos.get(i).getClonedPath());
        Git git = Git.open(gitWorkDir);
        git.pull();
        Repository localRepoGit = git.getRepository();
        BundleWriter bundleWriter = new BundleWriter(localRepoGit);
        ProgressMonitor pMonitor = new TextProgressMonitor();
        OutputStream oStream = new FileOutputStream(bundlePath+"/"+repos.get(i).getName()+".bundle");

        Map<String, Ref> allRefs = localRepoGit.getAllRefs();
        Collection<Ref> values = allRefs.values();
        Iterator<Ref> iter = values.iterator();
        while(iter.hasNext()){
            Ref element = iter.next();
            try {

                bundleWriter.include(element);
                System.out.println("Added: "+element.getName());
            } catch (Exception e) {
                // TODO: handle exception
            }


        }


        bundleWriter.writeBundle(pMonitor, oStream);


    }

}