From 570d90d7d0635c85db21efaa12e1ecf3582edd6b Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Sat, 19 Nov 2011 07:34:13 -0500
Subject: [PATCH] Removed legacy css file
---
src/com/gitblit/GitBlit.java | 138 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 136 insertions(+), 2 deletions(-)
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java
index 51d5612..bc35667 100644
--- a/src/com/gitblit/GitBlit.java
+++ b/src/com/gitblit/GitBlit.java
@@ -15,9 +15,12 @@
*/
package com.gitblit;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -35,6 +38,7 @@
import javax.mail.Message;
import javax.mail.MessagingException;
+import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.Cookie;
@@ -61,14 +65,17 @@
import com.gitblit.models.FederationProposal;
import com.gitblit.models.FederationSet;
import com.gitblit.models.Metric;
-import com.gitblit.models.ObjectCache;
import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.ServerSettings;
+import com.gitblit.models.ServerStatus;
+import com.gitblit.models.SettingModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.ByteFormat;
import com.gitblit.utils.FederationUtils;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.JsonUtils;
import com.gitblit.utils.MetricUtils;
+import com.gitblit.utils.ObjectCache;
import com.gitblit.utils.StringUtils;
/**
@@ -106,6 +113,8 @@
private RepositoryResolver<Void> repositoryResolver;
+ private ServletContext servletContext;
+
private File repositoriesFolder;
private boolean exportAll = true;
@@ -113,6 +122,10 @@
private IUserService userService;
private IStoredSettings settings;
+
+ private ServerSettings settingsModel;
+
+ private ServerStatus serverStatus;
private MailExecutor mailExecutor;
@@ -231,6 +244,23 @@
*/
public static boolean isDebugMode() {
return self().settings.getBoolean(Keys.web.debugMode, false);
+ }
+
+ /**
+ * Updates the list of server settings.
+ *
+ * @param settings
+ * @return true if the update succeeded
+ */
+ public boolean updateSettings(Map<String, String> updatedSettings) {
+ return settings.saveSettings(updatedSettings);
+ }
+
+ public ServerStatus getStatus() {
+ // update heap memory status
+ serverStatus.heapAllocated = Runtime.getRuntime().totalMemory();
+ serverStatus.heapFree = Runtime.getRuntime().freeMemory();
+ return serverStatus;
}
/**
@@ -420,6 +450,13 @@
*/
public void updateUserModel(String username, UserModel user, boolean isCreate)
throws GitBlitException {
+ if (!username.equalsIgnoreCase(user.username)) {
+ if (userService.getUserModel(user.username) != null) {
+ throw new GitBlitException(MessageFormat.format(
+ "Failed to rename ''{0}'' because ''{1}'' already exists.", username,
+ user.username));
+ }
+ }
if (!userService.updateUserModel(username, user)) {
throw new GitBlitException(isCreate ? "Failed to add user!" : "Failed to update user!");
}
@@ -518,7 +555,7 @@
return null;
}
if (model.accessRestriction.atLeast(AccessRestrictionType.VIEW)) {
- if (user != null && user.canAccessRepository(model.name)) {
+ if (user != null && user.canAccessRepository(model)) {
return model;
}
return null;
@@ -555,6 +592,7 @@
model.isFrozen = getConfig(config, "isFrozen", false);
model.showReadme = getConfig(config, "showReadme", false);
model.skipSizeCalculation = getConfig(config, "skipSizeCalculation", false);
+ model.skipSummaryMetrics = getConfig(config, "skipSummaryMetrics", false);
model.federationStrategy = FederationStrategy.fromName(getConfig(config,
"federationStrategy", null));
model.federationSets = new ArrayList<String>(Arrays.asList(config.getStringList(
@@ -702,6 +740,15 @@
} else {
// rename repository
if (!repositoryName.equalsIgnoreCase(repository.name)) {
+ if (!repository.name.toLowerCase().endsWith(
+ org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) {
+ repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT;
+ }
+ if (new File(repositoriesFolder, repository.name).exists()) {
+ throw new GitBlitException(MessageFormat.format(
+ "Failed to rename ''{0}'' because ''{1}'' already exists.",
+ repositoryName, repository.name));
+ }
closeRepository(repositoryName);
File folder = new File(repositoriesFolder, repositoryName);
File destFolder = new File(repositoriesFolder, repository.name);
@@ -766,6 +813,7 @@
config.setBoolean("gitblit", null, "isFrozen", repository.isFrozen);
config.setBoolean("gitblit", null, "showReadme", repository.showReadme);
config.setBoolean("gitblit", null, "skipSizeCalculation", repository.skipSizeCalculation);
+ config.setBoolean("gitblit", null, "skipSummaryMetrics", repository.skipSummaryMetrics);
config.setStringList("gitblit", null, "federationSets", repository.federationSets);
config.setString("gitblit", null, "federationStrategy",
repository.federationStrategy.name());
@@ -1253,6 +1301,87 @@
}
/**
+ * Returns the descriptions/comments of the Gitblit config settings.
+ *
+ * @return SettingsModel
+ */
+ public ServerSettings getSettingsModel() {
+ // ensure that the current values are updated in the setting models
+ for (String key : settings.getAllKeys(null)) {
+ SettingModel setting = settingsModel.get(key);
+ if (setting != null) {
+ setting.currentValue = settings.getString(key, "");
+ }
+ }
+ return settingsModel;
+ }
+
+ /**
+ * Parse the properties file and aggregate all the comments by the setting
+ * key. A setting model tracks the current value, the default value, the
+ * description of the setting and and directives about the setting.
+ *
+ * @return Map<String, SettingModel>
+ */
+ private ServerSettings loadSettingModels() {
+ ServerSettings settingsModel = new ServerSettings();
+ try {
+ // Read bundled Gitblit properties to extract setting descriptions.
+ // This copy is pristine and only used for populating the setting
+ // models map.
+ InputStream is = servletContext.getResourceAsStream("/WEB-INF/reference.properties");
+ BufferedReader propertiesReader = new BufferedReader(new InputStreamReader(is));
+ StringBuilder description = new StringBuilder();
+ SettingModel setting = new SettingModel();
+ String line = null;
+ while ((line = propertiesReader.readLine()) != null) {
+ if (line.length() == 0) {
+ description.setLength(0);
+ setting = new SettingModel();
+ } else {
+ if (line.charAt(0) == '#') {
+ if (line.length() > 1) {
+ String text = line.substring(1).trim();
+ if (SettingModel.CASE_SENSITIVE.equals(text)) {
+ setting.caseSensitive = true;
+ } else if (SettingModel.RESTART_REQUIRED.equals(text)) {
+ setting.restartRequired = true;
+ } else if (SettingModel.SPACE_DELIMITED.equals(text)) {
+ setting.spaceDelimited = true;
+ } else if (text.startsWith(SettingModel.SINCE)) {
+ try {
+ setting.since = text.split(" ")[1];
+ } catch (Exception e) {
+ setting.since = text;
+ }
+ } else {
+ description.append(text);
+ description.append('\n');
+ }
+ }
+ } else {
+ String[] kvp = line.split("=", 2);
+ String key = kvp[0].trim();
+ setting.name = key;
+ setting.defaultValue = kvp[1].trim();
+ setting.currentValue = setting.defaultValue;
+ setting.description = description.toString().trim();
+ settingsModel.add(setting);
+ description.setLength(0);
+ setting = new SettingModel();
+ }
+ }
+ }
+ propertiesReader.close();
+ } catch (NullPointerException e) {
+ logger.error("Failed to find resource copy of gitblit.properties");
+ } catch (IOException e) {
+ logger.error("Failed to load resource copy of gitblit.properties");
+ }
+ return settingsModel;
+ }
+
+ /**
* Configure the Gitblit singleton with the specified settings source. This
* source may be file settings (Gitblit GO) or may be web.xml settings
* (Gitblit WAR).
@@ -1265,6 +1394,7 @@
repositoriesFolder = new File(settings.getString(Keys.git.repositoriesFolder, "git"));
logger.info("Git repositories folder " + repositoriesFolder.getAbsolutePath());
repositoryResolver = new FileResolver<Void>(repositoriesFolder, exportAll);
+ serverStatus = new ServerStatus(isGO());
String realm = settings.getString(Keys.realm.userService, "users.properties");
IUserService loginService = null;
try {
@@ -1307,11 +1437,15 @@
*/
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
+ servletContext = contextEvent.getServletContext();
+ settingsModel = loadSettingModels();
if (settings == null) {
// Gitblit WAR is running in a servlet container
WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());
configureContext(webxmlSettings, true);
}
+
+ serverStatus.servletContainer = servletContext.getServerInfo();
}
/**
--
Gitblit v1.9.1