Skip to content

Commit

Permalink
Fixed issues after merging with .jvm approach
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo committed Dec 20, 2023
1 parent f6c2dc9 commit a81c26b
Show file tree
Hide file tree
Showing 23 changed files with 118 additions and 252 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle/
.idea/
build/
kotlin-js-store/
10 changes: 10 additions & 0 deletions demo-project/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.multiplatform)
Expand Down Expand Up @@ -39,3 +42,10 @@ dependencies {

commonTestImplementation(libs.kotlin.test)
}

tasks.withType<KotlinJsIrLink>().configureEach {
notCompatibleWithConfigurationCache("uses Task.project")
}
tasks.withType<KotlinNativeLink>().configureEach {
notCompatibleWithConfigurationCache("uses Task.project")
}
5 changes: 0 additions & 5 deletions demo-project/lib2/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
plugins {
<<<<<<<< HEAD:plugin/jvm-plugin/src/integrationTest/resources/project/lib2/build.gradle.kts
id("com.android.library")
id("io.github.gmazzo.codeowners.jvm")
========
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
id("io.github.gmazzo.codeowners.kotlin")
>>>>>>>> 91353a5 (Changed plugin id to `io.github.gmazzo.codeowners.kotlin`):demo-project/lib2/build.gradle.kts
}

android {
Expand Down
6 changes: 3 additions & 3 deletions plugin/jvm-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.samWithReceiver)
alias(libs.plugins.buildConfig)
alias(libs.plugins.gradle.pluginPublish)
com.github.gmazzo.buildconfig
`java-integration-tests`
`maven-central-publish`
jacoco
Expand All @@ -23,14 +23,14 @@ dependencies {
plugin.map { create("${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}") }

compileOnly(gradleKotlinDsl())
compileOnly(plugin(libs.plugins.android))
compileOnly(plugin(libs.plugins.android.application))

implementation(libs.jgit)

testImplementation(gradleKotlinDsl())
testRuntimeOnly(plugin(libs.plugins.kotlin.jvm))

pluginUnderTestImplementation(plugin(libs.plugins.android))
pluginUnderTestImplementation(plugin(libs.plugins.android.application))
pluginUnderTestImplementation(plugin(libs.plugins.kotlin.jvm))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package org.test.app

object AppClass
class AppClass {
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
plugins {
<<<<<<<< HEAD:plugin/jvm-plugin/src/integrationTest/resources/project/lib2/build.gradle.kts
id("com.android.library")
id("io.github.gmazzo.codeowners.jvm")
========
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
id("io.github.gmazzo.codeowners.kotlin")
>>>>>>>> 91353a5 (Changed plugin id to `io.github.gmazzo.codeowners.kotlin`):demo-project/lib2/build.gradle.kts
}

android {
Expand All @@ -21,7 +15,9 @@ android {
}

dependencies {
implementation(projects.demoProject.lib1)
implementation(project(":utils"))
}

testImplementation(libs.kotlin.test)
androidComponents.onVariants {
it.unitTest!!.codeOwners.enabled.set(false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import org.junit.Test;
import org.test.utils.more.MoreUtils;

import static io.github.gmazzo.codeowners.CodeOwnersUtils.getCodeOwners;
import static kotlin.collections.SetsKt.setOf;
import static io.github.gmazzo.codeowners.CodeOwners.getCodeOwners;
import static org.junit.Assert.assertEquals;
import static kotlin.collections.SetsKt.setOf;

public class UtilsOwnersTest {

Expand All @@ -17,7 +17,6 @@ public void ownerOfUtils() {
@Test
public void ownerOfMoreUtils() {
assertEquals(setOf("utils-devs"), getCodeOwners(MoreUtils.class));
assertEquals(setOf("utils-more"), getCodeOwners(MoreUtils.Companion.class));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.gmazzo.codeowners

import io.github.gmazzo.codeowners.matcher.CodeOwnersFile
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package io.github.gmazzo.codeowners
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.Component
import com.android.build.api.variant.HasAndroidTest
import io.github.gmazzo.codeowners.matcher.CodeOwnersFile
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.gmazzo.codeowners

import io.github.gmazzo.codeowners.matcher.CodeOwnersFile
import org.eclipse.jgit.ignore.FastIgnoreRule
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.gmazzo.codeowners

import io.github.gmazzo.codeowners.matcher.CodeOwnersFile
import org.gradle.api.artifacts.transform.CacheableTransform
import org.gradle.api.artifacts.transform.InputArtifact
import org.gradle.api.artifacts.transform.TransformAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.gmazzo.codeowners
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.exclude
import org.gradle.kotlin.dsl.withType
import org.gradle.testfixtures.ProjectBuilder
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
Expand All @@ -11,11 +12,7 @@ import java.io.File
import kotlin.test.assertEquals

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
<<<<<<<< HEAD:plugin/jvm-plugin/src/test/kotlin/io/github/gmazzo/codeowners/CodeOwnersJVMPluginTest.kt
class CodeOwnersJVMPluginTest {
========
class CodeOwnersKotlinPluginTest {
>>>>>>>> 91353a5 (Changed plugin id to `io.github.gmazzo.codeowners.kotlin`):plugin/kotlin-plugin/src/test/kotlin/io/github/gmazzo/codeowners/CodeOwnersKotlinPluginTest.kt

private val root = ProjectBuilder.builder()
.withName("root")
Expand Down Expand Up @@ -51,11 +48,7 @@ class CodeOwnersKotlinPluginTest {

root.allprojects {
apply(plugin = "java")
<<<<<<<< HEAD:plugin/jvm-plugin/src/test/kotlin/io/github/gmazzo/codeowners/CodeOwnersJVMPluginTest.kt
apply<CodeOwnersJVMPlugin>()
========
apply<CodeOwnersKotlinPlugin>()
>>>>>>>> 91353a5 (Changed plugin id to `io.github.gmazzo.codeowners.kotlin`):plugin/kotlin-plugin/src/test/kotlin/io/github/gmazzo/codeowners/CodeOwnersKotlinPluginTest.kt

repositories.mavenCentral()
configurations.configureEach {
Expand Down
10 changes: 10 additions & 0 deletions plugin/kotlin-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink

plugins {
alias(libs.plugins.kotlin.multiplatform)
`jvm-convention-module`
Expand All @@ -18,3 +21,10 @@ dependencies {
commonTestImplementation(libs.kotlin.test)
commonTestImplementation(platform(libs.junit.bom))
}

tasks.withType<KotlinJsIrLink>().configureEach {
notCompatibleWithConfigurationCache("uses Task.project")
}
tasks.withType<KotlinNativeLink>().configureEach {
notCompatibleWithConfigurationCache("uses Task.project")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.test

import io.github.gmazzo.codeowners.CodeOwners

@CodeOwners("baz")
class AnotherBaz
6 changes: 6 additions & 0 deletions plugin/kotlin-core/src/commonTest/kotlin/org.test/Bar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.test

import io.github.gmazzo.codeowners.CodeOwners

@CodeOwners("bar")
abstract class Bar
15 changes: 15 additions & 0 deletions plugin/kotlin-core/src/commonTest/kotlin/org.test/BarImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.test

import io.github.gmazzo.codeowners.CodeOwners

@CodeOwners("bar")
object BarImpl : Bar() {

@CodeOwners("bar-inner")
object Inner {
fun throwException() {
error("Bar")
}
}

}
9 changes: 9 additions & 0 deletions plugin/kotlin-core/src/commonTest/kotlin/org.test/Baz.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@file:CodeOwners("baz")
package org.test

import io.github.gmazzo.codeowners.CodeOwners

@CodeOwners("baz")
class Baz

fun baz() = println("baz")
6 changes: 6 additions & 0 deletions plugin/kotlin-core/src/commonTest/kotlin/org.test/Foo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.test

import io.github.gmazzo.codeowners.CodeOwners

@CodeOwners("foo")
interface Foo
6 changes: 6 additions & 0 deletions plugin/kotlin-core/src/commonTest/kotlin/org.test/FooImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.test

import io.github.gmazzo.codeowners.CodeOwners

@CodeOwners("foo")
object FooImpl : Foo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package io.github.gmazzo.codeowners

import java.lang.reflect.Proxy
import kotlin.reflect.KClass
import kotlin.reflect.KFunction
import kotlin.reflect.jvm.javaMethod
Expand All @@ -10,7 +11,10 @@ actual val KClass<*>.codeOwners: Set<String>?
get() = java.codeOwners

val Class<*>.codeOwners: Set<String>?
get() = getAnnotation(CodeOwners::class.java)?.owners?.toSet()
get() = when {
Proxy.isProxyClass(this) -> resolveInterfacesIfProxy().mapNotNull { it.codeOwners }.flatten().toSet()
else -> getAnnotation(CodeOwners::class.java)?.owners?.toSet()
}

val KFunction<*>.codeOwners: Set<String>?
get() = javaMethod?.declaringClass?.codeOwners
Expand All @@ -27,3 +31,8 @@ private fun StackTraceElement.getCodeOwners(classLoader: ClassLoader) = try {
} catch (e: Throwable) {
null
}

private fun Class<*>.resolveInterfacesIfProxy() = when {
!Proxy.isProxyClass(this) -> sequenceOf(this)
else -> interfaces.asSequence()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package io.github.gmazzo.codeowners

import org.test.*
import org.test.AnotherBaz
import org.test.Bar
import org.test.BarImpl
import org.test.Baz
import org.test.Foo
import org.test.FooImpl
import org.test.baz
import java.lang.reflect.Proxy
import kotlin.test.Test
import kotlin.test.assertEquals

// it only applies to JVM as annotations are not available on other targets
class CodeOwnersTest {

@Test
Expand All @@ -16,7 +24,7 @@ class CodeOwnersTest {
fun reports_Bar_owners_correctly() {
assertEquals(setOf("bar"), codeOwnersOf<Bar>())
assertEquals(setOf("bar"), BarImpl::class.codeOwners)
assertEquals(setOf("bar"), codeOwnersOf<BarImpl.Inner>())
assertEquals(setOf("bar-inner"), codeOwnersOf<BarImpl.Inner>())
}

@Test
Expand All @@ -31,7 +39,19 @@ class CodeOwnersTest {

val exception = runCatching { myFun() }.exceptionOrNull()

assertEquals(setOf("bar"), exception?.codeOwners)
assertEquals(setOf("bar-inner"), exception?.codeOwners)
}

@Test
fun `reports_proxy_of_Foo_owners_correctly`() {
val proxy = Proxy.newProxyInstance(javaClass.classLoader, arrayOf(Foo::class.java)) { _, _, _ -> }

assertEquals(setOf("foo"), proxy::class.codeOwners)
}

@Test
fun `reports_baz_function_owners_correctly`() {
assertEquals(setOf("baz"), ::baz.codeOwners)
}

}
Loading

0 comments on commit a81c26b

Please sign in to comment.