Create SubmoduleSectionParser using assisted injection

This will allow to change dependencies of SubmoduleSectionParser without
adding them to SubmoduleOp only to pass them to SubmoduleSectionParser
constructor.

Change-Id: Ib995027284310caec21cd367ffde3c5f27b2eb3f
This commit is contained in:
Hugo Arès
2015-04-16 15:50:49 -04:00
parent 1ad61122e2
commit 723d26d39f
4 changed files with 25 additions and 10 deletions

View File

@@ -123,6 +123,7 @@ import com.google.gerrit.server.query.change.ConflictsCacheImpl;
import com.google.gerrit.server.ssh.SshAddressesModule;
import com.google.gerrit.server.tools.ToolsCatalog;
import com.google.gerrit.server.util.IdGenerator;
import com.google.gerrit.server.util.SubmoduleSectionParser;
import com.google.gerrit.server.util.ThreadLocalRequestContext;
import com.google.gerrit.server.validators.GroupCreationValidationListener;
import com.google.gerrit.server.validators.HashtagValidationListener;
@@ -294,6 +295,7 @@ public class GerritGlobalModule extends FactoryModule {
factory(MergeValidators.Factory.class);
factory(ProjectConfigValidator.Factory.class);
factory(NotesBranchUtil.Factory.class);
factory(SubmoduleSectionParser.Factory.class);
bind(AccountManager.class);
bind(ChangeUserName.CurrentUser.class);

View File

@@ -93,6 +93,7 @@ public class SubmoduleOp {
private final Set<Branch.NameKey> updatedSubscribers;
private final Account account;
private final ChangeHooks changeHooks;
private final SubmoduleSectionParser.Factory subSecParserFactory;
@Inject
public SubmoduleOp(@Assisted Branch.NameKey destBranch,
@@ -109,7 +110,8 @@ public class SubmoduleOp {
GitRepositoryManager repoManager,
GitReferenceUpdated gitRefUpdated,
@Nullable @Assisted Account account,
ChangeHooks changeHooks) {
ChangeHooks changeHooks,
SubmoduleSectionParser.Factory subSecParserFactory) {
this.destBranch = destBranch;
this.mergeTip = mergeTip;
this.rw = rw;
@@ -124,6 +126,7 @@ public class SubmoduleOp {
this.gitRefUpdated = gitRefUpdated;
this.account = account;
this.changeHooks = changeHooks;
this.subSecParserFactory = subSecParserFactory;
updatedSubscribers = new HashSet<>();
}
@@ -168,8 +171,8 @@ public class SubmoduleOp {
final Set<SubmoduleSubscription> oldSubscriptions =
new HashSet<>(schema.submoduleSubscriptions()
.bySuperProject(destBranch).toList());
final List<SubmoduleSubscription> newSubscriptions =
new SubmoduleSectionParser(bbc, thisServer, target, repoManager)
List<SubmoduleSubscription> newSubscriptions =
subSecParserFactory.create(bbc, thisServer, target)
.parseAllSections();
final Set<SubmoduleSubscription> alreadySubscribeds = new HashSet<>();

View File

@@ -18,6 +18,8 @@ import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.SubmoduleSubscription;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.lib.BlobBasedConfig;
import org.eclipse.jgit.lib.Constants;
@@ -45,18 +47,26 @@ import java.util.List;
* </pre>
*/
public class SubmoduleSectionParser {
public interface Factory {
SubmoduleSectionParser create(BlobBasedConfig bbc, String thisServer,
Branch.NameKey superProjectBranch);
}
private final GitRepositoryManager repoManager;
private final BlobBasedConfig bbc;
private final String thisServer;
private final Branch.NameKey superProjectBranch;
private final GitRepositoryManager repoManager;
public SubmoduleSectionParser(final BlobBasedConfig bbc,
final String thisServer, final Branch.NameKey superProjectBranch,
final GitRepositoryManager repoManager) {
@Inject
public SubmoduleSectionParser(GitRepositoryManager repoManager,
@Assisted BlobBasedConfig bbc,
@Assisted String thisServer,
@Assisted Branch.NameKey superProjectBranch) {
this.repoManager = repoManager;
this.bbc = bbc;
this.thisServer = thisServer;
this.superProjectBranch = superProjectBranch;
this.repoManager = repoManager;
}
public List<SubmoduleSubscription> parseAllSections() {

View File

@@ -229,8 +229,8 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
doReplay();
final SubmoduleSectionParser ssp =
new SubmoduleSectionParser(bbc, THIS_SERVER, superProjectBranch,
repoManager);
new SubmoduleSectionParser(repoManager, bbc, THIS_SERVER,
superProjectBranch);
List<SubmoduleSubscription> returnedSubscriptions = ssp.parseAllSections();