001 package org.apache.maven.repository.legacy.resolver.transform;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import org.apache.maven.artifact.Artifact;
023 import org.apache.maven.artifact.metadata.ArtifactMetadata;
024 import org.apache.maven.artifact.repository.ArtifactRepository;
025 import org.apache.maven.artifact.repository.RepositoryRequest;
026 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
027 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
028 import org.apache.maven.artifact.repository.metadata.Versioning;
029 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
030 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
031 import org.codehaus.plexus.component.annotations.Component;
032
033 /**
034 * Change the version <code>RELEASE</code> to the appropriate release version from the remote repository.
035 *
036 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
037 */
038 @Component( role = ArtifactTransformation.class, hint = "release" )
039 public class ReleaseArtifactTransformation
040 extends AbstractVersionTransformation
041 {
042
043 public void transformForResolve( Artifact artifact, RepositoryRequest request )
044 throws ArtifactResolutionException, ArtifactNotFoundException
045 {
046 if ( Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) )
047 {
048 try
049 {
050 String version = resolveVersion( artifact, request );
051
052 if ( Artifact.RELEASE_VERSION.equals( version ) )
053 {
054 throw new ArtifactNotFoundException( "Unable to determine the release version", artifact );
055 }
056
057 artifact.setBaseVersion( version );
058 artifact.updateVersion( version, request.getLocalRepository() );
059 }
060 catch ( RepositoryMetadataResolutionException e )
061 {
062 throw new ArtifactResolutionException( e.getMessage(), artifact, e );
063 }
064 }
065 }
066
067 public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
068 {
069 ArtifactMetadata metadata = createMetadata( artifact );
070
071 artifact.addMetadata( metadata );
072 }
073
074 public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
075 ArtifactRepository localRepository )
076 {
077 ArtifactMetadata metadata = createMetadata( artifact );
078
079 artifact.addMetadata( metadata );
080 }
081
082 private ArtifactMetadata createMetadata( Artifact artifact )
083 {
084 Versioning versioning = new Versioning();
085 versioning.updateTimestamp();
086 versioning.addVersion( artifact.getVersion() );
087
088 if ( artifact.isRelease() )
089 {
090 versioning.setRelease( artifact.getVersion() );
091 }
092
093 return new ArtifactRepositoryMetadata( artifact, versioning );
094 }
095
096 protected String constructVersion( Versioning versioning, String baseVersion )
097 {
098 return versioning.getRelease();
099 }
100 }