Search in sources :

Example 1 with UpdateResult

use of com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult in project android by JetBrains.

the class AndroidPluginVersionUpdaterIntegrationTest method testUpdatePluginVersion.

public void testUpdatePluginVersion() throws Throwable {
    loadProject(SYNC_MULTIPROJECT);
    setAndroidPluginVersion("1.0.0");
    UpdateResult result = myVersionUpdater.updatePluginVersion(GradleVersion.parse("20.0.0"), null);
    assertTrue(result.isPluginVersionUpdated());
    assertFalse(result.isGradleVersionUpdated());
    verifyAndroidPluginVersion("20.0.0");
}
Also used : UpdateResult(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult)

Example 2 with UpdateResult

use of com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult in project android by JetBrains.

the class AndroidPluginVersionUpdaterIntegrationTest method testUpdateExperimentalPluginVersion.

public void testUpdateExperimentalPluginVersion() throws Throwable {
    loadProject(EXPERIMENTAL_PLUGIN);
    setAndroidPluginVersion("1.0.0");
    UpdateResult result = myVersionUpdater.updatePluginVersion(GradleVersion.parse("20.0.0"), null);
    assertTrue(result.isPluginVersionUpdated());
    assertFalse(result.isGradleVersionUpdated());
    verifyAndroidPluginVersion("20.0.0");
}
Also used : UpdateResult(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult)

Example 3 with UpdateResult

use of com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult in project android by JetBrains.

the class AndroidPluginVersionUpdaterIntegrationTest method testUpdatePluginVersionWhenPluginHasAlreadyUpdatedVersion.

public void testUpdatePluginVersionWhenPluginHasAlreadyUpdatedVersion() throws Throwable {
    loadProject(SYNC_MULTIPROJECT);
    setAndroidPluginVersion("20.0.0");
    UpdateResult result = myVersionUpdater.updatePluginVersion(GradleVersion.parse("20.0.0"), null);
    assertFalse(result.isPluginVersionUpdated());
    assertFalse(result.isGradleVersionUpdated());
    verifyAndroidPluginVersion("20.0.0");
}
Also used : UpdateResult(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult)

Example 4 with UpdateResult

use of com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult in project android by JetBrains.

the class InstantRunConfigurable method updateProjectToInstantRunTools.

/** Update versions relevant for Instant Run, and trigger a Gradle sync if successful */
public static boolean updateProjectToInstantRunTools(@NotNull Project project, @Nullable GradleSyncListener listener) {
    String pluginVersion = MINIMUM_GRADLE_PLUGIN_VERSION_STRING;
    // Pick max version of "recommended Gradle plugin" and "minimum required for instant run"
    if (GradleVersion.parse(GRADLE_PLUGIN_RECOMMENDED_VERSION).compareTo(MINIMUM_GRADLE_PLUGIN_VERSION) > 0) {
        pluginVersion = GRADLE_PLUGIN_RECOMMENDED_VERSION;
    }
    // Update plugin version
    AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
    UpdateResult result = updater.updatePluginVersion(GradleVersion.parse(pluginVersion), GradleVersion.parse(GRADLE_LATEST_VERSION));
    if (result.isPluginVersionUpdated() && result.versionUpdateSuccess()) {
        // Should be at least 23.0.2
        String buildToolsVersion = "23.0.2";
        AndroidSdkHandler sdk = AndroidSdks.getInstance().tryToChooseSdkHandler();
        BuildToolInfo latestBuildTool = sdk.getLatestBuildTool(new StudioLoggerProgressIndicator(InstantRunConfigurable.class), false);
        if (latestBuildTool != null) {
            Revision revision = latestBuildTool.getRevision();
            if (revision.compareTo(Revision.parseRevision(buildToolsVersion)) > 0) {
                buildToolsVersion = revision.toShortString();
            }
        }
        // Also update build files to set build tools version 23.0.2
        GradleUtil.setBuildToolsVersion(project, buildToolsVersion);
        // Also update Gradle wrapper version
        GradleWrapper gradleWrapper = GradleWrapper.find(project);
        if (gradleWrapper != null) {
            gradleWrapper.updateDistributionUrlAndDisplayFailure(GRADLE_LATEST_VERSION);
        }
        // Request a sync
        GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setRunInBackground(false);
        GradleSyncInvoker.getInstance().requestProjectSync(project, request, listener);
        return true;
    } else {
        return false;
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) AndroidPluginVersionUpdater(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater) UpdateResult(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper)

Aggregations

UpdateResult (com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult)4 Revision (com.android.repository.Revision)1 BuildToolInfo (com.android.sdklib.BuildToolInfo)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 AndroidPluginVersionUpdater (com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)1 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)1 GradleWrapper (com.android.tools.idea.gradle.util.GradleWrapper)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1