Search in sources :

Example 6 with AndroidPluginInfo

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

the class ChooseActivityTypeStep method determineGradlePluginVersion.

/**
   * Find the most appropriated Gradle Plugin version for the specified project.
   * @param project If {@code null} (ie we are creating a new project) returns the recommended gradle version.
   */
@NotNull
private static String determineGradlePluginVersion(@Nullable Project project) {
    String defaultGradleVersion = AndroidPluginGeneration.ORIGINAL.getLatestKnownVersion();
    if (project == null) {
        return defaultGradleVersion;
    }
    GradleVersion versionInUse = GradleUtil.getAndroidGradleModelVersionInUse(project);
    if (versionInUse != null) {
        return versionInUse.toString();
    }
    AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.searchInBuildFilesOnly(project);
    GradleVersion pluginVersion = (androidPluginInfo == null) ? null : androidPluginInfo.getPluginVersion();
    return (pluginVersion == null) ? defaultGradleVersion : pluginVersion.toString();
}
Also used : AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) GradleVersion(com.android.ide.common.repository.GradleVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with AndroidPluginInfo

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

the class PluginVersionUpgrade method checkAndPerformUpgrade.

/**
   * Checks if the Android plugin used in the project needs to be upgraded, and if so, performs the upgrade.
   *
   * @return {@code true} if an upgrade was needed and was successfully performed; {@code false} otherwise.
   */
public boolean checkAndPerformUpgrade() {
    AndroidPluginInfo pluginInfo = AndroidPluginInfo.find(myProject);
    if (pluginInfo == null) {
        getLog().warn("Unable to obtain application's Android Project");
        return false;
    }
    log(pluginInfo);
    for (PluginVersionUpgradeStep upgradeStep : myUpgradeSteps) {
        if (upgradeStep.checkAndPerformUpgrade(myProject, pluginInfo)) {
            // plugin was updated and sync requested. No need to continue.
            return true;
        }
    }
    return false;
}
Also used : AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo)

Example 8 with AndroidPluginInfo

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

the class NewModuleWizardDynamic method determineGradlePluginVersion.

@NotNull
private static String determineGradlePluginVersion(@Nullable Project project) {
    if (project != null) {
        GradleVersion versionInUse = GradleUtil.getAndroidGradleModelVersionInUse(project);
        if (versionInUse != null) {
            return versionInUse.toString();
        }
        AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.searchInBuildFilesOnly(project);
        if (androidPluginInfo != null) {
            GradleVersion pluginVersion = androidPluginInfo.getPluginVersion();
            if (pluginVersion != null) {
                return pluginVersion.toString();
            }
        }
    }
    return AndroidPluginGeneration.ORIGINAL.getLatestKnownVersion();
}
Also used : AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) GradleVersion(com.android.ide.common.repository.GradleVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with AndroidPluginInfo

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

the class OldAndroidPluginErrorHandler method getQuickFixHyperlinks.

@Override
@NotNull
protected List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    hyperlinks.add(new FixAndroidGradlePluginVersionHyperlink());
    AndroidPluginInfo result = searchInBuildFilesOnly(project);
    if (result != null && result.getPluginBuildFile() != null) {
        hyperlinks.add(new OpenFileHyperlink(result.getPluginBuildFile().getPath()));
    }
    return hyperlinks;
}
Also used : FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) ArrayList(java.util.ArrayList) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with AndroidPluginInfo

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

the class SdkBuildToolsTooLowErrorHandler method getQuickFixHyperlinks.

@NotNull
public List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull String minimumVersion, @NotNull Project project, @Nullable Module module) {
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    boolean buildToolInstalled = false;
    AndroidSdkHandler sdkHandler = null;
    AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    if (androidSdkData != null) {
        sdkHandler = androidSdkData.getSdkHandler();
    }
    if (sdkHandler != null) {
        ProgressIndicator progress = new StudioLoggerProgressIndicator(SdkBuildToolsTooLowErrorHandler.class);
        RepositoryPackages packages = sdkHandler.getSdkManager(progress).getPackages();
        LocalPackage buildTool = packages.getLocalPackages().get(getBuildToolsPath(parseRevision(minimumVersion)));
        buildToolInstalled = buildTool != null;
    }
    if (module != null) {
        VirtualFile buildFile = getGradleBuildFile(module);
        AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(project);
        if (!buildToolInstalled) {
            if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
                hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, null));
            } else {
                hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, buildFile));
            }
        } else if (buildFile != null && androidPluginInfo != null && !androidPluginInfo.isExperimental()) {
            hyperlinks.add(new FixBuildToolsVersionHyperlink(buildFile, minimumVersion));
        }
        if (buildFile != null) {
            hyperlinks.add(new OpenFileHyperlink(buildFile.getPath()));
        }
    }
    return hyperlinks;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalPackage(com.android.repository.api.LocalPackage) FixBuildToolsVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixBuildToolsVersionHyperlink) ArrayList(java.util.ArrayList) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) InstallBuildToolsHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.InstallBuildToolsHyperlink) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) 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