예제 #1
0
 private void debugRange() {
   LOGGER.debug(
       "Limiting data to range: "
           + (config.getStart() == null ? "first-commit" : config.getStart())
           + " - "
           + (config.getEnd() == null ? "most-recent-commit" : config.getEnd()));
 }
예제 #2
0
  private void printLimitedRange(final BranchInfo... bis) {

    debugRange();

    for (final BranchInfo bi : bis) {

      final AuthorInfoBuilder aib =
          bi.getAuthorStatistics()
              .limitToDateRange(Util.getAppropriateRange(config.getStart(), config.getEnd()));
      out.println(aib);
    }
  }
예제 #3
0
  /** Prints the help message to stdout. */
  void help() {
    if (config.getUrl() == null) {
      out.println(ProgramConfig.getUsage());
    } else {

      try {
        final Action action = Action.valueOf(config.getUrl().toUpperCase());
        out.print(action.getUsage());
      } catch (final Exception e) {
        LOGGER.trace("Unrecognized help parameter", e);
        out.println(ProgramConfig.getUsage());
      }
    }
  }
예제 #4
0
  public static void main(final String[] args) throws GitAPIException {

    Util.setLoggingLevel(Level.INFO);

    try {
      APPLICATION.setConfig(ProgramConfig.parseArgs(args)).execute();
    } catch (final Exception e) {
      err.println("An error occurred during application execution: " + e.getMessage());
      LOGGER.debug("Error: ", e);
    }
  }
예제 #5
0
  /**
   * Runs the program with the given config parameters.
   *
   * @throws GitAPIException
   * @throws SVNException
   */
  void execute() throws GitAPIException, SVNException {

    if (config.shouldShowVersion()) {
      out.println(VERISION);
    }

    if (config.isDebugEnabled()) {
      Util.setLoggingLevel(Level.DEBUG);
    }

    LOGGER.debug("Executing with params: " + config.toString());

    if (!config.getAction().isValid(config)) {
      out.println(config.getAction().getUsage());
      return;
    }

    switch (config.getAction()) {
      case ANALYZE:
        analyze();
        break;
      case INIT:
        init();
        break;
      case DEBUG:
        debug();
        break;
      case HELP:
      default:
        help();
        break;
    }
  }
예제 #6
0
  private void analyze() throws GitAPIException, SVNException {

    if (config.getUrl() == null) {

      out.println();

    } else {

      ClocService.init();

      if (config.shouldForceGit()) {
        analyzeAsGit();
      } else if (config.shouldForceSvn()) {
        analyzeAsSVN();
      } else {

        if (config.getUrl().endsWith(".git")) {
          analyzeAsGit();
        } else {
          analyzeAsSVN();
        }
      }
    }
  }
예제 #7
0
  private void analyzeAsGit() throws GitAPIException {

    final UsernamePasswordCredentialsProvider cp =
        new UsernamePasswordCredentialsProvider(config.getUsername(), config.getPassword());

    final GitRepo repo = new GitRepo(config.getUrl(), config.getBranch(), false, cp);
    repo.sync(config.getBranch(), config.shouldGenerateStats(), config.shouldUseCloc());

    if (!(config.getStart() == null && config.getEnd() == null)) {

      if (config.getBranch() != null) {
        printLimitedRange(repo.getRepoStatistics().getBranchInfoFor(config.getBranch()));
      } else {
        printLimitedRange(repo.getRepoStatistics().getBranchInfos());
      }

    } else {
      out.println(repo.getRepoStatistics().toString(config.shouldShowCommits()));
    }

    repo.close();
  }
예제 #8
0
  /**
   * Treats the url as a svn repo
   *
   * @throws SVNException
   * @throws BranchNotFoundException
   */
  private void analyzeAsSVN() throws SVNException, BranchNotFoundException {

    if (config.shouldForceSvn()) {
      LOGGER.debug("Force running as SVN");
    }

    final SVNRepo repo =
        new SVNRepo(
            config.getUrl(),
            config.getBranch(),
            config.getUsername(),
            config.getPassword(),
            false,
            false);

    repo.setLogEntryCacheDisabled(config.svnIgnoreCache);

    repo.sync(
        config.getBranch(),
        config.shouldGetLangStats(),
        config.shouldGenerateStats(),
        config.getRevA(),
        config.getRevB());

    if (!(config.getStart() == null && config.getEnd() == null)) {

      if (config.getBranch() != null) {
        printLimitedRange(repo.getRepoStatistics().getBranchInfoFor(config.getBranch()));
      } else {
        printLimitedRange(repo.getRepoStatistics().getBranchInfos());
      }

    } else {
      out.println(repo.getRepoStatistics().toString(config.shouldShowCommits()));
    }
  }