Line data Source code
1 : // Copyright (C) 2012 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.submit; 16 : 17 : import com.google.common.flogger.FluentLogger; 18 : import com.google.gerrit.entities.BranchNameKey; 19 : import com.google.gerrit.entities.SubmissionId; 20 : import com.google.gerrit.exceptions.StorageException; 21 : import com.google.gerrit.extensions.api.changes.SubmitInput; 22 : import com.google.gerrit.extensions.client.SubmitType; 23 : import com.google.gerrit.server.IdentifiedUser; 24 : import com.google.gerrit.server.git.CodeReviewCommit; 25 : import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk; 26 : import com.google.gerrit.server.git.MergeTip; 27 : import com.google.gerrit.server.submit.MergeOp.CommitStatus; 28 : import com.google.inject.Inject; 29 : import com.google.inject.Singleton; 30 : import java.util.Set; 31 : import org.eclipse.jgit.revwalk.RevCommit; 32 : import org.eclipse.jgit.revwalk.RevFlag; 33 : 34 : /** Factory to create a {@link SubmitStrategy} for a {@link SubmitType}. */ 35 : @Singleton 36 : public class SubmitStrategyFactory { 37 142 : private static final FluentLogger logger = FluentLogger.forEnclosingClass(); 38 : 39 : private final SubmitStrategy.Arguments.Factory argsFactory; 40 : 41 : @Inject 42 142 : SubmitStrategyFactory(SubmitStrategy.Arguments.Factory argsFactory) { 43 142 : this.argsFactory = argsFactory; 44 142 : } 45 : 46 : public SubmitStrategy create( 47 : SubmitType submitType, 48 : CodeReviewRevWalk rw, 49 : RevFlag canMergeFlag, 50 : Set<RevCommit> alreadyAccepted, 51 : Set<CodeReviewCommit> incoming, 52 : BranchNameKey destBranch, 53 : IdentifiedUser caller, 54 : MergeTip mergeTip, 55 : CommitStatus commitStatus, 56 : SubmissionId submissionId, 57 : SubmitInput submitInput, 58 : SubmoduleCommits submoduleCommits, 59 : SubscriptionGraph subscriptionGraph, 60 : boolean dryrun) { 61 53 : SubmitStrategy.Arguments args = 62 53 : argsFactory.create( 63 : submitType, 64 : destBranch, 65 : commitStatus, 66 : rw, 67 : caller, 68 : mergeTip, 69 : canMergeFlag, 70 : alreadyAccepted, 71 : incoming, 72 : submissionId, 73 : submitInput, 74 : submoduleCommits, 75 : subscriptionGraph, 76 : dryrun); 77 53 : switch (submitType) { 78 : case CHERRY_PICK: 79 7 : return new CherryPick(args); 80 : case FAST_FORWARD_ONLY: 81 3 : return new FastForwardOnly(args); 82 : case MERGE_ALWAYS: 83 5 : return new MergeAlways(args); 84 : case MERGE_IF_NECESSARY: 85 53 : return new MergeIfNecessary(args); 86 : case REBASE_IF_NECESSARY: 87 4 : return new RebaseIfNecessary(args); 88 : case REBASE_ALWAYS: 89 4 : return new RebaseAlways(args); 90 : case INHERIT: 91 : default: 92 0 : String errorMsg = "No submit strategy for: " + submitType; 93 0 : logger.atSevere().log("%s", errorMsg); 94 0 : throw new StorageException(errorMsg); 95 : } 96 : } 97 : }