View Javadoc
1   package org.apache.maven.shared.release.phase;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.text.MessageFormat;
24  import java.util.Collection;
25  import java.util.List;
26  
27  import org.apache.maven.project.MavenProject;
28  import org.apache.maven.shared.release.ReleaseExecutionException;
29  import org.apache.maven.shared.release.ReleaseResult;
30  import org.apache.maven.shared.release.config.ReleaseDescriptor;
31  import org.apache.maven.shared.release.env.ReleaseEnvironment;
32  import org.apache.maven.shared.release.scm.ReleaseScmCommandException;
33  import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
34  import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
35  
36  /**
37   * Commit the changes that were done to prepare the branch or tag to the SCM.
38   *
39   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
40   */
41  public abstract class AbstractScmCommitDevelopmentPhase
42          extends AbstractScmCommitPhase
43  {
44      /**
45       * The format for the
46       */
47      private final String rollbackMessageFormat;
48  
49      protected AbstractScmCommitDevelopmentPhase(
50              ScmRepositoryConfigurator scmRepositoryConfigurator,
51              String descriptorCommentGetter, String rollbackMessageFormat )
52      {
53          super( scmRepositoryConfigurator, descriptorCommentGetter );
54          this.rollbackMessageFormat = rollbackMessageFormat;
55      }
56  
57      @Override
58      protected void runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
59                               List<MavenProject> reactorProjects, ReleaseResult result, boolean simulating )
60              throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException
61      {
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          {
69              if ( simulating )
70              {
71                  logInfo( result, "Full run would not commit changes, because updateWorkingCopyVersions is false." );
72              }
73              else
74              {
75                  logInfo( result, "Modified POMs are not committed because updateWorkingCopyVersions is set to false." );
76              }
77          }
78          // rollback or commit development versions required
79          else
80          {
81              String message;
82              if ( !releaseDescriptor.isUpdateWorkingCopyVersions() )
83              {
84                  // the commit is a rollback
85                  message = createRollbackMessage( releaseDescriptor );
86              }
87              else
88              {
89                  // a normal commit
90                  message = createMessage( reactorProjects, releaseDescriptor );
91              }
92              if ( simulating )
93              {
94                  Collection<File> pomFiles = createPomFiles( releaseDescriptor, reactorProjects );
95                  logInfo( result,
96                          "Full run would commit " + pomFiles.size() + " files with message: '" + message + "'" );
97              }
98              else
99              {
100                 performCheckins( releaseDescriptor, releaseEnvironment, reactorProjects, message );
101             }
102         }
103     }
104 
105     private String createRollbackMessage( ReleaseDescriptor releaseDescriptor )
106     {
107         return MessageFormat.format( releaseDescriptor.getScmCommentPrefix() + rollbackMessageFormat,
108                 releaseDescriptor.getScmReleaseLabel() );
109     }
110 
111 }