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.io.File;
22  import java.text.MessageFormat;
23  import java.util.Collection;
24  import java.util.List;
25  
26  import org.apache.maven.project.MavenProject;
27  import org.apache.maven.shared.release.ReleaseExecutionException;
28  import org.apache.maven.shared.release.ReleaseResult;
29  import org.apache.maven.shared.release.config.ReleaseDescriptor;
30  import org.apache.maven.shared.release.env.ReleaseEnvironment;
31  import org.apache.maven.shared.release.scm.ReleaseScmCommandException;
32  import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
33  import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
34  
35  /**
36   * Commit the changes that were done to prepare the branch or tag to the SCM.
37   *
38   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
39   */
40  public abstract class AbstractScmCommitDevelopmentPhase extends AbstractScmCommitPhase {
41      /**
42       * The format for the
43       */
44      private final String rollbackMessageFormat;
45  
46      protected AbstractScmCommitDevelopmentPhase(
47              ScmRepositoryConfigurator scmRepositoryConfigurator,
48              String descriptorCommentGetter,
49              String rollbackMessageFormat) {
50          super(scmRepositoryConfigurator, descriptorCommentGetter);
51          this.rollbackMessageFormat = rollbackMessageFormat;
52      }
53  
54      @Override
55      protected void runLogic(
56              ReleaseDescriptor releaseDescriptor,
57              ReleaseEnvironment releaseEnvironment,
58              List<MavenProject> reactorProjects,
59              ReleaseResult result,
60              boolean simulating)
61              throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException {
62          // no rollback required
63          if (
64          // was there no commit that has to be rolled back by a new one
65          releaseDescriptor.isSuppressCommitBeforeTagOrBranch()
66                  // and working copy should not be touched
67                  && !releaseDescriptor.isUpdateWorkingCopyVersions()) {
68              if (simulating) {
69                  logInfo(result, "Full run would not commit changes, because updateWorkingCopyVersions is false.");
70              } else {
71                  logInfo(result, "Modified POMs are not committed because updateWorkingCopyVersions is set to false.");
72              }
73          }
74          // rollback or commit development versions required
75          else {
76              String message;
77              if (!releaseDescriptor.isUpdateWorkingCopyVersions()) {
78                  // the commit is a rollback
79                  message = createRollbackMessage(releaseDescriptor);
80              } else {
81                  // a normal commit
82                  message = createMessage(reactorProjects, releaseDescriptor);
83              }
84              if (simulating) {
85                  Collection<File> pomFiles = createPomFiles(releaseDescriptor, reactorProjects);
86                  logInfo(result, "Full run would commit " + pomFiles.size() + " files with message: '" + message + "'");
87              } else {
88                  performCheckins(releaseDescriptor, releaseEnvironment, reactorProjects, message);
89              }
90          }
91      }
92  
93      private String createRollbackMessage(ReleaseDescriptor releaseDescriptor) {
94          return MessageFormat.format(
95                  releaseDescriptor.getScmCommentPrefix() + rollbackMessageFormat,
96                  releaseDescriptor.getScmReleaseLabel());
97      }
98  }