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