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