1 package org.apache.maven.project;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25
26 import org.apache.maven.artifact.InvalidRepositoryException;
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
29 import org.apache.maven.model.DeploymentRepository;
30 import org.apache.maven.model.Repository;
31 import org.apache.maven.plugin.LegacySupport;
32 import org.apache.maven.repository.RepositorySystem;
33 import org.codehaus.plexus.PlexusContainer;
34 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
35 import org.eclipse.aether.RepositorySystemSession;
36
37
38
39
40
41
42
43 @Deprecated
44 public final class ProjectUtils
45 {
46
47 private ProjectUtils()
48 {
49 }
50
51 public static List<ArtifactRepository> buildArtifactRepositories(
52 List<Repository> repositories, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c )
53 throws InvalidRepositoryException
54 {
55
56 List<ArtifactRepository> remoteRepositories = new ArrayList<>();
57
58 for ( Repository r : repositories )
59 {
60 remoteRepositories.add( buildArtifactRepository( r, artifactRepositoryFactory, c ) );
61 }
62
63 return remoteRepositories;
64 }
65
66 public static ArtifactRepository buildDeploymentArtifactRepository(
67 DeploymentRepository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c )
68 throws InvalidRepositoryException
69 {
70 return buildArtifactRepository( repo, artifactRepositoryFactory, c );
71 }
72
73 public static ArtifactRepository buildArtifactRepository(
74 Repository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c )
75 throws InvalidRepositoryException
76 {
77 RepositorySystem repositorySystem = rs( c );
78 RepositorySystemSession session = rss( c );
79
80 ArtifactRepository repository = repositorySystem.buildArtifactRepository( repo );
81
82 if ( session != null )
83 {
84 repositorySystem.injectMirror( session, Arrays.asList( repository ) );
85 repositorySystem.injectProxy( session, Arrays.asList( repository ) );
86 repositorySystem.injectAuthentication( session, Arrays.asList( repository ) );
87 }
88
89 return repository;
90 }
91
92 private static RepositorySystem rs( PlexusContainer c )
93 {
94 try
95 {
96 return c.lookup( RepositorySystem.class );
97 }
98 catch ( ComponentLookupException e )
99 {
100 throw new IllegalStateException( e );
101 }
102 }
103
104 private static RepositorySystemSession rss( PlexusContainer c )
105 {
106 try
107 {
108 LegacySupport legacySupport = c.lookup( LegacySupport.class );
109
110 return legacySupport.getRepositorySession();
111 }
112 catch ( ComponentLookupException e )
113 {
114 throw new IllegalStateException( e );
115 }
116 }
117
118 }