View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.repository.legacy.resolver.transform;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.metadata.ArtifactMetadata;
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.artifact.repository.RepositoryRequest;
28  import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
29  import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
30  import org.apache.maven.artifact.repository.metadata.Versioning;
31  import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
32  import org.apache.maven.artifact.resolver.ArtifactResolutionException;
33  
34  /**
35   * Change the version <code>RELEASE</code> to the appropriate release version from the remote repository.
36   *
37   */
38  @Named("release")
39  @Singleton
40  @Deprecated
41  public class ReleaseArtifactTransformation extends AbstractVersionTransformation {
42  
43      public void transformForResolve(Artifact artifact, RepositoryRequest request)
44              throws ArtifactResolutionException, ArtifactNotFoundException {
45          if (Artifact.RELEASE_VERSION.equals(artifact.getVersion())) {
46              try {
47                  String version = resolveVersion(artifact, request);
48  
49                  if (Artifact.RELEASE_VERSION.equals(version)) {
50                      throw new ArtifactNotFoundException("Unable to determine the release version", artifact);
51                  }
52  
53                  artifact.setBaseVersion(version);
54                  artifact.updateVersion(version, request.getLocalRepository());
55              } catch (RepositoryMetadataResolutionException e) {
56                  throw new ArtifactResolutionException(e.getMessage(), artifact, e);
57              }
58          }
59      }
60  
61      public void transformForInstall(Artifact artifact, ArtifactRepository localRepository) {
62          ArtifactMetadata metadata = createMetadata(artifact);
63  
64          artifact.addMetadata(metadata);
65      }
66  
67      public void transformForDeployment(
68              Artifact artifact, ArtifactRepository remoteRepository, ArtifactRepository localRepository) {
69          ArtifactMetadata metadata = createMetadata(artifact);
70  
71          artifact.addMetadata(metadata);
72      }
73  
74      private ArtifactMetadata createMetadata(Artifact artifact) {
75          Versioning versioning = new Versioning();
76          // TODO Should this be changed for MNG-6754 too?
77          versioning.updateTimestamp();
78          versioning.addVersion(artifact.getVersion());
79  
80          if (artifact.isRelease()) {
81              versioning.setRelease(artifact.getVersion());
82          }
83  
84          return new ArtifactRepositoryMetadata(artifact, versioning);
85      }
86  
87      protected String constructVersion(Versioning versioning, String baseVersion) {
88          return versioning.getRelease();
89      }
90  }