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);
}
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();
}
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);
}
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);
}
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;
}
Aggregations