Search in sources :

Example 1 with Settings

use of org.apache.maven.settings.Settings in project che by eclipse.

the class MavenServerImpl method getSettings.

private Settings getSettings(SettingsBuilder builder, MavenSettings settings, Properties systemProperties, Properties userProperties) throws RemoteException {
    SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    request.setGlobalSettingsFile(settings.getGlobalSettings());
    request.setUserSettingsFile(settings.getUserSettings());
    request.setSystemProperties(systemProperties);
    request.setUserProperties(userProperties);
    Settings result = new Settings();
    try {
        result = builder.build(request).getEffectiveSettings();
    } catch (SettingsBuildingException e) {
        MavenServerContext.getLogger().info(e);
    }
    result.setOffline(settings.isOffline());
    if (settings.getLocalRepository() != null) {
        result.setLocalRepository(settings.getLocalRepository().getPath());
    }
    if (result.getLocalRepository() == null) {
        result.setLocalRepository(new File(System.getProperty("user.home"), ".m2/repository").getPath());
    }
    return result;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) File(java.io.File) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 2 with Settings

use of org.apache.maven.settings.Settings in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method buildSettings.

private static Settings buildSettings(SettingsBuilder builder, MavenServerSettings settings, Properties systemProperties, Properties userProperties) throws RemoteException {
    SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
    settingsRequest.setGlobalSettingsFile(settings.getGlobalSettingsFile());
    settingsRequest.setUserSettingsFile(settings.getUserSettingsFile());
    settingsRequest.setSystemProperties(systemProperties);
    settingsRequest.setUserProperties(userProperties);
    Settings result = new Settings();
    try {
        result = builder.build(settingsRequest).getEffectiveSettings();
    } catch (SettingsBuildingException e) {
        Maven3ServerGlobals.getLogger().info(e);
    }
    result.setOffline(settings.isOffline());
    if (settings.getLocalRepository() != null) {
        result.setLocalRepository(settings.getLocalRepository().getPath());
    }
    if (result.getLocalRepository() == null) {
        result.setLocalRepository(new File(SystemProperties.getUserHome(), ".m2/repository").getPath());
    }
    return result;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) File(java.io.File) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 3 with Settings

use of org.apache.maven.settings.Settings 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();
        }
    }
}
Also used : HashMap(java.util.HashMap) AuthAsyncProxyServlet(org.apache.maven.plugin.javadoc.ProxyServer.AuthAsyncProxyServlet) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) URL(java.net.URL) Proxy(org.apache.maven.settings.Proxy) SocketTimeoutException(java.net.SocketTimeoutException) File(java.io.File) Settings(org.apache.maven.settings.Settings)

Example 4 with Settings

use of org.apache.maven.settings.Settings in project maven-plugins by apache.

the class JavadocUtilTest method testHideProxyPassword.

/**
     * Method to test the hiding proxy password.
     *
     * @throws Exception if any
     */
public void testHideProxyPassword() throws Exception {
    String cmdLine = "javadoc.exe " + "-J-Dhttp.proxySet=true " + "-J-Dhttp.proxyHost=127.0.0.1 " + "-J-Dhttp.proxyPort=80 " + "-J-Dhttp.nonProxyHosts=\"www.google.com|*.somewhere.com\" " + "-J-Dhttp.proxyUser=\"toto\" " + "-J-Dhttp.proxyPassword=\"toto\" " + "@options @packages";
    cmdLine = JavadocUtil.hideProxyPassword(cmdLine, null);
    assertFalse(cmdLine.contains("-J-Dhttp.proxyPassword=\"****\""));
    Settings settings = new Settings();
    Proxy proxy = new Proxy();
    proxy.setActive(true);
    proxy.setHost("127.0.0.1");
    proxy.setPort(80);
    proxy.setProtocol("http");
    proxy.setUsername("toto");
    proxy.setPassword("toto");
    proxy.setNonProxyHosts("www.google.com|*.somewhere.com");
    settings.addProxy(proxy);
    cmdLine = "javadoc.exe " + "-J-Dhttp.proxySet=true " + "-J-Dhttp.proxyHost=127.0.0.1 " + "-J-Dhttp.proxyPort=80 " + "-J-Dhttp.nonProxyHosts=\"www.google.com|*.somewhere.com\" " + "-J-Dhttp.proxyUser=\"toto\" " + "-J-Dhttp.proxyPassword=\"toto\" " + "@options @packages";
    cmdLine = JavadocUtil.hideProxyPassword(cmdLine, settings);
    assertTrue(cmdLine.contains("-J-Dhttp.proxyPassword=\"****\""));
    settings = new Settings();
    proxy = new Proxy();
    proxy.setActive(true);
    proxy.setHost("127.0.0.1");
    proxy.setPort(80);
    proxy.setProtocol("http");
    proxy.setUsername("toto");
    proxy.setNonProxyHosts("www.google.com|*.somewhere.com");
    settings.addProxy(proxy);
    cmdLine = "javadoc.exe " + "-J-Dhttp.proxySet=true " + "-J-Dhttp.proxyHost=127.0.0.1 " + "-J-Dhttp.proxyPort=80 " + "-J-Dhttp.nonProxyHosts=\"www.google.com|*.somewhere.com\" " + "-J-Dhttp.proxyUser=\"toto\" " + "-J-Dhttp.proxyPassword=\"toto\" " + "@options @packages";
    cmdLine = JavadocUtil.hideProxyPassword(cmdLine, null);
    assertFalse(cmdLine.contains("-J-Dhttp.proxyPassword=\"****\""));
}
Also used : Proxy(org.apache.maven.settings.Proxy) Settings(org.apache.maven.settings.Settings)

Example 5 with Settings

use of org.apache.maven.settings.Settings in project maven-plugins by apache.

the class InterpolationTest method testProfilesWithNoFile.

public void testProfilesWithNoFile() throws Exception {
    InvokerMojo invokerMojo = new InvokerMojo();
    setVariableValueToObject(invokerMojo, "profiles", Arrays.asList("zloug"));
    setVariableValueToObject(invokerMojo, "settings", new Settings());
    String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
    List<String> profiles = invokerMojo.getProfiles(new File(dirPath));
    assertTrue(profiles.contains("zloug"));
    assertEquals(1, profiles.size());
}
Also used : InvokerMojo(org.apache.maven.plugins.invoker.InvokerMojo) File(java.io.File) Settings(org.apache.maven.settings.Settings)

Aggregations

Settings (org.apache.maven.settings.Settings)26 File (java.io.File)14 Proxy (org.apache.maven.settings.Proxy)6 IOException (java.io.IOException)5 DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)5 Server (org.apache.maven.settings.Server)4 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)4 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 MavenSession (org.apache.maven.execution.MavenSession)3 AbstractMojo (org.apache.maven.plugin.AbstractMojo)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 SiteMavenProjectStub (org.apache.maven.plugins.site.stubs.SiteMavenProjectStub)3 MavenProject (org.apache.maven.project.MavenProject)3 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)3 StringWriter (java.io.StringWriter)2 Properties (java.util.Properties)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1