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  
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 class ScmCommitDevelopmentPhase
41      extends AbstractScmCommitPhase
42  {
43  
44      /**
45       * The format for the
46       */
47      private String rollbackMessageFormat;
48  
49      protected void runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
50                               List<MavenProject> reactorProjects, ReleaseResult result, boolean simulating )
51          throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException
52      {
53          // no rollback required
54          if (
55              // was there no commit that has to be rolled back by a new one
56              releaseDescriptor.isSuppressCommitBeforeTagOrBranch()
57                  // and working copy should not be touched
58                  && !releaseDescriptor.isUpdateWorkingCopyVersions() )
59          {
60              if ( simulating )
61              {
62                  logInfo( result, "Full run would not commit changes, because updateWorkingCopyVersions is false." );
63              }
64              else
65              {
66                  logInfo( result, "Modified POMs are not committed because updateWorkingCopyVersions is set to false." );
67              }
68          }
69          // rollback or commit development versions required
70          else
71          {
72              String message;
73              if ( !releaseDescriptor.isUpdateWorkingCopyVersions() )
74              {
75                  // the commit is a rollback
76                  message = createRollbackMessage( releaseDescriptor );
77              }
78              else
79              {
80                  // a normal commit
81                  message = createMessage( releaseDescriptor );
82              }
83              if ( simulating )
84              {
85                  Collection<File> pomFiles = createPomFiles( releaseDescriptor, reactorProjects );
86                  logInfo( result,
87                           "Full run would be commit " + pomFiles.size() + " files with message: '" + message + "'" );
88              }
89              else
90              {
91                  performCheckins( releaseDescriptor, releaseEnvironment, reactorProjects, message );
92              }
93          }
94      }
95  
96      private String createRollbackMessage( ReleaseDescriptor releaseDescriptor )
97      {
98          return MessageFormat.format( releaseDescriptor.getScmCommentPrefix() + rollbackMessageFormat,
99                                       new Object[]{releaseDescriptor.getScmReleaseLabel()} );
100     }
101 
102 }