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
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
37
38
39
40
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 }