summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-07-22 09:37:14 -0400
committerJames Moger <james.moger@gitblit.com>2011-07-22 09:37:14 -0400
commit88598bb2f779b73479512d818c675dea8fa72138 (patch)
tree77e1a8e89da1faa3444f03aefa8a201f77010e9e
parent0d3e3ca5b85d7e81066030a5081ea3a9cbe76607 (diff)
downloadgitblit-88598bb2f779b73479512d818c675dea8fa72138.tar.gz
gitblit-88598bb2f779b73479512d818c675dea8fa72138.zip
Documentation. Unit testing. Checkstyle. Findbugs.
-rw-r--r--docs/00_index.mkd2
-rw-r--r--src/com/gitblit/AccessRestrictionFilter.java3
-rw-r--r--src/com/gitblit/Constants.java3
-rw-r--r--src/com/gitblit/DownloadZipServlet.java2
-rw-r--r--src/com/gitblit/GitBlitException.java4
-rw-r--r--src/com/gitblit/GitBlitServer.java7
-rw-r--r--src/com/gitblit/IStoredSettings.java2
-rw-r--r--src/com/gitblit/MakeCertificate.java8
-rw-r--r--src/com/gitblit/build/Build.java10
-rw-r--r--src/com/gitblit/build/BuildSite.java49
-rw-r--r--src/com/gitblit/build/BuildThumbnails.java9
-rw-r--r--src/com/gitblit/build/BuildWebXml.java6
-rw-r--r--src/com/gitblit/utils/DiffUtils.java3
-rw-r--r--src/com/gitblit/utils/FileUtils.java5
-rw-r--r--src/com/gitblit/utils/JGitUtils.java9
-rw-r--r--src/com/gitblit/utils/MarkdownUtils.java10
-rw-r--r--src/com/gitblit/utils/PatchFormatter.java4
-rw-r--r--src/com/gitblit/utils/TimeUtils.java40
-rw-r--r--src/com/gitblit/wicket/GitBlitWebApp.java1
-rw-r--r--src/com/gitblit/wicket/GitblitParamUrlCodingStrategy.java2
-rw-r--r--src/com/gitblit/wicket/pages/BasePage.java4
-rw-r--r--src/com/gitblit/wicket/pages/ChangePasswordPage.java19
-rw-r--r--src/com/gitblit/wicket/pages/EditRepositoryPage.java14
-rw-r--r--src/com/gitblit/wicket/pages/EditUserPage.java16
-rw-r--r--src/com/gitblit/wicket/pages/LogoutPage.java2
-rw-r--r--src/com/gitblit/wicket/pages/RepositoriesPage.java1
-rw-r--r--src/com/gitblit/wicket/pages/SummaryPage.java4
-rw-r--r--src/com/gitblit/wicket/panels/BranchesPanel.java14
-rw-r--r--src/com/gitblit/wicket/panels/RepositoriesPanel.java12
-rw-r--r--src/com/gitblit/wicket/panels/TagsPanel.java2
-rw-r--r--tests/com/gitblit/tests/FileUtilsTest.java45
-rw-r--r--tests/com/gitblit/tests/GitBlitSuite.java3
-rw-r--r--tests/com/gitblit/tests/GitBlitTest.java18
-rw-r--r--tests/com/gitblit/tests/MetricUtilsTest.java6
-rw-r--r--tests/com/gitblit/tests/StringUtilsTest.java6
-rw-r--r--tests/com/gitblit/tests/SyndicationUtilsTest.java3
36 files changed, 233 insertions, 115 deletions
diff --git a/docs/00_index.mkd b/docs/00_index.mkd
index 2be3b061..a6559b21 100644
--- a/docs/00_index.mkd
+++ b/docs/00_index.mkd
@@ -34,7 +34,7 @@ Gitblit requires a Java 6 Runtime Environment (JRE) or a Java 6 Development Kit
- 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 74571789..6ec70dbd 100644
--- a/src/com/gitblit/AccessRestrictionFilter.java
+++ b/src/com/gitblit/AccessRestrictionFilter.java
@@ -108,7 +108,8 @@ public abstract class AccessRestrictionFilter implements Filter {
* 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 766f7c20..4297dbd9 100644
--- a/src/com/gitblit/Constants.java
+++ b/src/com/gitblit/Constants.java
@@ -51,6 +51,9 @@ public class Constants {
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 32369ae1..5f2a2a4b 100644
--- a/src/com/gitblit/DownloadZipServlet.java
+++ b/src/com/gitblit/DownloadZipServlet.java
@@ -38,7 +38,7 @@ import com.gitblit.utils.StringUtils;
* 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 0cfc7825..032e41f7 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 92305fc7..2caaaf64 100644
--- a/src/com/gitblit/GitBlitServer.java
+++ b/src/com/gitblit/GitBlitServer.java
@@ -176,7 +176,7 @@ public class GitBlitServer {
}
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 @@ public class GitBlitServer {
connector.setMaxIdleTime(30000);
return connector;
}
-
+
/**
* Tests to see if the operating system is Windows.
*
@@ -376,6 +376,9 @@ public class GitBlitServer {
}
}
+ /**
+ * 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 0cc4bb46..be836c9b 100644
--- a/src/com/gitblit/IStoredSettings.java
+++ b/src/com/gitblit/IStoredSettings.java
@@ -116,7 +116,7 @@ public abstract class IStoredSettings {
}
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 894f7a84..f2fc7300 100644
--- a/src/com/gitblit/MakeCertificate.java
+++ b/src/com/gitblit/MakeCertificate.java
@@ -47,7 +47,7 @@ import com.gitblit.utils.TimeUtils;
* Utility class to generate self-signed certificates.
*
* @author James Moger
- *
+ *
*/
public class MakeCertificate {
@@ -63,7 +63,8 @@ public class MakeCertificate {
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 @@ public class MakeCertificate {
}
}
+ /**
+ * 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 22d61b5c..66bf49a1 100644
--- a/src/com/gitblit/build/Build.java
+++ b/src/com/gitblit/build/Build.java
@@ -49,6 +49,11 @@ import com.gitblit.utils.StringUtils;
*/
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 @@ public class Build {
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 c3a7f5f8..dca51168 100644
--- a/src/com/gitblit/build/BuildSite.java
+++ b/src/com/gitblit/build/BuildSite.java
@@ -55,11 +55,11 @@ import com.gitblit.utils.StringUtils;
*/
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 @@ public class BuildSite {
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 @@ public class BuildSite {
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 @@ public class BuildSite {
// 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 @@ public class BuildSite {
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 @@ public class BuildSite {
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 @@ public class BuildSite {
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 @@ public class BuildSite {
}
}
+ /**
+ * 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 0676ecaf..fe06c6ca 100644
--- a/src/com/gitblit/build/BuildThumbnails.java
+++ b/src/com/gitblit/build/BuildThumbnails.java
@@ -65,8 +65,9 @@ public class BuildThumbnails {
*/
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 @@ public class BuildThumbnails {
}
}
} 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 e53a4aff..4fcc6e97 100644
--- a/src/com/gitblit/build/BuildWebXml.java
+++ b/src/com/gitblit/build/BuildWebXml.java
@@ -126,6 +126,9 @@ public class BuildWebXml {
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 @@ public class BuildWebXml {
}
}
+ /**
+ * 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 beeb5323..9f0d04fc 100644
--- a/src/com/gitblit/utils/DiffUtils.java
+++ b/src/com/gitblit/utils/DiffUtils.java
@@ -48,6 +48,9 @@ public class DiffUtils {
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 ce8cdf94..310e35a9 100644
--- a/src/com/gitblit/utils/FileUtils.java
+++ b/src/com/gitblit/utils/FileUtils.java
@@ -73,10 +73,11 @@ public class FileUtils {
}
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 2e14b679..a72299dd 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -80,6 +80,12 @@ import com.gitblit.models.PathModel;
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 @@ public class JGitUtils {
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 c7c1f9fe..a3a18592 100644
--- a/src/com/gitblit/utils/MarkdownUtils.java
+++ b/src/com/gitblit/utils/MarkdownUtils.java
@@ -40,7 +40,10 @@ public class MarkdownUtils {
*/
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);
}
@@ -65,11 +68,6 @@ public class MarkdownUtils {
throw new java.text.ParseException(p.getMessage(), 0);
} finally {
try {
- markdownReader.close();
- } catch (IOException e) {
- // IGNORE
- }
- try {
writer.close();
} catch (IOException e) {
// IGNORE
diff --git a/src/com/gitblit/utils/PatchFormatter.java b/src/com/gitblit/utils/PatchFormatter.java
index 92559561..90b3fb16 100644
--- a/src/com/gitblit/utils/PatchFormatter.java
+++ b/src/com/gitblit/utils/PatchFormatter.java
@@ -115,6 +115,10 @@ public class PatchFormatter extends DiffFormatter {
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 ad814636..dbd2d9a8 100644
--- a/src/com/gitblit/utils/TimeUtils.java
+++ b/src/com/gitblit/utils/TimeUtils.java
@@ -185,7 +185,6 @@ public class TimeUtils {
* @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 @@ public class TimeUtils {
}
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 @@ public class TimeUtils {
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";
- }
- } else if (days > 90) {
- int months = days / 30;
- int weeks = (days % 30) / 7;
- if (weeks >= 2) {
- months++;
+ return weeks + " weeks ago";
}
- 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 4b5e6604..8cbab9c4 100644
--- a/src/com/gitblit/wicket/GitBlitWebApp.java
+++ b/src/com/gitblit/wicket/GitBlitWebApp.java
@@ -22,7 +22,6 @@ import org.apache.wicket.Response;
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 c30b9c30..3248a082 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 e95aee32..acfb3236 100644
--- a/src/com/gitblit/wicket/pages/BasePage.java
+++ b/src/com/gitblit/wicket/pages/BasePage.java
@@ -189,7 +189,7 @@ public abstract class BasePage extends WebPage {
* 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 @@ public abstract class BasePage extends WebPage {
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 42cd2b7d..054b3430 100644
--- a/src/com/gitblit/wicket/pages/ChangePasswordPage.java
+++ b/src/com/gitblit/wicket/pages/ChangePasswordPage.java
@@ -49,7 +49,8 @@ public class ChangePasswordPage extends WebPage {
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 @@ public class ChangePasswordPage extends WebPage {
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 824f13dc..eea389ea 100644
--- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java
+++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java
@@ -184,17 +184,17 @@ public class EditRepositoryPage extends BasePage {
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 cb61adbc..dd50d56d 100644
--- a/src/com/gitblit/wicket/pages/EditUserPage.java
+++ b/src/com/gitblit/wicket/pages/EditUserPage.java
@@ -173,19 +173,19 @@ public class EditUserPage extends BasePage {
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 b049e8e0..15ef0e6e 100644
--- a/src/com/gitblit/wicket/pages/LogoutPage.java
+++ b/src/com/gitblit/wicket/pages/LogoutPage.java
@@ -25,7 +25,7 @@ public class LogoutPage extends WebPage {
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 f97adff5..053bee09 100644
--- a/src/com/gitblit/wicket/pages/RepositoriesPage.java
+++ b/src/com/gitblit/wicket/pages/RepositoriesPage.java
@@ -72,6 +72,7 @@ public class RepositoriesPage extends BasePage {
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 e753e5d0..07d57144 100644
--- a/src/com/gitblit/wicket/pages/SummaryPage.java
+++ b/src/com/gitblit/wicket/pages/SummaryPage.java
@@ -78,8 +78,8 @@ public class SummaryPage extends RepositoryPage {
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 8e58d673..24e0e98d 100644
--- a/src/com/gitblit/wicket/panels/BranchesPanel.java
+++ b/src/com/gitblit/wicket/panels/BranchesPanel.java
@@ -94,22 +94,22 @@ public class BranchesPanel extends BasePanel {
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 fa6c661d..416a8c12 100644
--- a/src/com/gitblit/wicket/panels/RepositoriesPanel.java
+++ b/src/com/gitblit/wicket/panels/RepositoriesPanel.java
@@ -76,9 +76,9 @@ public class RepositoriesPanel extends BasePanel {
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 @@ public class RepositoriesPanel extends BasePanel {
}
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 @@ public class RepositoriesPanel extends BasePanel {
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 @@ public class RepositoriesPanel extends BasePanel {
// 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 58cb4586..39d4092b 100644
--- a/src/com/gitblit/wicket/panels/TagsPanel.java
+++ b/src/com/gitblit/wicket/panels/TagsPanel.java
@@ -90,7 +90,7 @@ public class TagsPanel extends BasePanel {
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 00000000..4e416cb7
--- /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 bbf7c4b3..2908383e 100644
--- a/tests/com/gitblit/tests/GitBlitSuite.java
+++ b/tests/com/gitblit/tests/GitBlitSuite.java
@@ -24,8 +24,8 @@ import junit.framework.TestSuite;
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 class GitBlitSuite extends TestSetup {
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 22297683..e278e5ae 100644
--- a/tests/com/gitblit/tests/GitBlitTest.java
+++ b/tests/com/gitblit/tests/GitBlitTest.java
@@ -39,6 +39,8 @@ public class GitBlitTest extends TestCase {
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 @@ public class GitBlitTest extends TestCase {
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 class GitBlitTest extends TestCase {
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 @@ public class GitBlitTest extends TestCase {
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 @@ public class GitBlitTest extends TestCase {
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 c9d007df..bfa34b4b 100644
--- a/tests/com/gitblit/tests/MetricUtilsTest.java
+++ b/tests/com/gitblit/tests/MetricUtilsTest.java
@@ -27,7 +27,11 @@ import com.gitblit.utils.MetricUtils;
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 1bf0de4a..665b9140 100644
--- a/tests/com/gitblit/tests/StringUtilsTest.java
+++ b/tests/com/gitblit/tests/StringUtilsTest.java
@@ -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";
assertTrue(StringUtils.breakLinesForHtml(input).equals(output));
}
-
+
public void testEncodeUrl() throws Exception {
String input = "test /";
String output = "test%20%2F";
@@ -50,7 +50,7 @@ public class StringUtilsTest extends TestCase {
assertTrue(StringUtils.escapeForHtml(input, false).equals(outputNoChange));
assertTrue(StringUtils.escapeForHtml(input, true).equals(outputChange));
}
-
+
public void testDecodeForHtml() throws Exception {
String input = "&amp; &lt; &gt; &quot;";
String output = "& < > \"";
@@ -82,7 +82,7 @@ public class StringUtilsTest extends TestCase {
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 ab518041..1fa21fc3 100644
--- a/tests/com/gitblit/tests/SyndicationUtilsTest.java
+++ b/tests/com/gitblit/tests/SyndicationUtilsTest.java
@@ -32,7 +32,8 @@ public class SyndicationUtilsTest extends TestCase {
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);