mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-03 20:15:52 +01:00
Replace model object exception with generic ones and migrate guice
This commit is contained in:
@@ -38,25 +38,21 @@ package sonia.scm.repository;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.io.FileSystem;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.spi.GitRepositoryServiceProvider;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.schedule.Scheduler;
|
||||
import sonia.scm.schedule.Task;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.schedule.Scheduler;
|
||||
import sonia.scm.schedule.Task;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -185,20 +181,8 @@ public class GitRepositoryHandler
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param directory
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
protected void create(Repository repository, File directory)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
protected void create(Repository repository, File directory) throws IOException {
|
||||
try (org.eclipse.jgit.lib.Repository gitRepository = build(directory)) {
|
||||
gitRepository.create(true);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import org.eclipse.jgit.api.FetchCommand;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
@@ -54,23 +53,19 @@ import org.eclipse.jgit.transport.FetchResult;
|
||||
import org.eclipse.jgit.transport.RefSpec;
|
||||
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||
import org.eclipse.jgit.util.FS;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.GitUserAgentProvider;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import sonia.scm.web.GitUserAgentProvider;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -192,22 +187,7 @@ public final class GitUtil
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param git
|
||||
* @param directory
|
||||
* @param remoteRepository
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public static FetchResult fetch(Git git, File directory,
|
||||
Repository remoteRepository)
|
||||
throws RepositoryException
|
||||
{
|
||||
public static FetchResult fetch(Git git, File directory, Repository remoteRepository) {
|
||||
try
|
||||
{
|
||||
FetchCommand fetch = git.fetch();
|
||||
@@ -220,7 +200,7 @@ public final class GitUtil
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryException("could not fetch", ex);
|
||||
throw new InternalRepositoryException("could not fetch", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +274,7 @@ public final class GitUtil
|
||||
{
|
||||
if (walk != null)
|
||||
{
|
||||
walk.close();;
|
||||
walk.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,28 +36,25 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitChangesetConverter;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -117,21 +114,7 @@ public abstract class AbstractGitIncomingOutgoingCommand
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected ChangesetPagingResult getIncomingOrOutgoingChangesets(
|
||||
PagedRemoteCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
protected ChangesetPagingResult getIncomingOrOutgoingChangesets(PagedRemoteCommandRequest request) throws IOException {
|
||||
Repository remoteRepository = request.getRemoteRepository();
|
||||
|
||||
Git git = Git.wrap(open());
|
||||
@@ -141,8 +124,7 @@ public abstract class AbstractGitIncomingOutgoingCommand
|
||||
ObjectId localId = getDefaultBranch(git.getRepository());
|
||||
ObjectId remoteId = null;
|
||||
|
||||
Ref remoteBranch = getRemoteBranch(git.getRepository(), localId,
|
||||
remoteRepository);
|
||||
Ref remoteBranch = getRemoteBranch(git.getRepository(), localId, remoteRepository);
|
||||
|
||||
if (remoteBranch != null)
|
||||
{
|
||||
@@ -178,7 +160,7 @@ public abstract class AbstractGitIncomingOutgoingCommand
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new RepositoryException("could not execute incoming command", ex);
|
||||
throw new InternalRepositoryException("could not execute incoming command", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -191,23 +173,7 @@ public abstract class AbstractGitIncomingOutgoingCommand
|
||||
return new ChangesetPagingResult(changesets.size(), changesets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param local
|
||||
* @param remoteRepository
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private Ref getRemoteBranch(org.eclipse.jgit.lib.Repository repository,
|
||||
ObjectId local, Repository remoteRepository)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
private Ref getRemoteBranch(org.eclipse.jgit.lib.Repository repository, ObjectId local, Repository remoteRepository) throws IOException {
|
||||
Ref ref = null;
|
||||
|
||||
if (local != null)
|
||||
@@ -236,7 +202,7 @@ public abstract class AbstractGitIncomingOutgoingCommand
|
||||
{
|
||||
if (ref != null)
|
||||
{
|
||||
throw new RepositoryException("could not find remote branch");
|
||||
throw new InternalRepositoryException("could not find remote branch");
|
||||
}
|
||||
|
||||
ref = e.getValue();
|
||||
|
||||
@@ -37,28 +37,23 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.PushResult;
|
||||
import org.eclipse.jgit.transport.RemoteRefUpdate;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -94,20 +89,7 @@ public abstract class AbstractGitPushOrPullCommand extends AbstractGitCommand
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
* @param source
|
||||
* @param remoteUrl
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected long push(Repository source, String remoteUrl)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
protected long push(Repository source, String remoteUrl) {
|
||||
Git git = Git.wrap(source);
|
||||
org.eclipse.jgit.api.PushCommand push = git.push();
|
||||
|
||||
@@ -132,7 +114,7 @@ public abstract class AbstractGitPushOrPullCommand extends AbstractGitCommand
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new RepositoryException("could not execute push/pull command", ex);
|
||||
throw new InternalRepositoryException("could not execute push/pull command", ex);
|
||||
}
|
||||
|
||||
return counter;
|
||||
|
||||
@@ -37,30 +37,26 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.BlameLine;
|
||||
import sonia.scm.repository.BlameResult;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -76,15 +72,6 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
* @param repository
|
||||
* @param repositoryDirectory
|
||||
*/
|
||||
public GitBlameCommand(GitContext context, Repository repository)
|
||||
{
|
||||
super(context, repository);
|
||||
@@ -92,20 +79,9 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public BlameResult getBlameResult(BlameCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
throws IOException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -132,7 +108,7 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
|
||||
|
||||
if (gitBlameResult == null)
|
||||
{
|
||||
throw new RepositoryException(
|
||||
throw new InternalRepositoryException(
|
||||
"could not create blame result for path ".concat(
|
||||
request.getPath()));
|
||||
}
|
||||
@@ -174,7 +150,7 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryException("could not create blame view", ex);
|
||||
throw new InternalRepositoryException("could not create blame view", ex);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -36,22 +36,19 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -74,18 +71,8 @@ public class GitBranchesCommand extends AbstractGitCommand
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public List<Branch> getBranches() throws RepositoryException, IOException
|
||||
{
|
||||
public List<Branch> getBranches() throws IOException {
|
||||
List<Branch> branches = null;
|
||||
|
||||
Git git = new Git(open());
|
||||
@@ -115,7 +102,7 @@ public class GitBranchesCommand extends AbstractGitCommand
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryException("could not read branches", ex);
|
||||
throw new InternalRepositoryException("could not read branches", ex);
|
||||
}
|
||||
|
||||
return branches;
|
||||
|
||||
@@ -37,7 +37,6 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -49,29 +48,25 @@ import org.eclipse.jgit.treewalk.TreeWalk;
|
||||
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
|
||||
import org.eclipse.jgit.treewalk.filter.PathFilter;
|
||||
import org.eclipse.jgit.treewalk.filter.TreeFilter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
import sonia.scm.repository.FileObject;
|
||||
import sonia.scm.repository.GitSubModuleParser;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.PathNotFoundException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
import sonia.scm.repository.SubRepository;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -105,22 +100,10 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public BrowserResult getBrowserResult(BrowseCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
throws IOException, RevisionNotFoundException {
|
||||
logger.debug("try to create browse result for {}", request);
|
||||
|
||||
BrowserResult result;
|
||||
@@ -174,8 +157,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
*/
|
||||
private FileObject createFileObject(org.eclipse.jgit.lib.Repository repo,
|
||||
BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
throws IOException, RevisionNotFoundException {
|
||||
FileObject file;
|
||||
|
||||
try
|
||||
@@ -283,24 +265,9 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repo
|
||||
* @param request
|
||||
* @param revId
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private BrowserResult getResult(org.eclipse.jgit.lib.Repository repo,
|
||||
BrowseCommandRequest request, ObjectId revId)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
throws IOException, RevisionNotFoundException {
|
||||
BrowserResult result = null;
|
||||
RevWalk revWalk = null;
|
||||
TreeWalk treeWalk = null;
|
||||
@@ -393,24 +360,11 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repo
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String,
|
||||
SubRepository> getSubRepositories(org.eclipse.jgit.lib.Repository repo,
|
||||
ObjectId revision)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
throws IOException, RevisionNotFoundException {
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("read submodules of {} at {}", repository.getName(),
|
||||
@@ -435,8 +389,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
|
||||
private SubRepository getSubRepository(org.eclipse.jgit.lib.Repository repo,
|
||||
ObjectId revId, String path)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
throws IOException, RevisionNotFoundException {
|
||||
Map<String, SubRepository> subRepositories = subrepositoryCache.get(revId);
|
||||
|
||||
if (subRepositories == null)
|
||||
|
||||
@@ -46,7 +46,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.PathNotFoundException;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
@@ -66,7 +65,7 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getCatResult(CatCommandRequest request, OutputStream output) throws IOException, RepositoryException {
|
||||
public void getCatResult(CatCommandRequest request, OutputStream output) throws IOException, PathNotFoundException, RevisionNotFoundException {
|
||||
logger.debug("try to read content for {}", request);
|
||||
try (ClosableObjectLoaderContainer closableObjectLoaderContainer = getLoader(request)) {
|
||||
closableObjectLoaderContainer.objectLoader.copyTo(output);
|
||||
@@ -74,24 +73,24 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getCatResultStream(CatCommandRequest request) throws IOException, RepositoryException {
|
||||
public InputStream getCatResultStream(CatCommandRequest request) throws IOException, PathNotFoundException, RevisionNotFoundException {
|
||||
logger.debug("try to read content for {}", request);
|
||||
return new InputStreamWrapper(getLoader(request));
|
||||
}
|
||||
|
||||
void getContent(org.eclipse.jgit.lib.Repository repo, ObjectId revId, String path, OutputStream output) throws IOException, RepositoryException {
|
||||
void getContent(org.eclipse.jgit.lib.Repository repo, ObjectId revId, String path, OutputStream output) throws IOException, PathNotFoundException, RevisionNotFoundException {
|
||||
try (ClosableObjectLoaderContainer closableObjectLoaderContainer = getLoader(repo, revId, path)) {
|
||||
closableObjectLoaderContainer.objectLoader.copyTo(output);
|
||||
}
|
||||
}
|
||||
|
||||
private ClosableObjectLoaderContainer getLoader(CatCommandRequest request) throws IOException, RepositoryException {
|
||||
private ClosableObjectLoaderContainer getLoader(CatCommandRequest request) throws IOException, PathNotFoundException, RevisionNotFoundException {
|
||||
org.eclipse.jgit.lib.Repository repo = open();
|
||||
ObjectId revId = getCommitOrDefault(repo, request.getRevision());
|
||||
return getLoader(repo, revId, request.getPath());
|
||||
}
|
||||
|
||||
private ClosableObjectLoaderContainer getLoader(Repository repo, ObjectId revId, String path) throws IOException, RepositoryException {
|
||||
private ClosableObjectLoaderContainer getLoader(Repository repo, ObjectId revId, String path) throws IOException, PathNotFoundException, RevisionNotFoundException {
|
||||
TreeWalk treeWalk = new TreeWalk(repo);
|
||||
treeWalk.setRecursive(Util.nonNull(path).contains("/"));
|
||||
|
||||
|
||||
@@ -36,16 +36,14 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import org.eclipse.jgit.api.LogCommand;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -70,22 +68,8 @@ public class GitIncomingCommand extends AbstractGitIncomingOutgoingCommand
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public ChangesetPagingResult getIncomingChangesets(
|
||||
IncomingCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
public ChangesetPagingResult getIncomingChangesets(IncomingCommandRequest request) throws IOException {
|
||||
return getIncomingOrOutgoingChangesets(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -45,25 +44,22 @@ import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
|
||||
import org.eclipse.jgit.treewalk.filter.PathFilter;
|
||||
import org.eclipse.jgit.treewalk.filter.TreeFilter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitChangesetConverter;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -165,7 +161,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChangesetPagingResult getChangesets(LogCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
throws IOException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -268,7 +264,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new RepositoryException("could not create change log", ex);
|
||||
throw new InternalRepositoryException("could not create change log", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -36,16 +36,14 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import org.eclipse.jgit.api.LogCommand;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -84,7 +82,7 @@ public class GitOutgoingCommand extends AbstractGitIncomingOutgoingCommand
|
||||
@Override
|
||||
public ChangesetPagingResult getOutgoingChangesets(
|
||||
OutgoingCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
throws IOException
|
||||
{
|
||||
return getIncomingOrOutgoingChangesets(request);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -46,23 +45,20 @@ import org.eclipse.jgit.transport.FetchResult;
|
||||
import org.eclipse.jgit.transport.RefSpec;
|
||||
import org.eclipse.jgit.transport.TagOpt;
|
||||
import org.eclipse.jgit.transport.TrackingRefUpdate;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.api.PullResponse;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -109,7 +105,7 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
*/
|
||||
@Override
|
||||
public PullResponse pull(PullCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
throws IOException
|
||||
{
|
||||
PullResponse response;
|
||||
Repository sourceRepository = request.getRemoteRepository();
|
||||
@@ -130,21 +126,7 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param git
|
||||
* @param result
|
||||
* @param fetch
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private PullResponse convert(Git git, FetchResult fetch)
|
||||
throws RepositoryException
|
||||
{
|
||||
private PullResponse convert(Git git, FetchResult fetch) {
|
||||
long counter = 0l;
|
||||
|
||||
for (TrackingRefUpdate tru : fetch.getTrackingRefUpdates())
|
||||
@@ -212,19 +194,8 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param sourceRepository
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private PullResponse pullFromScmRepository(Repository sourceRepository)
|
||||
throws IOException, RepositoryException
|
||||
throws IOException
|
||||
{
|
||||
File sourceDirectory = handler.getDirectory(sourceRepository);
|
||||
|
||||
@@ -256,19 +227,8 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private PullResponse pullFromUrl(URL url)
|
||||
throws IOException, RepositoryException
|
||||
throws IOException
|
||||
{
|
||||
logger.debug("pull changes from {} to {}", url, repository.getId());
|
||||
|
||||
@@ -289,7 +249,7 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryException("error durring pull", ex);
|
||||
throw new InternalRepositoryException("error durring pull", ex);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
@@ -37,16 +37,14 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.api.PushResponse;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -91,7 +89,7 @@ public class GitPushCommand extends AbstractGitPushOrPullCommand
|
||||
*/
|
||||
@Override
|
||||
public PushResponse push(PushCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
throws IOException
|
||||
{
|
||||
String remoteUrl = getRemoteUrl(request);
|
||||
|
||||
|
||||
@@ -37,27 +37,23 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.Tag;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -79,17 +75,8 @@ public class GitTagsCommand extends AbstractGitCommand implements TagsCommand
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public List<Tag> getTags() throws IOException, RepositoryException
|
||||
public List<Tag> getTags() throws IOException
|
||||
{
|
||||
List<Tag> tags = null;
|
||||
|
||||
@@ -108,7 +95,7 @@ public class GitTagsCommand extends AbstractGitCommand implements TagsCommand
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryException("could not read tags from repository", ex);
|
||||
throw new InternalRepositoryException("could not read tags from repository", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -40,17 +40,14 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Branches;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.api.RepositoryService;
|
||||
import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
import sonia.scm.template.Template;
|
||||
@@ -60,16 +57,14 @@ import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -113,21 +108,9 @@ public class GitRepositoryViewer
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param repository
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
public void handleRequest(HttpServletRequest request,
|
||||
HttpServletResponse response, Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
throws IOException
|
||||
{
|
||||
|
||||
String baseUrl = HttpUtil.getCompleteUrl(request);
|
||||
@@ -171,7 +154,7 @@ public class GitRepositoryViewer
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private BranchesModel createBranchesModel(Repository repository)
|
||||
throws RepositoryException, IOException
|
||||
throws IOException
|
||||
{
|
||||
BranchesModel model = null;
|
||||
RepositoryService service = null;
|
||||
|
||||
@@ -42,7 +42,6 @@ import org.eclipse.jgit.http.server.GitServlet;
|
||||
import org.eclipse.jgit.lfs.lib.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.repository.RepositoryRequestListenerUtil;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
@@ -214,7 +213,7 @@ public class ScmGitServlet extends GitServlet
|
||||
private void handleBrowserRequest(HttpServletRequest request, HttpServletResponse response, Repository repository) throws ServletException, IOException {
|
||||
try {
|
||||
repositoryViewer.handleRequest(request, response, repository);
|
||||
} catch (RepositoryException | IOException ex) {
|
||||
} catch (IOException ex) {
|
||||
throw new ServletException("could not create repository view", ex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user