KickJava   Java API By Example, From Geeks To Geeks.

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


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.metadata.ArtifactMetadata;
21 import org.apache.maven.artifact.repository.ArtifactRepository;
22 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
23 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
24 import org.apache.maven.artifact.repository.metadata.Versioning;
25 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
26 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
27
28 import java.util.List JavaDoc;
29
30 /**
31  * Change the version <code>RELEASE</code> to the appropriate release version from the remote repository.
32  *
33  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
34  * @version $Id$
35  */

36 public class ReleaseArtifactTransformation
37     extends AbstractVersionTransformation
38 {
39     public void transformForResolve( Artifact artifact, List JavaDoc remoteRepositories, ArtifactRepository localRepository )
40         throws ArtifactResolutionException, ArtifactNotFoundException
41     {
42         if ( Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) )
43         {
44             try
45             {
46                 String JavaDoc version = resolveVersion( artifact, localRepository, remoteRepositories );
47
48                 if ( Artifact.RELEASE_VERSION.equals( version ) )
49                 {
50                     throw new ArtifactNotFoundException( "Unable to determine the release version", artifact );
51                 }
52
53                 artifact.setBaseVersion( version );
54                 artifact.updateVersion( version, localRepository );
55             }
56             catch ( RepositoryMetadataResolutionException e )
57             {
58                 throw new ArtifactResolutionException( e.getMessage(), artifact, e );
59             }
60         }
61     }
62
63     public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
64     {
65         ArtifactMetadata metadata = createMetadata( artifact );
66
67         artifact.addMetadata( metadata );
68     }
69
70     public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
71                                         ArtifactRepository localRepository )
72     {
73         ArtifactMetadata metadata = createMetadata( artifact );
74
75         artifact.addMetadata( metadata );
76     }
77
78     private ArtifactMetadata createMetadata( Artifact artifact )
79     {
80         Versioning versioning = new Versioning();
81         versioning.updateTimestamp();
82         versioning.addVersion( artifact.getVersion() );
83
84         if ( artifact.isRelease() )
85         {
86             versioning.setRelease( artifact.getVersion() );
87         }
88
89         return new ArtifactRepositoryMetadata( artifact, versioning );
90     }
91
92     protected String JavaDoc constructVersion( Versioning versioning, String JavaDoc baseVersion )
93     {
94         return versioning.getRelease();
95     }
96 }
97
Popular Tags