Search in sources :

Example 1 with ProxySettings

use of com.android.tools.idea.gradle.util.ProxySettings in project android by JetBrains.

the class GradlePreSyncTest method testAddProxyConfigureToPropertyFile.

// Verifies that the IDE, during sync, asks the user to copy IDE proxy settings to gradle.properties, if applicable.
// See https://code.google.com/p/android/issues/detail?id=65325
// Similar to {@link com.android.tools.idea.gradle.util.GradlePropertiesTest#testSetProxySettings} test, but also tests the UI
// element that is involved.
@Test
public void testAddProxyConfigureToPropertyFile() throws IOException {
    guiTest.importSimpleApplication();
    String host = "myproxy.test.com";
    int port = 443;
    HttpConfigurable ideSettings = HttpConfigurable.getInstance();
    ideSettings.USE_HTTP_PROXY = true;
    ideSettings.PROXY_HOST = host;
    ideSettings.PROXY_PORT = port;
    ideSettings.PROXY_AUTHENTICATION = true;
    ideSettings.setProxyLogin("test");
    ideSettings.setPlainProxyPassword("testPass");
    ProxySettings ideProxySettings = new ProxySettings(ideSettings);
    GradleProperties properties = new GradleProperties(guiTest.ideFrame().getProject());
    assertNotEquals(ideProxySettings, properties.getHttpProxySettings());
    guiTest.ideFrame().requestProjectSync();
    ProxySettingsDialogFixture proxySettingsDialog = ProxySettingsDialogFixture.find(guiTest.robot());
    proxySettingsDialog.enableHttpsProxy();
    proxySettingsDialog.clickOk();
    properties = new GradleProperties(guiTest.ideFrame().getProject());
    assertEquals(ideProxySettings, properties.getHttpProxySettings());
    ideProxySettings.setProxyType(ProxySettings.HTTPS_PROXY_TYPE);
    assertEquals(ideProxySettings, properties.getHttpsProxySettings());
    guiTest.ideFrame().waitForGradleProjectSyncToFinish();
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable) ProxySettingsDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.ProxySettingsDialogFixture) GradleProperties(com.android.tools.idea.gradle.util.GradleProperties) ProxySettings(com.android.tools.idea.gradle.util.ProxySettings) Test(org.junit.Test)

Example 2 with ProxySettings

use of com.android.tools.idea.gradle.util.ProxySettings in project android by JetBrains.

the class ProxySettingsDialog method applyProxySettings.

public void applyProxySettings(@NotNull Properties properties) {
    ProxySettings httpProxySetting = createProxySettingsFromUI(HTTP_PROXY_TYPE, myHttpProxyHostTextField, myHttpProxyPortTextField, myHttpProxyExceptions, myHttpProxyAuthCheckBox, myHttpProxyLoginTextField, myHttpProxyPasswordTextField);
    httpProxySetting.applyProxySettings(properties);
    if (myEnableHttpsProxyCheckBox.isSelected()) {
        ProxySettings httpsProxySettings = createProxySettingsFromUI(HTTPS_PROXY_TYPE, myHttpsProxyHostTextField, myHttpsProxyPortTextField, myHttpsProxyExceptions, myHttpsProxyAuthCheckBox, myHttpsProxyLoginTextField, myHttpsProxyPasswordTextField);
        httpsProxySettings.applyProxySettings(properties);
    }
}
Also used : ProxySettings(com.android.tools.idea.gradle.util.ProxySettings)

Example 3 with ProxySettings

use of com.android.tools.idea.gradle.util.ProxySettings in project android by JetBrains.

the class HttpProxySettingsCleanUpTask method doCleanUp.

@Override
void doCleanUp(@NotNull Project project) {
    HttpConfigurable ideHttpProxySettings = HttpConfigurable.getInstance();
    if (!ideHttpProxySettings.USE_HTTP_PROXY || isEmpty(ideHttpProxySettings.PROXY_HOST)) {
        return;
    }
    GradleProperties properties;
    try {
        properties = new GradleProperties(project);
    } catch (IOException e) {
        getLogger().info("Failed to read gradle.properties file", e);
        // Let sync continue, even though it may fail.
        return;
    }
    ProxySettings gradleProxySettings = properties.getHttpProxySettings();
    ProxySettings ideProxySettings = new ProxySettings(ideHttpProxySettings);
    if (!ideProxySettings.equals(gradleProxySettings)) {
        ProxySettingsDialog dialog = new ProxySettingsDialog(project, ideProxySettings);
        if (dialog.showAndGet()) {
            dialog.applyProxySettings(properties.getProperties());
            try {
                properties.save();
            } catch (IOException e) {
                Throwable root = getRootCause(e);
                String cause = root.getMessage();
                String errMsg = "Failed to save HTTP proxy settings to gradle.properties file.";
                if (isNotEmpty(cause)) {
                    if (!cause.endsWith(".")) {
                        cause += ".";
                    }
                    errMsg += String.format("\nCause: %1$s", cause);
                }
                AndroidGradleNotification notification = AndroidGradleNotification.getInstance(project);
                notification.showBalloon("Proxy Settings", errMsg, ERROR);
                getLogger().info("Failed to save changes to gradle.properties file", root);
            }
        }
    }
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable) GradleProperties(com.android.tools.idea.gradle.util.GradleProperties) ProxySettings(com.android.tools.idea.gradle.util.ProxySettings) AndroidGradleNotification(com.android.tools.idea.gradle.project.AndroidGradleNotification) IOException(java.io.IOException) ProxySettingsDialog(com.android.tools.idea.gradle.project.ProxySettingsDialog)

Example 4 with ProxySettings

use of com.android.tools.idea.gradle.util.ProxySettings in project android by JetBrains.

the class ProxySettingsDialog method createProxySettingsFromUI.

@NotNull
private static ProxySettings createProxySettingsFromUI(@NotNull String proxyType, @NotNull JTextField proxyHostTextField, @NotNull PortField proxyPortTextField, @NotNull RawCommandLineEditor proxyExceptions, @NotNull JCheckBox proxyAuthCheckBox, @NotNull JTextField proxyLoginTextField, @NotNull JPasswordField proxyPasswordTextField) {
    ProxySettings proxySettings = new ProxySettings(proxyType);
    proxySettings.setHost(proxyHostTextField.getText());
    proxySettings.setPort(proxyPortTextField.getNumber());
    proxySettings.setExceptions(proxyExceptions.getText());
    if (proxyAuthCheckBox.isSelected()) {
        proxySettings.setUser(proxyLoginTextField.getText());
        proxySettings.setPassword(new String(proxyPasswordTextField.getPassword()));
    }
    return proxySettings;
}
Also used : ProxySettings(com.android.tools.idea.gradle.util.ProxySettings) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProxySettings (com.android.tools.idea.gradle.util.ProxySettings)4 GradleProperties (com.android.tools.idea.gradle.util.GradleProperties)2 HttpConfigurable (com.intellij.util.net.HttpConfigurable)2 AndroidGradleNotification (com.android.tools.idea.gradle.project.AndroidGradleNotification)1 ProxySettingsDialog (com.android.tools.idea.gradle.project.ProxySettingsDialog)1 ProxySettingsDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ProxySettingsDialogFixture)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.Test)1