1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
36
37
38
39
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 }