]> source.dussan.org Git - gitblit.git/commitdiff
Documentation. Unit testing. Checkstyle. Findbugs.
authorJames Moger <james.moger@gitblit.com>
Fri, 22 Jul 2011 13:37:14 +0000 (09:37 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 22 Jul 2011 13:37:14 +0000 (09:37 -0400)
36 files changed:
docs/00_index.mkd
src/com/gitblit/AccessRestrictionFilter.java
src/com/gitblit/Constants.java
src/com/gitblit/DownloadZipServlet.java
src/com/gitblit/GitBlitException.java
src/com/gitblit/GitBlitServer.java
src/com/gitblit/IStoredSettings.java
src/com/gitblit/MakeCertificate.java
src/com/gitblit/build/Build.java
src/com/gitblit/build/BuildSite.java
src/com/gitblit/build/BuildThumbnails.java
src/com/gitblit/build/BuildWebXml.java
src/com/gitblit/utils/DiffUtils.java
src/com/gitblit/utils/FileUtils.java
src/com/gitblit/utils/JGitUtils.java
src/com/gitblit/utils/MarkdownUtils.java
src/com/gitblit/utils/PatchFormatter.java
src/com/gitblit/utils/TimeUtils.java
src/com/gitblit/wicket/GitBlitWebApp.java
src/com/gitblit/wicket/GitblitParamUrlCodingStrategy.java
src/com/gitblit/wicket/pages/BasePage.java
src/com/gitblit/wicket/pages/ChangePasswordPage.java
src/com/gitblit/wicket/pages/EditRepositoryPage.java
src/com/gitblit/wicket/pages/EditUserPage.java
src/com/gitblit/wicket/pages/LogoutPage.java
src/com/gitblit/wicket/pages/RepositoriesPage.java
src/com/gitblit/wicket/pages/SummaryPage.java
src/com/gitblit/wicket/panels/BranchesPanel.java
src/com/gitblit/wicket/panels/RepositoriesPanel.java
src/com/gitblit/wicket/panels/TagsPanel.java
tests/com/gitblit/tests/FileUtilsTest.java [new file with mode: 0644]
tests/com/gitblit/tests/GitBlitSuite.java
tests/com/gitblit/tests/GitBlitTest.java
tests/com/gitblit/tests/MetricUtilsTest.java
tests/com/gitblit/tests/StringUtilsTest.java
tests/com/gitblit/tests/SyndicationUtilsTest.java

index 2be3b061d42edcd9ad61d18f0cd335e5d59da3db..a6559b21b5f339f547a5d28b8aae9f74d79c7331 100644 (file)
@@ -34,7 +34,7 @@ Gitblit requires a Java 6 Runtime Environment (JRE) or a Java 6 Development Kit
 - updated: MarkdownPapers 1.1.0\r
 - updated: Jetty 7.4.3\r
 \r
-issues & binaries @ [Google Code][googlecode]<br/>\r
+issues, binaries, and sources @ [Google Code][googlecode]<br/>\r
 sources @ [Github][gitbltsrc]\r
 \r
 ### License\r
index 74571789e7c392f9ec2c3868aa886037f542154a..6ec70dbd3aa6f1d5f80ed7a370a5e97a66aad893 100644 (file)
@@ -108,7 +108,8 @@ public abstract class AccessRestrictionFilter implements Filter {
         * doFilter does the actual work of preprocessing the request to ensure that\r
         * the user may proceed.\r
         * \r
-        * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)\r
+        * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,\r
+        *      javax.servlet.ServletResponse, javax.servlet.FilterChain)\r
         */\r
        @Override\r
        public void doFilter(final ServletRequest request, final ServletResponse response,\r
index 766f7c20c091e1a0f5d1e88cee4920a2349582eb..4297dbd9f117af5f5057e7a006ee9ebd0895f28d 100644 (file)
@@ -51,6 +51,9 @@ public class Constants {
 \r
        public static final String BORDER = "***********************************************************";\r
 \r
+       /**\r
+        * Enumeration representing the 4 access restriction levels.\r
+        */\r
        public static enum AccessRestrictionType {\r
                NONE, PUSH, CLONE, VIEW;\r
 \r
index 32369ae1f1729f3b6e1dbaa63a1af014d15441c8..5f2a2a4b7365db20cacf27525cfdfe9d27b9d370 100644 (file)
@@ -38,7 +38,7 @@ import com.gitblit.utils.StringUtils;
  * protected by an AccessRestrictionFilter. It performs its own authorization\r
  * check, but it does not perform any authentication. The assumption is that\r
  * requests to this servlet are made via the web ui and not by direct url\r
- * access.  Unauthorized requests fail with a standard 403 (FORBIDDEN) code.\r
+ * access. Unauthorized requests fail with a standard 403 (FORBIDDEN) code.\r
  * \r
  * @author James Moger\r
  * \r
index 0cfc78252b37a8ac1dac85550618865906263353..032e41f7e2c333c336f6b00a98dbc11547adc1c3 100644 (file)
 package com.gitblit;\r
 \r
 /**\r
- * GitBlitException is a marginally useful class.  :)\r
+ * GitBlitException is a marginally useful class. :)\r
  * \r
  * @author James Moger\r
- *\r
+ * \r
  */\r
 public class GitBlitException extends Exception {\r
 \r
index 92305fc7db44c05caf80a2a973eab6b8e4425664..2caaaf648412f145c094c296c7f8084f09efc20a 100644 (file)
@@ -176,7 +176,7 @@ public class GitBlitServer {
                                }\r
                                if (params.securePort < 1024 && !isWindows()) {\r
                                        logger.warn("Gitblit needs to run with ROOT permissions for ports < 1024!");\r
-                               }                               \r
+                               }\r
                                connectors.add(secureConnector);\r
                        } else {\r
                                logger.warn("Failed to find or load Keystore?");\r
@@ -315,7 +315,7 @@ public class GitBlitServer {
                connector.setMaxIdleTime(30000);\r
                return connector;\r
        }\r
-       \r
+\r
        /**\r
         * Tests to see if the operating system is Windows.\r
         * \r
@@ -376,6 +376,9 @@ public class GitBlitServer {
                }\r
        }\r
 \r
+       /**\r
+        * JCommander Parameters class for GitBlitServer.\r
+        */\r
        @Parameters(separators = " ")\r
        private static class Params {\r
 \r
index 0cc4bb46757e6f00b29ed06c1f31c0aad0e008ad..be836c9baf947a87cf7c7f208fb5ca6fa34f738f 100644 (file)
@@ -116,7 +116,7 @@ public abstract class IStoredSettings {
                }\r
                return defaultValue;\r
        }\r
-       \r
+\r
        /**\r
         * Returns the char value for the specified key. If the key does not exist\r
         * or the value for the key can not be interpreted as a char, the\r
index 894f7a84a69ee8cbe5117e50f7839217a99cabb3..f2fc73004baa963681209d0c7938b3080aeea93d 100644 (file)
@@ -47,7 +47,7 @@ import com.gitblit.utils.TimeUtils;
  * Utility class to generate self-signed certificates.\r
  * \r
  * @author James Moger\r
- *\r
+ * \r
  */\r
 public class MakeCertificate {\r
 \r
@@ -63,7 +63,8 @@ public class MakeCertificate {
                        jc.usage();\r
                }\r
                File keystore = new File("keystore");\r
-               generateSelfSignedCertificate(params.hostname, keystore, params.storePassword, params.subject);\r
+               generateSelfSignedCertificate(params.hostname, keystore, params.storePassword,\r
+                               params.subject);\r
        }\r
 \r
        public static void generateSelfSignedCertificate(String hostname, File keystore,\r
@@ -159,6 +160,9 @@ public class MakeCertificate {
                }\r
        }\r
 \r
+       /**\r
+        * JCommander Parameters class for MakeCertificate.\r
+        */\r
        @Parameters(separators = " ")\r
        private static class Params {\r
 \r
index 22d61b5cca708f5a28a9f29d71e0df75c57ea7cd..66bf49a1c02f891744def9c4c500787d28c99bbe 100644 (file)
@@ -49,6 +49,11 @@ import com.gitblit.utils.StringUtils;
  */\r
 public class Build {\r
 \r
+       /**\r
+        * BuildType enumeration representing compile-time or runtime. This is used\r
+        * to download dependencies either for Gitblit GO runtime or for setting up\r
+        * a development environment.\r
+        */\r
        public static enum BuildType {\r
                RUNTIME, COMPILETIME;\r
        }\r
@@ -320,6 +325,11 @@ public class Build {
                System.out.print("] " + url);\r
        }\r
 \r
+       /**\r
+        * MavenObject represents a complete maven artifact (binary, sources, and\r
+        * javadoc). MavenObjects can be downloaded and checksummed to confirm\r
+        * authenticity.\r
+        */\r
        private static class MavenObject {\r
 \r
                public static final MavenObject JCOMMANDER = new MavenObject("jCommander", "com/beust",\r
index c3a7f5f88a8c444dfdba4c6967d76c34662a1ae8..dca511686a975530e7e7ca18af6ef9ce710710b4 100644 (file)
@@ -55,11 +55,11 @@ import com.gitblit.utils.StringUtils;
  */\r
 public class BuildSite {\r
 \r
-       private final static String CASE_SENSITIVE = "CASE-SENSITIVE";\r
+       private static final String CASE_SENSITIVE = "CASE-SENSITIVE";\r
 \r
-       private final static String RESTART_REQUIRED = "RESTART REQUIRED";\r
+       private static final String RESTART_REQUIRED = "RESTART REQUIRED";\r
 \r
-       private final static String SINCE = "SINCE";\r
+       private static final String SINCE = "SINCE";\r
 \r
        public static void main(String... args) {\r
                Params params = new Params();\r
@@ -135,10 +135,10 @@ public class BuildSite {
                                if (!params.skips.contains(documentName)) {\r
                                        String fileName = documentName + ".html";\r
                                        System.out.println(MessageFormat.format("  {0} => {1}", file.getName(),\r
-                                                       fileName));                                     \r
+                                                       fileName));\r
                                        String rawContent = FileUtils.readContent(file, "\n");\r
                                        String markdownContent = rawContent;\r
-                                       \r
+\r
                                        Map<String, List<String>> nomarkdownMap = new HashMap<String, List<String>>();\r
 \r
                                        // extract sections marked as no-markdown\r
@@ -159,8 +159,9 @@ public class BuildSite {
                                                        if (endCode == 0) {\r
                                                                strippedContent.append(markdownContent.substring(0, beginCode));\r
                                                        } else {\r
-                                                               strippedContent.append(markdownContent.substring(endCode, beginCode));\r
-                                                       }                                                       \r
+                                                               strippedContent.append(markdownContent\r
+                                                                               .substring(endCode, beginCode));\r
+                                                       }\r
                                                        strippedContent.append(nomarkdownKey);\r
                                                        endCode = markdownContent.indexOf(endToken, beginCode);\r
                                                        chunks.add(markdownContent.substring(beginCode, endCode));\r
@@ -169,27 +170,28 @@ public class BuildSite {
 \r
                                                // get remainder of text\r
                                                if (endCode < markdownContent.length()) {\r
-                                                       strippedContent.append(markdownContent.substring(endCode, markdownContent.length()));\r
+                                                       strippedContent.append(markdownContent.substring(endCode,\r
+                                                                       markdownContent.length()));\r
                                                }\r
                                                markdownContent = strippedContent.toString();\r
-                                               nmd++;                                          \r
+                                               nmd++;\r
                                        }\r
 \r
                                        // transform markdown to html\r
                                        String content = transformMarkdown(markdownContent.toString());\r
 \r
                                        // reinsert nomarkdown chunks\r
-                                       for (Map.Entry<String, List<String>> nomarkdown: nomarkdownMap.entrySet()) {\r
-                                               for (String chunk:nomarkdown.getValue()) {\r
+                                       for (Map.Entry<String, List<String>> nomarkdown : nomarkdownMap.entrySet()) {\r
+                                               for (String chunk : nomarkdown.getValue()) {\r
                                                        content = content.replaceFirst(nomarkdown.getKey(), chunk);\r
                                                }\r
                                        }\r
-                                       \r
+\r
                                        for (String token : params.substitutions) {\r
                                                String[] kv = token.split("=", 2);\r
                                                content = content.replace(kv[0], kv[1]);\r
                                        }\r
-                                       for (String token:params.regex) {\r
+                                       for (String token : params.regex) {\r
                                                String[] kv = token.split("!!!", 2);\r
                                                content = content.replaceAll(kv[0], kv[1]);\r
                                        }\r
@@ -199,7 +201,7 @@ public class BuildSite {
                                                content = content.replace(kv[0], loadedContent);\r
                                        }\r
                                        for (String alias : params.loads) {\r
-                                               String[] kv = alias.split("=" ,2);\r
+                                               String[] kv = alias.split("="2);\r
                                                String loadedContent = FileUtils.readContent(new File(kv[1]), "\n");\r
                                                loadedContent = StringUtils.escapeForHtml(loadedContent, false);\r
                                                loadedContent = StringUtils.breakLinesForHtml(loadedContent);\r
@@ -264,21 +266,26 @@ public class BuildSite {
                        for (String comment : setting.comments) {\r
                                if (comment.contains(SINCE) || comment.contains(RESTART_REQUIRED)\r
                                                || comment.contains(CASE_SENSITIVE)) {\r
-                                       sb.append(MessageFormat.format("<span style=\"color:#004000;\"># <i>{0}</i></span>", transformMarkdown(comment)));\r
+                                       sb.append(MessageFormat.format(\r
+                                                       "<span style=\"color:#004000;\"># <i>{0}</i></span>",\r
+                                                       transformMarkdown(comment)));\r
                                } else {\r
-                                       sb.append(MessageFormat.format("<span style=\"color:#004000;\"># {0}</span>", transformMarkdown(comment)));\r
+                                       sb.append(MessageFormat.format("<span style=\"color:#004000;\"># {0}</span>",\r
+                                                       transformMarkdown(comment)));\r
                                }\r
                                sb.append("<br/>\n");\r
                        }\r
                        if (!StringUtils.isEmpty(setting.name)) {\r
-                               sb.append(MessageFormat.format("<span style=\"color:#000080;\">{0}</span> = <span style=\"color:#800000;\">{1}</span>", setting.name, StringUtils.escapeForHtml(setting.value, false)));\r
+                               sb.append(MessageFormat\r
+                                               .format("<span style=\"color:#000080;\">{0}</span> = <span style=\"color:#800000;\">{1}</span>",\r
+                                                               setting.name, StringUtils.escapeForHtml(setting.value, false)));\r
                        }\r
                        sb.append("<br/>\n");\r
                }\r
 \r
                return sb.toString();\r
        }\r
-       \r
+\r
        private static String transformMarkdown(String comment) throws ParseException {\r
                String md = MarkdownUtils.transformMarkdown(comment);\r
                if (md.startsWith("<p>")) {\r
@@ -303,6 +310,9 @@ public class BuildSite {
                System.exit(0);\r
        }\r
 \r
+       /**\r
+        * Setting represents a setting with its comments from the properties file.\r
+        */\r
        private static class Setting {\r
                final String name;\r
                final String value;\r
@@ -315,6 +325,9 @@ public class BuildSite {
                }\r
        }\r
 \r
+       /**\r
+        * JCommander Parameters class for BuildSite.\r
+        */\r
        @Parameters(separators = " ")\r
        private static class Params {\r
 \r
index 0676ecafab91994f3321d4342e5c4ecc2a744169..fe06c6ca1ac24c12d4e670fc7cd956829d323f23 100644 (file)
@@ -65,8 +65,9 @@ public class BuildThumbnails {
         */\r
        public static void createImageThumbnail(String sourceFolder, String destinationFolder,\r
                        int maxDimension) {\r
-               if (maxDimension <= 0)\r
+               if (maxDimension <= 0) {\r
                        return;\r
+               }\r
                File source = new File(sourceFolder);\r
                File destination = new File(destinationFolder);\r
                destination.mkdirs();\r
@@ -135,12 +136,16 @@ public class BuildThumbnails {
                                }\r
                        }\r
                } finally {\r
-                       if (in != null)\r
+                       if (in != null) {\r
                                in.close();\r
+                       }\r
                }\r
                return null;\r
        }\r
 \r
+       /**\r
+        * JCommander Parameters class for BuildThumbnails.\r
+        */\r
        @Parameters(separators = " ")\r
        private static class Params {\r
 \r
index e53a4aff0e32cf428a5acc172257ce9a3081758c..4fcc6e97564e3ebec2c63a770e24ea2ecf948961 100644 (file)
@@ -126,6 +126,9 @@ public class BuildWebXml {
                return key.startsWith(Keys.server._ROOT);\r
        }\r
 \r
+       /**\r
+        * Setting represents a setting and its comments from the properties file.\r
+        */\r
        private static class Setting {\r
                final String name;\r
                final String value;\r
@@ -138,6 +141,9 @@ public class BuildWebXml {
                }\r
        }\r
 \r
+       /**\r
+        * JCommander Parameters class for BuildWebXml.\r
+        */\r
        @Parameters(separators = " ")\r
        private static class Params {\r
 \r
index beeb5323f96fc234e05350455789686eb24639f6..9f0d04fc43a8ea05e1cb423d99c2591629bee0d9 100644 (file)
@@ -48,6 +48,9 @@ public class DiffUtils {
 \r
        private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class);\r
 \r
+       /**\r
+        * Enumeration for the diff output types.\r
+        */\r
        public static enum DiffOutputType {\r
                PLAIN, GITWEB, GITBLIT;\r
 \r
index ce8cdf94d82874c193fb51f6f9ea744af080075b..310e35a9a44e2f6b9832be509248679e64a924c7 100644 (file)
@@ -73,10 +73,11 @@ public class FileUtils {
                }\r
                long length = 0;\r
                for (File file : directory.listFiles()) {\r
-                       if (file.isFile())\r
+                       if (file.isFile()) {\r
                                length += file.length();\r
-                       else\r
+                       } else {\r
                                length += folderSize(file);\r
+                       }\r
                }\r
                return length;\r
        }\r
index 2e14b6792fe87f2bf830958feccf1b6c050222b7..a72299ddb947c20d85287966d2f14421f9cc6423 100644 (file)
@@ -80,6 +80,12 @@ import com.gitblit.models.PathModel;
 import com.gitblit.models.PathModel.PathChangeModel;\r
 import com.gitblit.models.RefModel;\r
 \r
+/**\r
+ * Collection of static methods for retrieving information from a repository.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
 public class JGitUtils {\r
 \r
        static final Logger LOGGER = LoggerFactory.getLogger(JGitUtils.class);\r
@@ -795,6 +801,9 @@ public class JGitUtils {
                return list;\r
        }\r
 \r
+       /**\r
+        * Enumeration of the search types.\r
+        */\r
        public static enum SearchType {\r
                AUTHOR, COMMITTER, COMMIT;\r
 \r
index c7c1f9fe94aaa3f0137ea7fd361e782484ee75e5..a3a1859235899d0ab3f876abd6c09b6df7386dff 100644 (file)
@@ -40,7 +40,10 @@ public class MarkdownUtils {
         */\r
        public static String transformMarkdown(String markdown) throws java.text.ParseException {\r
                try {\r
-                       return transformMarkdown(new StringReader(markdown));\r
+                       StringReader reader = new StringReader(markdown);\r
+                       String html = transformMarkdown(reader);\r
+                       reader.close();\r
+                       return html;\r
                } catch (NullPointerException p) {\r
                        throw new java.text.ParseException("Markdown string is null!", 0);\r
                }\r
@@ -64,11 +67,6 @@ public class MarkdownUtils {
                } catch (ParseException p) {\r
                        throw new java.text.ParseException(p.getMessage(), 0);\r
                } finally {\r
-                       try {\r
-                               markdownReader.close();\r
-                       } catch (IOException e) {\r
-                               // IGNORE\r
-                       }\r
                        try {\r
                                writer.close();\r
                        } catch (IOException e) {\r
index 925595618ccdf4e78184ab47080ac04629a141a5..90b3fb16b286bfe63ded892b6e7b8eef3776ba46 100644 (file)
@@ -115,6 +115,10 @@ public class PatchFormatter extends DiffFormatter {
                return patch.toString();\r
        }\r
 \r
+       /**\r
+        * Class that represents the number of insertions and deletions from a\r
+        * chunk.\r
+        */\r
        private static class PatchTouple {\r
                int insertions;\r
                int deletions;\r
index ad814636efb9eee25797bbc798004bda486bc1d1..dbd2d9a80d496641c0819b06af13576b54d9fe02 100644 (file)
@@ -185,7 +185,6 @@ public class TimeUtils {
         * @return the string representation of the duration OR the css class\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
@@ -194,16 +193,15 @@ public class TimeUtils {
                                }\r
                                int hours = hoursAgo(date, true);\r
                                if (hours > 23) {\r
-                                       ago = "yesterday";\r
+                                       return "yesterday";\r
                                } else {\r
-                                       ago = hours + " hours ago";\r
+                                       return hours + " hours ago";\r
                                }\r
-                       } else {\r
-                               if (css) {\r
-                                       return "age0";\r
-                               }\r
-                               ago = mins + " min" + (mins > 1 ? "s" : "") + " ago";\r
                        }\r
+                       if (css) {\r
+                               return "age0";\r
+                       }\r
+                       return mins + " min" + (mins > 1 ? "s" : "") + " ago";\r
                } else {\r
                        if (css) {\r
                                return "age2";\r
@@ -211,35 +209,33 @@ public class TimeUtils {
                        int days = daysAgo(date, true);\r
                        if (days < 365) {\r
                                if (days <= 30) {\r
-                                       ago = days + " days ago";\r
+                                       return days + " days ago";\r
                                } else if (days <= 90) {\r
                                        int weeks = days / 7;\r
                                        if (weeks == 12) {\r
-                                               ago = "3 months ago";\r
+                                               return "3 months ago";\r
                                        } else {\r
-                                               ago = weeks + " weeks ago";\r
-                                       }\r
-                               } else if (days > 90) {\r
-                                       int months = days / 30;\r
-                                       int weeks = (days % 30) / 7;\r
-                                       if (weeks >= 2) {\r
-                                               months++;\r
+                                               return weeks + " weeks ago";\r
                                        }\r
-                                       ago = months + " months ago";\r
                                }\r
+                               int months = days / 30;\r
+                               int weeks = (days % 30) / 7;\r
+                               if (weeks >= 2) {\r
+                                       months++;\r
+                               }\r
+                               return months + " months ago";\r
                        } else if (days == 365) {\r
-                               ago = "1 year ago";\r
+                               return "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
+                                       return yr + " years ago";\r
                                } else {\r
-                                       ago = months + " months ago";\r
+                                       return months + " months ago";\r
                                }\r
                        }\r
                }\r
-               return ago;\r
        }\r
 }\r
index 4b5e660476665b082ccc60c420692efcab6ffc53..8cbab9c4d4faa56c5118f7a05f25efbafa092d84 100644 (file)
@@ -22,7 +22,6 @@ import org.apache.wicket.Response;
 import org.apache.wicket.Session;\r
 import org.apache.wicket.markup.html.WebPage;\r
 import org.apache.wicket.protocol.http.WebApplication;\r
-import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy;\r
 \r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
index c30b9c3017d35f2d0dc5e357beb7f93256dd6d5e..3248a082dce2dcf9a98174dc16108d8f3c77a89b 100644 (file)
@@ -16,8 +16,6 @@
 package com.gitblit.wicket;\r
 \r
 import org.apache.wicket.Page;\r
-import org.apache.wicket.protocol.http.WicketURLDecoder;\r
-import org.apache.wicket.protocol.http.WicketURLEncoder;\r
 import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy;\r
 \r
 import com.gitblit.GitBlit;\r
index e95aee32f3ba4f5b7efed959c686fa6de054ff42..acfb3236e3f8886a3b3cb1f8b44731abfc9e93a4 100644 (file)
@@ -189,7 +189,7 @@ public abstract class BasePage extends WebPage {
         * Panel fragment for displaying login or logout/change_password links.\r
         * \r
         */\r
-       class UserFragment extends Fragment {\r
+       static class UserFragment extends Fragment {\r
 \r
                private static final long serialVersionUID = 1L;\r
 \r
@@ -201,7 +201,7 @@ public abstract class BasePage extends WebPage {
                                add(new Label("username", GitBlitWebSession.get().getUser().toString() + ":"));\r
                                add(new LinkPanel("loginLink", null, markupProvider.getString("gb.logout"),\r
                                                LogoutPage.class));\r
-                               // quick and dirty hack for showing a separator \r
+                               // quick and dirty hack for showing a separator\r
                                add(new Label("separator", "|"));\r
                                add(new BookmarkablePageLink<Void>("changePasswordLink", ChangePasswordPage.class));\r
                        } else {\r
index 42cd2b7d37c87f997d8feed6be2fb7b974ce3a51..054b343078d1b0c48f180321337272e69b918a23 100644 (file)
@@ -49,7 +49,8 @@ public class ChangePasswordPage extends WebPage {
                        throw new RestartResponseException(getApplication().getHomePage());\r
                }\r
 \r
-               if (!GitBlit.getBoolean(Keys.web.authenticateAdminPages, true) && !GitBlit.getBoolean(Keys.web.authenticateViewPages, false)) {\r
+               if (!GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)\r
+                               && !GitBlit.getBoolean(Keys.web.authenticateViewPages, false)) {\r
                        // no authentication enabled\r
                        throw new RestartResponseException(getApplication().getHomePage());\r
                }\r
@@ -115,19 +116,19 @@ public class ChangePasswordPage extends WebPage {
                confirmPasswordField.setResetPassword(false);\r
                form.add(confirmPasswordField);\r
                form.add(new FeedbackPanel("feedback"));\r
-               \r
+\r
                form.add(new Button("save"));\r
-               Button cancel = new Button("cancel"){          \r
+               Button cancel = new Button("cancel") {\r
                        private static final long serialVersionUID = 1L;\r
 \r
                        @Override\r
                        public void onSubmit() {\r
-                setResponsePage(RepositoriesPage.class);\r
-            }\r
-        };\r
-        cancel.setDefaultFormProcessing(false);\r
-        form.add(cancel);\r
-        \r
+                               setResponsePage(RepositoriesPage.class);\r
+                       }\r
+               };\r
+               cancel.setDefaultFormProcessing(false);\r
+               form.add(cancel);\r
+\r
                add(form);\r
        }\r
 }\r
index 824f13dcf5049a4c7a168fbf306ad9875ec788a0..eea389ea24fe2901ce9462ebe4ded3df798c7c61 100644 (file)
@@ -184,17 +184,17 @@ public class EditRepositoryPage extends BasePage {
                form.add(usersPalette);\r
 \r
                form.add(new Button("save"));\r
-               Button cancel = new Button("cancel"){          \r
+               Button cancel = new Button("cancel") {\r
                        private static final long serialVersionUID = 1L;\r
 \r
                        @Override\r
                        public void onSubmit() {\r
-                setResponsePage(RepositoriesPage.class);\r
-            }\r
-        };\r
-        cancel.setDefaultFormProcessing(false);\r
-        form.add(cancel);\r
-        \r
+                               setResponsePage(RepositoriesPage.class);\r
+                       }\r
+               };\r
+               cancel.setDefaultFormProcessing(false);\r
+               form.add(cancel);\r
+\r
                add(form);\r
        }\r
 \r
index cb61adbc5668c3c578b52e3d1d862de54018dcfa..dd50d56dff1e356a66ea7af2293980a28ed45c29 100644 (file)
@@ -173,19 +173,19 @@ public class EditUserPage extends BasePage {
                form.add(confirmPasswordField);\r
                form.add(new CheckBox("canAdmin"));\r
                form.add(repositories);\r
-               \r
+\r
                form.add(new Button("save"));\r
-               Button cancel = new Button("cancel"){          \r
+               Button cancel = new Button("cancel") {\r
                        private static final long serialVersionUID = 1L;\r
 \r
                        @Override\r
                        public void onSubmit() {\r
-                setResponsePage(RepositoriesPage.class);\r
-            }\r
-        };\r
-        cancel.setDefaultFormProcessing(false);\r
-        form.add(cancel);\r
-        \r
+                               setResponsePage(RepositoriesPage.class);\r
+                       }\r
+               };\r
+               cancel.setDefaultFormProcessing(false);\r
+               form.add(cancel);\r
+\r
                add(form);\r
        }\r
 }\r
index b049e8e05a857a5021ba376e0f156452d42836bf..15ef0e6ef44e8932000ed9a8d095596cfa5903e9 100644 (file)
@@ -25,7 +25,7 @@ public class LogoutPage extends WebPage {
 \r
        public LogoutPage() {\r
                GitBlitWebSession.get().invalidate();\r
-               GitBlit.self().setCookie(((WebResponse) getResponse()), null);\r
+               GitBlit.self().setCookie((WebResponse) getResponse(), null);\r
                setRedirect(true);\r
                setResponsePage(getApplication().getHomePage());\r
        }\r
index f97adff565f14314600bec6899c65531f0ccf43b..053bee094cf6f8ab28ffd63925a74ddf1b61232f 100644 (file)
@@ -72,6 +72,7 @@ public class RepositoriesPage extends BasePage {
                                InputStream is = res.getResourceStream().getInputStream();\r
                                InputStreamReader reader = new InputStreamReader(is);\r
                                message = MarkdownUtils.transformMarkdown(reader);\r
+                               reader.close();\r
                        } catch (Throwable t) {\r
                                message = "Failed to read default welcome message!";\r
                                error(message, t, false);\r
index e753e5d0494b2cfd41ee2563595dc166a375b2f8..07d571447cc87d105ff2cfa7d9e42985e3dad9cf 100644 (file)
@@ -78,8 +78,8 @@ public class SummaryPage extends RepositoryPage {
                add(new Label("repositoryDescription", getRepositoryModel().description));\r
                add(new Label("repositoryOwner", getRepositoryModel().owner));\r
 \r
-               add(WicketUtils.createTimestampLabel("repositoryLastChange", JGitUtils.getLastChange(r, null),\r
-                               getTimeZone()));\r
+               add(WicketUtils.createTimestampLabel("repositoryLastChange",\r
+                               JGitUtils.getLastChange(r, null), getTimeZone()));\r
                if (metricsTotal == null) {\r
                        add(new Label("branchStats", ""));\r
                } else {\r
index 8e58d67350ecb8b7e14602c0c988a37121a7755b..24e0e98d9c6896e3da9b71154dd4c2941701cc14 100644 (file)
@@ -94,22 +94,22 @@ public class BranchesPanel extends BasePanel {
 \r
                                String author = entry.getAuthorIdent().getName();\r
                                LinkPanel authorLink = new LinkPanel("branchAuthor", "list", author,\r
-                                               SearchPage.class, WicketUtils.newSearchParameter(model.name, entry.getName(),\r
-                                                               author, SearchType.AUTHOR));\r
+                                               SearchPage.class, WicketUtils.newSearchParameter(model.name,\r
+                                                               entry.getName(), author, SearchType.AUTHOR));\r
                                setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);\r
                                item.add(authorLink);\r
-                               \r
+\r
                                // short message\r
                                String shortMessage = entry.getShortMessage();\r
                                String trimmedMessage = StringUtils.trimShortLog(shortMessage);\r
-                               LinkPanel shortlog = new LinkPanel("branchLog", "list subject",\r
-                                               trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(\r
-                                                               model.name, entry.getName()));\r
+                               LinkPanel shortlog = new LinkPanel("branchLog", "list subject", trimmedMessage,\r
+                                               CommitPage.class, WicketUtils.newObjectParameter(model.name,\r
+                                                               entry.getName()));\r
                                if (!shortMessage.equals(trimmedMessage)) {\r
                                        WicketUtils.setHtmlTooltip(shortlog, shortMessage);\r
                                }\r
                                item.add(shortlog);\r
-                               \r
+\r
                                if (maxCount <= 0) {\r
                                        Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);\r
                                        fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils\r
index fa6c661d0a889162e7632e08e4299996132bdcc1..416a8c12b5a69b5a5a10b648c076e29ebdbfae64 100644 (file)
@@ -76,9 +76,9 @@ public class RepositoriesPanel extends BasePanel {
                        Map<String, List<RepositoryModel>> groups = new HashMap<String, List<RepositoryModel>>();\r
                        for (RepositoryModel model : models) {\r
                                String rootPath = StringUtils.getRootPath(model.name);\r
-                               if (StringUtils.isEmpty(rootPath)) { \r
+                               if (StringUtils.isEmpty(rootPath)) {\r
                                        // root repository\r
-                                       rootRepositories.add(model);                                    \r
+                                       rootRepositories.add(model);\r
                                } else {\r
                                        // non-root, grouped repository\r
                                        if (!groups.containsKey(rootPath)) {\r
@@ -89,7 +89,7 @@ public class RepositoriesPanel extends BasePanel {
                        }\r
                        List<String> roots = new ArrayList<String>(groups.keySet());\r
                        Collections.sort(roots);\r
-                       \r
+\r
                        if (rootRepositories.size() > 0) {\r
                                // inject the root repositories at the top of the page\r
                                String rootPath = GitBlit.getString(Keys.web.repositoryRootGroupName, " ");\r
@@ -138,7 +138,8 @@ public class RepositoriesPanel extends BasePanel {
                                        row.add(new LinkPanel("repositoryDescription", "list", entry.description,\r
                                                        SummaryPage.class, pp));\r
                                        if (showSize) {\r
-                                               row.add(new Label("repositorySize", byteFormat.format(GitBlit.self().calculateSize(entry))));\r
+                                               row.add(new Label("repositorySize", byteFormat.format(GitBlit.self()\r
+                                                               .calculateSize(entry))));\r
                                        } else {\r
                                                row.add(new Label("repositorySize").setVisible(false));\r
                                        }\r
@@ -146,7 +147,8 @@ public class RepositoriesPanel extends BasePanel {
                                        // New repository\r
                                        row.add(new Label("repositoryName", entry.name));\r
                                        row.add(new Label("repositoryDescription", entry.description));\r
-                                       row.add(new Label("repositorySize", "<span class='empty'>(empty)</span>").setEscapeModelStrings(false));\r
+                                       row.add(new Label("repositorySize", "<span class='empty'>(empty)</span>")\r
+                                                       .setEscapeModelStrings(false));\r
                                }\r
 \r
                                if (entry.useTickets) {\r
index 58cb458645d3a1836ddb443f948cbdfbf3a42d1a..39d4092bb2074d40dd997f0db38983d2d680806c 100644 (file)
@@ -90,7 +90,7 @@ public class TagsPanel extends BasePanel {
                                item.add(new LinkPanel("tagName", "list name", entry.displayName, linkClass,\r
                                                WicketUtils.newObjectParameter(repositoryName, entry\r
                                                                .getReferencedObjectId().getName())));\r
-                               \r
+\r
                                // workaround for RevTag returning a lengthy shortlog. :(\r
                                String message = StringUtils.trimShortLog(entry.getShortMessage());\r
 \r
diff --git a/tests/com/gitblit/tests/FileUtilsTest.java b/tests/com/gitblit/tests/FileUtilsTest.java
new file mode 100644 (file)
index 0000000..4e416cb
--- /dev/null
@@ -0,0 +1,45 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.tests;\r
+\r
+import java.io.File;\r
+\r
+import com.gitblit.utils.FileUtils;\r
+\r
+import junit.framework.TestCase;\r
+\r
+public class FileUtilsTest extends TestCase {\r
+\r
+       public void testReadContent() throws Exception {\r
+               File dir = new File(System.getProperty("user.dir"));\r
+               String rawContent = FileUtils.readContent(new File(dir, "LICENSE"), "\n");\r
+               assertTrue(rawContent.trim().startsWith("Apache License"));\r
+       }\r
+\r
+       public void testFolderSize() throws Exception {\r
+               assertEquals(-1, FileUtils.folderSize(null));\r
+               assertEquals(-1, FileUtils.folderSize(new File(System.getProperty("user.dir"), "pretend")));\r
+\r
+               File dir = new File(System.getProperty("user.dir"), "distrib");\r
+               long size = FileUtils.folderSize(dir);\r
+               assertTrue("size is actually " + size, size >= 470000L);\r
+\r
+               File file = new File(System.getProperty("user.dir"), "LICENSE");\r
+               size = FileUtils.folderSize(file);\r
+               assertTrue("size is actually " + size, size == 11556L);\r
+\r
+       }\r
+}
\ No newline at end of file
index bbf7c4b3e4a548f130370b2b7366d96ebb0d0892..2908383ef1ee8b1d8f4d7da8cba3858a4c20d496 100644 (file)
@@ -24,8 +24,8 @@ import junit.framework.TestSuite;
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.storage.file.FileRepository;\r
 \r
-import com.gitblit.FileUserService;\r
 import com.gitblit.FileSettings;\r
+import com.gitblit.FileUserService;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -40,6 +40,7 @@ public class GitBlitSuite extends TestSetup {
 \r
        public static Test suite() {\r
                TestSuite suite = new TestSuite();\r
+               suite.addTestSuite(FileUtilsTest.class);\r
                suite.addTestSuite(TimeUtilsTest.class);\r
                suite.addTestSuite(StringUtilsTest.class);\r
                suite.addTestSuite(ByteFormatTest.class);\r
index 22297683aa319833e7bf63a2ea57b8edddd4c5fe..e278e5aeee09016f31215eeef27069bad1d98b53 100644 (file)
@@ -39,6 +39,8 @@ public class GitBlitTest extends TestCase {
                assertTrue("Helloworld model is null!", model != null);\r
                assertTrue(model.toString().equals(\r
                                GitBlitSuite.getHelloworldRepository().getDirectory().getName()));\r
+               assertEquals("" + GitBlit.self().calculateSize(model), GitBlit.self().calculateSize(model),\r
+                               22004L);\r
        }\r
 \r
        public void testUserModel() throws Exception {\r
@@ -54,6 +56,9 @@ public class GitBlitTest extends TestCase {
                assertFalse("Admin can still access repository!", model.canAccessRepository(repository));\r
                model.addRepository(repository);\r
                assertTrue("Admin can't access repository!", model.canAccessRepository(repository));\r
+               assertEquals(GitBlit.self().getRepositoryModel(model, "pretend"), null);\r
+               assertNotNull(GitBlit.self().getRepositoryModel(model, repository));\r
+               assertTrue(GitBlit.self().getRepositoryModels(model).size() > 0);\r
        }\r
 \r
        public void testAccessRestrictionTypes() throws Exception {\r
@@ -85,12 +90,12 @@ public class GitBlitTest extends TestCase {
 \r
        public void testFileSettings() throws Exception {\r
                FileSettings settings = new FileSettings("distrib/gitblit.properties");\r
-               assertTrue(settings.getBoolean("missing", true) == true);\r
+               assertTrue(settings.getBoolean("missing", true));\r
                assertTrue(settings.getString("missing", "default").equals("default"));\r
                assertTrue(settings.getInteger("missing", 10) == 10);\r
                assertTrue(settings.getInteger("realm.realmFile", 5) == 5);\r
 \r
-               assertTrue(settings.getBoolean("git.enableGitServlet", false) == true);\r
+               assertTrue(settings.getBoolean("git.enableGitServlet", false));\r
                assertTrue(settings.getString("realm.userService", null).equals("users.properties"));\r
                assertTrue(settings.getInteger("realm.minPasswordLength", 0) == 5);\r
                List<String> mdExtensions = settings.getStrings("web.markdownExtensions");\r
@@ -100,16 +105,18 @@ public class GitBlitTest extends TestCase {
                List<String> keys = settings.getAllKeys("server");\r
                assertTrue(keys.size() > 0);\r
                assertTrue(keys.contains("server.httpsPort"));\r
+\r
+               assertTrue(settings.getChar("web.forwardSlashCharacter", ' ') == '/');\r
        }\r
 \r
        public void testGitblitSettings() throws Exception {\r
                // These are already tested by above test method.\r
-               assertTrue(GitBlit.getBoolean("missing", true) == true);\r
+               assertTrue(GitBlit.getBoolean("missing", true));\r
                assertTrue(GitBlit.getString("missing", "default").equals("default"));\r
                assertTrue(GitBlit.getInteger("missing", 10) == 10);\r
                assertTrue(GitBlit.getInteger("realm.userService", 5) == 5);\r
 \r
-               assertTrue(GitBlit.getBoolean("git.enableGitServlet", false) == true);\r
+               assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));\r
                assertTrue(GitBlit.getString("realm.userService", null).equals("users.properties"));\r
                assertTrue(GitBlit.getInteger("realm.minPasswordLength", 0) == 5);\r
                List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");\r
@@ -119,6 +126,9 @@ public class GitBlitTest extends TestCase {
                List<String> keys = GitBlit.getAllKeys("server");\r
                assertTrue(keys.size() > 0);\r
                assertTrue(keys.contains("server.httpsPort"));\r
+\r
+               assertTrue(GitBlit.getChar("web.forwardSlashCharacter", ' ') == '/');\r
+               assertFalse(GitBlit.isDebugMode());\r
        }\r
 \r
        public void testAuthentication() throws Exception {\r
index c9d007df523f0325596ed4b17229b75f5b0e082f..bfa34b4b93db13e187ecc11002f70aa4c3219e63 100644 (file)
@@ -27,7 +27,11 @@ import com.gitblit.utils.MetricUtils;
 public class MetricUtilsTest extends TestCase {\r
 \r
        public void testMetrics() throws Exception {\r
-               Repository repository = GitBlitSuite.getHelloworldRepository();\r
+               testMetrics(GitBlitSuite.getHelloworldRepository());\r
+               testMetrics(GitBlitSuite.getBluezGnomeRepository());\r
+       }\r
+\r
+       private void testMetrics(Repository repository) throws Exception {\r
                List<Metric> metrics = MetricUtils.getDateMetrics(repository, null, true, null);\r
                repository.close();\r
                assertTrue("No date metrics found!", metrics.size() > 0);\r
index 1bf0de4aee3296039ebbc787092d5ccf59d7edc3..665b91403ec744b8ae91f64cbcaf9478fae9324b 100644 (file)
@@ -36,7 +36,7 @@ public class StringUtilsTest extends TestCase {
                String output = "this<br/>is<br/>a<br/>test<br/><br/>of<br/><br/>line<br/><br/>breaking";\r
                assertTrue(StringUtils.breakLinesForHtml(input).equals(output));\r
        }\r
-       \r
+\r
        public void testEncodeUrl() throws Exception {\r
                String input = "test /";\r
                String output = "test%20%2F";\r
@@ -50,7 +50,7 @@ public class StringUtilsTest extends TestCase {
                assertTrue(StringUtils.escapeForHtml(input, false).equals(outputNoChange));\r
                assertTrue(StringUtils.escapeForHtml(input, true).equals(outputChange));\r
        }\r
-       \r
+\r
        public void testDecodeForHtml() throws Exception {\r
                String input = "&amp; &lt; &gt; &quot;";\r
                String output = "& < > \"";\r
@@ -82,7 +82,7 @@ public class StringUtilsTest extends TestCase {
                assertTrue(StringUtils.getSHA1("blob 16\000what is up, doc?").equals(\r
                                "bd9dbf5aae1a3862dd1526723246b20206e5fc37"));\r
        }\r
-       \r
+\r
        public void testMD5() throws Exception {\r
                assertTrue(StringUtils.getMD5("blob 16\000what is up, doc?").equals(\r
                                "77fb8d95331f0d557472f6776d3aedf6"));\r
index ab5180414701bc6a77209e4664ba7b54e0f68f11..1fa21fc38c46fee7c1d9685ea35f7322b3109e44 100644 (file)
@@ -32,7 +32,8 @@ public class SyndicationUtilsTest extends TestCase {
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                List<RevCommit> commits = JGitUtils.getRevLog(repository, 1);\r
                ByteArrayOutputStream os = new ByteArrayOutputStream();\r
-               SyndicationUtils.toRSS("http://localhost", "Title", "Description", "Repository", commits, os);\r
+               SyndicationUtils.toRSS("http://localhost", "Title", "Description", "Repository", commits,\r
+                               os);\r
                String feed = os.toString();\r
                os.close();\r
                assertTrue(feed.length() > 100);\r