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