Skip to content

Commit

Permalink
try repro of oshai variant issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wakingrufus committed Oct 23, 2023
1 parent 51f923d commit 2569f9f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.artifacts.component.ModuleComponentSelector
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.artifacts.result.ResolvedDependencyResult
import org.gradle.api.attributes.Attribute
import org.gradle.api.attributes.Bundling
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

internal const val KTLINT_CONFIGURATION_NAME = "ktlint"
internal const val KTLINT_CONFIGURATION_DESCRIPTION = "Main ktlint-gradle configuration"
Expand All @@ -35,6 +37,7 @@ internal fun createKtlintConfiguration(target: Project, extension: KtlintExtensi
// Starting from KtLint 0.41.0 version published artifact has two variants: "external" and "shadowed"
attributes {
it.attribute(Bundling.BUNDLING_ATTRIBUTE, target.objects.named(Bundling::class.java, Bundling.EXTERNAL))
// it.attribute(Attribute.of("org.jetbrains.kotlin.platform.type", KotlinPlatformType::class.java),KotlinPlatformType.jvm)
}

// Workaround for gradle 6 https://github.com/gradle/gradle/issues/13255
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ class KtLintSupportedVersionsTest : AbstractPluginTest() {
// "0.49.0" did not expose needed baseline classes
"0.49.1",
"0.50.0",
"1.0.0"
"1.0.0",
"1.0.1"
).also {
// "0.37.0" is failing on Windows machines that is fixed in the next version
if (!OS.WINDOWS.isCurrentOs) it.add("0.37.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jlleitschuh.gradle.ktlint.testdsl.GradleTestVersions
import org.jlleitschuh.gradle.ktlint.testdsl.TestProject.Companion.FAIL_SOURCE_FILE
import org.jlleitschuh.gradle.ktlint.testdsl.build
import org.jlleitschuh.gradle.ktlint.testdsl.buildAndFail
import org.jlleitschuh.gradle.ktlint.testdsl.defaultProjectSetup
import org.jlleitschuh.gradle.ktlint.testdsl.project
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.params.ParameterizedTest
Expand Down Expand Up @@ -124,6 +125,28 @@ class KtlintBaselineSupportTest : AbstractPluginTest() {
}
}

@DisplayName("Generate baseline task should work only with ktlint 1.0 and kotlin 1.6")
@CommonTest
fun generateBaseline1(gradleVersion: GradleVersion) {
project(gradleVersion = gradleVersion, projectSetup = defaultProjectSetup(gradleVersion, "1.6.21")) {
withFailingSources()

//language=Groovy
buildGradle.appendText(
"""
ktlint {
version.set("1.0.0")
}
""".trimIndent()
)

build(GenerateBaselineTask.NAME, "--refresh-dependencies") {
assertThat(task(":${GenerateBaselineTask.NAME}")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}
}
}

@DisplayName("Should consider existing issues in baseline")
@ParameterizedTest(name = "{0} with KtLint {1}: {displayName}")
@ArgumentsSource(KtLintSupportedVersionsTest.SupportedKtlintVersionsProvider::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object TestVersions {
annotation class GradleTestVersions(
val minVersion: String = TestVersions.minSupportedGradleVersion,
val maxVersion: String = TestVersions.maxSupportedGradleVersion,
val additionalVersions: Array<String> = []
val additionalVersions: Array<String> = ["7.4.2"]
)

open class GradleArgumentsProvider : ArgumentsProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,18 @@ fun TestProject.buildAndFail(
.run { assertions() }
}

fun defaultProjectSetup(gradleVersion: GradleVersion): (File) -> Unit =
projectSetup("jvm", gradleVersion)
fun defaultProjectSetup(gradleVersion: GradleVersion, kotlinVersion: String? = null): (File) -> Unit =
projectSetup("jvm", gradleVersion, kotlinVersion)

private val GradleVersion.supportedKotlinVersion
get() = TestVersions.maxSupportedKotlinPluginVersion(this)

fun projectSetup(
kotlinPluginType: String,
gradleVersion: GradleVersion
gradleVersion: GradleVersion,
kotlinVersion: String? = null
): (File) -> Unit = {
val kotlinPluginVersion = gradleVersion.supportedKotlinVersion
val kotlinPluginVersion = kotlinVersion ?: gradleVersion.supportedKotlinVersion
//language=Groovy
it.resolve("build.gradle").writeText(
"""
Expand Down

0 comments on commit 2569f9f

Please sign in to comment.