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.sonatype.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 ), true );
85 }
86
87 public void setGlobalUpdatePolicy( String updatePolicy )
88 {
89 factory.setGlobalUpdatePolicy( updatePolicy );
90 }
91
92 public void setGlobalChecksumPolicy( String checksumPolicy )
93 {
94 factory.setGlobalChecksumPolicy( checksumPolicy );
95 }
96
97 private ArtifactRepository injectSession( ArtifactRepository repository, boolean mirrors )
98 {
99 RepositorySystemSession session = legacySupport.getRepositorySession();
100
101 if ( session != null && repository != null && !isLocalRepository( repository ) )
102 {
103 List<ArtifactRepository> repositories = Arrays.asList( repository );
104
105 if ( mirrors )
106 {
107 repositorySystem.injectMirror( session, repositories );
108 }
109
110 repositorySystem.injectProxy( session, repositories );
111
112 repositorySystem.injectAuthentication( session, repositories );
113 }
114
115 return repository;
116 }
117
118 private boolean isLocalRepository( ArtifactRepository repository )
119 {
120
121 return "local".equals( repository.getId() );
122 }
123
124 }