KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > artifact > transform > LatestArtifactTransformation


1 package org.apache.maven.artifact.transform;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.artifact.Artifact;
20 import org.apache.maven.artifact.repository.ArtifactRepository;
21 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
22 import org.apache.maven.artifact.repository.metadata.Versioning;
23 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
24 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
25
26 import java.util.List JavaDoc;
27
28 public class LatestArtifactTransformation
29     extends AbstractVersionTransformation
30 {
31     public void transformForResolve( Artifact artifact, List JavaDoc remoteRepositories, ArtifactRepository localRepository )
32         throws ArtifactResolutionException, ArtifactNotFoundException
33     {
34         if ( Artifact.LATEST_VERSION.equals( artifact.getVersion() ) )
35         {
36             try
37             {
38                 String JavaDoc version = resolveVersion( artifact, localRepository, remoteRepositories );
39                 if ( Artifact.LATEST_VERSION.equals( version ) )
40                 {
41                     throw new ArtifactNotFoundException( "Unable to determine the latest version", artifact );
42                 }
43
44                 artifact.setBaseVersion( version );
45                 artifact.updateVersion( version, localRepository );
46             }
47             catch ( RepositoryMetadataResolutionException e )
48             {
49                 throw new ArtifactResolutionException( e.getMessage(), artifact, e );
50             }
51         }
52     }
53
54     public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
55     {
56         // metadata is added via addPluginArtifactMetadata
57
}
58
59     public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
60                                         ArtifactRepository localRepository )
61     {
62         // metadata is added via addPluginArtifactMetadata
63
}
64
65     protected String JavaDoc constructVersion( Versioning versioning, String JavaDoc baseVersion )
66     {
67         return versioning.getLatest();
68     }
69 }
70
Popular Tags