From 1f9daef870a8c7a984955166a542628d69012ed5 Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 27 May 2011 23:37:24 -0400 Subject: Codepro analyze dependencies. Documentation. --- src/com/gitblit/Build.java | 9 +- src/com/gitblit/BuildSite.java | 22 +- src/com/gitblit/Constants.java | 2 + src/com/gitblit/DownloadZipServlet.java | 2 +- src/com/gitblit/GitBlit.java | 13 +- src/com/gitblit/GitBlitServer.java | 39 +- src/com/gitblit/GitBlitServlet.java | 2 +- src/com/gitblit/ILoginService.java | 2 +- src/com/gitblit/JettyLoginService.java | 2 +- src/com/gitblit/MakeCertificate.java | 6 +- src/com/gitblit/models/Metric.java | 32 ++ src/com/gitblit/models/PathModel.java | 106 ++++++ src/com/gitblit/models/RefModel.java | 81 +++++ src/com/gitblit/models/RepositoryModel.java | 59 +++ src/com/gitblit/models/TicketModel.java | 111 ++++++ src/com/gitblit/models/UserModel.java | 53 +++ src/com/gitblit/utils/DiffUtils.java | 149 ++++++++ src/com/gitblit/utils/JGitUtils.java | 147 +------- src/com/gitblit/wicket/AdminPage.java | 26 -- src/com/gitblit/wicket/AuthorizationStrategy.java | 6 +- src/com/gitblit/wicket/BasePage.html | 40 -- src/com/gitblit/wicket/BasePage.java | 143 -------- src/com/gitblit/wicket/GitBlitWebApp.java | 2 + src/com/gitblit/wicket/GitBlitWebSession.java | 2 +- src/com/gitblit/wicket/LinkPanel.html | 9 - src/com/gitblit/wicket/LinkPanel.java | 61 ---- src/com/gitblit/wicket/LoginPage.html | 40 -- src/com/gitblit/wicket/LoginPage.java | 91 ----- src/com/gitblit/wicket/LogoutPage.java | 27 -- src/com/gitblit/wicket/RepositoryPage.html | 32 -- src/com/gitblit/wicket/RepositoryPage.java | 402 --------------------- src/com/gitblit/wicket/RequiresAdminRole.java | 26 ++ src/com/gitblit/wicket/models/Metric.java | 32 -- src/com/gitblit/wicket/models/PathModel.java | 107 ------ src/com/gitblit/wicket/models/RefModel.java | 83 ----- src/com/gitblit/wicket/models/RepositoryModel.java | 59 --- src/com/gitblit/wicket/models/TicketModel.java | 117 ------ src/com/gitblit/wicket/models/UserModel.java | 53 --- src/com/gitblit/wicket/pages/BasePage.html | 40 ++ src/com/gitblit/wicket/pages/BasePage.java | 145 ++++++++ src/com/gitblit/wicket/pages/BlobDiffPage.java | 6 +- src/com/gitblit/wicket/pages/BlobPage.java | 1 - src/com/gitblit/wicket/pages/BranchesPage.java | 1 - src/com/gitblit/wicket/pages/CommitDiffPage.java | 8 +- src/com/gitblit/wicket/pages/CommitPage.java | 5 +- src/com/gitblit/wicket/pages/DocsPage.java | 5 +- .../gitblit/wicket/pages/EditRepositoryPage.java | 7 +- src/com/gitblit/wicket/pages/EditUserPage.java | 9 +- src/com/gitblit/wicket/pages/HistoryPage.java | 1 - src/com/gitblit/wicket/pages/LogPage.java | 1 - src/com/gitblit/wicket/pages/LoginPage.html | 40 ++ src/com/gitblit/wicket/pages/LoginPage.java | 86 +++++ src/com/gitblit/wicket/pages/LogoutPage.java | 27 ++ src/com/gitblit/wicket/pages/MarkdownPage.java | 1 - src/com/gitblit/wicket/pages/PatchPage.java | 3 +- src/com/gitblit/wicket/pages/RepositoriesPage.java | 1 - src/com/gitblit/wicket/pages/RepositoryPage.html | 32 ++ src/com/gitblit/wicket/pages/RepositoryPage.java | 396 ++++++++++++++++++++ src/com/gitblit/wicket/pages/SearchPage.java | 1 - src/com/gitblit/wicket/pages/SummaryPage.java | 3 +- src/com/gitblit/wicket/pages/TagPage.java | 5 +- src/com/gitblit/wicket/pages/TagsPage.java | 1 - src/com/gitblit/wicket/pages/TicketPage.java | 5 +- src/com/gitblit/wicket/pages/TicketsPage.java | 5 +- src/com/gitblit/wicket/pages/TreePage.java | 5 +- src/com/gitblit/wicket/panels/BranchesPanel.java | 5 +- .../gitblit/wicket/panels/CommitHeaderPanel.java | 1 - .../gitblit/wicket/panels/CommitLegendPanel.java | 2 +- src/com/gitblit/wicket/panels/HistoryPanel.java | 5 +- src/com/gitblit/wicket/panels/LinkPanel.html | 9 + src/com/gitblit/wicket/panels/LinkPanel.java | 61 ++++ src/com/gitblit/wicket/panels/LogPanel.java | 1 - .../wicket/panels/PathBreadcrumbsPanel.java | 15 +- src/com/gitblit/wicket/panels/RefsPanel.java | 1 - .../gitblit/wicket/panels/RepositoriesPanel.java | 5 +- src/com/gitblit/wicket/panels/SearchPanel.java | 1 - src/com/gitblit/wicket/panels/TagsPanel.java | 3 +- src/com/gitblit/wicket/panels/UsersPanel.java | 1 - 78 files changed, 1576 insertions(+), 1569 deletions(-) create mode 100644 src/com/gitblit/models/Metric.java create mode 100644 src/com/gitblit/models/PathModel.java create mode 100644 src/com/gitblit/models/RefModel.java create mode 100644 src/com/gitblit/models/RepositoryModel.java create mode 100644 src/com/gitblit/models/TicketModel.java create mode 100644 src/com/gitblit/models/UserModel.java create mode 100644 src/com/gitblit/utils/DiffUtils.java delete mode 100644 src/com/gitblit/wicket/AdminPage.java delete mode 100644 src/com/gitblit/wicket/BasePage.html delete mode 100644 src/com/gitblit/wicket/BasePage.java delete mode 100644 src/com/gitblit/wicket/LinkPanel.html delete mode 100644 src/com/gitblit/wicket/LinkPanel.java delete mode 100644 src/com/gitblit/wicket/LoginPage.html delete mode 100644 src/com/gitblit/wicket/LoginPage.java delete mode 100644 src/com/gitblit/wicket/LogoutPage.java delete mode 100644 src/com/gitblit/wicket/RepositoryPage.html delete mode 100644 src/com/gitblit/wicket/RepositoryPage.java create mode 100644 src/com/gitblit/wicket/RequiresAdminRole.java delete mode 100644 src/com/gitblit/wicket/models/Metric.java delete mode 100644 src/com/gitblit/wicket/models/PathModel.java delete mode 100644 src/com/gitblit/wicket/models/RefModel.java delete mode 100644 src/com/gitblit/wicket/models/RepositoryModel.java delete mode 100644 src/com/gitblit/wicket/models/TicketModel.java delete mode 100644 src/com/gitblit/wicket/models/UserModel.java create mode 100644 src/com/gitblit/wicket/pages/BasePage.html create mode 100644 src/com/gitblit/wicket/pages/BasePage.java create mode 100644 src/com/gitblit/wicket/pages/LoginPage.html create mode 100644 src/com/gitblit/wicket/pages/LoginPage.java create mode 100644 src/com/gitblit/wicket/pages/LogoutPage.java create mode 100644 src/com/gitblit/wicket/pages/RepositoryPage.html create mode 100644 src/com/gitblit/wicket/pages/RepositoryPage.java create mode 100644 src/com/gitblit/wicket/panels/LinkPanel.html create mode 100644 src/com/gitblit/wicket/panels/LinkPanel.java (limited to 'src') diff --git a/src/com/gitblit/Build.java b/src/com/gitblit/Build.java index da0c3e03..a6d5bb02 100644 --- a/src/com/gitblit/Build.java +++ b/src/com/gitblit/Build.java @@ -80,7 +80,7 @@ public class Build { downloadFromApache(MavenObject.MARKDOWNPAPERS, BuildType.COMPILETIME); downloadFromApache(MavenObject.BOUNCYCASTLE, BuildType.COMPILETIME); downloadFromApache(MavenObject.BOUNCYCASTLE_MAIL, BuildType.COMPILETIME); - + downloadFromApache(MavenObject.JSCH, BuildType.RUNTIME); downloadFromApache(MavenObject.JSCH, BuildType.COMPILETIME); @@ -389,10 +389,9 @@ public class Build { "384058ca906dffb8b8708c2db8849c9754359b28", "7b026658ed8de2eccc2d11d647d43d7c84a56911", "6c19e37b3caafd70c1b7b024ae1858c725181688"); - - public static final MavenObject JSCH = new MavenObject("JSch", "com/jcraft", - "jsch", "0.1.44-1", 214000, 211000, 413000, - "2e9ae08de5a71bd0e0d3ba2558598181bfa71d4e", + + public static final MavenObject JSCH = new MavenObject("JSch", "com/jcraft", "jsch", + "0.1.44-1", 214000, 211000, 413000, "2e9ae08de5a71bd0e0d3ba2558598181bfa71d4e", "e528f593b19b04d500992606f58b87fcfded8883", "d0ffadd0a4ab909d94a577b5aad43c13b617ddcb"); diff --git a/src/com/gitblit/BuildSite.java b/src/com/gitblit/BuildSite.java index f3a1a9f1..890cec1e 100644 --- a/src/com/gitblit/BuildSite.java +++ b/src/com/gitblit/BuildSite.java @@ -37,6 +37,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.ParameterException; import com.beust.jcommander.Parameters; import com.gitblit.utils.MarkdownUtils; +import com.gitblit.utils.StringUtils; public class BuildSite { @@ -83,8 +84,8 @@ public class BuildSite { sb.setLength(sb.length() - 3); sb.trimToSize(); - String htmlHeader = readContent(new File(params.pageHeader)); - String htmlFooter = readContent(new File(params.pageFooter)); + String htmlHeader = readContent(new File(params.pageHeader), "\n"); + String htmlFooter = readContent(new File(params.pageFooter), "\n"); final String links = sb.toString(); final String header = MessageFormat.format(htmlHeader, Constants.FULL_NAME, links); final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); @@ -101,6 +102,13 @@ public class BuildSite { String[] kv = token.split("="); content = content.replace(kv[0], kv[1]); } + for (String alias : params.loads) { + String[] kv = alias.split("="); + String loadedContent = readContent(new File(kv[1]), "\n"); + loadedContent = StringUtils.escapeForHtml(loadedContent, false); + loadedContent = StringUtils.breakLinesForHtml(loadedContent); + content = content.replace(kv[0], loadedContent); + } OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File( destinationFolder, fileName)), Charset.forName("UTF-8")); writer.write(header); @@ -115,7 +123,7 @@ public class BuildSite { } } - private static String readContent(File file) { + private static String readContent(File file, String lineEnding) { StringBuilder sb = new StringBuilder(); try { InputStreamReader is = new InputStreamReader(new FileInputStream(file), @@ -124,6 +132,9 @@ public class BuildSite { String line = null; while ((line = reader.readLine()) != null) { sb.append(line); + if (lineEnding != null) { + sb.append(lineEnding); + } } reader.close(); } catch (Throwable t) { @@ -171,8 +182,11 @@ public class BuildSite { @Parameter(names = { "--alias" }, description = "Filename=Linkname aliases", required = false) public List aliases = new ArrayList(); - @Parameter(names = { "--substitute" }, description = "@TOKEN@=value", required = false) + @Parameter(names = { "--substitute" }, description = "%TOKEN%=value", required = false) public List substitutions = new ArrayList(); + @Parameter(names = { "--load" }, description = "%TOKEN%=filename", required = false) + public List loads = new ArrayList(); + } } diff --git a/src/com/gitblit/Constants.java b/src/com/gitblit/Constants.java index b6741820..3589f491 100644 --- a/src/com/gitblit/Constants.java +++ b/src/com/gitblit/Constants.java @@ -37,6 +37,8 @@ public class Constants { public static final String ZIP_SERVLET_PATH = "/zip/"; + public static final String BORDER = "***********************************************************"; + public static enum AccessRestrictionType { NONE, PUSH, CLONE, VIEW; diff --git a/src/com/gitblit/DownloadZipServlet.java b/src/com/gitblit/DownloadZipServlet.java index 3bbf2253..86ca4e77 100644 --- a/src/com/gitblit/DownloadZipServlet.java +++ b/src/com/gitblit/DownloadZipServlet.java @@ -26,9 +26,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.gitblit.Constants.AccessRestrictionType; +import com.gitblit.models.RepositoryModel; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.models.RepositoryModel; public class DownloadZipServlet extends HttpServlet { diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 9dd3a9e5..52dd9dbb 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -35,10 +35,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.gitblit.Constants.AccessRestrictionType; +import com.gitblit.models.RepositoryModel; +import com.gitblit.models.UserModel; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.models.RepositoryModel; -import com.gitblit.wicket.models.UserModel; public class GitBlit implements ServletContextListener { @@ -151,8 +151,8 @@ public class GitBlit implements ServletContextListener { r = repositoryResolver.open(null, repositoryName); } catch (RepositoryNotFoundException e) { r = null; - logger.error("GitBlit.getRepository(String) failed to find repository " - + repositoryName); + logger.error("GitBlit.getRepository(String) failed to find " + + new File(repositoriesFolder, repositoryName).getAbsolutePath()); } catch (ServiceNotEnabledException e) { r = null; e.printStackTrace(); @@ -186,6 +186,9 @@ public class GitBlit implements ServletContextListener { public RepositoryModel getRepositoryModel(String repositoryName) { Repository r = getRepository(repositoryName); + if (r == null) { + return null; + } RepositoryModel model = new RepositoryModel(); model.name = repositoryName; model.hasCommits = JGitUtils.hasCommits(r); @@ -315,7 +318,7 @@ public class GitBlit implements ServletContextListener { } public void configureContext(IStoredSettings settings) { - logger.info("Using configuration from " + settings.toString()); + logger.info("Reading configuration from " + settings.toString()); this.storedSettings = settings; repositoriesFolder = new File(settings.getString(Keys.git.repositoriesFolder, "repos")); exportAll = settings.getBoolean(Keys.git.exportAll, true); diff --git a/src/com/gitblit/GitBlitServer.java b/src/com/gitblit/GitBlitServer.java index c8731572..416c47ad 100644 --- a/src/com/gitblit/GitBlitServer.java +++ b/src/com/gitblit/GitBlitServer.java @@ -65,12 +65,8 @@ import com.gitblit.wicket.GitBlitWebApp; public class GitBlitServer { - private static final String BORDER = "***********************************************************"; - private static Logger logger; - private static final FileSettings FILESETTINGS = new FileSettings(); - public static void main(String[] args) { Params params = new Params(); JCommander jc = new JCommander(params); @@ -91,9 +87,9 @@ public class GitBlitServer { } private static void usage(JCommander jc, ParameterException t) { - System.out.println(BORDER); + System.out.println(Constants.BORDER); System.out.println(Constants.getGitBlitVersion()); - System.out.println(BORDER); + System.out.println(Constants.BORDER); System.out.println(); if (t != null) { System.out.println(t.getMessage()); @@ -129,18 +125,19 @@ public class GitBlitServer { * Start Server. */ private static void start(Params params) { - String pattern = FILESETTINGS.getString(Keys.server.log4jPattern, + FileSettings settings = params.FILESETTINGS; + String pattern = settings.getString(Keys.server.log4jPattern, "%-5p %d{MM-dd HH:mm:ss.SSS} %-20.20c{1} %m%n"); // allow os override of logging pattern String os = System.getProperty("os.name").toLowerCase(); if (os.indexOf("windows") > -1) { - String winPattern = FILESETTINGS.getString(Keys.server.log4jPattern_windows, pattern); + String winPattern = settings.getString(Keys.server.log4jPattern_windows, pattern); if (!StringUtils.isEmpty(winPattern)) { pattern = winPattern; } } else if (os.indexOf("linux") > -1) { - String linuxPattern = FILESETTINGS.getString(Keys.server.log4jPattern_linux, pattern); + String linuxPattern = settings.getString(Keys.server.log4jPattern_linux, pattern); if (!StringUtils.isEmpty(linuxPattern)) { pattern = linuxPattern; } @@ -151,9 +148,9 @@ public class GitBlitServer { rootLogger.addAppender(new ConsoleAppender(layout)); logger = LoggerFactory.getLogger(GitBlitServer.class); - logger.info(BORDER); + logger.info(Constants.BORDER); logger.info(Constants.getGitBlitVersion()); - logger.info(BORDER); + logger.info(Constants.BORDER); String osname = System.getProperty("os.name"); String osversion = System.getProperty("os.version"); @@ -163,7 +160,7 @@ public class GitBlitServer { List connectors = new ArrayList(); if (params.port > 0) { Connector httpConnector = createConnector(params.useNIO, params.port); - String bindInterface = FILESETTINGS.getString(Keys.server.httpBindInterface, null); + String bindInterface = settings.getString(Keys.server.httpBindInterface, null); if (!StringUtils.isEmpty(bindInterface)) { logger.warn(MessageFormat.format("Binding connector on port {0} to {1}", params.port, bindInterface)); @@ -182,7 +179,7 @@ public class GitBlitServer { if (keystore.exists()) { Connector secureConnector = createSSLConnector(keystore, params.storePassword, params.useNIO, params.securePort); - String bindInterface = FILESETTINGS.getString(Keys.server.httpsBindInterface, null); + String bindInterface = settings.getString(Keys.server.httpsBindInterface, null); if (!StringUtils.isEmpty(bindInterface)) { logger.warn(MessageFormat.format("Binding ssl connector on port {0} to {1}", params.securePort, bindInterface)); @@ -246,11 +243,11 @@ public class GitBlitServer { // Git Servlet ServletHolder gitServlet = null; String gitServletPathSpec = Constants.GIT_SERVLET_PATH + "*"; - if (FILESETTINGS.getBoolean(Keys.git.enableGitServlet, true)) { + if (settings.getBoolean(Keys.git.enableGitServlet, true)) { gitServlet = rootContext.addServlet(GitBlitServlet.class, gitServletPathSpec); gitServlet.setInitParameter("base-path", params.repositoriesFolder); gitServlet.setInitParameter("export-all", - FILESETTINGS.getBoolean(Keys.git.exportAll, true) ? "1" : "0"); + settings.getBoolean(Keys.git.exportAll, true) ? "1" : "0"); } // Login Service @@ -300,12 +297,14 @@ public class GitBlitServer { handler = rootContext; } + logger.info("Git repositories folder " + new File(params.repositoriesFolder).getAbsolutePath()); + // Set the server's contexts server.setHandler(handler); // Setup the GitBlit context GitBlit gitblit = GitBlit.self(); - gitblit.configureContext(FILESETTINGS); + gitblit.configureContext(settings); rootContext.addEventListener(gitblit); // Start the Server @@ -385,6 +384,8 @@ public class GitBlitServer { private final ServerSocket socket; private final Server server; + + private final Logger logger = LoggerFactory.getLogger(ShutdownMonitorThread.class); public ShutdownMonitorThread(Server server, Params params) { this.server = server; @@ -408,9 +409,9 @@ public class GitBlitServer { BufferedReader reader = new BufferedReader(new InputStreamReader( accept.getInputStream())); reader.readLine(); - logger.info(BORDER); + logger.info(Constants.BORDER); logger.info("Stopping " + Constants.NAME); - logger.info(BORDER); + logger.info(Constants.BORDER); server.stop(); server.setStopAtShutdown(false); accept.close(); @@ -423,6 +424,8 @@ public class GitBlitServer { @Parameters(separators = " ") private static class Params { + + private static final FileSettings FILESETTINGS = new FileSettings(); /* * Server parameters diff --git a/src/com/gitblit/GitBlitServlet.java b/src/com/gitblit/GitBlitServlet.java index 91bd7b26..46868846 100644 --- a/src/com/gitblit/GitBlitServlet.java +++ b/src/com/gitblit/GitBlitServlet.java @@ -27,7 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.gitblit.Constants.AccessRestrictionType; -import com.gitblit.wicket.models.RepositoryModel; +import com.gitblit.models.RepositoryModel; public class GitBlitServlet extends GitServlet { diff --git a/src/com/gitblit/ILoginService.java b/src/com/gitblit/ILoginService.java index 155595bb..d7bfd017 100644 --- a/src/com/gitblit/ILoginService.java +++ b/src/com/gitblit/ILoginService.java @@ -17,7 +17,7 @@ package com.gitblit; import java.util.List; -import com.gitblit.wicket.models.UserModel; +import com.gitblit.models.UserModel; public interface ILoginService { diff --git a/src/com/gitblit/JettyLoginService.java b/src/com/gitblit/JettyLoginService.java index ac7dd799..63a98618 100644 --- a/src/com/gitblit/JettyLoginService.java +++ b/src/com/gitblit/JettyLoginService.java @@ -38,7 +38,7 @@ import org.eclipse.jetty.util.log.Log; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.gitblit.wicket.models.UserModel; +import com.gitblit.models.UserModel; public class JettyLoginService extends MappedLoginService implements ILoginService { diff --git a/src/com/gitblit/MakeCertificate.java b/src/com/gitblit/MakeCertificate.java index eafb98a4..67b2fd90 100644 --- a/src/com/gitblit/MakeCertificate.java +++ b/src/com/gitblit/MakeCertificate.java @@ -44,9 +44,7 @@ import com.beust.jcommander.Parameters; import com.gitblit.utils.TimeUtils; public class MakeCertificate { - - private static final FileSettings FILESETTINGS = new FileSettings(); - + private static final String BC = org.bouncycastle.jce.provider.BouncyCastleProvider.PROVIDER_NAME; public static void main(String... args) { @@ -158,6 +156,8 @@ public class MakeCertificate { @Parameters(separators = " ") private static class Params { + private static final FileSettings FILESETTINGS = new FileSettings(); + @Parameter(names = { "--alias" }, description = "Server alias", required = true) public String alias; diff --git a/src/com/gitblit/models/Metric.java b/src/com/gitblit/models/Metric.java new file mode 100644 index 00000000..9ff270ad --- /dev/null +++ b/src/com/gitblit/models/Metric.java @@ -0,0 +1,32 @@ +/* + * 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.models; + +import java.io.Serializable; + +public class Metric implements Serializable { + + private static final long serialVersionUID = 1L; + + public String name; + public double count; + public double tag; + public int duration; + + public Metric(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/src/com/gitblit/models/PathModel.java b/src/com/gitblit/models/PathModel.java new file mode 100644 index 00000000..17a7971e --- /dev/null +++ b/src/com/gitblit/models/PathModel.java @@ -0,0 +1,106 @@ +/* + * 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.models; + +import java.io.Serializable; + +import org.eclipse.jgit.diff.DiffEntry.ChangeType; +import org.eclipse.jgit.lib.FileMode; + +public class PathModel implements Serializable, Comparable { + + private static final long serialVersionUID = 1L; + + public final String name; + public final String path; + public final long size; + public final int mode; + public final String commitId; + public boolean isParentPath; + + public PathModel(String name, String path, long size, int mode, String commitId) { + this.name = name; + this.path = path; + this.size = size; + this.mode = mode; + this.commitId = commitId; + } + + public boolean isTree() { + return FileMode.TREE.equals(mode); + } + + public static PathModel getParentPath(String basePath, String commitId) { + String parentPath = null; + if (basePath.lastIndexOf('/') > -1) { + parentPath = basePath.substring(0, basePath.lastIndexOf('/')); + } + PathModel model = new PathModel("..", parentPath, 0, 40000, commitId); + model.isParentPath = true; + return model; + } + + @Override + public int hashCode() { + return commitId.hashCode() + path.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof PathModel) { + PathModel other = (PathModel) o; + return this.path.equals(other.path); + } + return super.equals(o); + } + + @Override + public int compareTo(PathModel o) { + boolean isTree = isTree(); + boolean otherTree = o.isTree(); + if (isTree && otherTree) { + return path.compareTo(o.path); + } else if (!isTree && !otherTree) { + return path.compareTo(o.path); + } else if (isTree && !otherTree) { + return -1; + } + return 1; + } + + public static class PathChangeModel extends PathModel { + + private static final long serialVersionUID = 1L; + + public final ChangeType changeType; + + public PathChangeModel(String name, String path, long size, int mode, String commitId, + ChangeType type) { + super(name, path, size, mode, commitId); + this.changeType = type; + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object o) { + return super.equals(o); + } + } +} diff --git a/src/com/gitblit/models/RefModel.java b/src/com/gitblit/models/RefModel.java new file mode 100644 index 00000000..b33c8ba7 --- /dev/null +++ b/src/com/gitblit/models/RefModel.java @@ -0,0 +1,81 @@ +/* + * 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.models; + +import java.io.Serializable; +import java.util.Date; + +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.revwalk.RevCommit; + +public class RefModel implements Serializable, Comparable { + + private static final long serialVersionUID = 1L; + public final String displayName; + public final RevCommit commit; + public transient Ref ref; + + public RefModel(String displayName, Ref ref, RevCommit commit) { + this.displayName = displayName; + this.ref = ref; + this.commit = commit; + } + + public Date getDate() { + return new Date(commit.getCommitTime() * 1000L); + } + + public String getName() { + return ref.getName(); + } + + public ObjectId getCommitId() { + return commit.getId(); + } + + public String getShortLog() { + return commit.getShortMessage(); + } + + public ObjectId getObjectId() { + return ref.getObjectId(); + } + + public boolean isAnnotatedTag() { + // ref.isPeeled() ?? + return !getCommitId().equals(getObjectId()); + } + + @Override + public int hashCode() { + return getCommitId().hashCode() + getName().hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof RefModel) { + RefModel other = (RefModel) o; + return getName().equals(other.getName()); + } + return super.equals(o); + } + + @Override + public int compareTo(RefModel o) { + return getDate().compareTo(o.getDate()); + } +} \ No newline at end of file diff --git a/src/com/gitblit/models/RepositoryModel.java b/src/com/gitblit/models/RepositoryModel.java new file mode 100644 index 00000000..7241d76b --- /dev/null +++ b/src/com/gitblit/models/RepositoryModel.java @@ -0,0 +1,59 @@ +/* + * 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.models; + +import java.io.Serializable; +import java.util.Date; + +import com.gitblit.Constants.AccessRestrictionType; + +public class RepositoryModel implements Serializable { + + private static final long serialVersionUID = 1L; + + // field names are reflectively mapped in EditRepository page + public String name; + public String description; + public String owner; + public Date lastChange; + public boolean hasCommits; + public boolean showRemoteBranches; + public boolean useTickets; + public boolean useDocs; + public AccessRestrictionType accessRestriction; + public boolean isFrozen; + + public RepositoryModel() { + this.name = ""; + this.description = ""; + this.owner = ""; + this.lastChange = new Date(0); + this.accessRestriction = AccessRestrictionType.NONE; + } + + public RepositoryModel(String name, String description, String owner, Date lastchange) { + this.name = name; + this.description = description; + this.owner = owner; + this.lastChange = lastchange; + this.accessRestriction = AccessRestrictionType.NONE; + } + + @Override + public String toString() { + return name; + } +} \ No newline at end of file diff --git a/src/com/gitblit/models/TicketModel.java b/src/com/gitblit/models/TicketModel.java new file mode 100644 index 00000000..b284340a --- /dev/null +++ b/src/com/gitblit/models/TicketModel.java @@ -0,0 +1,111 @@ +/* + * 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.models; + +import java.io.Serializable; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class TicketModel implements Serializable, Comparable { + + private static final long serialVersionUID = 1L; + + public String id; + public String name; + public String title; + public String state; + public Date date; + public String handler; + public String milestone; + public String email; + public String author; + public List comments; + public List tags; + + public TicketModel(String ticketName) throws ParseException { + state = ""; + name = ticketName; + comments = new ArrayList(); + tags = new ArrayList(); + + String[] chunks = name.split("_"); + if (chunks.length == 3) { + date = new Date(Long.parseLong(chunks[0]) * 1000L); + title = chunks[1].replace('-', ' '); + } + } + + public static class Comment implements Serializable, Comparable { + + private static final long serialVersionUID = 1L; + + public String text; + public String author; + public Date date; + + public Comment(String text, Date date) { + this.text = text; + this.date = date; + } + + public Comment(String filename, String content) throws ParseException { + String[] chunks = filename.split("_", -1); + this.date = new Date(Long.parseLong(chunks[1]) * 1000L); + this.author = chunks[2]; + this.text = content; + } + + @Override + public int hashCode() { + return text.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof Comment) { + Comment other = (Comment) o; + return text.equals(other.text); + } + return super.equals(o); + } + + @Override + public int compareTo(Comment o) { + return date.compareTo(o.date); + } + } + + @Override + public int hashCode() { + return id.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof TicketModel) { + TicketModel other = (TicketModel) o; + return id.equals(other.id); + } + return super.equals(o); + } + + @Override + public int compareTo(TicketModel o) { + return date.compareTo(o.date); + } +} diff --git a/src/com/gitblit/models/UserModel.java b/src/com/gitblit/models/UserModel.java new file mode 100644 index 00000000..797c14e2 --- /dev/null +++ b/src/com/gitblit/models/UserModel.java @@ -0,0 +1,53 @@ +/* + * 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.models; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class UserModel implements Serializable { + + private static final long serialVersionUID = 1L; + + // field names are reflectively mapped in EditUser page + public String username; + public String password; + public boolean canAdmin; + public final List repositories = new ArrayList(); + + public UserModel(String username) { + this.username = username; + } + + public boolean canAccessRepository(String repositoryName) { + return canAdmin || repositories.contains(repositoryName); + } + + public void setRepositories(List repositories) { + this.repositories.clear(); + this.repositories.addAll(repositories); + } + + public void addRepository(String name) { + repositories.add(name.toLowerCase()); + } + + @Override + public String toString() { + return username; + } +} diff --git a/src/com/gitblit/utils/DiffUtils.java b/src/com/gitblit/utils/DiffUtils.java new file mode 100644 index 00000000..d7a4a632 --- /dev/null +++ b/src/com/gitblit/utils/DiffUtils.java @@ -0,0 +1,149 @@ +package com.gitblit.utils; + +import java.io.ByteArrayOutputStream; +import java.util.List; + +import org.eclipse.jgit.diff.DiffEntry; +import org.eclipse.jgit.diff.DiffFormatter; +import org.eclipse.jgit.diff.RawTextComparator; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevTree; +import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.treewalk.filter.TreeFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.gitblit.utils.JGitUtils.DiffOutputType; + +public class DiffUtils { + + private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class); + + public static String getCommitDiff(Repository r, RevCommit commit, DiffOutputType outputType) { + return getCommitDiff(r, null, commit, null, outputType); + } + + public static String getCommitDiff(Repository r, RevCommit commit, String path, + DiffOutputType outputType) { + return getCommitDiff(r, null, commit, path, outputType); + } + + public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit, + DiffOutputType outputType) { + return getCommitDiff(r, baseCommit, commit, null, outputType); + } + + public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit, + String path, DiffOutputType outputType) { + try { + RevTree baseTree; + if (baseCommit == null) { + final RevWalk rw = new RevWalk(r); + RevCommit parent = rw.parseCommit(commit.getParent(0).getId()); + rw.dispose(); + baseTree = parent.getTree(); + } else { + baseTree = baseCommit.getTree(); + } + + RevTree commitTree = commit.getTree(); + + final TreeWalk walk = new TreeWalk(r); + walk.reset(); + walk.setRecursive(true); + walk.addTree(baseTree); + walk.addTree(commitTree); + walk.setFilter(TreeFilter.ANY_DIFF); + + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + RawTextComparator cmp = RawTextComparator.DEFAULT; + DiffFormatter df; + switch (outputType) { + case GITWEB: + df = new GitWebDiffFormatter(os); + break; + case GITBLIT: + df = new GitBlitDiffFormatter(os); + break; + case PLAIN: + default: + df = new DiffFormatter(os); + break; + } + df.setRepository(r); + df.setDiffComparator(cmp); + df.setDetectRenames(true); + List diffs = df.scan(baseTree, commitTree); + if (path != null && path.length() > 0) { + for (DiffEntry diff : diffs) { + if (diff.getNewPath().equalsIgnoreCase(path)) { + df.format(diff); + break; + } + } + } else { + df.format(diffs); + } + String diff; + if (df instanceof GitWebDiffFormatter) { + // workaround for complex private methods in DiffFormatter + diff = ((GitWebDiffFormatter) df).getHtml(); + } else { + diff = os.toString(); + } + df.flush(); + return diff; + } catch (Throwable t) { + LOGGER.error("failed to generate commit diff!", t); + } + return null; + } + + public static String getCommitPatch(Repository r, RevCommit baseCommit, RevCommit commit, + String path) { + try { + RevTree baseTree; + if (baseCommit == null) { + final RevWalk rw = new RevWalk(r); + RevCommit parent = rw.parseCommit(commit.getParent(0).getId()); + baseTree = parent.getTree(); + } else { + baseTree = baseCommit.getTree(); + } + RevTree commitTree = commit.getTree(); + + final TreeWalk walk = new TreeWalk(r); + walk.reset(); + walk.setRecursive(true); + walk.addTree(baseTree); + walk.addTree(commitTree); + walk.setFilter(TreeFilter.ANY_DIFF); + + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + RawTextComparator cmp = RawTextComparator.DEFAULT; + PatchFormatter df = new PatchFormatter(os); + df.setRepository(r); + df.setDiffComparator(cmp); + df.setDetectRenames(true); + List diffs = df.scan(baseTree, commitTree); + if (path != null && path.length() > 0) { + for (DiffEntry diff : diffs) { + if (diff.getNewPath().equalsIgnoreCase(path)) { + df.format(diff); + break; + } + } + } else { + df.format(diffs); + } + String diff = df.getPatch(commit); + df.flush(); + return diff; + } catch (Throwable t) { + LOGGER.error("failed to generate commit diff!", t); + } + return null; + } +} diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index 088cd00e..f99fbfdd 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -73,12 +73,12 @@ import org.eclipse.jgit.util.io.DisabledOutputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.gitblit.wicket.models.Metric; -import com.gitblit.wicket.models.PathModel; -import com.gitblit.wicket.models.PathModel.PathChangeModel; -import com.gitblit.wicket.models.RefModel; -import com.gitblit.wicket.models.TicketModel; -import com.gitblit.wicket.models.TicketModel.Comment; +import com.gitblit.models.Metric; +import com.gitblit.models.PathModel; +import com.gitblit.models.RefModel; +import com.gitblit.models.TicketModel; +import com.gitblit.models.PathModel.PathChangeModel; +import com.gitblit.models.TicketModel.Comment; public class JGitUtils { @@ -183,11 +183,18 @@ public class JGitUtils { } public static boolean hasCommits(Repository r) { - return new File(r.getDirectory(), Constants.R_HEADS).list().length > 0; + if (r != null && r.getDirectory().exists()) { + return new File(r.getDirectory(), Constants.R_HEADS).list().length > 0; + } + return false; } public static Date getLastChange(Repository r) { if (!hasCommits(r)) { + // null repository + if (r == null) { + return new Date(0); + } // fresh repository return new Date(r.getDirectory().lastModified()); } @@ -460,132 +467,6 @@ public class JGitUtils { } } - public static String getCommitDiff(Repository r, RevCommit commit, DiffOutputType outputType) { - return getCommitDiff(r, null, commit, null, outputType); - } - - public static String getCommitDiff(Repository r, RevCommit commit, String path, - DiffOutputType outputType) { - return getCommitDiff(r, null, commit, path, outputType); - } - - public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit, - DiffOutputType outputType) { - return getCommitDiff(r, baseCommit, commit, null, outputType); - } - - public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit, - String path, DiffOutputType outputType) { - try { - RevTree baseTree; - if (baseCommit == null) { - final RevWalk rw = new RevWalk(r); - RevCommit parent = rw.parseCommit(commit.getParent(0).getId()); - rw.dispose(); - baseTree = parent.getTree(); - } else { - baseTree = baseCommit.getTree(); - } - - RevTree commitTree = commit.getTree(); - - final TreeWalk walk = new TreeWalk(r); - walk.reset(); - walk.setRecursive(true); - walk.addTree(baseTree); - walk.addTree(commitTree); - walk.setFilter(TreeFilter.ANY_DIFF); - - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - RawTextComparator cmp = RawTextComparator.DEFAULT; - DiffFormatter df; - switch (outputType) { - case GITWEB: - df = new GitWebDiffFormatter(os); - break; - case GITBLIT: - df = new GitBlitDiffFormatter(os); - break; - case PLAIN: - default: - df = new DiffFormatter(os); - break; - } - df.setRepository(r); - df.setDiffComparator(cmp); - df.setDetectRenames(true); - List diffs = df.scan(baseTree, commitTree); - if (path != null && path.length() > 0) { - for (DiffEntry diff : diffs) { - if (diff.getNewPath().equalsIgnoreCase(path)) { - df.format(diff); - break; - } - } - } else { - df.format(diffs); - } - String diff; - if (df instanceof GitWebDiffFormatter) { - // workaround for complex private methods in DiffFormatter - diff = ((GitWebDiffFormatter) df).getHtml(); - } else { - diff = os.toString(); - } - df.flush(); - return diff; - } catch (Throwable t) { - LOGGER.error("failed to generate commit diff!", t); - } - return null; - } - - public static String getCommitPatch(Repository r, RevCommit baseCommit, RevCommit commit, - String path) { - try { - RevTree baseTree; - if (baseCommit == null) { - final RevWalk rw = new RevWalk(r); - RevCommit parent = rw.parseCommit(commit.getParent(0).getId()); - baseTree = parent.getTree(); - } else { - baseTree = baseCommit.getTree(); - } - RevTree commitTree = commit.getTree(); - - final TreeWalk walk = new TreeWalk(r); - walk.reset(); - walk.setRecursive(true); - walk.addTree(baseTree); - walk.addTree(commitTree); - walk.setFilter(TreeFilter.ANY_DIFF); - - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - RawTextComparator cmp = RawTextComparator.DEFAULT; - PatchFormatter df = new PatchFormatter(os); - df.setRepository(r); - df.setDiffComparator(cmp); - df.setDetectRenames(true); - List diffs = df.scan(baseTree, commitTree); - if (path != null && path.length() > 0) { - for (DiffEntry diff : diffs) { - if (diff.getNewPath().equalsIgnoreCase(path)) { - df.format(diff); - break; - } - } - } else { - df.format(diffs); - } - String diff = df.getPatch(commit); - df.flush(); - return diff; - } catch (Throwable t) { - LOGGER.error("failed to generate commit diff!", t); - } - return null; - } - private static PathModel getPathModel(TreeWalk walk, String basePath, RevCommit commit) { String name; long size = 0; diff --git a/src/com/gitblit/wicket/AdminPage.java b/src/com/gitblit/wicket/AdminPage.java deleted file mode 100644 index 1c9e0ef5..00000000 --- a/src/com/gitblit/wicket/AdminPage.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.wicket; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface AdminPage { -} diff --git a/src/com/gitblit/wicket/AuthorizationStrategy.java b/src/com/gitblit/wicket/AuthorizationStrategy.java index 42d25225..b6b745bd 100644 --- a/src/com/gitblit/wicket/AuthorizationStrategy.java +++ b/src/com/gitblit/wicket/AuthorizationStrategy.java @@ -22,7 +22,9 @@ import org.apache.wicket.authorization.strategies.page.AbstractPageAuthorization import com.gitblit.GitBlit; import com.gitblit.Keys; -import com.gitblit.wicket.models.UserModel; +import com.gitblit.models.UserModel; +import com.gitblit.wicket.pages.BasePage; +import com.gitblit.wicket.pages.LoginPage; import com.gitblit.wicket.pages.RepositoriesPage; public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy implements @@ -46,7 +48,7 @@ public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy imp } UserModel user = session.getUser(); - if (pageClass.isAnnotationPresent(AdminPage.class)) { + if (pageClass.isAnnotationPresent(RequiresAdminRole.class)) { // admin page if (allowAdmin) { if (authenticateAdmin) { diff --git a/src/com/gitblit/wicket/BasePage.html b/src/com/gitblit/wicket/BasePage.html deleted file mode 100644 index 0e8705c6..00000000 --- a/src/com/gitblit/wicket/BasePage.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - [page title] - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/com/gitblit/wicket/BasePage.java b/src/com/gitblit/wicket/BasePage.java deleted file mode 100644 index 2e4adfe3..00000000 --- a/src/com/gitblit/wicket/BasePage.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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.wicket; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.TimeZone; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.wicket.PageParameters; -import org.apache.wicket.RestartResponseAtInterceptPageException; -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.markup.html.panel.FeedbackPanel; -import org.apache.wicket.protocol.http.servlet.ServletWebRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.gitblit.Constants; -import com.gitblit.Constants.AccessRestrictionType; -import com.gitblit.GitBlit; -import com.gitblit.Keys; -import com.gitblit.wicket.pages.SummaryPage; - -public abstract class BasePage extends WebPage { - - private final Logger logger; - - public BasePage() { - super(); - logger = LoggerFactory.getLogger(getClass()); - } - - public BasePage(PageParameters params) { - super(params); - logger = LoggerFactory.getLogger(getClass()); - } - - protected void setupPage(String repositoryName, String pageName) { - if (repositoryName != null && repositoryName.trim().length() > 0) { - add(new Label("title", getServerName() + " - " + repositoryName)); - } else { - add(new Label("title", getServerName())); - } - // header - String siteName = GitBlit.getString(Keys.web.siteName, Constants.NAME); - if (siteName == null || siteName.trim().length() == 0) { - siteName = Constants.NAME; - } - add(new Label("siteName", siteName)); - add(new LinkPanel("repositoryName", null, repositoryName, SummaryPage.class, - WicketUtils.newRepositoryParameter(repositoryName))); - add(new Label("pageName", pageName)); - - // Feedback panel for info, warning, and non-fatal error messages - add(new FeedbackPanel("feedback")); - - // footer - if (GitBlit.getBoolean(Keys.web.authenticateViewPages, true) - || GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) { - if (GitBlitWebSession.get().isLoggedIn()) { - // logout - add(new LinkPanel("userPanel", null, getString("gb.logout") + " " - + GitBlitWebSession.get().getUser().toString(), LogoutPage.class)); - } else { - // login - add(new LinkPanel("userPanel", null, getString("gb.login"), LoginPage.class)); - } - } else { - add(new Label("userPanel", "")); - } - add(new Label("gbVersion", "v" + Constants.VERSION)); - if (GitBlit.getBoolean(Keys.web.aggressiveHeapManagement, false)) { - System.gc(); - } - } - - protected Map getAccessRestrictions() { - Map map = new LinkedHashMap(); - for (AccessRestrictionType type : AccessRestrictionType.values()) { - switch (type) { - case NONE: - map.put(type, getString("gb.notRestricted")); - break; - case PUSH: - map.put(type, getString("gb.pushRestricted")); - break; - case CLONE: - map.put(type, getString("gb.cloneRestricted")); - break; - case VIEW: - map.put(type, getString("gb.viewRestricted")); - break; - } - } - return map; - } - - protected TimeZone getTimeZone() { - return GitBlit.getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get() - .getTimezone() : TimeZone.getDefault(); - } - - protected String getServerName() { - ServletWebRequest servletWebRequest = (ServletWebRequest) getRequest(); - HttpServletRequest req = servletWebRequest.getHttpServletRequest(); - return req.getServerName(); - } - - public void error(String message, boolean redirect) { - logger.error(message); - if (redirect) { - GitBlitWebSession.get().cacheErrorMessage(message); - throw new RestartResponseAtInterceptPageException(getApplication().getHomePage()); - } else { - super.error(message); - } - } - - public void error(String message, Throwable t, boolean redirect) { - logger.error(message, t); - if (redirect) { - GitBlitWebSession.get().cacheErrorMessage(message); - throw new RestartResponseAtInterceptPageException(getApplication().getHomePage()); - } else { - super.error(message); - } - } -} diff --git a/src/com/gitblit/wicket/GitBlitWebApp.java b/src/com/gitblit/wicket/GitBlitWebApp.java index f78bb0da..1d251d9c 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.java +++ b/src/com/gitblit/wicket/GitBlitWebApp.java @@ -34,6 +34,8 @@ import com.gitblit.wicket.pages.CommitPage; import com.gitblit.wicket.pages.DocsPage; import com.gitblit.wicket.pages.HistoryPage; import com.gitblit.wicket.pages.LogPage; +import com.gitblit.wicket.pages.LoginPage; +import com.gitblit.wicket.pages.LogoutPage; import com.gitblit.wicket.pages.MarkdownPage; import com.gitblit.wicket.pages.PatchPage; import com.gitblit.wicket.pages.RawPage; diff --git a/src/com/gitblit/wicket/GitBlitWebSession.java b/src/com/gitblit/wicket/GitBlitWebSession.java index 6488695d..2238660f 100644 --- a/src/com/gitblit/wicket/GitBlitWebSession.java +++ b/src/com/gitblit/wicket/GitBlitWebSession.java @@ -22,7 +22,7 @@ import org.apache.wicket.Session; import org.apache.wicket.protocol.http.WebSession; import org.apache.wicket.protocol.http.request.WebClientInfo; -import com.gitblit.wicket.models.UserModel; +import com.gitblit.models.UserModel; public final class GitBlitWebSession extends WebSession { diff --git a/src/com/gitblit/wicket/LinkPanel.html b/src/com/gitblit/wicket/LinkPanel.html deleted file mode 100644 index e7e9ff5f..00000000 --- a/src/com/gitblit/wicket/LinkPanel.html +++ /dev/null @@ -1,9 +0,0 @@ - - - -[link] - - \ No newline at end of file diff --git a/src/com/gitblit/wicket/LinkPanel.java b/src/com/gitblit/wicket/LinkPanel.java deleted file mode 100644 index 2700cf86..00000000 --- a/src/com/gitblit/wicket/LinkPanel.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.wicket; - -import org.apache.wicket.PageParameters; -import org.apache.wicket.behavior.SimpleAttributeModifier; -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.markup.html.link.BookmarkablePageLink; -import org.apache.wicket.markup.html.link.Link; -import org.apache.wicket.markup.html.panel.Panel; -import org.apache.wicket.model.IModel; -import org.apache.wicket.model.Model; - -public class LinkPanel extends Panel { - - private static final long serialVersionUID = 1L; - - private final IModel labelModel; - - public LinkPanel(String wicketId, String linkCssClass, String label, - Class clazz) { - this(wicketId, linkCssClass, new Model(label), clazz, null); - } - - public LinkPanel(String wicketId, String linkCssClass, String label, - Class clazz, PageParameters parameters) { - this(wicketId, linkCssClass, new Model(label), clazz, parameters); - } - - public LinkPanel(String wicketId, String linkCssClass, IModel model, - Class clazz, PageParameters parameters) { - super(wicketId); - this.labelModel = model; - Link link = null; - if (parameters == null) { - link = new BookmarkablePageLink("link", clazz); - } else { - link = new BookmarkablePageLink("link", clazz, parameters); - } - if (linkCssClass != null) { - link.add(new SimpleAttributeModifier("class", linkCssClass)); - } - link.add(new Label("label", labelModel)); - add(link); - } - -} diff --git a/src/com/gitblit/wicket/LoginPage.html b/src/com/gitblit/wicket/LoginPage.html deleted file mode 100644 index 037063cc..00000000 --- a/src/com/gitblit/wicket/LoginPage.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - [page title] - - - - - - - -
-
- - Git:Blit
-
-
[name]
-
- -
-
-

-   - -

-   - -

- -

-
-
-
- - \ No newline at end of file diff --git a/src/com/gitblit/wicket/LoginPage.java b/src/com/gitblit/wicket/LoginPage.java deleted file mode 100644 index 87108787..00000000 --- a/src/com/gitblit/wicket/LoginPage.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.wicket; - -import org.apache.wicket.PageParameters; -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.markup.html.form.Form; -import org.apache.wicket.markup.html.form.PasswordTextField; -import org.apache.wicket.markup.html.form.StatelessForm; -import org.apache.wicket.markup.html.form.TextField; -import org.apache.wicket.markup.html.panel.FeedbackPanel; -import org.apache.wicket.model.IModel; -import org.apache.wicket.model.Model; - -import com.gitblit.Constants; -import com.gitblit.GitBlit; -import com.gitblit.Keys; -import com.gitblit.wicket.models.UserModel; - -public class LoginPage extends WebPage { - - IModel username = new Model(""); - IModel password = new Model(""); - - public LoginPage(PageParameters params) { - super(params); - - add(new Label("title", GitBlit.getString(Keys.web.siteName, Constants.NAME))); - add(new Label("name", Constants.NAME)); - - Form loginForm = new LoginForm("loginForm"); - loginForm.add(new TextField("username", username)); - loginForm.add(new PasswordTextField("password", password)); - loginForm.add(new FeedbackPanel("feedback")); - add(loginForm); - } - - class LoginForm extends StatelessForm { - private static final long serialVersionUID = 1L; - - public LoginForm(String id) { - super(id); - - // If we are already logged in because user directly accessed - // the login url, redirect to the home page - if (GitBlitWebSession.get().isLoggedIn()) { - setRedirect(true); - setResponsePage(getApplication().getHomePage()); - } - } - - @Override - public void onSubmit() { - String username = LoginPage.this.username.getObject(); - char[] password = LoginPage.this.password.getObject().toCharArray(); - - UserModel user = GitBlit.self().authenticate(username, password); - if (user == null) { - error("Invalid username or password!"); - } else { - loginUser(user); - } - } - } - - private void loginUser(UserModel user) { - if (user != null) { - // Set the user into the session - GitBlitWebSession.get().setUser(user); - - if (!continueToOriginalDestination()) { - // Redirect to home page - setResponsePage(getApplication().getHomePage()); - } - } - } -} diff --git a/src/com/gitblit/wicket/LogoutPage.java b/src/com/gitblit/wicket/LogoutPage.java deleted file mode 100644 index 47f80f0c..00000000 --- a/src/com/gitblit/wicket/LogoutPage.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.wicket; - -import org.apache.wicket.markup.html.WebPage; - -public class LogoutPage extends WebPage { - - public LogoutPage() { - getSession().invalidate(); - setRedirect(true); - setResponsePage(getApplication().getHomePage()); - } -} \ No newline at end of file diff --git a/src/com/gitblit/wicket/RepositoryPage.html b/src/com/gitblit/wicket/RepositoryPage.html deleted file mode 100644 index 0e0ce476..00000000 --- a/src/com/gitblit/wicket/RepositoryPage.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - -
- -
- -
- - - -
- -
[Feedback Panel]
- - - - -
- - \ No newline at end of file diff --git a/src/com/gitblit/wicket/RepositoryPage.java b/src/com/gitblit/wicket/RepositoryPage.java deleted file mode 100644 index 9d5253f0..00000000 --- a/src/com/gitblit/wicket/RepositoryPage.java +++ /dev/null @@ -1,402 +0,0 @@ -/* - * 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.wicket; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.wicket.Component; -import org.apache.wicket.PageParameters; -import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.markup.html.form.DropDownChoice; -import org.apache.wicket.markup.html.form.StatelessForm; -import org.apache.wicket.markup.html.form.TextField; -import org.apache.wicket.markup.html.link.BookmarkablePageLink; -import org.apache.wicket.markup.html.panel.Fragment; -import org.apache.wicket.markup.repeater.Item; -import org.apache.wicket.markup.repeater.data.DataView; -import org.apache.wicket.markup.repeater.data.ListDataProvider; -import org.apache.wicket.model.IModel; -import org.apache.wicket.model.Model; -import org.eclipse.jgit.diff.DiffEntry.ChangeType; -import org.eclipse.jgit.lib.PersonIdent; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.revwalk.RevCommit; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.gitblit.GitBlit; -import com.gitblit.Keys; -import com.gitblit.utils.JGitUtils; -import com.gitblit.utils.JGitUtils.SearchType; -import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.models.RepositoryModel; -import com.gitblit.wicket.pages.BranchesPage; -import com.gitblit.wicket.pages.DocsPage; -import com.gitblit.wicket.pages.EditRepositoryPage; -import com.gitblit.wicket.pages.LogPage; -import com.gitblit.wicket.pages.SearchPage; -import com.gitblit.wicket.pages.SummaryPage; -import com.gitblit.wicket.pages.TagsPage; -import com.gitblit.wicket.pages.TicketsPage; -import com.gitblit.wicket.pages.TreePage; -import com.gitblit.wicket.panels.RefsPanel; - -public abstract class RepositoryPage extends BasePage { - - protected final String repositoryName; - protected final String objectId; - - private transient Repository r; - - private RepositoryModel m; - - private final Logger logger = LoggerFactory.getLogger(RepositoryPage.class); - - private final Map knownPages = new HashMap() { - - private static final long serialVersionUID = 1L; - - { - put("summary", "gb.summary"); - put("log", "gb.log"); - put("branches", "gb.branches"); - put("tags", "gb.tags"); - put("tree", "gb.tree"); - put("tickets", "gb.tickets"); - put("edit", "gb.edit"); - } - }; - - public RepositoryPage(PageParameters params) { - super(params); - repositoryName = WicketUtils.getRepositoryName(params); - objectId = WicketUtils.getObject(params); - - if (StringUtils.isEmpty(repositoryName)) { - error(MessageFormat.format("Repository not specified for {0}!", getPageName()), true); - } - - Repository r = getRepository(); - RepositoryModel model = getRepositoryModel(); - - // standard page links - add(new BookmarkablePageLink("summary", SummaryPage.class, - WicketUtils.newRepositoryParameter(repositoryName))); - add(new BookmarkablePageLink("log", LogPage.class, - WicketUtils.newRepositoryParameter(repositoryName))); - add(new BookmarkablePageLink("branches", BranchesPage.class, - WicketUtils.newRepositoryParameter(repositoryName))); - add(new BookmarkablePageLink("tags", TagsPage.class, - WicketUtils.newRepositoryParameter(repositoryName))); - add(new BookmarkablePageLink("tree", TreePage.class, - WicketUtils.newRepositoryParameter(repositoryName))); - - // per-repository extra page links - List extraPageLinks = new ArrayList(); - - // Conditionally add tickets link - if (model.useTickets && JGitUtils.getTicketsBranch(r) != null) { - extraPageLinks.add("tickets"); - } - - // Conditionally add docs link - if (model.useDocs) { - extraPageLinks.add("docs"); - } - - final boolean showAdmin; - if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) { - boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false); - showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin(); - } else { - showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false); - } - - // Conditionally add edit link - if (showAdmin - || GitBlitWebSession.get().isLoggedIn() - && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get() - .getUser().username))) { - extraPageLinks.add("edit"); - } - - ListDataProvider extrasDp = new ListDataProvider(extraPageLinks); - DataView extrasView = new DataView("extra", extrasDp) { - private static final long serialVersionUID = 1L; - - public void populateItem(final Item item) { - String extra = item.getModelObject(); - if (extra.equals("tickets")) { - item.add(new Label("extraSeparator", " | ")); - item.add(new LinkPanel("extraLink", null, getString("gb.tickets"), - TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName))); - } else if (extra.equals("docs")) { - item.add(new Label("extraSeparator", " | ")); - item.add(new LinkPanel("extraLink", null, getString("gb.docs"), DocsPage.class, - WicketUtils.newRepositoryParameter(repositoryName))); - } else if (extra.equals("edit")) { - item.add(new Label("extraSeparator", " | ")); - item.add(new LinkPanel("extraLink", null, getString("gb.edit"), - EditRepositoryPage.class, WicketUtils - .newRepositoryParameter(repositoryName))); - } - } - }; - add(extrasView); - - // disable current page - disablePageLink(getPageName()); - - // add floating search form - SearchForm searchForm = new SearchForm("searchForm", repositoryName); - add(searchForm); - searchForm.setTranslatedAttributes(); - - // set stateless page preference - setStatelessHint(true); - } - - public void disablePageLink(String pageName) { - for (String wicketId : knownPages.keySet()) { - String key = knownPages.get(wicketId); - String linkName = getString(key); - if (linkName.equals(pageName)) { - Component c = get(wicketId); - if (c != null) { - c.setEnabled(false); - } - break; - } - } - } - - protected Repository getRepository() { - if (r == null) { - Repository r = GitBlit.self().getRepository(repositoryName); - if (r == null) { - error("Can not load repository " + repositoryName, true); - return null; - } - this.r = r; - } - return r; - } - - protected RepositoryModel getRepositoryModel() { - if (m == null) { - RepositoryModel model = GitBlit.self().getRepositoryModel( - GitBlitWebSession.get().getUser(), repositoryName); - if (model == null) { - error("Unauthorized access for repository " + repositoryName, true); - return null; - } - m = model; - } - return m; - } - - protected RevCommit getCommit() { - RevCommit commit = JGitUtils.getCommit(r, objectId); - if (commit == null) { - error(MessageFormat.format("Failed to find commit \"{0}\" in {1} for {2} page!", - objectId, repositoryName, getPageName()), true); - } - return commit; - } - - protected void addRefs(Repository r, RevCommit c) { - add(new RefsPanel("refsPanel", repositoryName, c, JGitUtils.getAllRefs(r))); - } - - protected void addFullText(String wicketId, String text, boolean substituteRegex) { - String html = StringUtils.breakLinesForHtml(text); - if (substituteRegex) { - Map map = new HashMap(); - // global regex keys - if (GitBlit.getBoolean(Keys.regex.global, false)) { - for (String key : GitBlit.getAllKeys(Keys.regex.global)) { - if (!key.equals(Keys.regex.global)) { - String subKey = key.substring(key.lastIndexOf('.') + 1); - map.put(subKey, GitBlit.getString(key, "")); - } - } - } - - // repository-specific regex keys - List keys = GitBlit.getAllKeys(Keys.regex._ROOT + "." - + repositoryName.toLowerCase()); - for (String key : keys) { - String subKey = key.substring(key.lastIndexOf('.') + 1); - map.put(subKey, GitBlit.getString(key, "")); - } - - for (Entry entry : map.entrySet()) { - String definition = entry.getValue().trim(); - String[] chunks = definition.split("!!!"); - if (chunks.length == 2) { - html = html.replaceAll(chunks[0], chunks[1]); - } else { - logger.warn(entry.getKey() - + " improperly formatted. Use !!! to separate match from replacement: " - + definition); - } - } - } - add(new Label(wicketId, html).setEscapeModelStrings(false)); - } - - protected abstract String getPageName(); - - protected Component createPersonPanel(String wicketId, PersonIdent identity, - SearchType searchType) { - boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false); - if (!showEmail || StringUtils.isEmpty(identity.getName()) - || StringUtils.isEmpty(identity.getEmailAddress())) { - String value = identity.getName(); - if (StringUtils.isEmpty(value)) { - if (showEmail) { - value = identity.getEmailAddress(); - } else { - value = getString("gb.missingUsername"); - } - } - Fragment partial = new Fragment(wicketId, "partialPersonIdent", this); - LinkPanel link = new LinkPanel("personName", "list", value, SearchPage.class, - WicketUtils.newSearchParameter(repositoryName, objectId, value, searchType)); - setPersonSearchTooltip(link, value, searchType); - partial.add(link); - return partial; - } else { - Fragment fullPerson = new Fragment(wicketId, "fullPersonIdent", this); - LinkPanel nameLink = new LinkPanel("personName", "list", identity.getName(), - SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId, - identity.getName(), searchType)); - setPersonSearchTooltip(nameLink, identity.getName(), searchType); - fullPerson.add(nameLink); - - LinkPanel addressLink = new LinkPanel("personAddress", "list", "<" - + identity.getEmailAddress() + ">", SearchPage.class, - WicketUtils.newSearchParameter(repositoryName, objectId, - identity.getEmailAddress(), searchType)); - setPersonSearchTooltip(addressLink, identity.getEmailAddress(), searchType); - fullPerson.add(addressLink); - return fullPerson; - } - } - - protected void setPersonSearchTooltip(Component component, String value, SearchType searchType) { - if (searchType.equals(SearchType.AUTHOR)) { - WicketUtils.setHtmlTooltip(component, getString("gb.searchForAuthor") + " " + value); - } else if (searchType.equals(SearchType.COMMITTER)) { - WicketUtils.setHtmlTooltip(component, getString("gb.searchForCommitter") + " " + value); - } - } - - protected void setChangeTypeTooltip(Component container, ChangeType type) { - switch (type) { - case ADD: - WicketUtils.setHtmlTooltip(container, getString("gb.addition")); - break; - case COPY: - case RENAME: - WicketUtils.setHtmlTooltip(container, getString("gb.rename")); - break; - case DELETE: - WicketUtils.setHtmlTooltip(container, getString("gb.deletion")); - break; - case MODIFY: - WicketUtils.setHtmlTooltip(container, getString("gb.modification")); - break; - } - } - - @Override - protected void onBeforeRender() { - // dispose of repository object - if (r != null) { - r.close(); - r = null; - } - // setup page header and footer - setupPage(repositoryName, "/ " + getPageName()); - super.onBeforeRender(); - } - - protected PageParameters newRepositoryParameter() { - return WicketUtils.newRepositoryParameter(repositoryName); - } - - protected PageParameters newCommitParameter() { - return WicketUtils.newObjectParameter(repositoryName, objectId); - } - - protected PageParameters newCommitParameter(String commitId) { - return WicketUtils.newObjectParameter(repositoryName, commitId); - } - - protected PageParameters newPathParameter(String path) { - return WicketUtils.newPathParameter(repositoryName, objectId, path); - } - - private static class SearchForm extends StatelessForm { - private static final long serialVersionUID = 1L; - - private final String repositoryName; - - private final IModel searchBoxModel = new Model(""); - - private final IModel searchTypeModel = new Model(SearchType.COMMIT); - - public SearchForm(String id, String repositoryName) { - super(id); - this.repositoryName = repositoryName; - DropDownChoice searchType = new DropDownChoice("searchType", - Arrays.asList(SearchType.values())); - searchType.setModel(searchTypeModel); - add(searchType.setVisible(GitBlit.getBoolean(Keys.web.showSearchTypeSelection, false))); - TextField searchBox = new TextField("searchBox", searchBoxModel); - add(searchBox); - } - - void setTranslatedAttributes() { - WicketUtils.setHtmlTooltip(get("searchType"), getString("gb.searchTypeTooltip")); - WicketUtils.setHtmlTooltip(get("searchBox"), getString("gb.searchTooltip")); - WicketUtils.setInputPlaceholder(get("searchBox"), getString("gb.search")); - } - - @Override - public void onSubmit() { - SearchType searchType = searchTypeModel.getObject(); - String searchString = searchBoxModel.getObject(); - for (SearchType type : SearchType.values()) { - if (searchString.toLowerCase().startsWith(type.name().toLowerCase() + ":")) { - searchType = type; - searchString = searchString.substring(type.name().toLowerCase().length() + 1) - .trim(); - break; - } - } - setResponsePage(SearchPage.class, - WicketUtils.newSearchParameter(repositoryName, null, searchString, searchType)); - } - } -} diff --git a/src/com/gitblit/wicket/RequiresAdminRole.java b/src/com/gitblit/wicket/RequiresAdminRole.java new file mode 100644 index 00000000..ce2dcfcf --- /dev/null +++ b/src/com/gitblit/wicket/RequiresAdminRole.java @@ -0,0 +1,26 @@ +/* + * 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.wicket; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface RequiresAdminRole { +} diff --git a/src/com/gitblit/wicket/models/Metric.java b/src/com/gitblit/wicket/models/Metric.java deleted file mode 100644 index 3014cd0c..00000000 --- a/src/com/gitblit/wicket/models/Metric.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.wicket.models; - -import java.io.Serializable; - -public class Metric implements Serializable { - - private static final long serialVersionUID = 1L; - - public String name; - public double count; - public double tag; - public int duration; - - public Metric(String name) { - this.name = name; - } -} \ No newline at end of file diff --git a/src/com/gitblit/wicket/models/PathModel.java b/src/com/gitblit/wicket/models/PathModel.java deleted file mode 100644 index 2edc96c9..00000000 --- a/src/com/gitblit/wicket/models/PathModel.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.wicket.models; - -import java.io.Serializable; - -import org.eclipse.jgit.diff.DiffEntry.ChangeType; - -import com.gitblit.utils.JGitUtils; - -public class PathModel implements Serializable, Comparable { - - private static final long serialVersionUID = 1L; - - public final String name; - public final String path; - public final long size; - public final int mode; - public final String commitId; - public boolean isParentPath; - - public PathModel(String name, String path, long size, int mode, String commitId) { - this.name = name; - this.path = path; - this.size = size; - this.mode = mode; - this.commitId = commitId; - } - - public boolean isTree() { - return JGitUtils.isTreeFromMode(mode); - } - - public static PathModel getParentPath(String basePath, String commitId) { - String parentPath = null; - if (basePath.lastIndexOf('/') > -1) { - parentPath = basePath.substring(0, basePath.lastIndexOf('/')); - } - PathModel model = new PathModel("..", parentPath, 0, 40000, commitId); - model.isParentPath = true; - return model; - } - - @Override - public int hashCode() { - return commitId.hashCode() + path.hashCode(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof PathModel) { - PathModel other = (PathModel) o; - return this.path.equals(other.path); - } - return super.equals(o); - } - - @Override - public int compareTo(PathModel o) { - boolean isTree = isTree(); - boolean otherTree = o.isTree(); - if (isTree && otherTree) { - return path.compareTo(o.path); - } else if (!isTree && !otherTree) { - return path.compareTo(o.path); - } else if (isTree && !otherTree) { - return -1; - } - return 1; - } - - public static class PathChangeModel extends PathModel { - - private static final long serialVersionUID = 1L; - - public final ChangeType changeType; - - public PathChangeModel(String name, String path, long size, int mode, String commitId, - ChangeType type) { - super(name, path, size, mode, commitId); - this.changeType = type; - } - - @Override - public int hashCode() { - return super.hashCode(); - } - - @Override - public boolean equals(Object o) { - return super.equals(o); - } - } -} diff --git a/src/com/gitblit/wicket/models/RefModel.java b/src/com/gitblit/wicket/models/RefModel.java deleted file mode 100644 index e0831f5a..00000000 --- a/src/com/gitblit/wicket/models/RefModel.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.wicket.models; - -import java.io.Serializable; -import java.util.Date; - -import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.revwalk.RevCommit; - -import com.gitblit.utils.JGitUtils; - -public class RefModel implements Serializable, Comparable { - - private static final long serialVersionUID = 1L; - public final String displayName; - public final RevCommit commit; - public transient Ref ref; - - public RefModel(String displayName, Ref ref, RevCommit commit) { - this.displayName = displayName; - this.ref = ref; - this.commit = commit; - } - - public Date getDate() { - return JGitUtils.getCommitDate(commit); - } - - public String getName() { - return ref.getName(); - } - - public ObjectId getCommitId() { - return commit.getId(); - } - - public String getShortLog() { - return commit.getShortMessage(); - } - - public ObjectId getObjectId() { - return ref.getObjectId(); - } - - public boolean isAnnotatedTag() { - // ref.isPeeled() ?? - return !getCommitId().equals(getObjectId()); - } - - @Override - public int hashCode() { - return getCommitId().hashCode() + getName().hashCode(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof RefModel) { - RefModel other = (RefModel) o; - return getName().equals(other.getName()); - } - return super.equals(o); - } - - @Override - public int compareTo(RefModel o) { - return getDate().compareTo(o.getDate()); - } -} \ No newline at end of file diff --git a/src/com/gitblit/wicket/models/RepositoryModel.java b/src/com/gitblit/wicket/models/RepositoryModel.java deleted file mode 100644 index 575e64a5..00000000 --- a/src/com/gitblit/wicket/models/RepositoryModel.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.wicket.models; - -import java.io.Serializable; -import java.util.Date; - -import com.gitblit.Constants.AccessRestrictionType; - -public class RepositoryModel implements Serializable { - - private static final long serialVersionUID = 1L; - - // field names are reflectively mapped in EditRepository page - public String name; - public String description; - public String owner; - public Date lastChange; - public boolean hasCommits; - public boolean showRemoteBranches; - public boolean useTickets; - public boolean useDocs; - public AccessRestrictionType accessRestriction; - public boolean isFrozen; - - public RepositoryModel() { - this.name = ""; - this.description = ""; - this.owner = ""; - this.lastChange = new Date(0); - this.accessRestriction = AccessRestrictionType.NONE; - } - - public RepositoryModel(String name, String description, String owner, Date lastchange) { - this.name = name; - this.description = description; - this.owner = owner; - this.lastChange = lastchange; - this.accessRestriction = AccessRestrictionType.NONE; - } - - @Override - public String toString() { - return name; - } -} \ No newline at end of file diff --git a/src/com/gitblit/wicket/models/TicketModel.java b/src/com/gitblit/wicket/models/TicketModel.java deleted file mode 100644 index b661c19a..00000000 --- a/src/com/gitblit/wicket/models/TicketModel.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.wicket.models; - -import java.io.Serializable; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class TicketModel implements Serializable, Comparable { - - private static final long serialVersionUID = 1L; - - public String id; - public String name; - public String title; - public String state; - public Date date; - public String handler; - public String milestone; - public String email; - public String author; - public List comments; - public List tags; - - public TicketModel() { - state = "open"; - comments = new ArrayList(); - tags = new ArrayList(); - } - - public TicketModel(String ticketName) throws ParseException { - state = ""; - name = ticketName; - comments = new ArrayList(); - tags = new ArrayList(); - - String[] chunks = name.split("_"); - if (chunks.length == 3) { - date = new Date(Long.parseLong(chunks[0]) * 1000L); - title = chunks[1].replace('-', ' '); - } - } - - public static class Comment implements Serializable, Comparable { - - private static final long serialVersionUID = 1L; - - public String text; - public String author; - public Date date; - - public Comment(String text, Date date) { - this.text = text; - this.date = date; - } - - public Comment(String filename, String content) throws ParseException { - String[] chunks = filename.split("_", -1); - this.date = new Date(Long.parseLong(chunks[1]) * 1000L); - this.author = chunks[2]; - this.text = content; - } - - @Override - public int hashCode() { - return text.hashCode(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof Comment) { - Comment other = (Comment) o; - return text.equals(other.text); - } - return super.equals(o); - } - - @Override - public int compareTo(Comment o) { - return date.compareTo(o.date); - } - } - - @Override - public int hashCode() { - return id.hashCode(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof TicketModel) { - TicketModel other = (TicketModel) o; - return id.equals(other.id); - } - return super.equals(o); - } - - @Override - public int compareTo(TicketModel o) { - return date.compareTo(o.date); - } -} diff --git a/src/com/gitblit/wicket/models/UserModel.java b/src/com/gitblit/wicket/models/UserModel.java deleted file mode 100644 index 1181ee15..00000000 --- a/src/com/gitblit/wicket/models/UserModel.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.wicket.models; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -public class UserModel implements Serializable { - - private static final long serialVersionUID = 1L; - - // field names are reflectively mapped in EditUser page - public String username; - public String password; - public boolean canAdmin; - public final List repositories = new ArrayList(); - - public UserModel(String username) { - this.username = username; - } - - public boolean canAccessRepository(String repositoryName) { - return canAdmin || repositories.contains(repositoryName); - } - - public void setRepositories(List repositories) { - this.repositories.clear(); - this.repositories.addAll(repositories); - } - - public void addRepository(String name) { - repositories.add(name.toLowerCase()); - } - - @Override - public String toString() { - return username; - } -} diff --git a/src/com/gitblit/wicket/pages/BasePage.html b/src/com/gitblit/wicket/pages/BasePage.html new file mode 100644 index 00000000..0da37d40 --- /dev/null +++ b/src/com/gitblit/wicket/pages/BasePage.html @@ -0,0 +1,40 @@ + + + + + + [page title] + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/BasePage.java b/src/com/gitblit/wicket/pages/BasePage.java new file mode 100644 index 00000000..9031befd --- /dev/null +++ b/src/com/gitblit/wicket/pages/BasePage.java @@ -0,0 +1,145 @@ +/* + * 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.wicket.pages; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TimeZone; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.wicket.PageParameters; +import org.apache.wicket.RestartResponseAtInterceptPageException; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.protocol.http.servlet.ServletWebRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.gitblit.Constants; +import com.gitblit.Constants.AccessRestrictionType; +import com.gitblit.GitBlit; +import com.gitblit.Keys; +import com.gitblit.wicket.GitBlitWebSession; +import com.gitblit.wicket.WicketUtils; +import com.gitblit.wicket.panels.LinkPanel; + +public abstract class BasePage extends WebPage { + + private final Logger logger; + + public BasePage() { + super(); + logger = LoggerFactory.getLogger(getClass()); + } + + public BasePage(PageParameters params) { + super(params); + logger = LoggerFactory.getLogger(getClass()); + } + + protected void setupPage(String repositoryName, String pageName) { + if (repositoryName != null && repositoryName.trim().length() > 0) { + add(new Label("title", getServerName() + " - " + repositoryName)); + } else { + add(new Label("title", getServerName())); + } + // header + String siteName = GitBlit.getString(Keys.web.siteName, Constants.NAME); + if (siteName == null || siteName.trim().length() == 0) { + siteName = Constants.NAME; + } + add(new Label("siteName", siteName)); + add(new LinkPanel("repositoryName", null, repositoryName, SummaryPage.class, + WicketUtils.newRepositoryParameter(repositoryName))); + add(new Label("pageName", pageName)); + + // Feedback panel for info, warning, and non-fatal error messages + add(new FeedbackPanel("feedback")); + + // footer + if (GitBlit.getBoolean(Keys.web.authenticateViewPages, true) + || GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) { + if (GitBlitWebSession.get().isLoggedIn()) { + // logout + add(new LinkPanel("userPanel", null, getString("gb.logout") + " " + + GitBlitWebSession.get().getUser().toString(), LogoutPage.class)); + } else { + // login + add(new LinkPanel("userPanel", null, getString("gb.login"), LoginPage.class)); + } + } else { + add(new Label("userPanel", "")); + } + add(new Label("gbVersion", "v" + Constants.VERSION)); + if (GitBlit.getBoolean(Keys.web.aggressiveHeapManagement, false)) { + System.gc(); + } + } + + protected Map getAccessRestrictions() { + Map map = new LinkedHashMap(); + for (AccessRestrictionType type : AccessRestrictionType.values()) { + switch (type) { + case NONE: + map.put(type, getString("gb.notRestricted")); + break; + case PUSH: + map.put(type, getString("gb.pushRestricted")); + break; + case CLONE: + map.put(type, getString("gb.cloneRestricted")); + break; + case VIEW: + map.put(type, getString("gb.viewRestricted")); + break; + } + } + return map; + } + + protected TimeZone getTimeZone() { + return GitBlit.getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get() + .getTimezone() : TimeZone.getDefault(); + } + + protected String getServerName() { + ServletWebRequest servletWebRequest = (ServletWebRequest) getRequest(); + HttpServletRequest req = servletWebRequest.getHttpServletRequest(); + return req.getServerName(); + } + + public void error(String message, boolean redirect) { + logger.error(message); + if (redirect) { + GitBlitWebSession.get().cacheErrorMessage(message); + throw new RestartResponseAtInterceptPageException(getApplication().getHomePage()); + } else { + super.error(message); + } + } + + public void error(String message, Throwable t, boolean redirect) { + logger.error(message, t); + if (redirect) { + GitBlitWebSession.get().cacheErrorMessage(message); + throw new RestartResponseAtInterceptPageException(getApplication().getHomePage()); + } else { + super.error(message); + } + } +} diff --git a/src/com/gitblit/wicket/pages/BlobDiffPage.java b/src/com/gitblit/wicket/pages/BlobDiffPage.java index aae41ba4..4bd61d5c 100644 --- a/src/com/gitblit/wicket/pages/BlobDiffPage.java +++ b/src/com/gitblit/wicket/pages/BlobDiffPage.java @@ -23,10 +23,10 @@ import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.utils.DiffUtils; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JGitUtils.DiffOutputType; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.CommitHeaderPanel; import com.gitblit.wicket.panels.PathBreadcrumbsPanel; @@ -48,13 +48,13 @@ public class BlobDiffPage extends RepositoryPage { String diff; if (StringUtils.isEmpty(baseObjectId)) { // use first parent - diff = JGitUtils.getCommitDiff(r, commit, blobPath, diffType); + diff = DiffUtils.getCommitDiff(r, commit, blobPath, diffType); add(new BookmarkablePageLink("patchLink", PatchPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath))); } else { // base commit specified RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId); - diff = JGitUtils.getCommitDiff(r, baseCommit, commit, blobPath, diffType); + diff = DiffUtils.getCommitDiff(r, baseCommit, commit, blobPath, diffType); add(new BookmarkablePageLink("patchLink", PatchPage.class, WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId, blobPath))); diff --git a/src/com/gitblit/wicket/pages/BlobPage.java b/src/com/gitblit/wicket/pages/BlobPage.java index 23244c0a..4601ac7b 100644 --- a/src/com/gitblit/wicket/pages/BlobPage.java +++ b/src/com/gitblit/wicket/pages/BlobPage.java @@ -29,7 +29,6 @@ import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.utils.JGitUtils; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.CommitHeaderPanel; import com.gitblit.wicket.panels.PathBreadcrumbsPanel; diff --git a/src/com/gitblit/wicket/pages/BranchesPage.java b/src/com/gitblit/wicket/pages/BranchesPage.java index f348fd4a..2b7d5187 100644 --- a/src/com/gitblit/wicket/pages/BranchesPage.java +++ b/src/com/gitblit/wicket/pages/BranchesPage.java @@ -17,7 +17,6 @@ package com.gitblit.wicket.pages; import org.apache.wicket.PageParameters; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.panels.BranchesPanel; public class BranchesPage extends RepositoryPage { diff --git a/src/com/gitblit/wicket/pages/CommitDiffPage.java b/src/com/gitblit/wicket/pages/CommitDiffPage.java index 81ee520a..1f492aca 100644 --- a/src/com/gitblit/wicket/pages/CommitDiffPage.java +++ b/src/com/gitblit/wicket/pages/CommitDiffPage.java @@ -29,14 +29,14 @@ import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.PathModel.PathChangeModel; +import com.gitblit.utils.DiffUtils; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JGitUtils.DiffOutputType; -import com.gitblit.wicket.LinkPanel; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.PathModel.PathChangeModel; import com.gitblit.wicket.panels.CommitHeaderPanel; import com.gitblit.wicket.panels.CommitLegendPanel; +import com.gitblit.wicket.panels.LinkPanel; public class CommitDiffPage extends RepositoryPage { @@ -47,7 +47,7 @@ public class CommitDiffPage extends RepositoryPage { RevCommit commit = getCommit(); DiffOutputType diffType = DiffOutputType.forName(GitBlit.getString(Keys.web.diffStyle, DiffOutputType.GITBLIT.name())); - String diff = JGitUtils.getCommitDiff(r, commit, diffType); + String diff = DiffUtils.getCommitDiff(r, commit, diffType); List parents = new ArrayList(); if (commit.getParentCount() > 0) { diff --git a/src/com/gitblit/wicket/pages/CommitPage.java b/src/com/gitblit/wicket/pages/CommitPage.java index 1a8f7c3c..dc674a2e 100644 --- a/src/com/gitblit/wicket/pages/CommitPage.java +++ b/src/com/gitblit/wicket/pages/CommitPage.java @@ -32,14 +32,13 @@ import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.DownloadZipServlet; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.PathModel.PathChangeModel; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JGitUtils.SearchType; -import com.gitblit.wicket.LinkPanel; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.PathModel.PathChangeModel; import com.gitblit.wicket.panels.CommitHeaderPanel; import com.gitblit.wicket.panels.CommitLegendPanel; +import com.gitblit.wicket.panels.LinkPanel; public class CommitPage extends RepositoryPage { diff --git a/src/com/gitblit/wicket/pages/DocsPage.java b/src/com/gitblit/wicket/pages/DocsPage.java index 32b208a8..7f41b71b 100644 --- a/src/com/gitblit/wicket/pages/DocsPage.java +++ b/src/com/gitblit/wicket/pages/DocsPage.java @@ -27,12 +27,11 @@ import org.eclipse.jgit.lib.Repository; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.PathModel; import com.gitblit.utils.ByteFormat; import com.gitblit.utils.JGitUtils; -import com.gitblit.wicket.LinkPanel; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.PathModel; +import com.gitblit.wicket.panels.LinkPanel; public class DocsPage extends RepositoryPage { diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java index 2b5cb999..a1a42d00 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -40,12 +40,11 @@ import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; +import com.gitblit.models.RepositoryModel; +import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.BasePage; import com.gitblit.wicket.GitBlitWebSession; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.RepositoryModel; -import com.gitblit.wicket.models.UserModel; public class EditRepositoryPage extends BasePage { @@ -57,7 +56,7 @@ public class EditRepositoryPage extends BasePage { // create constructor super(); isCreate = true; - setupPage(new RepositoryModel("", "", "", new Date())); + setupPage(new RepositoryModel()); } public EditRepositoryPage(PageParameters params) { diff --git a/src/com/gitblit/wicket/pages/EditUserPage.java b/src/com/gitblit/wicket/pages/EditUserPage.java index 1127ffb7..fb647f78 100644 --- a/src/com/gitblit/wicket/pages/EditUserPage.java +++ b/src/com/gitblit/wicket/pages/EditUserPage.java @@ -38,14 +38,13 @@ import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; +import com.gitblit.models.RepositoryModel; +import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.AdminPage; -import com.gitblit.wicket.BasePage; +import com.gitblit.wicket.RequiresAdminRole; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.RepositoryModel; -import com.gitblit.wicket.models.UserModel; -@AdminPage +@RequiresAdminRole public class EditUserPage extends BasePage { private final boolean isCreate; diff --git a/src/com/gitblit/wicket/pages/HistoryPage.java b/src/com/gitblit/wicket/pages/HistoryPage.java index e4f8f8d0..122eeb8a 100644 --- a/src/com/gitblit/wicket/pages/HistoryPage.java +++ b/src/com/gitblit/wicket/pages/HistoryPage.java @@ -18,7 +18,6 @@ package com.gitblit.wicket.pages; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.link.BookmarkablePageLink; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.HistoryPanel; diff --git a/src/com/gitblit/wicket/pages/LogPage.java b/src/com/gitblit/wicket/pages/LogPage.java index 2554f7d6..35f8a73f 100644 --- a/src/com/gitblit/wicket/pages/LogPage.java +++ b/src/com/gitblit/wicket/pages/LogPage.java @@ -18,7 +18,6 @@ package com.gitblit.wicket.pages; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.link.BookmarkablePageLink; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.LogPanel; diff --git a/src/com/gitblit/wicket/pages/LoginPage.html b/src/com/gitblit/wicket/pages/LoginPage.html new file mode 100644 index 00000000..280453d5 --- /dev/null +++ b/src/com/gitblit/wicket/pages/LoginPage.html @@ -0,0 +1,40 @@ + + + + + + [page title] + + + + + + + +
+
+ + Git:Blit
+
+
[name]
+
+ +
+
+

+   + +

+   + +

+ +

+
+
+
+ + \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/LoginPage.java b/src/com/gitblit/wicket/pages/LoginPage.java new file mode 100644 index 00000000..56e979ce --- /dev/null +++ b/src/com/gitblit/wicket/pages/LoginPage.java @@ -0,0 +1,86 @@ +/* + * 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.wicket.pages; + +import org.apache.wicket.PageParameters; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.PasswordTextField; +import org.apache.wicket.markup.html.form.StatelessForm; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; + +import com.gitblit.Constants; +import com.gitblit.GitBlit; +import com.gitblit.Keys; +import com.gitblit.models.UserModel; +import com.gitblit.wicket.GitBlitWebSession; + +public class LoginPage extends WebPage { + + IModel username = new Model(""); + IModel password = new Model(""); + + public LoginPage(PageParameters params) { + super(params); + + // If we are already logged in because user directly accessed + // the login url, redirect to the home page + if (GitBlitWebSession.get().isLoggedIn()) { + setRedirect(true); + setResponsePage(getApplication().getHomePage()); + } + + add(new Label("title", GitBlit.getString(Keys.web.siteName, Constants.NAME))); + add(new Label("name", Constants.NAME)); + + StatelessForm loginForm = new StatelessForm("loginForm") { + + private static final long serialVersionUID = 1L; + + @Override + public void onSubmit() { + String username = LoginPage.this.username.getObject(); + char[] password = LoginPage.this.password.getObject().toCharArray(); + + UserModel user = GitBlit.self().authenticate(username, password); + if (user == null) { + error("Invalid username or password!"); + } else { + loginUser(user); + } + } + }; + loginForm.add(new TextField("username", username)); + loginForm.add(new PasswordTextField("password", password)); + loginForm.add(new FeedbackPanel("feedback")); + add(loginForm); + } + + private void loginUser(UserModel user) { + if (user != null) { + // Set the user into the session + GitBlitWebSession.get().setUser(user); + + if (!continueToOriginalDestination()) { + // Redirect to home page + setResponsePage(getApplication().getHomePage()); + } + } + } +} diff --git a/src/com/gitblit/wicket/pages/LogoutPage.java b/src/com/gitblit/wicket/pages/LogoutPage.java new file mode 100644 index 00000000..05beab3c --- /dev/null +++ b/src/com/gitblit/wicket/pages/LogoutPage.java @@ -0,0 +1,27 @@ +/* + * 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.wicket.pages; + +import org.apache.wicket.markup.html.WebPage; + +public class LogoutPage extends WebPage { + + public LogoutPage() { + getSession().invalidate(); + setRedirect(true); + setResponsePage(getApplication().getHomePage()); + } +} \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/MarkdownPage.java b/src/com/gitblit/wicket/pages/MarkdownPage.java index d62c4330..fc8b7cbc 100644 --- a/src/com/gitblit/wicket/pages/MarkdownPage.java +++ b/src/com/gitblit/wicket/pages/MarkdownPage.java @@ -26,7 +26,6 @@ import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.MarkdownUtils; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; public class MarkdownPage extends RepositoryPage { diff --git a/src/com/gitblit/wicket/pages/PatchPage.java b/src/com/gitblit/wicket/pages/PatchPage.java index 02e4d386..04934735 100644 --- a/src/com/gitblit/wicket/pages/PatchPage.java +++ b/src/com/gitblit/wicket/pages/PatchPage.java @@ -22,6 +22,7 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.GitBlit; +import com.gitblit.utils.DiffUtils; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.GitBlitWebSession; @@ -61,7 +62,7 @@ public class PatchPage extends WebPage { if (!StringUtils.isEmpty(baseObjectId)) { baseCommit = JGitUtils.getCommit(r, baseObjectId); } - String patch = JGitUtils.getCommitPatch(r, baseCommit, commit, blobPath); + String patch = DiffUtils.getCommitPatch(r, baseCommit, commit, blobPath); add(new Label("patchText", patch)); r.close(); } diff --git a/src/com/gitblit/wicket/pages/RepositoriesPage.java b/src/com/gitblit/wicket/pages/RepositoriesPage.java index 2bb818da..b0e5e579 100644 --- a/src/com/gitblit/wicket/pages/RepositoriesPage.java +++ b/src/com/gitblit/wicket/pages/RepositoriesPage.java @@ -28,7 +28,6 @@ import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.utils.MarkdownUtils; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.BasePage; import com.gitblit.wicket.GitBlitWebSession; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.RepositoriesPanel; diff --git a/src/com/gitblit/wicket/pages/RepositoryPage.html b/src/com/gitblit/wicket/pages/RepositoryPage.html new file mode 100644 index 00000000..0e0ce476 --- /dev/null +++ b/src/com/gitblit/wicket/pages/RepositoryPage.html @@ -0,0 +1,32 @@ + + + + + + +
+ +
+ +
+ + + +
+ +
[Feedback Panel]
+ + + + +
+ + \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/RepositoryPage.java b/src/com/gitblit/wicket/pages/RepositoryPage.java new file mode 100644 index 00000000..109c51a8 --- /dev/null +++ b/src/com/gitblit/wicket/pages/RepositoryPage.java @@ -0,0 +1,396 @@ +/* + * 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.wicket.pages; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.wicket.Component; +import org.apache.wicket.PageParameters; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.StatelessForm; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; +import org.apache.wicket.markup.html.panel.Fragment; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.markup.repeater.data.DataView; +import org.apache.wicket.markup.repeater.data.ListDataProvider; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.eclipse.jgit.diff.DiffEntry.ChangeType; +import org.eclipse.jgit.lib.PersonIdent; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.gitblit.GitBlit; +import com.gitblit.Keys; +import com.gitblit.models.RepositoryModel; +import com.gitblit.utils.JGitUtils; +import com.gitblit.utils.JGitUtils.SearchType; +import com.gitblit.utils.StringUtils; +import com.gitblit.wicket.GitBlitWebSession; +import com.gitblit.wicket.WicketUtils; +import com.gitblit.wicket.panels.LinkPanel; +import com.gitblit.wicket.panels.RefsPanel; + +public abstract class RepositoryPage extends BasePage { + + protected final String repositoryName; + protected final String objectId; + + private transient Repository r; + + private RepositoryModel m; + + private final Logger logger = LoggerFactory.getLogger(RepositoryPage.class); + + private final Map knownPages = new HashMap() { + + private static final long serialVersionUID = 1L; + + { + put("summary", "gb.summary"); + put("log", "gb.log"); + put("branches", "gb.branches"); + put("tags", "gb.tags"); + put("tree", "gb.tree"); + put("tickets", "gb.tickets"); + put("edit", "gb.edit"); + } + }; + + public RepositoryPage(PageParameters params) { + super(params); + repositoryName = WicketUtils.getRepositoryName(params); + objectId = WicketUtils.getObject(params); + + if (StringUtils.isEmpty(repositoryName)) { + error(MessageFormat.format("Repository not specified for {0}!", getPageName()), true); + } + + Repository r = getRepository(); + RepositoryModel model = getRepositoryModel(); + + // standard page links + add(new BookmarkablePageLink("summary", SummaryPage.class, + WicketUtils.newRepositoryParameter(repositoryName))); + add(new BookmarkablePageLink("log", LogPage.class, + WicketUtils.newRepositoryParameter(repositoryName))); + add(new BookmarkablePageLink("branches", BranchesPage.class, + WicketUtils.newRepositoryParameter(repositoryName))); + add(new BookmarkablePageLink("tags", TagsPage.class, + WicketUtils.newRepositoryParameter(repositoryName))); + add(new BookmarkablePageLink("tree", TreePage.class, + WicketUtils.newRepositoryParameter(repositoryName))); + + // per-repository extra page links + List extraPageLinks = new ArrayList(); + + // Conditionally add tickets link + if (model.useTickets && JGitUtils.getTicketsBranch(r) != null) { + extraPageLinks.add("tickets"); + } + + // Conditionally add docs link + if (model.useDocs) { + extraPageLinks.add("docs"); + } + + final boolean showAdmin; + if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) { + boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false); + showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin(); + } else { + showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false); + } + + // Conditionally add edit link + if (showAdmin + || GitBlitWebSession.get().isLoggedIn() + && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get() + .getUser().username))) { + extraPageLinks.add("edit"); + } + + ListDataProvider extrasDp = new ListDataProvider(extraPageLinks); + DataView extrasView = new DataView("extra", extrasDp) { + private static final long serialVersionUID = 1L; + + public void populateItem(final Item item) { + String extra = item.getModelObject(); + if (extra.equals("tickets")) { + item.add(new Label("extraSeparator", " | ")); + item.add(new LinkPanel("extraLink", null, getString("gb.tickets"), + TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName))); + } else if (extra.equals("docs")) { + item.add(new Label("extraSeparator", " | ")); + item.add(new LinkPanel("extraLink", null, getString("gb.docs"), DocsPage.class, + WicketUtils.newRepositoryParameter(repositoryName))); + } else if (extra.equals("edit")) { + item.add(new Label("extraSeparator", " | ")); + item.add(new LinkPanel("extraLink", null, getString("gb.edit"), + EditRepositoryPage.class, WicketUtils + .newRepositoryParameter(repositoryName))); + } + } + }; + add(extrasView); + + // disable current page + disablePageLink(getPageName()); + + // add floating search form + SearchForm searchForm = new SearchForm("searchForm", repositoryName); + add(searchForm); + searchForm.setTranslatedAttributes(); + + // set stateless page preference + setStatelessHint(true); + } + + public void disablePageLink(String pageName) { + for (String wicketId : knownPages.keySet()) { + String key = knownPages.get(wicketId); + String linkName = getString(key); + if (linkName.equals(pageName)) { + Component c = get(wicketId); + if (c != null) { + c.setEnabled(false); + } + break; + } + } + } + + protected Repository getRepository() { + if (r == null) { + Repository r = GitBlit.self().getRepository(repositoryName); + if (r == null) { + error("Can not load repository " + repositoryName, true); + return null; + } + this.r = r; + } + return r; + } + + protected RepositoryModel getRepositoryModel() { + if (m == null) { + RepositoryModel model = GitBlit.self().getRepositoryModel( + GitBlitWebSession.get().getUser(), repositoryName); + if (model == null) { + error("Unauthorized access for repository " + repositoryName, true); + return null; + } + m = model; + } + return m; + } + + protected RevCommit getCommit() { + RevCommit commit = JGitUtils.getCommit(r, objectId); + if (commit == null) { + error(MessageFormat.format("Failed to find commit \"{0}\" in {1} for {2} page!", + objectId, repositoryName, getPageName()), true); + } + return commit; + } + + protected void addRefs(Repository r, RevCommit c) { + add(new RefsPanel("refsPanel", repositoryName, c, JGitUtils.getAllRefs(r))); + } + + protected void addFullText(String wicketId, String text, boolean substituteRegex) { + String html = StringUtils.breakLinesForHtml(text); + if (substituteRegex) { + Map map = new HashMap(); + // global regex keys + if (GitBlit.getBoolean(Keys.regex.global, false)) { + for (String key : GitBlit.getAllKeys(Keys.regex.global)) { + if (!key.equals(Keys.regex.global)) { + String subKey = key.substring(key.lastIndexOf('.') + 1); + map.put(subKey, GitBlit.getString(key, "")); + } + } + } + + // repository-specific regex keys + List keys = GitBlit.getAllKeys(Keys.regex._ROOT + "." + + repositoryName.toLowerCase()); + for (String key : keys) { + String subKey = key.substring(key.lastIndexOf('.') + 1); + map.put(subKey, GitBlit.getString(key, "")); + } + + for (Entry entry : map.entrySet()) { + String definition = entry.getValue().trim(); + String[] chunks = definition.split("!!!"); + if (chunks.length == 2) { + html = html.replaceAll(chunks[0], chunks[1]); + } else { + logger.warn(entry.getKey() + + " improperly formatted. Use !!! to separate match from replacement: " + + definition); + } + } + } + add(new Label(wicketId, html).setEscapeModelStrings(false)); + } + + protected abstract String getPageName(); + + protected Component createPersonPanel(String wicketId, PersonIdent identity, + SearchType searchType) { + boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false); + if (!showEmail || StringUtils.isEmpty(identity.getName()) + || StringUtils.isEmpty(identity.getEmailAddress())) { + String value = identity.getName(); + if (StringUtils.isEmpty(value)) { + if (showEmail) { + value = identity.getEmailAddress(); + } else { + value = getString("gb.missingUsername"); + } + } + Fragment partial = new Fragment(wicketId, "partialPersonIdent", this); + LinkPanel link = new LinkPanel("personName", "list", value, SearchPage.class, + WicketUtils.newSearchParameter(repositoryName, objectId, value, searchType)); + setPersonSearchTooltip(link, value, searchType); + partial.add(link); + return partial; + } else { + Fragment fullPerson = new Fragment(wicketId, "fullPersonIdent", this); + LinkPanel nameLink = new LinkPanel("personName", "list", identity.getName(), + SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId, + identity.getName(), searchType)); + setPersonSearchTooltip(nameLink, identity.getName(), searchType); + fullPerson.add(nameLink); + + LinkPanel addressLink = new LinkPanel("personAddress", "list", "<" + + identity.getEmailAddress() + ">", SearchPage.class, + WicketUtils.newSearchParameter(repositoryName, objectId, + identity.getEmailAddress(), searchType)); + setPersonSearchTooltip(addressLink, identity.getEmailAddress(), searchType); + fullPerson.add(addressLink); + return fullPerson; + } + } + + protected void setPersonSearchTooltip(Component component, String value, SearchType searchType) { + if (searchType.equals(SearchType.AUTHOR)) { + WicketUtils.setHtmlTooltip(component, getString("gb.searchForAuthor") + " " + value); + } else if (searchType.equals(SearchType.COMMITTER)) { + WicketUtils.setHtmlTooltip(component, getString("gb.searchForCommitter") + " " + value); + } + } + + protected void setChangeTypeTooltip(Component container, ChangeType type) { + switch (type) { + case ADD: + WicketUtils.setHtmlTooltip(container, getString("gb.addition")); + break; + case COPY: + case RENAME: + WicketUtils.setHtmlTooltip(container, getString("gb.rename")); + break; + case DELETE: + WicketUtils.setHtmlTooltip(container, getString("gb.deletion")); + break; + case MODIFY: + WicketUtils.setHtmlTooltip(container, getString("gb.modification")); + break; + } + } + + @Override + protected void onBeforeRender() { + // dispose of repository object + if (r != null) { + r.close(); + r = null; + } + // setup page header and footer + setupPage(repositoryName, "/ " + getPageName()); + super.onBeforeRender(); + } + + protected PageParameters newRepositoryParameter() { + return WicketUtils.newRepositoryParameter(repositoryName); + } + + protected PageParameters newCommitParameter() { + return WicketUtils.newObjectParameter(repositoryName, objectId); + } + + protected PageParameters newCommitParameter(String commitId) { + return WicketUtils.newObjectParameter(repositoryName, commitId); + } + + protected PageParameters newPathParameter(String path) { + return WicketUtils.newPathParameter(repositoryName, objectId, path); + } + + private static class SearchForm extends StatelessForm { + private static final long serialVersionUID = 1L; + + private final String repositoryName; + + private final IModel searchBoxModel = new Model(""); + + private final IModel searchTypeModel = new Model(SearchType.COMMIT); + + public SearchForm(String id, String repositoryName) { + super(id); + this.repositoryName = repositoryName; + DropDownChoice searchType = new DropDownChoice("searchType", + Arrays.asList(SearchType.values())); + searchType.setModel(searchTypeModel); + add(searchType.setVisible(GitBlit.getBoolean(Keys.web.showSearchTypeSelection, false))); + TextField searchBox = new TextField("searchBox", searchBoxModel); + add(searchBox); + } + + void setTranslatedAttributes() { + WicketUtils.setHtmlTooltip(get("searchType"), getString("gb.searchTypeTooltip")); + WicketUtils.setHtmlTooltip(get("searchBox"), getString("gb.searchTooltip")); + WicketUtils.setInputPlaceholder(get("searchBox"), getString("gb.search")); + } + + @Override + public void onSubmit() { + SearchType searchType = searchTypeModel.getObject(); + String searchString = searchBoxModel.getObject(); + for (SearchType type : SearchType.values()) { + if (searchString.toLowerCase().startsWith(type.name().toLowerCase() + ":")) { + searchType = type; + searchString = searchString.substring(type.name().toLowerCase().length() + 1) + .trim(); + break; + } + } + setResponsePage(SearchPage.class, + WicketUtils.newSearchParameter(repositoryName, null, searchString, searchType)); + } + } +} diff --git a/src/com/gitblit/wicket/pages/SearchPage.java b/src/com/gitblit/wicket/pages/SearchPage.java index b12beee3..335c40d7 100644 --- a/src/com/gitblit/wicket/pages/SearchPage.java +++ b/src/com/gitblit/wicket/pages/SearchPage.java @@ -19,7 +19,6 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.link.BookmarkablePageLink; import com.gitblit.utils.JGitUtils.SearchType; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.SearchPanel; diff --git a/src/com/gitblit/wicket/pages/SummaryPage.java b/src/com/gitblit/wicket/pages/SummaryPage.java index 835b344a..181de0da 100644 --- a/src/com/gitblit/wicket/pages/SummaryPage.java +++ b/src/com/gitblit/wicket/pages/SummaryPage.java @@ -42,12 +42,11 @@ import com.gitblit.Constants; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.Metric; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; import com.gitblit.utils.TimeUtils; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.Metric; import com.gitblit.wicket.panels.BranchesPanel; import com.gitblit.wicket.panels.LogPanel; import com.gitblit.wicket.panels.TagsPanel; diff --git a/src/com/gitblit/wicket/pages/TagPage.java b/src/com/gitblit/wicket/pages/TagPage.java index ff02b7bc..7945231d 100644 --- a/src/com/gitblit/wicket/pages/TagPage.java +++ b/src/com/gitblit/wicket/pages/TagPage.java @@ -21,12 +21,11 @@ import org.apache.wicket.PageParameters; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; +import com.gitblit.models.RefModel; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JGitUtils.SearchType; -import com.gitblit.wicket.LinkPanel; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.RefModel; +import com.gitblit.wicket.panels.LinkPanel; public class TagPage extends RepositoryPage { diff --git a/src/com/gitblit/wicket/pages/TagsPage.java b/src/com/gitblit/wicket/pages/TagsPage.java index 0f429425..3ddbde9b 100644 --- a/src/com/gitblit/wicket/pages/TagsPage.java +++ b/src/com/gitblit/wicket/pages/TagsPage.java @@ -17,7 +17,6 @@ package com.gitblit.wicket.pages; import org.apache.wicket.PageParameters; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.panels.TagsPanel; public class TagsPage extends RepositoryPage { diff --git a/src/com/gitblit/wicket/pages/TicketPage.java b/src/com/gitblit/wicket/pages/TicketPage.java index 9c8c3926..353c543e 100644 --- a/src/com/gitblit/wicket/pages/TicketPage.java +++ b/src/com/gitblit/wicket/pages/TicketPage.java @@ -22,13 +22,12 @@ import org.apache.wicket.markup.repeater.data.DataView; import org.apache.wicket.markup.repeater.data.ListDataProvider; import org.eclipse.jgit.lib.Repository; +import com.gitblit.models.TicketModel; +import com.gitblit.models.TicketModel.Comment; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.GitBlitWebSession; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.TicketModel; -import com.gitblit.wicket.models.TicketModel.Comment; public class TicketPage extends RepositoryPage { diff --git a/src/com/gitblit/wicket/pages/TicketsPage.java b/src/com/gitblit/wicket/pages/TicketsPage.java index 2832385c..8da4e942 100644 --- a/src/com/gitblit/wicket/pages/TicketsPage.java +++ b/src/com/gitblit/wicket/pages/TicketsPage.java @@ -23,13 +23,12 @@ import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.markup.repeater.data.DataView; import org.apache.wicket.markup.repeater.data.ListDataProvider; +import com.gitblit.models.TicketModel; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.GitBlitWebSession; -import com.gitblit.wicket.LinkPanel; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.TicketModel; +import com.gitblit.wicket.panels.LinkPanel; public class TicketsPage extends RepositoryPage { diff --git a/src/com/gitblit/wicket/pages/TreePage.java b/src/com/gitblit/wicket/pages/TreePage.java index 761b82e0..4fc7119a 100644 --- a/src/com/gitblit/wicket/pages/TreePage.java +++ b/src/com/gitblit/wicket/pages/TreePage.java @@ -32,13 +32,12 @@ import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.DownloadZipServlet; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.PathModel; import com.gitblit.utils.ByteFormat; import com.gitblit.utils.JGitUtils; -import com.gitblit.wicket.LinkPanel; -import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.PathModel; import com.gitblit.wicket.panels.CommitHeaderPanel; +import com.gitblit.wicket.panels.LinkPanel; import com.gitblit.wicket.panels.PathBreadcrumbsPanel; public class TreePage extends RepositoryPage { diff --git a/src/com/gitblit/wicket/panels/BranchesPanel.java b/src/com/gitblit/wicket/panels/BranchesPanel.java index 357c7c2c..d50db883 100644 --- a/src/com/gitblit/wicket/panels/BranchesPanel.java +++ b/src/com/gitblit/wicket/panels/BranchesPanel.java @@ -28,12 +28,11 @@ import org.apache.wicket.model.StringResourceModel; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; +import com.gitblit.models.RefModel; +import com.gitblit.models.RepositoryModel; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.RefModel; -import com.gitblit.wicket.models.RepositoryModel; import com.gitblit.wicket.pages.BranchesPage; import com.gitblit.wicket.pages.LogPage; import com.gitblit.wicket.pages.SummaryPage; diff --git a/src/com/gitblit/wicket/panels/CommitHeaderPanel.java b/src/com/gitblit/wicket/panels/CommitHeaderPanel.java index cb80321a..1a6580d6 100644 --- a/src/com/gitblit/wicket/panels/CommitHeaderPanel.java +++ b/src/com/gitblit/wicket/panels/CommitHeaderPanel.java @@ -18,7 +18,6 @@ package com.gitblit.wicket.panels; import org.apache.wicket.markup.html.basic.Label; import org.eclipse.jgit.revwalk.RevCommit; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.pages.CommitPage; diff --git a/src/com/gitblit/wicket/panels/CommitLegendPanel.java b/src/com/gitblit/wicket/panels/CommitLegendPanel.java index ee81c695..bbfa1855 100644 --- a/src/com/gitblit/wicket/panels/CommitLegendPanel.java +++ b/src/com/gitblit/wicket/panels/CommitLegendPanel.java @@ -28,9 +28,9 @@ import org.apache.wicket.markup.repeater.data.DataView; import org.apache.wicket.markup.repeater.data.ListDataProvider; import org.eclipse.jgit.diff.DiffEntry.ChangeType; +import com.gitblit.models.PathModel.PathChangeModel; import com.gitblit.utils.JGitUtils; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.PathModel.PathChangeModel; public class CommitLegendPanel extends Panel { diff --git a/src/com/gitblit/wicket/panels/HistoryPanel.java b/src/com/gitblit/wicket/panels/HistoryPanel.java index d65b02c7..180a248a 100644 --- a/src/com/gitblit/wicket/panels/HistoryPanel.java +++ b/src/com/gitblit/wicket/panels/HistoryPanel.java @@ -32,13 +32,12 @@ import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.PathModel; +import com.gitblit.models.PathModel.PathChangeModel; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JGitUtils.SearchType; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.PathModel; -import com.gitblit.wicket.models.PathModel.PathChangeModel; import com.gitblit.wicket.pages.BlobDiffPage; import com.gitblit.wicket.pages.BlobPage; import com.gitblit.wicket.pages.CommitDiffPage; diff --git a/src/com/gitblit/wicket/panels/LinkPanel.html b/src/com/gitblit/wicket/panels/LinkPanel.html new file mode 100644 index 00000000..e7e9ff5f --- /dev/null +++ b/src/com/gitblit/wicket/panels/LinkPanel.html @@ -0,0 +1,9 @@ + + + +[link] + + \ No newline at end of file diff --git a/src/com/gitblit/wicket/panels/LinkPanel.java b/src/com/gitblit/wicket/panels/LinkPanel.java new file mode 100644 index 00000000..475a71ef --- /dev/null +++ b/src/com/gitblit/wicket/panels/LinkPanel.java @@ -0,0 +1,61 @@ +/* + * 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.wicket.panels; + +import org.apache.wicket.PageParameters; +import org.apache.wicket.behavior.SimpleAttributeModifier; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; + +public class LinkPanel extends Panel { + + private static final long serialVersionUID = 1L; + + private final IModel labelModel; + + public LinkPanel(String wicketId, String linkCssClass, String label, + Class clazz) { + this(wicketId, linkCssClass, new Model(label), clazz, null); + } + + public LinkPanel(String wicketId, String linkCssClass, String label, + Class clazz, PageParameters parameters) { + this(wicketId, linkCssClass, new Model(label), clazz, parameters); + } + + public LinkPanel(String wicketId, String linkCssClass, IModel model, + Class clazz, PageParameters parameters) { + super(wicketId); + this.labelModel = model; + Link link = null; + if (parameters == null) { + link = new BookmarkablePageLink("link", clazz); + } else { + link = new BookmarkablePageLink("link", clazz, parameters); + } + if (linkCssClass != null) { + link.add(new SimpleAttributeModifier("class", linkCssClass)); + } + link.add(new Label("label", labelModel)); + add(link); + } + +} diff --git a/src/com/gitblit/wicket/panels/LogPanel.java b/src/com/gitblit/wicket/panels/LogPanel.java index b321917c..c5ccac43 100644 --- a/src/com/gitblit/wicket/panels/LogPanel.java +++ b/src/com/gitblit/wicket/panels/LogPanel.java @@ -34,7 +34,6 @@ import com.gitblit.Keys; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JGitUtils.SearchType; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.pages.CommitDiffPage; import com.gitblit.wicket.pages.CommitPage; diff --git a/src/com/gitblit/wicket/panels/PathBreadcrumbsPanel.java b/src/com/gitblit/wicket/panels/PathBreadcrumbsPanel.java index 2693cc2b..bc98e25c 100644 --- a/src/com/gitblit/wicket/panels/PathBreadcrumbsPanel.java +++ b/src/com/gitblit/wicket/panels/PathBreadcrumbsPanel.java @@ -25,7 +25,6 @@ import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.markup.repeater.data.DataView; import org.apache.wicket.markup.repeater.data.ListDataProvider; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.pages.TreePage; @@ -59,7 +58,10 @@ public class PathBreadcrumbsPanel extends Panel { public void populateItem(final Item item) { final BreadCrumb entry = item.getModelObject(); - String path = entry.getPath(); + String path = entry.path; + if (path.equals(ROOT)) { + path = null; + } if (entry.isLeaf) { item.add(new Label("pathLink", entry.name)); item.add(new Label("pathSeparator", "").setVisible(false)); @@ -85,13 +87,6 @@ public class PathBreadcrumbsPanel extends Panel { this.name = name; this.path = path; this.isLeaf = isLeaf; - } - - String getPath() { - if (path.equals(ROOT)) { - return null; - } - return path; - } + } } } \ No newline at end of file diff --git a/src/com/gitblit/wicket/panels/RefsPanel.java b/src/com/gitblit/wicket/panels/RefsPanel.java index b6e4b0bb..33b1884f 100644 --- a/src/com/gitblit/wicket/panels/RefsPanel.java +++ b/src/com/gitblit/wicket/panels/RefsPanel.java @@ -29,7 +29,6 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.revwalk.RevCommit; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.pages.CommitPage; import com.gitblit.wicket.pages.LogPage; diff --git a/src/com/gitblit/wicket/panels/RepositoriesPanel.java b/src/com/gitblit/wicket/panels/RepositoriesPanel.java index a566b595..a0c9e132 100644 --- a/src/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/com/gitblit/wicket/panels/RepositoriesPanel.java @@ -43,13 +43,12 @@ import org.apache.wicket.model.Model; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.RepositoryModel; +import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils; import com.gitblit.utils.TimeUtils; import com.gitblit.wicket.GitBlitWebSession; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.RepositoryModel; -import com.gitblit.wicket.models.UserModel; import com.gitblit.wicket.pages.EditRepositoryPage; import com.gitblit.wicket.pages.SummaryPage; diff --git a/src/com/gitblit/wicket/panels/SearchPanel.java b/src/com/gitblit/wicket/panels/SearchPanel.java index 8c63c423..f91e0e8a 100644 --- a/src/com/gitblit/wicket/panels/SearchPanel.java +++ b/src/com/gitblit/wicket/panels/SearchPanel.java @@ -32,7 +32,6 @@ import com.gitblit.Keys; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JGitUtils.SearchType; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.pages.CommitDiffPage; import com.gitblit.wicket.pages.CommitPage; diff --git a/src/com/gitblit/wicket/panels/TagsPanel.java b/src/com/gitblit/wicket/panels/TagsPanel.java index 1d8eec7d..de8112a4 100644 --- a/src/com/gitblit/wicket/panels/TagsPanel.java +++ b/src/com/gitblit/wicket/panels/TagsPanel.java @@ -26,11 +26,10 @@ import org.apache.wicket.markup.repeater.data.ListDataProvider; import org.apache.wicket.model.StringResourceModel; import org.eclipse.jgit.lib.Repository; +import com.gitblit.models.RefModel; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.RefModel; import com.gitblit.wicket.pages.CommitPage; import com.gitblit.wicket.pages.LogPage; import com.gitblit.wicket.pages.SummaryPage; diff --git a/src/com/gitblit/wicket/panels/UsersPanel.java b/src/com/gitblit/wicket/panels/UsersPanel.java index 27bc334b..4cf92a46 100644 --- a/src/com/gitblit/wicket/panels/UsersPanel.java +++ b/src/com/gitblit/wicket/panels/UsersPanel.java @@ -26,7 +26,6 @@ import org.apache.wicket.markup.repeater.data.DataView; import org.apache.wicket.markup.repeater.data.ListDataProvider; import com.gitblit.GitBlit; -import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.pages.EditUserPage; -- cgit v1.2.3