View Javadoc
1   package org.apache.maven.repository.legacy.resolver.transform;
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.artifact.Artifact;
23  import org.apache.maven.artifact.metadata.ArtifactMetadata;
24  import org.apache.maven.artifact.repository.ArtifactRepository;
25  import org.apache.maven.artifact.repository.RepositoryRequest;
26  import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
27  import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
28  import org.apache.maven.artifact.repository.metadata.Versioning;
29  import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
30  import org.apache.maven.artifact.resolver.ArtifactResolutionException;
31  import org.codehaus.plexus.component.annotations.Component;
32  
33  /**
34   * Change the version <code>RELEASE</code> to the appropriate release version from the remote repository.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   */
38  @Component( role = ArtifactTransformation.class, hint = "release" )
39  public class ReleaseArtifactTransformation
40      extends AbstractVersionTransformation
41  {
42  
43      public void transformForResolve( Artifact artifact, RepositoryRequest request )
44          throws ArtifactResolutionException, ArtifactNotFoundException
45      {
46          if ( Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) )
47          {
48              try
49              {
50                  String version = resolveVersion( artifact, request );
51  
52                  if ( Artifact.RELEASE_VERSION.equals( version ) )
53                  {
54                      throw new ArtifactNotFoundException( "Unable to determine the release version", artifact );
55                  }
56  
57                  artifact.setBaseVersion( version );
58                  artifact.updateVersion( version, request.getLocalRepository() );
59              }
60              catch ( RepositoryMetadataResolutionException e )
61              {
62                  throw new ArtifactResolutionException( e.getMessage(), artifact, e );
63              }
64          }
65      }
66  
67      public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
68      {
69          ArtifactMetadata metadata = createMetadata( artifact );
70  
71          artifact.addMetadata( metadata );
72      }
73  
74      public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
75                                          ArtifactRepository localRepository )
76      {
77          ArtifactMetadata metadata = createMetadata( artifact );
78  
79          artifact.addMetadata( metadata );
80      }
81  
82      private ArtifactMetadata createMetadata( Artifact artifact )
83      {
84          Versioning versioning = new Versioning();
85          // TODO Should this be changed for MNG-6754 too?
86          versioning.updateTimestamp();
87          versioning.addVersion( artifact.getVersion() );
88  
89          if ( artifact.isRelease() )
90          {
91              versioning.setRelease( artifact.getVersion() );
92          }
93  
94          return new ArtifactRepositoryMetadata( artifact, versioning );
95      }
96  
97      protected String constructVersion( Versioning versioning, String baseVersion )
98      {
99          return versioning.getRelease();
100     }
101 }