Minor: Reformat and fix warnings in dependencies.kt

This commit is contained in:
Vyacheslav Gerasimov
2021-12-09 02:13:39 +03:00
committed by teamcity
parent 944c7990a1
commit 443cbcbc3c
+21 -22
View File
@@ -3,10 +3,6 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("unused")
// usages in build scripts are not tracked properly
import org.gradle.api.GradleException import org.gradle.api.GradleException
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.* import org.gradle.api.artifacts.*
@@ -14,10 +10,7 @@ import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection import org.gradle.api.file.FileCollection
import org.gradle.internal.jvm.Jvm import org.gradle.internal.jvm.Jvm
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.accessors.runtime.addDependencyTo
import org.gradle.kotlin.dsl.closureOf import org.gradle.kotlin.dsl.closureOf
import org.gradle.kotlin.dsl.exclude
import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.project import org.gradle.kotlin.dsl.project
import java.io.File import java.io.File
@@ -25,14 +18,16 @@ import java.io.File
private val Project.isEAPIntellij get() = rootProject.extra["versions.intellijSdk"].toString().contains("-EAP-") private val Project.isEAPIntellij get() = rootProject.extra["versions.intellijSdk"].toString().contains("-EAP-")
private val Project.isNightlyIntellij get() = rootProject.extra["versions.intellijSdk"].toString().endsWith("SNAPSHOT") && !isEAPIntellij private val Project.isNightlyIntellij get() = rootProject.extra["versions.intellijSdk"].toString().endsWith("SNAPSHOT") && !isEAPIntellij
val Project.intellijRepo get() = val Project.intellijRepo
get() =
when { when {
isEAPIntellij -> "https://www.jetbrains.com/intellij-repository/snapshots" isEAPIntellij -> "https://www.jetbrains.com/intellij-repository/snapshots"
isNightlyIntellij -> "https://www.jetbrains.com/intellij-repository/nightly" isNightlyIntellij -> "https://www.jetbrains.com/intellij-repository/nightly"
else -> "https://www.jetbrains.com/intellij-repository/releases" else -> "https://www.jetbrains.com/intellij-repository/releases"
} }
val Project.internalBootstrapRepo: String? get() = val Project.internalBootstrapRepo: String?
get() =
when { when {
bootstrapKotlinRepo?.startsWith("https://buildserver.labs.intellij.net") == true bootstrapKotlinRepo?.startsWith("https://buildserver.labs.intellij.net") == true
|| bootstrapKotlinRepo?.startsWith("https://teamcity.jetbrains.com") == true -> || bootstrapKotlinRepo?.startsWith("https://teamcity.jetbrains.com") == true ->
@@ -45,13 +40,13 @@ val Project.internalBootstrapRepo: String? get() =
else -> null else -> null
} }
fun Project.commonDependency(coord: String): String { fun Project.commonDependency(coordinates: String): String {
val parts = coord.split(':') val parts = coordinates.split(':')
return when (parts.size) { return when (parts.size) {
1 -> "$coord:$coord:${commonDependencyVersion(coord, coord)}" 1 -> "$coordinates:$coordinates:${commonDependencyVersion(coordinates, coordinates)}"
2 -> "${parts[0]}:${parts[1]}:${commonDependencyVersion(parts[0], parts[1])}" 2 -> "${parts[0]}:${parts[1]}:${commonDependencyVersion(parts[0], parts[1])}"
3 -> coord 3 -> coordinates
else -> throw IllegalArgumentException("Illegal maven coordinates: $coord") else -> throw IllegalArgumentException("Illegal maven coordinates: $coordinates")
} }
} }
@@ -70,10 +65,10 @@ fun Project.commonDependencyVersion(group: String, artifact: String) =
fun Project.preloadedDeps( fun Project.preloadedDeps(
vararg artifactBaseNames: String, vararg artifactBaseNames: String,
baseDir: File = File(rootDir, "dependencies"), baseDir: File = File(rootDir, "dependencies"),
subdir: String? = null, subDir: String? = null,
optional: Boolean = false optional: Boolean = false
): ConfigurableFileCollection { ): ConfigurableFileCollection {
val dir = if (subdir != null) File(baseDir, subdir) else baseDir val dir = if (subDir != null) File(baseDir, subDir) else baseDir
if (!dir.exists() || !dir.isDirectory) { if (!dir.exists() || !dir.isDirectory) {
if (optional) return files() if (optional) return files()
throw GradleException("Invalid base directory $dir") throw GradleException("Invalid base directory $dir")
@@ -82,20 +77,22 @@ fun Project.preloadedDeps(
if (matchingFiles == null || matchingFiles.size < artifactBaseNames.size) { if (matchingFiles == null || matchingFiles.size < artifactBaseNames.size) {
throw GradleException( throw GradleException(
"Not all matching artifacts '${artifactBaseNames.joinToString()}' found in the '$dir' " + "Not all matching artifacts '${artifactBaseNames.joinToString()}' found in the '$dir' " +
"(missing: ${artifactBaseNames.filterNot { request -> "(missing: ${
matchingFiles.any { artifactBaseNames.filterNot { request ->
matchingFiles?.any {
it.matchMaybeVersionedArtifact( it.matchMaybeVersionedArtifact(
request request
) )
} } ?: false
}.joinToString()};" + }.joinToString()
};" +
" found: ${matchingFiles?.joinToString { it.name }})" " found: ${matchingFiles?.joinToString { it.name }})"
) )
} }
return files(*matchingFiles.map { it.canonicalPath }.toTypedArray()) return files(*matchingFiles.map { it.canonicalPath }.toTypedArray())
} }
fun Project.kotlinDep(artifactBaseName: String, version: String, classifier: String? = null): String = fun kotlinDep(artifactBaseName: String, version: String, classifier: String? = null): String =
listOfNotNull("org.jetbrains.kotlin:kotlin-$artifactBaseName:$version", classifier).joinToString(":") listOfNotNull("org.jetbrains.kotlin:kotlin-$artifactBaseName:$version", classifier).joinToString(":")
fun Project.kotlinStdlib(suffix: String? = null, classifier: String? = null): Any { fun Project.kotlinStdlib(suffix: String? = null, classifier: String? = null): Any {
@@ -126,6 +123,7 @@ fun DependencyHandler.add(configurationName: String, dependencyNotation: Any, co
} }
} }
@Suppress("unused") // Used in cooperative mode with IDEA Kotlin plugin
fun Project.disableDependencyVerification() { fun Project.disableDependencyVerification() {
configurations.all { configurations.all {
resolutionStrategy { resolutionStrategy {
@@ -171,6 +169,7 @@ fun DependencyHandler.jpsLikeJarDependency(
} }
} }
@Suppress("unused") // Used in cooperative mode with IDEA Kotlin plugin
fun DependencyHandler.jpsLikeModuleDependency(moduleName: String, scope: JpsDepScope, exported: Boolean = false) { fun DependencyHandler.jpsLikeModuleDependency(moduleName: String, scope: JpsDepScope, exported: Boolean = false) {
jpsLikeJarDependency(project(moduleName), scope, exported = exported) jpsLikeJarDependency(project(moduleName), scope, exported = exported)
when (scope) { when (scope) {
@@ -305,5 +304,5 @@ val compilerManifestClassPath
get() = "annotations-13.0.jar kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar trove4j.jar" get() = "annotations-13.0.jar kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar trove4j.jar"
object EmbeddedComponents { object EmbeddedComponents {
val CONFIGURATION_NAME = "embedded" const val CONFIGURATION_NAME = "embedded"
} }