Skip to content

Commit

Permalink
Fixed compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo committed Jan 11, 2023
1 parent 3bfe5ba commit 6ad52f7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ allprojects {
plugins.withId("java") {
apply(plugin = "jacoco-report-aggregation")

the<JavaPluginExtension>().toolchain.languageVersion.set(JavaLanguageVersion.of(11))
the<JavaPluginExtension>().targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
"testImplementation"(libs.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ val KClass<*>.codeOwners
get() = java.codeOwners

val Class<*>.codeOwners: Set<String>?
get() = with(topLevelClass()) { classLoader.codeOwners(packageName, simpleName) }
get() = with(topLevelClass()) { classLoader.codeOwners(`package`.name, simpleName) }

val Throwable.codeOwners
get() = stackTrace.asSequence().map { it.codeOwners }.firstOrNull()
Expand All @@ -27,7 +27,7 @@ private val StackTraceElement.codeOwners: Set<String>?
val clazz = runCatching { Class.forName(className) }.getOrNull() ?: return null

return fileName?.substringBeforeLast('.')
?.let { clazz.classLoader.codeOwners(clazz.packageName, it) }
?.let { clazz.classLoader.codeOwners(clazz.`package`.name, it) }
?: clazz.codeOwners
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ class CodeOwnersPluginITest {
@Order(4)
@EnabledIf("getAndroidTestPasses")
fun `app builds successfully`() {
val build = runBuild(":app:build")
val build = runBuild(":app:build", ":app:packageDebugAndroidTest")

assertEquals(TaskOutcome.UP_TO_DATE, build.task(":app:generateDebugCodeOwnersResources")?.outcome)
assertEquals(TaskOutcome.UP_TO_DATE, build.task(":app:generateDebugUnitTestCodeOwnersResources")?.outcome)
assertEquals(TaskOutcome.NO_SOURCE, build.task(":app:generateDebugAndroidTestCodeOwnersResources")?.outcome)
assertEquals(TaskOutcome.UP_TO_DATE, build.task(":app:generateDebugAndroidTestCodeOwnersResources")?.outcome)
assertEquals(null, build.task(":app:generateReleaseCodeOwnersResources")?.outcome)
assertEquals(null, build.task(":app:generateReleaseUnitTestCodeOwnersResources")?.outcome)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.type.ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE
import org.gradle.api.artifacts.type.ArtifactTypeDefinition.JAR_TYPE
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.plugins.JvmEcosystemPlugin
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
Expand Down Expand Up @@ -41,19 +40,26 @@ class CodeOwnersPlugin : Plugin<Project> {
.convention(layout.projectDirectory)
.finalizeValueOnRead()

val defaultLocations = files(
"CODEOWNERS",
".github/CODEOWNERS",
".gitlab/CODEOWNERS",
"docs/CODEOWNERS",
)
codeOwnersFile
.convention(layout.file(provider {
files(
"CODEOWNERS",
".github/CODEOWNERS",
".gitlab/CODEOWNERS",
"docs/CODEOWNERS",
).asFileTree.singleFile
}))
.convention(layout.file(provider { defaultLocations.asFileTree.singleOrNull() }))
.finalizeValueOnRead()

codeOwners
.value(codeOwnersFile.asFile.map { file -> file.useLines { CodeOwnersFile(it) } })
.value(codeOwnersFile.asFile.map { file -> file.useLines { CodeOwnersFile(it) } }.orElse(provider {
error(
defaultLocations.joinToString(
prefix = "No CODEOWNERS file found! Default locations:\n",
separator = "\n"
) {
"- ${it.toRelativeString(rootDir)}"
})
}))
.apply { disallowChanges() }
.finalizeValueOnRead()
}
Expand Down Expand Up @@ -82,33 +88,23 @@ class CodeOwnersPlugin : Plugin<Project> {

objects.newInstance<CodeOwnersSourceSetImpl>(ss, generateTask).apply {
includeAsResources.convention(true).finalizeValueOnRead()
includeCoreDependency.convention(includeAsResources).finalizeValueOnRead()
includeCoreDependency.convention(true).finalizeValueOnRead()
}
}

private fun Project.bindSourceSets(
sourceSets: NamedDomainObjectContainer<CodeOwnersSourceSet>,
) = the<SourceSetContainer>().configureEach { ss ->
val sources = sourceSets.maybeCreate(ss.name)
sources.source(ss.java)
sources.generateTask {
runtimeClasspathResources.from(configurations[ss.runtimeClasspathConfigurationName].codeOwners)
}

addCoreDependency(sources, ss.implementationConfigurationName)
ss.resources.srcDir(sources.includeAsResources.map { if (it) sources.generateTask else files() })
ss.extensions.add(CodeOwnersSourceSet::class.java, extensionName, sources)

plugins.withId("kotlin") {
val kotlin: SourceDirectorySet by ss.extensions

sources.source(kotlin)
}

plugins.withId("groovy") {
val groovy: SourceDirectorySet by ss.extensions
) = plugins.withId("java-base") {
the<SourceSetContainer>().configureEach {
val sources = sourceSets.maybeCreate(it.name)
sources.source(it.allJava)
sources.generateTask {
runtimeClasspathResources.from(configurations[it.runtimeClasspathConfigurationName].codeOwners)
}

sources.source(groovy)
addCoreDependency(sources, it.implementationConfigurationName)
it.resources.srcDir(sources.includeAsResources.map { if (it) sources.generateTask else files() })
it.extensions.add(CodeOwnersSourceSet::class.java, extensionName, sources)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class CodeOwnersTask : DefaultTask() {
}

@TaskAction
fun generateCodeOwnersInfo(): Unit = with(project.layout) {
fun generateCodeOwnersInfo() {
val root = rootDirectory.asFile.get()
val outputDir = outputDirectory.get().apply { asFile.deleteRecursively() }
val claimed = mutableMapOf<CharSequence, CodeOwnersFile.Entry>()
Expand Down

0 comments on commit 6ad52f7

Please sign in to comment.