]> source.dussan.org Git - gitblit.git/commitdiff
Settings overhaul. Fixes to authentication. Bind interface feature.
authorJames Moger <james.moger@gitblit.com>
Fri, 15 Apr 2011 21:18:51 +0000 (17:18 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 15 Apr 2011 21:18:51 +0000 (17:18 -0400)
Settings access has been abstracted and the way is becoming clear to
offer a WAR build in addition to the integrated server stack.  Util
methods moved around.

39 files changed:
build.xml
gitblit.properties
src/com/gitblit/Build.java
src/com/gitblit/FileSettings.java [new file with mode: 0644]
src/com/gitblit/GitBlit.java
src/com/gitblit/GitBlitServer.java
src/com/gitblit/IStoredSettings.java [new file with mode: 0644]
src/com/gitblit/StoredSettings.java [deleted file]
src/com/gitblit/WebXmlSettings.java [new file with mode: 0644]
src/com/gitblit/utils/ByteFormat.java
src/com/gitblit/utils/HtmlDiffFormatter.java
src/com/gitblit/utils/PatchFormatter.java
src/com/gitblit/utils/StringUtils.java [new file with mode: 0644]
src/com/gitblit/utils/TimeUtils.java [new file with mode: 0644]
src/com/gitblit/utils/Utils.java [deleted file]
src/com/gitblit/wicket/AuthorizationStrategy.java
src/com/gitblit/wicket/BasePage.html
src/com/gitblit/wicket/BasePage.java
src/com/gitblit/wicket/GitBlitWebApp.java
src/com/gitblit/wicket/GitBlitWebApp.properties
src/com/gitblit/wicket/LinkPanel.java
src/com/gitblit/wicket/LoginPage.html
src/com/gitblit/wicket/LoginPage.java
src/com/gitblit/wicket/LogoutPage.java [new file with mode: 0644]
src/com/gitblit/wicket/RepositoryPage.java
src/com/gitblit/wicket/User.java
src/com/gitblit/wicket/WicketUtils.java
src/com/gitblit/wicket/pages/BlobPage.java
src/com/gitblit/wicket/pages/RawPage.java
src/com/gitblit/wicket/pages/RepositoriesPage.java
src/com/gitblit/wicket/pages/SummaryPage.java
src/com/gitblit/wicket/pages/TicGitPage.java
src/com/gitblit/wicket/pages/TicGitTicketPage.html
src/com/gitblit/wicket/pages/TicGitTicketPage.java
src/com/gitblit/wicket/panels/BasePanel.java
src/com/gitblit/wicket/panels/BranchesPanel.java
src/com/gitblit/wicket/panels/LogPanel.java
src/com/gitblit/wicket/panels/PageLinksPanel.java
src/com/gitblit/wicket/panels/TagsPanel.java

index 34c195756564d03c9232bf1ac781f30b2383200b..524a1789662af447eaebd0dd316ef0ee22183131 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -17,6 +17,7 @@
                <javac srcdir="${basedir}/src" destdir="${project.build.dir}">\r
                        <include name="com/gitblit/Build.java" />\r
                        <include name="com/gitblit/Constants.java" />\r
+                       <include name="com/gitblit/utils/StringUtils.java" />\r
                </javac>\r
                <java classpath="${project.build.dir}" classname="com.gitblit.Build" />\r
 \r
index 7708a9b997f014cc928ec6370acd0a04cdbacb4a..1adadc8a4ac9f8cd279d3a04c260c82d2db7d803 100644 (file)
@@ -33,25 +33,14 @@ web.authenticate = true
 server.realmFile = users.properties\r
 \r
 #\r
-# Server Settings\r
-#\r
-server.debugMode = true\r
-server.tempFolder = temp\r
-server.log4jPattern = %-5p %d{MM-dd HH:mm:ss.SSS}  %-20.20c{1}  %m%n\r
-\r
-# Aggressive heap management will run the garbage collector on every generated\r
-# page.  This slows down page generation but improves heap consumption. \r
-server.aggressiveHeapManagement = true\r
-\r
-#\r
-# Git:Blit UI Settings\r
+# Git:Blit Web Settings\r
 #\r
 web.siteName =\r
 \r
-# If authenticateWebUI=true, users with "admin" role can create repositories,\r
+# If web.authenticate=true, users with "admin" role can create repositories,\r
 # create users, and edit repository metadata (owner, description, etc)\r
 #\r
-# If authenticateWebUI=false, any user can execute the aforementioned functions.  \r
+# If web.authenticate=false, any user can execute the aforementioned functions.  \r
 web.allowAdministration = true\r
 \r
 # This is the message display above the repositories table.\r
@@ -92,19 +81,37 @@ web.imageExtensions = bmp jpg gif png
 # Registered extensions for binary blobs\r
 web.binaryExtensions = jar pdf tar.gz zip\r
 \r
+# Aggressive heap management will run the garbage collector on every generated\r
+# page.  This slows down page generation but improves heap consumption. \r
+web.aggressiveHeapManagement = true\r
+\r
+# Run the webapp in debug mode\r
+web.debugMode = true\r
+\r
+# Enable/disable global regex substitutions (i.e. shared across repositories)\r
+regex.global = true\r
+\r
 # Example global regex substitutions\r
+# Use !!! to separate the search pattern and the replace pattern\r
+# searchpattern!!!replacepattern\r
 regex.global.bug = \\b(Bug:)(\\s*[#]?|-){0,1}(\\d+)\\b!!!<a href="http://somehost/bug/$3">Bug-Id: $3</a>\r
 regex.global.changeid = \\b(Change-Id:\\s*)([A-Za-z0-9]*)\\b!!!<a href="http://somehost/changeid/$2">Change-Id: $2</a>\r
 \r
 # Example per-repository regex substitutions overrides global\r
 #regex.myrepository.bug = \\b(Bug:)(\\s*[#]?|-){0,1}(\\d+)\\b!!!<a href="http://elsewhere/bug/$3">Bug-Id: $3</a>\r
 \r
-# Enable ticgit viewer for all repositories (checks for ticgit branch)\r
+# Enable ticgit pages for all repositories (if ticgit branch is present)\r
 ticgit.global = false\r
 \r
-# Enable ticgit viewer for specified repository (checks for ticgit branch)\r
+# Enable ticgit pages for specified repository (if ticgit branch is present)\r
 #ticgit.myrepository = true\r
 \r
+#\r
+# Server Settings\r
+#\r
+server.tempFolder = temp\r
+server.log4jPattern = %-5p %d{MM-dd HH:mm:ss.SSS}  %-20.20c{1}  %m%n\r
+\r
 #\r
 # Jetty Settings\r
 #\r
@@ -118,6 +125,14 @@ server.httpPort = 0
 # Secure/SSL https port to serve. <= 0 disables this connector.\r
 server.httpsPort = 443\r
 \r
+# Specify the interface for Jetty to bind the standard connector.\r
+# You may specify an ip or an empty value to bind to all interfaces. \r
+server.httpBindInterface = localhost\r
+\r
+# Specify the interface for Jetty to bind the secure connector.\r
+# You may specify an ip or an empty value to bind to all interfaces.\r
+server.httpsBindInterface = localhost\r
+\r
 # Password for SSL keystore (keystore password and certificate password must match)\r
 server.storePassword = dosomegit\r
 \r
index ec392e1fda030a4f3b5080177952e6ac200e63d8..b12d44ed47c5ca4d8cc1160458e7e328b3957c8b 100644 (file)
@@ -8,14 +8,16 @@ import java.io.IOException;
 import java.io.InputStream;\r
 import java.io.RandomAccessFile;\r
 import java.net.URL;\r
-import java.security.MessageDigest;\r
-import java.security.NoSuchAlgorithmException;\r
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
+import java.util.HashMap;\r
 import java.util.List;\r
+import java.util.Map;\r
 import java.util.Properties;\r
 \r
+import com.gitblit.utils.StringUtils;\r
+\r
 public class Build {\r
 \r
        public static void main(String... args) {\r
@@ -41,6 +43,7 @@ public class Build {
        }\r
 \r
        public static void buildSettingKeys() {\r
+               // Load all keys\r
                Properties properties = new Properties();\r
                try {\r
                        properties.load(new FileInputStream(Constants.PROPERTIES_FILE));\r
@@ -50,6 +53,23 @@ public class Build {
                List<String> keys = new ArrayList<String>(properties.stringPropertyNames());\r
                Collections.sort(keys);\r
 \r
+               // Determine static key group classes\r
+               Map<String, List<String>> staticClasses = new HashMap<String, List<String>>();\r
+               staticClasses.put("", new ArrayList<String>());\r
+               for (String key : keys) {\r
+                       String clazz = "";\r
+                       String field = key;\r
+                       if (key.indexOf('.') > -1) {\r
+                               clazz = key.substring(0, key.indexOf('.'));\r
+                               field = key.substring(key.indexOf('.') + 1);\r
+                       }\r
+                       if (!staticClasses.containsKey(clazz)) {\r
+                               staticClasses.put(clazz, new ArrayList<String>());\r
+                       }\r
+                       staticClasses.get(clazz).add(field);\r
+               }\r
+\r
+               // Assemble Keys source file\r
                StringBuilder sb = new StringBuilder();\r
                sb.append("package com.gitblit;\n");\r
                sb.append("\n");\r
@@ -59,10 +79,28 @@ public class Build {
                sb.append(" */\n");\r
                sb.append("public final class Keys {\n");\r
                sb.append("\n");\r
-               for (String key : keys) {\r
-                       sb.append(MessageFormat.format("\tpublic static final String {0} = \"{1}\";\n\n", key.replace('.', '_'), key));\r
+               List<String> classSet = new ArrayList<String>(staticClasses.keySet());\r
+               Collections.sort(classSet);\r
+               for (String clazz : classSet) {\r
+                       List<String> keySet = staticClasses.get(clazz);\r
+                       if (clazz.equals("")) {\r
+                               // root keys\r
+                               for (String key : keySet) {\r
+                                       sb.append(MessageFormat.format("\tpublic static final String {0} = \"{1}\";\n\n", key.replace('.', '_'), key));\r
+                               }\r
+                       } else {\r
+                               // class keys\r
+                               sb.append(MessageFormat.format("\tpublic static final class {0} '{'\n\n", clazz));\r
+                               sb.append(MessageFormat.format("\t\tpublic static final String _ROOT = \"{0}\";\n\n", clazz));\r
+                               for (String key : keySet) {\r
+                                       sb.append(MessageFormat.format("\t\tpublic static final String {0} = \"{1}\";\n\n", key.replace('.', '_'), clazz + "." + key));\r
+                               }\r
+                               sb.append("\t}\n\n");\r
+                       }\r
                }\r
                sb.append("}");\r
+\r
+               // Save Keys class definition\r
                try {\r
                        File file = new File("src/com/gitblit/Keys.java");\r
                        file.delete();\r
@@ -119,7 +157,7 @@ public class Build {
                        throw new RuntimeException("Error downloading " + mavenURL + " to " + targetFile, e);\r
                }\r
                byte[] data = buff.toByteArray();\r
-               String got = getSHA1(data);\r
+               String got = StringUtils.getSHA1(data);\r
                if (mo.sha1 != null && !got.equals(mo.sha1)) {\r
                        throw new RuntimeException("SHA1 checksum mismatch; got: " + got);\r
                }\r
@@ -134,29 +172,6 @@ public class Build {
                return targetFile;\r
        }\r
 \r
-       /**\r
-        * Generate the SHA1 checksum of a byte array.\r
-        * \r
-        * @param data\r
-        *            the byte array\r
-        * @return the SHA1 checksum\r
-        */\r
-       public static String getSHA1(byte[] data) {\r
-               MessageDigest md;\r
-               try {\r
-                       md = MessageDigest.getInstance("SHA-1");\r
-                       byte[] value = md.digest(data);\r
-                       StringBuilder buff = new StringBuilder(value.length * 2);\r
-                       for (byte c : value) {\r
-                               int x = c & 0xff;\r
-                               buff.append(Integer.toString(x >> 4, 16)).append(Integer.toString(x & 0xf, 16));\r
-                       }\r
-                       return buff.toString();\r
-               } catch (NoSuchAlgorithmException e) {\r
-                       throw new RuntimeException(e);\r
-               }\r
-       }\r
-\r
        private static class MavenObject {\r
 \r
                public static final MavenObject JCOMMANDER = new MavenObject("jCommander", "com/beust", "jcommander", "1.17", "219a3540f3b27d7cc3b1d91d6ea046cd8723290e");\r
diff --git a/src/com/gitblit/FileSettings.java b/src/com/gitblit/FileSettings.java
new file mode 100644 (file)
index 0000000..371b734
--- /dev/null
@@ -0,0 +1,143 @@
+package com.gitblit;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Properties;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * Reads GitBlit settings file.\r
+ * \r
+ */\r
+public class FileSettings implements IStoredSettings {\r
+\r
+       private Properties properties = new Properties();\r
+\r
+       private long lastread = 0;\r
+\r
+       private final Logger logger = LoggerFactory.getLogger(FileSettings.class);\r
+\r
+       @Override\r
+       public List<String> getAllKeys(String startingWith) {\r
+               startingWith = startingWith.toLowerCase();\r
+               List<String> keys = new ArrayList<String>();\r
+               Properties props = read();\r
+               for (Object o : props.keySet()) {\r
+                       String key = o.toString().toLowerCase();\r
+                       if (key.startsWith(startingWith)) {\r
+                               keys.add(key);\r
+                       }\r
+               }\r
+               return keys;\r
+       }\r
+\r
+       @Override\r
+       public boolean getBoolean(String name, boolean defaultValue) {\r
+               Properties props = read();\r
+               if (props.containsKey(name)) {\r
+                       try {\r
+                               String value = props.getProperty(name);\r
+                               if (value != null && value.trim().length() > 0) {\r
+                                       return Boolean.parseBoolean(value);\r
+                               }\r
+                       } catch (Exception e) {\r
+                               logger.warn("No override setting for " + name + " using default of " + defaultValue);\r
+                       }\r
+               }\r
+               return defaultValue;\r
+       }\r
+\r
+       @Override\r
+       public int getInteger(String name, int defaultValue) {\r
+               Properties props = read();\r
+               if (props.containsKey(name)) {\r
+                       try {\r
+                               String value = props.getProperty(name);\r
+                               if (value != null && value.trim().length() > 0) {\r
+                                       return Integer.parseInt(value);\r
+                               }\r
+                       } catch (Exception e) {\r
+                               logger.warn("No override setting for " + name + " using default of " + defaultValue);\r
+                       }\r
+               }\r
+               return defaultValue;\r
+       }\r
+\r
+       @Override\r
+       public String getString(String name, String defaultValue) {\r
+               Properties props = read();\r
+               if (props.containsKey(name)) {\r
+                       try {\r
+                               String value = props.getProperty(name);\r
+                               if (value != null) {\r
+                                       return value;\r
+                               }\r
+                       } catch (Exception e) {\r
+                               logger.warn("No override setting for " + name + " using default of " + defaultValue);\r
+                       }\r
+               }\r
+               return defaultValue;\r
+       }\r
+\r
+       @Override\r
+       public List<String> getStrings(String name) {\r
+               return getStrings(name, " ");\r
+       }\r
+\r
+       @Override\r
+       public List<String> getStringsFromValue(String value) {\r
+               return getStringsFromValue(value, " ");\r
+       }\r
+\r
+       @Override\r
+       public List<String> getStrings(String name, String separator) {\r
+               List<String> strings = new ArrayList<String>();\r
+               Properties props = read();\r
+               if (props.containsKey(name)) {\r
+                       String value = props.getProperty(name);\r
+                       strings = getStringsFromValue(value, separator);\r
+               }\r
+               return strings;\r
+       }\r
+\r
+       @Override\r
+       public List<String> getStringsFromValue(String value, String separator) {\r
+               List<String> strings = new ArrayList<String>();\r
+               try {\r
+                       String[] chunks = value.split(separator);\r
+                       for (String chunk : chunks) {\r
+                               chunk = chunk.trim();\r
+                               if (chunk.length() > 0) {\r
+                                       strings.add(chunk);\r
+                               }\r
+                       }\r
+               } catch (Exception e) {\r
+               }\r
+               return strings;\r
+       }\r
+\r
+       private synchronized Properties read() {\r
+               File file = new File(Constants.PROPERTIES_FILE);\r
+               if (file.exists() && (file.lastModified() > lastread)) {\r
+                       try {\r
+                               properties = new Properties();\r
+                               properties.load(new FileInputStream(Constants.PROPERTIES_FILE));\r
+                               lastread = file.lastModified();\r
+                       } catch (FileNotFoundException f) {\r
+                       } catch (Throwable t) {\r
+                               t.printStackTrace();\r
+                       }\r
+               }\r
+               return properties;\r
+       }\r
+       \r
+       @Override\r
+       public String toString() {\r
+               return getClass().getSimpleName() + ": " + new File(Constants.PROPERTIES_FILE).getAbsolutePath();\r
+       }\r
+}\r
index f437e5f03ed5fb5034efde786d5be8c839677b43..f285daf4ae33b86de5d4551c86c1c6975aac8828 100644 (file)
@@ -5,6 +5,8 @@ import java.util.ArrayList;
 import java.util.Date;\r
 import java.util.List;\r
 \r
+import javax.servlet.ServletContextEvent;\r
+import javax.servlet.ServletContextListener;\r
 import javax.servlet.http.Cookie;\r
 import javax.servlet.http.HttpServletRequest;\r
 \r
@@ -22,38 +24,43 @@ import com.gitblit.utils.JGitUtils;
 import com.gitblit.wicket.User;\r
 import com.gitblit.wicket.models.RepositoryModel;\r
 \r
-public class GitBlit {\r
+public class GitBlit implements ServletContextListener {\r
 \r
-       private static GitBlit gitblit;\r
+       private final static GitBlit gitblit;\r
 \r
        private final Logger logger = LoggerFactory.getLogger(GitBlit.class);\r
 \r
-       private final boolean debugMode;\r
+       private FileResolver repositoryResolver;\r
 \r
-       private final FileResolver repositoryResolver;\r
+       private File repositories;\r
 \r
-       private final File repositories;\r
-\r
-       private final boolean exportAll;\r
+       private boolean exportAll;\r
 \r
        private ILoginService loginService;\r
 \r
+       private IStoredSettings storedSettings;\r
+\r
+       static {\r
+               gitblit = new GitBlit();\r
+       }\r
+\r
        public static GitBlit self() {\r
-               if (gitblit == null) {\r
-                       gitblit = new GitBlit();\r
-               }\r
                return gitblit;\r
        }\r
 \r
        private GitBlit() {\r
-               repositories = new File(StoredSettings.getString(Keys.git_repositoriesFolder, "repos"));\r
-               exportAll = StoredSettings.getBoolean(Keys.git_exportAll, true);\r
-               repositoryResolver = new FileResolver(repositories, exportAll);\r
-               debugMode = StoredSettings.getBoolean(Keys.server_debugMode, false);\r
+       }\r
+\r
+       public IStoredSettings settings() {\r
+               return storedSettings;\r
        }\r
 \r
        public boolean isDebugMode() {\r
-               return debugMode;\r
+               return storedSettings.getBoolean(Keys.web.debugMode, false);\r
+       }\r
+\r
+       public String getCloneUrl(String repositoryName) {\r
+               return storedSettings.getString(Keys.git.cloneUrl, "https://localhost/git/") + repositoryName;\r
        }\r
 \r
        public void setLoginService(ILoginService loginService) {\r
@@ -90,7 +97,7 @@ public class GitBlit {
        }\r
 \r
        public List<String> getRepositoryList() {\r
-               return JGitUtils.getRepositoryList(repositories, exportAll, StoredSettings.getBoolean(Keys.git_nestedRepositories, true));\r
+               return JGitUtils.getRepositoryList(repositories, exportAll, storedSettings.getBoolean(Keys.git.nestedRepositories, true));\r
        }\r
 \r
        public List<RepositoryModel> getRepositories(Request request) {\r
@@ -124,4 +131,28 @@ public class GitBlit {
                }\r
                return r;\r
        }\r
+\r
+       public void setupContext(IStoredSettings settings) {\r
+               logger.info("Setting up GitBlit context from " + settings.toString());\r
+               this.storedSettings = settings;\r
+               repositories = new File(settings.getString(Keys.git.repositoriesFolder, "repos"));\r
+               exportAll = settings.getBoolean(Keys.git.exportAll, true);\r
+               repositoryResolver = new FileResolver(repositories, exportAll);\r
+       }\r
+\r
+       @Override\r
+       public void contextInitialized(ServletContextEvent contextEvent) {\r
+               logger.info("GitBlit context initialization by servlet container...");\r
+               if (storedSettings == null) {\r
+                       WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());\r
+                       setupContext(webxmlSettings);\r
+               } else {\r
+                       logger.info("GitBlit context already setup by " + storedSettings.toString());   \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void contextDestroyed(ServletContextEvent contextEvent) {\r
+               logger.info("GitBlit context destroyed by servlet container.");\r
+       }\r
 }\r
index b167e6c1e3b746d74cd5e6543ed0050c2426cb79..a82b595f29b05387ca86e1bc324ebce05f0f3f33 100644 (file)
@@ -11,6 +11,7 @@ import java.net.Socket;
 import java.net.URL;\r
 import java.net.UnknownHostException;\r
 import java.security.ProtectionDomain;\r
+import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
@@ -44,6 +45,7 @@ import com.beust.jcommander.JCommander;
 import com.beust.jcommander.Parameter;\r
 import com.beust.jcommander.ParameterException;\r
 import com.beust.jcommander.Parameters;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebApp;\r
 \r
 public class GitBlitServer {\r
@@ -51,6 +53,8 @@ public class GitBlitServer {
        private final static Logger logger = Log.getLogger(GitBlitServer.class.getSimpleName());\r
        private final static String border_star = "***********************************************************";\r
 \r
+       private final static FileSettings fileSettings = new FileSettings();\r
+\r
        public static void main(String[] args) {\r
                Params params = new Params();\r
                JCommander jc = new JCommander(params);\r
@@ -106,10 +110,7 @@ public class GitBlitServer {
         * Start Server.\r
         */\r
        private static void start(Params params) {\r
-               // instantiate GitBlit\r
-               GitBlit.self();\r
-\r
-               PatternLayout layout = new PatternLayout(StoredSettings.getString(Keys.server_log4jPattern, "%-5p %d{MM-dd HH:mm:ss.SSS}  %-20.20c{1}  %m%n"));\r
+               PatternLayout layout = new PatternLayout(fileSettings.getString(Keys.server.log4jPattern, "%-5p %d{MM-dd HH:mm:ss.SSS}  %-20.20c{1}  %m%n"));\r
                org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();\r
                rootLogger.addAppender(new ConsoleAppender(layout));\r
 \r
@@ -121,20 +122,26 @@ public class GitBlitServer {
                String osversion = System.getProperty("os.version");\r
                logger.info("Running on " + osname + " (" + osversion + ")");\r
 \r
-               if (StoredSettings.getBoolean(Keys.server_debugMode, false)) {\r
-                       logger.warn("DEBUG Mode");\r
-               }\r
-\r
                // Determine port connectors\r
                List<Connector> connectors = new ArrayList<Connector>();\r
                if (params.port > 0) {\r
                        Connector httpConnector = createConnector(params.useNIO, params.port);\r
+                       String bindInterface = fileSettings.getString(Keys.server.httpBindInterface, null);\r
+                       if (!StringUtils.isEmpty(bindInterface)) {\r
+                               logger.warn(MessageFormat.format("Binding port {0} to {1}", params.port, bindInterface));\r
+                               httpConnector.setHost(bindInterface);\r
+                       }\r
                        connectors.add(httpConnector);\r
                }\r
 \r
                if (params.securePort > 0) {\r
                        if (new File("keystore").exists()) {\r
                                Connector secureConnector = createSSLConnector(params.useNIO, params.securePort, params.storePassword);\r
+                               String bindInterface = fileSettings.getString(Keys.server.httpsBindInterface, null);\r
+                               if (!StringUtils.isEmpty(bindInterface)) {\r
+                                       logger.warn(MessageFormat.format("Binding port {0} to {1}", params.port, bindInterface));\r
+                                       secureConnector.setHost(bindInterface);\r
+                               }\r
                                connectors.add(secureConnector);\r
                        } else {\r
                                logger.warn("Failed to find Keystore?  Did you run \"makekeystore\"?");\r
@@ -177,7 +184,7 @@ public class GitBlitServer {
                // Git Servlet\r
                ServletHolder gitServlet = null;\r
                String gitServletPathSpec = "/git/*";\r
-               if (StoredSettings.getBoolean(Keys.git_allowPushPull, true)) {\r
+               if (fileSettings.getBoolean(Keys.git.allowPushPull, true)) {\r
                        gitServlet = rootContext.addServlet(GitServlet.class, gitServletPathSpec);\r
                        gitServlet.setInitParameter("base-path", params.repositoriesFolder);\r
                        gitServlet.setInitParameter("export-all", params.exportAll ? "1" : "0");\r
@@ -235,6 +242,11 @@ public class GitBlitServer {
                // Set the server's contexts\r
                server.setHandler(handler);\r
 \r
+               // Setup the GitBlit context\r
+               GitBlit gitblit = GitBlit.self();\r
+               gitblit.setupContext(fileSettings);\r
+               rootContext.addEventListener(gitblit);\r
+\r
                // Start the Server\r
                try {\r
                        if (params.shutdownPort > 0) {\r
@@ -356,43 +368,43 @@ public class GitBlitServer {
                public Boolean stop = false;\r
 \r
                @Parameter(names = { "--temp" }, description = "Server temp folder")\r
-               public String temp = StoredSettings.getString(Keys.server_tempFolder, "temp");\r
+               public String temp = fileSettings.getString(Keys.server.tempFolder, "temp");\r
 \r
                /*\r
                 * GIT Servlet Parameters\r
                 */\r
                @Parameter(names = { "--repos" }, description = "Git Repositories Folder")\r
-               public String repositoriesFolder = StoredSettings.getString(Keys.git_repositoriesFolder, "repos");\r
+               public String repositoriesFolder = fileSettings.getString(Keys.git.repositoriesFolder, "repos");\r
 \r
                @Parameter(names = { "--exportAll" }, description = "Export All Found Repositories")\r
-               public Boolean exportAll = StoredSettings.getBoolean(Keys.git_exportAll, true);\r
+               public Boolean exportAll = fileSettings.getBoolean(Keys.git.exportAll, true);\r
 \r
                /*\r
                 * Authentication Parameters\r
                 */\r
                @Parameter(names = { "--authenticatePushPull" }, description = "Authenticate Git Push/Pull access")\r
-               public Boolean authenticatePushPull = StoredSettings.getBoolean(Keys.git_authenticate, true);\r
+               public Boolean authenticatePushPull = fileSettings.getBoolean(Keys.git.authenticate, true);\r
 \r
                @Parameter(names = { "--realm" }, description = "Users Realm Hash File")\r
-               public String realmFile = StoredSettings.getString(Keys.server_realmFile, "users.properties");\r
+               public String realmFile = fileSettings.getString(Keys.server.realmFile, "users.properties");\r
 \r
                /*\r
                 * JETTY Parameters\r
                 */\r
                @Parameter(names = { "--nio" }, description = "Use NIO Connector else use Socket Connector.")\r
-               public Boolean useNIO = StoredSettings.getBoolean(Keys.server_useNio, true);\r
+               public Boolean useNIO = fileSettings.getBoolean(Keys.server.useNio, true);\r
 \r
                @Parameter(names = "--port", description = "HTTP port for to serve. (port <= 0 will disable this connector)")\r
-               public Integer port = StoredSettings.getInteger(Keys.server_httpPort, 80);\r
+               public Integer port = fileSettings.getInteger(Keys.server.httpPort, 80);\r
 \r
                @Parameter(names = "--securePort", description = "HTTPS port to serve.  (port <= 0 will disable this connector)")\r
-               public Integer securePort = StoredSettings.getInteger(Keys.server_httpsPort, 443);\r
+               public Integer securePort = fileSettings.getInteger(Keys.server.httpsPort, 443);\r
 \r
                @Parameter(names = "--storePassword", description = "Password for SSL (https) keystore.")\r
-               public String storePassword = StoredSettings.getString(Keys.server_storePassword, "");\r
+               public String storePassword = fileSettings.getString(Keys.server.storePassword, "");\r
 \r
                @Parameter(names = "--shutdownPort", description = "Port for Shutdown Monitor to listen on. (port <= 0 will disable this monitor)")\r
-               public Integer shutdownPort = StoredSettings.getInteger(Keys.server_shutdownPort, 8081);\r
+               public Integer shutdownPort = fileSettings.getInteger(Keys.server.shutdownPort, 8081);\r
 \r
        }\r
 }
\ No newline at end of file
diff --git a/src/com/gitblit/IStoredSettings.java b/src/com/gitblit/IStoredSettings.java
new file mode 100644 (file)
index 0000000..d5b74aa
--- /dev/null
@@ -0,0 +1,23 @@
+package com.gitblit;\r
+\r
+import java.util.List;\r
+\r
+public interface IStoredSettings {\r
+\r
+       public abstract List<String> getAllKeys(String startingWith);\r
+\r
+       public abstract boolean getBoolean(String name, boolean defaultValue);\r
+\r
+       public abstract int getInteger(String name, int defaultValue);\r
+\r
+       public abstract String getString(String name, String defaultValue);\r
+\r
+       public abstract List<String> getStrings(String name);\r
+\r
+       public abstract List<String> getStringsFromValue(String value);\r
+\r
+       public abstract List<String> getStrings(String name, String separator);\r
+\r
+       public abstract List<String> getStringsFromValue(String value, String separator);\r
+\r
+}
\ No newline at end of file
diff --git a/src/com/gitblit/StoredSettings.java b/src/com/gitblit/StoredSettings.java
deleted file mode 100644 (file)
index 1db87c0..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-package com.gitblit;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Properties;\r
-\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * Reads settings file.\r
- * \r
- */\r
-public class StoredSettings {\r
-\r
-       private static Properties properties = new Properties();\r
-\r
-       private static long lastread = 0;\r
-\r
-       private static final Logger logger = LoggerFactory.getLogger(StoredSettings.class);\r
-\r
-       public static List<String> getAllKeys(String startingWith) {\r
-               startingWith = startingWith.toLowerCase();\r
-               List<String> keys = new ArrayList<String>();\r
-               Properties props = read();\r
-               for (Object o : props.keySet()) {\r
-                       String key = o.toString().toLowerCase();\r
-                       if (key.startsWith(startingWith)) {\r
-                               keys.add(key);\r
-                       }\r
-               }\r
-               return keys;\r
-       }\r
-\r
-       public static boolean getBoolean(String name, boolean defaultValue) {\r
-               Properties props = read();\r
-               if (props.containsKey(name)) {\r
-                       try {\r
-                               String value = props.getProperty(name);\r
-                               if (value != null && value.trim().length() > 0) {\r
-                                       return Boolean.parseBoolean(value);\r
-                               }\r
-                       } catch (Exception e) {\r
-                               logger.warn("No override setting for " + name + " using default of " + defaultValue);\r
-                       }\r
-               }\r
-               return defaultValue;\r
-       }\r
-\r
-       public static int getInteger(String name, int defaultValue) {\r
-               Properties props = read();\r
-               if (props.containsKey(name)) {\r
-                       try {\r
-                               String value = props.getProperty(name);\r
-                               if (value != null && value.trim().length() > 0) {\r
-                                       return Integer.parseInt(value);\r
-                               }\r
-                       } catch (Exception e) {\r
-                               logger.warn("No override setting for " + name + " using default of " + defaultValue);\r
-                       }\r
-               }\r
-               return defaultValue;\r
-       }\r
-\r
-       public static String getString(String name, String defaultValue) {\r
-               Properties props = read();\r
-               if (props.containsKey(name)) {\r
-                       try {\r
-                               String value = props.getProperty(name);\r
-                               if (value != null) {\r
-                                       return value;\r
-                               }\r
-                       } catch (Exception e) {\r
-                               logger.warn("No override setting for " + name + " using default of " + defaultValue);\r
-                       }\r
-               }\r
-               return defaultValue;\r
-       }\r
-\r
-       public static List<String> getStrings(String name) {\r
-               return getStrings(name, " ");\r
-       }\r
-\r
-       public static List<String> getStringsFromValue(String value) {\r
-               return getStringsFromValue(value, " ");\r
-       }\r
-\r
-       public static List<String> getStrings(String name, String separator) {\r
-               List<String> strings = new ArrayList<String>();\r
-               Properties props = read();\r
-               if (props.containsKey(name)) {\r
-                       String value = props.getProperty(name);\r
-                       strings = getStringsFromValue(value, separator);\r
-               }\r
-               return strings;\r
-       }\r
-\r
-       public static List<String> getStringsFromValue(String value, String separator) {\r
-               List<String> strings = new ArrayList<String>();\r
-               try {\r
-                       String[] chunks = value.split(separator);\r
-                       for (String chunk : chunks) {\r
-                               chunk = chunk.trim();\r
-                               if (chunk.length() > 0) {\r
-                                       strings.add(chunk);\r
-                               }\r
-                       }\r
-               } catch (Exception e) {\r
-               }\r
-               return strings;\r
-       }\r
-\r
-       private static synchronized Properties read() {\r
-               File file = new File(Constants.PROPERTIES_FILE);\r
-               if (file.exists() && (file.lastModified() > lastread)) {\r
-                       try {\r
-                               properties = new Properties();\r
-                               properties.load(new FileInputStream(Constants.PROPERTIES_FILE));\r
-                               lastread = file.lastModified();\r
-                       } catch (FileNotFoundException f) {\r
-                       } catch (Throwable t) {\r
-                               t.printStackTrace();\r
-                       }\r
-               }\r
-               return properties;\r
-       }\r
-}\r
diff --git a/src/com/gitblit/WebXmlSettings.java b/src/com/gitblit/WebXmlSettings.java
new file mode 100644 (file)
index 0000000..00084bf
--- /dev/null
@@ -0,0 +1,65 @@
+package com.gitblit;\r
+\r
+import java.util.List;\r
+\r
+import javax.servlet.ServletContext;\r
+\r
+public class WebXmlSettings implements IStoredSettings {\r
+\r
+       public WebXmlSettings(ServletContext context) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public List<String> getAllKeys(String startingWith) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public boolean getBoolean(String name, boolean defaultValue) {\r
+               // TODO Auto-generated method stub\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public int getInteger(String name, int defaultValue) {\r
+               // TODO Auto-generated method stub\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public String getString(String name, String defaultValue) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public List<String> getStrings(String name) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public List<String> getStringsFromValue(String value) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public List<String> getStrings(String name, String separator) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public List<String> getStringsFromValue(String value, String separator) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public String toString() {\r
+               return getClass().getSimpleName() + ": web.xml";\r
+       }\r
+}\r
index a726368f8da1554dd95d7f8a06f9c99a10fcfdaf..8634f298fa0575e52e162c18f92cc77134ca9236 100644 (file)
@@ -1,8 +1,3 @@
-/*
- * Copyright 2011 Squeal Group.  Licensed under the Eclipse Public License, 
- * Version 1.0 (http://www.eclipse.org/legal/epl-v10.html).
- * Initial Developer: Squeal Group
- */
 package com.gitblit.utils;
 
 import java.text.DecimalFormat;
index a3e58c383d7b476f0d1f147a73cd9dd20cd85ced..24cdd8acb04c6e5f38bf34e9dd212491a74c8c52 100644 (file)
@@ -91,7 +91,7 @@ public class HtmlDiffFormatter extends DiffFormatter {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
                text.writeLine(bos, cur);\r
                String line = bos.toString();\r
-               line = Utils.escapeForHtml(line, false);\r
+               line = StringUtils.escapeForHtml(line, false);\r
                os.write(line.getBytes());\r
                switch (prefix) {\r
                case '+':\r
index f019ce405217fe966cffbc30a2231fd67e9e823c..15c1f94073d1d53b6d366782566dbab8df59d380 100644 (file)
@@ -78,7 +78,7 @@ public class PatchFormatter extends DiffFormatter {
                }\r
                for (String path : changes.keySet()) {\r
                        PatchTouple touple = changes.get(path);\r
-                       patch.append("\n " + Utils.rightPad(path, maxPathLen, ' ') + " | " + Utils.leftPad("" + touple.total(), 4, ' ') + " " + touple.relativeScale(unit));\r
+                       patch.append("\n " + StringUtils.rightPad(path, maxPathLen, ' ') + " | " + StringUtils.leftPad("" + touple.total(), 4, ' ') + " " + touple.relativeScale(unit));\r
                }\r
                patch.append(MessageFormat.format("\n {0} files changed, {1} insertions(+), {2} deletions(-)\n\n", files, insertions, deletions));\r
                patch.append(os.toString());\r
diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java
new file mode 100644 (file)
index 0000000..6d646df
--- /dev/null
@@ -0,0 +1,110 @@
+package com.gitblit.utils;\r
+\r
+import java.io.UnsupportedEncodingException;\r
+import java.security.MessageDigest;\r
+import java.security.NoSuchAlgorithmException;\r
+import java.util.List;\r
+\r
+public class StringUtils {\r
+       \r
+       public static boolean isEmpty(String value) {\r
+               return value == null || value.trim().length() == 0;\r
+       }\r
+\r
+       public static String breakLinesForHtml(String string) {\r
+               return string.replace("\r\n", "<br/>").replace("\r", "<br/>").replace("\n", "<br/>");\r
+       }\r
+\r
+       public static String escapeForHtml(String inStr, boolean changeSpace) {\r
+               StringBuffer retStr = new StringBuffer();\r
+               int i = 0;\r
+               while (i < inStr.length()) {\r
+                       if (inStr.charAt(i) == '&') {\r
+                               retStr.append("&amp;");\r
+                       } else if (inStr.charAt(i) == '<') {\r
+                               retStr.append("&lt;");\r
+                       } else if (inStr.charAt(i) == '>') {\r
+                               retStr.append("&gt;");\r
+                       } else if (inStr.charAt(i) == '\"') {\r
+                               retStr.append("&quot;");\r
+                       } else if (changeSpace && inStr.charAt(i) == ' ') {\r
+                               retStr.append("&nbsp;");\r
+                       } else if (changeSpace && inStr.charAt(i) == '\t') {\r
+                               retStr.append(" &nbsp; &nbsp;");\r
+                       } else\r
+                               retStr.append(inStr.charAt(i));\r
+                       i++;\r
+               }\r
+               return retStr.toString();\r
+       }\r
+\r
+       public static String flattenStrings(List<String> values) {\r
+               StringBuilder sb = new StringBuilder();\r
+               for (String value : values) {\r
+                       sb.append(value).append(" ");\r
+               }\r
+               return sb.toString().trim();\r
+       }\r
+\r
+       public static String trimString(String value, int max) {\r
+               if (value.length() <= max) {\r
+                       return value;\r
+               }\r
+               return value.substring(0, max - 3) + "...";\r
+       }\r
+\r
+       public static String trimShortLog(String string) {\r
+               return trimString(string, 60);\r
+       }\r
+\r
+       public static String leftPad(String input, int length, char pad) {\r
+               if (input.length() < length) {\r
+                       StringBuilder sb = new StringBuilder();\r
+                       for (int i = 0, len = length - input.length(); i < len; i++) {\r
+                               sb.append(pad);\r
+                       }\r
+                       sb.append(input);\r
+                       return sb.toString();\r
+               }\r
+               return input;\r
+       }\r
+\r
+       public static String rightPad(String input, int length, char pad) {\r
+               if (input.length() < length) {\r
+                       StringBuilder sb = new StringBuilder();\r
+                       sb.append(input);\r
+                       for (int i = 0, len = length - input.length(); i < len; i++) {\r
+                               sb.append(pad);\r
+                       }\r
+                       return sb.toString();\r
+               }\r
+               return input;\r
+       }\r
+\r
+       public static String getSHA1(String text) {\r
+               try {\r
+                       byte[] bytes = text.getBytes("iso-8859-1");\r
+                       return getSHA1(bytes);\r
+               } catch (UnsupportedEncodingException u) {\r
+                       throw new RuntimeException(u);\r
+               }\r
+       }\r
+\r
+       public static String getSHA1(byte[] bytes) {\r
+               try {\r
+                       MessageDigest md = MessageDigest.getInstance("SHA-1");\r
+                       md.update(bytes, 0, bytes.length);\r
+                       byte[] sha1hash = md.digest();\r
+                       StringBuilder sb = new StringBuilder(sha1hash.length * 2);\r
+                       for (int i = 0; i < sha1hash.length; i++) {\r
+                               if (((int) sha1hash[i] & 0xff) < 0x10)\r
+                                       sb.append("0");\r
+                               sb.append(Long.toString((int) sha1hash[i] & 0xff, 16));\r
+                       }\r
+                       return sb.toString();\r
+               } catch (NoSuchAlgorithmException t) {\r
+                       throw new RuntimeException(t);\r
+               }\r
+       }\r
+\r
+}\r
diff --git a/src/com/gitblit/utils/TimeUtils.java b/src/com/gitblit/utils/TimeUtils.java
new file mode 100644 (file)
index 0000000..60b525b
--- /dev/null
@@ -0,0 +1,119 @@
+package com.gitblit.utils;\r
+\r
+import java.util.Date;\r
+\r
+public class TimeUtils {\r
+       private final static long min = 1000 * 60l;\r
+\r
+       private final static long halfhour = min * 30l;\r
+\r
+       private final static long onehour = halfhour * 2;\r
+\r
+       private final static long oneday = onehour * 24l;\r
+\r
+       @SuppressWarnings("deprecation")\r
+       public static boolean isToday(Date date) {\r
+               Date now = new Date();\r
+               return now.getDate() == date.getDate() && now.getMonth() == date.getMonth() && now.getYear() == date.getYear();\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       public static boolean isYesterday(Date date) {\r
+               Date now = new Date();\r
+               return now.getDate() == (date.getDate() + 1) && now.getMonth() == date.getMonth() && now.getYear() == date.getYear();\r
+       }\r
+\r
+       public static int minutesAgo(Date date, long endTime, boolean roundup) {\r
+               long diff = endTime - date.getTime();\r
+               int mins = (int) (diff / min);\r
+               if (roundup && (diff % min) >= 30)\r
+                       mins++;\r
+               return mins;\r
+       }\r
+\r
+       public static int minutesAgo(Date date, boolean roundup) {\r
+               return minutesAgo(date, System.currentTimeMillis(), roundup);\r
+       }\r
+\r
+       public static int hoursAgo(Date date, boolean roundup) {\r
+               long diff = System.currentTimeMillis() - date.getTime();\r
+               int hours = (int) (diff / onehour);\r
+               if (roundup && (diff % onehour) >= halfhour)\r
+                       hours++;\r
+               return hours;\r
+       }\r
+\r
+       public static int daysAgo(Date date, boolean roundup) {\r
+               long diff = System.currentTimeMillis() - date.getTime();\r
+               int days = (int) (diff / oneday);\r
+               if (roundup && (diff % oneday) > 0)\r
+                       days++;\r
+               return days;\r
+       }\r
+\r
+       public static String timeAgo(Date date) {\r
+               return timeAgo(date, false);\r
+       }\r
+\r
+       public static String timeAgoCss(Date date) {\r
+               return timeAgo(date, true);\r
+       }\r
+\r
+       private static String timeAgo(Date date, boolean css) {\r
+               String ago = null;\r
+               if (isToday(date) || isYesterday(date)) {\r
+                       int mins = minutesAgo(date, true);\r
+                       if (mins > 120) {\r
+                               if (css) {\r
+                                       return "age1";\r
+                               }\r
+                               int hours = hoursAgo(date, true);\r
+                               if (hours > 23) {\r
+                                       ago = "yesterday";\r
+                               } else {\r
+                                       ago = hours + " hour" + (hours > 1 ? "s" : "") + " ago";\r
+                               }\r
+                       } else {\r
+                               if (css) {\r
+                                       return "age0";\r
+                               }\r
+                               ago = mins + " min" + (mins > 1 ? "s" : "") + " ago";\r
+                       }\r
+               } else {\r
+                       if (css) {\r
+                               return "age2";\r
+                       }\r
+                       int days = daysAgo(date, true);\r
+                       if (days < 365) {\r
+                               if (days <= 30) {\r
+                                       ago = days + " day" + (days > 1 ? "s" : "") + " ago";\r
+                               } else if (days <= 90) {\r
+                                       int weeks = days / 7;\r
+                                       if (weeks == 12)\r
+                                               ago = "3 months ago";\r
+                                       else\r
+                                               ago = weeks + " weeks ago";\r
+                               } else if (days > 90) {\r
+                                       int months = days / 30;\r
+                                       int weeks = (days % 30) / 7;\r
+                                       if (weeks >= 2)\r
+                                               months++;\r
+                                       ago = months + " month" + (months > 1 ? "s" : "") + " ago";\r
+                               } else\r
+                                       ago = days + " day" + (days > 1 ? "s" : "") + " ago";\r
+                       } else if (days == 365) {\r
+                               ago = "1 year ago";\r
+                       } else {\r
+                               int yr = days / 365;\r
+                               days = days % 365;\r
+                               int months = (yr * 12) + (days / 30);\r
+                               if (months > 23) {\r
+                                       ago = yr + " years ago";\r
+                               } else {\r
+                                       ago = months + " months ago";\r
+                               }\r
+                       }\r
+               }\r
+               return ago;\r
+       }\r
+}\r
diff --git a/src/com/gitblit/utils/Utils.java b/src/com/gitblit/utils/Utils.java
deleted file mode 100644 (file)
index 6d0c6b3..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-package com.gitblit.utils;\r
-\r
-import java.util.Date;\r
-\r
-public class Utils {\r
-       private final static long min = 1000 * 60l;\r
-\r
-       private final static long halfhour = min * 30l;\r
-\r
-       private final static long onehour = halfhour * 2;\r
-\r
-       private final static long oneday = onehour * 24l;\r
-\r
-       @SuppressWarnings("deprecation")\r
-       public static boolean isToday(Date date) {\r
-               Date now = new Date();\r
-               return now.getDate() == date.getDate() && now.getMonth() == date.getMonth() && now.getYear() == date.getYear();\r
-       }\r
-\r
-       @SuppressWarnings("deprecation")\r
-       public static boolean isYesterday(Date date) {\r
-               Date now = new Date();\r
-               return now.getDate() == (date.getDate() + 1) && now.getMonth() == date.getMonth() && now.getYear() == date.getYear();\r
-       }\r
-\r
-       public static int minutesAgo(Date date, long endTime, boolean roundup) {\r
-               long diff = endTime - date.getTime();\r
-               int mins = (int) (diff / min);\r
-               if (roundup && (diff % min) >= 30)\r
-                       mins++;\r
-               return mins;\r
-       }\r
-\r
-       public static int minutesAgo(Date date, boolean roundup) {\r
-               return minutesAgo(date, System.currentTimeMillis(), roundup);\r
-       }\r
-\r
-       public static int hoursAgo(Date date, boolean roundup) {\r
-               long diff = System.currentTimeMillis() - date.getTime();\r
-               int hours = (int) (diff / onehour);\r
-               if (roundup && (diff % onehour) >= halfhour)\r
-                       hours++;\r
-               return hours;\r
-       }\r
-\r
-       public static int daysAgo(Date date, boolean roundup) {\r
-               long diff = System.currentTimeMillis() - date.getTime();\r
-               int days = (int) (diff / oneday);\r
-               if (roundup && (diff % oneday) > 0)\r
-                       days++;\r
-               return days;\r
-       }\r
-\r
-       public static String timeAgo(Date date) {\r
-               return timeAgo(date, false);\r
-       }\r
-\r
-       public static String timeAgoCss(Date date) {\r
-               return timeAgo(date, true);\r
-       }\r
-\r
-       private static String timeAgo(Date date, boolean css) {\r
-               String ago = null;\r
-               if (isToday(date) || isYesterday(date)) {\r
-                       int mins = minutesAgo(date, true);\r
-                       if (mins > 120) {\r
-                               if (css) {\r
-                                       return "age1";\r
-                               }\r
-                               int hours = hoursAgo(date, true);\r
-                               if (hours > 23) {\r
-                                       ago = "yesterday";\r
-                               } else {\r
-                                       ago = hours + " hour" + (hours > 1 ? "s" : "") + " ago";\r
-                               }\r
-                       } else {\r
-                               if (css) {\r
-                                       return "age0";\r
-                               }\r
-                               ago = mins + " min" + (mins > 1 ? "s" : "") + " ago";\r
-                       }\r
-               } else {\r
-                       if (css) {\r
-                               return "age2";\r
-                       }\r
-                       int days = daysAgo(date, true);\r
-                       if (days < 365) {\r
-                               if (days <= 30) {\r
-                                       ago = days + " day" + (days > 1 ? "s" : "") + " ago";\r
-                               } else if (days <= 90) {\r
-                                       int weeks = days / 7;\r
-                                       if (weeks == 12)\r
-                                               ago = "3 months ago";\r
-                                       else\r
-                                               ago = weeks + " weeks ago";\r
-                               } else if (days > 90) {\r
-                                       int months = days / 30;\r
-                                       int weeks = (days % 30) / 7;\r
-                                       if (weeks >= 2)\r
-                                               months++;\r
-                                       ago = months + " month" + (months > 1 ? "s" : "") + " ago";\r
-                               } else\r
-                                       ago = days + " day" + (days > 1 ? "s" : "") + " ago";\r
-                       } else if (days == 365) {\r
-                               ago = "1 year ago";\r
-                       } else {\r
-                               int yr = days / 365;\r
-                               days = days % 365;\r
-                               int months = (yr * 12) + (days / 30);\r
-                               if (months > 23) {\r
-                                       ago = yr + " years ago";\r
-                               } else {\r
-                                       ago = months + " months ago";\r
-                               }\r
-                       }\r
-               }\r
-               return ago;\r
-       }\r
-\r
-       public static String leftPad(String input, int length, char pad) {\r
-               if (input.length() < length) {\r
-                       StringBuilder sb = new StringBuilder();\r
-                       for (int i = 0, len = length - input.length(); i < len; i++) {\r
-                               sb.append(pad);\r
-                       }\r
-                       sb.append(input);\r
-                       return sb.toString();\r
-               }\r
-               return input;\r
-       }\r
-\r
-       public static String rightPad(String input, int length, char pad) {\r
-               if (input.length() < length) {\r
-                       StringBuilder sb = new StringBuilder();\r
-                       sb.append(input);\r
-                       for (int i = 0, len = length - input.length(); i < len; i++) {\r
-                               sb.append(pad);\r
-                       }\r
-                       return sb.toString();\r
-               }\r
-               return input;\r
-       }\r
-\r
-       public static String escapeForHtml(String inStr, boolean changeSpace) {\r
-               StringBuffer retStr = new StringBuffer();\r
-               int i = 0;\r
-               while (i < inStr.length()) {\r
-                       if (inStr.charAt(i) == '&') {\r
-                               retStr.append("&amp;");\r
-                       } else if (inStr.charAt(i) == '<') {\r
-                               retStr.append("&lt;");\r
-                       } else if (inStr.charAt(i) == '>') {\r
-                               retStr.append("&gt;");\r
-                       } else if (inStr.charAt(i) == '\"') {\r
-                               retStr.append("&quot;");\r
-                       } else if (changeSpace && inStr.charAt(i) == ' ') {\r
-                               retStr.append("&nbsp;");\r
-                       } else if (changeSpace && inStr.charAt(i) == '\t') {\r
-                               retStr.append(" &nbsp; &nbsp;");\r
-                       } else\r
-                               retStr.append(inStr.charAt(i));\r
-                       i++;\r
-               }\r
-               return retStr.toString();\r
-       }\r
-}\r
index b73e849cc8c60cd17c014bb42630084883ad82b0..0a9d652b31dbd95713058f67d28e5aa2e38c559f 100644 (file)
@@ -15,9 +15,15 @@ public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy imp
        @SuppressWarnings({ "unchecked", "rawtypes" })\r
        @Override\r
        protected boolean isPageAuthorized(Class pageClass) {\r
-               if (BasePage.class.isAssignableFrom(pageClass))\r
-                       return isAuthorized(pageClass);\r
-               // Return contruction by default\r
+               if (BasePage.class.isAssignableFrom(pageClass)) {\r
+                       GitBlitWebSession session = GitBlitWebSession.get();\r
+                       if (!session.isLoggedIn())\r
+                               return false;\r
+                       User user = session.getUser();\r
+                       if (pageClass.isAnnotationPresent(AdminPage.class)) {\r
+                               return user.canAdmin();\r
+                       }\r
+               }\r
                return true;\r
        }\r
 \r
@@ -31,15 +37,4 @@ public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy imp
                                throw new RestartResponseAtInterceptPageException(RepositoriesPage.class);\r
                }\r
        }\r
-\r
-       protected boolean isAuthorized(Class<? extends BasePage> pageClass) {\r
-               GitBlitWebSession session = GitBlitWebSession.get();\r
-               if (!session.isLoggedIn())\r
-                       return false;\r
-               User user = session.getUser();\r
-               if (pageClass.isAnnotationPresent(AdminPage.class)) {\r
-\r
-               }\r
-               return true;\r
-       }\r
 }\r
index 9ca9f13e6fdd669776919225366eed37b5b06fdd..c3c56efcbe8e6605b3e84b97d62183967beb8731 100644 (file)
@@ -32,7 +32,7 @@
                        <div style="float:right">\r
                                <a href="http://gitblit.com"><span wicket:id="gbVersion"></span></a> \r
                        </div>\r
-                       <div wicket:id="userText">[user text]</div>\r
+                       <div wicket:id="userPanel">[user panel]</div>\r
                </div>\r
        </body>\r
 </html>
\ No newline at end of file
index 9aa7baa036b1fee0e930bfdcd7b91f08de915c1e..2540ce1870438a760debf546ccdd20d7db9b6b8f 100644 (file)
@@ -12,20 +12,22 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.Constants;\r
+import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
-import com.gitblit.StoredSettings;\r
 import com.gitblit.wicket.pages.SummaryPage;\r
 \r
 public abstract class BasePage extends WebPage {\r
 \r
-       Logger logger = LoggerFactory.getLogger(BasePage.class);\r
+       private final Logger logger;\r
 \r
        public BasePage() {\r
                super();\r
+               logger = LoggerFactory.getLogger(getClass());\r
        }\r
 \r
        public BasePage(PageParameters params) {\r
                super(params);\r
+               logger = LoggerFactory.getLogger(getClass());\r
        }\r
 \r
        protected void setupPage(String repositoryName, String pageName) {\r
@@ -35,7 +37,7 @@ public abstract class BasePage extends WebPage {
                        add(new Label("title", getServerName()));\r
                }\r
                // header\r
-               String siteName = StoredSettings.getString(Keys.web_siteName, Constants.NAME);\r
+               String siteName = GitBlit.self().settings().getString(Keys.web.siteName, Constants.NAME);\r
                if (siteName == null || siteName.trim().length() == 0) {\r
                        siteName = Constants.NAME;\r
                }\r
@@ -45,20 +47,20 @@ public abstract class BasePage extends WebPage {
 \r
                // footer\r
                User user = null;\r
-               if (StoredSettings.getBoolean(Keys.web_authenticate, true)) {\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.authenticate, true)) {\r
                        user = GitBlitWebSession.get().getUser();\r
-                       add(new Label("userText", "Logout " + user.toString()));\r
+                       add(new LinkPanel("userPanel", null, getString("gb.logout") + " " + user.toString(), LogoutPage.class));\r
                } else {\r
-                       add(new Label("userText", ""));\r
+                       add(new Label("userPanel", ""));\r
                }\r
                add(new Label("gbVersion", "v" + Constants.VERSION));\r
-               if (StoredSettings.getBoolean(Keys.server_aggressiveHeapManagement, false)) {\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.aggressiveHeapManagement, false)) {\r
                        System.gc();\r
                }\r
        }\r
 \r
        protected TimeZone getTimeZone() {\r
-               return StoredSettings.getBoolean(Keys.web_useClientTimezone, false) ? GitBlitWebSession.get().getTimezone() : TimeZone.getDefault();\r
+               return GitBlit.self().settings().getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get().getTimezone() : TimeZone.getDefault();\r
        }\r
 \r
        protected String getServerName() {\r
index 8589b75cff1e591d60a29d990024232f8cc385cc..b70c95f803810ef0aeec3593f64e0311bb6bcdb0 100644 (file)
@@ -12,7 +12,6 @@ import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy;
 \r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
-import com.gitblit.StoredSettings;\r
 import com.gitblit.wicket.pages.BlobDiffPage;\r
 import com.gitblit.wicket.pages.BlobPage;\r
 import com.gitblit.wicket.pages.BranchesPage;\r
@@ -36,14 +35,14 @@ public class GitBlitWebApp extends WebApplication {
                super.init();\r
 \r
                // Setup page authorization mechanism\r
-               if (StoredSettings.getBoolean(Keys.web_authenticate, false)) {\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.authenticate, false)) {\r
                        AuthorizationStrategy authStrategy = new AuthorizationStrategy();\r
                        getSecuritySettings().setAuthorizationStrategy(authStrategy);\r
                        getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy);\r
                }\r
 \r
                // Grab Browser info (like timezone, etc)\r
-               if (StoredSettings.getBoolean(Keys.web_useClientTimezone, false)) {\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.useClientTimezone, false)) {\r
                        getRequestCycleSettings().setGatherExtendedBrowserInfo(true);\r
                }\r
 \r
@@ -61,11 +60,15 @@ public class GitBlitWebApp extends WebApplication {
                mount(new MixedParamUrlCodingStrategy("/commitdiff", CommitDiffPage.class, new String[] { "r", "h" }));\r
                mount(new MixedParamUrlCodingStrategy("/patch", PatchPage.class, new String[] { "r", "h", "f" }));\r
 \r
-               // setup extended urls\r
+               // setup ticgit urls\r
                mount(new MixedParamUrlCodingStrategy("/ticgit", TicGitPage.class, new String[] { "r" }));\r
                mount(new MixedParamUrlCodingStrategy("/ticgittkt", TicGitTicketPage.class, new String[] { "r", "h", "f" }));\r
 \r
-               mount(new MixedParamUrlCodingStrategy("/login", LoginPage.class, new String[] {}));\r
+               // setup login/logout urls, if we are using authentication\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.authenticate, true)) {\r
+                       mount(new MixedParamUrlCodingStrategy("/login", LoginPage.class, new String[] {}));\r
+                       mount(new MixedParamUrlCodingStrategy("/logout", LogoutPage.class, new String[] {}));\r
+               }\r
        }\r
 \r
        @Override\r
@@ -90,10 +93,6 @@ public class GitBlitWebApp extends WebApplication {
                return Application.DEPLOYMENT;\r
        }\r
 \r
-       public String getCloneUrl(String repositoryName) {\r
-               return StoredSettings.getString(Keys.git_cloneUrl, "https://localhost/git/") + repositoryName;\r
-       }\r
-\r
        public static GitBlitWebApp get() {\r
                return (GitBlitWebApp) WebApplication.get();\r
        }\r
index 273ff5a7255dd3e070f339dd1a274c98c61cb454..1088891290013a57462572dcc586c11ccdfd4311 100644 (file)
@@ -40,4 +40,8 @@ gb.pagePrevious prev
 gb.pageNext = next\r
 gb.parent = parent\r
 gb.head = HEAD\r
-gb.blame = blame
\ No newline at end of file
+gb.blame = blame\r
+gb.login = Login\r
+gb.logout = Logout\r
+gb.username = Username\r
+gb.password = Password
\ No newline at end of file
index ab55cfdd321a528ce931666018da75a028cdeabe..91f24face9e0cc4d24c1fda019725e1a17ef9efd 100644 (file)
@@ -16,6 +16,10 @@ public class LinkPanel extends Panel {
 \r
        private final IModel<String> labelModel;\r
 \r
+       public LinkPanel(String wicketId, String linkCssClass, String label, Class<? extends WebPage> clazz) {\r
+               this(wicketId, linkCssClass, new Model<String>(label), clazz, null);\r
+       }\r
+       \r
        public LinkPanel(String wicketId, String linkCssClass, String label, Class<? extends WebPage> clazz, PageParameters parameters) {\r
                this(wicketId, linkCssClass, new Model<String>(label), clazz, parameters);\r
        }\r
index adbe64f5b2a223f2bf362c913f6c53c0a1d1d326..7108edbeba124585be057eb491352b32e546fd67 100644 (file)
        <body onload="document.getElementById('username').focus();">\r
        <div>\r
                <center>\r
-                       <img wicket:id="logo" /><br/>\r
+                       <wicket:link>\r
+                               <img src="resources/gitblt2.png" alt="Git:Blit"/><br/>\r
+                       </wicket:link>\r
                        <span style="font-weight:bold;" wicket:id="name">[name]</span><br/>\r
 \r
                        <div>\r
                                <form style="text-align:center;" wicket:id="loginForm">\r
                                        <p/>\r
-                                       Username <input type="text" id="username" wicket:id="username" value=""/>\r
+                                       <wicket:message key="gb.username"></wicket:message>\r
+                                       <input type="text" id="username" wicket:id="username" value=""/>\r
                                        <p/>\r
-                                       Password <input type="password"  wicket:id="password" value=""/>\r
+                                       <wicket:message key="gb.password"></wicket:message>\r
+                                       <input type="password"  wicket:id="password" value=""/>\r
                                        <p/>\r
-                                       <input type="submit" value="Login" />\r
+                                       <input type="submit" value="Login" wicket:message="value:gb.login" />\r
                                        <div style="background-color:#c7c7c7" wicket:id="feedback"></div>\r
                                </form>\r
                        </div>\r
index e3a345cebb2b836623b956ea9bff4d34d9dd963e..3f8206e4012a425decf7c7a8511a688a63c2f6fc 100644 (file)
@@ -1,24 +1,23 @@
 package com.gitblit.wicket;\r
 \r
 import javax.servlet.http.Cookie;\r
-import javax.servlet.http.HttpServletRequest;\r
 \r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.WebPage;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.markup.html.form.Form;\r
 import org.apache.wicket.markup.html.form.PasswordTextField;\r
+import org.apache.wicket.markup.html.form.StatelessForm;\r
 import org.apache.wicket.markup.html.form.TextField;\r
-import org.apache.wicket.markup.html.image.ContextImage;\r
 import org.apache.wicket.markup.html.panel.FeedbackPanel;\r
 import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.Model;\r
 import org.apache.wicket.protocol.http.WebRequest;\r
 import org.apache.wicket.protocol.http.WebResponse;\r
-import org.apache.wicket.protocol.http.servlet.ServletWebRequest;\r
 \r
 import com.gitblit.Constants;\r
 import com.gitblit.GitBlit;\r
+import com.gitblit.Keys;\r
 \r
 public class LoginPage extends WebPage {\r
 \r
@@ -30,8 +29,7 @@ public class LoginPage extends WebPage {
 \r
                tryAutomaticLogin();\r
 \r
-               add(new Label("title", getServerName()));\r
-               add(new ContextImage("logo", "gitblt2.png"));\r
+               add(new Label("title", GitBlit.self().settings().getString(Keys.web.siteName, Constants.NAME)));\r
                add(new Label("name", Constants.NAME));\r
 \r
                Form<Void> loginForm = new LoginForm("loginForm");\r
@@ -41,17 +39,20 @@ public class LoginPage extends WebPage {
                add(loginForm);\r
        }\r
 \r
-       protected String getServerName() {\r
-               ServletWebRequest servletWebRequest = (ServletWebRequest) getRequest();\r
-               HttpServletRequest req = servletWebRequest.getHttpServletRequest();\r
-               return req.getServerName();\r
-       }\r
-\r
-       class LoginForm extends Form<Void> {\r
+       class LoginForm extends StatelessForm<Void> {\r
                private static final long serialVersionUID = 1L;\r
 \r
                public LoginForm(String id) {\r
                        super(id);\r
+\r
+                       // If we are already logged in because user directly accessed\r
+                       // the login url, redirect to the home page\r
+                       if (GitBlitWebSession.get().isLoggedIn()) {\r
+                               setRedirect(true);\r
+                               setResponsePage(getApplication().getHomePage());\r
+                       }\r
+                       \r
+                       tryAutomaticLogin();\r
                }\r
 \r
                @Override\r
@@ -82,20 +83,16 @@ public class LoginPage extends WebPage {
 \r
        private void loginUser(User user) {\r
                if (user != null) {\r
-                       GitBlitWebSession session = GitBlitWebSession.get();\r
+                       // Set the user into the session\r
+                       GitBlitWebSession.get().setUser(user);\r
 \r
                        // Set Cookie\r
                        WebResponse response = (WebResponse) getRequestCycle().getResponse();\r
                        GitBlit.self().setCookie(response, user);\r
 \r
-                       // track user object so that we do not have to continue\r
-                       // re-authenticating on each request.\r
-                       session.setUser(user);\r
-\r
-                       // Redirect to original page OR to first available tab\r
                        if (!continueToOriginalDestination()) {\r
                                // Redirect to home page\r
-                               setResponsePage(session.getApplication().getHomePage());\r
+                               setResponsePage(getApplication().getHomePage());\r
                        }\r
                }\r
        }\r
diff --git a/src/com/gitblit/wicket/LogoutPage.java b/src/com/gitblit/wicket/LogoutPage.java
new file mode 100644 (file)
index 0000000..278fbec
--- /dev/null
@@ -0,0 +1,12 @@
+package com.gitblit.wicket;\r
+\r
+import org.apache.wicket.markup.html.WebPage;\r
+\r
+public class LogoutPage extends WebPage {\r
+\r
+       public LogoutPage() {\r
+               getSession().invalidate();\r
+               setRedirect(true);\r
+               setResponsePage(getApplication().getHomePage());\r
+       }\r
+}
\ No newline at end of file
index e7196690136b355696de43fa225563e51fc129d9..7378543f5ba1f7798d6f42410af2541bbec4c414 100644 (file)
@@ -11,10 +11,13 @@ import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.protocol.http.servlet.ServletWebRequest;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.GitBlit;\r
-import com.gitblit.StoredSettings;\r
+import com.gitblit.Keys;\r
 import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.pages.RepositoriesPage;\r
 import com.gitblit.wicket.panels.PageLinksPanel;\r
 import com.gitblit.wicket.panels.RefsPanel;\r
@@ -27,6 +30,8 @@ public abstract class RepositoryPage extends BasePage {
 \r
        private transient Repository r = null;\r
 \r
+       private final Logger logger = LoggerFactory.getLogger(RepositoryPage.class);\r
+       \r
        public RepositoryPage(PageParameters params) {\r
                super(params);\r
                if (!params.containsKey("r")) {\r
@@ -69,20 +74,24 @@ public abstract class RepositoryPage extends BasePage {
        }\r
 \r
        protected void addFullText(String wicketId, String text, boolean substituteRegex) {\r
-               String html = WicketUtils.breakLines(text);\r
+               String html = StringUtils.breakLinesForHtml(text);\r
                if (substituteRegex) {\r
                        Map<String, String> map = new HashMap<String, String>();\r
                        // global regex keys\r
-                       for (String key : StoredSettings.getAllKeys("regex.global")) {\r
-                               String subKey = key.substring(key.lastIndexOf('.') + 1);\r
-                               map.put(subKey, StoredSettings.getString(key, ""));\r
+                       if (GitBlit.self().settings().getBoolean(Keys.regex.global, false)) {\r
+                               for (String key : GitBlit.self().settings().getAllKeys(Keys.regex.global)) {\r
+                                       if (!key.equals(Keys.regex.global)) {\r
+                                               String subKey = key.substring(key.lastIndexOf('.') + 1);\r
+                                               map.put(subKey, GitBlit.self().settings().getString(key, ""));\r
+                                       }\r
+                               }\r
                        }\r
 \r
                        // repository-specific regex keys\r
-                       List<String> keys = StoredSettings.getAllKeys("regex." + repositoryName.toLowerCase());\r
+                       List<String> keys = GitBlit.self().settings().getAllKeys(Keys.regex._ROOT + "." + repositoryName.toLowerCase());\r
                        for (String key : keys) {\r
                                String subKey = key.substring(key.lastIndexOf('.') + 1);\r
-                               map.put(subKey, StoredSettings.getString(key, ""));\r
+                               map.put(subKey, GitBlit.self().settings().getString(key, ""));\r
                        }\r
 \r
                        for (String key : map.keySet()) {\r
index e506c8cb84eac2a0b9390cb3332bd40cdeac8e60..bd5e8c9249a29e51e0a680abc1d1e8e1ad33525e 100644 (file)
@@ -1,10 +1,14 @@
 package com.gitblit.wicket;\r
 \r
-import com.gitblit.Build;\r
+import java.io.Serializable;\r
+\r
 import com.gitblit.Constants;\r
+import com.gitblit.utils.StringUtils;\r
 \r
-public class User {\r
+public class User implements Serializable {\r
 \r
+       private static final long serialVersionUID = 1L;\r
+       \r
        private String username;\r
        private String cookie;\r
        private boolean canAdmin = false;\r
@@ -13,7 +17,7 @@ public class User {
 \r
        public User(String username, char[] password) {\r
                this.username = username;\r
-               this.cookie = Build.getSHA1((Constants.NAME + username + new String(password)).getBytes());\r
+               this.cookie = StringUtils.getSHA1((Constants.NAME + username + new String(password)));\r
        }\r
 \r
        public void canAdmin(boolean value) {\r
index 27992f138bde17ae116d8f0f969c3bec9e972b85..3288498f11e6652f5f4e59f81b0c97ed355e947a 100644 (file)
@@ -3,7 +3,6 @@ package com.gitblit.wicket;
 import java.text.DateFormat;\r
 import java.text.SimpleDateFormat;\r
 import java.util.Date;\r
-import java.util.List;\r
 import java.util.TimeZone;\r
 \r
 import org.apache.wicket.Component;\r
@@ -12,9 +11,9 @@ import org.apache.wicket.behavior.SimpleAttributeModifier;
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.eclipse.jgit.lib.Constants;\r
 \r
+import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
-import com.gitblit.StoredSettings;\r
-import com.gitblit.utils.Utils;\r
+import com.gitblit.utils.TimeUtils;\r
 \r
 public class WicketUtils {\r
 \r
@@ -30,10 +29,6 @@ public class WicketUtils {
                container.add(new SimpleAttributeModifier("title", value));\r
        }\r
 \r
-       public static String breakLines(String string) {\r
-               return string.replace("\r", "<br/>").replace("\n", "<br/>");\r
-       }\r
-\r
        public static void setTicketCssClass(Component container, String state) {\r
                String css = null;\r
                if (state.equals("open")) {\r
@@ -50,14 +45,6 @@ public class WicketUtils {
                }\r
        }\r
 \r
-       public static String flattenStrings(List<String> values) {\r
-               StringBuilder sb = new StringBuilder();\r
-               for (String value : values) {\r
-                       sb.append(value).append(" ");\r
-               }\r
-               return sb.toString().trim();\r
-       }\r
-\r
        public static void setAlternatingBackground(Component c, int i) {\r
                String clazz = i % 2 == 0 ? "dark" : "light";\r
                setCssClass(c, clazz);\r
@@ -69,17 +56,6 @@ public class WicketUtils {
                return label;\r
        }\r
 \r
-       public static String trimShortLog(String string) {\r
-               return trimString(string, 60);\r
-       }\r
-\r
-       public static String trimString(String value, int max) {\r
-               if (value.length() <= max) {\r
-                       return value;\r
-               }\r
-               return value.substring(0, max - 3) + "...";\r
-       }\r
-\r
        public static PageParameters newRepositoryParameter(String repositoryName) {\r
                return new PageParameters("r=" + repositoryName);\r
        }\r
@@ -122,30 +98,30 @@ public class WicketUtils {
        }\r
 \r
        public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone) {\r
-               DateFormat df = new SimpleDateFormat(StoredSettings.getString(Keys.web_datestampShortFormat, "MM/dd/yy"));\r
+               DateFormat df = new SimpleDateFormat(GitBlit.self().settings().getString(Keys.web.datestampShortFormat, "MM/dd/yy"));\r
                if (timeZone != null) {\r
                        df.setTimeZone(timeZone);\r
                }\r
                String dateString = df.format(date);\r
-               String title = Utils.timeAgo(date);\r
+               String title = TimeUtils.timeAgo(date);\r
                if ((System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000l) {\r
                        String tmp = dateString;\r
                        dateString = title;\r
                        title = tmp;\r
                }\r
                Label label = new Label(wicketId, dateString);\r
-               WicketUtils.setCssClass(label, Utils.timeAgoCss(date));\r
+               WicketUtils.setCssClass(label, TimeUtils.timeAgoCss(date));\r
                WicketUtils.setHtmlTitle(label, title);\r
                return label;\r
        }\r
 \r
        public static Label createTimestampLabel(String wicketId, Date date, TimeZone timeZone) {\r
-               DateFormat df = new SimpleDateFormat(StoredSettings.getString(Keys.web_datetimestampLongFormat, "EEEE, MMMM d, yyyy h:mm a z"));\r
+               DateFormat df = new SimpleDateFormat(GitBlit.self().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy h:mm a z"));\r
                if (timeZone != null) {\r
                        df.setTimeZone(timeZone);\r
                }\r
                String dateString = df.format(date);\r
-               String title = Utils.timeAgo(date);\r
+               String title = TimeUtils.timeAgo(date);\r
                Label label = new Label(wicketId, dateString);\r
                WicketUtils.setHtmlTitle(label, title);\r
                return label;\r
index 51749a362a9d2322836accaa72f658c0a5ea1955..51eadf33bea53f1dc209bae77966faf7731078ac 100644 (file)
@@ -11,8 +11,8 @@ import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
+import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
-import com.gitblit.StoredSettings;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.RepositoryPage;\r
@@ -45,13 +45,13 @@ public class BlobPage extends RepositoryPage {
 \r
                // Map the extensions to types\r
                Map<String, Integer> map = new HashMap<String, Integer>();\r
-               for (String ext : StoredSettings.getStrings(Keys.web_prettyPrintExtensions)) {\r
+               for (String ext : GitBlit.self().settings().getStrings(Keys.web.prettyPrintExtensions)) {\r
                        map.put(ext.toLowerCase(), 1);\r
                }\r
-               for (String ext : StoredSettings.getStrings(Keys.web_imageExtensions)) {\r
+               for (String ext : GitBlit.self().settings().getStrings(Keys.web.imageExtensions)) {\r
                        map.put(ext.toLowerCase(), 2);\r
                }\r
-               for (String ext : StoredSettings.getStrings(Keys.web_binaryExtensions)) {\r
+               for (String ext : GitBlit.self().settings().getStrings(Keys.web.binaryExtensions)) {\r
                        map.put(ext.toLowerCase(), 3);\r
                }\r
 \r
index 961e4c94ced0baa8a1e75fbf3bd7107eee83759a..4cbf96ca53f52916a289b99eb401c1c1dfd91585 100644 (file)
@@ -15,7 +15,6 @@ import org.eclipse.jgit.revwalk.RevCommit;
 \r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
-import com.gitblit.StoredSettings;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
@@ -52,10 +51,10 @@ public class RawPage extends WebPage {
 \r
                // Map the extensions to types\r
                Map<String, Integer> map = new HashMap<String, Integer>();\r
-               for (String ext : StoredSettings.getStrings(Keys.web_imageExtensions)) {\r
+               for (String ext : GitBlit.self().settings().getStrings(Keys.web.imageExtensions)) {\r
                        map.put(ext.toLowerCase(), 2);\r
                }\r
-               for (String ext : StoredSettings.getStrings(Keys.web_binaryExtensions)) {\r
+               for (String ext : GitBlit.self().settings().getStrings(Keys.web.binaryExtensions)) {\r
                        map.put(ext.toLowerCase(), 3);\r
                }\r
 \r
index eca216c9bb366737664361a8b8dff15f84102a2b..fd7ab52d3c76e941c131f72cd600eb5f49bbc0bf 100644 (file)
@@ -19,8 +19,7 @@ import org.apache.wicket.model.Model;
 \r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
-import com.gitblit.StoredSettings;\r
-import com.gitblit.utils.Utils;\r
+import com.gitblit.utils.TimeUtils;\r
 import com.gitblit.wicket.BasePage;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.LinkPanel;\r
@@ -34,11 +33,11 @@ public class RepositoriesPage extends BasePage {
                setupPage("", "");\r
 \r
                boolean showAdmin = false;\r
-               if (StoredSettings.getBoolean(Keys.web_authenticate, true)) {\r
-                       boolean allowAdmin = StoredSettings.getBoolean(Keys.web_allowAdministration, false);\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.authenticate, true)) {\r
+                       boolean allowAdmin = GitBlit.self().settings().getBoolean(Keys.web.allowAdministration, false);\r
                        showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();\r
                } else {\r
-                       showAdmin = StoredSettings.getBoolean(Keys.web_allowAdministration, false);\r
+                       showAdmin = GitBlit.self().settings().getBoolean(Keys.web.allowAdministration, false);\r
                }\r
 \r
                Fragment adminLinks = new Fragment("adminPanel", "adminLinks", this);\r
@@ -46,7 +45,7 @@ public class RepositoriesPage extends BasePage {
                adminLinks.add(new BookmarkablePageLink<Void>("newUser", RepositoriesPage.class));\r
                add(adminLinks.setVisible(showAdmin));\r
 \r
-               add(new Label("repositoriesMessage", StoredSettings.getString(Keys.web_repositoriesMessage, "")).setEscapeModelStrings(false));\r
+               add(new Label("repositoriesMessage", GitBlit.self().settings().getString(Keys.web.repositoriesMessage, "")).setEscapeModelStrings(false));\r
 \r
                List<RepositoryModel> rows = GitBlit.self().getRepositories(getRequest());\r
                DataProvider dp = new DataProvider(rows);\r
@@ -61,10 +60,10 @@ public class RepositoriesPage extends BasePage {
                                item.add(new LinkPanel("repositoryDescription", "list", entry.description, SummaryPage.class, pp));\r
                                item.add(new Label("repositoryOwner", entry.owner));\r
 \r
-                               String lastChange = Utils.timeAgo(entry.lastChange);\r
+                               String lastChange = TimeUtils.timeAgo(entry.lastChange);\r
                                Label lastChangeLabel = new Label("repositoryLastChange", lastChange);\r
                                item.add(lastChangeLabel);\r
-                               WicketUtils.setCssClass(lastChangeLabel, Utils.timeAgoCss(entry.lastChange));\r
+                               WicketUtils.setCssClass(lastChangeLabel, TimeUtils.timeAgoCss(entry.lastChange));\r
 \r
                                WicketUtils.setAlternatingBackground(item, counter);\r
                                counter++;\r
index 50de96ec12ef57cbbbeea4add12327333228a3ff..6d28df6e51525a3b6f0ae7fa5bf6da87d0ff31ee 100644 (file)
@@ -15,10 +15,9 @@ import com.codecommit.wicket.ChartAxisType;
 import com.codecommit.wicket.ChartProvider;\r
 import com.codecommit.wicket.ChartType;\r
 import com.codecommit.wicket.IChartData;\r
+import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
-import com.gitblit.StoredSettings;\r
 import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.wicket.GitBlitWebApp;\r
 import com.gitblit.wicket.RepositoryPage;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.models.Metric;\r
@@ -34,12 +33,12 @@ public class SummaryPage extends RepositoryPage {
                int numCommitsDef = 20;\r
                int numRefsDef = 5;\r
 \r
-               int numberCommits = StoredSettings.getInteger(Keys.web_summaryCommitCount, numCommitsDef);\r
+               int numberCommits = GitBlit.self().settings().getInteger(Keys.web.summaryCommitCount, numCommitsDef);\r
                if (numberCommits <= 0) {\r
                        numberCommits = numCommitsDef;\r
                }\r
 \r
-               int numberRefs = StoredSettings.getInteger(Keys.web_summaryRefsCount, numRefsDef);\r
+               int numberRefs = GitBlit.self().settings().getInteger(Keys.web.summaryRefsCount, numRefsDef);\r
                if (numberRefs <= 0) {\r
                        numberRefs = numRefsDef;\r
                }\r
@@ -57,7 +56,7 @@ public class SummaryPage extends RepositoryPage {
                add(new Label("repositoryOwner", JGitUtils.getRepositoryOwner(r)));\r
 \r
                add(WicketUtils.createTimestampLabel("repositoryLastChange", JGitUtils.getLastChange(r), getTimeZone()));\r
-               add(new Label("repositoryCloneUrl", GitBlitWebApp.get().getCloneUrl(repositoryName)));\r
+               add(new Label("repositoryCloneUrl", GitBlit.self().getCloneUrl(repositoryName)));\r
 \r
                add(new LogPanel("commitsPanel", repositoryName, null, r, numberCommits, 0));\r
                add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs));\r
@@ -73,7 +72,7 @@ public class SummaryPage extends RepositoryPage {
        }\r
 \r
        private void insertActivityGraph(List<Metric> metrics) {\r
-               if (StoredSettings.getBoolean(Keys.web_generateActivityGraph, true)) {\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.generateActivityGraph, true)) {\r
                        IChartData data = getChartData(metrics);\r
 \r
                        ChartProvider provider = new ChartProvider(new Dimension(400, 80), ChartType.LINE, data);\r
index 204565c66030b881cb990010553acad4203d2789..a03ee60711e1c89fa6fdb19129cfa631e76adab4 100644 (file)
@@ -9,6 +9,7 @@ import org.apache.wicket.markup.repeater.data.DataView;
 import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
 \r
 import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.RepositoryPage;\r
@@ -36,8 +37,8 @@ public class TicGitPage extends RepositoryPage {
                                WicketUtils.setTicketCssClass(stateLabel, entry.state);\r
                                item.add(stateLabel);\r
                                item.add(WicketUtils.createDateLabel("ticketDate", entry.date, GitBlitWebSession.get().getTimezone()));\r
-                               item.add(new Label("ticketHandler", WicketUtils.trimString(entry.handler.toLowerCase(), 30)));\r
-                               item.add(new LinkPanel("ticketTitle", "list subject", WicketUtils.trimString(entry.title, 80), TicGitTicketPage.class, newPathParameter(entry.name)));\r
+                               item.add(new Label("ticketHandler", StringUtils.trimString(entry.handler.toLowerCase(), 30)));\r
+                               item.add(new LinkPanel("ticketTitle", "list subject", StringUtils.trimString(entry.title, 80), TicGitTicketPage.class, newPathParameter(entry.name)));\r
 \r
                                WicketUtils.setAlternatingBackground(item, counter);\r
                                counter++;\r
index aafbf8c05bd7a47b916d1b6711fe8bb3c7a152c2..56e298040016ed8d639b8cccbeff820f76b56be3 100644 (file)
@@ -29,8 +29,9 @@
        <table style="width:100%;" class="comments">\r
                <tbody>\r
                        <tr valign="top" wicket:id="comment">\r
-                       <td><span class="date" wicket:id="commentDate">[comment date]</span><br/>\r
-                       <span class="author" wicket:id="commentAuthor">[comment author]</span></td>\r
+                       <td><span class="author" wicket:id="commentAuthor">[comment author]</span><br/>\r
+                               <span class="date" wicket:id="commentDate">[comment date]</span>\r
+                       </td>\r
                        <td><span wicket:id="commentText">[comment text]</span></td>\r
                        </tr>\r
                </tbody>\r
index 30bd6ccfdd6f3323de62ca1de8faa43ae70a79e6..b4c9cf55e622073a3064814c193e60eb431d648d 100644 (file)
@@ -8,7 +8,7 @@ import org.apache.wicket.markup.repeater.data.ListDataProvider;
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.utils.Utils;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.RepositoryPage;\r
 import com.gitblit.wicket.WicketUtils;\r
@@ -32,7 +32,7 @@ public class TicGitTicketPage extends RepositoryPage {
                Label stateLabel = new Label("ticketState", t.state);\r
                WicketUtils.setTicketCssClass(stateLabel, t.state);\r
                add(stateLabel);\r
-               add(new Label("ticketTags", WicketUtils.flattenStrings(t.tags)));\r
+               add(new Label("ticketTags", StringUtils.flattenStrings(t.tags)));\r
 \r
                ListDataProvider<Comment> commentsDp = new ListDataProvider<Comment>(t.comments);\r
                DataView<Comment> commentsView = new DataView<Comment>("comment", commentsDp) {\r
@@ -57,8 +57,8 @@ public class TicGitTicketPage extends RepositoryPage {
        }\r
 \r
        private String prepareComment(String comment) {\r
-               String html = Utils.escapeForHtml(comment, false);\r
-               html = WicketUtils.breakLines(comment).trim();\r
+               String html = StringUtils.escapeForHtml(comment, false);\r
+               html = StringUtils.breakLinesForHtml(comment).trim();\r
                return html.replaceAll("\\bcommit\\s*([A-Za-z0-9]*)\\b", "<a href=\"/commit/" + repositoryName + "/$1\">commit $1</a>");\r
        }\r
 }\r
index cdfc050c3ff120c9f5b2a1593761916159227fdd..6ddc0a072cf67b91dc9b279637d0ce9dc22f9742 100644 (file)
@@ -4,8 +4,8 @@ import java.util.TimeZone;
 \r
 import org.apache.wicket.markup.html.panel.Panel;\r
 \r
+import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
-import com.gitblit.StoredSettings;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 \r
 public abstract class BasePanel extends Panel {\r
@@ -17,6 +17,6 @@ public abstract class BasePanel extends Panel {
        }\r
 \r
        protected TimeZone getTimeZone() {\r
-               return StoredSettings.getBoolean(Keys.web_useClientTimezone, false) ? GitBlitWebSession.get().getTimezone() : TimeZone.getDefault();\r
+               return GitBlit.self().settings().getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get().getTimezone() : TimeZone.getDefault();\r
        }\r
 }\r
index 8ac78e4cc27e744a357bfafa8b91c8e50ef72b21..ff4679f5eeee6cb8235e38a4d3603858c305ba71 100644 (file)
@@ -14,6 +14,7 @@ import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.models.RefModel;\r
@@ -59,7 +60,7 @@ public class BranchesPanel extends BasePanel {
 \r
                                item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone()));\r
 \r
-                               item.add(new LinkPanel("branchName", "list name", WicketUtils.trimString(entry.getDisplayName(), 28), LogPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
+                               item.add(new LinkPanel("branchName", "list name", StringUtils.trimString(entry.getDisplayName(), 28), LogPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
 \r
                                // only show branch type on the branches page\r
                                boolean remote = entry.getName().startsWith(Constants.R_REMOTES);\r
index 504bdd3ad500da27ed445f1428c9a8c3095ca8f9..2075410804c62bce31228ed1af5779cda612ff91 100644 (file)
@@ -14,9 +14,10 @@ import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
+import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
-import com.gitblit.StoredSettings;\r
 import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.pages.CommitDiffPage;\r
@@ -32,7 +33,7 @@ public class LogPanel extends BasePanel {
        public LogPanel(String wicketId, final String repositoryName, String objectId, Repository r, int limit, int pageOffset) {\r
                super(wicketId);\r
                boolean pageResults = limit <= 0;\r
-               int itemsPerPage = StoredSettings.getInteger(Keys.web_logPageCommitCount, 50);\r
+               int itemsPerPage = GitBlit.self().settings().getInteger(Keys.web.logPageCommitCount, 50);\r
                if (itemsPerPage <= 1) {\r
                        itemsPerPage = 50;\r
                }\r
@@ -73,7 +74,7 @@ public class LogPanel extends BasePanel {
                                item.add(WicketUtils.createAuthorLabel("commitAuthor", author));\r
 \r
                                String shortMessage = entry.getShortMessage();\r
-                               String trimmedMessage = WicketUtils.trimShortLog(shortMessage);\r
+                               String trimmedMessage = StringUtils.trimShortLog(shortMessage);\r
                                LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject", trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName()));\r
                                if (!shortMessage.equals(trimmedMessage)) {\r
                                        WicketUtils.setHtmlTitle(shortlog, shortMessage);\r
index 252b49a4934b6c552752d9e4eb1e6e417e9b8799..18cfad6246e6693bc27e3c4df46be98ac6d12b13 100644 (file)
@@ -15,7 +15,8 @@ import org.apache.wicket.markup.repeater.data.DataView;
 import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
 import org.eclipse.jgit.lib.Repository;\r
 \r
-import com.gitblit.StoredSettings;\r
+import com.gitblit.GitBlit;\r
+import com.gitblit.Keys;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.WicketUtils;\r
@@ -55,8 +56,8 @@ public class PageLinksPanel extends Panel {
                add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils.newRepositoryParameter(repositoryName)));\r
 \r
                // Get the repository ticgit setting\r
-               boolean checkTicgit = StoredSettings.getBoolean("ticgit.global", false);\r
-               checkTicgit |= StoredSettings.getBoolean(MessageFormat.format("ticgit.{0}", repositoryName), false);\r
+               boolean checkTicgit = GitBlit.self().settings().getBoolean(Keys.ticgit.global, false);\r
+               checkTicgit |= GitBlit.self().settings().getBoolean(MessageFormat.format(Keys.ticgit._ROOT + ".{0}", repositoryName), false);\r
 \r
                // Add dynamic repository extras\r
                List<String> extras = new ArrayList<String>();\r
index 3d8364cd905e6b56a6401cdc4e62613492ac8ca6..979a27527240d9f8418ab9e18ffdcdab74e00703 100644 (file)
@@ -11,6 +11,7 @@ import org.apache.wicket.model.StringResourceModel;
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.models.RefModel;\r
@@ -52,7 +53,7 @@ public class TagsPanel extends BasePanel {
                                item.add(new LinkPanel("tagName", "list name", entry.getDisplayName(), CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getCommitId().getName())));\r
                                String message;\r
                                if (maxCount > 0) {\r
-                                       message = WicketUtils.trimString(entry.getShortLog(), 40);\r
+                                       message = StringUtils.trimString(entry.getShortLog(), 40);\r
                                } else {\r
                                        message = entry.getShortLog();\r
                                }\r