use of org.apache.maven.settings.Proxy in project frontend-maven-plugin by eirslett.
the class MojoUtils method getProxyConfig.
static ProxyConfig getProxyConfig(MavenSession mavenSession, SettingsDecrypter decrypter) {
if (mavenSession == null || mavenSession.getSettings() == null || mavenSession.getSettings().getProxies() == null || mavenSession.getSettings().getProxies().isEmpty()) {
return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList());
} else {
final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies();
final List<ProxyConfig.Proxy> proxies = new ArrayList<ProxyConfig.Proxy>(mavenProxies.size());
for (Proxy mavenProxy : mavenProxies) {
if (mavenProxy.isActive()) {
mavenProxy = decryptProxy(mavenProxy, decrypter);
proxies.add(new ProxyConfig.Proxy(mavenProxy.getId(), mavenProxy.getProtocol(), mavenProxy.getHost(), mavenProxy.getPort(), mavenProxy.getUsername(), mavenProxy.getPassword(), mavenProxy.getNonProxyHosts()));
}
}
LOGGER.info("Found proxies: {}", proxies);
return new ProxyConfig(proxies);
}
}
use of org.apache.maven.settings.Proxy in project grails-maven by grails.
the class AbstractGrailsMojo method configureMavenProxy.
private void configureMavenProxy() {
if (settings != null) {
Proxy activeProxy = settings.getActiveProxy();
if (activeProxy != null) {
String host = activeProxy.getHost();
int port = activeProxy.getPort();
String noProxy = activeProxy.getNonProxyHosts();
String username = activeProxy.getUsername();
String password = activeProxy.getPassword();
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", String.valueOf(port));
if (noProxy != null) {
System.setProperty("http.nonProxyHosts", noProxy);
}
if (username != null) {
System.setProperty("http.proxyUser", username);
}
if (password != null) {
System.setProperty("http.proxyPassword", password);
}
}
}
}
use of org.apache.maven.settings.Proxy in project karaf by apache.
the class MojoSupport method configureProxyToInlineRepo.
private org.apache.maven.repository.Proxy configureProxyToInlineRepo() {
if (mavenSession != null && mavenSession.getSettings() != null) {
Proxy proxy = mavenSession.getSettings().getActiveProxy();
org.apache.maven.repository.Proxy mavenProxy = new org.apache.maven.repository.Proxy();
if (proxy != null) {
mavenProxy.setProtocol(proxy.getProtocol());
mavenProxy.setHost(proxy.getHost());
mavenProxy.setPort(proxy.getPort());
mavenProxy.setNonProxyHosts(proxy.getNonProxyHosts());
mavenProxy.setUserName(proxy.getUsername());
mavenProxy.setPassword(proxy.getPassword());
return mavenProxy;
} else {
return null;
}
} else {
return null;
}
}
use of org.apache.maven.settings.Proxy in project maven-plugins by apache.
the class JavadocUtil method hideProxyPassword.
/**
* For security reasons, if an active proxy is defined and needs an authentication by
* username/password, hide the proxy password in the command line.
*
* @param cmdLine a command line, not null
* @param settings the user settings
* @return the cmdline with '*' for the http.proxyPassword JVM property
*/
protected static String hideProxyPassword(String cmdLine, Settings settings) {
if (cmdLine == null) {
throw new IllegalArgumentException("cmdLine could not be null");
}
if (settings == null) {
return cmdLine;
}
Proxy activeProxy = settings.getActiveProxy();
if (activeProxy != null && StringUtils.isNotEmpty(activeProxy.getHost()) && StringUtils.isNotEmpty(activeProxy.getUsername()) && StringUtils.isNotEmpty(activeProxy.getPassword())) {
String pass = "-J-Dhttp.proxyPassword=\"" + activeProxy.getPassword() + "\"";
String hidepass = "-J-Dhttp.proxyPassword=\"" + StringUtils.repeat("*", activeProxy.getPassword().length()) + "\"";
return StringUtils.replace(cmdLine, pass, hidepass);
}
return cmdLine;
}
use of org.apache.maven.settings.Proxy in project maven-plugins by apache.
the class JavadocUtilTest method testIsValidPackageList.
/**
* Method to test isValidPackageList()
*
* @throws Exception if any
*/
public void testIsValidPackageList() throws Exception {
Settings settings = null;
Proxy proxy;
URL url = null;
URL wrongUrl;
try {
JavadocUtil.isValidPackageList(url, settings, false);
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
url = new File(getBasedir(), "/pom.xml").toURL();
assertTrue(JavadocUtil.isValidPackageList(url, settings, false));
try {
assertFalse(JavadocUtil.isValidPackageList(url, settings, true));
} catch (IOException e) {
assertTrue(true);
}
url = this.getClass().getResource("/JavadocUtilTest-package-list.txt").toURI().toURL();
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
url = new URL("http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list");
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
wrongUrl = new URL("http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list2");
try {
JavadocUtil.isValidPackageList(wrongUrl, settings, false);
fail();
} catch (IOException e) {
assertTrue(true);
}
// real proxy
ProxyServer proxyServer = null;
AuthAsyncProxyServlet proxyServlet;
try {
proxyServlet = new AuthAsyncProxyServlet();
proxyServer = new ProxyServer(proxyServlet);
proxyServer.start();
settings = new Settings();
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
try {
JavadocUtil.isValidPackageList(wrongUrl, settings, false);
fail();
} catch (IOException e) {
assertTrue(true);
}
} finally {
if (proxyServer != null) {
proxyServer.stop();
}
}
Map<String, String> authentications = new HashMap<String, String>();
authentications.put("foo", "bar");
// wrong auth
try {
proxyServlet = new AuthAsyncProxyServlet(authentications);
proxyServer = new ProxyServer(proxyServlet);
proxyServer.start();
settings = new Settings();
proxy = new Proxy();
proxy.setActive(true);
proxy.setHost(proxyServer.getHostName());
proxy.setPort(proxyServer.getPort());
proxy.setProtocol("http");
settings.addProxy(proxy);
JavadocUtil.isValidPackageList(url, settings, false);
fail();
} catch (FileNotFoundException e) {
assertTrue(true);
} finally {
if (proxyServer != null) {
proxyServer.stop();
}
}
// auth proxy
try {
proxyServlet = new AuthAsyncProxyServlet(authentications);
proxyServer = new ProxyServer(proxyServlet);
proxyServer.start();
settings = new Settings();
proxy = new Proxy();
proxy.setActive(true);
proxy.setHost(proxyServer.getHostName());
proxy.setPort(proxyServer.getPort());
proxy.setProtocol("http");
proxy.setUsername("foo");
proxy.setPassword("bar");
settings.addProxy(proxy);
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
try {
JavadocUtil.isValidPackageList(wrongUrl, settings, false);
fail();
} catch (IOException e) {
assertTrue(true);
}
} finally {
if (proxyServer != null) {
proxyServer.stop();
}
}
// timeout
try {
// more than 2000, see fetchURL
proxyServlet = new AuthAsyncProxyServlet(authentications, 3000);
proxyServer = new ProxyServer(proxyServlet);
proxyServer.start();
settings = new Settings();
proxy = new Proxy();
proxy.setActive(true);
proxy.setHost(proxyServer.getHostName());
proxy.setPort(proxyServer.getPort());
proxy.setProtocol("http");
proxy.setUsername("foo");
proxy.setPassword("bar");
settings.addProxy(proxy);
JavadocUtil.isValidPackageList(url, settings, true);
fail();
} catch (SocketTimeoutException e) {
assertTrue(true);
} finally {
if (proxyServer != null) {
proxyServer.stop();
}
}
// nonProxyHosts
try {
proxyServlet = new AuthAsyncProxyServlet(authentications);
proxyServer = new ProxyServer(proxyServlet);
proxyServer.start();
settings = new Settings();
proxy = new Proxy();
proxy.setActive(true);
proxy.setHost(proxyServer.getHostName());
proxy.setPort(proxyServer.getPort());
proxy.setProtocol("http");
proxy.setUsername("foo");
proxy.setPassword("bar");
proxy.setNonProxyHosts("maven.apache.org");
settings.addProxy(proxy);
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
} finally {
if (proxyServer != null) {
proxyServer.stop();
}
}
}
Aggregations