Search in sources :

Example 1 with AndroidPluginVersionUpdater

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

the class FixAndroidGradlePluginVersionHyperlink method execute.

@Override
public void execute(@NotNull Project project) {
    AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
    updater.updatePluginVersionAndSync(myPluginVersion, myGradleVersion, false);
}
Also used : AndroidPluginVersionUpdater(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)

Example 2 with AndroidPluginVersionUpdater

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

the class ForcedPluginPreviewVersionUpgradeStep method checkAndPerformUpgrade.

@Override
public boolean checkAndPerformUpgrade(@NotNull Project project, @NotNull AndroidPluginInfo pluginInfo) {
    AndroidPluginGeneration pluginGeneration = pluginInfo.getPluginGeneration();
    GradleVersion recommended = GradleVersion.parse(pluginGeneration.getLatestKnownVersion());
    if (!shouldPreviewBeForcedToUpgradePluginVersion(recommended.toString(), pluginInfo.getPluginVersion())) {
        return false;
    }
    GradleSyncState syncState = GradleSyncState.getInstance(project);
    // Update the sync state before starting a new one.
    syncState.syncEnded();
    boolean userAcceptsForcedUpgrade = new ForcedPluginPreviewVersionUpgradeDialog(project, pluginInfo).showAndGet();
    if (userAcceptsForcedUpgrade) {
        AndroidPluginVersionUpdater versionUpdater = AndroidPluginVersionUpdater.getInstance(project);
        versionUpdater.updatePluginVersionAndSync(recommended, GradleVersion.parse(GRADLE_LATEST_VERSION), true);
    } else {
        String[] text = { "The project is using an incompatible version of the " + pluginGeneration.getDescription() + ".", "Please update your project to use version " + pluginGeneration.getLatestKnownVersion() + "." };
        SyncMessage msg = new SyncMessage(SyncMessage.DEFAULT_GROUP, ERROR, text);
        String pluginName = AndroidPluginGeneration.getGroupId() + GRADLE_PATH_SEPARATOR + pluginGeneration.getArtifactId();
        NotificationHyperlink quickFix = new SearchInBuildFilesHyperlink(pluginName);
        msg.add(quickFix);
        SyncMessages.getInstance(project).report(msg);
        syncState.invalidateLastSync("Force plugin upgrade declined");
    }
    return true;
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SearchInBuildFilesHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.SearchInBuildFilesHyperlink) GradleVersion(com.android.ide.common.repository.GradleVersion) AndroidPluginGeneration(com.android.tools.idea.gradle.plugin.AndroidPluginGeneration) AndroidPluginVersionUpdater(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 3 with AndroidPluginVersionUpdater

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

the class RecommendedPluginVersionUpgradeStep method checkAndPerformUpgrade.

@Override
public boolean checkAndPerformUpgrade(@NotNull Project project, @NotNull AndroidPluginInfo pluginInfo) {
    if (shouldRecommendUpgrade(pluginInfo)) {
        GradleVersion current = pluginInfo.getPluginVersion();
        assert current != null;
        AndroidPluginGeneration pluginGeneration = pluginInfo.getPluginGeneration();
        GradleVersion recommended = GradleVersion.parse(pluginGeneration.getLatestKnownVersion());
        RecommendedPluginVersionUpdateDialog updateDialog = new RecommendedPluginVersionUpdateDialog(project, current, recommended);
        boolean userAcceptsUpgrade = updateDialog.showAndGet();
        if (userAcceptsUpgrade) {
            AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
            GradleVersion latestGradleVersion = GradleVersion.parse(GRADLE_LATEST_VERSION);
            AndroidPluginVersionUpdater.UpdateResult result = updater.updatePluginVersionAndSync(recommended, latestGradleVersion, false);
            if (result.versionUpdateSuccess()) {
                // plugin version updated and a project sync was requested. No need to continue.
                return true;
            }
        }
    }
    return false;
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion) AndroidPluginGeneration(com.android.tools.idea.gradle.plugin.AndroidPluginGeneration) AndroidPluginVersionUpdater(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)

Example 4 with AndroidPluginVersionUpdater

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

AndroidPluginVersionUpdater (com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)4 GradleVersion (com.android.ide.common.repository.GradleVersion)2 AndroidPluginGeneration (com.android.tools.idea.gradle.plugin.AndroidPluginGeneration)2 Revision (com.android.repository.Revision)1 BuildToolInfo (com.android.sdklib.BuildToolInfo)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 UpdateResult (com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult)1 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)1 GradleSyncState (com.android.tools.idea.gradle.project.sync.GradleSyncState)1 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)1 SearchInBuildFilesHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.SearchInBuildFilesHyperlink)1 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)1 GradleWrapper (com.android.tools.idea.gradle.util.GradleWrapper)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1