List of usage examples for org.eclipse.jgit.storage.file FileRepositoryBuilder FileRepositoryBuilder
FileRepositoryBuilder
From source file:actions.DownloadSPDX.java
/** * Get the files from a given repository on github * @param slotId The thread where the download is happening * @param localPath The bigArchive on disk where the files will be placed * @param location The username/repository identification. We'd * expect something like triplecheck/reporter * @return True if everything went ok, false if something went wrong *//* w ww .jav a 2 s. co m*/ public Boolean download(final int slotId, final File localPath, final String location) { // we can't have any older files files.deleteDir(localPath); final String REMOTE_URL = "https://github.com/" + location + ".git"; try { Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).call(); // now open the created repository FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(localPath).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); System.out.println(slotId + "-> Downloaded repository: " + repository.getDirectory()); repository.close(); } catch (Exception ex) { Logger.getLogger(Repositories.class.getName()).log(Level.SEVERE, null, ex); // we need to add this event on the exception list utils_deprecated.files.addTextToFile(fileExceptionHappened, "\n" + location); // delete the files if possible files.deleteDir(localPath); System.out.println(slotId + " !!!! Failed to download: " + location); // clean up the slot slots[slotId] = false; return false; } System.out.println(slotId + "-> Downloaded: " + location); return true; }
From source file:at.ac.tuwien.inso.subcat.miner.GitMiner.java
License:Open Source License
private void _run() throws IOException, MinerException, SQLException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(new File(settings.srcLocalPath, ".git")).readEnvironment() .findGitDir().build();//from w w w. java2 s . c o m /* Map<String,Ref> refs = repository.getAllRefs(); for (Map.Entry<String, Ref> ref : refs.entrySet ()) { System.out.println (ref.getKey ()); } */ Ref head = repository.getRef(startRef); if (head == null) { throw new MinerException("Unknown reference: '" + startRef + "'"); } RevWalk walk = new RevWalk(repository); RevCommit commit = walk.parseCommit(head.getObjectId()); walk.markStart(commit); walk.sort(RevSort.REVERSE); // count commit: (fast) int commitCount = 0; Iterator<RevCommit> iter = walk.iterator(); while (iter.hasNext()) { iter.next(); commitCount++; } emitTasksTotal(commitCount); // process commits: (slow) walk.reset(); walk.markStart(commit); walk.sort(RevSort.REVERSE); Map<String, ManagedFile> fileCache = new HashMap<String, ManagedFile>(); for (RevCommit rev : walk) { if (stopped == true) { break; } processCommit(repository, walk, rev, fileCache); } walk.dispose(); repository.close(); }
From source file:bluej.groupwork.git.GitProvider.java
License:Open Source License
@Override public Repository getRepository(File projectDir, TeamSettings settings) { try {/*from ww w .j av a2s. co m*/ FileRepositoryBuilder builder = new FileRepositoryBuilder(); return new GitRepository(projectDir, settings.getProtocol(), makeGitUrl(settings), builder, settings.getUserName(), settings.getPassword(), settings.getYourName(), settings.getYourEmail()); } catch (UnsupportedSettingException e) { Debug.reportError("GitProvider.getRepository", e); return null; } }
From source file:boa.datagen.scm.GitConnector.java
License:Apache License
public GitConnector(final String path) { try {/*from w ww. j a v a2 s . c o m*/ this.path = path; this.repository = new FileRepositoryBuilder().setGitDir(new File(path + "/.git")).build(); this.git = new Git(this.repository); this.revwalk = new RevWalk(this.repository); } catch (final IOException e) { if (debug) System.err.println("Git Error connecting to " + path + ". " + e.getMessage()); } }
From source file:br.com.riselabs.cotonet.crawler.RepositoryCrawler.java
License:Open Source License
private Repository openRepository() throws IOException { // now open the resulting repository with a FileRepositoryBuilder FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.setWorkTree(repositoryDir);//from ww w. j a v a 2 s. c o m // builder.readEnvironment(); // scan environment GIT_* variables // builder.findGitDir(); // scan up the file system tree builder.setMustExist(true); Repository repository = builder.build(); return repository; }
From source file:ch.dals.buildtools.git.core.GitUtil.java
License:Open Source License
public static String currentBranch(final File location) throws IOException { final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final File gitDir = builder.findGitDir(location).readEnvironment().getGitDir(); if (gitDir == null) { throw new FileNotFoundException("Cannot find Git directory upwards from: '" + location + "'"); }/*from w w w .ja v a2 s . c o m*/ final Repository repository = builder.build(); try { final String branchName = repository.getBranch(); if (branchName == null) { throw new FileNotFoundException("Failed to find HEAD reference in Git directory: '" + gitDir + "'"); } return branchName; } finally { repository.close(); } }
From source file:ch.uzh.ifi.seal.permo.history.git.core.model.jgit.JGitService.java
License:Apache License
/** * {@inheritDoc}//from www . j a v a 2 s. co m */ @Override public Optional<Repository> getRepository(final Project project) { final IProject eclipseProject = getEclipseProject(project); if (eclipseProject.exists()) { try { final Optional<File> gitFolder = getGitFolder(eclipseProject); if (gitFolder.isPresent()) { final org.eclipse.jgit.lib.Repository repository = new FileRepositoryBuilder() .setGitDir(gitFolder.get()).readEnvironment().findGitDir().build(); return Optional.of(JGitRepository.of(repository)); } } catch (final IOException e) { } } return Optional.empty(); }
From source file:co.turnus.versioning.impl.GitVersioner.java
License:Open Source License
private Repository searchNearestRepository(File file) { if (file == null) { return null; } else if (file.exists()) { try {/* w w w . j av a2s.c o m*/ Repository repo = new FileRepositoryBuilder().findGitDir(file.getCanonicalFile()).build(); ObjectId revision = repo.resolve(Constants.HEAD); if (revision != null) { return repo; } } catch (Exception e) { } } return searchNearestRepository(file.getParentFile()); }
From source file:com.bb.extensions.plugin.unittests.internal.git.GitWrapper.java
License:Open Source License
/** * Clones the git repository located at the given url to the given path. * //from ww w. j a v a 2 s . c o m * @param path * * @param url * @return The GitWrapper to interact with the clone git repository. * @throws IllegalArgumentException */ public static GitWrapper cloneRepository(String path, String url) throws IllegalArgumentException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); File gitDir = new File(path); if (gitDir.exists() == false) { gitDir.mkdir(); } else if (gitDir.list().length > 0) { if (isGitRepository(gitDir)) { return openRepository(path); } else { throw new IllegalArgumentException("Cannot clone to a non-empty directory"); } } Repository repository; try { repository = builder.setGitDir(gitDir).readEnvironment().findGitDir().build(); GitWrapper gitWrapper = new GitWrapper(); gitWrapper.git = new Git(repository); CloneCommand clone = Git.cloneRepository(); clone.setBare(false); clone.setCloneAllBranches(true); clone.setDirectory(gitDir).setURI(url); // we have to close the newly returned Git object as call() creates // a new one every time clone.call().getRepository().close(); return gitWrapper; } catch (IOException e) { e.printStackTrace(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } return null; }
From source file:com.buildautomation.jgit.api.CookbookHelper.java
License:Apache License
public static Repository openJGitCookbookRepository() throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build();/*ww w .ja v a 2 s . c o m*/ return repository; }