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 org.apache.maven.project.MavenProject;
23  import org.apache.maven.shared.release.ReleaseExecutionException;
24  import org.apache.maven.shared.release.ReleaseFailureException;
25  import org.apache.maven.shared.release.ReleaseResult;
26  import org.apache.maven.shared.release.config.ReleaseDescriptor;
27  import org.apache.maven.shared.release.env.ReleaseEnvironment;
28  import org.apache.maven.shared.release.scm.ReleaseScmCommandException;
29  import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
30  
31  import java.text.MessageFormat;
32  import java.util.List;
33  
34  /**
35   * Commit the changes that were done to prepare the branch or tag to the SCM.
36   *
37   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
38   */
39  public class ScmCommitPreparationPhase
40      extends AbstractScmCommitPhase
41  {
42  
43      /**
44       * The format for the
45       */
46      private String rollbackMessageFormat;
47  
48      protected void runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
49                               List<MavenProject> reactorProjects, ReleaseResult result, boolean simulating )
50          throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException
51      {
52          // no prepare-commit required
53          if ( releaseDescriptor.isSuppressCommitBeforeTagOrBranch() )
54          {
55              if ( simulating )
56              {
57                  logInfo( result, "Full run would not commit changes, because suppressCommitBeforeTagOrBranch is set." );
58              }
59              else
60              {
61                  logInfo( result,
62                           "Modified POMs are not committed because suppressCommitBeforeTagOrBranch is set to false." );
63              }
64          }
65          // commit development versions required
66          else
67          {
68              String message = createMessage( releaseDescriptor );
69  
70              if ( simulating )
71              {
72                  simulateCheckins( releaseDescriptor, reactorProjects, result, message );
73              }
74              else
75              {
76                  performCheckins( releaseDescriptor, releaseEnvironment, reactorProjects, message );
77              }
78          }
79      }
80  
81      private String createRollbackMessage( ReleaseDescriptor releaseDescriptor )
82      {
83          return MessageFormat.format( releaseDescriptor.getScmCommentPrefix() + rollbackMessageFormat,
84                                       new Object[]{releaseDescriptor.getScmReleaseLabel()} );
85      }
86  
87      protected void validateConfiguration( ReleaseDescriptor releaseDescriptor )
88          throws ReleaseFailureException
89      {
90          super.validateConfiguration( releaseDescriptor );
91  
92          if ( releaseDescriptor.isSuppressCommitBeforeTagOrBranch() && releaseDescriptor.isRemoteTagging() )
93          {
94              throw new ReleaseFailureException(
95                  "Cannot perform a remote tag or branch without committing the working copy first." );
96          }
97      }
98  }