Example usage for org.eclipse.jgit.lib Repository getDirectory

List of usage examples for org.eclipse.jgit.lib Repository getDirectory

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository getDirectory.

Prototype


public File getDirectory() 

Source Link

Document

Get local metadata directory

Usage

From source file:org.uberfire.java.nio.fs.jgit.JGitFileSystemLockTest.java

License:Apache License

private JGitFileSystemLock createLock(long lastAccessThreshold) {
    Git gitMock = mock(Git.class);
    Repository repo = mock(Repository.class);
    File directory = mock(File.class);
    when(directory.isDirectory()).thenReturn(true);
    when(directory.toURI()).thenReturn(URI.create(""));
    when(repo.getDirectory()).thenReturn(directory);
    when(gitMock.getRepository()).thenReturn(repo);
    return new JGitFileSystemLock(gitMock, TimeUnit.MILLISECONDS, lastAccessThreshold) {

        @Override/*from   w  w  w. j  a va  2 s  . c o  m*/
        Path createLockInfra(URI uri) {
            return mock(Path.class);
        }
    };
}

From source file:org.uberfire.java.nio.fs.jgit.manager.JGitFileSystemsManager.java

License:Apache License

private String extractFSNameFromRepo(Repository db) {
    final String fullRepoName = config.getGitReposParentDir().toPath().relativize(db.getDirectory().toPath())
            .toString();//from  w  w  w.j a va 2  s.c  om
    return fullRepoName.substring(0, fullRepoName.indexOf(DOT_GIT_EXT)).replace('\\', '/');
}

From source file:org.uberfire.java.nio.fs.jgit.util.commands.RefTreeUpdateCommand.java

License:Apache License

private void commit(final Repository repo, final RevCommit original, final BiFunction fun) throws IOException {
    try (final ObjectReader reader = repo.newObjectReader();
            final ObjectInserter inserter = repo.newObjectInserter();
            final RevWalk rw = new RevWalk(reader)) {

        final RefTreeDatabase refdb = (RefTreeDatabase) repo.getRefDatabase();
        final RefDatabase bootstrap = refdb.getBootstrap();
        final RefUpdate refUpdate = bootstrap.newUpdate(refdb.getTxnCommitted(), false);

        final CommitBuilder cb = new CommitBuilder();
        final Ref ref = bootstrap.exactRef(refdb.getTxnCommitted());
        final RefTree tree;
        if (ref != null && ref.getObjectId() != null) {
            tree = RefTree.read(reader, rw.parseTree(ref.getObjectId()));
            cb.setParentId(ref.getObjectId());
            refUpdate.setExpectedOldObjectId(ref.getObjectId());
        } else {//  ww  w  .ja  va2s . c o  m
            tree = RefTree.newEmptyTree();
            refUpdate.setExpectedOldObjectId(ObjectId.zeroId());
        }

        if (fun.apply(reader, tree)) {
            final Ref ref2 = bootstrap.exactRef(refdb.getTxnCommitted());
            if (ref2 == null || ref2.getObjectId().equals(ref != null ? ref.getObjectId() : null)) {
                cb.setTreeId(tree.writeTree(inserter));
                if (original != null) {
                    cb.setAuthor(original.getAuthorIdent());
                    cb.setCommitter(original.getAuthorIdent());
                } else {
                    final PersonIdent personIdent = new PersonIdent("user", "user@example.com");
                    cb.setAuthor(personIdent);
                    cb.setCommitter(personIdent);
                }
                refUpdate.setNewObjectId(inserter.insert(cb));
                inserter.flush();
                final RefUpdate.Result result = refUpdate.update(rw);
                switch (result) {
                case NEW:
                case FAST_FORWARD:
                    break;
                default:
                    throw new RuntimeException(
                            repo.getDirectory() + " -> " + result.toString() + " : " + refUpdate.getName());
                }
                final File commited = new File(repo.getDirectory(), refdb.getTxnCommitted());
                final File accepted = new File(repo.getDirectory(), refdb.getTxnNamespace() + "accepted");
                Files.copy(commited.toPath(), accepted.toPath(), StandardCopyOption.REPLACE_EXISTING);
            }
        }
    }
}

From source file:org.uberfire.java.nio.fs.jgit.util.commands.SubdirectoryClone.java

License:Apache License

private List<RevCommit> getBranchCommits(final Repository repository, final RevWalk revWalk) {
    final List<RevCommit> branchTips = branches.stream().map(b -> {
        try {// w  w w  . jav  a2 s.  c o m
            return revWalk.parseCommit(repository.resolve(b));
        } catch (IOException ioe) {
            throw new IllegalArgumentException(
                    format("Unable to parse branch [%s] in repository [%s].", b, repository.getDirectory()));
        }
    }).collect(toList());
    return branchTips;
}

From source file:org.wso2.security.tools.scanner.dependency.js.reportpublisher.GitUploader.java

License:Open Source License

/**
 * Add generated reports to cloned github repository.
 *
 * @param productResponseMapper Mapper for product and scan result.
 * @throws GitAPIException      Exception occurred during github API call.
 * @throws FileHandlerException Exception occurred during report generation.
 *//*from   w  w w .  ja  va 2s. c om*/
private void storeFiles(HashMap<String, String> productResponseMapper)
        throws GitAPIException, FileHandlerException {
    Repository repository = gitRepo.getRepository();
    File targetDir = new File(repository.getDirectory().getParentFile().getAbsolutePath()
            + JSScannerConstants.SCN_REPORT_DIRECTORY_PATH);
    HashMap<String, String> fileMapper;
    fileMapper = ReportWriter.callWriter(productResponseMapper, targetDir);
    // Stage all files in the repo including new files
    gitRepo.add().addFilepattern(".").call();
    this.setReportFileMapper(fileMapper);
    log.info("[JS_SEC_DAILY_SCAN]  " + "Added files to Security artifact repo");
}

From source file:org.xwiki.contrib.githubstats.StubGitManager.java

License:Open Source License

private void addCommit(String authorId, String emailId, long commitDate, String file, Repository gitRepository,
        GitHelper gitHelper) throws Exception {
    PersonIdent author;/*from   w  w w  . j a  v  a2  s.  co  m*/
    if (commitDate == 0) {
        author = new PersonIdent(authorId, emailId);
    } else {
        author = new PersonIdent(authorId, emailId, commitDate, 0);
    }

    gitHelper.add(gitRepository.getDirectory(), file, "test content", author, author, "commit");
}

From source file:org.xwiki.git.internal.GitScriptServiceTest.java

License:Open Source License

private File createGitTestRepository(String repoName) throws Exception {
    File localDirectory = getRepositoryFile(repoName);
    File gitDirectory = new File(localDirectory, ".git");
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.setGitDir(gitDirectory).readEnvironment().findGitDir().build();
    repository.create();/*from w  w w  .  j av  a  2  s .c om*/
    return repository.getDirectory();
}

From source file:playRepository.BareRepository.java

License:Apache License

private static ObjectId getFirstFoundREADMEfileObjectId(Repository repository) throws IOException {
    TreeWalk treeWalk = new TreeWalk(repository);
    RevTree revTree = getRevTreeFromRef(repository, repository.getRef(HEAD));
    if (revTree == null) {
        return ObjectId.zeroId();
    }/*from  w w w.j  a  va  2s  .  c o  m*/
    treeWalk.addTree(revTree);
    treeWalk.setRecursive(false);
    treeWalk.setFilter(OrTreeFilter.create(READMEFileNameFilter()));

    if (!treeWalk.next()) {
        play.Logger.info("No tree or no README file found at " + repository.getDirectory());
    }
    return treeWalk.getObjectId(0);
}

From source file:playRepository.GitRepository.java

License:Apache License

/**
 * Clones a local repository./*  w w w  . j  av a  2  s .  co m*/
 *
 * This doesn't copy Git objects but hardlink them to save disk space.
 *
 * @param originalProject
 * @param forkProject
 * @throws IOException
 */
protected static void cloneHardLinkedRepository(Project originalProject, Project forkProject)
        throws IOException {
    Repository origin = GitRepository.buildGitRepository(originalProject);
    Repository forked = GitRepository.buildGitRepository(forkProject);
    forked.create();

    final Path originObjectsPath = Paths.get(new File(origin.getDirectory(), "objects").getAbsolutePath());
    final Path forkedObjectsPath = Paths.get(new File(forked.getDirectory(), "objects").getAbsolutePath());

    // Hardlink files .git/objects/ directory to save disk space,
    // but copy .git/info/alternates because the file can be modified.
    SimpleFileVisitor<Path> visitor = new SimpleFileVisitor<Path>() {
        public FileVisitResult visitFile(Path file, BasicFileAttributes attr) throws IOException {
            Path newPath = forkedObjectsPath.resolve(originObjectsPath.relativize(file.toAbsolutePath()));
            if (file.equals(forkedObjectsPath.resolve("/info/alternates"))) {
                Files.copy(file, newPath);
            } else {
                FileUtils.mkdirs(newPath.getParent().toFile(), true);
                Files.createLink(newPath, file);
            }
            return java.nio.file.FileVisitResult.CONTINUE;
        }
    };
    Files.walkFileTree(originObjectsPath, visitor);

    // Import refs.
    for (Map.Entry<String, Ref> entry : origin.getAllRefs().entrySet()) {
        RefUpdate updateRef = forked.updateRef(entry.getKey());
        Ref ref = entry.getValue();
        if (ref.isSymbolic()) {
            updateRef.link(ref.getTarget().getName());
        } else {
            updateRef.setNewObjectId(ref.getObjectId());
            updateRef.update();
        }
    }
}

From source file:svnserver.repository.git.push.GitPushEmbedded.java

License:GNU General Public License

private void runHook(@NotNull Repository repository, @Nullable String hook, @NotNull User userInfo,
        @NotNull HookRunner runner) throws IOException, SVNException {
    if (hook == null || hook.isEmpty()) {
        return;/*from  w  w  w  .j av a  2  s . c  o  m*/
    }
    final File script = ConfigHelper.joinPath(ConfigHelper.joinPath(repository.getDirectory(), "hooks"), hook);
    if (script.isFile()) {
        try {
            final ProcessBuilder processBuilder = new ProcessBuilder(script.getAbsolutePath())
                    .directory(repository.getDirectory()).redirectErrorStream(true);
            processBuilder.environment().put("LANG", "en_US.utf8");
            userInfo.updateEnvironment(processBuilder.environment());
            context.sure(UserDB.class).updateEnvironment(processBuilder.environment(), userInfo);
            final Process process = runner.exec(processBuilder);
            final String hookMessage = CharStreams
                    .toString(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));
            int exitCode = process.waitFor();
            if (exitCode != 0) {
                throw new SVNException(SVNErrorMessage.create(SVNErrorCode.REPOS_HOOK_FAILURE,
                        "Commit blocked by hook with output:\n" + hookMessage));
            }
        } catch (InterruptedException e) {
            log.error("Hook interrupted: " + script.getAbsolutePath(), e);
            throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_WRITE_ERROR, e));
        }
    }
}