Use correct repository for checking if current EAP version is published

Logic for determining the Maven repository corresponding to the current
plugin version has been centralized and reused in the version chooser
in "Configure Kotlin" dialog.
  #KT-17291 Fixed
This commit is contained in:
Dmitry Jemerov
2017-04-11 18:06:50 +02:00
parent 546040fafd
commit 40df565369
4 changed files with 23 additions and 28 deletions
@@ -35,13 +35,14 @@ import org.jetbrains.kotlin.idea.versions.hasKotlinJsKjsmFile
import org.jetbrains.kotlin.idea.vfilefinder.IDEVirtualFileFinder import org.jetbrains.kotlin.idea.vfilefinder.IDEVirtualFileFinder
import org.jetbrains.kotlin.utils.ifEmpty import org.jetbrains.kotlin.utils.ifEmpty
data class RepositoryDescription(val id: String, val name: String, val url: String, val isSnapshot: Boolean) data class RepositoryDescription(val id: String, val name: String, val url: String, val bintrayUrl: String?, val isSnapshot: Boolean)
@JvmField @JvmField
val SNAPSHOT_REPOSITORY = RepositoryDescription( val SNAPSHOT_REPOSITORY = RepositoryDescription(
"sonatype.oss.snapshots", "sonatype.oss.snapshots",
"Sonatype OSS Snapshot Repository", "Sonatype OSS Snapshot Repository",
"http://oss.sonatype.org/content/repositories/snapshots", "http://oss.sonatype.org/content/repositories/snapshots",
null,
isSnapshot = true) isSnapshot = true)
@JvmField @JvmField
@@ -49,6 +50,7 @@ val EAP_REPOSITORY = RepositoryDescription(
"bintray.kotlin.eap", "bintray.kotlin.eap",
"Bintray Kotlin EAP Repository", "Bintray Kotlin EAP Repository",
"http://dl.bintray.com/kotlin/kotlin-eap", "http://dl.bintray.com/kotlin/kotlin-eap",
"https://bintray.com/kotlin/kotlin-eap/kotlin/",
isSnapshot = false) isSnapshot = false)
@JvmField @JvmField
@@ -56,8 +58,18 @@ val EAP_11_REPOSITORY = RepositoryDescription(
"bintray.kotlin.eap", "bintray.kotlin.eap",
"Bintray Kotlin 1.1 EAP Repository", "Bintray Kotlin 1.1 EAP Repository",
"http://dl.bintray.com/kotlin/kotlin-eap-1.1", "http://dl.bintray.com/kotlin/kotlin-eap-1.1",
"https://bintray.com/kotlin/kotlin-eap-1.1/kotlin/",
isSnapshot = false) isSnapshot = false)
fun RepositoryDescription.toRepositorySnippet() = "maven {\nurl '$url'\n}"
fun getRepositoryForVersion(version: String): RepositoryDescription? = when {
isSnapshot(version) -> SNAPSHOT_REPOSITORY
useEap11Repository(version) -> EAP_11_REPOSITORY
isEap(version) -> EAP_REPOSITORY
else -> null
}
fun isModuleConfigured(module: Module): Boolean { fun isModuleConfigured(module: Module): Boolean {
return allConfigurators().any { return allConfigurators().any {
it.getStatus(module) == ConfigureKotlinStatus.CONFIGURED it.getStatus(module) == ConfigureKotlinStatus.CONFIGURED
@@ -43,25 +43,13 @@ abstract class GradleKotlinFrameworkSupportProvider(val frameworkTypeId: String,
modifiableModelsProvider: ModifiableModelsProvider, modifiableModelsProvider: ModifiableModelsProvider,
buildScriptData: BuildScriptDataBuilder) { buildScriptData: BuildScriptDataBuilder) {
var kotlinVersion = bundledRuntimeVersion() var kotlinVersion = bundledRuntimeVersion()
val additionalRepository = getRepositoryForVersion(kotlinVersion)
val additionalRepository: String? = when { if (isSnapshot(bundledRuntimeVersion())) {
kotlinVersion == "@snapshot@" -> { kotlinVersion = "1.1-SNAPSHOT"
kotlinVersion = "1.1-SNAPSHOT"
KotlinWithGradleConfigurator.SNAPSHOT_REPOSITORY_SNIPPET
}
useEap11Repository(kotlinVersion) -> {
KotlinWithGradleConfigurator.EAP_11_REPOSITORY_SNIPPET
}
isEap(kotlinVersion) -> {
KotlinWithGradleConfigurator.EAP_REPOSITORY_SNIPPET
}
else -> {
null
}
} }
if (additionalRepository != null) { if (additionalRepository != null) {
val oneLineRepository = additionalRepository.replace('\n', ' ') val oneLineRepository = additionalRepository.toRepositorySnippet().replace('\n', ' ')
buildScriptData.addBuildscriptRepositoriesDefinition(oneLineRepository) buildScriptData.addBuildscriptRepositoriesDefinition(oneLineRepository)
buildScriptData.addRepositoriesDefinition("mavenCentral()") buildScriptData.addRepositoriesDefinition("mavenCentral()")
@@ -218,10 +218,6 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
val CLASSPATH = "classpath \"$GROUP_ID:$GRADLE_PLUGIN_ID:\$kotlin_version\"" val CLASSPATH = "classpath \"$GROUP_ID:$GRADLE_PLUGIN_ID:\$kotlin_version\""
val SNAPSHOT_REPOSITORY_SNIPPET = "maven {\nurl '" + SNAPSHOT_REPOSITORY.url + "'\n}"
val EAP_REPOSITORY_SNIPPET = "maven {\nurl '" + EAP_REPOSITORY.url + "'\n}"
val EAP_11_REPOSITORY_SNIPPET = "maven {\nurl '" + EAP_11_REPOSITORY.url + "'\n}"
private val MAVEN_CENTRAL = "mavenCentral()\n" private val MAVEN_CENTRAL = "mavenCentral()\n"
private val JCENTER = "jcenter()\n" private val JCENTER = "jcenter()\n"
@@ -515,10 +511,9 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
} }
private fun addRepository(repositoriesBlock: GrClosableBlock, version: String): Boolean { private fun addRepository(repositoriesBlock: GrClosableBlock, version: String): Boolean {
val repository = getRepositoryForVersion(version)
val snippet = when { val snippet = when {
isSnapshot(version) -> SNAPSHOT_REPOSITORY_SNIPPET repository != null -> repository.toRepositorySnippet()
useEap11Repository(version) -> EAP_11_REPOSITORY_SNIPPET
isEap(version) -> EAP_REPOSITORY_SNIPPET
!isRepositoryConfigured(repositoriesBlock) -> MAVEN_CENTRAL !isRepositoryConfigured(repositoriesBlock) -> MAVEN_CENTRAL
else -> return false else -> return false
} }
@@ -38,6 +38,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.idea.KotlinPluginUtil; import org.jetbrains.kotlin.idea.KotlinPluginUtil;
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtilsKt; import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtilsKt;
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator; import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator;
import org.jetbrains.kotlin.idea.configuration.RepositoryDescription;
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt; import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt;
import javax.swing.*; import javax.swing.*;
@@ -55,8 +56,6 @@ public class ConfigureDialogWithModulesAndVersion extends DialogWrapper {
private static final String VERSIONS_LIST_URL = private static final String VERSIONS_LIST_URL =
"http://search.maven.org/solrsearch/select?q=g:%22org.jetbrains.kotlin%22+AND+a:%22kotlin-runtime%22&core=gav&rows=20&wt=json"; "http://search.maven.org/solrsearch/select?q=g:%22org.jetbrains.kotlin%22+AND+a:%22kotlin-runtime%22&core=gav&rows=20&wt=json";
private static final String EAP_VERSIONS_URL =
"https://bintray.com/kotlin/kotlin-eap/kotlin/";
@NotNull private final String minimumVersion; @NotNull private final String minimumVersion;
private final ChooseModulePanel chooseModulePanel; private final ChooseModulePanel chooseModulePanel;
@@ -176,8 +175,9 @@ public class ConfigureDialogWithModulesAndVersion extends DialogWrapper {
List<String> versions = Lists.newArrayList(); List<String> versions = Lists.newArrayList();
String bundledRuntimeVersion = KotlinRuntimeLibraryUtilKt.bundledRuntimeVersion(); String bundledRuntimeVersion = KotlinRuntimeLibraryUtilKt.bundledRuntimeVersion();
if (ConfigureKotlinInProjectUtilsKt.isEap(bundledRuntimeVersion)) { RepositoryDescription repositoryDescription = ConfigureKotlinInProjectUtilsKt.getRepositoryForVersion(bundledRuntimeVersion);
HttpURLConnection eapConnection = HttpConfigurable.getInstance().openHttpConnection(EAP_VERSIONS_URL + bundledRuntimeVersion); if (repositoryDescription != null && repositoryDescription.getBintrayUrl() != null) {
HttpURLConnection eapConnection = HttpConfigurable.getInstance().openHttpConnection(repositoryDescription.getBintrayUrl() + bundledRuntimeVersion);
try { try {
int timeout = (int) TimeUnit.SECONDS.toMillis(30); int timeout = (int) TimeUnit.SECONDS.toMillis(30);
eapConnection.setConnectTimeout(timeout); eapConnection.setConnectTimeout(timeout);