Exemplo n.º 1
0
  public boolean isBinaryRepositoryAvailable() {

    boolean result = false;
    // get the name of the source repository
    // String repositoryName = getRepositoryName();

    // find where ".git" folder is found
    File f = sourceRepository.getDirectory();

    // repository foldername
    String repositoryFolderName = f.getParentFile().getName();

    // go to parent directory
    File parent = f.getParentFile().getParentFile();
    File binaryRepoFolder = new File(parent, ("." + repositoryFolderName));

    // check whether ".SourceRepo.git" folder exists
    if (binaryRepoFolder.exists() && binaryRepoFolder.isDirectory() && binaryRepoFolder.canRead()) {
      // check whether ".SourceRepo.git/.git" exists
      File binGit = new File(binaryRepoFolder, ".git");
      if (binGit.exists() && binGit.isDirectory() && binGit.canRead()) {
        result = true;
      }
    }

    // return result && isRepoPresentInGit();
    boolean remoteRepoCheck = false;
    try {
      remoteRepoCheck = isRemoteBinaryRepositoryAvailable();
    } catch (GitException e) {
      e.printStackTrace();
    }

    if (result && remoteRepoCheck) {
      try {
        binaryRepository = new FileRepository(new File(binaryRepoFolder, ".git"));
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    return result && remoteRepoCheck;
  }
Exemplo n.º 2
0
  private int[] getGitVersion() {
    int minorVer = 1;
    int majorVer = 6;

    try {
      String v = firstLine(launchCommand("--version")).trim();
      Pattern p = Pattern.compile("git version ([0-9]+)\\.([0-9+])\\..*");
      Matcher m = p.matcher(v);
      if (m.matches() && m.groupCount() >= 2) {
        try {
          majorVer = Integer.parseInt(m.group(1));
          minorVer = Integer.parseInt(m.group(2));
        } catch (NumberFormatException e) {
        }
      }
    } catch (GitException ex) {
      listener.getLogger().println("Error trying to determine the git version: " + ex.getMessage());
      listener.getLogger().println("Assuming 1.6");
    }

    return new int[] {majorVer, minorVer};
  }
  public static void main(String[] args) throws Exception {
    Map<String, String> arguments = ArgumentsUtil.parseArguments(args);

    try {
      SourceFormatterArgs sourceFormatterArgs = new SourceFormatterArgs();

      boolean autoFix =
          GetterUtil.getBoolean(arguments.get("source.auto.fix"), SourceFormatterArgs.AUTO_FIX);

      sourceFormatterArgs.setAutoFix(autoFix);

      String baseDirName =
          GetterUtil.getString(arguments.get("source.base.dir"), SourceFormatterArgs.BASE_DIR_NAME);

      sourceFormatterArgs.setBaseDirName(baseDirName);

      boolean formatCurrentBranch =
          GetterUtil.getBoolean(
              arguments.get("format.current.branch"), SourceFormatterArgs.FORMAT_CURRENT_BRANCH);

      sourceFormatterArgs.setFormatCurrentBranch(formatCurrentBranch);

      boolean formatLatestAuthor =
          GetterUtil.getBoolean(
              arguments.get("format.latest.author"), SourceFormatterArgs.FORMAT_LATEST_AUTHOR);

      sourceFormatterArgs.setFormatLatestAuthor(formatLatestAuthor);

      boolean formatLocalChanges =
          GetterUtil.getBoolean(
              arguments.get("format.local.changes"), SourceFormatterArgs.FORMAT_LOCAL_CHANGES);

      sourceFormatterArgs.setFormatLocalChanges(formatLocalChanges);

      if (formatCurrentBranch) {
        sourceFormatterArgs.setRecentChangesFileNames(
            GitUtil.getCurrentBranchFileNames(baseDirName));
      } else if (formatLatestAuthor) {
        sourceFormatterArgs.setRecentChangesFileNames(
            GitUtil.getLatestAuthorFileNames(baseDirName));
      } else if (formatLocalChanges) {
        sourceFormatterArgs.setRecentChangesFileNames(
            GitUtil.getLocalChangesFileNames(baseDirName));
      }

      String copyrightFileName =
          GetterUtil.getString(
              arguments.get("source.copyright.file"), SourceFormatterArgs.COPYRIGHT_FILE_NAME);

      sourceFormatterArgs.setCopyrightFileName(copyrightFileName);

      String[] fileNames = StringUtil.split(arguments.get("source.files"), StringPool.COMMA);

      if (ArrayUtil.isNotEmpty(fileNames)) {
        sourceFormatterArgs.setFileNames(Arrays.asList(fileNames));
      }

      boolean printErrors =
          GetterUtil.getBoolean(
              arguments.get("source.print.errors"), SourceFormatterArgs.PRINT_ERRORS);

      sourceFormatterArgs.setPrintErrors(printErrors);

      boolean throwException =
          GetterUtil.getBoolean(
              arguments.get("source.throw.exception"), SourceFormatterArgs.THROW_EXCEPTION);

      sourceFormatterArgs.setThrowException(throwException);

      boolean useProperties =
          GetterUtil.getBoolean(
              arguments.get("source.use.properties"), SourceFormatterArgs.USE_PROPERTIES);

      sourceFormatterArgs.setUseProperties(useProperties);

      SourceFormatter sourceFormatter = new SourceFormatter(sourceFormatterArgs);

      sourceFormatter.format();
    } catch (GitException ge) {
      System.out.println(ge.getMessage());

      System.exit(0);
    } catch (Exception e) {
      ArgumentsUtil.processMainException(arguments, e);
    }
  }