import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.StringUtils;\r
String fullUrl = getFullUrl(httpRequest);\r
String repository = extractRepositoryName(fullUrl);\r
\r
- if (GitBlit.self().isCollectingGarbage(repository)) {\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
+ if (repositoryManager.isCollectingGarbage(repository)) {\r
logger.info(MessageFormat.format("ARF: Rejecting request for {0}, busy collecting garbage!", repository));\r
httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);\r
return;\r
UserModel user = getUser(httpRequest);\r
\r
// Load the repository model\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(repository);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(repository);\r
if (model == null) {\r
if (isCreationAllowed()) {\r
if (user == null) {\r
// challenge client to provide credentials for creation. send 401.\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("ARF: CREATE CHALLENGE {0}", fullUrl));\r
}\r
httpResponse.setHeader("WWW-Authenticate", CHALLENGE);\r
if (!StringUtils.isEmpty(urlRequestType) && requiresAuthentication(model, urlRequestType)) {\r
if (user == null) {\r
// challenge client to provide credentials. send 401.\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("ARF: CHALLENGE {0}", fullUrl));\r
}\r
httpResponse.setHeader("WWW-Authenticate", CHALLENGE);\r
return;\r
}\r
// valid user, but not for requested access. send 403.\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("ARF: {0} forbidden to access {1}",\r
user.username, fullUrl));\r
}\r
}\r
}\r
\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("ARF: {0} ({1}) unauthenticated", fullUrl,\r
HttpServletResponse.SC_CONTINUE));\r
}\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import com.gitblit.manager.ISessionManager;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.DeepCopier;\r
import com.gitblit.utils.StringUtils;\r
* @return user\r
*/\r
protected UserModel getUser(HttpServletRequest httpRequest) {\r
- UserModel user = GitBlit.self().authenticate(httpRequest, requiresClientCertificate());\r
+ ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);\r
+ UserModel user = sessionManager.authenticate(httpRequest, requiresClientCertificate());\r
return user;\r
}\r
\r
import org.eclipse.jgit.revplot.PlotWalk;\r
import org.eclipse.jgit.revwalk.RevCommit;\r
\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.StringUtils;\r
\r
protected long getLastModified(HttpServletRequest req) {\r
String repository = req.getParameter("r");\r
String objectId = req.getParameter("h");\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
Repository r = null;\r
try {\r
- r = GitBlit.self().getRepository(repository);\r
+ r = repositoryManager.getRepository(repository);\r
if (StringUtils.isEmpty(objectId)) {\r
objectId = JGitUtils.getHEADRef(r);\r
}\r
String objectId = request.getParameter("h");\r
String length = request.getParameter("l");\r
\r
- r = GitBlit.self().getRepository(repository);\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
+ r = repositoryManager.getRepository(repository);\r
\r
rw = new PlotWalk(r);\r
if (StringUtils.isEmpty(objectId)) {\r
rw.markStart(rw.lookupCommit(r.resolve(objectId)));\r
\r
// default to the items-per-page setting, unless specified\r
- int maxCommits = GitBlit.getInteger(Keys.web.itemsPerPage, 50);\r
+ int maxCommits = settings.getInteger(Keys.web.itemsPerPage, 50);\r
int requestedCommits = maxCommits;\r
if (!StringUtils.isEmpty(length)) {\r
int l = Integer.parseInt(length);\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.utils.CompressionUtils;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.MarkdownUtils;\r
private void processRequest(javax.servlet.http.HttpServletRequest request,\r
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
java.io.IOException {\r
- if (!GitBlit.getBoolean(Keys.web.allowZipDownloads, true)) {\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ if (!settings.getBoolean(Keys.web.allowZipDownloads, true)) {\r
logger.warn("Zip downloads are disabled");\r
response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
return;\r
name += "-" + objectId;\r
}\r
\r
- Repository r = GitBlit.self().getRepository(repository);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ Repository r = repositoryManager.getRepository(repository);\r
if (r == null) {\r
- if (GitBlit.self().isCollectingGarbage(repository)) {\r
+ if (repositoryManager.isCollectingGarbage(repository)) {\r
error(response, MessageFormat.format("# Error\nGitblit is busy collecting garbage in {0}", repository));\r
return;\r
} else {\r
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
import com.gitblit.models.UserModel;
/**
*/
@Override
public void init(FilterConfig filterConfig) throws ServletException {
- // nothing to be done
-
- } //init
+ }
/*
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
- /*
- * Determine whether to enforce the BASIC authentication:
- */
- @SuppressWarnings("static-access")
- Boolean mustForceAuth = GitBlit.self().getBoolean(Keys.web.authenticateViewPages, false)
- && GitBlit.self().getBoolean(Keys.web.enforceHttpBasicAuthentication, false);
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
+ ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
+ Boolean mustForceAuth = settings.getBoolean(Keys.web.authenticateViewPages, false)
+ && settings.getBoolean(Keys.web.enforceHttpBasicAuthentication, false);
- HttpServletRequest HttpRequest = (HttpServletRequest)request;
- HttpServletResponse HttpResponse = (HttpServletResponse)response;
- UserModel user = GitBlit.self().authenticate(HttpRequest);
+ HttpServletRequest httpRequest = (HttpServletRequest) request;
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
+ UserModel user = sessionManager.authenticate(httpRequest);
if (mustForceAuth && (user == null)) {
// not authenticated, enforce now:
logger.debug(MessageFormat.format("EnforceAuthFilter: user not authenticated for URL {0}!", request.toString()));
- @SuppressWarnings("static-access")
- String CHALLENGE = MessageFormat.format("Basic realm=\"{0}\"", GitBlit.self().getString("web.siteName",""));
- HttpResponse.setHeader("WWW-Authenticate", CHALLENGE);
- HttpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+ String challenge = MessageFormat.format("Basic realm=\"{0}\"", settings.getString(Keys.web.siteName, ""));
+ httpResponse.setHeader("WWW-Authenticate", challenge);
+ httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
} else {
// user is authenticated, or don't care, continue handling
- chain.doFilter( request, response );
-
- } // authenticated
- } // doFilter
+ chain.doFilter(request, response);
+ }
+ }
/*
*/
@Override
public void destroy() {
- // Nothing to be done
-
- } // destroy
-
+ }
}
}\r
\r
// configure the Gitblit singleton for minimal, non-server operation\r
- GitBlit.self().configureContext(settings, baseFolder, false);\r
+ GitBlit gitblit = new GitBlit(settings, baseFolder);\r
+ gitblit.configureContext(settings, baseFolder, false);\r
FederationPullExecutor executor = new FederationPullExecutor(registrations, params.isDaemon);\r
executor.run();\r
if (!params.isDaemon) {\r
import com.gitblit.Constants.FederationPullStatus;\r
import com.gitblit.Constants.FederationStrategy;\r
import com.gitblit.GitBlitException.ForbiddenException;\r
+import com.gitblit.manager.IGitblitManager;\r
+import com.gitblit.manager.INotificationManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.IUserManager;\r
import com.gitblit.models.FederationModel;\r
import com.gitblit.models.RefModel;\r
import com.gitblit.models.RepositoryModel;\r
if (registration.notifyOnError) {\r
String message = "Federation pull of " + registration.name + " @ "\r
+ registration.url + " is now at " + is.name();\r
- GitBlit.self()\r
+ INotificationManager mailManager = GitBlit.getManager(INotificationManager.class);\r
+ mailManager\r
.sendMailToAdministrators(\r
"Pull Status of " + registration.name + " is " + is.name(),\r
message);\r
c, registrationFolder, registration.name));\r
return;\r
}\r
- File repositoriesFolder = GitBlit.getRepositoriesFolder();\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ File repositoriesFolder = repositoryManager.getRepositoriesFolder();\r
File registrationFolderFile = new File(repositoriesFolder, registrationFolder);\r
registrationFolderFile.mkdirs();\r
\r
// confirm that the origin of any pre-existing repository matches\r
// the clone url\r
String fetchHead = null;\r
- Repository existingRepository = GitBlit.self().getRepository(repositoryName);\r
+ Repository existingRepository = repositoryManager.getRepository(repositoryName);\r
\r
- if (existingRepository == null && GitBlit.self().isCollectingGarbage(repositoryName)) {\r
+ if (existingRepository == null && repositoryManager.isCollectingGarbage(repositoryName)) {\r
logger.warn(MessageFormat.format("Skipping local repository {0}, busy collecting garbage", repositoryName));\r
continue;\r
}\r
\r
CloneResult result = JGitUtils.cloneRepository(registrationFolderFile, repository.name,\r
cloneUrl, registration.bare, credentials);\r
- Repository r = GitBlit.self().getRepository(repositoryName);\r
- RepositoryModel rm = GitBlit.self().getRepositoryModel(repositoryName);\r
+ Repository r = repositoryManager.getRepository(repositoryName);\r
+ RepositoryModel rm = repositoryManager.getRepositoryModel(repositoryName);\r
repository.isFrozen = registration.mirror;\r
if (result.createdRepository) {\r
// default local settings\r
// "federated" repositories.\r
repository.isFederated = cloneUrl.startsWith(registration.url);\r
\r
- GitBlit.self().updateConfiguration(r, repository);\r
+ repositoryManager.updateConfiguration(r, repository);\r
r.close();\r
}\r
\r
+ IUserManager userManager = GitBlit.getManager(IUserManager.class);\r
+ IGitblitManager gitblitManager = GitBlit.getManager(IGitblitManager.class);\r
IUserService userService = null;\r
\r
try {\r
}\r
\r
// insert new user or update local user\r
- UserModel localUser = GitBlit.self().getUserModel(user.username);\r
+ UserModel localUser = userManager.getUserModel(user.username);\r
if (localUser == null) {\r
// create new local user\r
- GitBlit.self().updateUserModel(user.username, user, true);\r
+ gitblitManager.updateUserModel(user.username, user, true);\r
} else {\r
// update repository permissions of local user\r
if (user.permissions != null) {\r
}\r
localUser.password = user.password;\r
localUser.canAdmin = user.canAdmin;\r
- GitBlit.self().updateUserModel(localUser.username, localUser, false);\r
+ gitblitManager.updateUserModel(localUser.username, localUser, false);\r
}\r
\r
- for (String teamname : GitBlit.self().getAllTeamnames()) {\r
- TeamModel team = GitBlit.self().getTeamModel(teamname);\r
+ for (String teamname : userManager.getAllTeamNames()) {\r
+ TeamModel team = userManager.getTeamModel(teamname);\r
if (user.isTeamMember(teamname) && !team.hasUser(user.username)) {\r
// new team member\r
team.addUser(user.username);\r
- GitBlit.self().updateTeamModel(teamname, team, false);\r
+ userManager.updateTeamModel(teamname, team);\r
} else if (!user.isTeamMember(teamname) && team.hasUser(user.username)) {\r
// remove team member\r
team.removeUser(user.username);\r
- GitBlit.self().updateTeamModel(teamname, team, false);\r
+ userManager.updateTeamModel(teamname, team);\r
}\r
\r
// update team repositories\r
for (Map.Entry<String, AccessPermission> entry : remoteTeam.permissions.entrySet()){\r
team.setRepositoryPermission(entry.getKey(), entry.getValue());\r
}\r
- GitBlit.self().updateTeamModel(teamname, team, false);\r
+ userManager.updateTeamModel(teamname, team);\r
} else if(!ArrayUtils.isEmpty(remoteTeam.repositories)) {\r
// pulling from <= 1.1\r
team.addRepositoryPermissions(remoteTeam.repositories);\r
- GitBlit.self().updateTeamModel(teamname, team, false);\r
+ userManager.updateTeamModel(teamname, team);\r
}\r
}\r
}\r
return;\r
}\r
InetAddress addr = InetAddress.getLocalHost();\r
- String federationName = GitBlit.getString(Keys.federation.name, null);\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ String federationName = settings.getString(Keys.federation.name, null);\r
if (StringUtils.isEmpty(federationName)) {\r
federationName = addr.getHostName();\r
}\r
import javax.servlet.http.HttpServletResponse;\r
\r
import com.gitblit.Constants.FederationRequest;\r
+import com.gitblit.manager.IFederationManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.IUserManager;\r
import com.gitblit.models.FederationModel;\r
import com.gitblit.models.FederationProposal;\r
import com.gitblit.models.TeamModel;\r
protected void processRequest(javax.servlet.http.HttpServletRequest request,\r
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
java.io.IOException {\r
+\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ IUserManager userManager = GitBlit.getManager(IUserManager.class);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ IFederationManager federationManager = GitBlit.getManager(IFederationManager.class);\r
+\r
FederationRequest reqType = FederationRequest.fromName(request.getParameter("req"));\r
logger.info(MessageFormat.format("Federation {0} request from {1}", reqType,\r
request.getRemoteAddr()));\r
return;\r
}\r
\r
- if (!GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {\r
+ if (!settings.getBoolean(Keys.git.enableGitServlet, true)) {\r
logger.warn(Keys.git.enableGitServlet + " must be set TRUE for federation requests.");\r
response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
return;\r
}\r
\r
- String uuid = GitBlit.getString(Keys.federation.passphrase, "");\r
+ String uuid = settings.getString(Keys.federation.passphrase, "");\r
if (StringUtils.isEmpty(uuid)) {\r
logger.warn(Keys.federation.passphrase\r
+ " is not properly set! Federation request denied.");\r
}\r
\r
// reject proposal, if not receipt prohibited\r
- if (!GitBlit.getBoolean(Keys.federation.allowProposals, false)) {\r
+ if (!settings.getBoolean(Keys.federation.allowProposals, false)) {\r
logger.error(MessageFormat.format("Rejected {0} federation proposal from {1}",\r
proposal.tokenType.name(), proposal.url));\r
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);\r
}\r
\r
String url = HttpUtils.getGitblitURL(request);\r
- GitBlit.self().submitFederationProposal(proposal, url);\r
+ federationManager.submitFederationProposal(proposal, url);\r
logger.info(MessageFormat.format(\r
"Submitted {0} federation proposal to pull {1} repositories from {2}",\r
proposal.tokenType.name(), proposal.repositories.size(), proposal.url));\r
results.nextPull = new Date(System.currentTimeMillis() + (mins * 60 * 1000L));\r
\r
// acknowledge the receipt of status\r
- GitBlit.self().acknowledgeFederationStatus(identification, results);\r
+ federationManager.acknowledgeFederationStatus(identification, results);\r
logger.info(MessageFormat.format(\r
"Received status of {0} federated repositories from {1}", results\r
.getStatusList().size(), identification));\r
\r
// Determine the federation tokens for this gitblit instance\r
String token = request.getParameter("token");\r
- List<String> tokens = GitBlit.self().getFederationTokens();\r
+ List<String> tokens = federationManager.getFederationTokens();\r
if (!tokens.contains(token)) {\r
logger.warn(MessageFormat.format(\r
"Received Federation token ''{0}'' does not match the server tokens", token));\r
Object result = null;\r
if (FederationRequest.PULL_REPOSITORIES.equals(reqType)) {\r
String gitblitUrl = HttpUtils.getGitblitURL(request);\r
- result = GitBlit.self().getRepositories(gitblitUrl, token);\r
+ result = federationManager.getRepositories(gitblitUrl, token);\r
} else {\r
if (FederationRequest.PULL_SETTINGS.equals(reqType)) {\r
// pull settings\r
- if (!GitBlit.self().validateFederationRequest(reqType, token)) {\r
+ if (!federationManager.validateFederationRequest(reqType, token)) {\r
// invalid token to pull users or settings\r
logger.warn(MessageFormat.format(\r
"Federation token from {0} not authorized to pull SETTINGS",\r
response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
return;\r
}\r
- Map<String, String> settings = new HashMap<String, String>();\r
- List<String> keys = GitBlit.getAllKeys(null);\r
+ Map<String, String> map = new HashMap<String, String>();\r
+ List<String> keys = settings.getAllKeys(null);\r
for (String key : keys) {\r
- settings.put(key, GitBlit.getString(key, ""));\r
+ map.put(key, settings.getString(key, ""));\r
}\r
- result = settings;\r
+ result = map;\r
} else if (FederationRequest.PULL_USERS.equals(reqType)) {\r
// pull users\r
- if (!GitBlit.self().validateFederationRequest(reqType, token)) {\r
+ if (!federationManager.validateFederationRequest(reqType, token)) {\r
// invalid token to pull users or settings\r
logger.warn(MessageFormat.format(\r
"Federation token from {0} not authorized to pull USERS",\r
response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
return;\r
}\r
- List<String> usernames = GitBlit.self().getAllUsernames();\r
+ List<String> usernames = userManager.getAllUsernames();\r
List<UserModel> users = new ArrayList<UserModel>();\r
for (String username : usernames) {\r
- UserModel user = GitBlit.self().getUserModel(username);\r
+ UserModel user = userManager.getUserModel(username);\r
if (!user.excludeFromFederation) {\r
users.add(user);\r
}\r
result = users;\r
} else if (FederationRequest.PULL_TEAMS.equals(reqType)) {\r
// pull teams\r
- if (!GitBlit.self().validateFederationRequest(reqType, token)) {\r
+ if (!federationManager.validateFederationRequest(reqType, token)) {\r
// invalid token to pull teams\r
logger.warn(MessageFormat.format(\r
"Federation token from {0} not authorized to pull TEAMS",\r
response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
return;\r
}\r
- List<String> teamnames = GitBlit.self().getAllTeamnames();\r
+ List<String> teamnames = userManager.getAllTeamNames();\r
List<TeamModel> teams = new ArrayList<TeamModel>();\r
for (String teamname : teamnames) {\r
- TeamModel user = GitBlit.self().getTeamModel(teamname);\r
+ TeamModel user = userManager.getTeamModel(teamname);\r
teams.add(user);\r
}\r
result = teams;\r
} else if (FederationRequest.PULL_SCRIPTS.equals(reqType)) {\r
// pull scripts\r
- if (!GitBlit.self().validateFederationRequest(reqType, token)) {\r
+ if (!federationManager.validateFederationRequest(reqType, token)) {\r
// invalid token to pull script\r
logger.warn(MessageFormat.format(\r
"Federation token from {0} not authorized to pull SCRIPTS",\r
Map<String, String> scripts = new HashMap<String, String>();\r
\r
Set<String> names = new HashSet<String>();\r
- names.addAll(GitBlit.getStrings(Keys.groovy.preReceiveScripts));\r
- names.addAll(GitBlit.getStrings(Keys.groovy.postReceiveScripts));\r
- for (TeamModel team : GitBlit.self().getAllTeams()) {\r
+ names.addAll(settings.getStrings(Keys.groovy.preReceiveScripts));\r
+ names.addAll(settings.getStrings(Keys.groovy.postReceiveScripts));\r
+ for (TeamModel team : userManager.getAllTeams()) {\r
names.addAll(team.preReceiveScripts);\r
names.addAll(team.postReceiveScripts);\r
}\r
- File scriptsFolder = GitBlit.getFileOrFolder(Keys.groovy.scriptsFolder, "groovy");\r
+ File scriptsFolder = repositoryManager.getHooksFolder();\r
for (String name : names) {\r
File file = new File(scriptsFolder, name);\r
if (!file.exists() && !file.getName().endsWith(".groovy")) {\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import com.gitblit.manager.IRepositoryManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.utils.FileUtils;\r
\r
running.set(true);\r
Date now = new Date();\r
\r
- for (String repositoryName : GitBlit.self().getRepositoryList()) {\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
+ for (String repositoryName : repositoryManager.getRepositoryList()) {\r
if (forceClose.get()) {\r
break;\r
}\r
RepositoryModel model = null;\r
Repository repository = null;\r
try {\r
- model = GitBlit.self().getRepositoryModel(repositoryName);\r
- repository = GitBlit.self().getRepository(repositoryName);\r
+ model = repositoryManager.getRepositoryModel(repositoryName);\r
+ repository = repositoryManager.getRepository(repositoryName);\r
if (repository == null) {\r
logger.warn(MessageFormat.format("GCExecutor is missing repository {0}?!?", repositoryName));\r
continue;\r
if (garbageCollected) {\r
// update the last GC date\r
model.lastGC = new Date();\r
- GitBlit.self().updateConfiguration(repository, model);\r
+ repositoryManager.updateConfiguration(repository, model);\r
}\r
\r
repository.close();\r
import javax.servlet.ServletContextListener;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.wicket.RequestCycle;
-import org.apache.wicket.protocol.http.WebResponse;
import org.apache.wicket.resource.ContextRelativeResource;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
import org.eclipse.jgit.lib.Repository;
import com.gitblit.fanout.FanoutService;
import com.gitblit.fanout.FanoutSocketService;
import com.gitblit.git.GitDaemon;
+import com.gitblit.manager.IFederationManager;
+import com.gitblit.manager.IGitblitManager;
+import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IProjectManager;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
+import com.gitblit.manager.IUserManager;
import com.gitblit.models.FederationModel;
import com.gitblit.models.FederationProposal;
import com.gitblit.models.FederationSet;
* @author James Moger
*
*/
-public class GitBlit implements ServletContextListener {
+public class GitBlit implements ServletContextListener,
+ IRuntimeManager,
+ INotificationManager,
+ IUserManager,
+ ISessionManager,
+ IRepositoryManager,
+ IProjectManager,
+ IFederationManager,
+ IGitblitManager {
private static GitBlit gitblit;
+ private final IStoredSettings goSettings;
+
private final Logger logger = LoggerFactory.getLogger(GitBlit.class);
private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(10);
private GitDaemon gitDaemon;
public GitBlit() {
- if (gitblit == null) {
- // set the static singleton reference
- gitblit = this;
- }
+ this.goSettings = null;
}
- public GitBlit(final IUserService userService) {
+ protected GitBlit(final IUserService userService) {
+ this.goSettings = null;
this.userService = userService;
gitblit = this;
}
+ public GitBlit(IStoredSettings settings, File baseFolder) {
+ this.goSettings = settings;
+ this.baseFolder = baseFolder;
+ gitblit = this;
+ }
+
/**
* Returns the Gitblit singleton.
*
* @return gitblit singleton
*/
public static GitBlit self() {
- if (gitblit == null) {
- new GitBlit();
- }
return gitblit;
}
+ @SuppressWarnings("unchecked")
+ public static <X> X getManager(Class<X> managerClass) {
+ if (managerClass.isAssignableFrom(GitBlit.class)) {
+ return (X) gitblit;
+ }
+ return null;
+ }
+
+ @Override
+ public File getBaseFolder() {
+ return baseFolder;
+ }
+
+ @Override
+ public void setBaseFolder(File folder) {
+ this.baseFolder = folder;
+ }
+
/**
* Returns the boot date of the Gitblit server.
*
* @return the boot date of Gitblit
*/
- public static Date getBootDate() {
- return self().serverStatus.bootDate;
+ @Override
+ public Date getBootDate() {
+ return serverStatus.bootDate;
}
/**
*
* @return a date
*/
- public static Date getLastActivityDate() {
+ @Override
+ public Date getLastActivityDate() {
Date date = null;
- for (String name : self().getRepositoryList()) {
- Repository r = self().getRepository(name);
+ for (String name : getRepositoryList()) {
+ Repository r = getRepository(name);
Date lastChange = JGitUtils.getLastChange(r).when;
r.close();
if (lastChange != null && (date == null || lastChange.after(date))) {
return date;
}
- /**
- * Determine if this is the GO variant of Gitblit.
- *
- * @return true if this is the GO variant of Gitblit.
- */
- public static boolean isGO() {
- return self().settings instanceof FileSettings;
- }
-
- /**
- * Determine if this Gitblit instance is actively serving git repositories
- * or if it is merely a repository viewer.
- *
- * @return true if Gitblit is serving repositories
- */
- public static boolean isServingRepositories() {
- return getBoolean(Keys.git.enableGitServlet, true) || (getInteger(Keys.git.daemonPort, 0) > 0);
- }
-
/**
* Determine if this Gitblit instance is actively serving git repositories
* or if it is merely a repository viewer.
*
* @return true if Gitblit is serving repositories
*/
- public static boolean isSendingMail() {
- return self().mailExecutor.isReady();
+ @Override
+ public boolean isServingRepositories() {
+ return settings.getBoolean(Keys.git.enableGitServlet, true) || (settings.getInteger(Keys.git.daemonPort, 0) > 0);
}
/**
*
* @return a timezone
*/
- public static TimeZone getTimezone() {
- if (self().timezone == null) {
- String tzid = getString("web.timezone", null);
+ @Override
+ public TimeZone getTimezone() {
+ if (timezone == null) {
+ String tzid = settings.getString("web.timezone", null);
if (StringUtils.isEmpty(tzid)) {
- self().timezone = TimeZone.getDefault();
- return self().timezone;
+ timezone = TimeZone.getDefault();
+ return timezone;
}
- self().timezone = TimeZone.getTimeZone(tzid);
+ timezone = TimeZone.getTimeZone(tzid);
}
- return self().timezone;
- }
-
- /**
- * Returns the active settings.
- *
- * @return the active settings
- */
- public static IStoredSettings getSettings() {
- return self().settings;
- }
-
- /**
- * Returns the user-defined blob encodings.
- *
- * @return an array of encodings, may be empty
- */
- public static String [] getEncodings() {
- return getStrings(Keys.web.blobEncodings).toArray(new String[0]);
- }
-
-
- /**
- * Returns the boolean value for the specified key. If the key does not
- * exist or the value for the key can not be interpreted as a boolean, the
- * defaultValue is returned.
- *
- * @see IStoredSettings.getBoolean(String, boolean)
- * @param key
- * @param defaultValue
- * @return key value or defaultValue
- */
- public static boolean getBoolean(String key, boolean defaultValue) {
- return self().settings.getBoolean(key, defaultValue);
- }
-
- /**
- * Returns the integer value for the specified key. If the key does not
- * exist or the value for the key can not be interpreted as an integer, the
- * defaultValue is returned.
- *
- * @see IStoredSettings.getInteger(String key, int defaultValue)
- * @param key
- * @param defaultValue
- * @return key value or defaultValue
- */
- public static int getInteger(String key, int defaultValue) {
- return self().settings.getInteger(key, defaultValue);
- }
-
- /**
- * Returns the integer list for the specified key. If the key does not
- * exist or the value for the key can not be interpreted as an integer, an
- * empty list is returned.
- *
- * @see IStoredSettings.getIntegers(String key)
- * @param key
- * @return key value or defaultValue
- */
- public static List<Integer> getIntegers(String key) {
- return self().settings.getIntegers(key);
- }
-
- /**
- * Returns the value in bytes for the specified key. If the key does not
- * exist or the value for the key can not be interpreted as an integer, the
- * defaultValue is returned.
- *
- * @see IStoredSettings.getFilesize(String key, int defaultValue)
- * @param key
- * @param defaultValue
- * @return key value or defaultValue
- */
- public static int getFilesize(String key, int defaultValue) {
- return self().settings.getFilesize(key, defaultValue);
- }
-
- /**
- * Returns the value in bytes for the specified key. If the key does not
- * exist or the value for the key can not be interpreted as a long, the
- * defaultValue is returned.
- *
- * @see IStoredSettings.getFilesize(String key, long defaultValue)
- * @param key
- * @param defaultValue
- * @return key value or defaultValue
- */
- public static long getFilesize(String key, long defaultValue) {
- return self().settings.getFilesize(key, defaultValue);
- }
-
- /**
- * Returns the char value for the specified key. If the key does not exist
- * or the value for the key can not be interpreted as a character, the
- * defaultValue is returned.
- *
- * @see IStoredSettings.getChar(String key, char defaultValue)
- * @param key
- * @param defaultValue
- * @return key value or defaultValue
- */
- public static char getChar(String key, char defaultValue) {
- return self().settings.getChar(key, defaultValue);
- }
-
- /**
- * Returns the string value for the specified key. If the key does not exist
- * or the value for the key can not be interpreted as a string, the
- * defaultValue is returned.
- *
- * @see IStoredSettings.getString(String key, String defaultValue)
- * @param key
- * @param defaultValue
- * @return key value or defaultValue
- */
- public static String getString(String key, String defaultValue) {
- return self().settings.getString(key, defaultValue);
- }
-
- /**
- * Returns a list of space-separated strings from the specified key.
- *
- * @see IStoredSettings.getStrings(String key)
- * @param n
- * @return list of strings
- */
- public static List<String> getStrings(String key) {
- return self().settings.getStrings(key);
- }
-
- /**
- * Returns a map of space-separated key-value pairs from the specified key.
- *
- * @see IStoredSettings.getStrings(String key)
- * @param n
- * @return map of string, string
- */
- public static Map<String, String> getMap(String key) {
- return self().settings.getMap(key);
- }
-
- /**
- * Returns the list of keys whose name starts with the specified prefix. If
- * the prefix is null or empty, all key names are returned.
- *
- * @see IStoredSettings.getAllKeys(String key)
- * @param startingWith
- * @return list of keys
- */
-
- public static List<String> getAllKeys(String startingWith) {
- return self().settings.getAllKeys(startingWith);
+ return timezone;
}
/**
*
* @return true if Gitblit is running in debug mode
*/
- public static boolean isDebugMode() {
- return self().settings.getBoolean(Keys.web.debugMode, false);
+ @Override
+ public boolean isDebugMode() {
+ return settings.getBoolean(Keys.web.debugMode, false);
}
/**
*
* @return the file
*/
- public static File getFileOrFolder(String key, String defaultFileOrFolder) {
- String fileOrFolder = GitBlit.getString(key, defaultFileOrFolder);
+ @Override
+ public File getFileOrFolder(String key, String defaultFileOrFolder) {
+ String fileOrFolder = settings.getString(key, defaultFileOrFolder);
return getFileOrFolder(fileOrFolder);
}
*
* @return the file
*/
- public static File getFileOrFolder(String fileOrFolder) {
+ @Override
+ public File getFileOrFolder(String fileOrFolder) {
return com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$,
- self().baseFolder, fileOrFolder);
+ baseFolder, fileOrFolder);
}
/**
*
* @return the repositories folder path
*/
- public static File getRepositoriesFolder() {
+ @Override
+ public File getRepositoriesFolder() {
return getFileOrFolder(Keys.git.repositoriesFolder, "${baseFolder}/git");
}
*
* @return the proposals folder path
*/
- public static File getProposalsFolder() {
+ @Override
+ public File getProposalsFolder() {
return getFileOrFolder(Keys.federation.proposalsFolder, "${baseFolder}/proposals");
}
*
* @return the Groovy scripts folder path
*/
- public static File getGroovyScriptsFolder() {
+ @Override
+ public File getHooksFolder() {
return getFileOrFolder(Keys.groovy.scriptsFolder, "${baseFolder}/groovy");
}
/**
- * Updates the list of server settings.
+ * Returns the path of the Groovy Grape folder. This method checks to see if
+ * Gitblit is running on a cloud service and may return an adjusted path.
+ *
+ * @return the Groovy Grape folder path
+ */
+ @Override
+ public File getGrapesFolder() {
+ return getFileOrFolder(Keys.groovy.grapeFolder, "${baseFolder}/groovy/grape");
+ }
+
+ /**
+ * Returns the runtime settings.
+ *
+ * @return runtime settings
+ */
+ @Override
+ public IStoredSettings getSettings() {
+ return settings;
+ }
+
+ /**
+ * Updates the runtime settings.
*
* @param settings
* @return true if the update succeeded
*/
+ @Override
public boolean updateSettings(Map<String, String> updatedSettings) {
return settings.saveSettings(updatedSettings);
}
+ @Override
public ServerStatus getStatus() {
// update heap memory status
serverStatus.heapAllocated = Runtime.getRuntime().totalMemory();
* @param repository
* @return a list of repository urls
*/
+ @Override
public List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository) {
if (user == null) {
user = UserModel.ANONYMOUS;
*
* @return a collection of client applications
*/
+ @Override
public Collection<GitClientApplication> getClientApplications() {
// prefer user definitions, if they exist
File userDefs = new File(baseFolder, "clientapps.json");
this.userService.setup(settings);
}
+ @Override
public boolean supportsAddUser() {
return supportsCredentialChanges(new UserModel(""));
}
* @param user
* @return true if the user service supports credential changes
*/
+ @Override
public boolean supportsCredentialChanges(UserModel user) {
if (user == null) {
return false;
* @param user
* @return true if the user service supports display name changes
*/
+ @Override
public boolean supportsDisplayNameChanges(UserModel user) {
return (user != null && user.isLocalAccount()) || userService.supportsDisplayNameChanges();
}
* @param user
* @return true if the user service supports email address changes
*/
+ @Override
public boolean supportsEmailAddressChanges(UserModel user) {
return (user != null && user.isLocalAccount()) || userService.supportsEmailAddressChanges();
}
* @param user
* @return true if the user service supports team membership changes
*/
+ @Override
public boolean supportsTeamMembershipChanges(UserModel user) {
return (user != null && user.isLocalAccount()) || userService.supportsTeamMembershipChanges();
}
* @param password
* @return a user object or null
*/
+ @Override
public UserModel authenticate(String username, char[] password) {
if (StringUtils.isEmpty(username)) {
// can not authenticate empty username
* @param httpRequest
* @return a user object or null
*/
+ @Override
public UserModel authenticate(HttpServletRequest httpRequest) {
return authenticate(httpRequest, false);
}
* @param requiresCertificate
* @return a user object or null
*/
+ @Override
public UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate) {
// try to authenticate by certificate
boolean checkValidity = settings.getBoolean(Keys.git.enforceCertificateValidity, true);
- String [] oids = getStrings(Keys.git.certificateUsernameOIDs).toArray(new String[0]);
+ String [] oids = settings.getStrings(Keys.git.certificateUsernameOIDs).toArray(new String[0]);
UserModel model = HttpUtils.getUserModelFromCertificate(httpRequest, checkValidity, oids);
if (model != null) {
// grab real user model and preserve certificate serial number
}
// try to authenticate by cookie
- if (allowCookieAuthentication()) {
+ if (supportsCookies()) {
UserModel user = authenticate(httpRequest.getCookies());
if (user != null) {
flagWicketSession(AuthenticationType.COOKIE);
* @param response
* @param user
*/
- public void setCookie(WebResponse response, UserModel user) {
+ @Override
+ public void setCookie(HttpServletResponse response, UserModel user) {
if (userService == null) {
return;
}
*
* @param user
*/
+ @Override
public void logout(UserModel user) {
if (userService == null) {
return;
* @see IUserService.getAllUsernames()
* @return list of all usernames
*/
+ @Override
public List<String> getAllUsernames() {
List<String> names = new ArrayList<String>(userService.getAllUsernames());
return names;
* @see IUserService.getAllUsernames()
* @return list of all usernames
*/
+ @Override
public List<UserModel> getAllUsers() {
List<UserModel> users = userService.getAllUsers();
return users;
* @param username
* @return true if successful
*/
+ @Override
public boolean deleteUser(String username) {
if (StringUtils.isEmpty(username)) {
return false;
return userService.deleteUser(usernameDecoded);
}
- protected UserModel getFederationUser() {
+ @Override
+ public UserModel getFederationUser() {
// the federation user is an administrator
UserModel federationUser = new UserModel(Constants.FEDERATION_USER);
federationUser.canAdmin = true;
* @param username
* @return a user object or null
*/
+ @Override
public UserModel getUserModel(String username) {
if (StringUtils.isEmpty(username)) {
return null;
* @param user
* @return the effective list of permissions for the user
*/
+ @Override
public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) {
if (StringUtils.isEmpty(user.username)) {
// new user
// Flag missing repositories
for (RegistrantAccessPermission permission : set) {
if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
- RepositoryModel rm = GitBlit.self().getRepositoryModel(permission.registrant);
+ RepositoryModel rm = getRepositoryModel(permission.registrant);
if (rm == null) {
permission.permissionType = PermissionType.MISSING;
permission.mutable = false;
* @param repository
* @return a list of RegistrantAccessPermissions
*/
+ @Override
public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) {
List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
if (AccessRestrictionType.NONE.equals(repository.accessRestriction)) {
* @param permissions
* @return true if the user models have been updated
*/
+ @Override
public boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {
List<UserModel> users = new ArrayList<UserModel>();
for (RegistrantAccessPermission up : permissions) {
* @param repository
* @return list of all usernames that have an access permission for the repository
*/
+ @Override
public List<String> getRepositoryUsers(RepositoryModel repository) {
return userService.getUsernamesForRepositoryRole(repository.name);
}
* @param isCreate
* @throws GitBlitException
*/
+ @Override
public void updateUserModel(String username, UserModel user, boolean isCreate)
throws GitBlitException {
if (!username.equalsIgnoreCase(user.username)) {
*
* @return the list of teams
*/
+ @Override
public List<TeamModel> getAllTeams() {
List<TeamModel> teams = userService.getAllTeams();
return teams;
* @param teamname
* @return a TeamModel object or null
*/
+ @Override
public TeamModel getTeamModel(String teamname) {
return userService.getTeamModel(teamname);
}
* @param repository
* @return a list of RegistrantAccessPermissions
*/
+ @Override
public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {
List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
for (TeamModel team : userService.getAllTeams()) {
* @param permissions
* @return true if the team models have been updated
*/
+ @Override
public boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {
List<TeamModel> teams = new ArrayList<TeamModel>();
for (RegistrantAccessPermission tp : permissions) {
* @param repository
* @return list of all teamnames with explicit access permissions to the repository
*/
+ @Override
public List<String> getRepositoryTeams(RepositoryModel repository) {
return userService.getTeamnamesForRepositoryRole(repository.name);
}
* @param team
* @param isCreate
*/
+ @Override
public void updateTeamModel(String teamname, TeamModel team, boolean isCreate)
throws GitBlitException {
if (!teamname.equalsIgnoreCase(team.name)) {
* @param teamname
* @return true if successful
*/
+ @Override
public boolean deleteTeam(String teamname) {
return userService.deleteTeam(teamname);
}
*
* @param model
*/
- private void addToCachedRepositoryList(RepositoryModel model) {
+ @Override
+ public void addToCachedRepositoryList(RepositoryModel model) {
if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
repositoryListCache.put(model.name.toLowerCase(), model);
* Resets the repository list cache.
*
*/
+ @Override
public void resetRepositoryListCache() {
logger.info("Repository cache manually reset");
repositoryListCache.clear();
*
* @return list of all repositories
*/
+ @Override
public List<String> getRepositoryList() {
if (repositoryListCache.size() == 0 || !isValidRepositoryList()) {
// we are not caching OR we have not yet cached OR the cached list is invalid
} else {
// we are caching this list
String msg = "{0} repositories identified in {1} msecs";
- if (getBoolean(Keys.web.showRepositorySizes, true)) {
+ if (settings.getBoolean(Keys.web.showRepositorySizes, true)) {
// optionally (re)calculate repository sizes
msg = "{0} repositories identified with calculated folder sizes in {1} msecs";
}
* @param repositoryName
* @return repository or null
*/
+ @Override
public Repository getRepository(String repositoryName) {
return getRepository(repositoryName, true);
}
* @param logError
* @return repository or null
*/
+ @Override
public Repository getRepository(String repositoryName, boolean logError) {
// Decode url-encoded repository name (issue-278)
// http://stackoverflow.com/questions/17183110
* @param user
* @return list of repository models accessible to user
*/
+ @Override
public List<RepositoryModel> getRepositoryModels(UserModel user) {
long methodStart = System.currentTimeMillis();
List<String> list = getRepositoryList();
* @param repositoryName
* @return repository model or null
*/
+ @Override
public RepositoryModel getRepositoryModel(UserModel user, String repositoryName) {
RepositoryModel model = getRepositoryModel(repositoryName);
if (model == null) {
* @param repositoryName
* @return repository model or null
*/
+ @Override
public RepositoryModel getRepositoryModel(String repositoryName) {
// Decode url-encoded repository name (issue-278)
// http://stackoverflow.com/questions/17183110
* @param repository
* @return the star count
*/
+ @Override
public long getStarCount(RepositoryModel repository) {
long count = 0;
for (UserModel user : getAllUsers()) {
}
// project configs
- String rootName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main");
+ String rootName = settings.getString(Keys.web.repositoryRootGroupName, "main");
ProjectModel rootProject = new ProjectModel(rootName, true);
Map<String, ProjectModel> configs = new HashMap<String, ProjectModel>();
* @param includeUsers
* @return list of projects that are accessible to the user
*/
+ @Override
public List<ProjectModel> getProjectModels(UserModel user, boolean includeUsers) {
Map<String, ProjectModel> configs = getProjectConfigs();
* @param user
* @return a project model, or null if it does not exist
*/
+ @Override
public ProjectModel getProjectModel(String name, UserModel user) {
for (ProjectModel project : getProjectModels(user, true)) {
if (project.name.equalsIgnoreCase(name)) {
* @param name a project name
* @return a project model or null if the project does not exist
*/
+ @Override
public ProjectModel getProjectModel(String name) {
Map<String, ProjectModel> configs = getProjectConfigs();
ProjectModel project = configs.get(name.toLowerCase());
* @param includeUsers
* @return a list of project models
*/
+ @Override
public List<ProjectModel> getProjectModels(List<RepositoryModel> repositoryModels, boolean includeUsers) {
Map<String, ProjectModel> projects = new LinkedHashMap<String, ProjectModel>();
for (RepositoryModel repository : repositoryModels) {
* @param n
* @return true if the repository exists
*/
+ @Override
public boolean hasRepository(String repositoryName) {
return hasRepository(repositoryName, false);
}
* @param caseInsensitive
* @return true if the repository exists
*/
+ @Override
public boolean hasRepository(String repositoryName, boolean caseSensitiveCheck) {
if (!caseSensitiveCheck && settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
// if we are caching use the cache to determine availability
* @param origin
* @return true the if the user has a fork
*/
+ @Override
public boolean hasFork(String username, String origin) {
return getFork(username, origin) != null;
}
* @param origin
* @return the name of the user's fork, null otherwise
*/
+ @Override
public String getFork(String username, String origin) {
String userProject = ModelUtils.getPersonalPath(username);
if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
* @param repository
* @return a ForkModel
*/
+ @Override
public ForkModel getForkNetwork(String repository) {
if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
// find the root, cached
* @param model
* @return size in bytes of the repository
*/
+ @Override
public long updateLastChangeFields(Repository r, RepositoryModel model) {
LastChange lc = JGitUtils.getLastChange(r);
model.lastChange = lc.when;
model.lastChangeAuthor = lc.who;
- if (!getBoolean(Keys.web.showRepositorySizes, true) || model.skipSizeCalculation) {
+ if (!settings.getBoolean(Keys.web.showRepositorySizes, true) || model.skipSizeCalculation) {
model.size = null;
return 0L;
}
* @param repository
* @return a new array list of metrics
*/
+ @Override
public List<Metric> getRepositoryDefaultMetrics(RepositoryModel model, Repository repository) {
if (repositoryMetricsCache.hasCurrent(model.name, model.lastChange)) {
return new ArrayList<Metric>(repositoryMetricsCache.getObject(model.name));
* @param isCreate
* @throws GitBlitException
*/
+ @Override
public void updateRepositoryModel(String repositoryName, RepositoryModel repository,
boolean isCreate) throws GitBlitException {
if (gcExecutor.isCollectingGarbage(repositoryName)) {
Repository r = null;
String projectPath = StringUtils.getFirstPathElement(repository.name);
if (!StringUtils.isEmpty(projectPath)) {
- if (projectPath.equalsIgnoreCase(getString(Keys.web.repositoryRootGroupName, "main"))) {
+ if (projectPath.equalsIgnoreCase(settings.getString(Keys.web.repositoryRootGroupName, "main"))) {
// strip leading group name
repository.name = repository.name.substring(projectPath.length() + 1);
}
}
// create repository
logger.info("create repository " + repository.name);
- String shared = getString(Keys.git.createRepositoriesShared, "FALSE");
+ String shared = settings.getString(Keys.git.createRepositoriesShared, "FALSE");
r = JGitUtils.createRepository(repositoriesFolder, repository.name, shared);
} else {
// rename repository
// Adjust permissions in case we updated the config files
JGitUtils.adjustSharedPerm(new File(r.getDirectory().getAbsolutePath(), "config"),
- getString(Keys.git.createRepositoriesShared, "FALSE"));
+ settings.getString(Keys.git.createRepositoriesShared, "FALSE"));
JGitUtils.adjustSharedPerm(new File(r.getDirectory().getAbsolutePath(), "HEAD"),
- getString(Keys.git.createRepositoriesShared, "FALSE"));
+ settings.getString(Keys.git.createRepositoriesShared, "FALSE"));
// close the repository object
r.close();
* @param repository
* the Gitblit repository model
*/
+ @Override
public void updateConfiguration(Repository r, RepositoryModel repository) {
StoredConfig config = r.getConfig();
config.setString(Constants.CONFIG_GITBLIT, null, "description", repository.description);
* @param model
* @return true if successful
*/
+ @Override
public boolean deleteRepositoryModel(RepositoryModel model) {
return deleteRepository(model.name);
}
* @param repositoryName
* @return true if successful
*/
+ @Override
public boolean deleteRepository(String repositoryName) {
try {
closeRepository(repositoryName);
return scheduledExecutor;
}
- public static boolean canFederate() {
- String passphrase = getString(Keys.federation.passphrase, "");
+ @Override
+ public boolean canFederate() {
+ String passphrase = settings.getString(Keys.federation.passphrase, "");
return !StringUtils.isEmpty(passphrase);
}
*
* @return list of registered gitblit instances
*/
+ @Override
public List<FederationModel> getFederationRegistrations() {
if (federationRegistrations.isEmpty()) {
federationRegistrations.addAll(FederationUtils.getFederationRegistrations(settings));
* the name of the registration
* @return a federation registration
*/
+ @Override
public FederationModel getFederationRegistration(String url, String name) {
// check registrations
for (FederationModel r : getFederationRegistrations()) {
*
* @return list of federation sets
*/
+ @Override
public List<FederationSet> getFederationSets(String gitblitUrl) {
List<FederationSet> list = new ArrayList<FederationSet>();
// generate standard tokens
*
* @return list of federation tokens
*/
+ @Override
public List<String> getFederationTokens() {
List<String> tokens = new ArrayList<String>();
// generate standard tokens
* @param type
* @return a federation token
*/
+ @Override
public String getFederationToken(FederationToken type) {
return getFederationToken(type.name());
}
* @param value
* @return a federation token
*/
+ @Override
public String getFederationToken(String value) {
String passphrase = settings.getString(Keys.federation.passphrase, "");
return StringUtils.getSHA1(passphrase + "-" + value);
* @param token
* @return true if the request can be executed
*/
+ @Override
public boolean validateFederationRequest(FederationRequest req, String token) {
String all = getFederationToken(FederationToken.ALL);
String unr = getFederationToken(FederationToken.USERS_AND_REPOSITORIES);
* the registration from the pulling Gitblit instance
* @return true if acknowledged
*/
+ @Override
public boolean acknowledgeFederationStatus(String identification, FederationModel registration) {
// reset the url to the identification of the pulling Gitblit instance
registration.url = identification;
*
* @return the list of registration results
*/
+ @Override
public List<FederationModel> getFederationResultRegistrations() {
return new ArrayList<FederationModel>(federationPullResults.values());
}
* administrators
* @return true if the proposal was submitted
*/
+ @Override
public boolean submitFederationProposal(FederationProposal proposal, String gitblitUrl) {
// convert proposal to json
String json = JsonUtils.toJsonString(proposal);
*
* @return list of federation proposals
*/
+ @Override
public List<FederationProposal> getPendingFederationProposals() {
List<FederationProposal> list = new ArrayList<FederationProposal>();
File folder = getProposalsFolder();
* the federation token
* @return a map of <cloneurl, RepositoryModel>
*/
+ @Override
public Map<String, RepositoryModel> getRepositories(String gitblitUrl, String token) {
Map<String, String> federationSets = new HashMap<String, String>();
- for (String set : getStrings(Keys.federation.sets)) {
+ for (String set : settings.getStrings(Keys.federation.sets)) {
federationSets.put(getFederationToken(set), set);
}
* @param token
* @return a potential proposal
*/
+ @Override
public FederationProposal createFederationProposal(String gitblitUrl, String token) {
FederationToken tokenType = FederationToken.REPOSITORIES;
for (FederationToken type : FederationToken.values()) {
* @param token
* @return the specified proposal or null
*/
+ @Override
public FederationProposal getPendingFederationProposal(String token) {
List<FederationProposal> list = getPendingFederationProposals();
for (FederationProposal proposal : list) {
* proposal
* @return true if the proposal was deleted
*/
+ @Override
public boolean deletePendingFederationProposal(FederationProposal proposal) {
File folder = getProposalsFolder();
File file = new File(folder, proposal.token + Constants.PROPOSAL_EXT);
*
* @return list of available hook scripts
*/
+ @Override
public List<String> getAllScripts() {
- File groovyFolder = getGroovyScriptsFolder();
+ File groovyFolder = getHooksFolder();
File[] files = groovyFolder.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
* if null only the globally specified scripts are returned
* @return a list of scripts
*/
+ @Override
public List<String> getPreReceiveScriptsInherited(RepositoryModel repository) {
Set<String> scripts = new LinkedHashSet<String>();
// Globals
- for (String script : getStrings(Keys.groovy.preReceiveScripts)) {
+ for (String script : settings.getStrings(Keys.groovy.preReceiveScripts)) {
if (script.endsWith(".groovy")) {
scripts.add(script.substring(0, script.lastIndexOf('.')));
} else {
* optional parameter
* @return list of available hook scripts
*/
+ @Override
public List<String> getPreReceiveScriptsUnused(RepositoryModel repository) {
Set<String> inherited = new TreeSet<String>(getPreReceiveScriptsInherited(repository));
* if null only the globally specified scripts are returned
* @return a list of scripts
*/
+ @Override
public List<String> getPostReceiveScriptsInherited(RepositoryModel repository) {
Set<String> scripts = new LinkedHashSet<String>();
// Global Scripts
- for (String script : getStrings(Keys.groovy.postReceiveScripts)) {
+ for (String script : settings.getStrings(Keys.groovy.postReceiveScripts)) {
if (script.endsWith(".groovy")) {
scripts.add(script.substring(0, script.lastIndexOf('.')));
} else {
* optional parameter
* @return list of available hook scripts
*/
+ @Override
public List<String> getPostReceiveScriptsUnused(RepositoryModel repository) {
Set<String> inherited = new TreeSet<String>(getPostReceiveScriptsInherited(repository));
* @param repositories
* @return
*/
+ @Override
public List<SearchResult> search(String query, int page, int pageSize, List<String> repositories) {
List<SearchResult> srs = luceneExecutor.search(query, page, pageSize, repositories);
return srs;
* @param subject
* @param message
*/
+ @Override
public void sendMailToAdministrators(String subject, String message) {
List<String> toAddresses = settings.getStrings(Keys.mail.adminAddresses);
sendMail(subject, message, toAddresses);
* @param message
* @param toAddresses
*/
+ @Override
public void sendMail(String subject, String message, Collection<String> toAddresses) {
this.sendMail(subject, message, toAddresses.toArray(new String[0]));
}
* @param message
* @param toAddresses
*/
+ @Override
public void sendMail(String subject, String message, String... toAddresses) {
if (toAddresses == null || toAddresses.length == 0) {
logger.debug(MessageFormat.format("Dropping message {0} because there are no recipients", subject));
* @param message
* @param toAddresses
*/
+ @Override
public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) {
this.sendHtmlMail(subject, message, toAddresses.toArray(new String[0]));
}
* @param message
* @param toAddresses
*/
+ @Override
public void sendHtmlMail(String subject, String message, String... toAddresses) {
if (toAddresses == null || toAddresses.length == 0) {
logger.debug(MessageFormat.format("Dropping message {0} because there are no recipients", subject));
*
* @return SettingsModel
*/
+ @Override
public ServerSettings getSettingsModel() {
// ensure that the current values are updated in the setting models
for (String key : settings.getAllKeys(null)) {
logTimezone("JVM", TimeZone.getDefault());
logTimezone(Constants.NAME, getTimezone());
- serverStatus = new ServerStatus(isGO());
+ serverStatus = new ServerStatus(goSettings != null);
if (this.userService == null) {
String realm = settings.getString(Keys.realm.userService, "${baseFolder}/users.properties");
*
* @return true if we are running the gc executor
*/
+ @Override
public boolean isCollectingGarbage() {
return gcExecutor.isRunning();
}
* @param repositoryName
* @return true if actively collecting garbage
*/
+ @Override
public boolean isCollectingGarbage(String repositoryName) {
return gcExecutor.isCollectingGarbage(repositoryName);
}
* @return the repository model of the fork, if successful
* @throws GitBlitException
*/
+ @Override
public RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException {
String cloneName = MessageFormat.format("{0}/{1}.git", user.getPersonalPath(), StringUtils.stripDotGit(StringUtils.getLastPathElement(repository.name)));
String fromUrl = MessageFormat.format("file://{0}/{1}", repositoriesFolder.getAbsolutePath(), repository.name);
*
* @return status of Cookie authentication enablement.
*/
- public boolean allowCookieAuthentication() {
- return GitBlit.getBoolean(Keys.web.allowCookieAuthentication, true) && userService.supportsCookies();
+ @Override
+ public boolean supportsCookies() {
+ return settings.getBoolean(Keys.web.allowCookieAuthentication, true) && userService.supportsCookies();
+ }
+
+ @Override
+ public String getCookie(UserModel model) {
+ return userService.getCookie(model);
+ }
+
+ @Override
+ public UserModel authenticate(char[] cookie) {
+ return userService.authenticate(cookie);
+ }
+
+ @Override
+ public boolean updateUserModel(UserModel model) {
+ return userService.updateUserModel(model);
+ }
+
+ @Override
+ public boolean updateUserModels(Collection<UserModel> models) {
+ return userService.updateUserModels(models);
+ }
+
+ @Override
+ public boolean updateUserModel(String username, UserModel model) {
+ return userService.updateUserModel(username, model);
+ }
+
+ @Override
+ public boolean deleteUserModel(UserModel model) {
+ return userService.deleteUserModel(model);
+ }
+
+ @Override
+ public List<String> getAllTeamNames() {
+ return userService.getAllTeamNames();
+ }
+
+ @Override
+ public List<String> getTeamnamesForRepositoryRole(String role) {
+ return userService.getTeamnamesForRepositoryRole(role);
+ }
+
+ @Override
+ public boolean updateTeamModel(TeamModel model) {
+ return userService.updateTeamModel(model);
+ }
+
+ @Override
+ public boolean updateTeamModels(Collection<TeamModel> models) {
+ return userService.updateTeamModels(models);
+ }
+
+ @Override
+ public boolean updateTeamModel(String teamname, TeamModel model) {
+ return userService.updateTeamModel(teamname, model);
+ }
+
+ @Override
+ public boolean deleteTeamModel(TeamModel model) {
+ return userService.deleteTeamModel(model);
+ }
+
+ @Override
+ public List<String> getUsernamesForRepositoryRole(String role) {
+ return userService.getUsernamesForRepositoryRole(role);
+ }
+
+ @Override
+ public boolean renameRepositoryRole(String oldRole, String newRole) {
+ return userService.renameRepositoryRole(oldRole, newRole);
+ }
+
+ @Override
+ public boolean deleteRepositoryRole(String role) {
+ return userService.deleteRepositoryRole(role);
+ }
+
+ @Override
+ public void logout(HttpServletResponse response, UserModel user) {
+ setCookie(response, null);
+ userService.logout(user);
}
}
}\r
\r
// Setup the GitBlit context\r
- GitBlit gitblit = getGitBlitInstance();\r
+ GitBlit gitblit = newGitblit(settings, baseFolder);\r
gitblit.configureContext(settings, baseFolder, true);\r
rootContext.addEventListener(gitblit);\r
\r
}\r
}\r
\r
- protected GitBlit getGitBlitInstance() {\r
- return GitBlit.self();\r
+ protected GitBlit newGitblit(IStoredSettings settings, File baseFolder) {\r
+ return new GitBlit(settings, baseFolder);\r
}\r
\r
/**\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.Constants.AuthorizationControl;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.StringUtils;\r
*/\r
@Override\r
protected boolean isCreationAllowed() {\r
- return GitBlit.getBoolean(Keys.git.allowCreateOnPush, true);\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ return settings.getBoolean(Keys.git.allowCreateOnPush, true);\r
}\r
\r
/**\r
\r
@Override\r
protected boolean requiresClientCertificate() {\r
- return GitBlit.getBoolean(Keys.git.requiresClientCertificate, false);\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ return settings.getBoolean(Keys.git.requiresClientCertificate, false);\r
}\r
\r
/**\r
*/\r
@Override\r
protected boolean canAccess(RepositoryModel repository, UserModel user, String action) {\r
- if (!GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ if (!settings.getBoolean(Keys.git.enableGitServlet, true)) {\r
// Git Servlet disabled\r
return false;\r
}\r
model.accessRestriction = AccessRestrictionType.VIEW;\r
} else {\r
// common repository, user default server settings\r
- model.authorizationControl = AuthorizationControl.fromName(GitBlit.getString(Keys.git.defaultAuthorizationControl, ""));\r
- model.accessRestriction = AccessRestrictionType.fromName(GitBlit.getString(Keys.git.defaultAccessRestriction, "PUSH"));\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ model.authorizationControl = AuthorizationControl.fromName(settings.getString(Keys.git.defaultAuthorizationControl, ""));\r
+ model.accessRestriction = AccessRestrictionType.fromName(settings.getString(Keys.git.defaultAccessRestriction, "PUSH"));\r
}\r
\r
// create the repository\r
try {\r
- GitBlit.self().updateRepositoryModel(model.name, model, true);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ repositoryManager.updateRepositoryModel(model.name, model, true);\r
logger.info(MessageFormat.format("{0} created {1} ON-PUSH", user.username, model.name));\r
- return GitBlit.self().getRepositoryModel(model.name);\r
+ return repositoryManager.getRepositoryModel(model.name);\r
} catch (GitBlitException e) {\r
logger.error(MessageFormat.format("{0} failed to create repository {1} ON-PUSH!", user.username, model.name), e);\r
}\r
import org.slf4j.LoggerFactory;\r
\r
import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.TeamModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.DeepCopier;\r
\r
@Override\r
public void setup(IStoredSettings settings) {\r
- File realmFile = GitBlit.getFileOrFolder(Keys.realm.userService, "${baseFolder}/users.conf");\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ File realmFile = runtimeManager.getFileOrFolder(Keys.realm.userService, "${baseFolder}/users.conf");\r
serviceImpl = createUserService(realmFile);\r
logger.info("GUS delegating to " + serviceImpl.toString());\r
}\r
import org.slf4j.LoggerFactory;
import com.gitblit.Constants.AccountType;
+import com.gitblit.manager.IRuntimeManager;
import com.gitblit.models.UserModel;
import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.StringUtils;
this.settings = settings;
// This is done in two steps in order to avoid calling GitBlit.getFileOrFolder(String, String) which will segfault for unit tests.
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
String file = settings.getString(KEY_BACKING_US, DEFAULT_BACKING_US);
- File realmFile = GitBlit.getFileOrFolder(file);
+ File realmFile = runtimeManager.getFileOrFolder(file);
serviceImpl = createUserService(realmFile);
logger.info("Htpasswd User Service backed by " + serviceImpl.toString());
if ( !file.equals(htpasswdFilePath) ) {
// The htpasswd file setting changed. Rediscover the file.
this.htpasswdFilePath = file;
- this.htpasswdFile = GitBlit.getFileOrFolder(file);
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
+ this.htpasswdFile = runtimeManager.getFileOrFolder(file);
this.htUsers.clear();
this.forceReload = true;
}
overrides.put(key, "" + value);\r
}\r
\r
+ /**\r
+ * Override the specified key with the specified value.\r
+ *\r
+ * @param key\r
+ * @param value\r
+ */\r
+ public void overrideSetting(String key, boolean value) {\r
+ overrides.put(key, "" + value);\r
+ }\r
+\r
/**\r
* Updates the values for the specified keys and persists the entire\r
* configuration file.\r
import org.slf4j.LoggerFactory;\r
\r
import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.TeamModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ArrayUtils;\r
public void setup(IStoredSettings settings) {\r
this.settings = settings;\r
String file = settings.getString(Keys.realm.ldap.backingUserService, "${baseFolder}/users.conf");\r
- File realmFile = GitBlit.getFileOrFolder(file);\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ File realmFile = runtimeManager.getFileOrFolder(file);\r
\r
serviceImpl = createUserService(realmFile);\r
logger.info("LDAP User Service backed by " + serviceImpl.toString());\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
+import com.gitblit.manager.IRuntimeManager;\r
+\r
/**\r
* Handles requests for logo.png\r
*\r
\r
@Override\r
protected long getLastModified(HttpServletRequest req) {\r
- File file = GitBlit.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ File file = runtimeManager.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\r
if (file.exists()) {\r
return Math.max(lastModified, file.lastModified());\r
} else {\r
InputStream is = null;\r
try {\r
String contentType = null;\r
- File file = GitBlit.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ File file = runtimeManager.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\r
if (file.exists()) {\r
// custom logo\r
ServletContext context = request.getSession().getServletContext();\r
} catch (Exception e) {\r
e.printStackTrace();\r
} finally {\r
- if(is != null) {\r
+ if (is != null) {\r
is.close();\r
}\r
}\r
import org.slf4j.LoggerFactory;\r
\r
import com.gitblit.Constants.SearchObjectType;\r
+import com.gitblit.manager.IRepositoryManager;\r
import com.gitblit.models.PathModel.PathChangeModel;\r
import com.gitblit.models.RefModel;\r
import com.gitblit.models.RepositoryModel;\r
String exts = storedSettings.getString(Keys.web.luceneIgnoreExtensions, luceneIgnoreExtensions);\r
excludedExtensions = new TreeSet<String>(StringUtils.getStringsFromValue(exts));\r
\r
- if (GitBlit.self().isCollectingGarbage()) {\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ if (repositoryManager.isCollectingGarbage()) {\r
// busy collecting garbage, try again later\r
return;\r
}\r
\r
- for (String repositoryName: GitBlit.self().getRepositoryList()) {\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
+ for (String repositoryName: repositoryManager.getRepositoryList()) {\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);\r
if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) {\r
- Repository repository = GitBlit.self().getRepository(model.name);\r
+ Repository repository = repositoryManager.getRepository(model.name);\r
if (repository == null) {\r
- if (GitBlit.self().isCollectingGarbage(model.name)) {\r
+ if (repositoryManager.isCollectingGarbage(model.name)) {\r
logger.info(MessageFormat.format("Skipping Lucene index of {0}, busy garbage collecting", repositoryName));\r
}\r
continue;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import com.gitblit.manager.IRepositoryManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.JGitUtils;\r
\r
running.set(true);\r
\r
- for (String repositoryName : GitBlit.self().getRepositoryList()) {\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
+ for (String repositoryName : repositoryManager.getRepositoryList()) {\r
if (forceClose.get()) {\r
break;\r
}\r
- if (GitBlit.self().isCollectingGarbage(repositoryName)) {\r
+ if (repositoryManager.isCollectingGarbage(repositoryName)) {\r
logger.debug("mirror is skipping {} garbagecollection", repositoryName);\r
continue;\r
}\r
RepositoryModel model = null;\r
Repository repository = null;\r
try {\r
- model = GitBlit.self().getRepositoryModel(repositoryName);\r
+ model = repositoryManager.getRepositoryModel(repositoryName);\r
if (!model.isMirror && !model.isBare) {\r
// repository must be a valid bare git mirror\r
logger.debug("mirror is skipping {} !mirror !bare", repositoryName);\r
continue;\r
}\r
\r
- repository = GitBlit.self().getRepository(repositoryName);\r
+ repository = repositoryManager.getRepository(repositoryName);\r
if (repository == null) {\r
logger.warn(MessageFormat.format("MirrorExecutor is missing repository {0}?!?", repositoryName));\r
continue;\r
import org.slf4j.LoggerFactory;\r
\r
import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.StringUtils;\r
this.settings = settings;\r
\r
String file = settings.getString(Keys.realm.pam.backingUserService, "${baseFolder}/users.conf");\r
- File realmFile = GitBlit.getFileOrFolder(file);\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ File realmFile = runtimeManager.getFileOrFolder(file);\r
\r
serviceImpl = createUserService(realmFile);\r
logger.info("PAM User Service backed by " + serviceImpl.toString());\r
import org.eclipse.jgit.lib.Repository;\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.manager.IRepositoryManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
\r
} else {\r
repository = url.substring(0, slash);\r
}\r
- r = GitBlit.self().getRepository(repository, false);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ r = repositoryManager.getRepository(repository, false);\r
if (r == null) {\r
// try again\r
offset = slash + 1;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.PathModel;\r
import com.gitblit.models.RefModel;\r
import com.gitblit.utils.ArrayUtils;\r
path = path.substring(1);\r
}\r
\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
// determine repository and resource from url\r
String repository = "";\r
String resource = "";\r
} else {\r
repository = path.substring(0, slash);\r
}\r
- r = GitBlit.self().getRepository(repository, false);\r
+ r = repositoryManager.getRepository(repository, false);\r
offset = slash + 1;\r
if (offset > 0) {\r
resource = path.substring(offset);\r
return;\r
}\r
\r
- MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings());\r
- String [] encodings = GitBlit.getEncodings();\r
+ MarkupProcessor processor = new MarkupProcessor(settings);\r
+ String [] encodings = settings.getStrings(Keys.web.blobEncodings).toArray(new String[0]);\r
\r
RevTree tree = commit.getTree();\r
\r
import org.slf4j.LoggerFactory;\r
\r
import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.ConnectionUtils;\r
this.settings = settings;\r
\r
String file = settings.getString(Keys.realm.redmine.backingUserService, "${baseFolder}/users.conf");\r
- File realmFile = GitBlit.getFileOrFolder(file);\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ File realmFile = runtimeManager.getFileOrFolder(file);\r
\r
serviceImpl = createUserService(realmFile);\r
logger.info("Redmine User Service backed by " + serviceImpl.toString());\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.utils.FileUtils;\r
\r
/**\r
protected void processRequest(javax.servlet.http.HttpServletRequest request,\r
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
java.io.IOException {\r
- File file = GitBlit.getFileOrFolder(Keys.web.robots.txt, null);\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ File file = runtimeManager.getFileOrFolder(Keys.web.robots.txt, null);\r
String content = "";\r
if (file.exists()) {\r
content = FileUtils.readContent(file, "\n");\r
import javax.servlet.http.HttpServletResponse;\r
\r
import com.gitblit.Constants.RpcRequest;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.UserModel;\r
\r
/**\r
return;\r
}\r
\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ IStoredSettings settings = runtimeManager.getSettings();\r
+\r
boolean adminRequest = requestType.exceeds(RpcRequest.LIST_SETTINGS);\r
\r
// conditionally reject all rpc requests\r
- if (!GitBlit.getBoolean(Keys.web.enableRpcServlet, true)) {\r
+ if (!settings.getBoolean(Keys.web.enableRpcServlet, true)) {\r
logger.warn(Keys.web.enableRpcServlet + " must be set TRUE for rpc requests.");\r
httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);\r
return;\r
}\r
\r
- boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, false);\r
- boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true);\r
+ boolean authenticateView = settings.getBoolean(Keys.web.authenticateViewPages, false);\r
+ boolean authenticateAdmin = settings.getBoolean(Keys.web.authenticateAdminPages, true);\r
\r
// Wrap the HttpServletRequest with the RpcServletRequest which\r
// overrides the servlet container user principal methods.\r
}\r
\r
// conditionally reject rpc management/administration requests\r
- if (adminRequest && !GitBlit.getBoolean(Keys.web.enableRpcManagement, false)) {\r
+ if (adminRequest && !settings.getBoolean(Keys.web.enableRpcManagement, false)) {\r
logger.warn(MessageFormat.format("{0} must be set TRUE for {1} rpc requests.",\r
Keys.web.enableRpcManagement, requestType.toString()));\r
httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);\r
if ((adminRequest && authenticateAdmin) || (!adminRequest && authenticateView)) {\r
if (user == null) {\r
// challenge client to provide credentials. send 401.\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("RPC: CHALLENGE {0}", fullUrl));\r
\r
}\r
return;\r
}\r
// valid user, but not for requested access. send 403.\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("RPC: {0} forbidden to access {1}",\r
user.username, fullUrl));\r
}\r
}\r
}\r
\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("RPC: {0} ({1}) unauthenticated", fullUrl,\r
HttpServletResponse.SC_CONTINUE));\r
}\r
import org.eclipse.jgit.lib.Repository;\r
\r
import com.gitblit.Constants.RpcRequest;\r
+import com.gitblit.manager.IFederationManager;\r
+import com.gitblit.manager.IGitblitManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.IUserManager;\r
import com.gitblit.models.RefModel;\r
import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType,\r
request.getRemoteAddr()));\r
\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ IUserManager userManager = GitBlit.getManager(IUserManager.class);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ IGitblitManager gitblitManager = GitBlit.getManager(IGitblitManager.class);\r
+ IFederationManager federationManager = GitBlit.getManager(IFederationManager.class);\r
+ IStoredSettings settings = runtimeManager.getSettings();\r
+\r
UserModel user = (UserModel) request.getUserPrincipal();\r
\r
boolean allowManagement = user != null && user.canAdmin()\r
- && GitBlit.getBoolean(Keys.web.enableRpcManagement, false);\r
+ && settings.getBoolean(Keys.web.enableRpcManagement, false);\r
\r
boolean allowAdmin = user != null && user.canAdmin()\r
- && GitBlit.getBoolean(Keys.web.enableRpcAdministration, false);\r
+ && settings.getBoolean(Keys.web.enableRpcAdministration, false);\r
\r
Object result = null;\r
if (RpcRequest.GET_PROTOCOL.equals(reqType)) {\r
String cloneUrl = sb.toString();\r
\r
// list repositories\r
- List<RepositoryModel> list = GitBlit.self().getRepositoryModels(user);\r
+ List<RepositoryModel> list = repositoryManager.getRepositoryModels(user);\r
Map<String, RepositoryModel> repositories = new HashMap<String, RepositoryModel>();\r
for (RepositoryModel model : list) {\r
String url = MessageFormat.format(cloneUrl, model.name);\r
} else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {\r
// list all local branches in all repositories accessible to user\r
Map<String, List<String>> localBranches = new HashMap<String, List<String>>();\r
- List<RepositoryModel> models = GitBlit.self().getRepositoryModels(user);\r
+ List<RepositoryModel> models = repositoryManager.getRepositoryModels(user);\r
for (RepositoryModel model : models) {\r
if (!model.hasCommits) {\r
// skip empty repository\r
continue;\r
}\r
// get local branches\r
- Repository repository = GitBlit.self().getRepository(model.name);\r
+ Repository repository = repositoryManager.getRepository(model.name);\r
List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);\r
if (model.showRemoteBranches) {\r
// add remote branches if repository displays them\r
} else {\r
if (user.canAdmin() || objectName.equals(user.username)) {\r
// return the specified user\r
- UserModel requestedUser = GitBlit.self().getUserModel(objectName);\r
+ UserModel requestedUser = userManager.getUserModel(objectName);\r
if (requestedUser == null) {\r
response.setStatus(failureCode);\r
} else {\r
}\r
} else if (RpcRequest.LIST_USERS.equals(reqType)) {\r
// list users\r
- List<String> names = GitBlit.self().getAllUsernames();\r
+ List<String> names = userManager.getAllUsernames();\r
List<UserModel> users = new ArrayList<UserModel>();\r
for (String name : names) {\r
- users.add(GitBlit.self().getUserModel(name));\r
+ users.add(userManager.getUserModel(name));\r
}\r
result = users;\r
} else if (RpcRequest.LIST_TEAMS.equals(reqType)) {\r
// list teams\r
- List<String> names = GitBlit.self().getAllTeamnames();\r
+ List<String> names = userManager.getAllTeamNames();\r
List<TeamModel> teams = new ArrayList<TeamModel>();\r
for (String name : names) {\r
- teams.add(GitBlit.self().getTeamModel(name));\r
+ teams.add(userManager.getTeamModel(name));\r
}\r
result = teams;\r
} else if (RpcRequest.CREATE_REPOSITORY.equals(reqType)) {\r
// create repository\r
RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
try {\r
- GitBlit.self().updateRepositoryModel(model.name, model, true);\r
+ repositoryManager.updateRepositoryModel(model.name, model, true);\r
} catch (GitBlitException e) {\r
response.setStatus(failureCode);\r
}\r
repoName = model.name;\r
}\r
try {\r
- GitBlit.self().updateRepositoryModel(repoName, model, false);\r
+ repositoryManager.updateRepositoryModel(repoName, model, false);\r
} catch (GitBlitException e) {\r
response.setStatus(failureCode);\r
}\r
} else if (RpcRequest.DELETE_REPOSITORY.equals(reqType)) {\r
// delete repository\r
RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
- GitBlit.self().deleteRepositoryModel(model);\r
+ repositoryManager.deleteRepositoryModel(model);\r
} else if (RpcRequest.CREATE_USER.equals(reqType)) {\r
// create user\r
UserModel model = deserialize(request, response, UserModel.class);\r
try {\r
- GitBlit.self().updateUserModel(model.username, model, true);\r
+ gitblitManager.updateUserModel(model.username, model, true);\r
} catch (GitBlitException e) {\r
response.setStatus(failureCode);\r
}\r
username = model.username;\r
}\r
try {\r
- GitBlit.self().updateUserModel(username, model, false);\r
+ gitblitManager.updateUserModel(username, model, false);\r
} catch (GitBlitException e) {\r
response.setStatus(failureCode);\r
}\r
} else if (RpcRequest.DELETE_USER.equals(reqType)) {\r
// delete user\r
UserModel model = deserialize(request, response, UserModel.class);\r
- if (!GitBlit.self().deleteUser(model.username)) {\r
+ if (!userManager.deleteUser(model.username)) {\r
response.setStatus(failureCode);\r
}\r
} else if (RpcRequest.CREATE_TEAM.equals(reqType)) {\r
// create team\r
TeamModel model = deserialize(request, response, TeamModel.class);\r
try {\r
- GitBlit.self().updateTeamModel(model.name, model, true);\r
+ gitblitManager.updateTeamModel(model.name, model, true);\r
} catch (GitBlitException e) {\r
response.setStatus(failureCode);\r
}\r
teamname = model.name;\r
}\r
try {\r
- GitBlit.self().updateTeamModel(teamname, model, false);\r
+ gitblitManager.updateTeamModel(teamname, model, false);\r
} catch (GitBlitException e) {\r
response.setStatus(failureCode);\r
}\r
} else if (RpcRequest.DELETE_TEAM.equals(reqType)) {\r
// delete team\r
TeamModel model = deserialize(request, response, TeamModel.class);\r
- if (!GitBlit.self().deleteTeam(model.name)) {\r
+ if (!userManager.deleteTeam(model.name)) {\r
response.setStatus(failureCode);\r
}\r
} else if (RpcRequest.LIST_REPOSITORY_MEMBERS.equals(reqType)) {\r
// get repository members\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
- result = GitBlit.self().getRepositoryUsers(model);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
+ result = repositoryManager.getRepositoryUsers(model);\r
} else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {\r
// rejected since 1.2.0\r
response.setStatus(failureCode);\r
} else if (RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
// get repository member permissions\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
- result = GitBlit.self().getUserAccessPermissions(model);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
+ result = repositoryManager.getUserAccessPermissions(model);\r
} else if (RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
// set the repository permissions for the specified users\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
- result = GitBlit.self().setUserAccessPermissions(model, permissions);\r
+ result = repositoryManager.setUserAccessPermissions(model, permissions);\r
} else if (RpcRequest.LIST_REPOSITORY_TEAMS.equals(reqType)) {\r
// get repository teams\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
- result = GitBlit.self().getRepositoryTeams(model);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
+ result = repositoryManager.getRepositoryTeams(model);\r
} else if (RpcRequest.SET_REPOSITORY_TEAMS.equals(reqType)) {\r
// rejected since 1.2.0\r
response.setStatus(failureCode);\r
} else if (RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
// get repository team permissions\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
- result = GitBlit.self().getTeamAccessPermissions(model);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
+ result = repositoryManager.getTeamAccessPermissions(model);\r
} else if (RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
// set the repository permissions for the specified teams\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
- result = GitBlit.self().setTeamAccessPermissions(model, permissions);\r
+ result = repositoryManager.setTeamAccessPermissions(model, permissions);\r
} else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {\r
// return the list of federation registrations\r
if (allowAdmin) {\r
- result = GitBlit.self().getFederationRegistrations();\r
+ result = federationManager.getFederationRegistrations();\r
} else {\r
response.sendError(notAllowedCode);\r
}\r
} else if (RpcRequest.LIST_FEDERATION_RESULTS.equals(reqType)) {\r
// return the list of federation result registrations\r
- if (allowAdmin && GitBlit.canFederate()) {\r
- result = GitBlit.self().getFederationResultRegistrations();\r
+ if (allowAdmin && federationManager.canFederate()) {\r
+ result = federationManager.getFederationResultRegistrations();\r
} else {\r
response.sendError(notAllowedCode);\r
}\r
} else if (RpcRequest.LIST_FEDERATION_PROPOSALS.equals(reqType)) {\r
// return the list of federation proposals\r
- if (allowAdmin && GitBlit.canFederate()) {\r
- result = GitBlit.self().getPendingFederationProposals();\r
+ if (allowAdmin && federationManager.canFederate()) {\r
+ result = federationManager.getPendingFederationProposals();\r
} else {\r
response.sendError(notAllowedCode);\r
}\r
} else if (RpcRequest.LIST_FEDERATION_SETS.equals(reqType)) {\r
// return the list of federation sets\r
- if (allowAdmin && GitBlit.canFederate()) {\r
+ if (allowAdmin && federationManager.canFederate()) {\r
String gitblitUrl = HttpUtils.getGitblitURL(request);\r
- result = GitBlit.self().getFederationSets(gitblitUrl);\r
+ result = federationManager.getFederationSets(gitblitUrl);\r
} else {\r
response.sendError(notAllowedCode);\r
}\r
} else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
// return the server's settings\r
- ServerSettings settings = GitBlit.self().getSettingsModel();\r
+ ServerSettings serverSettings = runtimeManager.getSettingsModel();\r
if (allowAdmin) {\r
// return all settings\r
- result = settings;\r
+ result = serverSettings;\r
} else {\r
// anonymous users get a few settings to allow browser launching\r
List<String> keys = new ArrayList<String>();\r
// build the settings\r
ServerSettings managementSettings = new ServerSettings();\r
for (String key : keys) {\r
- managementSettings.add(settings.get(key));\r
+ managementSettings.add(serverSettings.get(key));\r
}\r
if (allowManagement) {\r
- managementSettings.pushScripts = settings.pushScripts;\r
+ managementSettings.pushScripts = serverSettings.pushScripts;\r
}\r
result = managementSettings;\r
}\r
} else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {\r
// update settings on the server\r
if (allowAdmin) {\r
- Map<String, String> settings = deserialize(request, response,\r
+ Map<String, String> map = deserialize(request, response,\r
RpcUtils.SETTINGS_TYPE);\r
- GitBlit.self().updateSettings(settings);\r
+ runtimeManager.updateSettings(map);\r
} else {\r
response.sendError(notAllowedCode);\r
}\r
} else if (RpcRequest.LIST_STATUS.equals(reqType)) {\r
// return the server's status information\r
if (allowAdmin) {\r
- result = GitBlit.self().getStatus();\r
+ result = runtimeManager.getStatus();\r
} else {\r
response.sendError(notAllowedCode);\r
}\r
} else if (RpcRequest.CLEAR_REPOSITORY_CACHE.equals(reqType)) {\r
// clear the repository list cache\r
if (allowManagement) {\r
- GitBlit.self().resetRepositoryListCache();\r
+ repositoryManager.resetRepositoryListCache();\r
} else {\r
response.sendError(notAllowedCode);\r
}\r
import org.slf4j.LoggerFactory;
import com.gitblit.Constants.AccountType;
+import com.gitblit.manager.IRuntimeManager;
import com.gitblit.models.UserModel;
import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.StringUtils;
String file = settings.getString(
Keys.realm.salesforce.backingUserService,
"${baseFolder}/users.conf");
- File realmFile = GitBlit.getFileOrFolder(file);
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
+ File realmFile = runtimeManager.getFileOrFolder(file);
serviceImpl = createUserService(realmFile);
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.ISessionManager;\r
+import com.gitblit.manager.IUserManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.StringUtils;\r
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
java.io.IOException {\r
\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ IUserManager userManager = GitBlit.getManager(IUserManager.class);\r
+ ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
// extract repo name from request\r
String repoUrl = request.getPathInfo().substring(1);\r
\r
}\r
UserModel user;\r
if (StringUtils.isEmpty(username)) {\r
- user = GitBlit.self().authenticate(request);\r
+ user = sessionManager.authenticate(request);\r
} else {\r
- user = GitBlit.self().getUserModel(username);\r
+ user = userManager.getUserModel(username);\r
}\r
if (user == null) {\r
user = UserModel.ANONYMOUS;\r
}\r
\r
// ensure that the requested repository exists\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(path);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(path);\r
if (model == null) {\r
response.setStatus(HttpServletResponse.SC_NOT_FOUND);\r
response.getWriter().append(MessageFormat.format("Repository \"{0}\" not found!", path));\r
sb.append("<sparkleshare><invite>\n");\r
sb.append(MessageFormat.format("<address>{0}</address>\n", host));\r
sb.append(MessageFormat.format("<remote_path>{0}{1}</remote_path>\n", servletPath, model.name));\r
- if (GitBlit.getInteger(Keys.fanout.port, 0) > 0) {\r
+ if (settings.getInteger(Keys.fanout.port, 0) > 0) {\r
// Gitblit is running it's own fanout service for pubsub notifications\r
- sb.append(MessageFormat.format("<announcements_url>tcp://{0}:{1}</announcements_url>\n", request.getServerName(), GitBlit.getString(Keys.fanout.port, "")));\r
+ sb.append(MessageFormat.format("<announcements_url>tcp://{0}:{1}</announcements_url>\n", request.getServerName(), settings.getString(Keys.fanout.port, "")));\r
}\r
sb.append("</invite></sparkleshare>\n");\r
\r
import javax.servlet.http.HttpServletResponse;\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.manager.IProjectManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.ProjectModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
String fullUrl = getFullUrl(httpRequest);\r
String name = extractRequestedName(fullUrl);\r
\r
- ProjectModel project = GitBlit.self().getProjectModel(name);\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ IProjectManager projectManager = GitBlit.getManager(IProjectManager.class);\r
+\r
+ ProjectModel project = projectManager.getProjectModel(name);\r
RepositoryModel model = null;\r
\r
if (project == null) {\r
// try loading a repository model\r
- model = GitBlit.self().getRepositoryModel(name);\r
+ model = repositoryManager.getRepositoryModel(name);\r
if (model == null) {\r
// repository not found. send 404.\r
logger.info(MessageFormat.format("ARF: {0} ({1})", fullUrl,\r
if (model.accessRestriction.atLeast(AccessRestrictionType.VIEW)) {\r
if (user == null) {\r
// challenge client to provide credentials. send 401.\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("ARF: CHALLENGE {0}", fullUrl));\r
}\r
httpResponse.setHeader("WWW-Authenticate", CHALLENGE);\r
return;\r
}\r
// valid user, but not for requested access. send 403.\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("ARF: {0} forbidden to access {1}",\r
user.username, fullUrl));\r
}\r
}\r
}\r
\r
- if (GitBlit.isDebugMode()) {\r
+ if (runtimeManager.isDebugMode()) {\r
logger.info(MessageFormat.format("ARF: {0} ({1}) unauthenticated", fullUrl,\r
HttpServletResponse.SC_CONTINUE));\r
}\r
import org.slf4j.LoggerFactory;\r
\r
import com.gitblit.AuthenticationFilter.AuthenticatedRequest;\r
+import com.gitblit.manager.IProjectManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.FeedEntryModel;\r
import com.gitblit.models.ProjectModel;\r
import com.gitblit.models.RefModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.HttpUtils;\r
import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.MessageProcessor;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.utils.SyndicationUtils;\r
\r
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
java.io.IOException {\r
\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ IProjectManager projectManager = GitBlit.getManager(IProjectManager.class);\r
+\r
String servletUrl = request.getContextPath() + request.getServletPath();\r
String url = request.getRequestURI().substring(servletUrl.length());\r
if (url.charAt(0) == '/' && url.length() > 1) {\r
searchType = type;\r
}\r
}\r
- int length = GitBlit.getInteger(Keys.web.syndicationEntries, 25);\r
+ int length = settings.getInteger(Keys.web.syndicationEntries, 25);\r
if (StringUtils.isEmpty(objectId)) {\r
objectId = org.eclipse.jgit.lib.Constants.HEAD;\r
}\r
if (request instanceof AuthenticatedRequest) {\r
user = ((AuthenticatedRequest) request).getUser();\r
}\r
- ProjectModel project = GitBlit.self().getProjectModel(repositoryName, user);\r
+ ProjectModel project = projectManager.getProjectModel(repositoryName, user);\r
if (project != null) {\r
isProjectFeed = true;\r
repositories = new ArrayList<String>(project.repositories);\r
}\r
\r
\r
- boolean mountParameters = GitBlit.getBoolean(Keys.web.mountParameters, true);\r
+ boolean mountParameters = settings.getBoolean(Keys.web.mountParameters, true);\r
String urlPattern;\r
if (mountParameters) {\r
// mounted parameters\r
urlPattern = "{0}/commit/?r={1}&h={2}";\r
}\r
String gitblitUrl = HttpUtils.getGitblitURL(request);\r
- char fsc = GitBlit.getChar(Keys.web.forwardSlashCharacter, '/');\r
+ char fsc = settings.getChar(Keys.web.forwardSlashCharacter, '/');\r
\r
List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();\r
\r
for (String name : repositories) {\r
- Repository repository = GitBlit.self().getRepository(name);\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(name);\r
+ Repository repository = repositoryManager.getRepository(name);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(name);\r
\r
if (repository == null) {\r
if (model.isCollectingGarbage) {\r
offset, length);\r
}\r
Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, model.showRemoteBranches);\r
+ MessageProcessor processor = new MessageProcessor(settings);\r
\r
// convert RevCommit to SyndicatedEntryModel\r
for (RevCommit commit : commits) {\r
StringUtils.encodeURL(model.name.replace('/', fsc)), commit.getName());\r
entry.published = commit.getCommitterIdent().getWhen();\r
entry.contentType = "text/html";\r
- String message = GitBlit.self().processCommitMessage(model,\r
- commit.getFullMessage());\r
+ String message = processor.processCommitMessage(model, commit.getFullMessage());\r
entry.content = message;\r
entry.repository = model.name;\r
entry.branch = objectId;\r
import waffle.windows.auth.impl.WindowsAuthProviderImpl;\r
\r
import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.StringUtils;\r
this.settings = settings;\r
\r
String file = settings.getString(Keys.realm.windows.backingUserService, "${baseFolder}/users.conf");\r
- File realmFile = GitBlit.getFileOrFolder(file);\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ File realmFile = runtimeManager.getFileOrFolder(file);\r
\r
serviceImpl = createUserService(realmFile);\r
logger.info("Windows User Service backed by " + serviceImpl.toString());\r
import javax.servlet.http.HttpServletRequest;\r
\r
import com.gitblit.GitBlit;\r
+import com.gitblit.manager.IRepositoryManager;\r
\r
/**\r
* The GitServlet provides http/https access to Git repositories.\r
\r
@Override\r
public void init(ServletConfig config) throws ServletException {\r
- setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(GitBlit.getRepositoriesFolder()));\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(repositoryManager.getRepositoriesFolder()));\r
setUploadPackFactory(new GitblitUploadPackFactory<HttpServletRequest>());\r
setReceivePackFactory(new GitblitReceivePackFactory<HttpServletRequest>());\r
super.init(config);\r
import com.gitblit.Constants;\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.GitBlit;\r
+import com.gitblit.IStoredSettings;\r
import com.gitblit.Keys;\r
import com.gitblit.client.Translation;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ArrayUtils;\r
\r
public GitblitReceivePack(Repository db, RepositoryModel repository, UserModel user) {\r
super(db);\r
+\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
this.repository = repository;\r
this.user = user == null ? UserModel.ANONYMOUS : user;\r
- this.groovyDir = GitBlit.getGroovyScriptsFolder();\r
+ this.groovyDir = repositoryManager.getHooksFolder();\r
try {\r
// set Grape root\r
- File grapeRoot = GitBlit.getFileOrFolder(Keys.groovy.grapeFolder, "${baseFolder}/groovy/grape").getAbsoluteFile();\r
+ File grapeRoot = repositoryManager.getGrapesFolder();\r
grapeRoot.mkdirs();\r
System.setProperty("grape.root", grapeRoot.getAbsolutePath());\r
this.gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());\r
}\r
}\r
\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
Set<String> scripts = new LinkedHashSet<String>();\r
- scripts.addAll(GitBlit.self().getPreReceiveScriptsInherited(repository));\r
+ scripts.addAll(repositoryManager.getPreReceiveScriptsInherited(repository));\r
if (!ArrayUtils.isEmpty(repository.preReceiveScripts)) {\r
scripts.addAll(repository.preReceiveScripts);\r
}\r
return;\r
}\r
\r
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+\r
// log ref changes\r
for (ReceiveCommand cmd : commands) {\r
\r
String msg = MessageFormat.format(template, branch);\r
String prefix;\r
if (StringUtils.isEmpty(repository.incrementalPushTagPrefix)) {\r
- prefix = GitBlit.getString(Keys.git.defaultIncrementalPushTagPrefix, "r");\r
+ prefix = settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r");\r
} else {\r
prefix = repository.incrementalPushTagPrefix;\r
}\r
LOGGER.error(MessageFormat.format("Failed to update {0} pushlog", repository.name), e);\r
}\r
\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
// run Groovy hook scripts\r
Set<String> scripts = new LinkedHashSet<String>();\r
- scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));\r
+ scripts.addAll(repositoryManager.getPostReceiveScriptsInherited(repository));\r
if (!ArrayUtils.isEmpty(repository.postReceiveScripts)) {\r
scripts.addAll(repository.postReceiveScripts);\r
}\r
import org.slf4j.LoggerFactory;
import com.gitblit.GitBlit;
+import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.IUserManager;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.HttpUtils;
public ReceivePack create(X req, Repository db)
throws ServiceNotEnabledException, ServiceNotAuthorizedException {
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
+ IUserManager userManager = GitBlit.getManager(IUserManager.class);
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
+
UserModel user = UserModel.ANONYMOUS;
String repositoryName = "";
String origin = "";
// determine pushing user
String username = request.getRemoteUser();
if (!StringUtils.isEmpty(username)) {
- UserModel u = GitBlit.self().getUserModel(username);
+ UserModel u = userManager.getUserModel(username);
if (u != null) {
user = u;
}
timeout = client.getDaemon().getTimeout();
}
- boolean allowAnonymousPushes = GitBlit.getBoolean(Keys.git.allowAnonymousPushes, false);
+ boolean allowAnonymousPushes = settings.getBoolean(Keys.git.allowAnonymousPushes, false);
if (!allowAnonymousPushes && UserModel.ANONYMOUS.equals(user)) {
// prohibit anonymous pushes
throw new ServiceNotEnabledException();
}
- final RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName);
+ final RepositoryModel repository = repositoryManager.getRepositoryModel(repositoryName);
final GitblitReceivePack rp = new GitblitReceivePack(db, repository, user);
rp.setGitblitUrl(gitblitUrl);
import org.eclipse.jgit.transport.resolver.UploadPackFactory;
import com.gitblit.GitBlit;
+import com.gitblit.manager.ISessionManager;
import com.gitblit.models.UserModel;
/**
public UploadPack create(X req, Repository db)
throws ServiceNotEnabledException, ServiceNotAuthorizedException {
+ ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
UserModel user = UserModel.ANONYMOUS;
int timeout = 0;
if (req instanceof HttpServletRequest) {
// http/https request may or may not be authenticated
- user = GitBlit.self().authenticate((HttpServletRequest) req);
+ user = sessionManager.authenticate((HttpServletRequest) req);
if (user == null) {
user = UserModel.ANONYMOUS;
}
import org.slf4j.LoggerFactory;
import com.gitblit.GitBlit;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.ISessionManager;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
*/
@Override
protected boolean isExportOk(X req, String repositoryName, Repository db) throws IOException {
- RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
+ ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
+ RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);
String scheme = null;
UserModel user = null;
HttpServletRequest httpRequest = (HttpServletRequest) req;
scheme = httpRequest.getScheme();
origin = httpRequest.getRemoteAddr();
- user = GitBlit.self().authenticate(httpRequest);
+ user = sessionManager.authenticate(httpRequest);
if (user == null) {
user = UserModel.ANONYMOUS;
}
--- /dev/null
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.manager;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import com.gitblit.Constants.FederationRequest;
+import com.gitblit.Constants.FederationToken;
+import com.gitblit.models.FederationModel;
+import com.gitblit.models.FederationProposal;
+import com.gitblit.models.FederationSet;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.UserModel;
+
+public interface IFederationManager {
+
+ /**
+ * Returns the path of the proposals folder. This method checks to see if
+ * Gitblit is running on a cloud service and may return an adjusted path.
+ *
+ * @return the proposals folder path
+ */
+ File getProposalsFolder();
+
+ UserModel getFederationUser();
+
+ boolean canFederate();
+
+ /**
+ * Returns the list of federated gitblit instances that this instance will
+ * try to pull.
+ *
+ * @return list of registered gitblit instances
+ */
+ List<FederationModel> getFederationRegistrations();
+
+ /**
+ * Retrieve the specified federation registration.
+ *
+ * @param name
+ * the name of the registration
+ * @return a federation registration
+ */
+ FederationModel getFederationRegistration(String url, String name);
+
+ /**
+ * Returns the list of federation sets.
+ *
+ * @return list of federation sets
+ */
+ List<FederationSet> getFederationSets(String gitblitUrl);
+
+ /**
+ * Returns the list of possible federation tokens for this Gitblit instance.
+ *
+ * @return list of federation tokens
+ */
+ List<String> getFederationTokens();
+
+ /**
+ * Returns the specified federation token for this Gitblit instance.
+ *
+ * @param type
+ * @return a federation token
+ */
+ String getFederationToken(FederationToken type);
+
+ /**
+ * Returns the specified federation token for this Gitblit instance.
+ *
+ * @param value
+ * @return a federation token
+ */
+ String getFederationToken(String value);
+
+ /**
+ * Compares the provided token with this Gitblit instance's tokens and
+ * determines if the requested permission may be granted to the token.
+ *
+ * @param req
+ * @param token
+ * @return true if the request can be executed
+ */
+ boolean validateFederationRequest(FederationRequest req, String token);
+
+ /**
+ * Acknowledge and cache the status of a remote Gitblit instance.
+ *
+ * @param identification
+ * the identification of the pulling Gitblit instance
+ * @param registration
+ * the registration from the pulling Gitblit instance
+ * @return true if acknowledged
+ */
+ boolean acknowledgeFederationStatus(String identification, FederationModel registration);
+
+ /**
+ * Returns the list of registration results.
+ *
+ * @return the list of registration results
+ */
+ List<FederationModel> getFederationResultRegistrations();
+
+ /**
+ * Submit a federation proposal. The proposal is cached locally and the
+ * Gitblit administrator(s) are notified via email.
+ *
+ * @param proposal
+ * the proposal
+ * @param gitblitUrl
+ * the url of your gitblit instance to send an email to
+ * administrators
+ * @return true if the proposal was submitted
+ */
+ boolean submitFederationProposal(FederationProposal proposal, String gitblitUrl);
+
+ /**
+ * Returns the list of pending federation proposals
+ *
+ * @return list of federation proposals
+ */
+ List<FederationProposal> getPendingFederationProposals();
+
+ /**
+ * Get repositories for the specified token.
+ *
+ * @param gitblitUrl
+ * the base url of this gitblit instance
+ * @param token
+ * the federation token
+ * @return a map of <cloneurl, RepositoryModel>
+ */
+ Map<String, RepositoryModel> getRepositories(String gitblitUrl, String token);
+
+ /**
+ * Creates a proposal from the token.
+ *
+ * @param gitblitUrl
+ * the url of this Gitblit instance
+ * @param token
+ * @return a potential proposal
+ */
+ FederationProposal createFederationProposal(String gitblitUrl, String token);
+
+ /**
+ * Returns the proposal identified by the supplied token.
+ *
+ * @param token
+ * @return the specified proposal or null
+ */
+ FederationProposal getPendingFederationProposal(String token);
+
+ /**
+ * Deletes a pending federation proposal.
+ *
+ * @param a
+ * proposal
+ * @return true if the proposal was deleted
+ */
+ boolean deletePendingFederationProposal(FederationProposal proposal);
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.manager;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import com.gitblit.GitBlitException;
+import com.gitblit.models.GitClientApplication;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.RepositoryUrl;
+import com.gitblit.models.TeamModel;
+import com.gitblit.models.UserModel;
+
+public interface IGitblitManager {
+
+ /**
+ * Returns a list of repository URLs and the user access permission.
+ *
+ * @param request
+ * @param user
+ * @param repository
+ * @return a list of repository urls
+ */
+ List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository);
+
+ /**
+ * Adds/updates a complete user object keyed by username. This method allows
+ * for renaming a user.
+ *
+ * @see IUserService.updateUserModel(String, UserModel)
+ * @param username
+ * @param user
+ * @param isCreate
+ * @throws GitBlitException
+ */
+ void updateUserModel(String username, UserModel user, boolean isCreate) throws GitBlitException;
+
+ /**
+ * Updates the TeamModel object for the specified name.
+ *
+ * @param teamname
+ * @param team
+ * @param isCreate
+ */
+ void updateTeamModel(String teamname, TeamModel team, boolean isCreate) throws GitBlitException;
+
+ /**
+ * Creates a personal fork of the specified repository. The clone is view
+ * restricted by default and the owner of the source repository is given
+ * access to the clone.
+ *
+ * @param repository
+ * @param user
+ * @return the repository model of the fork, if successful
+ * @throws GitBlitException
+ */
+ RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException;
+
+ /**
+ * Returns the list of custom client applications to be used for the
+ * repository url panel;
+ *
+ * @return a collection of client applications
+ */
+ Collection<GitClientApplication> getClientApplications();
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.manager;
+
+import java.util.Collection;
+
+public interface INotificationManager {
+
+ /**
+ * Notify the administrators by email.
+ *
+ * @param subject
+ * @param message
+ */
+ void sendMailToAdministrators(String subject, String message);
+
+ /**
+ * Notify users by email of something.
+ *
+ * @param subject
+ * @param message
+ * @param toAddresses
+ */
+ void sendMail(String subject, String message, Collection<String> toAddresses);
+
+ /**
+ * Notify users by email of something.
+ *
+ * @param subject
+ * @param message
+ * @param toAddresses
+ */
+ void sendMail(String subject, String message, String... toAddresses);
+
+ /**
+ * Notify users by email of something.
+ *
+ * @param subject
+ * @param message
+ * @param toAddresses
+ */
+ void sendHtmlMail(String subject, String message, Collection<String> toAddresses);
+
+ /**
+ * Notify users by email of something.
+ *
+ * @param subject
+ * @param message
+ * @param toAddresses
+ */
+ void sendHtmlMail(String subject, String message, String... toAddresses);
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.manager;
+
+import java.util.List;
+
+import com.gitblit.models.ProjectModel;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.UserModel;
+
+public interface IProjectManager {
+
+ /**
+ * Returns a list of project models for the user.
+ *
+ * @param user
+ * @param includeUsers
+ * @return list of projects that are accessible to the user
+ */
+ List<ProjectModel> getProjectModels(UserModel user, boolean includeUsers);
+
+ /**
+ * Returns the project model for the specified user.
+ *
+ * @param name
+ * @param user
+ * @return a project model, or null if it does not exist
+ */
+ ProjectModel getProjectModel(String name, UserModel user);
+
+ /**
+ * Returns a project model for the Gitblit/system user.
+ *
+ * @param name a project name
+ * @return a project model or null if the project does not exist
+ */
+ ProjectModel getProjectModel(String name);
+
+ /**
+ * Returns the list of project models that are referenced by the supplied
+ * repository model list. This is an alternative method exists to ensure
+ * Gitblit does not call getRepositoryModels(UserModel) twice in a request.
+ *
+ * @param repositoryModels
+ * @param includeUsers
+ * @return a list of project models
+ */
+ List<ProjectModel> getProjectModels(List<RepositoryModel> repositoryModels, boolean includeUsers);
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.manager;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import org.eclipse.jgit.lib.Repository;
+
+import com.gitblit.GitBlitException;
+import com.gitblit.models.ForkModel;
+import com.gitblit.models.Metric;
+import com.gitblit.models.RegistrantAccessPermission;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.SearchResult;
+import com.gitblit.models.UserModel;
+
+public interface IRepositoryManager {
+
+ /**
+ * Returns the path of the repositories folder. This method checks to see if
+ * Gitblit is running on a cloud service and may return an adjusted path.
+ *
+ * @return the repositories folder path
+ */
+ File getRepositoriesFolder();
+
+ /**
+ * Returns the path of the hooks folder. This method checks to see if
+ * Gitblit is running on a cloud service and may return an adjusted path.
+ *
+ * @return the Groovy hook scripts folder path
+ */
+ File getHooksFolder();
+
+ /**
+ * Returns the path of the grapes folder. This method checks to see if
+ * Gitblit is running on a cloud service and may return an adjusted path.
+ *
+ * @return the Groovy grapes folder path
+ */
+ File getGrapesFolder();
+
+ /**
+ * Returns the most recent change date of any repository served by Gitblit.
+ *
+ * @return a date
+ */
+ Date getLastActivityDate();
+
+ /**
+ * Returns the effective list of permissions for this user, taking into account
+ * team memberships, ownerships.
+ *
+ * @param user
+ * @return the effective list of permissions for the user
+ */
+ List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user);
+
+ /**
+ * Returns the list of users and their access permissions for the specified
+ * repository including permission source information such as the team or
+ * regular expression which sets the permission.
+ *
+ * @param repository
+ * @return a list of RegistrantAccessPermissions
+ */
+ List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository);
+
+ /**
+ * Sets the access permissions to the specified repository for the specified users.
+ *
+ * @param repository
+ * @param permissions
+ * @return true if the user models have been updated
+ */
+ boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions);
+
+ /**
+ * Returns the list of all users who have an explicit access permission
+ * for the specified repository.
+ *
+ * @see IUserService.getUsernamesForRepositoryRole(String)
+ * @param repository
+ * @return list of all usernames that have an access permission for the repository
+ */
+ List<String> getRepositoryUsers(RepositoryModel repository);
+
+ /**
+ * Returns the list of teams and their access permissions for the specified
+ * repository including the source of the permission such as the admin flag
+ * or a regular expression.
+ *
+ * @param repository
+ * @return a list of RegistrantAccessPermissions
+ */
+ List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository);
+
+ /**
+ * Sets the access permissions to the specified repository for the specified teams.
+ *
+ * @param repository
+ * @param permissions
+ * @return true if the team models have been updated
+ */
+ boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions);
+
+ /**
+ * Returns the list of all teams who have an explicit access permission for
+ * the specified repository.
+ *
+ * @see IUserService.getTeamnamesForRepositoryRole(String)
+ * @param repository
+ * @return list of all teamnames with explicit access permissions to the repository
+ */
+ List<String> getRepositoryTeams(RepositoryModel repository);
+
+ /**
+ * Adds the repository to the list of cached repositories if Gitblit is
+ * configured to cache the repository list.
+ *
+ * @param model
+ */
+ void addToCachedRepositoryList(RepositoryModel model);
+
+ /**
+ * Resets the repository list cache.
+ *
+ */
+ void resetRepositoryListCache();
+
+ /**
+ * Returns the list of all repositories available to Gitblit. This method
+ * does not consider user access permissions.
+ *
+ * @return list of all repositories
+ */
+ List<String> getRepositoryList();
+
+ /**
+ * Returns the JGit repository for the specified name.
+ *
+ * @param repositoryName
+ * @return repository or null
+ */
+ Repository getRepository(String repositoryName);
+
+ /**
+ * Returns the JGit repository for the specified name.
+ *
+ * @param repositoryName
+ * @param logError
+ * @return repository or null
+ */
+ Repository getRepository(String repositoryName, boolean logError);
+
+ /**
+ * Returns the list of repository models that are accessible to the user.
+ *
+ * @param user
+ * @return list of repository models accessible to user
+ */
+ List<RepositoryModel> getRepositoryModels(UserModel user);
+
+ /**
+ * Returns a repository model if the repository exists and the user may
+ * access the repository.
+ *
+ * @param user
+ * @param repositoryName
+ * @return repository model or null
+ */
+ RepositoryModel getRepositoryModel(UserModel user, String repositoryName);
+
+ /**
+ * Returns the repository model for the specified repository. This method
+ * does not consider user access permissions.
+ *
+ * @param repositoryName
+ * @return repository model or null
+ */
+ RepositoryModel getRepositoryModel(String repositoryName);
+
+ /**
+ * Returns the star count of the repository.
+ *
+ * @param repository
+ * @return the star count
+ */
+ long getStarCount(RepositoryModel repository);
+
+ /**
+ * Determines if this server has the requested repository.
+ *
+ * @param n
+ * @return true if the repository exists
+ */
+ boolean hasRepository(String repositoryName);
+
+ /**
+ * Determines if this server has the requested repository.
+ *
+ * @param n
+ * @param caseInsensitive
+ * @return true if the repository exists
+ */
+ boolean hasRepository(String repositoryName, boolean caseSensitiveCheck);
+
+ /**
+ * Determines if the specified user has a fork of the specified origin
+ * repository.
+ *
+ * @param username
+ * @param origin
+ * @return true the if the user has a fork
+ */
+ boolean hasFork(String username, String origin);
+
+ /**
+ * Gets the name of a user's fork of the specified origin
+ * repository.
+ *
+ * @param username
+ * @param origin
+ * @return the name of the user's fork, null otherwise
+ */
+ String getFork(String username, String origin);
+
+ /**
+ * Returns the fork network for a repository by traversing up the fork graph
+ * to discover the root and then down through all children of the root node.
+ *
+ * @param repository
+ * @return a ForkModel
+ */
+ ForkModel getForkNetwork(String repository);
+
+ /**
+ * Updates the last changed fields and optionally calculates the size of the
+ * repository. Gitblit caches the repository sizes to reduce the performance
+ * penalty of recursive calculation. The cache is updated if the repository
+ * has been changed since the last calculation.
+ *
+ * @param model
+ * @return size in bytes of the repository
+ */
+ long updateLastChangeFields(Repository r, RepositoryModel model);
+
+ /**
+ * Returns the metrics for the default branch of the specified repository.
+ * This method builds a metrics cache. The cache is updated if the
+ * repository is updated. A new copy of the metrics list is returned on each
+ * call so that modifications to the list are non-destructive.
+ *
+ * @param model
+ * @param repository
+ * @return a new array list of metrics
+ */
+ List<Metric> getRepositoryDefaultMetrics(RepositoryModel model, Repository repository);
+
+ /**
+ * Creates/updates the repository model keyed by reopsitoryName. Saves all
+ * repository settings in .git/config. This method allows for renaming
+ * repositories and will update user access permissions accordingly.
+ *
+ * All repositories created by this method are bare and automatically have
+ * .git appended to their names, which is the standard convention for bare
+ * repositories.
+ *
+ * @param repositoryName
+ * @param repository
+ * @param isCreate
+ * @throws GitBlitException
+ */
+ void updateRepositoryModel(String repositoryName, RepositoryModel repository, boolean isCreate)
+ throws GitBlitException;
+
+ /**
+ * Updates the Gitblit configuration for the specified repository.
+ *
+ * @param r
+ * the Git repository
+ * @param repository
+ * the Gitblit repository model
+ */
+ void updateConfiguration(Repository r, RepositoryModel repository);
+
+ /**
+ * Deletes the repository from the file system and removes the repository
+ * permission from all repository users.
+ *
+ * @param model
+ * @return true if successful
+ */
+ boolean deleteRepositoryModel(RepositoryModel model);
+
+ /**
+ * Deletes the repository from the file system and removes the repository
+ * permission from all repository users.
+ *
+ * @param repositoryName
+ * @return true if successful
+ */
+ boolean deleteRepository(String repositoryName);
+
+ /**
+ * Returns the list of all Groovy push hook scripts. Script files must have
+ * .groovy extension
+ *
+ * @return list of available hook scripts
+ */
+ List<String> getAllScripts();
+
+ /**
+ * Returns the list of pre-receive scripts the repository inherited from the
+ * global settings and team affiliations.
+ *
+ * @param repository
+ * if null only the globally specified scripts are returned
+ * @return a list of scripts
+ */
+ List<String> getPreReceiveScriptsInherited(RepositoryModel repository);
+
+ /**
+ * Returns the list of all available Groovy pre-receive push hook scripts
+ * that are not already inherited by the repository. Script files must have
+ * .groovy extension
+ *
+ * @param repository
+ * optional parameter
+ * @return list of available hook scripts
+ */
+ List<String> getPreReceiveScriptsUnused(RepositoryModel repository);
+
+ /**
+ * Returns the list of post-receive scripts the repository inherited from
+ * the global settings and team affiliations.
+ *
+ * @param repository
+ * if null only the globally specified scripts are returned
+ * @return a list of scripts
+ */
+ List<String> getPostReceiveScriptsInherited(RepositoryModel repository);
+
+ /**
+ * Returns the list of unused Groovy post-receive push hook scripts that are
+ * not already inherited by the repository. Script files must have .groovy
+ * extension
+ *
+ * @param repository
+ * optional parameter
+ * @return list of available hook scripts
+ */
+ List<String> getPostReceiveScriptsUnused(RepositoryModel repository);
+
+ /**
+ * Search the specified repositories using the Lucene query.
+ *
+ * @param query
+ * @param page
+ * @param pageSize
+ * @param repositories
+ * @return
+ */
+ List<SearchResult> search(String query, int page, int pageSize, List<String> repositories);
+
+ /**
+ *
+ * @return true if we are running the gc executor
+ */
+ boolean isCollectingGarbage();
+
+ /**
+ * Returns true if Gitblit is actively collecting garbage in this repository.
+ *
+ * @param repositoryName
+ * @return true if actively collecting garbage
+ */
+ boolean isCollectingGarbage(String repositoryName);
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.manager;
+
+import java.io.File;
+import java.util.Date;
+import java.util.Map;
+import java.util.TimeZone;
+
+import com.gitblit.IStoredSettings;
+import com.gitblit.models.ServerSettings;
+import com.gitblit.models.ServerStatus;
+
+public interface IRuntimeManager {
+
+ void setBaseFolder(File folder);
+
+ File getBaseFolder();
+
+ /**
+ * Returns the preferred timezone for the Gitblit instance.
+ *
+ * @return a timezone
+ */
+ TimeZone getTimezone();
+
+ /**
+ * Determine if this Gitblit instance is actively serving git repositories
+ * or if it is merely a repository viewer.
+ *
+ * @return true if Gitblit is serving repositories
+ */
+ boolean isServingRepositories();
+
+ /**
+ * Determine if this Gitblit instance is running in debug mode
+ *
+ * @return true if Gitblit is running in debug mode
+ */
+ boolean isDebugMode();
+
+ /**
+ * Returns the boot date of the Gitblit server.
+ *
+ * @return the boot date of Gitblit
+ */
+ Date getBootDate();
+
+ ServerStatus getStatus();
+
+ /**
+ * Returns the descriptions/comments of the Gitblit config settings.
+ *
+ * @return SettingsModel
+ */
+ ServerSettings getSettingsModel();
+
+ /**
+ * Returns the file object for the specified configuration key.
+ *
+ * @return the file
+ */
+ File getFileOrFolder(String key, String defaultFileOrFolder);
+
+ /**
+ * Returns the file object which may have it's base-path determined by
+ * environment variables for running on a cloud hosting service. All Gitblit
+ * file or folder retrievals are (at least initially) funneled through this
+ * method so it is the correct point to globally override/alter filesystem
+ * access based on environment or some other indicator.
+ *
+ * @return the file
+ */
+ File getFileOrFolder(String fileOrFolder);
+
+ /**
+ * Returns the runtime settings.
+ *
+ * @return settings
+ */
+ IStoredSettings getSettings();
+
+ /**
+ * Updates the runtime settings.
+ *
+ * @param settings
+ * @return true if the update succeeded
+ */
+ boolean updateSettings(Map<String, String> updatedSettings);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.manager;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.gitblit.models.UserModel;
+
+public interface ISessionManager {
+
+ /**
+ * Authenticate a user based on HTTP request parameters.
+ *
+ * Authentication by X509Certificate is tried first and then by cookie.
+ *
+ * @param httpRequest
+ * @return a user object or null
+ */
+ UserModel authenticate(HttpServletRequest httpRequest);
+
+ /**
+ * Authenticate a user based on HTTP request parameters.
+ *
+ * Authentication by X509Certificate, servlet container principal, cookie,
+ * and BASIC header.
+ *
+ * @param httpRequest
+ * @param requiresCertificate
+ * @return a user object or null
+ */
+ UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate);
+
+ UserModel authenticate(String username, char[] password);
+
+ /**
+ * Sets a cookie for the specified user.
+ *
+ * @param response
+ * @param user
+ */
+ void setCookie(HttpServletResponse response, UserModel user);
+
+ /**
+ * Logout a user.
+ *
+ * @param user
+ */
+ void logout(HttpServletResponse response, UserModel user);
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.manager;
+
+import java.util.Collection;
+import java.util.List;
+
+import com.gitblit.models.TeamModel;
+import com.gitblit.models.UserModel;
+
+public interface IUserManager {
+
+ boolean supportsAddUser();
+
+ /**
+ * Does the user service support changes to credentials?
+ *
+ * @return true or false
+ * @since 1.0.0
+ */
+ boolean supportsCredentialChanges(UserModel user);
+
+ /**
+ * Returns true if the user's display name can be changed.
+ *
+ * @param user
+ * @return true if the user service supports display name changes
+ */
+ boolean supportsDisplayNameChanges(UserModel user);
+
+ /**
+ * Returns true if the user's email address can be changed.
+ *
+ * @param user
+ * @return true if the user service supports email address changes
+ */
+ boolean supportsEmailAddressChanges(UserModel user);
+
+ /**
+ * Returns true if the user's team memberships can be changed.
+ *
+ * @param user
+ * @return true if the user service supports team membership changes
+ */
+ boolean supportsTeamMembershipChanges(UserModel user);
+
+ /**
+ * Does the user service support cookie authentication?
+ *
+ * @return true or false
+ */
+ boolean supportsCookies();
+
+ /**
+ * Returns the cookie value for the specified user.
+ *
+ * @param model
+ * @return cookie value
+ */
+ String getCookie(UserModel model);
+
+ /**
+ * Authenticate a user based on their cookie.
+ *
+ * @param cookie
+ * @return a user object or null
+ */
+ UserModel authenticate(char[] cookie);
+
+ /**
+ * Authenticate a user based on a username and password.
+ *
+ * @param username
+ * @param password
+ * @return a user object or null
+ */
+ UserModel authenticate(String username, char[] password);
+
+ /**
+ * Logout a user.
+ *
+ * @param user
+ */
+ void logout(UserModel user);
+
+ /**
+ * Retrieve the user object for the specified username.
+ *
+ * @param username
+ * @return a user object or null
+ */
+ UserModel getUserModel(String username);
+
+ /**
+ * Updates/writes a complete user object.
+ *
+ * @param model
+ * @return true if update is successful
+ */
+ boolean updateUserModel(UserModel model);
+
+ /**
+ * Updates/writes all specified user objects.
+ *
+ * @param models a list of user models
+ * @return true if update is successful
+ * @since 1.2.0
+ */
+ boolean updateUserModels(Collection<UserModel> models);
+
+ /**
+ * Adds/updates a user object keyed by username. This method allows for
+ * renaming a user.
+ *
+ * @param username
+ * the old username
+ * @param model
+ * the user object to use for username
+ * @return true if update is successful
+ */
+ boolean updateUserModel(String username, UserModel model);
+
+ /**
+ * Deletes the user object from the user service.
+ *
+ * @param model
+ * @return true if successful
+ */
+ boolean deleteUserModel(UserModel model);
+
+ /**
+ * Delete the user object with the specified username
+ *
+ * @param username
+ * @return true if successful
+ */
+ boolean deleteUser(String username);
+
+ /**
+ * Returns the list of all users available to the login service.
+ *
+ * @return list of all usernames
+ */
+ List<String> getAllUsernames();
+
+ /**
+ * Returns the list of all users available to the login service.
+ *
+ * @return list of all users
+ * @since 0.8.0
+ */
+ List<UserModel> getAllUsers();
+
+ /**
+ * Returns the list of all teams available to the login service.
+ *
+ * @return list of all teams
+ * @since 0.8.0
+ */
+ List<String> getAllTeamNames();
+
+ /**
+ * Returns the list of all teams available to the login service.
+ *
+ * @return list of all teams
+ * @since 0.8.0
+ */
+ List<TeamModel> getAllTeams();
+
+ /**
+ * Returns the list of all users who are allowed to bypass the access
+ * restriction placed on the specified repository.
+ *
+ * @param role
+ * the repository name
+ * @return list of all usernames that can bypass the access restriction
+ * @since 0.8.0
+ */
+ List<String> getTeamnamesForRepositoryRole(String role);
+
+ /**
+ * Retrieve the team object for the specified team name.
+ *
+ * @param teamname
+ * @return a team object or null
+ * @since 0.8.0
+ */
+ TeamModel getTeamModel(String teamname);
+
+ /**
+ * Updates/writes a complete team object.
+ *
+ * @param model
+ * @return true if update is successful
+ * @since 0.8.0
+ */
+ boolean updateTeamModel(TeamModel model);
+
+ /**
+ * Updates/writes all specified team objects.
+ *
+ * @param models a list of team models
+ * @return true if update is successful
+ * @since 1.2.0
+ */
+ boolean updateTeamModels(Collection<TeamModel> models);
+
+ /**
+ * Updates/writes and replaces a complete team object keyed by teamname.
+ * This method allows for renaming a team.
+ *
+ * @param teamname
+ * the old teamname
+ * @param model
+ * the team object to use for teamname
+ * @return true if update is successful
+ * @since 0.8.0
+ */
+ boolean updateTeamModel(String teamname, TeamModel model);
+
+ /**
+ * Deletes the team object from the user service.
+ *
+ * @param model
+ * @return true if successful
+ * @since 0.8.0
+ */
+ boolean deleteTeamModel(TeamModel model);
+
+ /**
+ * Delete the team object with the specified teamname
+ *
+ * @param teamname
+ * @return true if successful
+ * @since 0.8.0
+ */
+ boolean deleteTeam(String teamname);
+
+ /**
+ * Returns the list of all users who are allowed to bypass the access
+ * restriction placed on the specified repository.
+ *
+ * @param role
+ * the repository name
+ * @return list of all usernames that can bypass the access restriction
+ * @since 0.8.0
+ */
+ List<String> getUsernamesForRepositoryRole(String role);
+
+ /**
+ * Renames a repository role.
+ *
+ * @param oldRole
+ * @param newRole
+ * @return true if successful
+ */
+ boolean renameRepositoryRole(String oldRole, String newRole);
+
+ /**
+ * Removes a repository role from all users.
+ *
+ * @param role
+ * @return true if successful
+ */
+ boolean deleteRepositoryRole(String role);
+
+}
\ No newline at end of file
import org.eclipse.jgit.lib.Constants;\r
import org.eclipse.jgit.lib.Repository;\r
\r
-import com.gitblit.GitBlit;\r
+import com.gitblit.IStoredSettings;\r
import com.gitblit.Keys;\r
+import com.gitblit.manager.IRepositoryManager;\r
import com.gitblit.models.Activity;\r
import com.gitblit.models.GravatarProfile;\r
import com.gitblit.models.RefModel;\r
* Gets the recent activity from the repositories for the last daysBack days\r
* on the specified branch.\r
*\r
+ * @param settings\r
+ * the runtime settings\r
+ * @param repositoryManager\r
+ * the repository manager\r
* @param models\r
* the list of repositories to query\r
* @param daysBack\r
* the timezone for aggregating commits\r
* @return\r
*/\r
- public static List<Activity> getRecentActivity(List<RepositoryModel> models, int daysBack,\r
- String objectId, TimeZone timezone) {\r
+ public static List<Activity> getRecentActivity(\r
+ IStoredSettings settings,\r
+ IRepositoryManager repositoryManager,\r
+ List<RepositoryModel> models,\r
+ int daysBack,\r
+ String objectId,\r
+ TimeZone timezone) {\r
\r
// Activity panel shows last daysBack of activity across all\r
// repositories.\r
\r
// aggregate author exclusions\r
Set<String> authorExclusions = new TreeSet<String>();\r
- authorExclusions.addAll(GitBlit.getStrings(Keys.web.metricAuthorExclusions));\r
+ authorExclusions.addAll(settings.getStrings(Keys.web.metricAuthorExclusions));\r
for (RepositoryModel model : models) {\r
if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {\r
authorExclusions.addAll(model.metricAuthorExclusions);\r
if (model.isCollectingGarbage) {\r
continue;\r
}\r
- Repository repository = GitBlit.self()\r
- .getRepository(model.name);\r
+ Repository repository = repositoryManager.getRepository(model.name);\r
List<String> branches = new ArrayList<String>();\r
if (StringUtils.isEmpty(objectId)) {\r
for (RefModel local : JGitUtils.getLocalBranches(\r
import com.gitblit.GitBlit;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
+import com.gitblit.manager.IFederationManager;
+import com.gitblit.manager.IGitblitManager;
+import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IProjectManager;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
+import com.gitblit.manager.IUserManager;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.pages.ActivityPage;
import com.gitblit.wicket.pages.BlamePage;
public void init() {
super.init();
- settings = GitBlit.getSettings();
+ settings = runtime().getSettings();
// Setup page authorization mechanism
boolean useAuthentication = settings.getBoolean(Keys.web.authenticateViewPages, false)
* @return true if Gitblit is running in debug mode
*/
public boolean isDebugMode() {
- return GitBlit.isDebugMode();
+ return runtime().isDebugMode();
}
/*
* step towards modularization across multiple commits.
*/
public Date getBootDate() {
- return GitBlit.getBootDate();
+ return runtime().getBootDate();
}
public Date getLastActivityDate() {
- return GitBlit.getLastActivityDate();
+ return repositories().getLastActivityDate();
}
- public GitBlit runtime() {
- return GitBlit.self();
+ public IRuntimeManager runtime() {
+ return GitBlit.getManager(IRuntimeManager.class);
}
- public GitBlit mail() {
- return GitBlit.self();
+ public INotificationManager notifier() {
+ return GitBlit.getManager(INotificationManager.class);
}
- public GitBlit users() {
- return GitBlit.self();
+ public IUserManager users() {
+ return GitBlit.getManager(IUserManager.class);
}
- public GitBlit session() {
- return GitBlit.self();
+ public ISessionManager session() {
+ return GitBlit.getManager(ISessionManager.class);
}
- public GitBlit repositories() {
- return GitBlit.self();
+ public IRepositoryManager repositories() {
+ return GitBlit.getManager(IRepositoryManager.class);
}
- public GitBlit projects() {
- return GitBlit.self();
+ public IProjectManager projects() {
+ return GitBlit.getManager(IProjectManager.class);
}
- public GitBlit federation() {
- return GitBlit.self();
+ public IFederationManager federation() {
+ return GitBlit.getManager(IFederationManager.class);
}
- public GitBlit gitblit() {
- return GitBlit.self();
+ public IGitblitManager gitblit() {
+ return GitBlit.getManager(IGitblitManager.class);
}
public TimeZone getTimezone() {
- return GitBlit.getTimezone();
+ return runtime().getTimezone();
}
@Override
import org.eclipse.jgit.revwalk.RevCommit;\r
\r
import com.gitblit.GitBlit;\r
+import com.gitblit.IStoredSettings;\r
import com.gitblit.Keys;\r
+import com.gitblit.manager.IProjectManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
import com.gitblit.models.ProjectModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.utils.JGitUtils;\r
commitId = servletRequest.getParameter("h");\r
}\r
\r
- repo = repo.replace("%2f", "/").replace("%2F", "/").replace(GitBlit.getChar(Keys.web.forwardSlashCharacter, '/'), '/');\r
+ IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+ IStoredSettings settings = runtimeManager.getSettings();\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ IProjectManager projectManager = GitBlit.getManager(IProjectManager.class);\r
+\r
+ repo = repo.replace("%2f", "/").replace("%2F", "/").replace(settings.getChar(Keys.web.forwardSlashCharacter, '/'), '/');\r
\r
GitBlitWebApp app = (GitBlitWebApp) getWebApplication();\r
- int expires = GitBlit.getInteger(Keys.web.pageCacheExpires, 0);\r
+ int expires = settings.getInteger(Keys.web.pageCacheExpires, 0);\r
if (!StringUtils.isEmpty(page) && app.isCacheablePage(page) && expires > 0) {\r
// page can be cached by the browser\r
CacheControl cacheControl = app.getCacheControl(page);\r
- Date bootDate = GitBlit.getBootDate();\r
+ Date bootDate = runtimeManager.getBootDate();\r
switch (cacheControl.value()) {\r
case ACTIVITY:\r
// returns the last activity date of the server\r
- Date activityDate = GitBlit.getLastActivityDate();\r
+ Date activityDate = repositoryManager.getLastActivityDate();\r
if (activityDate != null) {\r
return activityDate.after(bootDate) ? activityDate.getTime() : bootDate.getTime();\r
}\r
return bootDate.getTime();\r
case PROJECT:\r
// return the latest change date for the project OR the boot date\r
- ProjectModel project = GitBlit.self().getProjectModel(StringUtils.getRootPath(repo));\r
+ ProjectModel project = projectManager.getProjectModel(StringUtils.getRootPath(repo));\r
if (project != null) {\r
return project.lastChange.after(bootDate) ? project.lastChange.getTime() : bootDate.getTime();\r
}\r
case REPOSITORY:\r
// return the lastest change date for the repository OR the boot\r
// date, whichever is latest\r
- RepositoryModel repository = GitBlit.self().getRepositoryModel(repo);\r
+ RepositoryModel repository = repositoryManager.getRepositoryModel(repo);\r
if (repository != null && repository.lastChange != null) {\r
return repository.lastChange.after(bootDate) ? repository.lastChange.getTime() : bootDate.getTime();\r
}\r
Repository r = null;\r
try {\r
// return the timestamp of the associated commit\r
- r = GitBlit.self().getRepository(repo);\r
+ r = repositoryManager.getRepository(repo);\r
if (r != null) {\r
RevCommit commit = JGitUtils.getCommit(r, commitId);\r
if (commit != null) {\r
\r
// determine repositories to view and retrieve the activity\r
List<RepositoryModel> models = getRepositories(params);\r
- List<Activity> recentActivity = ActivityUtils.getRecentActivity(models,\r
- daysBack, objectId, getTimeZone());\r
+ List<Activity> recentActivity = ActivityUtils.getRecentActivity(\r
+ app().settings(),\r
+ app().repositories(),\r
+ models,\r
+ daysBack,\r
+ objectId,\r
+ getTimeZone());\r
\r
String headerPattern;\r
if (daysBack == 1) {\r
\r
user.password = password;\r
try {\r
- app().users().updateUserModel(user.username, user, false);\r
+ app().gitblit().updateUserModel(user.username, user, false);\r
if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) {\r
WebResponse response = (WebResponse) getRequestCycle().getResponse();\r
- app().session().setCookie(response, user);\r
+ app().session().setCookie(response.getHttpServletResponse(), user);\r
}\r
} catch (GitBlitException e) {\r
error(e.getMessage());\r
final RegistrantPermissionsPanel usersPalette = new RegistrantPermissionsPanel("users",\r
RegistrantType.USER, app().users().getAllUsernames(), repositoryUsers, getAccessPermissions());\r
final RegistrantPermissionsPanel teamsPalette = new RegistrantPermissionsPanel("teams",\r
- RegistrantType.TEAM, app().users().getAllTeamnames(), repositoryTeams, getAccessPermissions());\r
+ RegistrantType.TEAM, app().users().getAllTeamNames(), repositoryTeams, getAccessPermissions());\r
\r
// owners palette\r
List<String> owners = new ArrayList<String>(repositoryModel.owners);\r
teamModel.postReceiveScripts.addAll(postReceiveScripts);\r
\r
try {\r
- app().users().updateTeamModel(oldName, teamModel, isCreate);\r
+ app().gitblit().updateTeamModel(oldName, teamModel, isCreate);\r
} catch (GitBlitException e) {\r
error(e.getMessage());\r
return;\r
\r
final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(\r
new ArrayList<String>(userTeams)), new CollectionModel<String>(app().users()\r
- .getAllTeamnames()), new StringChoiceRenderer(), 10, false);\r
+ .getAllTeamNames()), new StringChoiceRenderer(), 10, false);\r
Form<UserModel> form = new Form<UserModel>("editForm", model) {\r
\r
private static final long serialVersionUID = 1L;\r
}\r
\r
try {\r
- app().users().updateUserModel(oldName, userModel, isCreate);\r
+ app().gitblit().updateUserModel(oldName, userModel, isCreate);\r
} catch (GitBlitException e) {\r
error(e.getMessage());\r
return;\r
}\r
\r
HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();\r
- List<RepositoryUrl> repositoryUrls = app().repositories().getRepositoryUrls(req, user, repository);\r
+ List<RepositoryUrl> repositoryUrls = app().gitblit().getRepositoryUrls(req, user, repository);\r
RepositoryUrl primaryUrl = repositoryUrls.size() == 0 ? null : repositoryUrls.get(0);\r
String url = primaryUrl != null ? primaryUrl.url : "";\r
\r
super();\r
GitBlitWebSession session = GitBlitWebSession.get();\r
UserModel user = session.getUser();\r
- app().session().setCookie((WebResponse) getResponse(), null);\r
- app().session().logout(user);\r
+ app().session().logout(((WebResponse) getResponse()).getHttpServletResponse(), user);\r
session.invalidate();\r
\r
/*\r
UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(getRepositoryModel().name);\r
prefs.starred = star;\r
try {\r
- app().users().updateUserModel(user.username, user, false);\r
+ app().gitblit().updateUserModel(user.username, user, false);\r
} catch (GitBlitException e) {\r
logger.error("Failed to update user " + user.username, e);\r
error(getString("gb.failedToUpdateUser"), false);\r
// Set Cookie\r
if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) {\r
WebResponse response = (WebResponse) getRequestCycle().getResponse();\r
- app().session().setCookie(response, user);\r
+ app().session().setCookie(response.getHttpServletResponse(), user);\r
}\r
\r
if (!session.continueRequest()) {\r
\r
// Set Cookie\r
WebResponse response = (WebResponse) getRequestCycle().getResponse();\r
- app().session().setCookie(response, user);\r
+ app().session().setCookie(response.getHttpServletResponse(), user);\r
\r
session.continueRequest();\r
}\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-\r
import java.io.IOException;\r
\r
import org.junit.Test;\r
import com.gitblit.models.GravatarProfile;\r
import com.gitblit.utils.ActivityUtils;\r
\r
-public class ActivityTest {\r
+public class ActivityTest extends GitblitUnitTest {\r
\r
@Test\r
public void testGravatarProfile() throws IOException {\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.HashSet;\r
\r
import com.gitblit.utils.ArrayUtils;\r
\r
-public class ArrayUtilsTest {\r
+public class ArrayUtilsTest extends GitblitUnitTest {\r
\r
@Test\r
public void testArrays() {\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-\r
import org.junit.Test;\r
\r
import com.gitblit.utils.Base64;\r
\r
-public class Base64Test {\r
+public class Base64Test extends GitblitUnitTest {\r
\r
@Test\r
public void testBase64() {\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-\r
import java.util.Locale;\r
\r
import org.junit.Test;\r
\r
import com.gitblit.utils.ByteFormat;\r
\r
-public class ByteFormatTest {\r
+public class ByteFormatTest extends GitblitUnitTest {\r
\r
@Test\r
public void testByteFormat() throws Exception {\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.util.List;\r
\r
import org.eclipse.jgit.lib.Repository;\r
import com.gitblit.utils.DiffUtils.DiffOutputType;\r
import com.gitblit.utils.JGitUtils;\r
\r
-public class DiffUtilsTest {\r
+public class DiffUtilsTest extends GitblitUnitTest {\r
\r
@Test\r
public void testDiffOutputTypes() throws Exception {\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-\r
import java.text.MessageFormat;\r
import java.util.Date;\r
import java.util.Map;\r
import com.gitblit.fanout.FanoutService;\r
import com.gitblit.fanout.FanoutSocketService;\r
\r
-public class FanoutServiceTest {\r
+public class FanoutServiceTest extends GitblitUnitTest {\r
\r
int fanoutPort = FanoutService.DEFAULT_PORT;\r
\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.util.Date;\r
import java.util.HashMap;\r
import java.util.List;\r
import com.gitblit.utils.JsonUtils;\r
import com.gitblit.utils.RpcUtils;\r
\r
-public class FederationTests {\r
+public class FederationTests extends GitblitUnitTest {\r
\r
String url = GitBlitSuite.url;\r
String account = GitBlitSuite.account;\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.io.File;\r
\r
import org.junit.Test;\r
\r
import com.gitblit.utils.FileUtils;\r
\r
-public class FileUtilsTest {\r
+public class FileUtilsTest extends GitblitUnitTest {\r
\r
@Test\r
public void testReadContent() throws Exception {\r
import com.gitblit.GitBlit;\r
import com.gitblit.GitBlitException;\r
import com.gitblit.GitBlitServer;\r
+import com.gitblit.manager.IRepositoryManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.utils.JGitUtils;\r
\r
\r
private static void showRemoteBranches(String repositoryName) {\r
try {\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);\r
model.showRemoteBranches = true;\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ repositoryManager.updateRepositoryModel(model.name, model, false);\r
} catch (GitBlitException g) {\r
g.printStackTrace();\r
}\r
\r
private static void automaticallyTagBranchTips(String repositoryName) {\r
try {\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+ RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);\r
model.useIncrementalPushTags = true;\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ repositoryManager.updateRepositoryModel(model.name, model, false);\r
} catch (GitBlitException g) {\r
g.printStackTrace();\r
}\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.util.List;\r
\r
import org.eclipse.jgit.lib.Repository;\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.FileSettings;\r
-import com.gitblit.GitBlit;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
\r
-public class GitBlitTest {\r
+public class GitBlitTest extends GitblitUnitTest {\r
\r
@Test\r
public void testRepositoryModel() throws Exception {\r
- List<String> repositories = GitBlit.self().getRepositoryList();\r
+ List<String> repositories = repositories().getRepositoryList();\r
assertTrue("Repository list is empty!", repositories.size() > 0);\r
assertTrue(\r
"Missing Helloworld repository!",\r
repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory()\r
.getName()));\r
Repository r = GitBlitSuite.getHelloworldRepository();\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(r.getDirectory().getName());\r
+ RepositoryModel model = repositories().getRepositoryModel(r.getDirectory().getName());\r
assertTrue("Helloworld model is null!", model != null);\r
assertEquals(GitBlitSuite.getHelloworldRepository().getDirectory().getName(), model.name);\r
- assertTrue(GitBlit.self().updateLastChangeFields(r, model) > 22000L);\r
+ assertTrue(repositories().updateLastChangeFields(r, model) > 22000L);\r
r.close();\r
}\r
\r
@Test\r
public void testUserModel() throws Exception {\r
- List<String> users = GitBlit.self().getAllUsernames();\r
+ List<String> users = users().getAllUsernames();\r
assertTrue("No users found!", users.size() > 0);\r
assertTrue("Admin not found", users.contains("admin"));\r
- UserModel user = GitBlit.self().getUserModel("admin");\r
+ UserModel user = users().getUserModel("admin");\r
assertEquals("admin", user.toString());\r
assertTrue("Admin missing #admin role!", user.canAdmin);\r
user.canAdmin = false;\r
assertFalse("Admin should not have #admin!", user.canAdmin);\r
String repository = GitBlitSuite.getHelloworldRepository().getDirectory().getName();\r
- RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repository);\r
+ RepositoryModel repositoryModel = repositories().getRepositoryModel(repository);\r
repositoryModel.accessRestriction = AccessRestrictionType.VIEW;\r
assertFalse("Admin can still access repository!",\r
user.canView(repositoryModel));\r
user.addRepositoryPermission(repository);\r
assertTrue("Admin can't access repository!", user.canView(repositoryModel));\r
- assertEquals(GitBlit.self().getRepositoryModel(user, "pretend"), null);\r
- assertNotNull(GitBlit.self().getRepositoryModel(user, repository));\r
- assertTrue(GitBlit.self().getRepositoryModels(user).size() > 0);\r
+ assertEquals(repositories().getRepositoryModel(user, "pretend"), null);\r
+ assertNotNull(repositories().getRepositoryModel(user, repository));\r
+ assertTrue(repositories().getRepositoryModels(user).size() > 0);\r
}\r
\r
@Test\r
@Test\r
public void testGitblitSettings() throws Exception {\r
// These are already tested by above test method.\r
- assertTrue(GitBlit.getBoolean("missing", true));\r
- assertEquals("default", GitBlit.getString("missing", "default"));\r
- assertEquals(10, GitBlit.getInteger("missing", 10));\r
- assertEquals(5, GitBlit.getInteger("realm.userService", 5));\r
-\r
- assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));\r
- assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), GitBlit.getString("realm.userService", null));\r
- assertEquals(5, GitBlit.getInteger("realm.minPasswordLength", 0));\r
- List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");\r
+ assertTrue(settings().getBoolean("missing", true));\r
+ assertEquals("default", settings().getString("missing", "default"));\r
+ assertEquals(10, settings().getInteger("missing", 10));\r
+ assertEquals(5, settings().getInteger("realm.userService", 5));\r
+\r
+ assertTrue(settings().getBoolean("git.enableGitServlet", false));\r
+ assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), settings().getString("realm.userService", null));\r
+ assertEquals(5, settings().getInteger("realm.minPasswordLength", 0));\r
+ List<String> mdExtensions = settings().getStrings("web.markdownExtensions");\r
assertTrue(mdExtensions.size() > 0);\r
assertTrue(mdExtensions.contains("md"));\r
\r
- List<String> keys = GitBlit.getAllKeys("server");\r
+ List<String> keys = settings().getAllKeys("server");\r
assertTrue(keys.size() > 0);\r
assertTrue(keys.contains("server.httpsPort"));\r
\r
- assertTrue(GitBlit.getChar("web.forwardSlashCharacter", ' ') == '/');\r
- assertFalse(GitBlit.isDebugMode());\r
+ assertTrue(settings().getChar("web.forwardSlashCharacter", ' ') == '/');\r
+ assertFalse(runtime().isDebugMode());\r
}\r
\r
@Test\r
public void testAuthentication() throws Exception {\r
- assertTrue(GitBlit.self().authenticate("admin", "admin".toCharArray()) != null);\r
+ assertTrue(session().authenticate("admin", "admin".toCharArray()) != null);\r
}\r
\r
@Test\r
public void testRepositories() throws Exception {\r
- assertTrue(GitBlit.self().getRepository("missing") == null);\r
- assertTrue(GitBlit.self().getRepositoryModel("missing") == null);\r
+ assertTrue(repositories().getRepository("missing") == null);\r
+ assertTrue(repositories().getRepositoryModel("missing") == null);\r
}\r
}\r
*/
package com.gitblit.tests;
-import org.junit.Assert;
import org.junit.Test;
import com.gitblit.git.GitDaemon;
-public class GitDaemonStopTest extends Assert {
+public class GitDaemonStopTest extends GitblitUnitTest {
@Test
public void testGitDaemonStop() throws Exception {
import org.eclipse.jgit.transport.RemoteRefUpdate.Status;
import org.eclipse.jgit.util.FileUtils;
import org.junit.AfterClass;
-import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.AuthorizationControl;
-import com.gitblit.GitBlit;
import com.gitblit.models.RepositoryModel;
-public class GitDaemonTest extends Assert {
+public class GitDaemonTest extends GitblitUnitTest {
static File ticgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");
}
// set push restriction
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.PUSH;
model.authorizationControl = AuthorizationControl.NAMED;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
// restore anonymous repository access
model.accessRestriction = AccessRestrictionType.NONE;
model.authorizationControl = AuthorizationControl.NAMED;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
}
@Test
}
// restrict repository access
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.CLONE;
model.authorizationControl = AuthorizationControl.NAMED;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
// delete any existing working folder
boolean cloned = false;
// restore anonymous repository access
model.accessRestriction = AccessRestrictionType.NONE;
model.authorizationControl = AuthorizationControl.NAMED;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
}
@Test
}
// restore anonymous repository access
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.NONE;
model.authorizationControl = AuthorizationControl.NAMED;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
}
// restore anonymous repository access
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.PUSH;
model.authorizationControl = AuthorizationControl.NAMED;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
assertTrue(true);
// freeze repo
- RepositoryModel model = GitBlit.self().getRepositoryModel("test/jgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("test/jgit.git");
model.isFrozen = true;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
Git git = Git.open(jgitFolder);
File file = new File(jgitFolder, "TODO");
// unfreeze repo
model.isFrozen = false;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
results = git.push().setPushAll().call();
GitBlitSuite.close(git);
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.io.BufferedWriter;\r
import java.io.File;\r
import java.io.FileOutputStream;\r
import com.gitblit.Constants.AccessPermission;\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.Constants.AuthorizationControl;\r
-import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
import com.gitblit.models.RefLogEntry;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.RefLogUtils;\r
\r
-public class GitServletTest {\r
+public class GitServletTest extends GitblitUnitTest {\r
\r
static File ticgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");\r
\r
}\r
\r
private static void delete(UserModel user) {\r
- if (GitBlit.self().getUserModel(user.username) != null) {\r
- GitBlit.self().deleteUser(user.username);\r
+ if (users().getUserModel(user.username) != null) {\r
+ users().deleteUser(user.username);\r
}\r
}\r
\r
@Test\r
public void testBogusLoginClone() throws Exception {\r
// restrict repository access\r
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");\r
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");\r
model.accessRestriction = AccessRestrictionType.CLONE;\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
// delete any existing working folder\r
boolean cloned = false;\r
\r
// restore anonymous repository access\r
model.accessRestriction = AccessRestrictionType.NONE;\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
assertFalse("Bogus login cloned a repository?!", cloned);\r
}\r
@Test\r
public void testUnauthorizedLoginClone() throws Exception {\r
// restrict repository access\r
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");\r
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");\r
model.accessRestriction = AccessRestrictionType.CLONE;\r
model.authorizationControl = AuthorizationControl.NAMED;\r
UserModel user = new UserModel("james");\r
user.password = "james";\r
- GitBlit.self().updateUserModel(user.username, user, true);\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ gitblit().updateUserModel(user.username, user, true);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);\r
\r
\r
// switch to authenticated\r
model.authorizationControl = AuthorizationControl.AUTHENTICATED;\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
// try clone again\r
cloned = false;\r
// restore anonymous repository access\r
model.accessRestriction = AccessRestrictionType.NONE;\r
model.authorizationControl = AuthorizationControl.NAMED;\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
delete(user);\r
}\r
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);\r
}\r
\r
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");\r
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");\r
model.accessRestriction = AccessRestrictionType.NONE;\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
CloneCommand clone = Git.cloneRepository();\r
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));\r
assertTrue(true);\r
\r
// freeze repo\r
- RepositoryModel model = GitBlit.self().getRepositoryModel("test/jgit.git");\r
+ RepositoryModel model = repositories().getRepositoryModel("test/jgit.git");\r
model.isFrozen = true;\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
Git git = Git.open(jgitFolder);\r
File file = new File(jgitFolder, "TODO");\r
\r
// unfreeze repo\r
model.isFrozen = false;\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
results = git.push().setPushAll().setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)).call();\r
GitBlitSuite.close(git);\r
GitBlitSuite.close(clone.call());\r
\r
// require push permissions and committer verification\r
- RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/verify-committer.git");\r
+ RepositoryModel model = repositories().getRepositoryModel("refchecks/verify-committer.git");\r
model.authorizationControl = AuthorizationControl.NAMED;\r
model.accessRestriction = AccessRestrictionType.PUSH;\r
model.verifyCommitter = true;\r
// grant user push permission\r
user.setRepositoryPermission(model.name, AccessPermission.PUSH);\r
\r
- GitBlit.self().updateUserModel(user.username, user, true);\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ gitblit().updateUserModel(user.username, user, true);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
// clone temp bare repo to working copy\r
File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-wc");\r
GitBlitSuite.close(clone.call());\r
\r
// require push permissions and committer verification\r
- RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/verify-committer.git");\r
+ RepositoryModel model = repositories().getRepositoryModel("refchecks/verify-committer.git");\r
model.authorizationControl = AuthorizationControl.NAMED;\r
model.accessRestriction = AccessRestrictionType.PUSH;\r
model.verifyCommitter = true;\r
// grant user push permission\r
user.setRepositoryPermission(model.name, AccessPermission.PUSH);\r
\r
- GitBlit.self().updateUserModel(user.username, user, true);\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ gitblit().updateUserModel(user.username, user, true);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
// clone temp bare repo to working copy\r
File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-wc");\r
GitBlitSuite.close(clone.call());\r
\r
// elevate repository to clone permission\r
- RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/ticgit.git");\r
+ RepositoryModel model = repositories().getRepositoryModel("refchecks/ticgit.git");\r
switch (permission) {\r
case VIEW:\r
model.accessRestriction = AccessRestrictionType.CLONE;\r
// grant user specified\r
user.setRepositoryPermission(model.name, permission);\r
\r
- GitBlit.self().updateUserModel(user.username, user, true);\r
- GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+ gitblit().updateUserModel(user.username, user, true);\r
+ repositories().updateRepositoryModel(model.name, model, false);\r
\r
// clone temp bare repo to working copy\r
File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit-wc");\r
user.canCreate = canCreate;\r
user.canAdmin = canAdmin;\r
\r
- GitBlit.self().updateUserModel(user.username, user, true);\r
+ gitblit().updateUserModel(user.username, user, true);\r
\r
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);\r
\r
assertTrue("User canAdmin:" + user.canAdmin + " canCreate:" + user.canCreate, user.canAdmin || user.canCreate);\r
\r
// confirm default personal repository permissions\r
- RepositoryModel model = GitBlit.self().getRepositoryModel(MessageFormat.format("~{0}/ticgit.git", user.username));\r
+ RepositoryModel model = repositories().getRepositoryModel(MessageFormat.format("~{0}/ticgit.git", user.username));\r
assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners));\r
assertEquals("Unexpected authorization control", AuthorizationControl.NAMED, model.authorizationControl);\r
assertEquals("Unexpected access restriction", AccessRestrictionType.VIEW, model.accessRestriction);\r
assertTrue("User canAdmin:" + user.canAdmin, user.canAdmin);\r
\r
// confirm default project repository permissions\r
- RepositoryModel model = GitBlit.self().getRepositoryModel("project/ticgit.git");\r
+ RepositoryModel model = repositories().getRepositoryModel("project/ticgit.git");\r
assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners));\r
- assertEquals("Unexpected authorization control", AuthorizationControl.fromName(GitBlit.getString(Keys.git.defaultAuthorizationControl, "NAMED")), model.authorizationControl);\r
- assertEquals("Unexpected access restriction", AccessRestrictionType.fromName(GitBlit.getString(Keys.git.defaultAccessRestriction, "NONE")), model.accessRestriction);\r
+ assertEquals("Unexpected authorization control", AuthorizationControl.fromName(settings().getString(Keys.git.defaultAuthorizationControl, "NAMED")), model.authorizationControl);\r
+ assertEquals("Unexpected access restriction", AccessRestrictionType.fromName(settings().getString(Keys.git.defaultAccessRestriction, "NONE")), model.accessRestriction);\r
\r
} catch (GitAPIException e) {\r
assertTrue(e.getMessage(), e.getMessage().contains("git-receive-pack not found"));\r
--- /dev/null
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.tests;
+
+import com.gitblit.GitBlit;
+import com.gitblit.IStoredSettings;
+import com.gitblit.manager.IFederationManager;
+import com.gitblit.manager.IGitblitManager;
+import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IProjectManager;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
+import com.gitblit.manager.IUserManager;
+
+
+public class GitblitUnitTest extends org.junit.Assert {
+
+ public static IStoredSettings settings() {
+ return runtime().getSettings();
+ }
+
+ public static IRuntimeManager runtime() {
+ return GitBlit.getManager(IRuntimeManager.class);
+ }
+
+ public static INotificationManager notifier() {
+ return GitBlit.getManager(INotificationManager.class);
+ }
+
+ public static IUserManager users() {
+ return GitBlit.getManager(IUserManager.class);
+ }
+
+ public static ISessionManager session() {
+ return GitBlit.getManager(ISessionManager.class);
+ }
+
+ public static IRepositoryManager repositories() {
+ return GitBlit.getManager(IRepositoryManager.class);
+ }
+
+ public static IProjectManager projects() {
+ return GitBlit.getManager(IProjectManager.class);
+ }
+
+ public static IFederationManager federation() {
+ return GitBlit.getManager(IFederationManager.class);
+ }
+
+ public static IGitblitManager gitblit() {
+ return GitBlit.getManager(IGitblitManager.class);
+ }
+}
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
import groovy.lang.Binding;\r
import groovy.util.GroovyScriptEngine;\r
\r
import org.junit.BeforeClass;\r
import org.junit.Test;\r
\r
-import com.gitblit.GitBlit;\r
import com.gitblit.GitBlitException;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.TeamModel;\r
* @author James Moger\r
*\r
*/\r
-public class GroovyScriptTest {\r
+public class GroovyScriptTest extends GitblitUnitTest {\r
\r
private static final AtomicBoolean started = new AtomicBoolean(false);\r
\r
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));\r
\r
- RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");\r
+ RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");\r
repository.customFields = new HashMap<String,String>();\r
repository.customFields.put( "fogbugzUrl", "http://bugs.test.com" );\r
repository.customFields.put( "fogbugzRepositoryId", "1" );\r
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));\r
\r
- RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");\r
+ RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");\r
repository.mailingLists.add("list@helloworld.git");\r
\r
test("sendmail-html.groovy", gitblit, logger, clientLogger, commands, repository);\r
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));\r
\r
- RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");\r
+ RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");\r
repository.mailingLists.add("list@helloworld.git");\r
\r
test("sendmail.groovy", gitblit, logger, clientLogger, commands, repository);\r
\r
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
\r
- File groovyDir = GitBlit.getGroovyScriptsFolder();\r
+ File groovyDir = repositories().getHooksFolder();\r
File tempScript = File.createTempFile("testClientLogging", "groovy", groovyDir);\r
tempScript.deleteOnExit();\r
\r
\r
String gitblitUrl = GitBlitSuite.url;\r
\r
- File groovyDir = GitBlit.getGroovyScriptsFolder();\r
+ File groovyDir = repositories().getHooksFolder();\r
GroovyScriptEngine gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());\r
\r
Binding binding = new Binding();\r
*/
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
* Test the Htpasswd user service.
*
*/
-public class HtpasswdUserServiceTest {
+public class HtpasswdUserServiceTest extends GitblitUnitTest {
private static final String RESOURCE_DIR = "src/test/resources/htpasswdUSTest/";
private static final String KEY_SUPPORT_PLAINTEXT_PWD = "realm.htpasswd.supportPlaintextPasswords";
\r
import java.io.File;\r
\r
-import org.junit.Assert;\r
import org.junit.Test;\r
\r
import com.gitblit.ConfigUserService;\r
* @author James Moger\r
*\r
*/\r
-public class Issue0259Test extends Assert {\r
+public class Issue0259Test extends GitblitUnitTest {\r
\r
RepositoryModel repo(String name, AccessRestrictionType restriction) {\r
RepositoryModel repo = new RepositoryModel();\r
\r
import java.io.File;\r
\r
-import org.junit.Assert;\r
import org.junit.Test;\r
\r
import com.gitblit.ConfigUserService;\r
* @author James Moger\r
*\r
*/\r
-public class Issue0271Test extends Assert {\r
+public class Issue0271Test extends GitblitUnitTest {\r
\r
RepositoryModel repo(String name, AccessRestrictionType restriction) {\r
RepositoryModel repo = new RepositoryModel();\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.io.File;\r
import java.io.FileOutputStream;\r
import java.text.SimpleDateFormat;\r
import com.gitblit.utils.JnaUtils;\r
import com.gitblit.utils.StringUtils;\r
\r
-public class JGitUtilsTest {\r
+public class JGitUtilsTest extends GitblitUnitTest {\r
\r
@Test\r
public void testDisplayName() throws Exception {\r
*/
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.io.IOException;
*
* @author Florian Zschocke
*/
-public class JnaUtilsTest {
+public class JnaUtilsTest extends GitblitUnitTest {
@Test
public void testGetgid() {
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-\r
import java.text.SimpleDateFormat;\r
import java.util.Date;\r
import java.util.HashMap;\r
import com.gitblit.utils.JsonUtils;\r
import com.google.gson.reflect.TypeToken;\r
\r
-public class JsonUtilsTest {\r
+public class JsonUtilsTest extends GitblitUnitTest {\r
\r
@Test\r
public void testSerialization() {\r
*/
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
import java.util.HashMap;
import java.util.Map;
* @author jcrygier
*
*/
-public class LdapUserServiceTest {
+public class LdapUserServiceTest extends GitblitUnitTest {
private LdapUserService ldapUserService;
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.List;\r
* @author James Moger\r
*\r
*/\r
-public class LuceneExecutorTest {\r
+public class LuceneExecutorTest extends GitblitUnitTest {\r
\r
LuceneExecutor lucene;\r
\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertTrue;\r
-\r
import javax.mail.Message;\r
\r
import org.junit.Test;\r
import com.gitblit.Keys;\r
import com.gitblit.MailExecutor;\r
\r
-public class MailTest {\r
+public class MailTest extends GitblitUnitTest {\r
\r
@Test\r
public void testSendMail() throws Exception {\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-\r
import org.junit.Test;\r
\r
import com.gitblit.utils.MarkdownUtils;\r
\r
-public class MarkdownUtilsTest {\r
+public class MarkdownUtilsTest extends GitblitUnitTest {\r
\r
@Test\r
public void testMarkdown() throws Exception {\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.util.List;\r
import java.util.TimeZone;\r
\r
import com.gitblit.models.Metric;\r
import com.gitblit.utils.MetricUtils;\r
\r
-public class MetricUtilsTest {\r
+public class MetricUtilsTest extends GitblitUnitTest {\r
\r
@Test\r
public void testMetrics() throws Exception {\r
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import org.junit.After;
import org.junit.Test;
import com.gitblit.Constants;
import com.gitblit.utils.ModelUtils;
-public class ModelUtilsTest {
+public class ModelUtilsTest extends GitblitUnitTest {
@After
public void resetPrefix()
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.util.Date;\r
\r
import org.junit.Test;\r
\r
import com.gitblit.utils.ObjectCache;\r
\r
-public class ObjectCacheTest {\r
+public class ObjectCacheTest extends GitblitUnitTest {\r
\r
@Test\r
public void testCache() throws Exception {\r
import java.util.Date;
-import org.junit.Assert;
import org.junit.Test;
import com.gitblit.Constants.AccessPermission;
* @author James Moger
*
*/
-public class PermissionsTest extends Assert {
+public class PermissionsTest extends GitblitUnitTest {
/**
* Admin access rights/permissions
import com.gitblit.models.RefLogEntry;\r
import com.gitblit.utils.RefLogUtils;\r
\r
-public class PushLogTest {\r
+public class PushLogTest extends GitblitUnitTest {\r
\r
@Test\r
public void testPushLog() throws IOException {\r
package com.gitblit.tests;\r
\r
import static org.hamcrest.CoreMatchers.is;\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertThat;\r
-import static org.junit.Assert.assertTrue;\r
\r
import java.util.HashMap;\r
\r
import com.gitblit.tests.mock.MemorySettings;\r
import com.gitblit.utils.StringUtils;\r
\r
-public class RedmineUserServiceTest {\r
+public class RedmineUserServiceTest extends GitblitUnitTest {\r
\r
private static final String JSON = "{\"user\":{\"created_on\":\"2011-03-28T00:41:29Z\",\"lastname\":\"foo\","\r
+ "\"last_login_on\":\"2012-09-06T23:59:26Z\",\"firstname\":\"baz\","\r
*/
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.junit.After;
import org.junit.Test;
import com.gitblit.Constants;
-import com.gitblit.GitBlit;
import com.gitblit.models.RepositoryModel;
-public class RepositoryModelTest {
+public class RepositoryModelTest extends GitblitUnitTest {
private static boolean wasStarted = false;
@Test
public void testGetCustomProperty() throws Exception {
- RepositoryModel model = GitBlit.self().getRepositoryModel(
+ RepositoryModel model = repositories().getRepositoryModel(
GitBlitSuite.getHelloworldRepository().getDirectory().getName());
assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
@Test
public void testSetCustomProperty() throws Exception {
- RepositoryModel model = GitBlit.self().getRepositoryModel(
+ RepositoryModel model = repositories().getRepositoryModel(
GitBlitSuite.getHelloworldRepository().getDirectory().getName());
assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
assertEquals("Hello", model.customFields.get("anotherProperty"));
assertEquals("Hello", model.customFields.put("anotherProperty", "GoodBye"));
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
- model = GitBlit.self().getRepositoryModel(
+ model = repositories().getRepositoryModel(
GitBlitSuite.getHelloworldRepository().getDirectory().getName());
assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.io.IOException;\r
import java.util.ArrayList;\r
import java.util.Collection;\r
* @author James Moger\r
*\r
*/\r
-public class RpcTests {\r
+public class RpcTests extends GitblitUnitTest {\r
\r
String url = GitBlitSuite.url;\r
String account = GitBlitSuite.account;\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.util.Arrays;\r
import java.util.List;\r
\r
\r
import com.gitblit.utils.StringUtils;\r
\r
-public class StringUtilsTest {\r
+public class StringUtilsTest extends GitblitUnitTest {\r
\r
@Test\r
public void testIsEmpty() throws Exception {\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.io.ByteArrayOutputStream;\r
import java.util.ArrayList;\r
import java.util.Date;\r
import com.gitblit.models.FeedEntryModel;\r
import com.gitblit.utils.SyndicationUtils;\r
\r
-public class SyndicationUtilsTest {\r
+public class SyndicationUtilsTest extends GitblitUnitTest {\r
\r
@Test\r
public void testSyndication() throws Exception {\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.util.Date;\r
\r
import org.junit.Test;\r
\r
import com.gitblit.utils.TimeUtils;\r
\r
-public class TimeUtilsTest {\r
+public class TimeUtilsTest extends GitblitUnitTest {\r
\r
private Date offset(long subtract) {\r
return new Date(System.currentTimeMillis() - subtract);\r
*/\r
package com.gitblit.tests;\r
\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
import java.io.File;\r
import java.io.IOException;\r
\r
import com.gitblit.models.TeamModel;\r
import com.gitblit.models.UserModel;\r
\r
-public class UserServiceTest {\r
+public class UserServiceTest extends GitblitUnitTest {\r
\r
@Test\r
public void testConfigUserService() throws IOException {\r
\r
import org.eclipse.jgit.util.FileUtils;\r
import org.junit.After;\r
-import org.junit.Assert;\r
import org.junit.Before;\r
import org.junit.Test;\r
\r
* @author James Moger\r
*\r
*/\r
-public class X509UtilsTest extends Assert {\r
+public class X509UtilsTest extends GitblitUnitTest {\r
\r
// passwords are case-sensitive and may be length-limited\r
// based on the JCE policy files\r
private boolean luceneIndexingEnabled;
public GitBlit4UITests(boolean luceneIndexingEnabled) {
+ super(null);
this.luceneIndexingEnabled = luceneIndexingEnabled;
}
.info("Lucene executor is scheduled to process indexed branches every 2 minutes.");
}
}
-
+
}
package de.akquinet.devops;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.beust.jcommander.ParameterException;
import com.gitblit.GitBlit;
import com.gitblit.GitBlitServer;
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
public class GitBlitServer4UITests extends GitBlitServer {
}
}
- private GitBlit4UITests instance;
-
@Override
- protected GitBlit getGitBlitInstance() {
- if (instance == null) {
- instance = new GitBlit4UITests(false);
- }
- return instance;
+ protected GitBlit newGitblit(IStoredSettings settings, File baseFolder) {
+ settings.overrideSetting(Keys.web.allowLuceneIndexing, false);
+ return new GitBlit(settings, baseFolder);
}
}