From 99d0d4fd66f3490b61c700065b7d16bc4e73f226 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 16 Nov 2013 11:42:06 -0500 Subject: Eliminate nearly all direct GitBlit singleton references in Wicket This is the first step towards modularization and injection. All direct references to the GitBlit singleton within the Wicket pages and panels have been replaced to proxy methods in the GitBlitWebApp singleton. There are still two Wicket classes which rely on the GitBlit singleton; those require manual instantiation (servlet 3). Change-Id: I0cdbbcf87959d590c446c99abb09c07c87c737bc --- .../java/com/gitblit/utils/MessageProcessor.java | 126 ++++++ .../com/gitblit/wicket/AuthorizationStrategy.java | 12 +- .../java/com/gitblit/wicket/GitBlitWebApp.java | 455 ++++++++++++--------- .../wicket/GitblitParamUrlCodingStrategy.java | 14 +- src/main/java/com/gitblit/wicket/WicketUtils.java | 19 +- .../com/gitblit/wicket/pages/ActivityPage.java | 7 +- .../java/com/gitblit/wicket/pages/BasePage.java | 39 +- .../java/com/gitblit/wicket/pages/BlamePage.java | 3 +- .../java/com/gitblit/wicket/pages/BlobPage.java | 11 +- .../gitblit/wicket/pages/ChangePasswordPage.java | 19 +- .../com/gitblit/wicket/pages/CommitDiffPage.java | 3 +- .../java/com/gitblit/wicket/pages/CommitPage.java | 3 +- .../com/gitblit/wicket/pages/DashboardPage.java | 7 +- .../java/com/gitblit/wicket/pages/DocPage.java | 5 +- .../java/com/gitblit/wicket/pages/DocsPage.java | 3 +- .../gitblit/wicket/pages/EditRepositoryPage.java | 53 ++- .../com/gitblit/wicket/pages/EditTeamPage.java | 25 +- .../com/gitblit/wicket/pages/EditUserPage.java | 33 +- .../gitblit/wicket/pages/EmptyRepositoryPage.java | 5 +- .../com/gitblit/wicket/pages/FederationPage.java | 5 +- .../wicket/pages/FederationRegistrationPage.java | 3 +- .../java/com/gitblit/wicket/pages/ForkPage.java | 12 +- .../java/com/gitblit/wicket/pages/ForksPage.java | 7 +- .../java/com/gitblit/wicket/pages/LogoutPage.java | 5 +- .../com/gitblit/wicket/pages/LuceneSearchPage.java | 9 +- .../com/gitblit/wicket/pages/MyDashboardPage.java | 15 +- .../com/gitblit/wicket/pages/OverviewPage.java | 13 +- .../java/com/gitblit/wicket/pages/PatchPage.java | 6 +- .../java/com/gitblit/wicket/pages/ProjectPage.java | 7 +- .../com/gitblit/wicket/pages/ProjectsPage.java | 5 +- .../java/com/gitblit/wicket/pages/RawPage.java | 11 +- .../com/gitblit/wicket/pages/RepositoriesPage.java | 9 +- .../com/gitblit/wicket/pages/RepositoryPage.java | 48 ++- .../gitblit/wicket/pages/ReviewProposalPage.java | 16 +- .../java/com/gitblit/wicket/pages/RootPage.java | 55 ++- .../java/com/gitblit/wicket/pages/RootSubPage.java | 5 +- .../com/gitblit/wicket/pages/SendProposalPage.java | 5 +- .../java/com/gitblit/wicket/pages/SessionPage.java | 17 +- .../java/com/gitblit/wicket/pages/SummaryPage.java | 17 +- .../java/com/gitblit/wicket/pages/UserPage.java | 9 +- .../com/gitblit/wicket/panels/ActivityPanel.java | 3 +- .../java/com/gitblit/wicket/panels/BasePanel.java | 10 +- .../com/gitblit/wicket/panels/BranchesPanel.java | 5 +- .../wicket/panels/CompressedDownloadsPanel.java | 8 +- .../com/gitblit/wicket/panels/DigestsPanel.java | 7 +- .../wicket/panels/FederationProposalsPanel.java | 5 +- .../panels/FederationRegistrationsPanel.java | 5 +- .../wicket/panels/FederationTokensPanel.java | 13 +- .../wicket/panels/FilterableProjectList.java | 3 +- .../wicket/panels/FilterableRepositoryList.java | 5 +- .../com/gitblit/wicket/panels/GravatarImage.java | 6 +- .../com/gitblit/wicket/panels/HistoryPanel.java | 11 +- .../java/com/gitblit/wicket/panels/LogPanel.java | 7 +- .../wicket/panels/ProjectRepositoryPanel.java | 9 +- .../com/gitblit/wicket/panels/ReflogPanel.java | 7 +- .../wicket/panels/RegistrantPermissionsPanel.java | 3 +- .../gitblit/wicket/panels/RepositoriesPanel.java | 19 +- .../gitblit/wicket/panels/RepositoryUrlPanel.java | 15 +- .../com/gitblit/wicket/panels/SearchPanel.java | 3 +- .../java/com/gitblit/wicket/panels/TeamsPanel.java | 7 +- .../java/com/gitblit/wicket/panels/UsersPanel.java | 7 +- 61 files changed, 718 insertions(+), 561 deletions(-) create mode 100644 src/main/java/com/gitblit/utils/MessageProcessor.java (limited to 'src') diff --git a/src/main/java/com/gitblit/utils/MessageProcessor.java b/src/main/java/com/gitblit/utils/MessageProcessor.java new file mode 100644 index 00000000..58493de4 --- /dev/null +++ b/src/main/java/com/gitblit/utils/MessageProcessor.java @@ -0,0 +1,126 @@ +/* + * Copyright 2013 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.utils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.gitblit.IStoredSettings; +import com.gitblit.Keys; +import com.gitblit.models.RepositoryModel; + +public class MessageProcessor { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + private final IStoredSettings settings; + + public MessageProcessor(IStoredSettings settings) { + this.settings = settings; + } + + /** + * Returns an html version of the commit message with any global or + * repository-specific regular expression substitution applied. + * + * This method uses the preferred renderer to transform the commit message. + * + * @param repository + * @param text + * @return html version of the commit message + */ + public String processCommitMessage(RepositoryModel repository, String text) { + switch (repository.commitMessageRenderer) { + case MARKDOWN: + try { + String prepared = processCommitMessageRegex(repository.name, text); + return MarkdownUtils.transformMarkdown(prepared); + } catch (Exception e) { + logger.error("Failed to render commit message as markdown", e); + } + break; + default: + // noop + break; + } + + return processPlainCommitMessage(repository.name, text); + } + + /** + * Returns an html version of the commit message with any global or + * repository-specific regular expression substitution applied. + * + * This method assumes the commit message is plain text. + * + * @param repositoryName + * @param text + * @return html version of the commit message + */ + public String processPlainCommitMessage(String repositoryName, String text) { + String html = StringUtils.escapeForHtml(text, false); + html = processCommitMessageRegex(repositoryName, html); + return StringUtils.breakLinesForHtml(html); + + } + + /** + * Apply globally or per-repository specified regex substitutions to the + * commit message. + * + * @param repositoryName + * @param text + * @return the processed commit message + */ + protected String processCommitMessageRegex(String repositoryName, String text) { + Map map = new HashMap(); + // global regex keys + if (settings.getBoolean(Keys.regex.global, false)) { + for (String key : settings.getAllKeys(Keys.regex.global)) { + if (!key.equals(Keys.regex.global)) { + String subKey = key.substring(key.lastIndexOf('.') + 1); + map.put(subKey, settings.getString(key, "")); + } + } + } + + // repository-specific regex keys + List keys = settings.getAllKeys(Keys.regex._ROOT + "." + + repositoryName.toLowerCase()); + for (String key : keys) { + String subKey = key.substring(key.lastIndexOf('.') + 1); + map.put(subKey, settings.getString(key, "")); + } + + for (Entry entry : map.entrySet()) { + String definition = entry.getValue().trim(); + String[] chunks = definition.split("!!!"); + if (chunks.length == 2) { + text = text.replaceAll(chunks[0], chunks[1]); + } else { + logger.warn(entry.getKey() + + " improperly formatted. Use !!! to separate match from replacement: " + + definition); + } + } + return text; + } +} diff --git a/src/main/java/com/gitblit/wicket/AuthorizationStrategy.java b/src/main/java/com/gitblit/wicket/AuthorizationStrategy.java index a00e2e2f..51ae6481 100644 --- a/src/main/java/com/gitblit/wicket/AuthorizationStrategy.java +++ b/src/main/java/com/gitblit/wicket/AuthorizationStrategy.java @@ -21,7 +21,7 @@ import org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListen import org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy; import org.apache.wicket.markup.html.WebPage; -import com.gitblit.GitBlit; +import com.gitblit.IStoredSettings; import com.gitblit.Keys; import com.gitblit.models.UserModel; import com.gitblit.wicket.pages.BasePage; @@ -29,9 +29,11 @@ import com.gitblit.wicket.pages.BasePage; public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy implements IUnauthorizedComponentInstantiationListener { + IStoredSettings settings; Class homepageClass; - public AuthorizationStrategy(Class homepageClass) { + public AuthorizationStrategy(IStoredSettings settings, Class homepageClass) { + this.settings = settings; this.homepageClass = homepageClass; } @@ -45,9 +47,9 @@ public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy imp } if (BasePage.class.isAssignableFrom(pageClass)) { - boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, true); - boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true); - boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, true); + boolean authenticateView = settings.getBoolean(Keys.web.authenticateViewPages, true); + boolean authenticateAdmin = settings.getBoolean(Keys.web.authenticateAdminPages, true); + boolean allowAdmin = settings.getBoolean(Keys.web.allowAdministration, true); GitBlitWebSession session = GitBlitWebSession.get(); if (authenticateView && !session.isLoggedIn()) { diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java index 8cbda461..1a46a1f7 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java @@ -1,193 +1,262 @@ -/* - * 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.HashMap; -import java.util.Locale; -import java.util.Map; - -import org.apache.wicket.Application; -import org.apache.wicket.Request; -import org.apache.wicket.Response; -import org.apache.wicket.Session; -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.protocol.http.WebApplication; - -import com.gitblit.GitBlit; -import com.gitblit.Keys; -import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.pages.ActivityPage; -import com.gitblit.wicket.pages.BlamePage; -import com.gitblit.wicket.pages.BlobDiffPage; -import com.gitblit.wicket.pages.BlobPage; -import com.gitblit.wicket.pages.BranchesPage; -import com.gitblit.wicket.pages.CommitDiffPage; -import com.gitblit.wicket.pages.CommitPage; -import com.gitblit.wicket.pages.ComparePage; -import com.gitblit.wicket.pages.DocPage; -import com.gitblit.wicket.pages.DocsPage; -import com.gitblit.wicket.pages.FederationRegistrationPage; -import com.gitblit.wicket.pages.ForkPage; -import com.gitblit.wicket.pages.ForksPage; -import com.gitblit.wicket.pages.GitSearchPage; -import com.gitblit.wicket.pages.GravatarProfilePage; -import com.gitblit.wicket.pages.HistoryPage; -import com.gitblit.wicket.pages.LogPage; -import com.gitblit.wicket.pages.LogoutPage; -import com.gitblit.wicket.pages.LuceneSearchPage; -import com.gitblit.wicket.pages.MetricsPage; -import com.gitblit.wicket.pages.MyDashboardPage; -import com.gitblit.wicket.pages.OverviewPage; -import com.gitblit.wicket.pages.PatchPage; -import com.gitblit.wicket.pages.ProjectPage; -import com.gitblit.wicket.pages.ProjectsPage; -import com.gitblit.wicket.pages.RawPage; -import com.gitblit.wicket.pages.ReflogPage; -import com.gitblit.wicket.pages.RepositoriesPage; -import com.gitblit.wicket.pages.ReviewProposalPage; -import com.gitblit.wicket.pages.SummaryPage; -import com.gitblit.wicket.pages.TagPage; -import com.gitblit.wicket.pages.TagsPage; -import com.gitblit.wicket.pages.TreePage; -import com.gitblit.wicket.pages.UserPage; -import com.gitblit.wicket.pages.UsersPage; - -public class GitBlitWebApp extends WebApplication { - - private final Class homePageClass = MyDashboardPage.class; - - private final Map cacheablePages = new HashMap(); - - @Override - public void init() { - super.init(); - - // Setup page authorization mechanism - boolean useAuthentication = GitBlit.getBoolean(Keys.web.authenticateViewPages, false) - || GitBlit.getBoolean(Keys.web.authenticateAdminPages, false); - if (useAuthentication) { - AuthorizationStrategy authStrategy = new AuthorizationStrategy(homePageClass); - getSecuritySettings().setAuthorizationStrategy(authStrategy); - getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy); - } - - // Grab Browser info (like timezone, etc) - if (GitBlit.getBoolean(Keys.web.useClientTimezone, false)) { - getRequestCycleSettings().setGatherExtendedBrowserInfo(true); - } - - // configure the resource cache duration to 90 days for deployment - if (!GitBlit.isDebugMode()) { - getResourceSettings().setDefaultCacheDuration(90 * 86400); - } - - // setup the standard gitweb-ish urls - mount("/repositories", RepositoriesPage.class); - mount("/overview", OverviewPage.class, "r", "h"); - mount("/summary", SummaryPage.class, "r"); - mount("/reflog", ReflogPage.class, "r", "h"); - mount("/commits", LogPage.class, "r", "h"); - mount("/log", LogPage.class, "r", "h"); - mount("/tags", TagsPage.class, "r"); - mount("/branches", BranchesPage.class, "r"); - mount("/commit", CommitPage.class, "r", "h"); - mount("/tag", TagPage.class, "r", "h"); - mount("/tree", TreePage.class, "r", "h", "f"); - mount("/blob", BlobPage.class, "r", "h", "f"); - mount("/raw", RawPage.class, "r", "h", "f"); - mount("/blobdiff", BlobDiffPage.class, "r", "h", "f"); - mount("/commitdiff", CommitDiffPage.class, "r", "h"); - mount("/compare", ComparePage.class, "r", "h"); - mount("/patch", PatchPage.class, "r", "h", "f"); - mount("/history", HistoryPage.class, "r", "h", "f"); - mount("/search", GitSearchPage.class); - mount("/metrics", MetricsPage.class, "r"); - mount("/blame", BlamePage.class, "r", "h", "f"); - mount("/users", UsersPage.class); - mount("/logout", LogoutPage.class); - - // setup the markup document urls - mount("/docs", DocsPage.class, "r"); - mount("/doc", DocPage.class, "r", "h", "f"); - - // federation urls - mount("/proposal", ReviewProposalPage.class, "t"); - mount("/registration", FederationRegistrationPage.class, "u", "n"); - - mount("/activity", ActivityPage.class, "r", "h"); - mount("/gravatar", GravatarProfilePage.class, "h"); - mount("/lucene", LuceneSearchPage.class); - mount("/project", ProjectPage.class, "p"); - mount("/projects", ProjectsPage.class); - mount("/user", UserPage.class, "user"); - mount("/forks", ForksPage.class, "r"); - mount("/fork", ForkPage.class, "r"); - - getMarkupSettings().setDefaultMarkupEncoding("UTF-8"); - } - - private void mount(String location, Class clazz, String... parameters) { - if (parameters == null) { - parameters = new String[] {}; - } - if (!GitBlit.getBoolean(Keys.web.mountParameters, true)) { - parameters = new String[] {}; - } - mount(new GitblitParamUrlCodingStrategy(location, clazz, parameters)); - - // map the mount point to the cache control definition - if (clazz.isAnnotationPresent(CacheControl.class)) { - CacheControl cacheControl = clazz.getAnnotation(CacheControl.class); - cacheablePages.put(location.substring(1), cacheControl); - } - } - - @Override - public Class getHomePage() { - return homePageClass; - } - - public boolean isCacheablePage(String mountPoint) { - return cacheablePages.containsKey(mountPoint); - } - - public CacheControl getCacheControl(String mountPoint) { - return cacheablePages.get(mountPoint); - } - - @Override - public final Session newSession(Request request, Response response) { - GitBlitWebSession gitBlitWebSession = new GitBlitWebSession(request); - - String forcedLocale = GitBlit.getString(Keys.web.forceDefaultLocale, null); - if (!StringUtils.isEmpty(forcedLocale)) { - gitBlitWebSession.setLocale(new Locale(forcedLocale)); - } - return gitBlitWebSession; - } - - @Override - public final String getConfigurationType() { - if (GitBlit.isDebugMode()) { - return Application.DEVELOPMENT; - } - return Application.DEPLOYMENT; - } - - public static GitBlitWebApp get() { - return (GitBlitWebApp) WebApplication.get(); - } -} +/* + * 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.Date; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.TimeZone; + +import org.apache.wicket.Application; +import org.apache.wicket.Request; +import org.apache.wicket.Response; +import org.apache.wicket.Session; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.protocol.http.WebApplication; + +import com.gitblit.GitBlit; +import com.gitblit.IStoredSettings; +import com.gitblit.Keys; +import com.gitblit.utils.StringUtils; +import com.gitblit.wicket.pages.ActivityPage; +import com.gitblit.wicket.pages.BlamePage; +import com.gitblit.wicket.pages.BlobDiffPage; +import com.gitblit.wicket.pages.BlobPage; +import com.gitblit.wicket.pages.BranchesPage; +import com.gitblit.wicket.pages.CommitDiffPage; +import com.gitblit.wicket.pages.CommitPage; +import com.gitblit.wicket.pages.ComparePage; +import com.gitblit.wicket.pages.DocPage; +import com.gitblit.wicket.pages.DocsPage; +import com.gitblit.wicket.pages.FederationRegistrationPage; +import com.gitblit.wicket.pages.ForkPage; +import com.gitblit.wicket.pages.ForksPage; +import com.gitblit.wicket.pages.GitSearchPage; +import com.gitblit.wicket.pages.GravatarProfilePage; +import com.gitblit.wicket.pages.HistoryPage; +import com.gitblit.wicket.pages.LogPage; +import com.gitblit.wicket.pages.LogoutPage; +import com.gitblit.wicket.pages.LuceneSearchPage; +import com.gitblit.wicket.pages.MetricsPage; +import com.gitblit.wicket.pages.MyDashboardPage; +import com.gitblit.wicket.pages.OverviewPage; +import com.gitblit.wicket.pages.PatchPage; +import com.gitblit.wicket.pages.ProjectPage; +import com.gitblit.wicket.pages.ProjectsPage; +import com.gitblit.wicket.pages.RawPage; +import com.gitblit.wicket.pages.ReflogPage; +import com.gitblit.wicket.pages.RepositoriesPage; +import com.gitblit.wicket.pages.ReviewProposalPage; +import com.gitblit.wicket.pages.SummaryPage; +import com.gitblit.wicket.pages.TagPage; +import com.gitblit.wicket.pages.TagsPage; +import com.gitblit.wicket.pages.TreePage; +import com.gitblit.wicket.pages.UserPage; +import com.gitblit.wicket.pages.UsersPage; + +public class GitBlitWebApp extends WebApplication { + + private final Class homePageClass = MyDashboardPage.class; + + private final Map cacheablePages = new HashMap(); + + private IStoredSettings settings; + + @Override + public void init() { + super.init(); + + settings = GitBlit.getSettings(); + + // Setup page authorization mechanism + boolean useAuthentication = settings.getBoolean(Keys.web.authenticateViewPages, false) + || settings.getBoolean(Keys.web.authenticateAdminPages, false); + if (useAuthentication) { + AuthorizationStrategy authStrategy = new AuthorizationStrategy(settings, homePageClass); + getSecuritySettings().setAuthorizationStrategy(authStrategy); + getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy); + } + + // Grab Browser info (like timezone, etc) + if (settings.getBoolean(Keys.web.useClientTimezone, false)) { + getRequestCycleSettings().setGatherExtendedBrowserInfo(true); + } + + // configure the resource cache duration to 90 days for deployment + if (!isDebugMode()) { + getResourceSettings().setDefaultCacheDuration(90 * 86400); + } + + // setup the standard gitweb-ish urls + mount("/repositories", RepositoriesPage.class); + mount("/overview", OverviewPage.class, "r", "h"); + mount("/summary", SummaryPage.class, "r"); + mount("/reflog", ReflogPage.class, "r", "h"); + mount("/commits", LogPage.class, "r", "h"); + mount("/log", LogPage.class, "r", "h"); + mount("/tags", TagsPage.class, "r"); + mount("/branches", BranchesPage.class, "r"); + mount("/commit", CommitPage.class, "r", "h"); + mount("/tag", TagPage.class, "r", "h"); + mount("/tree", TreePage.class, "r", "h", "f"); + mount("/blob", BlobPage.class, "r", "h", "f"); + mount("/raw", RawPage.class, "r", "h", "f"); + mount("/blobdiff", BlobDiffPage.class, "r", "h", "f"); + mount("/commitdiff", CommitDiffPage.class, "r", "h"); + mount("/compare", ComparePage.class, "r", "h"); + mount("/patch", PatchPage.class, "r", "h", "f"); + mount("/history", HistoryPage.class, "r", "h", "f"); + mount("/search", GitSearchPage.class); + mount("/metrics", MetricsPage.class, "r"); + mount("/blame", BlamePage.class, "r", "h", "f"); + mount("/users", UsersPage.class); + mount("/logout", LogoutPage.class); + + // setup the markup document urls + mount("/docs", DocsPage.class, "r"); + mount("/doc", DocPage.class, "r", "h", "f"); + + // federation urls + mount("/proposal", ReviewProposalPage.class, "t"); + mount("/registration", FederationRegistrationPage.class, "u", "n"); + + mount("/activity", ActivityPage.class, "r", "h"); + mount("/gravatar", GravatarProfilePage.class, "h"); + mount("/lucene", LuceneSearchPage.class); + mount("/project", ProjectPage.class, "p"); + mount("/projects", ProjectsPage.class); + mount("/user", UserPage.class, "user"); + mount("/forks", ForksPage.class, "r"); + mount("/fork", ForkPage.class, "r"); + + getMarkupSettings().setDefaultMarkupEncoding("UTF-8"); + super.init(); + } + + private void mount(String location, Class clazz, String... parameters) { + if (parameters == null) { + parameters = new String[] {}; + } + if (!settings.getBoolean(Keys.web.mountParameters, true)) { + parameters = new String[] {}; + } + mount(new GitblitParamUrlCodingStrategy(settings, location, clazz, parameters)); + + // map the mount point to the cache control definition + if (clazz.isAnnotationPresent(CacheControl.class)) { + CacheControl cacheControl = clazz.getAnnotation(CacheControl.class); + cacheablePages.put(location.substring(1), cacheControl); + } + } + + @Override + public Class getHomePage() { + return homePageClass; + } + + public boolean isCacheablePage(String mountPoint) { + return cacheablePages.containsKey(mountPoint); + } + + public CacheControl getCacheControl(String mountPoint) { + return cacheablePages.get(mountPoint); + } + + @Override + public final Session newSession(Request request, Response response) { + GitBlitWebSession gitBlitWebSession = new GitBlitWebSession(request); + + String forcedLocale = settings.getString(Keys.web.forceDefaultLocale, null); + if (!StringUtils.isEmpty(forcedLocale)) { + gitBlitWebSession.setLocale(new Locale(forcedLocale)); + } + return gitBlitWebSession; + } + + public IStoredSettings settings() { + return settings; + } + + /** + * Is Gitblit running in debug mode? + * + * @return true if Gitblit is running in debug mode + */ + public boolean isDebugMode() { + return GitBlit.isDebugMode(); + } + + /* + * These methods look strange... and they are... but they are the first + * step towards modularization across multiple commits. + */ + public Date getBootDate() { + return GitBlit.getBootDate(); + } + + public Date getLastActivityDate() { + return GitBlit.getLastActivityDate(); + } + + public GitBlit runtime() { + return GitBlit.self(); + } + + public GitBlit mail() { + return GitBlit.self(); + } + + public GitBlit users() { + return GitBlit.self(); + } + + public GitBlit session() { + return GitBlit.self(); + } + + public GitBlit repositories() { + return GitBlit.self(); + } + + public GitBlit projects() { + return GitBlit.self(); + } + + public GitBlit federation() { + return GitBlit.self(); + } + + public GitBlit gitblit() { + return GitBlit.self(); + } + + public TimeZone getTimezone() { + return GitBlit.getTimezone(); + } + + @Override + public final String getConfigurationType() { + if (isDebugMode()) { + return Application.DEVELOPMENT; + } + return Application.DEPLOYMENT; + } + + public static GitBlitWebApp get() { + return (GitBlitWebApp) WebApplication.get(); + } +} diff --git a/src/main/java/com/gitblit/wicket/GitblitParamUrlCodingStrategy.java b/src/main/java/com/gitblit/wicket/GitblitParamUrlCodingStrategy.java index 2d65d37b..4f67a4ab 100644 --- a/src/main/java/com/gitblit/wicket/GitblitParamUrlCodingStrategy.java +++ b/src/main/java/com/gitblit/wicket/GitblitParamUrlCodingStrategy.java @@ -25,7 +25,7 @@ import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.gitblit.GitBlit; +import com.gitblit.IStoredSettings; import com.gitblit.Keys; /** @@ -42,6 +42,8 @@ public class GitblitParamUrlCodingStrategy extends MixedParamUrlCodingStrategy { private Logger logger = LoggerFactory.getLogger(GitblitParamUrlCodingStrategy.class); + private IStoredSettings settings; + /** * Construct. * @@ -53,9 +55,13 @@ public class GitblitParamUrlCodingStrategy extends MixedParamUrlCodingStrategy { * @param parameterNames * the parameter names (not null) */ - public GitblitParamUrlCodingStrategy(String mountPath, + public GitblitParamUrlCodingStrategy( + IStoredSettings settings, + String mountPath, Class bookmarkablePageClass, String[] parameterNames) { + super(mountPath, bookmarkablePageClass, parameterNames); + this.settings = settings; } /** @@ -67,7 +73,7 @@ public class GitblitParamUrlCodingStrategy extends MixedParamUrlCodingStrategy { */ @Override protected String urlEncodePathComponent(String string) { - char altChar = GitBlit.getChar(Keys.web.forwardSlashCharacter, '/'); + char altChar = settings.getChar(Keys.web.forwardSlashCharacter, '/'); if (altChar != '/') { string = string.replace('/', altChar); } @@ -83,7 +89,7 @@ public class GitblitParamUrlCodingStrategy extends MixedParamUrlCodingStrategy { */ @Override protected String urlDecodePathComponent(String value) { - char altChar = GitBlit.getChar(Keys.web.forwardSlashCharacter, '/'); + char altChar = settings.getChar(Keys.web.forwardSlashCharacter, '/'); if (altChar != '/') { value = value.replace(altChar, '/'); } diff --git a/src/main/java/com/gitblit/wicket/WicketUtils.java b/src/main/java/com/gitblit/wicket/WicketUtils.java index 6e3d932f..8e119da8 100644 --- a/src/main/java/com/gitblit/wicket/WicketUtils.java +++ b/src/main/java/com/gitblit/wicket/WicketUtils.java @@ -44,7 +44,6 @@ import org.wicketstuff.googlecharts.IChartData; import com.gitblit.Constants; import com.gitblit.Constants.AccessPermission; import com.gitblit.Constants.FederationPullStatus; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.FederationModel; import com.gitblit.models.Metric; @@ -189,7 +188,7 @@ public class WicketUtils { return newImage(wicketId, "file_settings_16x16.png"); } - MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings()); + MarkupProcessor processor = new MarkupProcessor(GitBlitWebApp.get().settings()); String ext = StringUtils.getFileExtension(filename).toLowerCase(); if (processor.getMarkupExtensions().contains(ext)) { return newImage(wicketId, "file_world_16x16.png"); @@ -510,10 +509,10 @@ public class WicketUtils { } public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils, boolean setCss) { - String format = GitBlit.getString(Keys.web.datestampShortFormat, "MM/dd/yy"); + String format = GitBlitWebApp.get().settings().getString(Keys.web.datestampShortFormat, "MM/dd/yy"); DateFormat df = new SimpleDateFormat(format); if (timeZone == null) { - timeZone = GitBlit.getTimezone(); + timeZone = GitBlitWebApp.get().getTimezone(); } df.setTimeZone(timeZone); String dateString; @@ -543,10 +542,10 @@ public class WicketUtils { } public static Label createTimeLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) { - String format = GitBlit.getString(Keys.web.timeFormat, "HH:mm"); + String format = GitBlitWebApp.get().settings().getString(Keys.web.timeFormat, "HH:mm"); DateFormat df = new SimpleDateFormat(format); if (timeZone == null) { - timeZone = GitBlit.getTimezone(); + timeZone = GitBlitWebApp.get().getTimezone(); } df.setTimeZone(timeZone); String timeString; @@ -564,10 +563,10 @@ public class WicketUtils { } public static Label createDatestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) { - String format = GitBlit.getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy"); + String format = GitBlitWebApp.get().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy"); DateFormat df = new SimpleDateFormat(format); if (timeZone == null) { - timeZone = GitBlit.getTimezone(); + timeZone = GitBlitWebApp.get().getTimezone(); } df.setTimeZone(timeZone); String dateString; @@ -598,11 +597,11 @@ public class WicketUtils { } public static Label createTimestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) { - String format = GitBlit.getString(Keys.web.datetimestampLongFormat, + String format = GitBlitWebApp.get().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy HH:mm Z"); DateFormat df = new SimpleDateFormat(format); if (timeZone == null) { - timeZone = GitBlit.getTimezone(); + timeZone = GitBlitWebApp.get().getTimezone(); } df.setTimeZone(timeZone); String dateString; diff --git a/src/main/java/com/gitblit/wicket/pages/ActivityPage.java b/src/main/java/com/gitblit/wicket/pages/ActivityPage.java index 99992eae..5e7332f5 100644 --- a/src/main/java/com/gitblit/wicket/pages/ActivityPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ActivityPage.java @@ -29,7 +29,6 @@ import org.apache.wicket.behavior.HeaderContributor; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.panel.Fragment; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.Activity; import com.gitblit.models.Metric; @@ -66,7 +65,7 @@ public class ActivityPage extends RootPage { // parameters int daysBack = WicketUtils.getDaysBack(params); if (daysBack < 1) { - daysBack = GitBlit.getInteger(Keys.web.activityDuration, 7); + daysBack = app().settings().getInteger(Keys.web.activityDuration, 7); } String objectId = WicketUtils.getObject(params); @@ -113,7 +112,7 @@ public class ActivityPage extends RootPage { daysBack, totalCommits, totalAuthors))); // create the activity charts - if (GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) { + if (app().settings().getBoolean(Keys.web.generateActivityGraph, true)) { GoogleCharts charts = createCharts(recentActivity); add(new HeaderContributor(charts)); add(new Fragment("chartsPanel", "chartsFragment", this)); @@ -137,7 +136,7 @@ public class ActivityPage extends RootPage { ActivityPage.class); PageParameters currentParameters = getPageParameters(); - int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 7); + int daysBack = app().settings().getInteger(Keys.web.activityDuration, 7); if (currentParameters != null && !currentParameters.containsKey("db")) { currentParameters.put("db", daysBack); } diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index 9bae3783..647a9388 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -52,7 +52,6 @@ import com.gitblit.Constants.AccessPermission; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Constants.AuthorizationControl; import com.gitblit.Constants.FederationStrategy; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.ProjectModel; import com.gitblit.models.TeamModel; @@ -83,7 +82,7 @@ public abstract class BasePage extends SessionPage { } private void customizeHeader() { - if (GitBlit.getBoolean(Keys.web.useResponsiveLayout, true)) { + if (app().settings().getBoolean(Keys.web.useResponsiveLayout, true)) { add(CSSPackageResource.getHeaderContribution("bootstrap/css/bootstrap-responsive.css")); } } @@ -121,7 +120,7 @@ public abstract class BasePage extends SessionPage { @Override protected void onBeforeRender() { - if (GitBlit.isDebugMode()) { + if (app().isDebugMode()) { // strip Wicket tags in debug mode for jQuery DOM traversal Application.get().getMarkupSettings().setStripWicketTags(true); } @@ -130,7 +129,7 @@ public abstract class BasePage extends SessionPage { @Override protected void onAfterRender() { - if (GitBlit.isDebugMode()) { + if (app().isDebugMode()) { // restore Wicket debug tags Application.get().getMarkupSettings().setStripWicketTags(false); } @@ -141,8 +140,8 @@ public abstract class BasePage extends SessionPage { protected void setHeaders(WebResponse response) { // set canonical link as http header for SEO (issue-304) // https://support.google.com/webmasters/answer/139394?hl=en - response.setHeader("Link" ,MessageFormat.format("<{0}>; rel=\"canonical\"", getCanonicalUrl())); - int expires = GitBlit.getInteger(Keys.web.pageCacheExpires, 0); + response.setHeader("Link", MessageFormat.format("<{0}>; rel=\"canonical\"", getCanonicalUrl())); + int expires = app().settings().getInteger(Keys.web.pageCacheExpires, 0); if (expires > 0) { // pages are personalized for the authenticated user so they must be // marked private to prohibit proxy servers from caching them @@ -164,10 +163,10 @@ public abstract class BasePage extends SessionPage { CacheControl cacheControl = getClass().getAnnotation(CacheControl.class); switch (cacheControl.value()) { case ACTIVITY: - setLastModified(GitBlit.getLastActivityDate()); + setLastModified(app().getLastActivityDate()); break; case BOOT: - setLastModified(GitBlit.getBootDate()); + setLastModified(app().getBootDate()); break; case NONE: break; @@ -188,21 +187,21 @@ public abstract class BasePage extends SessionPage { return; } - if (when.before(GitBlit.getBootDate())) { + if (when.before(app().getBootDate())) { // last-modified can not be before the Gitblit boot date // this helps ensure that pages are properly refreshed after a // server config change - when = GitBlit.getBootDate(); + when = app().getBootDate(); } - int expires = GitBlit.getInteger(Keys.web.pageCacheExpires, 0); + int expires = app().settings().getInteger(Keys.web.pageCacheExpires, 0); WebResponse response = (WebResponse) getResponse(); response.setLastModifiedTime(Time.valueOf(when)); response.setDateHeader("Expires", System.currentTimeMillis() + Duration.minutes(expires).getMilliseconds()); } protected void setupPage(String repositoryName, String pageName) { - String siteName = GitBlit.getString(Keys.web.siteName, Constants.NAME); + String siteName = app().settings().getString(Keys.web.siteName, Constants.NAME); if (StringUtils.isEmpty(siteName)) { siteName = Constants.NAME; } @@ -212,16 +211,16 @@ public abstract class BasePage extends SessionPage { add(new Label("title", siteName)); } - String rootLinkUrl = GitBlit.getString(Keys.web.rootLink, urlFor(GitBlitWebApp.get().getHomePage(), null).toString()); + String rootLinkUrl = app().settings().getString(Keys.web.rootLink, urlFor(GitBlitWebApp.get().getHomePage(), null).toString()); ExternalLink rootLink = new ExternalLink("rootLink", rootLinkUrl); - WicketUtils.setHtmlTooltip(rootLink, GitBlit.getString(Keys.web.siteName, Constants.NAME)); + WicketUtils.setHtmlTooltip(rootLink, app().settings().getString(Keys.web.siteName, Constants.NAME)); add(rootLink); // Feedback panel for info, warning, and non-fatal error messages add(new FeedbackPanel("feedback")); add(new Label("gbVersion", "v" + Constants.getVersion())); - if (GitBlit.getBoolean(Keys.web.aggressiveHeapManagement, false)) { + if (app().settings().getBoolean(Keys.web.aggressiveHeapManagement, false)) { System.gc(); } } @@ -314,8 +313,8 @@ public abstract class BasePage extends SessionPage { } protected TimeZone getTimeZone() { - return GitBlit.getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get() - .getTimezone() : GitBlit.getTimezone(); + return app().settings().getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get() + .getTimezone() : app().getTimezone(); } protected String getServerName() { @@ -326,7 +325,7 @@ public abstract class BasePage extends SessionPage { protected List getProjectModels() { final UserModel user = GitBlitWebSession.get().getUser(); - List projects = GitBlit.self().getProjectModels(user, true); + List projects = app().projects().getProjectModels(user, true); return projects; } @@ -339,7 +338,7 @@ public abstract class BasePage extends SessionPage { String regex = WicketUtils.getRegEx(params); String team = WicketUtils.getTeam(params); int daysBack = params.getInt("db", 0); - int maxDaysBack = GitBlit.getInteger(Keys.web.activityDurationMaximum, 30); + int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30); List availableModels = getProjectModels(); Set models = new HashSet(); @@ -363,7 +362,7 @@ public abstract class BasePage extends SessionPage { // need TeamModels first List teamModels = new ArrayList(); for (String name : teams) { - TeamModel teamModel = GitBlit.self().getTeamModel(name); + TeamModel teamModel = app().users().getTeamModel(name); if (teamModel != null) { teamModels.add(teamModel); } diff --git a/src/main/java/com/gitblit/wicket/pages/BlamePage.java b/src/main/java/com/gitblit/wicket/pages/BlamePage.java index 9f00d212..52682639 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlamePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlamePage.java @@ -30,7 +30,6 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.revwalk.RevCommit; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.AnnotatedLine; import com.gitblit.models.PathModel; @@ -71,7 +70,7 @@ public class BlamePage extends RepositoryPage { add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId)); - String format = GitBlit.getString(Keys.web.datetimestampLongFormat, + String format = app().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy HH:mm Z"); final DateFormat df = new SimpleDateFormat(format); df.setTimeZone(getTimeZone()); diff --git a/src/main/java/com/gitblit/wicket/pages/BlobPage.java b/src/main/java/com/gitblit/wicket/pages/BlobPage.java index 56ad5b96..c4eca10a 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlobPage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlobPage.java @@ -28,7 +28,6 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; @@ -50,7 +49,7 @@ public class BlobPage extends RepositoryPage { Repository r = getRepository(); final String blobPath = WicketUtils.getPath(params); - String [] encodings = GitBlit.getEncodings(); + String [] encodings = getEncodings(); if (StringUtils.isEmpty(blobPath)) { // blob by objectid @@ -75,7 +74,7 @@ public class BlobPage extends RepositoryPage { } // see if we should redirect to the doc page - MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings()); + MarkupProcessor processor = new MarkupProcessor(app().settings()); for (String ext : processor.getMarkupExtensions()) { if (ext.equals(extension)) { setResponsePage(DocPage.class, params); @@ -102,13 +101,13 @@ public class BlobPage extends RepositoryPage { // Map the extensions to types Map map = new HashMap(); - for (String ext : GitBlit.getStrings(Keys.web.prettyPrintExtensions)) { + for (String ext : app().settings().getStrings(Keys.web.prettyPrintExtensions)) { map.put(ext.toLowerCase(), 1); } - for (String ext : GitBlit.getStrings(Keys.web.imageExtensions)) { + for (String ext : app().settings().getStrings(Keys.web.imageExtensions)) { map.put(ext.toLowerCase(), 2); } - for (String ext : GitBlit.getStrings(Keys.web.binaryExtensions)) { + for (String ext : app().settings().getStrings(Keys.web.binaryExtensions)) { map.put(ext.toLowerCase(), 3); } diff --git a/src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java b/src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java index 302de0da..3e308f1b 100644 --- a/src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java @@ -25,7 +25,6 @@ import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import org.apache.wicket.protocol.http.WebResponse; -import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; import com.gitblit.models.UserModel; @@ -45,16 +44,16 @@ public class ChangePasswordPage extends RootSubPage { throw new RestartResponseException(getApplication().getHomePage()); } - if (!GitBlit.getBoolean(Keys.web.authenticateAdminPages, true) - && !GitBlit.getBoolean(Keys.web.authenticateViewPages, false)) { + if (!app().settings().getBoolean(Keys.web.authenticateAdminPages, true) + && !app().settings().getBoolean(Keys.web.authenticateViewPages, false)) { // no authentication enabled throw new RestartResponseException(getApplication().getHomePage()); } UserModel user = GitBlitWebSession.get().getUser(); - if (!GitBlit.self().supportsCredentialChanges(user)) { + if (!app().users().supportsCredentialChanges(user)) { error(MessageFormat.format(getString("gb.userServiceDoesNotPermitPasswordChanges"), - GitBlit.getString(Keys.realm.userService, "${baseFolder}/users.conf")), true); + app().settings().getString(Keys.realm.userService, "${baseFolder}/users.conf")), true); } setupPage(getString("gb.changePassword"), user.username); @@ -74,7 +73,7 @@ public class ChangePasswordPage extends RootSubPage { } // ensure password satisfies minimum length requirement - int minLength = GitBlit.getInteger(Keys.realm.minPasswordLength, 5); + int minLength = app().settings().getInteger(Keys.realm.minPasswordLength, 5); if (minLength < 4) { minLength = 4; } @@ -86,7 +85,7 @@ public class ChangePasswordPage extends RootSubPage { UserModel user = GitBlitWebSession.get().getUser(); // convert to MD5 digest, if appropriate - String type = GitBlit.getString(Keys.realm.passwordStorage, "md5"); + String type = app().settings().getString(Keys.realm.passwordStorage, "md5"); if (type.equalsIgnoreCase("md5")) { // store MD5 digest of password password = StringUtils.MD5_TYPE + StringUtils.getMD5(password); @@ -98,10 +97,10 @@ public class ChangePasswordPage extends RootSubPage { user.password = password; try { - GitBlit.self().updateUserModel(user.username, user, false); - if (GitBlit.getBoolean(Keys.web.allowCookieAuthentication, false)) { + app().users().updateUserModel(user.username, user, false); + if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) { WebResponse response = (WebResponse) getRequestCycle().getResponse(); - GitBlit.self().setCookie(response, user); + app().session().setCookie(response, user); } } catch (GitBlitException e) { error(e.getMessage()); diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java index 468fb667..5d14bfec 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java +++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java @@ -31,7 +31,6 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.Constants; -import com.gitblit.GitBlit; import com.gitblit.models.GitNote; import com.gitblit.models.PathModel.PathChangeModel; import com.gitblit.models.SubmoduleModel; @@ -108,7 +107,7 @@ public class CommitDiffPage extends RepositoryPage { item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent())); item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef .getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils())); - item.add(new Label("noteContent", GitBlit.self().processPlainCommitMessage(repositoryName, + item.add(new Label("noteContent", messageProcessor().processPlainCommitMessage(repositoryName, entry.content)).setEscapeModelStrings(false)); } }; diff --git a/src/main/java/com/gitblit/wicket/pages/CommitPage.java b/src/main/java/com/gitblit/wicket/pages/CommitPage.java index 1772f3af..59422332 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitPage.java +++ b/src/main/java/com/gitblit/wicket/pages/CommitPage.java @@ -32,7 +32,6 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.Constants; -import com.gitblit.GitBlit; import com.gitblit.models.GitNote; import com.gitblit.models.PathModel.PathChangeModel; import com.gitblit.models.SubmoduleModel; @@ -136,7 +135,7 @@ public class CommitPage extends RepositoryPage { item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent())); item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef .getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils())); - item.add(new Label("noteContent", GitBlit.self().processPlainCommitMessage(repositoryName, + item.add(new Label("noteContent", messageProcessor().processPlainCommitMessage(repositoryName, entry.content)).setEscapeModelStrings(false)); } }; diff --git a/src/main/java/com/gitblit/wicket/pages/DashboardPage.java b/src/main/java/com/gitblit/wicket/pages/DashboardPage.java index 46adcffe..959a3d31 100644 --- a/src/main/java/com/gitblit/wicket/pages/DashboardPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DashboardPage.java @@ -34,7 +34,6 @@ import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.panel.Fragment; import org.eclipse.jgit.lib.Repository; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.DailyLogEntry; import com.gitblit.models.Metric; @@ -83,7 +82,7 @@ public abstract class DashboardPage extends RootPage { continue; } if (model.hasCommits && model.lastChange.after(minimumDate)) { - Repository repository = GitBlit.self().getRepository(model.name); + Repository repository = app().repositories().getRepository(model.name); List entries = RefLogUtils.getDailyLogByRef(model.name, repository, minimumDate, timezone); digests.addAll(entries); repository.close(); @@ -123,7 +122,7 @@ public abstract class DashboardPage extends RootPage { if (!ArrayUtils.isEmpty(digests)) { // aggregate author exclusions Set authorExclusions = new TreeSet(); - for (String author : GitBlit.getStrings(Keys.web.metricAuthorExclusions)) { + for (String author : app().settings().getStrings(Keys.web.metricAuthorExclusions)) { authorExclusions.add(author.toLowerCase()); } for (RepositoryModel model : repositories) { @@ -217,7 +216,7 @@ public abstract class DashboardPage extends RootPage { frag.add(new Label("feedheader", MessageFormat.format(headerPattern, daysBack, totalCommits, authorMetrics.size()))); - if (GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) { + if (app().settings().getBoolean(Keys.web.generateActivityGraph, true)) { // build google charts GoogleCharts charts = new GoogleCharts(); diff --git a/src/main/java/com/gitblit/wicket/pages/DocPage.java b/src/main/java/com/gitblit/wicket/pages/DocPage.java index ab0c4623..03d23372 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocPage.java @@ -24,7 +24,6 @@ import org.apache.wicket.markup.html.panel.Fragment; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; -import com.gitblit.GitBlit; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.CacheControl; @@ -41,11 +40,11 @@ public class DocPage extends RepositoryPage { super(params); final String path = WicketUtils.getPath(params).replace("%2f", "/").replace("%2F", "/"); - MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings()); + MarkupProcessor processor = new MarkupProcessor(app().settings()); Repository r = getRepository(); RevCommit commit = JGitUtils.getCommit(r, objectId); - String [] encodings = GitBlit.getEncodings(); + String [] encodings = getEncodings(); // Read raw markup content and transform it to html String documentPath = path; diff --git a/src/main/java/com/gitblit/wicket/pages/DocsPage.java b/src/main/java/com/gitblit/wicket/pages/DocsPage.java index 174311c4..3f9ccdb5 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocsPage.java @@ -30,7 +30,6 @@ import org.apache.wicket.markup.repeater.data.ListDataProvider; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; -import com.gitblit.GitBlit; import com.gitblit.models.PathModel; import com.gitblit.utils.ByteFormat; import com.gitblit.utils.JGitUtils; @@ -49,7 +48,7 @@ public class DocsPage extends RepositoryPage { public DocsPage(PageParameters params) { super(params); - MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings()); + MarkupProcessor processor = new MarkupProcessor(app().settings()); Repository r = getRepository(); RevCommit head = JGitUtils.getCommit(r, null); diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java index 1b3cbd6c..76b34f3a 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -55,7 +55,6 @@ import com.gitblit.Constants.AuthorizationControl; import com.gitblit.Constants.CommitMessageRenderer; import com.gitblit.Constants.FederationStrategy; import com.gitblit.Constants.RegistrantType; -import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; import com.gitblit.models.RegistrantAccessPermission; @@ -86,9 +85,9 @@ public class EditRepositoryPage extends RootSubPage { super(); isCreate = true; RepositoryModel model = new RepositoryModel(); - String restriction = GitBlit.getString(Keys.git.defaultAccessRestriction, "PUSH"); + String restriction = app().settings().getString(Keys.git.defaultAccessRestriction, "PUSH"); model.accessRestriction = AccessRestrictionType.fromName(restriction); - String authorization = GitBlit.getString(Keys.git.defaultAuthorizationControl, null); + String authorization = app().settings().getString(Keys.git.defaultAuthorizationControl, null); model.authorizationControl = AuthorizationControl.fromName(authorization); GitBlitWebSession session = GitBlitWebSession.get(); @@ -113,7 +112,7 @@ public class EditRepositoryPage extends RootSubPage { super(params); isCreate = false; String name = WicketUtils.getRepositoryName(params); - RepositoryModel model = GitBlit.self().getRepositoryModel(name); + RepositoryModel model = app().repositories().getRepositoryModel(name); setupPage(model); setStatelessHint(false); setOutputMarkupId(true); @@ -154,8 +153,8 @@ public class EditRepositoryPage extends RootSubPage { } } else { super.setupPage(getString("gb.edit"), repositoryModel.name); - repositoryUsers.addAll(GitBlit.self().getUserAccessPermissions(repositoryModel)); - repositoryTeams.addAll(GitBlit.self().getTeamAccessPermissions(repositoryModel)); + repositoryUsers.addAll(app().repositories().getUserAccessPermissions(repositoryModel)); + repositoryTeams.addAll(app().repositories().getTeamAccessPermissions(repositoryModel)); Collections.sort(repositoryUsers); Collections.sort(repositoryTeams); @@ -168,13 +167,13 @@ public class EditRepositoryPage extends RootSubPage { final String oldName = repositoryModel.name; final RegistrantPermissionsPanel usersPalette = new RegistrantPermissionsPanel("users", - RegistrantType.USER, GitBlit.self().getAllUsernames(), repositoryUsers, getAccessPermissions()); + RegistrantType.USER, app().users().getAllUsernames(), repositoryUsers, getAccessPermissions()); final RegistrantPermissionsPanel teamsPalette = new RegistrantPermissionsPanel("teams", - RegistrantType.TEAM, GitBlit.self().getAllTeamnames(), repositoryTeams, getAccessPermissions()); + RegistrantType.TEAM, app().users().getAllTeamnames(), repositoryTeams, getAccessPermissions()); // owners palette List owners = new ArrayList(repositoryModel.owners); - List persons = GitBlit.self().getAllUsernames(); + List persons = app().users().getAllUsernames(); final Palette ownersPalette = new Palette("owners", new ListModel(owners), new CollectionModel( persons), new StringChoiceRenderer(), 12, true); @@ -182,14 +181,14 @@ public class EditRepositoryPage extends RootSubPage { List allLocalBranches = new ArrayList(); allLocalBranches.add(Constants.DEFAULT_BRANCH); allLocalBranches.addAll(repositoryModel.getLocalBranches()); - boolean luceneEnabled = GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true); + boolean luceneEnabled = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true); final Palette indexedBranchesPalette = new Palette("indexedBranches", new ListModel( indexedBranches), new CollectionModel(allLocalBranches), new StringChoiceRenderer(), 8, false); indexedBranchesPalette.setEnabled(luceneEnabled); // federation sets palette - List sets = GitBlit.getStrings(Keys.federation.sets); + List sets = app().settings().getStrings(Keys.federation.sets); final Palette federationSetsPalette = new Palette("federationSets", new ListModel(federationSets), new CollectionModel(sets), new StringChoiceRenderer(), 8, false); @@ -199,8 +198,8 @@ public class EditRepositoryPage extends RootSubPage { preReceiveScripts.addAll(repositoryModel.preReceiveScripts); } final Palette preReceivePalette = new Palette("preReceiveScripts", - new ListModel(preReceiveScripts), new CollectionModel(GitBlit - .self().getPreReceiveScriptsUnused(repositoryModel)), + new ListModel(preReceiveScripts), new CollectionModel(app().repositories() + .getPreReceiveScriptsUnused(repositoryModel)), new StringChoiceRenderer(), 12, true); // post-receive palette @@ -208,12 +207,12 @@ public class EditRepositoryPage extends RootSubPage { postReceiveScripts.addAll(repositoryModel.postReceiveScripts); } final Palette postReceivePalette = new Palette("postReceiveScripts", - new ListModel(postReceiveScripts), new CollectionModel(GitBlit - .self().getPostReceiveScriptsUnused(repositoryModel)), + new ListModel(postReceiveScripts), new CollectionModel(app().repositories() + .getPostReceiveScriptsUnused(repositoryModel)), new StringChoiceRenderer(), 12, true); // custom fields - final Map customFieldsMap = GitBlit.getMap(Keys.groovy.customFields); + final Map customFieldsMap = app().settings().getMap(Keys.groovy.customFields); List customKeys = new ArrayList(customFieldsMap.keySet()); final ListView customFieldsListView = new ListView("customFieldsListView", customKeys) { @@ -393,12 +392,12 @@ public class EditRepositoryPage extends RootSubPage { } // save the repository - GitBlit.self().updateRepositoryModel(oldName, repositoryModel, isCreate); + app().repositories().updateRepositoryModel(oldName, repositoryModel, isCreate); // repository access permissions if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)) { - GitBlit.self().setUserAccessPermissions(repositoryModel, repositoryUsers); - GitBlit.self().setTeamAccessPermissions(repositoryModel, repositoryTeams); + app().repositories().setUserAccessPermissions(repositoryModel, repositoryUsers); + app().repositories().setTeamAccessPermissions(repositoryModel, repositoryTeams); } } catch (GitBlitException e) { error(e.getMessage()); @@ -416,9 +415,9 @@ public class EditRepositoryPage extends RootSubPage { form.add(new TextField("name").setEnabled(allowEditName)); form.add(new TextField("description")); form.add(ownersPalette); - form.add(new CheckBox("allowForks").setEnabled(GitBlit.getBoolean(Keys.web.allowForking, true))); + form.add(new CheckBox("allowForks").setEnabled(app().settings().getBoolean(Keys.web.allowForking, true))); DropDownChoice accessRestriction = new DropDownChoice("accessRestriction", - AccessRestrictionType.choices(GitBlit.getBoolean(Keys.git.allowAnonymousPushes, false)), new AccessRestrictionRenderer()); + AccessRestrictionType.choices(app().settings().getBoolean(Keys.git.allowAnonymousPushes, false)), new AccessRestrictionRenderer()); form.add(accessRestriction); form.add(new CheckBox("isFrozen")); // TODO enable origin definition @@ -431,7 +430,7 @@ public class EditRepositoryPage extends RootSubPage { } form.add(new DropDownChoice("HEAD", availableRefs).setEnabled(availableRefs.size() > 0)); - boolean gcEnabled = GitBlit.getBoolean(Keys.git.enableGarbageCollection, false); + boolean gcEnabled = app().settings().getBoolean(Keys.git.enableGarbageCollection, false); List gcPeriods = Arrays.asList(1, 2, 3, 4, 5, 7, 10, 14 ); form.add(new DropDownChoice("gcPeriod", gcPeriods, new GCPeriodRenderer()).setEnabled(gcEnabled)); form.add(new TextField("gcThreshold").setEnabled(gcEnabled)); @@ -474,15 +473,15 @@ public class EditRepositoryPage extends RootSubPage { form.add(teamsPalette); form.add(federationSetsPalette); form.add(preReceivePalette); - form.add(new BulletListPanel("inheritedPreReceive", getString("gb.inherited"), GitBlit.self() + form.add(new BulletListPanel("inheritedPreReceive", getString("gb.inherited"), app().repositories() .getPreReceiveScriptsInherited(repositoryModel))); form.add(postReceivePalette); - form.add(new BulletListPanel("inheritedPostReceive", getString("gb.inherited"), GitBlit.self() + form.add(new BulletListPanel("inheritedPostReceive", getString("gb.inherited"), app().repositories() .getPostReceiveScriptsInherited(repositoryModel))); WebMarkupContainer customFieldsSection = new WebMarkupContainer("customFieldsSection"); customFieldsSection.add(customFieldsListView); - form.add(customFieldsSection.setVisible(!GitBlit.getString(Keys.groovy.customFields, "").isEmpty())); + form.add(customFieldsSection.setVisible(!app().settings().getString(Keys.groovy.customFields, "").isEmpty())); // initial enable/disable of permission controls if (repositoryModel.accessRestriction.equals(AccessRestrictionType.NONE)) { @@ -579,8 +578,8 @@ public class EditRepositoryPage extends RootSubPage { * Repository Owners should be able to edit their repository. */ private void checkPermissions(RepositoryModel model) { - boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true); - boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, true); + boolean authenticateAdmin = app().settings().getBoolean(Keys.web.authenticateAdminPages, true); + boolean allowAdmin = app().settings().getBoolean(Keys.web.allowAdministration, true); GitBlitWebSession session = GitBlitWebSession.get(); UserModel user = session.getUser(); diff --git a/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java b/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java index 617aa86b..32905c95 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java @@ -37,7 +37,6 @@ import org.apache.wicket.model.util.CollectionModel; import org.apache.wicket.model.util.ListModel; import com.gitblit.Constants.RegistrantType; -import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; import com.gitblit.models.RegistrantAccessPermission; @@ -70,7 +69,7 @@ public class EditTeamPage extends RootSubPage { super(params); isCreate = false; String name = WicketUtils.getTeamname(params); - TeamModel model = GitBlit.self().getTeamModel(name); + TeamModel model = app().users().getTeamModel(name); setupPage(model); setStatelessHint(false); setOutputMarkupId(true); @@ -107,7 +106,7 @@ public class EditTeamPage extends RootSubPage { // users palette final Palette users = new Palette("users", new ListModel( - new ArrayList(teamUsers)), new CollectionModel(GitBlit.self() + new ArrayList(teamUsers)), new CollectionModel(app().users() .getAllUsernames()), new StringChoiceRenderer(), 10, false); // pre-receive palette @@ -115,8 +114,8 @@ public class EditTeamPage extends RootSubPage { preReceiveScripts.addAll(teamModel.preReceiveScripts); } final Palette preReceivePalette = new Palette("preReceiveScripts", - new ListModel(preReceiveScripts), new CollectionModel(GitBlit - .self().getPreReceiveScriptsUnused(null)), new StringChoiceRenderer(), + new ListModel(preReceiveScripts), new CollectionModel(app().repositories() + .getPreReceiveScriptsUnused(null)), new StringChoiceRenderer(), 12, true); // post-receive palette @@ -124,8 +123,8 @@ public class EditTeamPage extends RootSubPage { postReceiveScripts.addAll(teamModel.postReceiveScripts); } final Palette postReceivePalette = new Palette("postReceiveScripts", - new ListModel(postReceiveScripts), new CollectionModel(GitBlit - .self().getPostReceiveScriptsUnused(null)), new StringChoiceRenderer(), + new ListModel(postReceiveScripts), new CollectionModel(app().repositories() + .getPostReceiveScriptsUnused(null)), new StringChoiceRenderer(), 12, true); Form form = new Form("editForm", model) { @@ -145,7 +144,7 @@ public class EditTeamPage extends RootSubPage { return; } if (isCreate) { - TeamModel model = GitBlit.self().getTeamModel(teamname); + TeamModel model = app().users().getTeamModel(teamname); if (model != null) { error(MessageFormat.format(getString("gb.teamNameUnavailable"), teamname)); return; @@ -197,7 +196,7 @@ public class EditTeamPage extends RootSubPage { teamModel.postReceiveScripts.addAll(postReceiveScripts); try { - GitBlit.self().updateTeamModel(oldName, teamModel, isCreate); + app().users().updateTeamModel(oldName, teamModel, isCreate); } catch (GitBlitException e) { error(e.getMessage()); return; @@ -217,12 +216,12 @@ public class EditTeamPage extends RootSubPage { form.add(new SimpleAttributeModifier("autocomplete", "off")); // not all user services support manipulating team memberships - boolean editMemberships = GitBlit.self().supportsTeamMembershipChanges(null); + boolean editMemberships = app().users().supportsTeamMembershipChanges(null); // field names reflective match TeamModel fields form.add(new TextField("name")); form.add(new CheckBox("canAdmin")); - form.add(new CheckBox("canFork").setEnabled(GitBlit.getBoolean(Keys.web.allowForking, true))); + form.add(new CheckBox("canFork").setEnabled(app().settings().getBoolean(Keys.web.allowForking, true))); form.add(new CheckBox("canCreate")); form.add(users.setEnabled(editMemberships)); mailingLists = new Model(teamModel.mailingLists == null ? "" @@ -232,10 +231,10 @@ public class EditTeamPage extends RootSubPage { form.add(new RegistrantPermissionsPanel("repositories", RegistrantType.REPOSITORY, repos, permissions, getAccessPermissions())); form.add(preReceivePalette); - form.add(new BulletListPanel("inheritedPreReceive", "inherited", GitBlit.self() + form.add(new BulletListPanel("inheritedPreReceive", "inherited", app().repositories() .getPreReceiveScriptsInherited(null))); form.add(postReceivePalette); - form.add(new BulletListPanel("inheritedPostReceive", "inherited", GitBlit.self() + form.add(new BulletListPanel("inheritedPostReceive", "inherited", app().repositories() .getPostReceiveScriptsInherited(null))); form.add(new Button("save")); diff --git a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java index 6838c196..d0e52f46 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java @@ -35,7 +35,6 @@ import org.apache.wicket.model.util.CollectionModel; import org.apache.wicket.model.util.ListModel; import com.gitblit.Constants.RegistrantType; -import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; import com.gitblit.models.RegistrantAccessPermission; @@ -55,9 +54,9 @@ public class EditUserPage extends RootSubPage { public EditUserPage() { // create constructor super(); - if (!GitBlit.self().supportsAddUser()) { + if (!app().users().supportsAddUser()) { error(MessageFormat.format(getString("gb.userServiceDoesNotPermitAddUser"), - GitBlit.getString(Keys.realm.userService, "${baseFolder}/users.conf")), true); + app().settings().getString(Keys.realm.userService, "${baseFolder}/users.conf")), true); } isCreate = true; setupPage(new UserModel("")); @@ -70,7 +69,7 @@ public class EditUserPage extends RootSubPage { super(params); isCreate = false; String name = WicketUtils.getUsername(params); - UserModel model = GitBlit.self().getUserModel(name); + UserModel model = app().users().getUserModel(name); setupPage(model); setStatelessHint(false); setOutputMarkupId(true); @@ -107,10 +106,10 @@ public class EditUserPage extends RootSubPage { Collections.sort(userTeams); final String oldName = userModel.username; - final List permissions = GitBlit.self().getUserAccessPermissions(userModel); + final List permissions = app().repositories().getUserAccessPermissions(userModel); final Palette teams = new Palette("teams", new ListModel( - new ArrayList(userTeams)), new CollectionModel(GitBlit.self() + new ArrayList(userTeams)), new CollectionModel(app().users() .getAllTeamnames()), new StringChoiceRenderer(), 10, false); Form form = new Form("editForm", model) { @@ -131,7 +130,7 @@ public class EditUserPage extends RootSubPage { userModel.username = userModel.username.toLowerCase(); String username = userModel.username; if (isCreate) { - UserModel model = GitBlit.self().getUserModel(username); + UserModel model = app().users().getUserModel(username); if (model != null) { error(MessageFormat.format(getString("gb.usernameUnavailable"), username)); return; @@ -139,7 +138,7 @@ public class EditUserPage extends RootSubPage { } boolean rename = !StringUtils.isEmpty(oldName) && !oldName.equalsIgnoreCase(username); - if (GitBlit.self().supportsCredentialChanges(userModel)) { + if (app().users().supportsCredentialChanges(userModel)) { if (!userModel.password.equals(confirmPassword.getObject())) { error(getString("gb.passwordsDoNotMatch")); return; @@ -149,7 +148,7 @@ public class EditUserPage extends RootSubPage { && !password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) { // This is a plain text password. // Check length. - int minLength = GitBlit.getInteger(Keys.realm.minPasswordLength, 5); + int minLength = app().settings().getInteger(Keys.realm.minPasswordLength, 5); if (minLength < 4) { minLength = 4; } @@ -160,7 +159,7 @@ public class EditUserPage extends RootSubPage { } // Optionally store the password MD5 digest. - String type = GitBlit.getString(Keys.realm.passwordStorage, "md5"); + String type = app().settings().getString(Keys.realm.passwordStorage, "md5"); if (type.equalsIgnoreCase("md5")) { // store MD5 digest of password userModel.password = StringUtils.MD5_TYPE @@ -185,7 +184,7 @@ public class EditUserPage extends RootSubPage { Iterator selectedTeams = teams.getSelectedChoices(); userModel.teams.clear(); while (selectedTeams.hasNext()) { - TeamModel team = GitBlit.self().getTeamModel(selectedTeams.next()); + TeamModel team = app().users().getTeamModel(selectedTeams.next()); if (team == null) { continue; } @@ -193,7 +192,7 @@ public class EditUserPage extends RootSubPage { } try { - GitBlit.self().updateUserModel(oldName, userModel, isCreate); + app().users().updateUserModel(oldName, userModel, isCreate); } catch (GitBlitException e) { error(e.getMessage()); return; @@ -215,16 +214,16 @@ public class EditUserPage extends RootSubPage { form.add(new SimpleAttributeModifier("autocomplete", "off")); // not all user services support manipulating username and password - boolean editCredentials = GitBlit.self().supportsCredentialChanges(userModel); + boolean editCredentials = app().users().supportsCredentialChanges(userModel); // not all user services support manipulating display name - boolean editDisplayName = GitBlit.self().supportsDisplayNameChanges(userModel); + boolean editDisplayName = app().users().supportsDisplayNameChanges(userModel); // not all user services support manipulating email address - boolean editEmailAddress = GitBlit.self().supportsEmailAddressChanges(userModel); + boolean editEmailAddress = app().users().supportsEmailAddressChanges(userModel); // not all user services support manipulating team memberships - boolean editTeams = GitBlit.self().supportsTeamMembershipChanges(userModel); + boolean editTeams = app().users().supportsTeamMembershipChanges(userModel); // field names reflective match UserModel fields form.add(new TextField("username").setEnabled(editCredentials)); @@ -238,7 +237,7 @@ public class EditUserPage extends RootSubPage { form.add(new TextField("displayName").setEnabled(editDisplayName)); form.add(new TextField("emailAddress").setEnabled(editEmailAddress)); form.add(new CheckBox("canAdmin")); - form.add(new CheckBox("canFork").setEnabled(GitBlit.getBoolean(Keys.web.allowForking, true))); + form.add(new CheckBox("canFork").setEnabled(app().settings().getBoolean(Keys.web.allowForking, true))); form.add(new CheckBox("canCreate")); form.add(new CheckBox("excludeFromFederation")); form.add(new RegistrantPermissionsPanel("repositories", RegistrantType.REPOSITORY, repos, permissions, getAccessPermissions())); diff --git a/src/main/java/com/gitblit/wicket/pages/EmptyRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EmptyRepositoryPage.java index 4e05fad6..9e4d355c 100644 --- a/src/main/java/com/gitblit/wicket/pages/EmptyRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EmptyRepositoryPage.java @@ -24,7 +24,6 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.protocol.http.WebRequest; -import com.gitblit.GitBlit; import com.gitblit.models.RepositoryModel; import com.gitblit.models.RepositoryUrl; import com.gitblit.models.UserModel; @@ -41,7 +40,7 @@ public class EmptyRepositoryPage extends RootPage { setVersioned(false); String repositoryName = WicketUtils.getRepositoryName(params); - RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName); + RepositoryModel repository = app().repositories().getRepositoryModel(repositoryName); if (repository == null) { error(getString("gb.canNotLoadRepository") + " " + repositoryName, true); } @@ -59,7 +58,7 @@ public class EmptyRepositoryPage extends RootPage { } HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest(); - List repositoryUrls = GitBlit.self().getRepositoryUrls(req, user, repository); + List repositoryUrls = app().repositories().getRepositoryUrls(req, user, repository); RepositoryUrl primaryUrl = repositoryUrls.size() == 0 ? null : repositoryUrls.get(0); String url = primaryUrl != null ? primaryUrl.url : ""; diff --git a/src/main/java/com/gitblit/wicket/pages/FederationPage.java b/src/main/java/com/gitblit/wicket/pages/FederationPage.java index 1f98c172..a8342938 100644 --- a/src/main/java/com/gitblit/wicket/pages/FederationPage.java +++ b/src/main/java/com/gitblit/wicket/pages/FederationPage.java @@ -15,7 +15,6 @@ */ package com.gitblit.wicket.pages; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.wicket.panels.FederationProposalsPanel; import com.gitblit.wicket.panels.FederationRegistrationsPanel; @@ -27,7 +26,7 @@ public class FederationPage extends RootPage { super(); setupPage("", ""); - boolean showFederation = showAdmin && GitBlit.canFederate(); + boolean showFederation = showAdmin && app().federation().canFederate(); add(new FederationTokensPanel("federationTokensPanel", showFederation) .setVisible(showFederation)); FederationProposalsPanel proposalsPanel = new FederationProposalsPanel( @@ -38,7 +37,7 @@ public class FederationPage extends RootPage { proposalsPanel.setVisible(false); } - boolean showRegistrations = GitBlit.getBoolean(Keys.web.showFederationRegistrations, false); + boolean showRegistrations = app().settings().getBoolean(Keys.web.showFederationRegistrations, false); FederationRegistrationsPanel registrationsPanel = new FederationRegistrationsPanel( "federationRegistrationsPanel"); if (showAdmin || showRegistrations) { diff --git a/src/main/java/com/gitblit/wicket/pages/FederationRegistrationPage.java b/src/main/java/com/gitblit/wicket/pages/FederationRegistrationPage.java index 42f46943..c26c9757 100644 --- a/src/main/java/com/gitblit/wicket/pages/FederationRegistrationPage.java +++ b/src/main/java/com/gitblit/wicket/pages/FederationRegistrationPage.java @@ -24,7 +24,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.GitBlit; import com.gitblit.models.FederationModel; import com.gitblit.models.FederationModel.RepositoryStatus; import com.gitblit.wicket.WicketUtils; @@ -39,7 +38,7 @@ public class FederationRegistrationPage extends RootSubPage { String url = WicketUtils.getUrlParameter(params); String name = WicketUtils.getNameParameter(params); - FederationModel registration = GitBlit.self().getFederationRegistration(url, name); + FederationModel registration = app().federation().getFederationRegistration(url, name); if (registration == null) { error(getString("gb.couldNotFindFederationRegistration"), true); } diff --git a/src/main/java/com/gitblit/wicket/pages/ForkPage.java b/src/main/java/com/gitblit/wicket/pages/ForkPage.java index fe316fff..12020128 100644 --- a/src/main/java/com/gitblit/wicket/pages/ForkPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ForkPage.java @@ -21,9 +21,9 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.slf4j.LoggerFactory; -import com.gitblit.GitBlit; import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel; +import com.gitblit.wicket.GitBlitWebApp; import com.gitblit.wicket.GitBlitWebSession; import com.gitblit.wicket.GitblitRedirectException; import com.gitblit.wicket.WicketUtils; @@ -49,7 +49,7 @@ public class ForkPage extends RepositoryPage { throw new GitblitRedirectException(SummaryPage.class, WicketUtils.newRepositoryParameter(repository.name)); } - String fork = GitBlit.self().getFork(user.username, repository.name); + String fork = app().repositories().getFork(user.username, repository.name); if (fork != null) { // redirect to user's fork throw new GitblitRedirectException(SummaryPage.class, WicketUtils.newRepositoryParameter(fork)); @@ -62,7 +62,7 @@ public class ForkPage extends RepositoryPage { session.isForking(true); // fork it - ForkThread forker = new ForkThread(repository, session); + ForkThread forker = new ForkThread(app(), repository, session); forker.start(); } } @@ -84,10 +84,12 @@ public class ForkPage extends RepositoryPage { */ private static class ForkThread extends Thread { + private final GitBlitWebApp app; private final RepositoryModel repository; private final GitBlitWebSession session; - public ForkThread(RepositoryModel repository, GitBlitWebSession session) { + public ForkThread(GitBlitWebApp app, RepositoryModel repository, GitBlitWebSession session) { + this.app = app; this.repository = repository; this.session = session; } @@ -96,7 +98,7 @@ public class ForkPage extends RepositoryPage { public void run() { UserModel user = session.getUser(); try { - GitBlit.self().fork(repository, user); + app.gitblit().fork(repository, user); } catch (Exception e) { LoggerFactory.getLogger(ForkPage.class).error(MessageFormat.format("Failed to fork {0} for {1}", repository.name, user.username), e); } finally { diff --git a/src/main/java/com/gitblit/wicket/pages/ForksPage.java b/src/main/java/com/gitblit/wicket/pages/ForksPage.java index 5b5fcc0a..9fd7f4db 100644 --- a/src/main/java/com/gitblit/wicket/pages/ForksPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ForksPage.java @@ -27,7 +27,6 @@ import org.apache.wicket.markup.repeater.data.DataView; import org.apache.wicket.markup.repeater.data.ListDataProvider; import org.eclipse.jgit.lib.PersonIdent; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.ForkModel; import com.gitblit.models.RepositoryModel; @@ -45,7 +44,7 @@ public class ForksPage extends RepositoryPage { final RepositoryModel pageRepository = getRepositoryModel(); - ForkModel root = GitBlit.self().getForkNetwork(pageRepository.name); + ForkModel root = app().repositories().getForkNetwork(pageRepository.name); List network = flatten(root); ListDataProvider forksDp = new ListDataProvider(network); @@ -58,7 +57,7 @@ public class ForksPage extends RepositoryPage { RepositoryModel repository = fork.repository; if (repository.isPersonalRepository()) { - UserModel user = GitBlit.self().getUserModel(repository.projectPath.substring(1)); + UserModel user = app().users().getUserModel(repository.projectPath.substring(1)); if (user == null) { // user account no longer exists user = new UserModel(repository.projectPath.substring(1)); @@ -84,7 +83,7 @@ public class ForksPage extends RepositoryPage { item.add(swatch); String projectName = repository.projectPath; if (StringUtils.isEmpty(projectName)) { - projectName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main"); + projectName = app().settings().getString(Keys.web.repositoryRootGroupName, "main"); } if (pageRepository.equals(repository)) { // do not link to self diff --git a/src/main/java/com/gitblit/wicket/pages/LogoutPage.java b/src/main/java/com/gitblit/wicket/pages/LogoutPage.java index ff3b507f..f7be99ae 100644 --- a/src/main/java/com/gitblit/wicket/pages/LogoutPage.java +++ b/src/main/java/com/gitblit/wicket/pages/LogoutPage.java @@ -18,7 +18,6 @@ package com.gitblit.wicket.pages; import org.apache.wicket.protocol.http.WebRequest; import org.apache.wicket.protocol.http.WebResponse; -import com.gitblit.GitBlit; import com.gitblit.models.UserModel; import com.gitblit.wicket.GitBlitWebSession; @@ -28,8 +27,8 @@ public class LogoutPage extends BasePage { super(); GitBlitWebSession session = GitBlitWebSession.get(); UserModel user = session.getUser(); - GitBlit.self().setCookie((WebResponse) getResponse(), null); - GitBlit.self().logout(user); + app().session().setCookie((WebResponse) getResponse(), null); + app().session().logout(user); session.invalidate(); /* diff --git a/src/main/java/com/gitblit/wicket/pages/LuceneSearchPage.java b/src/main/java/com/gitblit/wicket/pages/LuceneSearchPage.java index 86a426ca..4d4545a5 100644 --- a/src/main/java/com/gitblit/wicket/pages/LuceneSearchPage.java +++ b/src/main/java/com/gitblit/wicket/pages/LuceneSearchPage.java @@ -32,7 +32,6 @@ import org.apache.wicket.model.Model; import org.eclipse.jgit.lib.Constants; import com.gitblit.Constants.SearchType; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.RepositoryModel; import com.gitblit.models.SearchResult; @@ -65,7 +64,7 @@ public class LuceneSearchPage extends RootPage { ArrayList repositories = new ArrayList(); String query = ""; int page = 1; - int pageSize = GitBlit.getInteger(Keys.web.itemsPerPage, 50); + int pageSize = app().settings().getInteger(Keys.web.itemsPerPage, 50); if (params != null) { String repository = WicketUtils.getRepositoryName(params); @@ -100,12 +99,12 @@ public class LuceneSearchPage extends RootPage { // display user-accessible selections UserModel user = GitBlitWebSession.get().getUser(); List availableRepositories = new ArrayList(); - for (RepositoryModel model : GitBlit.self().getRepositoryModels(user)) { + for (RepositoryModel model : app().repositories().getRepositoryModels(user)) { if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) { availableRepositories.add(model.name); } } - boolean luceneEnabled = GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true); + boolean luceneEnabled = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true); if (luceneEnabled) { if (availableRepositories.size() == 0) { info(getString("gb.noIndexedRepositoriesWarning")); @@ -158,7 +157,7 @@ public class LuceneSearchPage extends RootPage { // execute search final List results = new ArrayList(); if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) { - results.addAll(GitBlit.self().search(query, page, pageSize, searchRepositories)); + results.addAll(app().repositories().search(query, page, pageSize, searchRepositories)); } // results header diff --git a/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java b/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java index 8e05b4f0..ba85b822 100644 --- a/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java +++ b/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java @@ -35,7 +35,6 @@ import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.panel.Fragment; import org.eclipse.jgit.lib.Constants; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.ProjectModel; import com.gitblit.models.RepositoryModel; @@ -71,9 +70,9 @@ public class MyDashboardPage extends DashboardPage { private void setup(PageParameters params) { setupPage("", ""); // check to see if we should display a login message - boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, true); + boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true); if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) { - String messageSource = GitBlit.getString(Keys.web.loginMessage, "gitblit"); + String messageSource = app().settings().getString(Keys.web.loginMessage, "gitblit"); String message = readMarkdown(messageSource, "login.mkd"); Component repositoriesMessage = new Label("repositoriesMessage", message); add(repositoriesMessage.setEscapeModelStrings(false)); @@ -83,7 +82,7 @@ public class MyDashboardPage extends DashboardPage { } // Load the markdown welcome message - String messageSource = GitBlit.getString(Keys.web.repositoriesMessage, "gitblit"); + String messageSource = app().settings().getString(Keys.web.repositoriesMessage, "gitblit"); String message = readMarkdown(messageSource, "welcome.mkd"); Component repositoriesMessage = new Label("repositoriesMessage", message) .setEscapeModelStrings(false).setVisible(message.length() > 0); @@ -96,9 +95,9 @@ public class MyDashboardPage extends DashboardPage { // parameters int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params); - int maxDaysBack = GitBlit.getInteger(Keys.web.activityDurationMaximum, 30); + int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30); if (daysBack < 1) { - daysBack = GitBlit.getInteger(Keys.web.activityDuration, 7); + daysBack = app().settings().getInteger(Keys.web.activityDuration, 7); } if (maxDaysBack > 0 && daysBack > maxDaysBack) { daysBack = maxDaysBack; @@ -168,7 +167,7 @@ public class MyDashboardPage extends DashboardPage { add(repositoryTabs); // projects list - List projects = GitBlit.self().getProjectModels(getRepositoryModels(), false); + List projects = app().projects().getProjectModels(getRepositoryModels(), false); repositoryTabs.add(new FilterableProjectList("projects", projects)); // active repository list @@ -208,7 +207,7 @@ public class MyDashboardPage extends DashboardPage { } else { // Read user-supplied message if (!StringUtils.isEmpty(messageSource)) { - File file = GitBlit.getFileOrFolder(messageSource); + File file = app().runtime().getFileOrFolder(messageSource); if (file.exists()) { try { FileInputStream fis = new FileInputStream(file); diff --git a/src/main/java/com/gitblit/wicket/pages/OverviewPage.java b/src/main/java/com/gitblit/wicket/pages/OverviewPage.java index f6362c22..efb7f4cf 100644 --- a/src/main/java/com/gitblit/wicket/pages/OverviewPage.java +++ b/src/main/java/com/gitblit/wicket/pages/OverviewPage.java @@ -28,7 +28,6 @@ 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.GitBlit; import com.gitblit.Keys; import com.gitblit.models.Metric; import com.gitblit.models.RepositoryModel; @@ -53,7 +52,7 @@ public class OverviewPage extends RepositoryPage { public OverviewPage(PageParameters params) { super(params); - int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5); + int numberRefs = app().settings().getInteger(Keys.web.summaryRefsCount, 5); Repository r = getRepository(); final RepositoryModel model = getRepositoryModel(); @@ -64,8 +63,8 @@ public class OverviewPage extends RepositoryPage { List metrics = null; Metric metricsTotal = null; - if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) { - metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r); + if (!model.skipSummaryMetrics && app().settings().getBoolean(Keys.web.generateActivityGraph, true)) { + metrics = app().repositories().getRepositoryDefaultMetrics(model, r); metricsTotal = metrics.remove(0); } @@ -83,7 +82,7 @@ public class OverviewPage extends RepositoryPage { @Override public void populateItem(final Item item) { String ownername = item.getModelObject(); - UserModel ownerModel = GitBlit.self().getUserModel(ownername); + UserModel ownerModel = app().users().getUserModel(ownername); if (ownerModel != null) { item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true)); @@ -117,7 +116,7 @@ public class OverviewPage extends RepositoryPage { add(new RepositoryUrlPanel("repositoryUrlPanel", false, user, model)); - int reflogCount = GitBlit.getInteger(Keys.web.overviewReflogCount, 5); + int reflogCount = app().settings().getInteger(Keys.web.overviewReflogCount, 5); ReflogPanel reflog = new ReflogPanel("reflogPanel", getRepositoryModel(), r, reflogCount, 0); add(reflog); add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty()); @@ -134,7 +133,7 @@ public class OverviewPage extends RepositoryPage { private void insertActivityGraph(List metrics) { if ((metrics != null) && (metrics.size() > 0) - && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) { + && app().settings().getBoolean(Keys.web.generateActivityGraph, true)) { // daily line chart GoogleChart chart = new GoogleLineChart("chartDaily", "", "unit", diff --git a/src/main/java/com/gitblit/wicket/pages/PatchPage.java b/src/main/java/com/gitblit/wicket/pages/PatchPage.java index be959d01..ece41367 100644 --- a/src/main/java/com/gitblit/wicket/pages/PatchPage.java +++ b/src/main/java/com/gitblit/wicket/pages/PatchPage.java @@ -16,12 +16,10 @@ 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.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; @@ -31,7 +29,7 @@ import com.gitblit.wicket.GitBlitWebSession; import com.gitblit.wicket.WicketUtils; @CacheControl(LastModified.BOOT) -public class PatchPage extends WebPage { +public class PatchPage extends SessionPage { public PatchPage(PageParameters params) { super(params); @@ -47,7 +45,7 @@ public class PatchPage extends WebPage { final String objectId = WicketUtils.getObject(params); final String blobPath = WicketUtils.getPath(params); - Repository r = GitBlit.self().getRepository(repositoryName); + Repository r = app().repositories().getRepository(repositoryName); if (r == null) { GitBlitWebSession.get().cacheErrorMessage(getString("gb.canNotLoadRepository") + " " + repositoryName); redirectToInterceptPage(new RepositoriesPage()); diff --git a/src/main/java/com/gitblit/wicket/pages/ProjectPage.java b/src/main/java/com/gitblit/wicket/pages/ProjectPage.java index 19588a95..22396bec 100644 --- a/src/main/java/com/gitblit/wicket/pages/ProjectPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ProjectPage.java @@ -25,7 +25,6 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.ExternalLink; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.SyndicationServlet; import com.gitblit.models.ProjectModel; @@ -87,7 +86,7 @@ public class ProjectPage extends DashboardPage { private void setup(PageParameters params) { setupPage("", ""); // check to see if we should display a login message - boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, true); + boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true); if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) { authenticationError("Please login"); return; @@ -130,7 +129,7 @@ public class ProjectPage extends DashboardPage { } int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params); if (daysBack < 1) { - daysBack = GitBlit.getInteger(Keys.web.activityDuration, 7); + daysBack = app().settings().getInteger(Keys.web.activityDuration, 7); } // reset the daysback parameter so that we have a complete project // repository list. the recent activity will be built up by the @@ -186,7 +185,7 @@ public class ProjectPage extends DashboardPage { protected List getProjectModels() { if (projectModels.isEmpty()) { List repositories = getRepositoryModels(); - List projects = GitBlit.self().getProjectModels(repositories, false); + List projects = app().projects().getProjectModels(repositories, false); projectModels.addAll(projects); } return projectModels; diff --git a/src/main/java/com/gitblit/wicket/pages/ProjectsPage.java b/src/main/java/com/gitblit/wicket/pages/ProjectsPage.java index e5000462..77d49846 100644 --- a/src/main/java/com/gitblit/wicket/pages/ProjectsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ProjectsPage.java @@ -23,7 +23,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.GitBlit; import com.gitblit.Keys; import com.gitblit.models.ProjectModel; import com.gitblit.wicket.GitBlitWebSession; @@ -57,13 +56,13 @@ public class ProjectsPage extends RootPage { @Override protected List getProjectModels() { - return GitBlit.self().getProjectModels(getRepositoryModels(), false); + return app().projects().getProjectModels(getRepositoryModels(), false); } private void setup(PageParameters params) { setupPage("", ""); // check to see if we should display a login message - boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, true); + boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true); if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) { add(new Label("projectsPanel")); return; diff --git a/src/main/java/com/gitblit/wicket/pages/RawPage.java b/src/main/java/com/gitblit/wicket/pages/RawPage.java index 17837649..ac4af6d5 100644 --- a/src/main/java/com/gitblit/wicket/pages/RawPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RawPage.java @@ -31,7 +31,6 @@ 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.models.UserModel; @@ -66,11 +65,11 @@ public class RawPage extends SessionPage { final String repositoryName = WicketUtils.getRepositoryName(params); final String objectId = WicketUtils.getObject(params); final String blobPath = WicketUtils.getPath(params); - String[] encodings = GitBlit.getEncodings(); + String[] encodings = getEncodings(); GitBlitWebSession session = GitBlitWebSession.get(); UserModel user = session.getUser(); - RepositoryModel model = GitBlit.self().getRepositoryModel(user, repositoryName); + RepositoryModel model = app().repositories().getRepositoryModel(user, repositoryName); if (model == null) { // user does not have permission error(getString("gb.canNotLoadRepository") + " " + repositoryName); @@ -78,7 +77,7 @@ public class RawPage extends SessionPage { return; } - Repository r = GitBlit.self().getRepository(repositoryName); + Repository r = app().repositories().getRepository(repositoryName); if (r == null) { error(getString("gb.canNotLoadRepository") + " " + repositoryName); redirectToInterceptPage(new RepositoriesPage()); @@ -112,10 +111,10 @@ public class RawPage extends SessionPage { // Map the extensions to types Map map = new HashMap(); - for (String ext : GitBlit.getStrings(Keys.web.imageExtensions)) { + for (String ext : app().settings().getStrings(Keys.web.imageExtensions)) { map.put(ext.toLowerCase(), 2); } - for (String ext : GitBlit.getStrings(Keys.web.binaryExtensions)) { + for (String ext : app().settings().getStrings(Keys.web.binaryExtensions)) { map.put(ext.toLowerCase(), 3); } diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoriesPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoriesPage.java index b446279a..70266f8f 100644 --- a/src/main/java/com/gitblit/wicket/pages/RepositoriesPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RepositoriesPage.java @@ -28,7 +28,6 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.eclipse.jgit.lib.Constants; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.RepositoryModel; import com.gitblit.utils.MarkdownUtils; @@ -63,9 +62,9 @@ public class RepositoriesPage extends RootPage { private void setup(PageParameters params) { setupPage("", ""); // check to see if we should display a login message - boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, true); + boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true); if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) { - String messageSource = GitBlit.getString(Keys.web.loginMessage, "gitblit"); + String messageSource = app().settings().getString(Keys.web.loginMessage, "gitblit"); String message = readMarkdown(messageSource, "login.mkd"); Component repositoriesMessage = new Label("repositoriesMessage", message); add(repositoriesMessage.setEscapeModelStrings(false)); @@ -74,7 +73,7 @@ public class RepositoriesPage extends RootPage { } // Load the markdown welcome message - String messageSource = GitBlit.getString(Keys.web.repositoriesMessage, "gitblit"); + String messageSource = app().settings().getString(Keys.web.repositoriesMessage, "gitblit"); String message = readMarkdown(messageSource, "welcome.mkd"); Component repositoriesMessage = new Label("repositoriesMessage", message) .setEscapeModelStrings(false).setVisible(message.length() > 0); @@ -120,7 +119,7 @@ public class RepositoriesPage extends RootPage { } else { // Read user-supplied message if (!StringUtils.isEmpty(messageSource)) { - File file = GitBlit.getFileOrFolder(messageSource); + File file = app().runtime().getFileOrFolder(messageSource); if (file.exists()) { try { FileInputStream fis = new FileInputStream(file); diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java index 93af1bef..e19c1955 100644 --- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java @@ -46,7 +46,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.gitblit.Constants; -import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; import com.gitblit.PagesServlet; @@ -60,6 +59,7 @@ import com.gitblit.models.UserRepositoryPreferences; import com.gitblit.utils.ArrayUtils; import com.gitblit.utils.DeepCopier; import com.gitblit.utils.JGitUtils; +import com.gitblit.utils.MessageProcessor; import com.gitblit.utils.RefLogUtils; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.CacheControl; @@ -97,7 +97,7 @@ public abstract class RepositoryPage extends RootPage { repositoryName = WicketUtils.getRepositoryName(params); String root =StringUtils.getFirstPathElement(repositoryName); if (StringUtils.isEmpty(root)) { - projectName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main"); + projectName = app().settings().getString(Keys.web.repositoryRootGroupName, "main"); } else { projectName = root; } @@ -139,7 +139,7 @@ public abstract class RepositoryPage extends RootPage { UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(getRepositoryModel().name); prefs.starred = star; try { - GitBlit.self().updateUserModel(user.username, user, false); + app().users().updateUserModel(user.username, user, false); } catch (GitBlitException e) { logger.error("Failed to update user " + user.username, e); error(getString("gb.failedToUpdateUser"), false); @@ -176,6 +176,10 @@ public abstract class RepositoryPage extends RootPage { return getClass(); } + protected MessageProcessor messageProcessor() { + return new MessageProcessor(app().settings()); + } + private Map registerPages() { PageParameters params = null; if (!StringUtils.isEmpty(repositoryName)) { @@ -198,7 +202,7 @@ public abstract class RepositoryPage extends RootPage { pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params)); pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params, true)); pages.put("compare", new PageRegistration("gb.compare", ComparePage.class, params, true)); - if (GitBlit.getBoolean(Keys.web.allowForking, true)) { + if (app().settings().getBoolean(Keys.web.allowForking, true)) { pages.put("forks", new PageRegistration("gb.forks", ForksPage.class, params, true)); } @@ -212,11 +216,11 @@ public abstract class RepositoryPage extends RootPage { // Conditionally add edit link showAdmin = false; - if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) { - boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false); + if (app().settings().getBoolean(Keys.web.authenticateAdminPages, true)) { + boolean allowAdmin = app().settings().getBoolean(Keys.web.allowAdministration, false); showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin(); } else { - showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false); + showAdmin = app().settings().getBoolean(Keys.web.allowAdministration, false); } isOwner = GitBlitWebSession.get().isLoggedIn() && (model.isOwner(GitBlitWebSession.get() @@ -225,13 +229,13 @@ public abstract class RepositoryPage extends RootPage { } protected boolean allowForkControls() { - return GitBlit.getBoolean(Keys.web.allowForking, true); + return app().settings().getBoolean(Keys.web.allowForking, true); } @Override protected void setupPage(String repositoryName, String pageName) { String projectName = StringUtils.getFirstPathElement(repositoryName); - ProjectModel project = GitBlit.self().getProjectModel(projectName); + ProjectModel project = app().projects().getProjectModel(projectName); if (project.isUserProject()) { // user-as-project add(new LinkPanel("projectTitle", null, project.getDisplayName(), @@ -267,7 +271,7 @@ public abstract class RepositoryPage extends RootPage { add(new Label("originRepository").setVisible(false)); } } else { - RepositoryModel origin = GitBlit.self().getRepositoryModel(model.originRepository); + RepositoryModel origin = app().repositories().getRepositoryModel(model.originRepository); if (origin == null) { // no origin repository add(new Label("originRepository").setVisible(false)); @@ -311,7 +315,7 @@ public abstract class RepositoryPage extends RootPage { add(new ExternalLink("forkLink", "").setVisible(false)); add(new ExternalLink("myForkLink", "").setVisible(false)); } else { - String fork = GitBlit.self().getFork(user.username, model.name); + String fork = app().repositories().getFork(user.username, model.name); boolean hasFork = fork != null; boolean canFork = user.canFork(model); @@ -363,7 +367,7 @@ public abstract class RepositoryPage extends RootPage { protected Repository getRepository() { if (r == null) { - Repository r = GitBlit.self().getRepository(repositoryName); + Repository r = app().repositories().getRepository(repositoryName); if (r == null) { error(getString("gb.canNotLoadRepository") + " " + repositoryName, true); return null; @@ -375,10 +379,10 @@ public abstract class RepositoryPage extends RootPage { protected RepositoryModel getRepositoryModel() { if (m == null) { - RepositoryModel model = GitBlit.self().getRepositoryModel( + RepositoryModel model = app().repositories().getRepositoryModel( GitBlitWebSession.get().getUser(), repositoryName); if (model == null) { - if (GitBlit.self().hasRepository(repositoryName, true)) { + if (app().repositories().hasRepository(repositoryName, true)) { // has repository, but unauthorized authenticationError(getString("gb.unauthorizedAccessForRepository") + " " + repositoryName); } else { @@ -450,7 +454,7 @@ public abstract class RepositoryPage extends RootPage { return model; } else { // extract the repository name from the clone url - List patterns = GitBlit.getStrings(Keys.git.submoduleUrlPatterns); + List patterns = app().settings().getStrings(Keys.git.submoduleUrlPatterns); String submoduleName = StringUtils.extractRepositoryPath(model.url, patterns.toArray(new String[0])); // determine the current path for constructing paths relative @@ -489,7 +493,7 @@ public abstract class RepositoryPage extends RootPage { // create a unique, ordered set of candidate paths Set paths = new LinkedHashSet(candidates); for (String candidate : paths) { - if (GitBlit.self().hasRepository(candidate)) { + if (app().repositories().hasRepository(candidate)) { model.hasSubmodule = true; model.gitblitPath = candidate; return model; @@ -503,7 +507,7 @@ public abstract class RepositoryPage extends RootPage { } protected String getShortObjectId(String objectId) { - return objectId.substring(0, GitBlit.getInteger(Keys.web.shortCommitIdLength, 6)); + return objectId.substring(0, app().settings().getInteger(Keys.web.shortCommitIdLength, 6)); } protected void addRefs(Repository r, RevCommit c) { @@ -512,7 +516,7 @@ public abstract class RepositoryPage extends RootPage { protected void addFullText(String wicketId, String text) { RepositoryModel model = getRepositoryModel(); - String content = GitBlit.self().processCommitMessage(model, text); + String content = messageProcessor().processCommitMessage(model, text); String html; switch (model.commitMessageRenderer) { case MARKDOWN: @@ -533,7 +537,7 @@ public abstract class RepositoryPage extends RootPage { String address = identity == null ? "" : identity.getEmailAddress(); name = StringUtils.removeNewlines(name); address = StringUtils.removeNewlines(address); - boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false); + boolean showEmail = app().settings().getBoolean(Keys.web.showEmailAddresses, false); if (!showEmail || StringUtils.isEmpty(name) || StringUtils.isEmpty(address)) { String value = name; if (StringUtils.isEmpty(value)) { @@ -664,7 +668,7 @@ public abstract class RepositoryPage extends RootPage { DropDownChoice searchType = new DropDownChoice( "searchType", Arrays.asList(Constants.SearchType.values())); searchType.setModel(searchTypeModel); - add(searchType.setVisible(GitBlit.getBoolean(Keys.web.showSearchTypeSelection, false))); + add(searchType.setVisible(app().settings().getBoolean(Keys.web.showSearchTypeSelection, false))); TextField searchBox = new TextField("searchBox", searchBoxModel); add(searchBox); } @@ -695,8 +699,8 @@ public abstract class RepositoryPage extends RootPage { } } Class searchPageClass = GitSearchPage.class; - RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName); - if (GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true) + RepositoryModel model = app().repositories().getRepositoryModel(repositoryName); + if (app().settings().getBoolean(Keys.web.allowLuceneIndexing, true) && !ArrayUtils.isEmpty(model.indexedBranches)) { // this repository is Lucene-indexed searchPageClass = LuceneSearchPage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/ReviewProposalPage.java b/src/main/java/com/gitblit/wicket/pages/ReviewProposalPage.java index ebe15304..8aec9e63 100644 --- a/src/main/java/com/gitblit/wicket/pages/ReviewProposalPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ReviewProposalPage.java @@ -23,7 +23,6 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; import com.gitblit.Constants.FederationToken; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.FederationProposal; import com.gitblit.models.RepositoryModel; @@ -37,14 +36,12 @@ public class ReviewProposalPage extends RootSubPage { private final String PROPS_PATTERN = "{0} = {1}\n"; - private final String WEBXML_PATTERN = "\n\n\t{0}\n\t{1}\n\n"; - public ReviewProposalPage(PageParameters params) { super(params); final String token = WicketUtils.getToken(params); - FederationProposal proposal = GitBlit.self().getPendingFederationProposal(token); + FederationProposal proposal = app().federation().getPendingFederationProposal(token); if (proposal == null) { error(getString("gb.couldNotFindFederationProposal"), true); } @@ -58,14 +55,7 @@ public class ReviewProposalPage extends RootSubPage { add(new Label("token", proposal.token)); add(new Label("tokenType", proposal.tokenType.name())); - String p; - if (GitBlit.isGO()) { - // gitblit.properties definition - p = PROPS_PATTERN; - } else { - // web.xml definition - p = WEBXML_PATTERN; - } + String p = PROPS_PATTERN; // build proposed definition StringBuilder sb = new StringBuilder(); @@ -77,7 +67,7 @@ public class ReviewProposalPage extends RootSubPage { sb.append(asParam(p, proposal.name, "mergeAccounts", "false")); } sb.append(asParam(p, proposal.name, "frequency", - GitBlit.getString(Keys.federation.defaultFrequency, "60 mins"))); + app().settings().getString(Keys.federation.defaultFrequency, "60 mins"))); sb.append(asParam(p, proposal.name, "folder", proposal.name)); sb.append(asParam(p, proposal.name, "bare", "true")); sb.append(asParam(p, proposal.name, "mirror", "true")); diff --git a/src/main/java/com/gitblit/wicket/pages/RootPage.java b/src/main/java/com/gitblit/wicket/pages/RootPage.java index a59e2022..98a8cb32 100644 --- a/src/main/java/com/gitblit/wicket/pages/RootPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RootPage.java @@ -46,7 +46,6 @@ import org.apache.wicket.model.Model; import org.apache.wicket.protocol.http.WebResponse; import com.gitblit.Constants; -import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.RepositoryModel; import com.gitblit.models.TeamModel; @@ -97,22 +96,22 @@ public abstract class RootPage extends BasePage { StringBuilder buffer = new StringBuilder(); buffer.append("