Search in sources :

Example 1 with COMPARE_PLUS_HIGHER

use of com.android.ide.common.repository.GradleCoordinate.COMPARE_PLUS_HIGHER in project android by JetBrains.

the class AndroidPluginGeneration method getLatestKnownVersion.

@NotNull
protected String getLatestKnownVersion(@NotNull AndroidPluginGeneration generation) {
    String artifactId = generation.getArtifactId();
    FileOp fileOp = FileOpUtils.create();
    List<File> repoPaths = EmbeddedDistributionPaths.getInstance().findAndroidStudioLocalMavenRepoPaths();
    Optional<GradleCoordinate> highestValueCoordinate = repoPaths.stream().map(repoPath -> getHighestInstalledVersion(getGroupId(), artifactId, repoPath, null, true, fileOp)).filter(coordinate -> coordinate != null).max(COMPARE_PLUS_HIGHER);
    if (!highestValueCoordinate.isPresent()) {
        if (IdeInfo.getInstance().isAndroidStudio() && !isGuiTestingMode() && !ApplicationManager.getApplication().isInternal() && !ApplicationManager.getApplication().isUnitTestMode()) {
            // In a release build, Android Studio must find the latest version in its offline repo(s).
            throw new IllegalStateException("Gradle plugin missing from the offline Maven repo");
        } else {
            // In all other scenarios we will not throw an exception, but use the last known version from SdkConstants.
            // TODO: revisit this when tests are running with the latest (source) build.
            String version = generation.getRecommendedVersion();
            getLog().info("'" + artifactId + "' plugin missing from the offline Maven repo, will use default " + version);
            return version;
        }
    }
    return highestValueCoordinate.get().getRevision();
}
Also used : FileOp(com.android.repository.io.FileOp) GRADLE_PLUGIN_RECOMMENDED_VERSION(com.android.SdkConstants.GRADLE_PLUGIN_RECOMMENDED_VERSION) IdeInfo(com.android.tools.idea.IdeInfo) COMPARE_PLUS_HIGHER(com.android.ide.common.repository.GradleCoordinate.COMPARE_PLUS_HIGHER) Nullable(com.android.annotations.Nullable) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) Collection(java.util.Collection) FileOp(com.android.repository.io.FileOp) MavenRepositories.getHighestInstalledVersion(com.android.ide.common.repository.MavenRepositories.getHighestInstalledVersion) GENERATION_COMPONENT(com.android.builder.model.AndroidProject.GENERATION_COMPONENT) File(java.io.File) AndroidPlugin.isGuiTestingMode(org.jetbrains.android.AndroidPlugin.isGuiTestingMode) List(java.util.List) GradleValue.getValues(com.android.tools.idea.gradle.dsl.model.values.GradleValue.getValues) FileOpUtils(com.android.repository.io.FileOpUtils) GRADLE_EXPERIMENTAL_PLUGIN_RECOMMENDED_VERSION(com.android.SdkConstants.GRADLE_EXPERIMENTAL_PLUGIN_RECOMMENDED_VERSION) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Optional(java.util.Optional) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) EmbeddedDistributionPaths(com.android.tools.idea.gradle.util.EmbeddedDistributionPaths) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) NotNull(org.jetbrains.annotations.NotNull) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GRADLE_EXPERIMENTAL_PLUGIN_RECOMMENDED_VERSION (com.android.SdkConstants.GRADLE_EXPERIMENTAL_PLUGIN_RECOMMENDED_VERSION)1 GRADLE_PLUGIN_RECOMMENDED_VERSION (com.android.SdkConstants.GRADLE_PLUGIN_RECOMMENDED_VERSION)1 Nullable (com.android.annotations.Nullable)1 GENERATION_COMPONENT (com.android.builder.model.AndroidProject.GENERATION_COMPONENT)1 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)1 COMPARE_PLUS_HIGHER (com.android.ide.common.repository.GradleCoordinate.COMPARE_PLUS_HIGHER)1 MavenRepositories.getHighestInstalledVersion (com.android.ide.common.repository.MavenRepositories.getHighestInstalledVersion)1 FileOp (com.android.repository.io.FileOp)1 FileOpUtils (com.android.repository.io.FileOpUtils)1 IdeInfo (com.android.tools.idea.IdeInfo)1 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 GradleValue.getValues (com.android.tools.idea.gradle.dsl.model.values.GradleValue.getValues)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 EmbeddedDistributionPaths (com.android.tools.idea.gradle.util.EmbeddedDistributionPaths)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Module (com.intellij.openapi.module.Module)1 File (java.io.File)1 Collection (java.util.Collection)1 List (java.util.List)1