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.project;
20  
21  import java.util.ArrayList;
22  import java.util.Arrays;
23  import java.util.List;
24  
25  import org.apache.maven.artifact.InvalidRepositoryException;
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
28  import org.apache.maven.model.DeploymentRepository;
29  import org.apache.maven.model.Repository;
30  import org.apache.maven.plugin.LegacySupport;
31  import org.apache.maven.repository.RepositorySystem;
32  import org.codehaus.plexus.PlexusContainer;
33  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
34  import org.eclipse.aether.RepositorySystemSession;
35  
36  // This class needs to stick around because it was exposed the the remote resources plugin started using it instead of
37  // getting the repositories from the project.
38  
39  /**
40   * ProjectUtils
41   */
42  @Deprecated
43  public final class ProjectUtils {
44  
45      private ProjectUtils() {}
46  
47      public static List<ArtifactRepository> buildArtifactRepositories(
48              List<Repository> repositories, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c)
49              throws InvalidRepositoryException {
50  
51          List<ArtifactRepository> remoteRepositories = new ArrayList<>();
52  
53          for (Repository r : repositories) {
54              remoteRepositories.add(buildArtifactRepository(r, artifactRepositoryFactory, c));
55          }
56  
57          return remoteRepositories;
58      }
59  
60      public static ArtifactRepository buildDeploymentArtifactRepository(
61              DeploymentRepository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c)
62              throws InvalidRepositoryException {
63          return buildArtifactRepository(repo, artifactRepositoryFactory, c);
64      }
65  
66      public static ArtifactRepository buildArtifactRepository(
67              Repository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c)
68              throws InvalidRepositoryException {
69          RepositorySystem repositorySystem = rs(c);
70          RepositorySystemSession session = rss(c);
71  
72          ArtifactRepository repository = repositorySystem.buildArtifactRepository(repo);
73  
74          if (session != null) {
75              repositorySystem.injectMirror(session, Arrays.asList(repository));
76              repositorySystem.injectProxy(session, Arrays.asList(repository));
77              repositorySystem.injectAuthentication(session, Arrays.asList(repository));
78          }
79  
80          return repository;
81      }
82  
83      private static RepositorySystem rs(PlexusContainer c) {
84          try {
85              return c.lookup(RepositorySystem.class);
86          } catch (ComponentLookupException e) {
87              throw new IllegalStateException(e);
88          }
89      }
90  
91      private static RepositorySystemSession rss(PlexusContainer c) {
92          try {
93              LegacySupport legacySupport = c.lookup(LegacySupport.class);
94  
95              return legacySupport.getRepositorySession();
96          } catch (ComponentLookupException e) {
97              throw new IllegalStateException(e);
98          }
99      }
100 }