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.plugin.LegacySupport;
28 import org.apache.maven.repository.RepositorySystem;
29 import org.codehaus.plexus.component.annotations.Component;
30 import org.codehaus.plexus.component.annotations.Requirement;
31 import org.eclipse.aether.RepositorySystemSession;
32
33
34
35
36 @Component( role = ArtifactRepositoryFactory.class )
37 public class DefaultArtifactRepositoryFactory
38 implements ArtifactRepositoryFactory
39 {
40
41 @Requirement
42 private org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory factory;
43
44 @Requirement
45 private LegacySupport legacySupport;
46
47 @Requirement
48 private RepositorySystem repositorySystem;
49
50 public ArtifactRepositoryLayout getLayout( String layoutId )
51 throws UnknownRepositoryLayoutException
52 {
53 return factory.getLayout( layoutId );
54 }
55
56 public ArtifactRepository createDeploymentArtifactRepository( String id, String url, String layoutId,
57 boolean uniqueVersion )
58 throws UnknownRepositoryLayoutException
59 {
60 return injectSession( factory.createDeploymentArtifactRepository( id, url, layoutId, uniqueVersion ), false );
61 }
62
63 public ArtifactRepository createDeploymentArtifactRepository( String id, String url,
64 ArtifactRepositoryLayout repositoryLayout,
65 boolean uniqueVersion )
66 {
67 return injectSession( factory.createDeploymentArtifactRepository( id, url, repositoryLayout, uniqueVersion ),
68 false );
69 }
70
71 public ArtifactRepository createArtifactRepository( String id, String url, String layoutId,
72 ArtifactRepositoryPolicy snapshots,
73 ArtifactRepositoryPolicy releases )
74 throws UnknownRepositoryLayoutException
75 {
76 return injectSession( factory.createArtifactRepository( id, url, layoutId, snapshots, releases ), true );
77 }
78
79 public ArtifactRepository createArtifactRepository( String id, String url,
80 ArtifactRepositoryLayout repositoryLayout,
81 ArtifactRepositoryPolicy snapshots,
82 ArtifactRepositoryPolicy releases )
83 {
84 return injectSession( factory.createArtifactRepository( id, url, repositoryLayout, snapshots, releases ),
85 true );
86
87 }
88
89 public void setGlobalUpdatePolicy( String updatePolicy )
90 {
91 factory.setGlobalUpdatePolicy( updatePolicy );
92 }
93
94 public void setGlobalChecksumPolicy( String checksumPolicy )
95 {
96 factory.setGlobalChecksumPolicy( checksumPolicy );
97 }
98
99 private ArtifactRepository injectSession( ArtifactRepository repository, boolean mirrors )
100 {
101 RepositorySystemSession session = legacySupport.getRepositorySession();
102
103 if ( session != null && repository != null && !isLocalRepository( repository ) )
104 {
105 List<ArtifactRepository> repositories = Arrays.asList( repository );
106
107 if ( mirrors )
108 {
109 repositorySystem.injectMirror( session, repositories );
110 }
111
112 repositorySystem.injectProxy( session, repositories );
113
114 repositorySystem.injectAuthentication( session, repositories );
115 }
116
117 return repository;
118 }
119
120 private boolean isLocalRepository( ArtifactRepository repository )
121 {
122
123 return "local".equals( repository.getId() );
124 }
125
126 }