Bind ProjectDeletionAction and CacheDeleteHandler explicitly The ProjectDelectionAction and its CacheDeleteHandler classes were implicitly bound at their first outer-level container class in a non-controlled injector. In same cases, e.g. when the pull-replication plugin was loaded before the delete-project and was accessible at top-level class loader, Guice was generating a just-in-time binding in the parent class loader that would have then conflicted with the explicit binding performed in the delete-project plugin. See below an example of the resulting exception: 1) [Guice/JitBindingAlreadySet]: A just-in-time binding to CacheDeleteHandler was already configured on a parent injector. at PluginModule.configure(PluginModule.java:49) 1 error CacheDeleteHandler: "com.googlesource.gerrit.plugins.deleteproject.cache.CacheDeleteHandler" PluginModule: "com.googlesource.gerrit.plugins.deleteproject.PluginModule" Binding the classes explicitly to the injector that is loading the plugin, prevents Guice from creating just-in-time binding at unexpected hierarchy levels. Change-Id: I11192677a3af752719df3b37c84856a976290d7c
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/HttpModule.java index 95082b8..72a0182 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/HttpModule.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/HttpModule.java
@@ -20,6 +20,7 @@ import com.google.inject.Scopes; import com.google.inject.name.Names; import com.google.inject.servlet.ServletModule; +import com.googlesource.gerrit.plugins.deleteproject.cache.CacheDeleteHandler; import com.googlesource.gerrit.plugins.replication.pull.BearerTokenProvider; public class HttpModule extends ServletModule { @@ -46,6 +47,9 @@ .in(Scopes.SINGLETON); }); + bind(CacheDeleteHandler.class); + bind(ProjectDeletionAction.class).in(Scopes.SINGLETON); + DynamicSet.bind(binder(), AllRequestFilter.class) .to(PullReplicationFilter.class) .in(Scopes.SINGLETON);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectDeletionAction.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectDeletionAction.java index 6a21104..f9165ad 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectDeletionAction.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectDeletionAction.java
@@ -29,7 +29,6 @@ import com.google.gerrit.server.project.ProjectResource; import com.google.inject.Inject; import com.google.inject.Provider; -import com.google.inject.Singleton; import com.googlesource.gerrit.plugins.deleteproject.cache.CacheDeleteHandler; import com.googlesource.gerrit.plugins.deleteproject.fs.RepositoryDelete; import com.googlesource.gerrit.plugins.replication.pull.GerritConfigOps; @@ -38,7 +37,6 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.transport.URIish; -@Singleton class ProjectDeletionAction implements RestModifyView<ProjectResource, ProjectDeletionAction.DeleteInput> { private static final PluginPermission DELETE_PROJECT =