Search in sources :

Example 1 with AndroidPluginInfo

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

the class GradleBuildModel method android.

/**
   * Returns {@link AndroidModel} to read and update android block contents in the build.gradle file.
   *
   * <p>Returns {@code null} when experimental plugin is used as reading and updating android section is not supported for the
   * experimental dsl.</p>
   */
@Nullable
public AndroidModel android() {
    AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(myGradleDslFile.getProject());
    if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
        // Reading or updating Android block contents is not supported when experimental plugin is used.
        return null;
    }
    AndroidDslElement androidDslElement = myGradleDslFile.getPropertyElement(ANDROID_BLOCK_NAME, AndroidDslElement.class);
    if (androidDslElement == null) {
        androidDslElement = new AndroidDslElement(myGradleDslFile);
        myGradleDslFile.setNewElement(ANDROID_BLOCK_NAME, androidDslElement);
    }
    return new AndroidModel(androidDslElement);
}
Also used : AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) AndroidDslElement(com.android.tools.idea.gradle.dsl.parser.android.AndroidDslElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AndroidPluginInfo

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

the class AndroidGradlePluginVersionReader method getQuickFixes.

@Override
@NotNull
public List<NotificationHyperlink> getQuickFixes(@NotNull Module module, @Nullable VersionRange expectedVersion, @Nullable PositionInFile location) {
    AndroidPluginInfo pluginInfo = AndroidPluginInfo.find(module.getProject());
    if (isSupportedGeneration(pluginInfo)) {
        String version = pluginInfo.getPluginGeneration().getLatestKnownVersion();
        List<NotificationHyperlink> quickFixes = new ArrayList<>();
        quickFixes.add(new FixAndroidGradlePluginVersionHyperlink(GradleVersion.parse(version), GradleVersion.parse(GRADLE_LATEST_VERSION)));
        quickFixes.add(new OpenUrlHyperlink("https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle", "Open Documentation"));
        return quickFixes;
    }
    return emptyList();
}
Also used : FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) ArrayList(java.util.ArrayList) OpenUrlHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenUrlHyperlink) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AndroidPluginInfo

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

the class PluginVersionUpgradeTest method testCheckAndPerformUpgradeWhenUpgradeIsPerformed.

public void testCheckAndPerformUpgradeWhenUpgradeIsPerformed() {
    Module module = getModule();
    simulateAndroidModule(module, GENERATION_ORIGINAL);
    AndroidPluginInfo pluginInfo = new AndroidPluginInfo(module, ORIGINAL, null, null);
    Project project = getProject();
    when(myUpgradeStep1.checkAndPerformUpgrade(project, pluginInfo)).thenReturn(false);
    when(myUpgradeStep2.checkAndPerformUpgrade(project, pluginInfo)).thenReturn(true);
    assertTrue(myVersionUpgrade.checkAndPerformUpgrade());
    verify(myUpgradeStep1, times(1)).checkAndPerformUpgrade(project, pluginInfo);
    verify(myUpgradeStep2, times(1)).checkAndPerformUpgrade(project, pluginInfo);
    // because myUpgradeStep2 upgraded the project, myUpgradeStep3 should not be invoked.
    verify(myUpgradeStep3, never()).checkAndPerformUpgrade(project, pluginInfo);
}
Also used : AndroidProject(com.android.builder.model.AndroidProject) Project(com.intellij.openapi.project.Project) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) Module(com.intellij.openapi.module.Module)

Example 4 with AndroidPluginInfo

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

the class PluginVersionUpgradeTest method testCheckAndPerformUpgradeWhenUpgradeIsNotPerformed.

public void testCheckAndPerformUpgradeWhenUpgradeIsNotPerformed() {
    Module module = getModule();
    simulateAndroidModule(module, GENERATION_ORIGINAL);
    AndroidPluginInfo pluginInfo = new AndroidPluginInfo(module, ORIGINAL, null, null);
    Project project = getProject();
    when(myUpgradeStep1.checkAndPerformUpgrade(project, pluginInfo)).thenReturn(false);
    when(myUpgradeStep2.checkAndPerformUpgrade(project, pluginInfo)).thenReturn(false);
    when(myUpgradeStep3.checkAndPerformUpgrade(project, pluginInfo)).thenReturn(false);
    assertFalse(myVersionUpgrade.checkAndPerformUpgrade());
    verify(myUpgradeStep1, times(1)).checkAndPerformUpgrade(project, pluginInfo);
    verify(myUpgradeStep2, times(1)).checkAndPerformUpgrade(project, pluginInfo);
    verify(myUpgradeStep3, times(1)).checkAndPerformUpgrade(project, pluginInfo);
}
Also used : AndroidProject(com.android.builder.model.AndroidProject) Project(com.intellij.openapi.project.Project) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) Module(com.intellij.openapi.module.Module)

Example 5 with AndroidPluginInfo

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

the class GradleVersionReader method getQuickFixes.

@Override
@NotNull
public List<NotificationHyperlink> getQuickFixes(@NotNull Module module, @Nullable VersionRange expectedVersion, @Nullable PositionInFile location) {
    List<NotificationHyperlink> quickFixes = new ArrayList<>();
    AndroidPluginInfo pluginInfo = AndroidPluginInfo.find(module.getProject());
    if (pluginInfo != null) {
        GradleVersion pluginVersion = GradleVersion.parse(pluginInfo.getPluginGeneration().getLatestKnownVersion());
        GradleVersion gradleVersion = GradleVersion.parse(GRADLE_LATEST_VERSION);
        String text = "Fix Gradle version (as part of the update, the Android plugin will be updated to version " + pluginVersion + ")";
        quickFixes.add(new FixAndroidGradlePluginVersionHyperlink(text, pluginVersion, gradleVersion));
    }
    quickFixes.add(new OpenUrlHyperlink("https://developer.android.com/studio/releases/index.html#Revisions", "Open Documentation"));
    return quickFixes;
}
Also used : FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) ArrayList(java.util.ArrayList) OpenUrlHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenUrlHyperlink) GradleVersion(com.android.ide.common.repository.GradleVersion) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)11 NotNull (org.jetbrains.annotations.NotNull)6 GradleVersion (com.android.ide.common.repository.GradleVersion)4 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)4 ArrayList (java.util.ArrayList)4 FixAndroidGradlePluginVersionHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink)3 Module (com.intellij.openapi.module.Module)3 AndroidProject (com.android.builder.model.AndroidProject)2 OpenFileHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink)2 OpenUrlHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.OpenUrlHyperlink)2 Project (com.intellij.openapi.project.Project)2 SyncIssue (com.android.builder.model.SyncIssue)1 LocalPackage (com.android.repository.api.LocalPackage)1 ProgressIndicator (com.android.repository.api.ProgressIndicator)1 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 ProjectLibraries (com.android.tools.idea.gradle.ProjectLibraries)1 AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)1 AndroidDslElement (com.android.tools.idea.gradle.dsl.parser.android.AndroidDslElement)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1