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();
}
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);
}
}
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);
}
}
}
}
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;
}
Aggregations