Merge "Exclude not needed artifacts from shaded jar"
diff --git a/pom.xml b/pom.xml
index af165e1..3b71cc3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
<artifactId>gitblit-plugin</artifactId>
<description>GitBlit for Gerrit integrated as a plugin</description>
<name>Gerrit - GitBlit Plugin</name>
- <version>2.8-SNAPSHOT</version>
+ <version>2.9-SNAPSHOT</version>
<properties>
<Gerrit-ApiType>plugin</Gerrit-ApiType>
<Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion>
@@ -38,7 +38,7 @@
<dependency>
<groupId>com.gitblit</groupId>
<artifactId>gitblit</artifactId>
- <version>1.3.1</version>
+ <version>1.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritWicketFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritWicketFilter.java
index d2d557f..a9d0601 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritWicketFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritWicketFilter.java
@@ -14,11 +14,9 @@
package com.googlesource.gerrit.plugins.gitblit;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.Properties;
import java.util.Vector;
import javax.servlet.FilterChain;
@@ -30,17 +28,12 @@
import javax.servlet.ServletResponse;
import org.apache.wicket.protocol.http.WicketFilter;
-import org.eclipse.jgit.lib.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gitblit.Constants;
import com.gitblit.GitBlit;
-import com.gitblit.IStoredSettings;
-import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.httpd.WebSession;
-import com.google.gerrit.server.config.GerritServerConfig;
-import com.google.gerrit.server.git.LocalDiskRepositoryManager;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -48,33 +41,27 @@
import com.googlesource.gerrit.plugins.gitblit.app.GerritToGitBlitWebApp;
import com.googlesource.gerrit.plugins.gitblit.app.GitBlitSettings;
import com.googlesource.gerrit.plugins.gitblit.auth.GerritAuthFilter;
-import com.googlesource.gerrit.plugins.gitblit.auth.GerritToGitBlitUserService;
@Singleton
public class GerritWicketFilter extends WicketFilter {
- private static final String GITBLIT_GERRIT_PROPERTIES = "/gitblit.properties";
private static final Logger log = LoggerFactory
.getLogger(GerritWicketFilter.class);
- private final LocalDiskRepositoryManager repoManager;
private final Provider<WebSession> webSession;
@SuppressWarnings("unused")
// We need Guice to create the GerritGitBlit instance
private final GerritGitBlit gitBlit;
private final GerritAuthFilter gerritAuthFilter;
- private final GitBlitUrlsConfig config;
+ private final GitBlitSettings settings;
@Inject
- public GerritWicketFilter(final LocalDiskRepositoryManager repoManager,
+ public GerritWicketFilter(
final Provider<WebSession> webSession, final GerritGitBlit gitBlit,
- final GerritAuthFilter gerritAuthFilter, final @GerritServerConfig Config config,
- final GerritConfig gerritConfig) {
-
- this.repoManager = repoManager;
+ final GerritAuthFilter gerritAuthFilter, final GitBlitSettings settings) {
this.webSession = webSession;
this.gitBlit = gitBlit;
this.gerritAuthFilter = gerritAuthFilter;
- this.config = new GitBlitUrlsConfig(config);
+ this.settings = settings;
}
@Override
@@ -82,29 +69,7 @@
showGitBlitBanner();
try {
- InputStream resin =
- getClass().getResourceAsStream(GITBLIT_GERRIT_PROPERTIES);
- Properties properties = null;
- try {
- properties = new Properties();
- properties.load(resin);
- properties.put("git.repositoriesFolder", repoManager.getBasePath()
- .getAbsolutePath());
- properties.put("realm.userService",
- GerritToGitBlitUserService.class.getName());
- if (properties.get("web.otherUrls") != null) {
- properties.put("web.otherUrls",
- (config.getGitHttpUrl() + " " + config.getGitSshUrl()).trim()
- + " " + properties.get("web.otherUrls"));
- } else {
- properties.put("web.otherUrls",
- (config.getGitHttpUrl() + " " + config.getGitSshUrl()).trim());
- }
- } finally {
- resin.close();
- }
- IStoredSettings settings = new GitBlitSettings(properties);
- GitBlit.self().configureContext(settings, repoManager.getBasePath(),
+ GitBlit.self().configureContext(settings, settings.getBasePath(),
false);
GitBlit.self().contextInitialized(
new ServletContextEvent(filterConfig.getServletContext()));
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritToGitBlitWebApp.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritToGitBlitWebApp.java
index d291279..419487c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritToGitBlitWebApp.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritToGitBlitWebApp.java
@@ -24,7 +24,7 @@
protected IRequestCycleProcessor newRequestCycleProcessor() {
return new WebRequestCycleProcessor() {
protected IRequestCodingStrategy newRequestCodingStrategy() {
- return new StaticCodingStrategy();
+ return new StaticCodingStrategy("summary/", "project/");
}
};
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GitBlitSettings.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GitBlitSettings.java
index f11e715..2f93f52 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GitBlitSettings.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GitBlitSettings.java
@@ -13,17 +13,48 @@
// limitations under the License.
package com.googlesource.gerrit.plugins.gitblit.app;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Map;
import java.util.Properties;
+import org.eclipse.jgit.lib.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.gitblit.IStoredSettings;
+import com.google.gerrit.server.config.GerritServerConfig;
+import com.google.gerrit.server.config.SitePaths;
+import com.google.gerrit.server.git.LocalDiskRepositoryManager;
+import com.google.inject.Inject;
+import com.googlesource.gerrit.plugins.gitblit.GitBlitUrlsConfig;
+import com.googlesource.gerrit.plugins.gitblit.auth.GerritToGitBlitUserService;
public class GitBlitSettings extends IStoredSettings {
- private Properties properties;
+ private static final String GITBLIT_GERRIT_PROPERTIES = "/gitblit.properties";
- public GitBlitSettings(Properties properties) {
+ private final LocalDiskRepositoryManager repoManager;
+ private final GitBlitUrlsConfig config;
+ private final File etcDir;
+
+ private Properties properties;
+ private File gitblitPropertiesFile;
+
+ @Inject
+ public GitBlitSettings(final LocalDiskRepositoryManager repoManager,
+ final @GerritServerConfig Config config, final SitePaths sitePaths)
+ throws IOException {
super(GitBlitSettings.class);
- this.properties = properties;
+ this.properties = new Properties();
+ this.repoManager = repoManager;
+ this.config = new GitBlitUrlsConfig(config);
+ this.etcDir = sitePaths.etc_dir;
+ load();
}
@Override
@@ -36,4 +67,65 @@
properties.putAll(updatedSettings);
return true;
}
+
+ private void load() throws IOException {
+ InputStream resin = openPropertiesFile();
+ try {
+ properties = new Properties();
+ properties.load(resin);
+ properties.put("git.repositoriesFolder", repoManager.getBasePath()
+ .getAbsolutePath());
+ properties.put("realm.userService",
+ GerritToGitBlitUserService.class.getName());
+ if (properties.get("web.otherUrls") != null) {
+ properties.put("web.otherUrls",
+ (config.getGitHttpUrl() + " " + config.getGitSshUrl()).trim() + " "
+ + properties.get("web.otherUrls"));
+ } else {
+ properties.put("web.otherUrls",
+ (config.getGitHttpUrl() + " " + config.getGitSshUrl()).trim());
+ }
+ } finally {
+ resin.close();
+ }
+ }
+
+ private InputStream openPropertiesFile() {
+ InputStream gitblitPropertiesIn;
+ gitblitPropertiesFile = new File(etcDir, GITBLIT_GERRIT_PROPERTIES);
+ if (gitblitPropertiesFile.exists()) {
+ try {
+ gitblitPropertiesIn = new FileInputStream(gitblitPropertiesFile);
+ } catch (FileNotFoundException e) {
+ // this would never happen as we checked for file existence before
+ throw new IllegalStateException(e);
+ }
+ } else {
+ gitblitPropertiesIn =
+ getClass().getResourceAsStream(GITBLIT_GERRIT_PROPERTIES);
+ }
+ return gitblitPropertiesIn;
+ }
+
+ public File getBasePath() {
+ return repoManager.getBasePath();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder stringSettings = new StringBuilder();
+ if (!gitblitPropertiesFile.exists()) {
+ stringSettings.append(GITBLIT_GERRIT_PROPERTIES
+ + " from gitblit plugin jar");
+ } else {
+ stringSettings.append(gitblitPropertiesFile.getAbsolutePath()
+ + " (lastModified: "
+ + new SimpleDateFormat().format(new Date(gitblitPropertiesFile
+ .lastModified())) + ")");
+ }
+
+ stringSettings.append(" with values ");
+ stringSettings.append(properties.toString());
+ return stringSettings.toString();
+ }
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/StaticCodingStrategy.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/StaticCodingStrategy.java
index 5dd9e5f..f196e27 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/StaticCodingStrategy.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/StaticCodingStrategy.java
@@ -17,8 +17,17 @@
import org.apache.wicket.RequestCycle;
import org.apache.wicket.protocol.http.request.WebRequestCodingStrategy;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class StaticCodingStrategy extends WebRequestCodingStrategy {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(StaticCodingStrategy.class);
+ private String[] ignoreResourceUrlPrefixes;
+
+ public StaticCodingStrategy(String... ignoreResourceUrlPrefixes) {
+ this.ignoreResourceUrlPrefixes = ignoreResourceUrlPrefixes;
+ }
@Override
public String rewriteStaticRelativeUrl(String url) {
@@ -28,12 +37,25 @@
return url;
}
+ if(isMatchingIgnoreUrlPrefixes(url)) {
+ return url;
+ }
+
int depth =
((ServletWebRequest) RequestCycle.get().getRequest())
.getDepthRelativeToWicketHandler();
return getRelativeStaticUrl(url, depth);
}
+ private boolean isMatchingIgnoreUrlPrefixes(String url) {
+ for (String ignoredUrlPrefix : ignoreResourceUrlPrefixes) {
+ if(url.startsWith(ignoredUrlPrefix)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public static String getRelativePrefix(Request request) {
int depth = ((ServletWebRequest) request).getDepthRelativeToWicketHandler();
@@ -60,6 +82,8 @@
// file
urlBuffer.append(url);
+ LOG.debug("Rewriting URL " + url + " to " + urlBuffer);
+
return urlBuffer.toString();
}
}