diff options
author | Saša Živkov <sasa.zivkov@sap.com> | 2019-03-08 11:27:15 +0100 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2019-04-04 11:02:19 +0900 |
commit | ed5c9f26b255fe915ba9abfad77771728fc0d3d8 (patch) | |
tree | 31310f4c273293ed25314779e1bd4534827346fe | |
parent | 4c95625d9509bff39962e5fe6cd5c6b133de71e9 (diff) |
Replace DestinationFactory with Guice generated Factory and assisted injectionv2.16.8
Change-Id: Ib64461f6066e59ad7951af86ba11b43f3a6ad0da
5 files changed, 16 insertions, 91 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/AutoReloadConfigDecorator.java b/src/main/java/com/googlesource/gerrit/plugins/replication/AutoReloadConfigDecorator.java index 7374c4a..ad6e67d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/AutoReloadConfigDecorator.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/AutoReloadConfigDecorator.java @@ -35,7 +35,7 @@ public class AutoReloadConfigDecorator implements ReplicationConfig { private long lastFailedConfigTs; private final SitePaths site; - private final DestinationFactory destinationFactory; + private final Destination.Factory destinationFactory; private final Path pluginDataDir; // Use Provider<> instead of injecting the ReplicationQueue because of circular dependency with // ReplicationConfig @@ -44,7 +44,7 @@ public class AutoReloadConfigDecorator implements ReplicationConfig { @Inject public AutoReloadConfigDecorator( SitePaths site, - DestinationFactory destinationFactory, + Destination.Factory destinationFactory, Provider<ReplicationQueue> replicationQueue, @PluginData Path pluginDataDir) throws ConfigInvalidException, IOException { diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java index 1827e61..5a3b92c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java @@ -52,9 +52,11 @@ import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.util.RequestContext; +import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provider; import com.google.inject.Provides; +import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.FactoryModuleBuilder; import com.google.inject.servlet.RequestScoped; import com.googlesource.gerrit.plugins.replication.ReplicationState.RefPushResult; @@ -80,6 +82,11 @@ import org.slf4j.Logger; public class Destination { private static final Logger repLog = ReplicationQueue.repLog; + + public interface Factory { + Destination create(DestinationConfiguration config); + } + private final ReplicationStateListener stateLog; private final Object stateLock = new Object(); private final Map<URIish, PushOne> pending = new HashMap<>(); @@ -110,9 +117,9 @@ public class Destination { } } + @Inject protected Destination( Injector injector, - DestinationConfiguration cfg, PluginUser pluginUser, GitRepositoryManager gitRepositoryManager, PermissionBackend permissionBackend, @@ -121,15 +128,15 @@ public class Destination { GroupBackend groupBackend, ReplicationStateListeners stateLog, GroupIncludeCache groupIncludeCache, - DynamicItem<EventDispatcher> eventDispatcher) { - config = cfg; + DynamicItem<EventDispatcher> eventDispatcher, + @Assisted DestinationConfiguration cfg) { this.eventDispatcher = eventDispatcher; gitManager = gitRepositoryManager; this.permissionBackend = permissionBackend; this.userProvider = userProvider; this.projectCache = projectCache; this.stateLog = stateLog; - + config = cfg; CurrentUser remoteUser; if (!cfg.getAuthGroupNames().isEmpty()) { ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder(); diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/DestinationFactory.java b/src/main/java/com/googlesource/gerrit/plugins/replication/DestinationFactory.java deleted file mode 100644 index 09f4f4e..0000000 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/DestinationFactory.java +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2016 The Android Open Source Project -// -// 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.googlesource.gerrit.plugins.replication; - -import com.google.gerrit.extensions.registration.DynamicItem; -import com.google.gerrit.server.CurrentUser; -import com.google.gerrit.server.PluginUser; -import com.google.gerrit.server.account.GroupBackend; -import com.google.gerrit.server.account.GroupIncludeCache; -import com.google.gerrit.server.events.EventDispatcher; -import com.google.gerrit.server.git.GitRepositoryManager; -import com.google.gerrit.server.permissions.PermissionBackend; -import com.google.gerrit.server.project.ProjectCache; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.Provider; -import com.google.inject.Singleton; - -@Singleton -public class DestinationFactory { - private final Injector injector; - private final PluginUser pluginUser; - private final GitRepositoryManager gitRepositoryManager; - private final PermissionBackend permissionBackend; - private final Provider<CurrentUser> userProvider; - private final ProjectCache projectCache; - private final GroupBackend groupBackend; - private final ReplicationStateListeners stateLog; - private final GroupIncludeCache groupIncludeCache; - private final DynamicItem<EventDispatcher> eventDispatcher; - - @Inject - public DestinationFactory( - Injector injector, - PluginUser pluginUser, - GitRepositoryManager gitRepositoryManager, - PermissionBackend permissionBackend, - Provider<CurrentUser> userProvider, - ProjectCache projectCache, - GroupBackend groupBackend, - ReplicationStateListeners stateLog, - GroupIncludeCache groupIncludeCache, - DynamicItem<EventDispatcher> eventDispatcher) { - this.injector = injector; - this.pluginUser = pluginUser; - this.gitRepositoryManager = gitRepositoryManager; - this.permissionBackend = permissionBackend; - this.userProvider = userProvider; - this.projectCache = projectCache; - this.groupBackend = groupBackend; - this.stateLog = stateLog; - this.groupIncludeCache = groupIncludeCache; - this.eventDispatcher = eventDispatcher; - } - - Destination create(DestinationConfiguration config) { - return new Destination( - injector, - config, - pluginUser, - gitRepositoryManager, - permissionBackend, - userProvider, - projectCache, - groupBackend, - stateLog, - groupIncludeCache, - eventDispatcher); - } -} diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationFileBasedConfig.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationFileBasedConfig.java index 3e8781e..46d2f66 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationFileBasedConfig.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationFileBasedConfig.java @@ -53,7 +53,7 @@ public class ReplicationFileBasedConfig implements ReplicationConfig { @Inject public ReplicationFileBasedConfig( - SitePaths site, DestinationFactory destinationFactory, @PluginData Path pluginDataDir) + SitePaths site, Destination.Factory destinationFactory, @PluginData Path pluginDataDir) throws ConfigInvalidException, IOException { this.site = site; this.cfgPath = site.etc_dir.resolve("replication.config"); @@ -86,7 +86,7 @@ public class ReplicationFileBasedConfig implements ReplicationConfig { return destinations.stream().filter(Objects::nonNull).filter(filter).collect(toList()); } - private List<Destination> allDestinations(DestinationFactory destinationFactory) + private List<Destination> allDestinations(Destination.Factory destinationFactory) throws ConfigInvalidException, IOException { if (!config.getFile().exists()) { logger.atWarning().log("Config file %s does not exist; not replicating", config.getFile()); diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationModule.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationModule.java index f37ed52..1405a12 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationModule.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationModule.java @@ -34,7 +34,7 @@ import org.eclipse.jgit.transport.SshSessionFactory; class ReplicationModule extends AbstractModule { @Override protected void configure() { - bind(DestinationFactory.class).in(Scopes.SINGLETON); + install(new FactoryModuleBuilder().build(Destination.Factory.class)); bind(ReplicationQueue.class).in(Scopes.SINGLETON); bind(LifecycleListener.class) .annotatedWith(UniqueAnnotations.create()) |