View Javadoc

1   package org.apache.maven.artifact.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.metadata.ArtifactRepositoryMetadata;
26  import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
27  import org.apache.maven.artifact.repository.metadata.Versioning;
28  import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
29  import org.apache.maven.artifact.resolver.ArtifactResolutionException;
30  
31  import java.util.List;
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   * @version $Id: ReleaseArtifactTransformation.java 640549 2008-03-24 20:05:11Z bentmann $
38   */
39  public class ReleaseArtifactTransformation
40      extends AbstractVersionTransformation
41  {
42      public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
43          throws ArtifactResolutionException, ArtifactNotFoundException
44      {
45          if ( Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) )
46          {
47              try
48              {
49                  String version = resolveVersion( artifact, localRepository, remoteRepositories );
50  
51                  if ( Artifact.RELEASE_VERSION.equals( version ) )
52                  {
53                      throw new ArtifactNotFoundException( "Unable to determine the release version", artifact );
54                  }
55  
56                  artifact.setBaseVersion( version );
57                  artifact.updateVersion( version, localRepository );
58              }
59              catch ( RepositoryMetadataResolutionException e )
60              {
61                  throw new ArtifactResolutionException( e.getMessage(), artifact, e );
62              }
63          }
64      }
65  
66      public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
67      {
68          ArtifactMetadata metadata = createMetadata( artifact );
69  
70          artifact.addMetadata( metadata );
71      }
72  
73      public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
74                                          ArtifactRepository localRepository )
75      {
76          ArtifactMetadata metadata = createMetadata( artifact );
77  
78          artifact.addMetadata( metadata );
79      }
80  
81      private ArtifactMetadata createMetadata( Artifact artifact )
82      {
83          Versioning versioning = new Versioning();
84          versioning.updateTimestamp();
85          versioning.addVersion( artifact.getVersion() );
86  
87          if ( artifact.isRelease() )
88          {
89              versioning.setRelease( artifact.getVersion() );
90          }
91  
92          return new ArtifactRepositoryMetadata( artifact, versioning );
93      }
94  
95      protected String constructVersion( Versioning versioning, String baseVersion )
96      {
97          return versioning.getRelease();
98      }
99  }