Skip to content

Commit

Permalink
Enable explicit API mode (#232)
Browse files Browse the repository at this point in the history
* Enable Explicit API mode

* Fix all Explicit API errors

* Improve missing composition local error

* Fix after rebase

* Update again after new rebase
  • Loading branch information
rock3r authored Nov 2, 2023
1 parent ea25c1c commit 09b74eb
Show file tree
Hide file tree
Showing 207 changed files with 5,521 additions and 5,755 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ tasks {
source(configurations.outgoingSarif)
include { it.file.extension == "sarif" }
}
register("check") {
dependsOn(mergeSarifReports)
}

register("check") { dependsOn(mergeSarifReports) }
}
3 changes: 2 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.poko.gradlePlugin)

// Enables using type-safe accessors to reference plugins from the [plugins] block defined in version catalogs.
// Enables using type-safe accessors to reference plugins from the [plugins] block defined in
// version catalogs.
// Context: https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
1 change: 1 addition & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencyResolutionManagement {
gradlePluginPortal()
mavenCentral()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
Expand Down
14 changes: 8 additions & 6 deletions buildSrc/src/main/kotlin/IdeaConfiguration.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import java.util.concurrent.atomic.AtomicBoolean
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.jvm.toolchain.JavaLanguageVersion
import java.util.concurrent.atomic.AtomicBoolean

enum class SupportedIJVersion {
IJ_232,
Expand All @@ -12,16 +12,17 @@ private var warned = AtomicBoolean(false)

fun Project.supportedIJVersion(): SupportedIJVersion {
val prop = kotlin.runCatching {
rootProject.findProperty("supported.ij.version")?.toString() ?:
localProperty("supported.ij.version")
rootProject.findProperty("supported.ij.version")?.toString()
?: localProperty("supported.ij.version")
}.getOrNull()

if (prop == null) {
if (!warned.getAndSet(true)) {
logger.warn(
"""
No 'supported.ij.version' property provided. Falling back to IJ 233.
It is recommended to provide it using local.properties file or -Psupported.ij.version to avoid unexpected behavior.
No 'supported.ij.version' property provided. Falling back to IJ 233.
It is recommended to provide it using the local.properties file or
-Psupported.ij.version to avoid unexpected behavior.
""".trimIndent()
)
}
Expand All @@ -33,10 +34,11 @@ fun Project.supportedIJVersion(): SupportedIJVersion {
"233" -> SupportedIJVersion.IJ_233
else -> error(
"Invalid 'supported.ij.version' with value '$prop' is provided. " +
"It should be in set of these values: ('232', '233')"
"It should be one of these values: ('232', '233')"
)
}
}

@Suppress("unused") // Used to set the Java toolchain version
fun Property<JavaLanguageVersion>.assign(version: Int) =
set(JavaLanguageVersion.of(version))
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/LocalProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ internal fun Project.localProperty(propertyName: String): String? {
val properties = Properties()
localPropertiesFile.inputStream().use { properties.load(it) }
return properties.getProperty(propertyName)
}
}
52 changes: 32 additions & 20 deletions buildSrc/src/main/kotlin/MergeSarifTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.TaskAction

private const val SARIF_SCHEMA =
"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"

@CacheableTask
open class MergeSarifTask : SourceTask() {

Expand All @@ -17,34 +20,43 @@ open class MergeSarifTask : SourceTask() {
}

@get:OutputFile
val mergedSarifPath: RegularFileProperty = project.objects.fileProperty()
.convention(project.layout.buildDirectory.file("reports/static-analysis.sarif"))
val mergedSarifPath: RegularFileProperty =
project.objects
.fileProperty()
.convention(project.layout.buildDirectory.file("reports/static-analysis.sarif"))

@TaskAction
fun merge() {
val json = Json { prettyPrint = true }

logger.lifecycle("Merging ${source.files.size} SARIF file(s)...")
logger.lifecycle(source.files.joinToString("\n") { " * ~${it.path.removePrefix(project.rootDir.path)}" })

val merged = SarifSchema210(
schema = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
version = Version.The210,
runs = source.files
.asSequence()
.filter { it.extension == "sarif" }
.map { file -> file.inputStream().use { json.decodeFromStream<SarifSchema210>(it) } }
.flatMap { report -> report.runs }
.groupBy { run -> run.tool.driver.guid ?: run.tool.driver.name }
.values
.asSequence()
.filter { it.isNotEmpty() }
.map { run -> run.first().copy(results = run.flatMap { it.results ?: emptyList() }) }
.toList()
logger.lifecycle(
source.files.joinToString("\n") { " * ~${it.path.removePrefix(project.rootDir.path)}" }
)

val merged =
SarifSchema210(
schema = SARIF_SCHEMA,
version = Version.The210,
runs = source.files
.asSequence()
.filter { it.extension == "sarif" }
.map { file ->
file.inputStream().use { json.decodeFromStream<SarifSchema210>(it) }
}
.flatMap { report -> report.runs }
.groupBy { run -> run.tool.driver.guid ?: run.tool.driver.name }
.values
.asSequence()
.filter { it.isNotEmpty() }
.map { run ->
run.first().copy(results = run.flatMap { it.results ?: emptyList() })
}
.toList()
)

logger.lifecycle("Merged SARIF file contains ${merged.runs.size} run(s)")
logger.info("Writing merged SARIF file to $mergedSarifPath...")
mergedSarifPath.asFile.get().outputStream()
.use { json.encodeToStream(merged, it) }
mergedSarifPath.asFile.get().outputStream().use { json.encodeToStream(merged, it) }
}
}
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/PublishConfiguration.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("UnstableApiUsage")
@file:Suppress("UnstableApiUsage", "UnusedImports")

import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
Expand Down Expand Up @@ -32,4 +32,4 @@ internal fun MavenPom.configureJewelPom() {
developerConnection = "scm:git:https://github.com/JetBrains/jewel.git"
url = "https://github.com/JetBrains/jewel"
}
}
}
8 changes: 5 additions & 3 deletions buildSrc/src/main/kotlin/ValidatePublicApiTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ open class ValidatePublicApiTask : SourceTask() {
private val classFqnRegex = "public (?:\\w+ )*class (\\S+)\\b".toRegex()

@Suppress("ConvertToStringTemplate") // The odd concatenation is needed because of $; escapes get confused
private val copyMethodRegex = ("public static synthetic fun copy(-\\w+)?" + "\\$" + "default\\b").toRegex()
private val copyMethodRegex =
("public static synthetic fun copy(-\\w+)?" + "\\$" + "default\\b").toRegex()

@TaskAction
fun validatePublicApi() {
Expand Down Expand Up @@ -86,8 +87,9 @@ open class ValidatePublicApiTask : SourceTask() {
}
}

val actualDataClasses = dataClasses.filterValues { it.hasCopyMethod && !it.isLikelyValueClass }
.keys
val actualDataClasses =
dataClasses.filterValues { it.hasCopyMethod && !it.isLikelyValueClass }
.keys
return actualDataClasses
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,16 @@ val extension: StudioVersionsGenerationExtension =
val task =
tasks.register<AndroidStudioReleasesGeneratorTask>("generateAndroidStudioReleasesList") {
val className = ClassName.bestGuess(STUDIO_RELEASES_OUTPUT_CLASS_NAME)
outputFile = extension.targetDir.file(
className.packageName.replace(".", "/")
.plus("/${className.simpleName}.kt")
)
val filePath = className.packageName.replace(".", "/") +
"/${className.simpleName}.kt"
outputFile = extension.targetDir.file(filePath)
dataUrl = extension.dataUrl
resourcesDirs = extension.resourcesDirs
}

tasks {
withType<BaseKotlinCompile> {
dependsOn(task)
}

withType<Detekt> {
dependsOn(task)
}
withType<BaseKotlinCompile> { dependsOn(task) }
withType<Detekt> { dependsOn(task) }
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
Expand Down
30 changes: 14 additions & 16 deletions buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile

val extension = ThemeGeneratorContainer(container<ThemeGeneration> { ThemeGeneration(it, project) })

extensions.add("intelliJThemeGenerator", extension)

extension.all {
val task = tasks.register<IntelliJThemeGeneratorTask>("generate${GUtil.toCamelCase(name)}Theme") {
outputFile = targetDir.file(this@all.themeClassName.map {
val className = ClassName.bestGuess(it)
className.packageName.replace(".", "/")
.plus("/${className.simpleName}.kt")
})
themeClassName = this@all.themeClassName
ideaVersion = this@all.ideaVersion
themeFile = this@all.themeFile
}
val task =
tasks.register<IntelliJThemeGeneratorTask>("generate${GUtil.toCamelCase(name)}Theme") {
val paths = this@all.themeClassName.map {
val className = ClassName.bestGuess(it)
className.packageName.replace(".", "/") + "/${className.simpleName}.kt"
}

tasks {
withType<BaseKotlinCompile> {
dependsOn(task)
outputFile = targetDir.file(paths)
themeClassName = this@all.themeClassName
ideaVersion = this@all.ideaVersion
themeFile = this@all.themeFile
}

withType<Detekt> {
dependsOn(task)
}
tasks {
withType<BaseKotlinCompile> { dependsOn(task) }
withType<Detekt> { dependsOn(task) }
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
Expand Down
20 changes: 12 additions & 8 deletions buildSrc/src/main/kotlin/jewel-check-public-api.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
plugins {
id("org.jetbrains.kotlinx.binary-compatibility-validator")
id("dev.drewhamilton.poko")
kotlin("jvm")
}

apiValidation {
Expand All @@ -18,14 +19,17 @@ poko {
pokoAnnotation = "org.jetbrains.jewel.foundation.GenerateDataFunctions"
}

kotlin {
explicitApi()
}

tasks {
val validatePublicApi = register<ValidatePublicApiTask>("validatePublicApi") {
include { it.file.extension == "api" }
source(project.fileTree("api"))
dependsOn(named("apiCheck"))
}
val validatePublicApi =
register<ValidatePublicApiTask>("validatePublicApi") {
include { it.file.extension == "api" }
source(project.fileTree("api"))
dependsOn(named("apiCheck"))
}

named("check") {
dependsOn(validatePublicApi)
}
named("check") { dependsOn(validatePublicApi) }
}
12 changes: 4 additions & 8 deletions buildSrc/src/main/kotlin/jewel-ij-publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,23 @@ publishing {
}
version = project.version.toString().withVersionSuffix("ij-$ijVersionRaw")
artifactId = "jewel-${project.name}"
pom {
configureJewelPom()
}
pom { configureJewelPom() }
}
}
}

/**
* Adds suffix to the version taking SNAPSHOT suffix into account
*
* For example, if [this] is "0.0.1-SNAPSHOT" and [suffix] is "ij-233"
* then result will be "0.0.1-ij-233-SNAPSHOT"
* For example, if [this] is "0.0.1-SNAPSHOT" and [suffix] is "ij-233" then
* the result will be "0.0.1-ij-233-SNAPSHOT"
*/
fun String.withVersionSuffix(suffix: String): String {
val splitString = this.split('-')
val snapshotRaw = "SNAPSHOT"
val withSnapshot = splitString.contains(snapshotRaw)

if (!withSnapshot) {
return "$this-$suffix"
}
if (!withSnapshot) return "$this-$suffix"

val withoutSnapshot = splitString.filter { it != snapshotRaw }.joinToString("-")

Expand Down
8 changes: 2 additions & 6 deletions buildSrc/src/main/kotlin/jewel-linting.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ plugins {
}

configurations {
val dependencies = register("sarif") {
isCanBeDeclared = true
}
val dependencies = register("sarif") { isCanBeDeclared = true }
register("outgoingSarif") {
isCanBeConsumed = true
isCanBeResolved = true
extendsFrom(dependencies.get())
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named("sarif"))
}
attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named("sarif")) }
}
}
4 changes: 1 addition & 3 deletions buildSrc/src/main/kotlin/jewel-publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ publishing {
artifact(sourcesJar)
version = project.version.toString()
artifactId = "jewel-${project.name}"
pom {
configureJewelPom()
}
pom { configureJewelPom() }
}
}
}
Loading

0 comments on commit 09b74eb

Please sign in to comment.