-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed tests actuals propagation * Fixed computation of owners per file * Fixed computation of owners per file * Fixed computation of owners per file
- Loading branch information
Showing
30 changed files
with
230 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
demo-project-kotlin/utils/src/main/kotlin/org/test/kotlin/utils/Rethrow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package org.test.kotlin.utils | ||
|
||
fun rethrow(throwable: () -> Throwable) { | ||
throw throwable() | ||
fun rethrow(throwable: Throwable) { | ||
throw throwable.javaClass.newInstance() | ||
} |
4 changes: 0 additions & 4 deletions
4
demo-project-kotlin/utils/src/main/kotlin/org/test/kotlin/utils/more/MoreUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
package org.test.kotlin.utils.more | ||
|
||
import io.github.gmazzo.codeowners.CodeOwners | ||
|
||
class MoreUtils { | ||
|
||
// manual override owners | ||
@CodeOwners("utils-more") | ||
companion object | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...st/resources/expectedReports/:demo-project-kotlin:app/app-androidDebugUnitTest.codeowners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# CodeOwners of module ':demo-project-kotlin:app' (source set 'androidDebugUnitTest') | ||
|
||
org/test/kotlin/app/AppException app-devs | ||
org/test/kotlin/app/AppOwnersTest app-devs | ||
org/test/kotlin/app/AppOwnersTest$ownerFromExceptionStacktrace$exception$1$1 app-devs | ||
org/test/kotlin/app/RethrowKt app-devs | ||
org/test/kotlin/app/AppException app-devs | ||
org/test/kotlin/app/AppOwnersTest app-devs | ||
org/test/kotlin/app/RethrowKt app-devs | ||
org/test/kotlin/app/RethrowUtils app-devs |
8 changes: 4 additions & 4 deletions
8
.../resources/expectedReports/:demo-project-kotlin:app/app-androidReleaseUnitTest.codeowners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# CodeOwners of module ':demo-project-kotlin:app' (source set 'androidReleaseUnitTest') | ||
|
||
org/test/kotlin/app/AppException app-devs | ||
org/test/kotlin/app/AppOwnersTest app-devs | ||
org/test/kotlin/app/AppOwnersTest$ownerFromExceptionStacktrace$exception$1$1 app-devs | ||
org/test/kotlin/app/RethrowKt app-devs | ||
org/test/kotlin/app/AppException app-devs | ||
org/test/kotlin/app/AppOwnersTest app-devs | ||
org/test/kotlin/app/RethrowKt app-devs | ||
org/test/kotlin/app/RethrowUtils app-devs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
...-tests/src/test/resources/expectedReports/:demo-project-kotlin:app/app-jvmTest.codeowners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# CodeOwners of module ':demo-project-kotlin:app' (source set 'jvmTest') | ||
|
||
org/test/kotlin/app/AppException app-devs | ||
org/test/kotlin/app/AppOwnersJVMTest app-devs | ||
org/test/kotlin/app/AppOwnersJVMTest$ownerOfUtilFunctions$1 app-devs | ||
org/test/kotlin/app/AppOwnersTest app-devs | ||
org/test/kotlin/app/AppOwnersTest$ownerFromExceptionStacktrace$exception$1$1 app-devs | ||
org/test/kotlin/app/RethrowKt app-devs | ||
org/test/kotlin/app/AppException app-devs | ||
org/test/kotlin/app/AppOwnersJVMTest app-devs | ||
org/test/kotlin/app/AppOwnersJVMTest$ownerOfUtilFunctions$1 app-devs | ||
org/test/kotlin/app/AppOwnersTest app-devs | ||
org/test/kotlin/app/RethrowKt app-devs | ||
org/test/kotlin/app/RethrowUtils app-devs |
20 changes: 10 additions & 10 deletions
20
...-project-tests/src/test/resources/expectedReports/:demo-project-kotlin:app/app.codeowners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# CodeOwners of module ':demo-project-kotlin:app' | ||
|
||
org/test/kotlin/app/AppClass app-devs | ||
org/test/kotlin/app/AppException app-devs | ||
org/test/kotlin/app/AppOwnersJVMTest app-devs | ||
org/test/kotlin/app/AppOwnersJVMTest$ownerOfUtilFunctions$1 app-devs | ||
org/test/kotlin/app/AppOwnersTest app-devs | ||
org/test/kotlin/app/AppOwnersTest$ownerFromExceptionStacktrace$exception$1$1 app-devs | ||
org/test/kotlin/app/BuildConfig app-devs | ||
org/test/kotlin/app/RethrowKt app-devs | ||
org/test/kotlin/app/test/BuildConfig app-devs | ||
org/test/kotlin/utils/AppUtils app-devs | ||
org/test/kotlin/app/AppClass app-devs | ||
org/test/kotlin/app/AppException app-devs | ||
org/test/kotlin/app/AppOwnersJVMTest app-devs | ||
org/test/kotlin/app/AppOwnersJVMTest$ownerOfUtilFunctions$1 app-devs | ||
org/test/kotlin/app/AppOwnersTest app-devs | ||
org/test/kotlin/app/BuildConfig app-devs | ||
org/test/kotlin/app/RethrowKt app-devs | ||
org/test/kotlin/app/RethrowUtils app-devs | ||
org/test/kotlin/app/test/BuildConfig app-devs | ||
org/test/kotlin/utils/AppUtils app-devs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...r/src/main/kotlin/io/github/gmazzo/codeowners/compiler/CodeOwnersFirExtensionRegistrar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.gmazzo.codeowners.compiler | ||
|
||
import org.jetbrains.kotlin.fir.FirSession | ||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar | ||
|
||
class CodeOwnersFirExtensionRegistrar( | ||
private val mappings: CodeOwnersMappings, | ||
) : FirExtensionRegistrar() { | ||
|
||
override fun ExtensionRegistrarContext.configurePlugin() { | ||
+{ session: FirSession -> CodeOwnersFirProcessor(session, mappings) } | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...n-compiler/src/main/kotlin/io/github/gmazzo/codeowners/compiler/CodeOwnersFirProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.github.gmazzo.codeowners.compiler | ||
|
||
import org.jetbrains.kotlin.backend.common.serialization.toIoFileOrNull | ||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter | ||
import org.jetbrains.kotlin.fir.FirElement | ||
import org.jetbrains.kotlin.fir.FirSession | ||
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind | ||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext | ||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.DeclarationCheckers | ||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirFileChecker | ||
import org.jetbrains.kotlin.fir.analysis.extensions.FirAdditionalCheckersExtension | ||
import org.jetbrains.kotlin.fir.declarations.FirFile | ||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass | ||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction | ||
import org.jetbrains.kotlin.fir.declarations.utils.classId | ||
import org.jetbrains.kotlin.fir.java.findJvmNameValue | ||
import org.jetbrains.kotlin.fir.packageFqName | ||
import org.jetbrains.kotlin.fir.visitors.FirVisitor | ||
import org.jetbrains.kotlin.name.Name | ||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName | ||
|
||
class CodeOwnersFirProcessor( | ||
session: FirSession, | ||
private val mappings: CodeOwnersMappings, | ||
) : FirAdditionalCheckersExtension(session) { | ||
|
||
override val declarationCheckers = object : DeclarationCheckers() { | ||
override val fileCheckers = setOf(CodeOwnersMapper()) | ||
} | ||
|
||
inner class CodeOwnersMapper : FirFileChecker(MppCheckerKind.Platform) { | ||
override fun check(declaration: FirFile, context: CheckerContext, reporter: DiagnosticReporter) { | ||
val mappings = declaration.sourceFile?.toIoFileOrNull()?.let(mappings::resolve) ?: return | ||
|
||
declaration.accept(fileVisitor, mappings) | ||
} | ||
} | ||
|
||
private val fileVisitor = object : FirVisitor<Unit, CodeOwnersMappings.Mapping>() { | ||
|
||
override fun visitFile(file: FirFile, data: CodeOwnersMappings.Mapping) { | ||
file.acceptChildren(this, data) | ||
|
||
if (file.declarations.any { it is FirSimpleFunction }) { | ||
val fileJvmName = file.findJvmNameValue() ?: file.name.replace("\\.kt".toRegex(), "Kt") | ||
val fileClass = JvmClassName.byFqNameWithoutInnerClasses(file.packageFqName.child(Name.identifier(fileJvmName))).internalName | ||
|
||
data.classes += fileClass | ||
} | ||
} | ||
|
||
override fun visitRegularClass(regularClass: FirRegularClass, data: CodeOwnersMappings.Mapping) { | ||
data.classes += JvmClassName.byClassId(regularClass.classId).internalName | ||
|
||
regularClass.acceptChildren(this, data) | ||
} | ||
|
||
override fun visitElement(element: FirElement, data: CodeOwnersMappings.Mapping) { | ||
} | ||
|
||
} | ||
|
||
} |
25 changes: 7 additions & 18 deletions
25
...r/src/main/kotlin/io/github/gmazzo/codeowners/compiler/CodeOwnersIrGenerationExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,23 @@ | ||
package io.github.gmazzo.codeowners.compiler | ||
|
||
import io.github.gmazzo.codeowners.matcher.CodeOwnersFile | ||
import io.github.gmazzo.codeowners.matcher.CodeOwnersMatcher | ||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension | ||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext | ||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment | ||
import java.io.File | ||
|
||
internal class CodeOwnersIrGenerationExtension( | ||
private val matcher: CodeOwnersMatcher, | ||
private val mappingsFile: File?, | ||
private val mappings: CodeOwnersMappings, | ||
) : IrGenerationExtension { | ||
|
||
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { | ||
val mappings = mappingsFile?.let { mutableMapOf<String, MutableSet<String>>() } | ||
val transformer = CodeOwnersIrTransformer(pluginContext, mappings) | ||
val owners = moduleFragment.files.asSequence() | ||
.flatMap { matcher.ownerOf(File(it.fileEntry.name)).orEmpty() } | ||
.toSet() | ||
mappings.noteFrontedFinished() | ||
|
||
if (owners.isNotEmpty()) { | ||
moduleFragment.accept(transformer, owners) | ||
val transformer = CodeOwnersIrTransformer(pluginContext, mappings) | ||
|
||
if (mappings != null) { | ||
val entries = mappings.map { (file, owners) -> CodeOwnersFile.Entry(file, owners.toList()) } | ||
val codeOwners = CodeOwnersFile(entries) | ||
moduleFragment.accept(transformer, InvalidOwners) | ||
} | ||
|
||
mappingsFile!!.appendText(codeOwners.content) | ||
} | ||
} | ||
private data object InvalidOwners : Set<String> by emptySet() { | ||
override val size: Int get() = error("Invalid owners") | ||
} | ||
|
||
} |
Oops, something went wrong.