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      @Override
44      public void transformForResolve(Artifact artifact, RepositoryRequest request)
45              throws ArtifactResolutionException, ArtifactNotFoundException {
46          if (Artifact.RELEASE_VERSION.equals(artifact.getVersion())) {
47              try {
48                  String version = resolveVersion(artifact, request);
49  
50                  if (Artifact.RELEASE_VERSION.equals(version)) {
51                      throw new ArtifactNotFoundException("Unable to determine the release version", artifact);
52                  }
53  
54                  artifact.setBaseVersion(version);
55                  artifact.updateVersion(version, request.getLocalRepository());
56              } catch (RepositoryMetadataResolutionException e) {
57                  throw new ArtifactResolutionException(e.getMessage(), artifact, e);
58              }
59          }
60      }
61  
62      @Override
63      public void transformForInstall(Artifact artifact, ArtifactRepository localRepository) {
64          ArtifactMetadata metadata = createMetadata(artifact);
65  
66          artifact.addMetadata(metadata);
67      }
68  
69      @Override
70      public void transformForDeployment(
71              Artifact artifact, ArtifactRepository remoteRepository, ArtifactRepository localRepository) {
72          ArtifactMetadata metadata = createMetadata(artifact);
73  
74          artifact.addMetadata(metadata);
75      }
76  
77      private ArtifactMetadata createMetadata(Artifact artifact) {
78          Versioning versioning = new Versioning();
79          // TODO Should this be changed for MNG-6754 too?
80          versioning.updateTimestamp();
81          versioning.addVersion(artifact.getVersion());
82  
83          if (artifact.isRelease()) {
84              versioning.setRelease(artifact.getVersion());
85          }
86  
87          return new ArtifactRepositoryMetadata(artifact, versioning);
88      }
89  
90      @Override
91      protected String constructVersion(Versioning versioning, String baseVersion) {
92          return versioning.getRelease();
93      }
94  }