Browse Source

Documentation. Unit testing. Checkstyle. Findbugs.

tags/v0.5.2
James Moger 13 years ago
parent
commit
88598bb2f7
36 changed files with 233 additions and 115 deletions
  1. 1
    1
      docs/00_index.mkd
  2. 2
    1
      src/com/gitblit/AccessRestrictionFilter.java
  3. 3
    0
      src/com/gitblit/Constants.java
  4. 1
    1
      src/com/gitblit/DownloadZipServlet.java
  5. 2
    2
      src/com/gitblit/GitBlitException.java
  6. 5
    2
      src/com/gitblit/GitBlitServer.java
  7. 1
    1
      src/com/gitblit/IStoredSettings.java
  8. 6
    2
      src/com/gitblit/MakeCertificate.java
  9. 10
    0
      src/com/gitblit/build/Build.java
  10. 31
    18
      src/com/gitblit/build/BuildSite.java
  11. 7
    2
      src/com/gitblit/build/BuildThumbnails.java
  12. 6
    0
      src/com/gitblit/build/BuildWebXml.java
  13. 3
    0
      src/com/gitblit/utils/DiffUtils.java
  14. 3
    2
      src/com/gitblit/utils/FileUtils.java
  15. 9
    0
      src/com/gitblit/utils/JGitUtils.java
  16. 4
    6
      src/com/gitblit/utils/MarkdownUtils.java
  17. 4
    0
      src/com/gitblit/utils/PatchFormatter.java
  18. 18
    22
      src/com/gitblit/utils/TimeUtils.java
  19. 0
    1
      src/com/gitblit/wicket/GitBlitWebApp.java
  20. 0
    2
      src/com/gitblit/wicket/GitblitParamUrlCodingStrategy.java
  21. 2
    2
      src/com/gitblit/wicket/pages/BasePage.java
  22. 10
    9
      src/com/gitblit/wicket/pages/ChangePasswordPage.java
  23. 7
    7
      src/com/gitblit/wicket/pages/EditRepositoryPage.java
  24. 8
    8
      src/com/gitblit/wicket/pages/EditUserPage.java
  25. 1
    1
      src/com/gitblit/wicket/pages/LogoutPage.java
  26. 1
    0
      src/com/gitblit/wicket/pages/RepositoriesPage.java
  27. 2
    2
      src/com/gitblit/wicket/pages/SummaryPage.java
  28. 7
    7
      src/com/gitblit/wicket/panels/BranchesPanel.java
  29. 7
    5
      src/com/gitblit/wicket/panels/RepositoriesPanel.java
  30. 1
    1
      src/com/gitblit/wicket/panels/TagsPanel.java
  31. 45
    0
      tests/com/gitblit/tests/FileUtilsTest.java
  32. 2
    1
      tests/com/gitblit/tests/GitBlitSuite.java
  33. 14
    4
      tests/com/gitblit/tests/GitBlitTest.java
  34. 5
    1
      tests/com/gitblit/tests/MetricUtilsTest.java
  35. 3
    3
      tests/com/gitblit/tests/StringUtilsTest.java
  36. 2
    1
      tests/com/gitblit/tests/SyndicationUtilsTest.java

+ 1
- 1
docs/00_index.mkd View File

@@ -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

+ 2
- 1
src/com/gitblit/AccessRestrictionFilter.java View File

@@ -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,

+ 3
- 0
src/com/gitblit/Constants.java View File

@@ -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;

+ 1
- 1
src/com/gitblit/DownloadZipServlet.java View File

@@ -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
*

+ 2
- 2
src/com/gitblit/GitBlitException.java View File

@@ -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 {

+ 5
- 2
src/com/gitblit/GitBlitServer.java View File

@@ -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 {

+ 1
- 1
src/com/gitblit/IStoredSettings.java View File

@@ -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

+ 6
- 2
src/com/gitblit/MakeCertificate.java View File

@@ -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 {

+ 10
- 0
src/com/gitblit/build/Build.java View File

@@ -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",

+ 31
- 18
src/com/gitblit/build/BuildSite.java View File

@@ -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 {

+ 7
- 2
src/com/gitblit/build/BuildThumbnails.java View File

@@ -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 {

+ 6
- 0
src/com/gitblit/build/BuildWebXml.java View File

@@ -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 {

+ 3
- 0
src/com/gitblit/utils/DiffUtils.java View File

@@ -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;

+ 3
- 2
src/com/gitblit/utils/FileUtils.java View File

@@ -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;
}

+ 9
- 0
src/com/gitblit/utils/JGitUtils.java View File

@@ -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;

+ 4
- 6
src/com/gitblit/utils/MarkdownUtils.java View File

@@ -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);
}
@@ -64,11 +67,6 @@ public class MarkdownUtils {
} 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) {

+ 4
- 0
src/com/gitblit/utils/PatchFormatter.java View File

@@ -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;

+ 18
- 22
src/com/gitblit/utils/TimeUtils.java View File

@@ -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;
}
}

+ 0
- 1
src/com/gitblit/wicket/GitBlitWebApp.java View File

@@ -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;

+ 0
- 2
src/com/gitblit/wicket/GitblitParamUrlCodingStrategy.java View File

@@ -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;

+ 2
- 2
src/com/gitblit/wicket/pages/BasePage.java View File

@@ -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 {

+ 10
- 9
src/com/gitblit/wicket/pages/ChangePasswordPage.java View File

@@ -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);
}
}

+ 7
- 7
src/com/gitblit/wicket/pages/EditRepositoryPage.java View File

@@ -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);
}

+ 8
- 8
src/com/gitblit/wicket/pages/EditUserPage.java View File

@@ -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);
}
}

+ 1
- 1
src/com/gitblit/wicket/pages/LogoutPage.java View File

@@ -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());
}

+ 1
- 0
src/com/gitblit/wicket/pages/RepositoriesPage.java View File

@@ -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);

+ 2
- 2
src/com/gitblit/wicket/pages/SummaryPage.java View File

@@ -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 {

+ 7
- 7
src/com/gitblit/wicket/panels/BranchesPanel.java View File

@@ -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

+ 7
- 5
src/com/gitblit/wicket/panels/RepositoriesPanel.java View File

@@ -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) {

+ 1
- 1
src/com/gitblit/wicket/panels/TagsPanel.java View File

@@ -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());

+ 45
- 0
tests/com/gitblit/tests/FileUtilsTest.java View File

@@ -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);
}
}

+ 2
- 1
tests/com/gitblit/tests/GitBlitSuite.java View File

@@ -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);

+ 14
- 4
tests/com/gitblit/tests/GitBlitTest.java View File

@@ -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 {

+ 5
- 1
tests/com/gitblit/tests/MetricUtilsTest.java View File

@@ -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);

+ 3
- 3
tests/com/gitblit/tests/StringUtilsTest.java View 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";
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"));

+ 2
- 1
tests/com/gitblit/tests/SyndicationUtilsTest.java View File

@@ -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);

Loading…
Cancel
Save