Search in sources :

Example 1 with ProxySettingsDialog

use of com.android.tools.idea.gradle.project.ProxySettingsDialog 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)

Aggregations

AndroidGradleNotification (com.android.tools.idea.gradle.project.AndroidGradleNotification)1 ProxySettingsDialog (com.android.tools.idea.gradle.project.ProxySettingsDialog)1 GradleProperties (com.android.tools.idea.gradle.util.GradleProperties)1 ProxySettings (com.android.tools.idea.gradle.util.ProxySettings)1 HttpConfigurable (com.intellij.util.net.HttpConfigurable)1 IOException (java.io.IOException)1