View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.release.phase;
20  
21  import java.util.List;
22  
23  import org.apache.maven.project.MavenProject;
24  import org.apache.maven.shared.release.ReleaseExecutionException;
25  import org.apache.maven.shared.release.ReleaseFailureException;
26  import org.apache.maven.shared.release.ReleaseResult;
27  import org.apache.maven.shared.release.config.ReleaseDescriptor;
28  import org.apache.maven.shared.release.env.ReleaseEnvironment;
29  import org.apache.maven.shared.release.scm.ReleaseScmCommandException;
30  import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
31  import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
32  
33  /**
34   * Commit the changes that were done to prepare the branch or tag to the SCM.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   */
38  public abstract class AbstractScmCommitPreparationPhase extends AbstractScmCommitPhase {
39      protected AbstractScmCommitPreparationPhase(
40              ScmRepositoryConfigurator scmRepositoryConfigurator, String descriptorCommentGetter) {
41          super(scmRepositoryConfigurator, descriptorCommentGetter);
42      }
43  
44      @Override
45      protected void runLogic(
46              ReleaseDescriptor releaseDescriptor,
47              ReleaseEnvironment releaseEnvironment,
48              List<MavenProject> reactorProjects,
49              ReleaseResult result,
50              boolean simulating)
51              throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException {
52          // no prepare-commit required
53          if (releaseDescriptor.isSuppressCommitBeforeTagOrBranch()) {
54              String parameterName;
55              if (releaseDescriptor.isBranchCreation()) {
56                  parameterName = "suppressCommitBeforeBranch";
57              } else {
58                  parameterName = "suppressCommitBeforeTag";
59              }
60  
61              if (simulating) {
62                  logInfo(
63                          result,
64                          "Full run would not commit changes, " + "because " + parameterName + " is set to true.");
65              } else {
66                  logInfo(result, "Modified POMs are not committed because " + parameterName + " is set to true.");
67              }
68          }
69          // commit development versions required
70          else {
71              String message = createMessage(reactorProjects, releaseDescriptor);
72              if (simulating) {
73                  simulateCheckins(releaseDescriptor, reactorProjects, result, message);
74              } else {
75                  performCheckins(releaseDescriptor, releaseEnvironment, reactorProjects, message);
76              }
77          }
78      }
79  
80      protected void validateConfiguration(ReleaseDescriptor releaseDescriptor) throws ReleaseFailureException {
81          super.validateConfiguration(releaseDescriptor);
82  
83          if (releaseDescriptor.isSuppressCommitBeforeTagOrBranch() && releaseDescriptor.isRemoteTagging()) {
84              throw new ReleaseFailureException(
85                      "Cannot perform a remote tag or branch without committing the working copy first.");
86          }
87      }
88  }