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.util.List;
23  import java.util.Map;
24  
25  import org.apache.maven.model.Scm;
26  import org.apache.maven.project.MavenProject;
27  import org.apache.maven.scm.repository.ScmRepository;
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.scm.ScmTranslator;
32  import org.jdom.Element;
33  import org.jdom.Namespace;
34  
35  /**
36   * Rewrite POMs for future development
37   *
38   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
39   */
40  public class RewritePomsForDevelopmentPhase
41      extends AbstractRewritePomsPhase
42  {
43      /**
44       * SCM URL translators mapped by provider name.
45       */
46      private Map<String, ScmTranslator> scmTranslators;
47  
48      protected void transformScm( MavenProject project, Element rootElement, Namespace namespace,
49                                   ReleaseDescriptor releaseDescriptor, String projectId, ScmRepository scmRepository,
50                                   ReleaseResult result, String commonBasedir )
51          throws ReleaseExecutionException
52      {
53          // If SCM is null in original model, it is inherited, no mods needed
54          if ( project.getScm() != null )
55          {
56              Element scmRoot = rootElement.getChild( "scm", namespace );
57              if ( scmRoot != null )
58              {
59                  @SuppressWarnings( "unchecked" )
60                  Map<String, Scm> originalScmInfo = releaseDescriptor.getOriginalScmInfo();
61                  // check containsKey, not == null, as we store null as a value
62                  if ( !originalScmInfo.containsKey( projectId ) )
63                  {
64                      throw new ReleaseExecutionException(
65                          "Unable to find original SCM info for '" + project.getName() + "'" );
66                  }
67  
68                  ScmTranslator translator = scmTranslators.get( scmRepository.getProvider() );
69                  if ( translator != null )
70                  {
71                      Scm scm = originalScmInfo.get( projectId );
72  
73                      if ( scm != null )
74                      {
75                          rewriteElement( "connection", scm.getConnection(), scmRoot, namespace );
76                          rewriteElement( "developerConnection", scm.getDeveloperConnection(), scmRoot, namespace );
77                          rewriteElement( "url", scm.getUrl(), scmRoot, namespace );
78                          rewriteElement( "tag", translator.resolveTag( scm.getTag() ), scmRoot, namespace );
79                      }
80                      else
81                      {
82                          // cleanly remove the SCM element
83                          rewriteElement( "scm", null, rootElement, namespace );
84                      }
85                  }
86                  else
87                  {
88                      String message = "No SCM translator found - skipping rewrite";
89                      result.appendDebug( message );
90                      getLogger().debug( message );
91                  }
92              }
93          }
94      }
95  
96      @SuppressWarnings( "unchecked" )
97      protected Map<String, String> getOriginalVersionMap( ReleaseDescriptor releaseDescriptor,
98                                                           List<MavenProject> reactorProjects, boolean simulate )
99      {
100         return simulate
101             ? releaseDescriptor.getOriginalVersions( reactorProjects )
102             : releaseDescriptor.getReleaseVersions();
103     }
104 
105     @SuppressWarnings( "unchecked" )
106     protected Map<String,String> getNextVersionMap( ReleaseDescriptor releaseDescriptor )
107     {
108         return releaseDescriptor.getDevelopmentVersions();
109     }
110 
111     protected String getResolvedSnapshotVersion( String artifactVersionlessKey,
112                                                  Map<String, Map<String, String>> resolvedSnapshotsMap )
113     {
114         Map<String, String> versionsMap = resolvedSnapshotsMap.get( artifactVersionlessKey );
115 
116         if ( versionsMap != null )
117         {
118             return versionsMap.get( ReleaseDescriptor.DEVELOPMENT_KEY );
119         }
120         else
121         {
122             return null;
123         }
124     }
125 }