- updated: MarkdownPapers 1.1.0\r
- updated: Jetty 7.4.3\r
\r
-issues & binaries @ [Google Code][googlecode]<br/>\r
+issues, binaries, and sources @ [Google Code][googlecode]<br/>\r
sources @ [Github][gitbltsrc]\r
\r
### License\r
* doFilter does the actual work of preprocessing the request to ensure that\r
* the user may proceed.\r
* \r
- * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)\r
+ * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,\r
+ * javax.servlet.ServletResponse, javax.servlet.FilterChain)\r
*/\r
@Override\r
public void doFilter(final ServletRequest request, final ServletResponse response,\r
\r
public static final String BORDER = "***********************************************************";\r
\r
+ /**\r
+ * Enumeration representing the 4 access restriction levels.\r
+ */\r
public static enum AccessRestrictionType {\r
NONE, PUSH, CLONE, VIEW;\r
\r
* protected by an AccessRestrictionFilter. It performs its own authorization\r
* check, but it does not perform any authentication. The assumption is that\r
* requests to this servlet are made via the web ui and not by direct url\r
- * access. Unauthorized requests fail with a standard 403 (FORBIDDEN) code.\r
+ * access. Unauthorized requests fail with a standard 403 (FORBIDDEN) code.\r
* \r
* @author James Moger\r
* \r
package com.gitblit;\r
\r
/**\r
- * GitBlitException is a marginally useful class. :)\r
+ * GitBlitException is a marginally useful class. :)\r
* \r
* @author James Moger\r
- *\r
+ * \r
*/\r
public class GitBlitException extends Exception {\r
\r
}\r
if (params.securePort < 1024 && !isWindows()) {\r
logger.warn("Gitblit needs to run with ROOT permissions for ports < 1024!");\r
- } \r
+ }\r
connectors.add(secureConnector);\r
} else {\r
logger.warn("Failed to find or load Keystore?");\r
connector.setMaxIdleTime(30000);\r
return connector;\r
}\r
- \r
+\r
/**\r
* Tests to see if the operating system is Windows.\r
* \r
}\r
}\r
\r
+ /**\r
+ * JCommander Parameters class for GitBlitServer.\r
+ */\r
@Parameters(separators = " ")\r
private static class Params {\r
\r
}\r
return defaultValue;\r
}\r
- \r
+\r
/**\r
* Returns the char value for the specified key. If the key does not exist\r
* or the value for the key can not be interpreted as a char, the\r
* Utility class to generate self-signed certificates.\r
* \r
* @author James Moger\r
- *\r
+ * \r
*/\r
public class MakeCertificate {\r
\r
jc.usage();\r
}\r
File keystore = new File("keystore");\r
- generateSelfSignedCertificate(params.hostname, keystore, params.storePassword, params.subject);\r
+ generateSelfSignedCertificate(params.hostname, keystore, params.storePassword,\r
+ params.subject);\r
}\r
\r
public static void generateSelfSignedCertificate(String hostname, File keystore,\r
}\r
}\r
\r
+ /**\r
+ * JCommander Parameters class for MakeCertificate.\r
+ */\r
@Parameters(separators = " ")\r
private static class Params {\r
\r
*/\r
public class Build {\r
\r
+ /**\r
+ * BuildType enumeration representing compile-time or runtime. This is used\r
+ * to download dependencies either for Gitblit GO runtime or for setting up\r
+ * a development environment.\r
+ */\r
public static enum BuildType {\r
RUNTIME, COMPILETIME;\r
}\r
System.out.print("] " + url);\r
}\r
\r
+ /**\r
+ * MavenObject represents a complete maven artifact (binary, sources, and\r
+ * javadoc). MavenObjects can be downloaded and checksummed to confirm\r
+ * authenticity.\r
+ */\r
private static class MavenObject {\r
\r
public static final MavenObject JCOMMANDER = new MavenObject("jCommander", "com/beust",\r
*/\r
public class BuildSite {\r
\r
- private final static String CASE_SENSITIVE = "CASE-SENSITIVE";\r
+ private static final String CASE_SENSITIVE = "CASE-SENSITIVE";\r
\r
- private final static String RESTART_REQUIRED = "RESTART REQUIRED";\r
+ private static final String RESTART_REQUIRED = "RESTART REQUIRED";\r
\r
- private final static String SINCE = "SINCE";\r
+ private static final String SINCE = "SINCE";\r
\r
public static void main(String... args) {\r
Params params = new Params();\r
if (!params.skips.contains(documentName)) {\r
String fileName = documentName + ".html";\r
System.out.println(MessageFormat.format(" {0} => {1}", file.getName(),\r
- fileName)); \r
+ fileName));\r
String rawContent = FileUtils.readContent(file, "\n");\r
String markdownContent = rawContent;\r
- \r
+\r
Map<String, List<String>> nomarkdownMap = new HashMap<String, List<String>>();\r
\r
// extract sections marked as no-markdown\r
if (endCode == 0) {\r
strippedContent.append(markdownContent.substring(0, beginCode));\r
} else {\r
- strippedContent.append(markdownContent.substring(endCode, beginCode));\r
- } \r
+ strippedContent.append(markdownContent\r
+ .substring(endCode, beginCode));\r
+ }\r
strippedContent.append(nomarkdownKey);\r
endCode = markdownContent.indexOf(endToken, beginCode);\r
chunks.add(markdownContent.substring(beginCode, endCode));\r
\r
// get remainder of text\r
if (endCode < markdownContent.length()) {\r
- strippedContent.append(markdownContent.substring(endCode, markdownContent.length()));\r
+ strippedContent.append(markdownContent.substring(endCode,\r
+ markdownContent.length()));\r
}\r
markdownContent = strippedContent.toString();\r
- nmd++; \r
+ nmd++;\r
}\r
\r
// transform markdown to html\r
String content = transformMarkdown(markdownContent.toString());\r
\r
// reinsert nomarkdown chunks\r
- for (Map.Entry<String, List<String>> nomarkdown: nomarkdownMap.entrySet()) {\r
- for (String chunk:nomarkdown.getValue()) {\r
+ for (Map.Entry<String, List<String>> nomarkdown : nomarkdownMap.entrySet()) {\r
+ for (String chunk : nomarkdown.getValue()) {\r
content = content.replaceFirst(nomarkdown.getKey(), chunk);\r
}\r
}\r
- \r
+\r
for (String token : params.substitutions) {\r
String[] kv = token.split("=", 2);\r
content = content.replace(kv[0], kv[1]);\r
}\r
- for (String token:params.regex) {\r
+ for (String token : params.regex) {\r
String[] kv = token.split("!!!", 2);\r
content = content.replaceAll(kv[0], kv[1]);\r
}\r
content = content.replace(kv[0], loadedContent);\r
}\r
for (String alias : params.loads) {\r
- String[] kv = alias.split("=" ,2);\r
+ String[] kv = alias.split("=", 2);\r
String loadedContent = FileUtils.readContent(new File(kv[1]), "\n");\r
loadedContent = StringUtils.escapeForHtml(loadedContent, false);\r
loadedContent = StringUtils.breakLinesForHtml(loadedContent);\r
for (String comment : setting.comments) {\r
if (comment.contains(SINCE) || comment.contains(RESTART_REQUIRED)\r
|| comment.contains(CASE_SENSITIVE)) {\r
- sb.append(MessageFormat.format("<span style=\"color:#004000;\"># <i>{0}</i></span>", transformMarkdown(comment)));\r
+ sb.append(MessageFormat.format(\r
+ "<span style=\"color:#004000;\"># <i>{0}</i></span>",\r
+ transformMarkdown(comment)));\r
} else {\r
- sb.append(MessageFormat.format("<span style=\"color:#004000;\"># {0}</span>", transformMarkdown(comment)));\r
+ sb.append(MessageFormat.format("<span style=\"color:#004000;\"># {0}</span>",\r
+ transformMarkdown(comment)));\r
}\r
sb.append("<br/>\n");\r
}\r
if (!StringUtils.isEmpty(setting.name)) {\r
- sb.append(MessageFormat.format("<span style=\"color:#000080;\">{0}</span> = <span style=\"color:#800000;\">{1}</span>", setting.name, StringUtils.escapeForHtml(setting.value, false)));\r
+ sb.append(MessageFormat\r
+ .format("<span style=\"color:#000080;\">{0}</span> = <span style=\"color:#800000;\">{1}</span>",\r
+ setting.name, StringUtils.escapeForHtml(setting.value, false)));\r
}\r
sb.append("<br/>\n");\r
}\r
\r
return sb.toString();\r
}\r
- \r
+\r
private static String transformMarkdown(String comment) throws ParseException {\r
String md = MarkdownUtils.transformMarkdown(comment);\r
if (md.startsWith("<p>")) {\r
System.exit(0);\r
}\r
\r
+ /**\r
+ * Setting represents a setting with its comments from the properties file.\r
+ */\r
private static class Setting {\r
final String name;\r
final String value;\r
}\r
}\r
\r
+ /**\r
+ * JCommander Parameters class for BuildSite.\r
+ */\r
@Parameters(separators = " ")\r
private static class Params {\r
\r
*/\r
public static void createImageThumbnail(String sourceFolder, String destinationFolder,\r
int maxDimension) {\r
- if (maxDimension <= 0)\r
+ if (maxDimension <= 0) {\r
return;\r
+ }\r
File source = new File(sourceFolder);\r
File destination = new File(destinationFolder);\r
destination.mkdirs();\r
}\r
}\r
} finally {\r
- if (in != null)\r
+ if (in != null) {\r
in.close();\r
+ }\r
}\r
return null;\r
}\r
\r
+ /**\r
+ * JCommander Parameters class for BuildThumbnails.\r
+ */\r
@Parameters(separators = " ")\r
private static class Params {\r
\r
return key.startsWith(Keys.server._ROOT);\r
}\r
\r
+ /**\r
+ * Setting represents a setting and its comments from the properties file.\r
+ */\r
private static class Setting {\r
final String name;\r
final String value;\r
}\r
}\r
\r
+ /**\r
+ * JCommander Parameters class for BuildWebXml.\r
+ */\r
@Parameters(separators = " ")\r
private static class Params {\r
\r
\r
private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class);\r
\r
+ /**\r
+ * Enumeration for the diff output types.\r
+ */\r
public static enum DiffOutputType {\r
PLAIN, GITWEB, GITBLIT;\r
\r
}\r
long length = 0;\r
for (File file : directory.listFiles()) {\r
- if (file.isFile())\r
+ if (file.isFile()) {\r
length += file.length();\r
- else\r
+ } else {\r
length += folderSize(file);\r
+ }\r
}\r
return length;\r
}\r
import com.gitblit.models.PathModel.PathChangeModel;\r
import com.gitblit.models.RefModel;\r
\r
+/**\r
+ * Collection of static methods for retrieving information from a repository.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
public class JGitUtils {\r
\r
static final Logger LOGGER = LoggerFactory.getLogger(JGitUtils.class);\r
return list;\r
}\r
\r
+ /**\r
+ * Enumeration of the search types.\r
+ */\r
public static enum SearchType {\r
AUTHOR, COMMITTER, COMMIT;\r
\r
*/\r
public static String transformMarkdown(String markdown) throws java.text.ParseException {\r
try {\r
- return transformMarkdown(new StringReader(markdown));\r
+ StringReader reader = new StringReader(markdown);\r
+ String html = transformMarkdown(reader);\r
+ reader.close();\r
+ return html;\r
} catch (NullPointerException p) {\r
throw new java.text.ParseException("Markdown string is null!", 0);\r
}\r
} catch (ParseException p) {\r
throw new java.text.ParseException(p.getMessage(), 0);\r
} finally {\r
- try {\r
- markdownReader.close();\r
- } catch (IOException e) {\r
- // IGNORE\r
- }\r
try {\r
writer.close();\r
} catch (IOException e) {\r
return patch.toString();\r
}\r
\r
+ /**\r
+ * Class that represents the number of insertions and deletions from a\r
+ * chunk.\r
+ */\r
private static class PatchTouple {\r
int insertions;\r
int deletions;\r
* @return the string representation of the duration OR the css class\r
*/\r
private static String timeAgo(Date date, boolean css) {\r
- String ago = null;\r
if (isToday(date) || isYesterday(date)) {\r
int mins = minutesAgo(date, true);\r
if (mins >= 120) {\r
}\r
int hours = hoursAgo(date, true);\r
if (hours > 23) {\r
- ago = "yesterday";\r
+ return "yesterday";\r
} else {\r
- ago = hours + " hours ago";\r
+ return hours + " hours ago";\r
}\r
- } else {\r
- if (css) {\r
- return "age0";\r
- }\r
- ago = mins + " min" + (mins > 1 ? "s" : "") + " ago";\r
}\r
+ if (css) {\r
+ return "age0";\r
+ }\r
+ return mins + " min" + (mins > 1 ? "s" : "") + " ago";\r
} else {\r
if (css) {\r
return "age2";\r
int days = daysAgo(date, true);\r
if (days < 365) {\r
if (days <= 30) {\r
- ago = days + " days ago";\r
+ return days + " days ago";\r
} else if (days <= 90) {\r
int weeks = days / 7;\r
if (weeks == 12) {\r
- ago = "3 months ago";\r
+ return "3 months ago";\r
} else {\r
- ago = weeks + " weeks ago";\r
- }\r
- } else if (days > 90) {\r
- int months = days / 30;\r
- int weeks = (days % 30) / 7;\r
- if (weeks >= 2) {\r
- months++;\r
+ return weeks + " weeks ago";\r
}\r
- ago = months + " months ago";\r
}\r
+ int months = days / 30;\r
+ int weeks = (days % 30) / 7;\r
+ if (weeks >= 2) {\r
+ months++;\r
+ }\r
+ return months + " months ago";\r
} else if (days == 365) {\r
- ago = "1 year ago";\r
+ return "1 year ago";\r
} else {\r
int yr = days / 365;\r
days = days % 365;\r
int months = (yr * 12) + (days / 30);\r
if (months > 23) {\r
- ago = yr + " years ago";\r
+ return yr + " years ago";\r
} else {\r
- ago = months + " months ago";\r
+ return months + " months ago";\r
}\r
}\r
}\r
- return ago;\r
}\r
}\r
import org.apache.wicket.Session;\r
import org.apache.wicket.markup.html.WebPage;\r
import org.apache.wicket.protocol.http.WebApplication;\r
-import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy;\r
\r
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
package com.gitblit.wicket;\r
\r
import org.apache.wicket.Page;\r
-import org.apache.wicket.protocol.http.WicketURLDecoder;\r
-import org.apache.wicket.protocol.http.WicketURLEncoder;\r
import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy;\r
\r
import com.gitblit.GitBlit;\r
* Panel fragment for displaying login or logout/change_password links.\r
* \r
*/\r
- class UserFragment extends Fragment {\r
+ static class UserFragment extends Fragment {\r
\r
private static final long serialVersionUID = 1L;\r
\r
add(new Label("username", GitBlitWebSession.get().getUser().toString() + ":"));\r
add(new LinkPanel("loginLink", null, markupProvider.getString("gb.logout"),\r
LogoutPage.class));\r
- // quick and dirty hack for showing a separator \r
+ // quick and dirty hack for showing a separator\r
add(new Label("separator", "|"));\r
add(new BookmarkablePageLink<Void>("changePasswordLink", ChangePasswordPage.class));\r
} else {\r
throw new RestartResponseException(getApplication().getHomePage());\r
}\r
\r
- if (!GitBlit.getBoolean(Keys.web.authenticateAdminPages, true) && !GitBlit.getBoolean(Keys.web.authenticateViewPages, false)) {\r
+ if (!GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)\r
+ && !GitBlit.getBoolean(Keys.web.authenticateViewPages, false)) {\r
// no authentication enabled\r
throw new RestartResponseException(getApplication().getHomePage());\r
}\r
confirmPasswordField.setResetPassword(false);\r
form.add(confirmPasswordField);\r
form.add(new FeedbackPanel("feedback"));\r
- \r
+\r
form.add(new Button("save"));\r
- Button cancel = new Button("cancel"){ \r
+ Button cancel = new Button("cancel") {\r
private static final long serialVersionUID = 1L;\r
\r
@Override\r
public void onSubmit() {\r
- setResponsePage(RepositoriesPage.class);\r
- }\r
- };\r
- cancel.setDefaultFormProcessing(false);\r
- form.add(cancel);\r
- \r
+ setResponsePage(RepositoriesPage.class);\r
+ }\r
+ };\r
+ cancel.setDefaultFormProcessing(false);\r
+ form.add(cancel);\r
+\r
add(form);\r
}\r
}\r
form.add(usersPalette);\r
\r
form.add(new Button("save"));\r
- Button cancel = new Button("cancel"){ \r
+ Button cancel = new Button("cancel") {\r
private static final long serialVersionUID = 1L;\r
\r
@Override\r
public void onSubmit() {\r
- setResponsePage(RepositoriesPage.class);\r
- }\r
- };\r
- cancel.setDefaultFormProcessing(false);\r
- form.add(cancel);\r
- \r
+ setResponsePage(RepositoriesPage.class);\r
+ }\r
+ };\r
+ cancel.setDefaultFormProcessing(false);\r
+ form.add(cancel);\r
+\r
add(form);\r
}\r
\r
form.add(confirmPasswordField);\r
form.add(new CheckBox("canAdmin"));\r
form.add(repositories);\r
- \r
+\r
form.add(new Button("save"));\r
- Button cancel = new Button("cancel"){ \r
+ Button cancel = new Button("cancel") {\r
private static final long serialVersionUID = 1L;\r
\r
@Override\r
public void onSubmit() {\r
- setResponsePage(RepositoriesPage.class);\r
- }\r
- };\r
- cancel.setDefaultFormProcessing(false);\r
- form.add(cancel);\r
- \r
+ setResponsePage(RepositoriesPage.class);\r
+ }\r
+ };\r
+ cancel.setDefaultFormProcessing(false);\r
+ form.add(cancel);\r
+\r
add(form);\r
}\r
}\r
\r
public LogoutPage() {\r
GitBlitWebSession.get().invalidate();\r
- GitBlit.self().setCookie(((WebResponse) getResponse()), null);\r
+ GitBlit.self().setCookie((WebResponse) getResponse(), null);\r
setRedirect(true);\r
setResponsePage(getApplication().getHomePage());\r
}\r
InputStream is = res.getResourceStream().getInputStream();\r
InputStreamReader reader = new InputStreamReader(is);\r
message = MarkdownUtils.transformMarkdown(reader);\r
+ reader.close();\r
} catch (Throwable t) {\r
message = "Failed to read default welcome message!";\r
error(message, t, false);\r
add(new Label("repositoryDescription", getRepositoryModel().description));\r
add(new Label("repositoryOwner", getRepositoryModel().owner));\r
\r
- add(WicketUtils.createTimestampLabel("repositoryLastChange", JGitUtils.getLastChange(r, null),\r
- getTimeZone()));\r
+ add(WicketUtils.createTimestampLabel("repositoryLastChange",\r
+ JGitUtils.getLastChange(r, null), getTimeZone()));\r
if (metricsTotal == null) {\r
add(new Label("branchStats", ""));\r
} else {\r
\r
String author = entry.getAuthorIdent().getName();\r
LinkPanel authorLink = new LinkPanel("branchAuthor", "list", author,\r
- SearchPage.class, WicketUtils.newSearchParameter(model.name, entry.getName(),\r
- author, SearchType.AUTHOR));\r
+ SearchPage.class, WicketUtils.newSearchParameter(model.name,\r
+ entry.getName(), author, SearchType.AUTHOR));\r
setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);\r
item.add(authorLink);\r
- \r
+\r
// short message\r
String shortMessage = entry.getShortMessage();\r
String trimmedMessage = StringUtils.trimShortLog(shortMessage);\r
- LinkPanel shortlog = new LinkPanel("branchLog", "list subject",\r
- trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(\r
- model.name, entry.getName()));\r
+ LinkPanel shortlog = new LinkPanel("branchLog", "list subject", trimmedMessage,\r
+ CommitPage.class, WicketUtils.newObjectParameter(model.name,\r
+ entry.getName()));\r
if (!shortMessage.equals(trimmedMessage)) {\r
WicketUtils.setHtmlTooltip(shortlog, shortMessage);\r
}\r
item.add(shortlog);\r
- \r
+\r
if (maxCount <= 0) {\r
Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);\r
fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils\r
Map<String, List<RepositoryModel>> groups = new HashMap<String, List<RepositoryModel>>();\r
for (RepositoryModel model : models) {\r
String rootPath = StringUtils.getRootPath(model.name);\r
- if (StringUtils.isEmpty(rootPath)) { \r
+ if (StringUtils.isEmpty(rootPath)) {\r
// root repository\r
- rootRepositories.add(model); \r
+ rootRepositories.add(model);\r
} else {\r
// non-root, grouped repository\r
if (!groups.containsKey(rootPath)) {\r
}\r
List<String> roots = new ArrayList<String>(groups.keySet());\r
Collections.sort(roots);\r
- \r
+\r
if (rootRepositories.size() > 0) {\r
// inject the root repositories at the top of the page\r
String rootPath = GitBlit.getString(Keys.web.repositoryRootGroupName, " ");\r
row.add(new LinkPanel("repositoryDescription", "list", entry.description,\r
SummaryPage.class, pp));\r
if (showSize) {\r
- row.add(new Label("repositorySize", byteFormat.format(GitBlit.self().calculateSize(entry))));\r
+ row.add(new Label("repositorySize", byteFormat.format(GitBlit.self()\r
+ .calculateSize(entry))));\r
} else {\r
row.add(new Label("repositorySize").setVisible(false));\r
}\r
// New repository\r
row.add(new Label("repositoryName", entry.name));\r
row.add(new Label("repositoryDescription", entry.description));\r
- row.add(new Label("repositorySize", "<span class='empty'>(empty)</span>").setEscapeModelStrings(false));\r
+ row.add(new Label("repositorySize", "<span class='empty'>(empty)</span>")\r
+ .setEscapeModelStrings(false));\r
}\r
\r
if (entry.useTickets) {\r
item.add(new LinkPanel("tagName", "list name", entry.displayName, linkClass,\r
WicketUtils.newObjectParameter(repositoryName, entry\r
.getReferencedObjectId().getName())));\r
- \r
+\r
// workaround for RevTag returning a lengthy shortlog. :(\r
String message = StringUtils.trimShortLog(entry.getShortMessage());\r
\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.tests;\r
+\r
+import java.io.File;\r
+\r
+import com.gitblit.utils.FileUtils;\r
+\r
+import junit.framework.TestCase;\r
+\r
+public class FileUtilsTest extends TestCase {\r
+\r
+ public void testReadContent() throws Exception {\r
+ File dir = new File(System.getProperty("user.dir"));\r
+ String rawContent = FileUtils.readContent(new File(dir, "LICENSE"), "\n");\r
+ assertTrue(rawContent.trim().startsWith("Apache License"));\r
+ }\r
+\r
+ public void testFolderSize() throws Exception {\r
+ assertEquals(-1, FileUtils.folderSize(null));\r
+ assertEquals(-1, FileUtils.folderSize(new File(System.getProperty("user.dir"), "pretend")));\r
+\r
+ File dir = new File(System.getProperty("user.dir"), "distrib");\r
+ long size = FileUtils.folderSize(dir);\r
+ assertTrue("size is actually " + size, size >= 470000L);\r
+\r
+ File file = new File(System.getProperty("user.dir"), "LICENSE");\r
+ size = FileUtils.folderSize(file);\r
+ assertTrue("size is actually " + size, size == 11556L);\r
+\r
+ }\r
+}
\ No newline at end of file
import org.eclipse.jgit.lib.Repository;\r
import org.eclipse.jgit.storage.file.FileRepository;\r
\r
-import com.gitblit.FileUserService;\r
import com.gitblit.FileSettings;\r
+import com.gitblit.FileUserService;\r
import com.gitblit.GitBlit;\r
import com.gitblit.GitBlitException;\r
import com.gitblit.models.RepositoryModel;\r
\r
public static Test suite() {\r
TestSuite suite = new TestSuite();\r
+ suite.addTestSuite(FileUtilsTest.class);\r
suite.addTestSuite(TimeUtilsTest.class);\r
suite.addTestSuite(StringUtilsTest.class);\r
suite.addTestSuite(ByteFormatTest.class);\r
assertTrue("Helloworld model is null!", model != null);\r
assertTrue(model.toString().equals(\r
GitBlitSuite.getHelloworldRepository().getDirectory().getName()));\r
+ assertEquals("" + GitBlit.self().calculateSize(model), GitBlit.self().calculateSize(model),\r
+ 22004L);\r
}\r
\r
public void testUserModel() throws Exception {\r
assertFalse("Admin can still access repository!", model.canAccessRepository(repository));\r
model.addRepository(repository);\r
assertTrue("Admin can't access repository!", model.canAccessRepository(repository));\r
+ assertEquals(GitBlit.self().getRepositoryModel(model, "pretend"), null);\r
+ assertNotNull(GitBlit.self().getRepositoryModel(model, repository));\r
+ assertTrue(GitBlit.self().getRepositoryModels(model).size() > 0);\r
}\r
\r
public void testAccessRestrictionTypes() throws Exception {\r
\r
public void testFileSettings() throws Exception {\r
FileSettings settings = new FileSettings("distrib/gitblit.properties");\r
- assertTrue(settings.getBoolean("missing", true) == true);\r
+ assertTrue(settings.getBoolean("missing", true));\r
assertTrue(settings.getString("missing", "default").equals("default"));\r
assertTrue(settings.getInteger("missing", 10) == 10);\r
assertTrue(settings.getInteger("realm.realmFile", 5) == 5);\r
\r
- assertTrue(settings.getBoolean("git.enableGitServlet", false) == true);\r
+ assertTrue(settings.getBoolean("git.enableGitServlet", false));\r
assertTrue(settings.getString("realm.userService", null).equals("users.properties"));\r
assertTrue(settings.getInteger("realm.minPasswordLength", 0) == 5);\r
List<String> mdExtensions = settings.getStrings("web.markdownExtensions");\r
List<String> keys = settings.getAllKeys("server");\r
assertTrue(keys.size() > 0);\r
assertTrue(keys.contains("server.httpsPort"));\r
+\r
+ assertTrue(settings.getChar("web.forwardSlashCharacter", ' ') == '/');\r
}\r
\r
public void testGitblitSettings() throws Exception {\r
// These are already tested by above test method.\r
- assertTrue(GitBlit.getBoolean("missing", true) == true);\r
+ assertTrue(GitBlit.getBoolean("missing", true));\r
assertTrue(GitBlit.getString("missing", "default").equals("default"));\r
assertTrue(GitBlit.getInteger("missing", 10) == 10);\r
assertTrue(GitBlit.getInteger("realm.userService", 5) == 5);\r
\r
- assertTrue(GitBlit.getBoolean("git.enableGitServlet", false) == true);\r
+ assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));\r
assertTrue(GitBlit.getString("realm.userService", null).equals("users.properties"));\r
assertTrue(GitBlit.getInteger("realm.minPasswordLength", 0) == 5);\r
List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");\r
List<String> keys = GitBlit.getAllKeys("server");\r
assertTrue(keys.size() > 0);\r
assertTrue(keys.contains("server.httpsPort"));\r
+\r
+ assertTrue(GitBlit.getChar("web.forwardSlashCharacter", ' ') == '/');\r
+ assertFalse(GitBlit.isDebugMode());\r
}\r
\r
public void testAuthentication() throws Exception {\r
public class MetricUtilsTest extends TestCase {\r
\r
public void testMetrics() throws Exception {\r
- Repository repository = GitBlitSuite.getHelloworldRepository();\r
+ testMetrics(GitBlitSuite.getHelloworldRepository());\r
+ testMetrics(GitBlitSuite.getBluezGnomeRepository());\r
+ }\r
+\r
+ private void testMetrics(Repository repository) throws Exception {\r
List<Metric> metrics = MetricUtils.getDateMetrics(repository, null, true, null);\r
repository.close();\r
assertTrue("No date metrics found!", metrics.size() > 0);\r
String output = "this<br/>is<br/>a<br/>test<br/><br/>of<br/><br/>line<br/><br/>breaking";\r
assertTrue(StringUtils.breakLinesForHtml(input).equals(output));\r
}\r
- \r
+\r
public void testEncodeUrl() throws Exception {\r
String input = "test /";\r
String output = "test%20%2F";\r
assertTrue(StringUtils.escapeForHtml(input, false).equals(outputNoChange));\r
assertTrue(StringUtils.escapeForHtml(input, true).equals(outputChange));\r
}\r
- \r
+\r
public void testDecodeForHtml() throws Exception {\r
String input = "& < > "";\r
String output = "& < > \"";\r
assertTrue(StringUtils.getSHA1("blob 16\000what is up, doc?").equals(\r
"bd9dbf5aae1a3862dd1526723246b20206e5fc37"));\r
}\r
- \r
+\r
public void testMD5() throws Exception {\r
assertTrue(StringUtils.getMD5("blob 16\000what is up, doc?").equals(\r
"77fb8d95331f0d557472f6776d3aedf6"));\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
List<RevCommit> commits = JGitUtils.getRevLog(repository, 1);\r
ByteArrayOutputStream os = new ByteArrayOutputStream();\r
- SyndicationUtils.toRSS("http://localhost", "Title", "Description", "Repository", commits, os);\r
+ SyndicationUtils.toRSS("http://localhost", "Title", "Description", "Repository", commits,\r
+ os);\r
String feed = os.toString();\r
os.close();\r
assertTrue(feed.length() > 100);\r