Add configuration option to not add weblinks
In some situations a site may want to install gitiles in Gerrit,
but not have weblinks from the Gerrit UI.
Add a new configuration option:
[gerrit]
noWebLinks = true
which, when set, will prevent the weblinks from being added.
The default is unset, meaning the weblinks are displayed as before.
Change-Id: Id50c7148bb1e4c58ef78261c0b07f3dd576f1b38
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java
index 343e716..202f1bb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java
@@ -26,11 +26,13 @@
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.GerritServerConfig;
+import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.gerrit.server.ssh.SshAdvertisedAddresses;
import com.google.gitiles.ArchiveFormat;
import com.google.gitiles.DefaultUrls;
import com.google.gitiles.GitilesAccess;
import com.google.gitiles.GitilesUrls;
+import com.google.inject.Inject;
import com.google.inject.Provides;
import com.google.inject.ProvisionException;
import com.google.inject.Singleton;
@@ -45,14 +47,24 @@
import org.eclipse.jgit.transport.resolver.RepositoryResolver;
class Module extends LifecycleModule {
+ private final boolean noWebLinks;
+
+ @Inject
+ Module(PluginConfigFactory configFactory) {
+ Config config = configFactory.getGlobalPluginConfig("gitiles");
+ this.noWebLinks = config.getBoolean("gerrit", null, "noWebLinks", false);
+ }
+
@Override
protected void configure() {
- DynamicSet.bind(binder(), BranchWebLink.class).to(GitilesWeblinks.class);
- DynamicSet.bind(binder(), FileHistoryWebLink.class).to(GitilesWeblinks.class);
- DynamicSet.bind(binder(), FileWebLink.class).to(GitilesWeblinks.class);
- DynamicSet.bind(binder(), ParentWebLink.class).to(GitilesWeblinks.class);
- DynamicSet.bind(binder(), PatchSetWebLink.class).to(GitilesWeblinks.class);
- DynamicSet.bind(binder(), ProjectWebLink.class).to(GitilesWeblinks.class);
+ if (!noWebLinks) {
+ DynamicSet.bind(binder(), BranchWebLink.class).to(GitilesWeblinks.class);
+ DynamicSet.bind(binder(), FileHistoryWebLink.class).to(GitilesWeblinks.class);
+ DynamicSet.bind(binder(), FileWebLink.class).to(GitilesWeblinks.class);
+ DynamicSet.bind(binder(), ParentWebLink.class).to(GitilesWeblinks.class);
+ DynamicSet.bind(binder(), PatchSetWebLink.class).to(GitilesWeblinks.class);
+ DynamicSet.bind(binder(), ProjectWebLink.class).to(GitilesWeblinks.class);
+ }
bind(GitilesAccess.Factory.class).to(GerritGitilesAccess.Factory.class);
bind(new TypeLiteral<RepositoryResolver<HttpServletRequest>>() {}).to(Resolver.class);
listener().to(Lifecycle.class);
diff --git a/src/main/resources/+Documentation/config.md b/src/main/resources/+Documentation/config.md
index abb6b71..8b4a371 100644
--- a/src/main/resources/+Documentation/config.md
+++ b/src/main/resources/+Documentation/config.md
@@ -41,3 +41,12 @@
linkname = gitiles
target = _self
```
+
+The flag `gerrit.noWebLinks` can be set to `true` to run Gitiles without
+adding links in the Gerrit UI. Defaults to `false` if not set, meaning the
+links are added.
+
+```
+ [gerrit]
+ noWebLinks = true
+```