All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jetbrains.pluginverifier.dependencies.resolution.LastCompatibleVersionSelector.kt Maven / Gradle / Ivy

Go to download

JetBrains Plugin Verifier Classes for IntelliJ Platform integration with API usage detection and reporting.

There is a newer version: 1.381
Show newest version
/*
 * Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 */

package com.jetbrains.pluginverifier.dependencies.resolution

import com.jetbrains.plugin.structure.intellij.version.IdeVersion
import com.jetbrains.pluginverifier.repository.PluginRepository

/**
 * The [PluginVersionSelector] that selects
 * the _last_ version of the plugin _compatible_ with [ideVersion].
 */
class LastCompatibleVersionSelector(val ideVersion: IdeVersion) : PluginVersionSelector {
  override fun selectPluginVersion(pluginId: String, pluginRepository: PluginRepository): PluginVersionSelector.Result {
    val pluginInfo = pluginRepository.getLastCompatibleVersionOfPlugin(ideVersion, pluginId)
    if (pluginInfo != null) {
      return PluginVersionSelector.Result.Selected(pluginInfo)
    }
    val allVersions = pluginRepository.getAllVersionsOfPlugin(pluginId)
    if (allVersions.isEmpty()) {
      return PluginVersionSelector.Result.NotFound("Plugin $pluginId is not available in ${pluginRepository.presentableName}")
    }
    return PluginVersionSelector.Result.NotFound("Plugin $pluginId doesn't have a build compatible with $ideVersion in ${pluginRepository.presentableName}")
  }

  override fun selectPluginByModuleId(moduleId: String, pluginRepository: PluginRepository): PluginVersionSelector.Result {
    val plugins = pluginRepository.getPluginsDeclaringModule(moduleId, ideVersion)
    val somePlugin = plugins.firstOrNull()
    if (somePlugin != null) {
      return PluginVersionSelector.Result.Selected(somePlugin)
    }
    return PluginVersionSelector.Result.NotFound("Plugins declaring module '$moduleId' are not found in ${pluginRepository.presentableName}")
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy