public void
deploy(Artifact artifact) throws DeploymentException
{
RepositorySystemSession
session = newSession();
DeployRequest r = new DeployRequest();
r.addArtifact(artifact);
r.setRepository(remoteRepository);
system.deploy(session, r);
log.info("deployed
'{}'
to {}",
artifact, remoteRepository.getUrl());
}
private
DefaultRepositorySystemSession newSession() {
MavenRepositorySystemSession
session = new
MavenRepositorySystemSession();
session.setProxySelector(new MyProxySelector(proxyService));
LocalRepository
localRepo = new
LocalRepository(location);
session.setLocalRepositoryManager(system.newLocalRepositoryManager(localRepo));
return session;
}
public class
MyProxySelector implements ProxySelector {
private final
IProxyService proxyService;
public
MyProxySelector(IProxyService proxyService) {
this.proxyService = proxyService;
}
@Override
public Proxy
getProxy(RemoteRepository remote) {
if (proxyService != null
&& proxyService.isProxiesEnabled())
{
URI uri = URI.create(remote.getUrl());
for
(IProxyData data : proxyService.select(uri)) {
String host
= data.getHost();
if
(host != null) {
String
type = "http";
int port
= data.getPort();
Authentication
auth = new
Authentication(data.getUserId(), data.getPassword());
return new
Proxy(type, host, port, auth);
}
}
}
return null; //
Proxies disabled or no matching proxy found.
}
}