Search in sources :

Example 1 with AndroidPluginGeneration

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

the class LinkExternalCppProjectAction method isValidAndroidGradleModuleSelected.

private static boolean isValidAndroidGradleModuleSelected(@NotNull DataContext dataContext) {
    Module module = getSelectedModule(dataContext);
    if (module == null) {
        return false;
    }
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel == null || !androidModel.getFeatures().isExternalBuildSupported()) {
        return false;
    }
    AndroidPluginGeneration pluginGeneration = AndroidPluginGeneration.find(module);
    if (pluginGeneration == COMPONENT) {
        // Updating experimental plugin DSL is not yet supported.
        return false;
    }
    NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
    if (ndkModuleModel != null) {
        // Some external native project is already linked to this module.
        return false;
    }
    if (GradleBuildModel.get(module) == null) {
        // This should never for an fully synced module, but checking for just in case.
        return false;
    }
    return true;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) AndroidPluginGeneration(com.android.tools.idea.gradle.plugin.AndroidPluginGeneration)

Example 2 with AndroidPluginGeneration

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

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

Aggregations

AndroidPluginGeneration (com.android.tools.idea.gradle.plugin.AndroidPluginGeneration)3 GradleVersion (com.android.ide.common.repository.GradleVersion)2 AndroidPluginVersionUpdater (com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)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 Module (com.intellij.openapi.module.Module)1