Java Code Examples for org.eclipse.jgit.storage.file.FileRepositoryBuilder#build()

The following examples show how to use org.eclipse.jgit.storage.file.FileRepositoryBuilder#build() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitRepo.java    From git-changelog-lib with Apache License 2.0 6 votes vote down vote up
public GitRepo(final File repo) throws GitChangelogRepositoryException {
  try {
    File repoFile = new File(repo.getAbsolutePath());
    final File gitRepoFile = new File(repo.getAbsolutePath() + "/.git");
    if (gitRepoFile.exists()) {
      repoFile = gitRepoFile;
    }
    final FileRepositoryBuilder builder =
        new FileRepositoryBuilder() //
            .findGitDir(repoFile) //
            .readEnvironment();
    if (builder.getGitDir() == null) {
      throw new GitChangelogRepositoryException(
          "Did not find a GIT repo in " + repo.getAbsolutePath());
    }
    this.repository = builder.build();
    this.revWalk = new RevWalk(this.repository);
    this.git = new Git(this.repository);
  } catch (final IOException e) {
    throw new GitChangelogRepositoryException(
        "Could not use GIT repo in " + repo.getAbsolutePath(), e);
  }
}
 
Example 2
Source File: SimpleCommitSearcher.java    From SZZUnleashed with MIT License 5 votes vote down vote up
/**
 * Constructor using a path to a local repository.
 */
public SimpleCommitSearcher(String repoPath) throws IOException, GitAPIException {
  Configuration conf = Configuration.getInstance();
  FileRepositoryBuilder builder = new FileRepositoryBuilder();
  builder.setMustExist(true);

  builder.addCeilingDirectory(new File(repoPath));
  builder.findGitDir(new File(repoPath));
  this.repo = builder.build();
  this.git = new Git(repo);

  bugpatterns = Arrays.asList(compile("JENKINS\\-[0-9]"));
}
 
Example 3
Source File: GitParser.java    From SZZUnleashed with MIT License 5 votes vote down vote up
/**
 * The constructor for the GitParser class. It requires the repository to exist and will fail if
 * its not. The resultPath is also created if it's not existing.
 *
 * @param path the path to where the local repository can be found.
 * @param resultPath the path to where the JSON files will be written.
 */
public GitParser(String path, String resultPath, int depth, int customContext)
    throws IOException, GitAPIException {
  FileRepositoryBuilder builder = new FileRepositoryBuilder();
  builder.setMustExist(true);

  builder.addCeilingDirectory(new File(path));
  builder.findGitDir(new File(path));
  this.repo = builder.build();

  this.resultPath = resultPath;

  /*
   * Check if the resultpath exists otherwise create it.
   */

  if (this.resultPath != null) {
    File resDirectory = new File(resultPath);
    if (!resDirectory.exists()) resDirectory.mkdirs();
  } else {
    System.err.println("Resultpath not set! Using deafult directory instead.");
    this.resultPath = this.DEFAULT_RES_PATH;
  }

  this.util = new CommitUtil(this.repo, customContext);

  this.depth = depth;
}
 
Example 4
Source File: GitFlowMetaData.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
/**
 * Open a Git repository using the specified directory.
 * @param gitProjectRootDir a root directory of a Git project
 * @return created Repository
 * @throws IOException thrown when the specified directory does not exist,
 * does not have read/write privilege or not containing .git directory
 */
private Repository openRepository(final File gitProjectRootDir) throws IOException {

    // Instead of using FileUtils.ensureDirectoryExistAndCanReadAndWrite, check availability manually here.
    // Because the util will try to create a dir if not exist.
    // The git dir should be initialized and configured by users.
    if (!gitProjectRootDir.isDirectory()) {
        throw new IOException(format("'%s' is not a directory or does not exist.", gitProjectRootDir));
    }

    if (!(gitProjectRootDir.canRead() && gitProjectRootDir.canWrite())) {
        throw new IOException(format("Directory '%s' does not have read/write privilege.", gitProjectRootDir));
    }

    // Search .git dir but avoid searching parent directories.
    final FileRepositoryBuilder builder = new FileRepositoryBuilder()
            .readEnvironment()
            .setMustExist(true)
            .addCeilingDirectory(gitProjectRootDir)
            .findGitDir(gitProjectRootDir);

    if (builder.getGitDir() == null) {
        throw new IOException(format("Directory '%s' does not contain a .git directory." +
                " Please init and configure the directory with 'git init' command before using it from NiFi Registry.",
                gitProjectRootDir));
    }

    return builder.build();
}
 
Example 5
Source File: Git.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
public Git() throws IOException {
  final FileRepositoryBuilder builder = new FileRepositoryBuilder();
  // scan environment GIT_* variables
  builder.readEnvironment();
  // scan up the file system tree
  builder.findGitDir();
  // if getGitDir is null, then we are not in a git repository
  repo = builder.getGitDir() == null ? null : builder.build();
}