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.Inject;
22  import javax.inject.Named;
23  import javax.inject.Singleton;
24  
25  import java.util.List;
26  import java.util.Map;
27  import java.util.Objects;
28  import java.util.stream.Collectors;
29  import java.util.stream.Stream;
30  
31  import org.apache.maven.artifact.Artifact;
32  import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
33  import org.apache.maven.artifact.installer.ArtifactInstallationException;
34  import org.apache.maven.artifact.repository.ArtifactRepository;
35  import org.apache.maven.artifact.repository.RepositoryRequest;
36  import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
37  import org.apache.maven.artifact.resolver.ArtifactResolutionException;
38  
39  /**
40   */
41  @Named
42  @Singleton
43  @Deprecated
44  public class DefaultArtifactTransformationManager implements ArtifactTransformationManager {
45  
46      private List<ArtifactTransformation> artifactTransformations;
47  
48      @Inject
49      public DefaultArtifactTransformationManager(Map<String, ArtifactTransformation> artifactTransformations) {
50          this.artifactTransformations = Stream.of("release", "latest", "snapshot")
51                  .map(artifactTransformations::get)
52                  .filter(Objects::nonNull)
53                  .collect(Collectors.toList());
54      }
55  
56      public void transformForResolve(Artifact artifact, RepositoryRequest request)
57              throws ArtifactResolutionException, ArtifactNotFoundException {
58          for (ArtifactTransformation transform : artifactTransformations) {
59              transform.transformForResolve(artifact, request);
60          }
61      }
62  
63      public void transformForResolve(
64              Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository)
65              throws ArtifactResolutionException, ArtifactNotFoundException {
66          for (ArtifactTransformation transform : artifactTransformations) {
67              transform.transformForResolve(artifact, remoteRepositories, localRepository);
68          }
69      }
70  
71      public void transformForInstall(Artifact artifact, ArtifactRepository localRepository)
72              throws ArtifactInstallationException {
73          for (ArtifactTransformation transform : artifactTransformations) {
74              transform.transformForInstall(artifact, localRepository);
75          }
76      }
77  
78      public void transformForDeployment(
79              Artifact artifact, ArtifactRepository remoteRepository, ArtifactRepository localRepository)
80              throws ArtifactDeploymentException {
81          for (ArtifactTransformation transform : artifactTransformations) {
82              transform.transformForDeployment(artifact, remoteRepository, localRepository);
83          }
84      }
85  
86      public List<ArtifactTransformation> getArtifactTransformations() {
87          return artifactTransformations;
88      }
89  }