Search in sources :

Example 1 with GradleProperties

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

the class GradleSyncTest method withIdeProxySettings.

// 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
@Test
public void withIdeProxySettings() throws IOException {
    System.getProperties().setProperty("show.do.not.copy.http.proxy.settings.to.gradle", "true");
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    File gradlePropertiesPath = new File(ideFrame.getProjectPath(), "gradle.properties");
    createIfNotExists(gradlePropertiesPath);
    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;
    ideFrame.requestProjectSync();
    // Expect IDE to ask user to copy proxy settings.
    ProxySettingsDialogFixture proxyDialog = ProxySettingsDialogFixture.find(guiTest.robot());
    proxyDialog.setDoNotShowThisDialog(true);
    proxyDialog.clickOk();
    ideFrame.waitForGradleProjectSyncToStart().waitForGradleProjectSyncToFinish();
    // Verify gradle.properties has proxy settings.
    assertAbout(file()).that(gradlePropertiesPath).isFile();
    Properties gradleProperties = getProperties(gradlePropertiesPath);
    assertEquals(host, gradleProperties.getProperty("systemProp.http.proxyHost"));
    assertEquals(String.valueOf(port), gradleProperties.getProperty("systemProp.http.proxyPort"));
    // Verifies that the "Do not show this dialog in the future" does not show up. If it does show up the test will timeout and fail.
    ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) Properties(java.util.Properties) PropertiesFiles.getProperties(com.android.tools.idea.gradle.util.PropertiesFiles.getProperties) GradleProperties(com.android.tools.idea.gradle.util.GradleProperties) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) Test(org.junit.Test)

Example 2 with GradleProperties

use of com.android.tools.idea.gradle.util.GradleProperties 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 3 with GradleProperties

use of com.android.tools.idea.gradle.util.GradleProperties 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 GradleProperties

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

the class GradleSyncTest method shouldClearJvmArgsOnSyncAndBuild.

// See https://code.google.com/p/android/issues/detail?id=169743
// JVM settings for Gradle should be cleared before any invocation to Gradle.
@Test
public void shouldClearJvmArgsOnSyncAndBuild() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    Project project = ideFrame.getProject();
    GradleProperties gradleProperties = new GradleProperties(project);
    gradleProperties.clear();
    gradleProperties.save();
    VirtualFile gradlePropertiesFile = findFileByIoFile(gradleProperties.getPath(), true);
    ideFrame.getEditor().open(gradlePropertiesFile, Tab.DEFAULT);
    String jvmArgs = "-Xmx2048m";
    ideFrame.setGradleJvmArgs(jvmArgs);
    ideFrame.requestProjectSync();
    // Copy JVM args to gradle.properties file.
    ideFrame.findMessageDialog(GRADLE_SETTINGS_DIALOG_TITLE).clickYes();
    // Verify JVM args were removed from IDE's Gradle settings.
    ideFrame.waitForGradleProjectSyncToFinish();
    assertNull(GradleSettings.getInstance(project).getGradleVmOptions());
    // Verify JVM args were copied to gradle.properties file
    refreshFiles();
    gradleProperties = new GradleProperties(project);
    assertEquals(jvmArgs, gradleProperties.getJvmArgs());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GradleProperties(com.android.tools.idea.gradle.util.GradleProperties) Test(org.junit.Test)

Aggregations

GradleProperties (com.android.tools.idea.gradle.util.GradleProperties)4 HttpConfigurable (com.intellij.util.net.HttpConfigurable)3 Test (org.junit.Test)3 ProxySettings (com.android.tools.idea.gradle.util.ProxySettings)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1 AndroidGradleNotification (com.android.tools.idea.gradle.project.AndroidGradleNotification)1 ProxySettingsDialog (com.android.tools.idea.gradle.project.ProxySettingsDialog)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 LocalProperties (com.android.tools.idea.gradle.util.LocalProperties)1 PropertiesFiles.getProperties (com.android.tools.idea.gradle.util.PropertiesFiles.getProperties)1 ProxySettingsDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ProxySettingsDialogFixture)1 Project (com.intellij.openapi.project.Project)1 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)1 File (java.io.File)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1