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

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

Introduction

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

Prototype

@Override
public void close() 

Source Link

Document

Decrement the use count, and maybe close resources.

Usage

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.Observer, Role.User })
@Override/* w w w.j a v  a  2 s.  c om*/
public List<Commit> getLog(String repoName, String revision, String path, Region region)
        throws EntityNotFoundException {
    try {
        Repository r = findRepositoryByName(repoName);
        List<Commit> commits = GitBrowseUtil.getLog(r, revision, path, region);
        r.close();
        return commits;
    } catch (AmbiguousObjectException ex) {
        throw new EntityNotFoundException();
    } catch (IOException ex) {
        throw new EntityNotFoundException();
    } catch (URISyntaxException ex) {
        throw new EntityNotFoundException();
    }

}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.Observer, Role.User })
@Override// ww  w .ja  va 2 s.c o  m
public List<Commit> getLog(String repoName, Region region) throws EntityNotFoundException {
    try {
        Repository repo;
        repo = findRepositoryByName(repoName);
        Set<ObjectId> visited = new HashSet<ObjectId>();

        List<Commit> result = getLog(repo, region, visited);
        repo.close();

        Collections.sort(result, new Comparator<Commit>() {

            @Override
            public int compare(Commit o1, Commit o2) {
                return o2.getDate().compareTo(o1.getDate());
            }
        });

        QueryUtil.applyRegionToList(result, region);

        return result;

    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.User })
@Override/*from w ww. ja v  a  2s  . com*/
public String createBranch(String repoName, String branchName) throws EntityNotFoundException {
    try {
        Repository r = findRepositoryByName(repoName);
        Git git = Git.wrap(r);
        CreateBranchCommand command = git.branchCreate();
        command.setName(branchName);

        /*
         * command.setStartPoint(getStartPoint().name()); if (upstreamMode != null)
         * command.setUpstreamMode(upstreamMode); command.call();
         */

        command.call();
        r.close();
        return branchName;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (GitAPIException e) {
        throw new RuntimeException(e);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.User })
@Override//from w  w  w  .j  a v  a2s.  com
public void deleteBranch(String repoName, String branchName) throws EntityNotFoundException {
    try {
        Repository r = findRepositoryByName(repoName);
        Git git = Git.wrap(r);
        DeleteBranchCommand command = git.branchDelete();
        command.setBranchNames(branchName);
        command.setForce(true);
        command.call();
        r.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (GitAPIException e) {
        throw new RuntimeException(e);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.Observer, Role.User })
@Override/*  ww  w  .  jav  a 2  s  .  c  om*/
public Trees getTrees(String repoName, String revision, String path, boolean history, int recursion)
        throws EntityNotFoundException {
    try {
        Repository r = findRepositoryByName(repoName);
        Trees trees = GitBrowseUtil.getTrees(r, revision, path, history, recursion);
        r.close();
        return trees;
    } catch (AmbiguousObjectException ex) {
        throw new EntityNotFoundException();
    } catch (IOException ex) {
        throw new EntityNotFoundException();
    } catch (URISyntaxException ex) {
        throw new EntityNotFoundException();
    } catch (GitAPIException ex) {
        throw new EntityNotFoundException();
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.Observer, Role.User })
@Override//  ww  w .j a  v  a 2s  .  c om
public Blob getBlob(String repoName, String revision, String path) throws EntityNotFoundException {
    try {
        Repository r = findRepositoryByName(repoName);
        Blob b = GitBrowseUtil.getBlob(r, revision, path);
        r.close();
        return b;
    } catch (AmbiguousObjectException ex) {
        throw new EntityNotFoundException();
    } catch (IOException ex) {
        throw new EntityNotFoundException();
    } catch (URISyntaxException ex) {
        throw new EntityNotFoundException();
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.Observer, Role.User })
@Override//w ww.ja v  a2s. c  o m
public Blame getBlame(String repoName, String revision, String path) throws EntityNotFoundException {
    try {
        Repository r = findRepositoryByName(repoName);
        Blame b = GitBrowseUtil.getBlame(r, revision, path);
        r.close();
        return b;
    } catch (AmbiguousObjectException ex) {
        throw new EntityNotFoundException();
    } catch (IOException ex) {
        throw new EntityNotFoundException();
    } catch (URISyntaxException ex) {
        throw new EntityNotFoundException();
    } catch (GitAPIException e) {
        throw new EntityNotFoundException();
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.Observer, Role.User })
@Override/*ww w .j av  a  2s  . c o m*/
public Commit getMergeBase(String repoName, String revA, String revB) throws EntityNotFoundException {
    try {
        Repository r = findRepositoryByName(repoName);
        Commit c = GitBrowseUtil.getMergeBase(r, revA, revB);
        r.close();
        return c;
    } catch (IOException ex) {
        throw new EntityNotFoundException(ex.getMessage());
    } catch (URISyntaxException ex) {
        throw new EntityNotFoundException(ex.getMessage());
    }

}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.Observer, Role.User })
@Override//from w  ww .j a v  a  2  s  . c om
public Item getItem(String repoName, String revision, String path) throws EntityNotFoundException {
    try {
        Repository r = findRepositoryByName(repoName);
        Item i = GitBrowseUtil.getItem(r, revision, path);
        r.close();
        return i;
    } catch (AmbiguousObjectException ex) {
        throw new EntityNotFoundException();
    } catch (IOException ex) {
        throw new EntityNotFoundException();
    } catch (URISyntaxException ex) {
        throw new EntityNotFoundException();
    }
}

From source file:com.tasktop.c2c.server.scm.web.GitHandler.java

License:Open Source License

@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final boolean containerSupportsChunkedIO = computeContainerSupportsChunkedIO();

    String pathInfo = request.getPathInfo();
    log.info("Git request: " + request.getMethod() + " " + request.getRequestURI() + " " + pathInfo);

    Repository repository = null;
    try {/*w w  w .ja v  a2 s . c o m*/
        // only work on Git requests
        Matcher matcher = pathInfo == null ? null : GIT_COMMAND_PATTERN.matcher(pathInfo);
        if (matcher == null || !matcher.matches()) {
            log.info("Unexpected path: " + pathInfo);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        String requestCommand = matcher.group(1);
        String requestPath = matcher.group(2);

        // sanity check on path, disallow path separator components
        if (requestPath == null || requestPath.contains("/") || requestPath.contains("..")) {
            badPathResponse();
        }

        repository = repositoryResolver.open(request, requestPath);

        InputStream requestInput = request.getInputStream();
        if (!containerSupportsChunkedIO) {
            requestInput = new ChunkedInputStream(requestInput);
        }

        MultiplexingOutputStream mox = createMultiplexingOutputStream(response, containerSupportsChunkedIO);
        // indicate that we're ok to handle the request
        // note that following this there will be a two-way communication with the process
        // that might still encounter errors. That's ok.
        startOkResponse(response, containerSupportsChunkedIO);

        // identify the git command
        GitCommand command = GitCommand.fromCommandName(requestCommand);
        if (command != null) {
            // permissions check
            if (!Security.hasOneOfRoles(command.getRoles())) {
                log.info("Access denied to " + Security.getCurrentUser() + " for " + command.getCommandName()
                        + " on " + TenancyUtil.getCurrentTenantProjectIdentifer() + " " + requestPath);
                response.sendError(HttpServletResponse.SC_FORBIDDEN);
                return;
            }
            switch (command) {
            case RECEIVE_PACK:
                ReceivePack rp = new ReceivePack(repository);
                rp.setPostReceiveHook(postReceiveHook);
                rp.receive(requestInput, mox.stream(PacketType.STDOUT), mox.stream(PacketType.STDERR));
                break;
            case UPLOAD_PACK:
                UploadPack up = new UploadPack(repository);
                up.upload(requestInput, mox.stream(PacketType.STDOUT), mox.stream(PacketType.STDERR));
                break;
            default:
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
        }

        // at this stage we're done with IO
        // send the exit value and closing chunk
        try {
            int exitValue = 0;

            if (exitValue != 0) {
                log.info("Exit value: " + exitValue);
            }
            mox.writeExitCode(exitValue);
            mox.close();
        } catch (IOException e) {
            // ignore
            log.debug("Cannot complete writing exit state", e);
        }

        // clear interrupt status
        Thread.interrupted();

    } catch (ErrorResponseException e) {
        createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage());
    } catch (ServiceNotAuthorizedException e) {
        createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage());
    } catch (ServiceNotEnabledException e) {
        createGitErrorResponse(response, containerSupportsChunkedIO, e.getMessage());
    } finally {
        log.info("Git request complete");
        if (repository != null) {
            repository.close();
        }
    }
}