1 package org.apache.maven.artifact.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Arrays;
23 import java.util.List;
24
25 import org.apache.maven.artifact.UnknownRepositoryLayoutException;
26 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
27 import org.apache.maven.execution.MavenExecutionRequest;
28 import org.apache.maven.execution.MavenSession;
29 import org.apache.maven.plugin.LegacySupport;
30 import org.apache.maven.repository.RepositorySystem;
31 import org.codehaus.plexus.component.annotations.Component;
32 import org.codehaus.plexus.component.annotations.Requirement;
33
34
35
36
37 @Component( role = ArtifactRepositoryFactory.class )
38 public class DefaultArtifactRepositoryFactory
39 implements ArtifactRepositoryFactory
40 {
41
42 @Requirement
43 private org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory factory;
44
45 @Requirement
46 private LegacySupport legacySupport;
47
48 @Requirement
49 private RepositorySystem repositorySystem;
50
51 public ArtifactRepositoryLayout getLayout( String layoutId )
52 throws UnknownRepositoryLayoutException
53 {
54 return factory.getLayout( layoutId );
55 }
56
57 public ArtifactRepository createDeploymentArtifactRepository( String id, String url, String layoutId,
58 boolean uniqueVersion )
59 throws UnknownRepositoryLayoutException
60 {
61 return injectSession( factory.createDeploymentArtifactRepository( id, url, layoutId, uniqueVersion ), false );
62 }
63
64 public ArtifactRepository createDeploymentArtifactRepository( String id, String url,
65 ArtifactRepositoryLayout repositoryLayout,
66 boolean uniqueVersion )
67 {
68 return injectSession( factory.createDeploymentArtifactRepository( id, url, repositoryLayout, uniqueVersion ),
69 false );
70 }
71
72 public ArtifactRepository createArtifactRepository( String id, String url, String layoutId,
73 ArtifactRepositoryPolicy snapshots,
74 ArtifactRepositoryPolicy releases )
75 throws UnknownRepositoryLayoutException
76 {
77 return injectSession( factory.createArtifactRepository( layoutId, url, layoutId, snapshots, releases ), true );
78 }
79
80 public ArtifactRepository createArtifactRepository( String id, String url,
81 ArtifactRepositoryLayout repositoryLayout,
82 ArtifactRepositoryPolicy snapshots,
83 ArtifactRepositoryPolicy releases )
84 {
85 return injectSession( factory.createArtifactRepository( id, url, repositoryLayout, snapshots, releases ), true );
86 }
87
88 public void setGlobalUpdatePolicy( String updatePolicy )
89 {
90 factory.setGlobalUpdatePolicy( updatePolicy );
91 }
92
93 public void setGlobalChecksumPolicy( String checksumPolicy )
94 {
95 factory.setGlobalChecksumPolicy( checksumPolicy );
96 }
97
98 private ArtifactRepository injectSession( ArtifactRepository repository, boolean mirrors )
99 {
100 MavenSession session = legacySupport.getSession();
101
102 if ( session != null && repository != null && !isLocalRepository( repository ) )
103 {
104 MavenExecutionRequest request = session.getRequest();
105 if ( request != null )
106 {
107 List<ArtifactRepository> repositories = Arrays.asList( repository );
108
109 if ( mirrors )
110 {
111 repositorySystem.injectMirror( repositories, request.getMirrors() );
112 }
113
114 repositorySystem.injectProxy( repositories, request.getProxies() );
115
116 repositorySystem.injectAuthentication( repositories, request.getServers() );
117 }
118 }
119
120 return repository;
121 }
122
123 private boolean isLocalRepository( ArtifactRepository repository )
124 {
125
126 return "local".equals( repository.getId() );
127 }
128
129 }