1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.artifact.manager;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.List;
26
27 import org.apache.maven.artifact.Artifact;
28 import org.apache.maven.artifact.repository.ArtifactRepository;
29 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
30 import org.apache.maven.execution.MavenExecutionRequest;
31 import org.apache.maven.execution.MavenSession;
32 import org.apache.maven.plugin.LegacySupport;
33 import org.apache.maven.repository.MirrorSelector;
34 import org.apache.maven.settings.Mirror;
35 import org.apache.maven.settings.Proxy;
36 import org.apache.maven.settings.Server;
37 import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
38 import org.apache.maven.settings.crypto.SettingsDecrypter;
39 import org.apache.maven.settings.crypto.SettingsDecryptionResult;
40 import org.apache.maven.wagon.ResourceDoesNotExistException;
41 import org.apache.maven.wagon.TransferFailedException;
42 import org.apache.maven.wagon.authentication.AuthenticationInfo;
43 import org.apache.maven.wagon.proxy.ProxyInfo;
44 import org.codehaus.plexus.logging.Logger;
45
46
47
48
49 @Named
50 @Singleton
51 public class DefaultWagonManager extends org.apache.maven.repository.legacy.DefaultWagonManager
52 implements WagonManager {
53
54
55 @Inject
56 private Logger log;
57
58 @Inject
59 private LegacySupport legacySupport;
60
61 @Inject
62 private SettingsDecrypter settingsDecrypter;
63
64 @Inject
65 private MirrorSelector mirrorSelector;
66
67 @Inject
68 private ArtifactRepositoryFactory artifactRepositoryFactory;
69
70 public AuthenticationInfo getAuthenticationInfo(String id) {
71 MavenSession session = legacySupport.getSession();
72
73 if (session != null && id != null) {
74 MavenExecutionRequest request = session.getRequest();
75
76 if (request != null) {
77 List<Server> servers = request.getServers();
78
79 if (servers != null) {
80 for (Server server : servers) {
81 if (id.equalsIgnoreCase(server.getId())) {
82 SettingsDecryptionResult result =
83 settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(server));
84 server = result.getServer();
85
86 AuthenticationInfo authInfo = new AuthenticationInfo();
87 authInfo.setUserName(server.getUsername());
88 authInfo.setPassword(server.getPassword());
89 authInfo.setPrivateKey(server.getPrivateKey());
90 authInfo.setPassphrase(server.getPassphrase());
91
92 return authInfo;
93 }
94 }
95 }
96 }
97 }
98
99
100 return new AuthenticationInfo();
101 }
102
103 public ProxyInfo getProxy(String protocol) {
104 MavenSession session = legacySupport.getSession();
105
106 if (session != null && protocol != null) {
107 MavenExecutionRequest request = session.getRequest();
108
109 if (request != null) {
110 List<Proxy> proxies = request.getProxies();
111
112 if (proxies != null) {
113 for (Proxy proxy : proxies) {
114 if (proxy.isActive() && protocol.equalsIgnoreCase(proxy.getProtocol())) {
115 SettingsDecryptionResult result =
116 settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
117 proxy = result.getProxy();
118
119 ProxyInfo proxyInfo = new ProxyInfo();
120 proxyInfo.setHost(proxy.getHost());
121 proxyInfo.setType(proxy.getProtocol());
122 proxyInfo.setPort(proxy.getPort());
123 proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
124 proxyInfo.setUserName(proxy.getUsername());
125 proxyInfo.setPassword(proxy.getPassword());
126
127 return proxyInfo;
128 }
129 }
130 }
131 }
132 }
133
134 return null;
135 }
136
137 public void getArtifact(Artifact artifact, ArtifactRepository repository)
138 throws TransferFailedException, ResourceDoesNotExistException {
139 getArtifact(artifact, repository, null, false);
140 }
141
142 public void getArtifact(Artifact artifact, List<ArtifactRepository> remoteRepositories)
143 throws TransferFailedException, ResourceDoesNotExistException {
144 getArtifact(artifact, remoteRepositories, null, false);
145 }
146
147 @Deprecated
148 public ArtifactRepository getMirrorRepository(ArtifactRepository repository) {
149
150 Mirror mirror = mirrorSelector.getMirror(
151 repository, legacySupport.getSession().getSettings().getMirrors());
152
153 if (mirror != null) {
154 String id = mirror.getId();
155 if (id == null) {
156
157 id = repository.getId();
158 }
159
160 log.debug("Using mirror: " + mirror.getUrl() + " (id: " + id + ")");
161
162 repository = artifactRepositoryFactory.createArtifactRepository(
163 id, mirror.getUrl(), repository.getLayout(), repository.getSnapshots(), repository.getReleases());
164 }
165 return repository;
166 }
167 }