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.repository.ArtifactRepository;
26  import org.apache.maven.artifact.repository.RepositoryRequest;
27  import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
28  import org.apache.maven.artifact.repository.metadata.Versioning;
29  import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
30  import org.apache.maven.artifact.resolver.ArtifactResolutionException;
31  
32  /**
33   * Describes a version transformation during artifact resolution - "latest" type
34   */
35  @Named("latest")
36  @Singleton
37  @Deprecated
38  public class LatestArtifactTransformation extends AbstractVersionTransformation {
39  
40      public void transformForResolve(Artifact artifact, RepositoryRequest request)
41              throws ArtifactResolutionException, ArtifactNotFoundException {
42          if (Artifact.LATEST_VERSION.equals(artifact.getVersion())) {
43              try {
44                  String version = resolveVersion(artifact, request);
45                  if (Artifact.LATEST_VERSION.equals(version)) {
46                      throw new ArtifactNotFoundException("Unable to determine the latest version", artifact);
47                  }
48  
49                  artifact.setBaseVersion(version);
50                  artifact.updateVersion(version, request.getLocalRepository());
51              } catch (RepositoryMetadataResolutionException e) {
52                  throw new ArtifactResolutionException(e.getMessage(), artifact, e);
53              }
54          }
55      }
56  
57      public void transformForInstall(Artifact artifact, ArtifactRepository localRepository) {
58          // metadata is added via addPluginArtifactMetadata
59      }
60  
61      public void transformForDeployment(
62              Artifact artifact, ArtifactRepository remoteRepository, ArtifactRepository localRepository) {
63          // metadata is added via addPluginArtifactMetadata
64      }
65  
66      protected String constructVersion(Versioning versioning, String baseVersion) {
67          return versioning.getLatest();
68      }
69  }