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 @Deprecated
41 public final class ProjectUtils
42 {
43
44 private ProjectUtils()
45 {
46 }
47
48 public static List<ArtifactRepository> buildArtifactRepositories(
49 List<Repository> repositories, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c )
50 throws InvalidRepositoryException
51 {
52
53 List<ArtifactRepository> remoteRepositories = new ArrayList<>();
54
55 for ( Repository r : repositories )
56 {
57 remoteRepositories.add( buildArtifactRepository( r, artifactRepositoryFactory, c ) );
58 }
59
60 return remoteRepositories;
61 }
62
63 public static ArtifactRepository buildDeploymentArtifactRepository(
64 DeploymentRepository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c )
65 throws InvalidRepositoryException
66 {
67 return buildArtifactRepository( repo, artifactRepositoryFactory, c );
68 }
69
70 public static ArtifactRepository buildArtifactRepository(
71 Repository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c )
72 throws InvalidRepositoryException
73 {
74 RepositorySystem repositorySystem = rs( c );
75 RepositorySystemSession session = rss( c );
76
77 ArtifactRepository repository = repositorySystem.buildArtifactRepository( repo );
78
79 if ( session != null )
80 {
81 repositorySystem.injectMirror( session, Arrays.asList( repository ) );
82 repositorySystem.injectProxy( session, Arrays.asList( repository ) );
83 repositorySystem.injectAuthentication( session, Arrays.asList( repository ) );
84 }
85
86 return repository;
87 }
88
89 private static RepositorySystem rs( PlexusContainer c )
90 {
91 try
92 {
93 return c.lookup( RepositorySystem.class );
94 }
95 catch ( ComponentLookupException e )
96 {
97 throw new IllegalStateException( e );
98 }
99 }
100
101 private static RepositorySystemSession rss( PlexusContainer c )
102 {
103 try
104 {
105 LegacySupport legacySupport = c.lookup( LegacySupport.class );
106
107 return legacySupport.getRepositorySession();
108 }
109 catch ( ComponentLookupException e )
110 {
111 throw new IllegalStateException( e );
112 }
113 }
114
115 }