From 34d835c32a9ffc3c90c99ea1e91c701e0419e83c Mon Sep 17 00:00:00 2001 From: stefankoppier Date: Sat, 16 Nov 2024 17:04:37 +0100 Subject: [PATCH 1/5] Fixed bug --- .../src/main/kotlin/tech/mappie/MappieGradlePlugin.kt | 10 +--------- gradle.properties | 2 +- website/src/changelog.md | 4 ++++ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/tech/mappie/MappieGradlePlugin.kt b/gradle-plugin/src/main/kotlin/tech/mappie/MappieGradlePlugin.kt index aa031e79..a819865d 100644 --- a/gradle-plugin/src/main/kotlin/tech/mappie/MappieGradlePlugin.kt +++ b/gradle-plugin/src/main/kotlin/tech/mappie/MappieGradlePlugin.kt @@ -1,7 +1,6 @@ package tech.mappie import org.gradle.api.Project -import org.gradle.api.artifacts.Dependency import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.plugin.* import java.util.* @@ -50,19 +49,12 @@ class MappieGradlePlugin : KotlinCompilerPluginSupportPlugin { override fun isApplicable(kotlinCompilation: KotlinCompilation<*>) = kotlinCompilation.target.project.run { - hasMappiePlugin() && hasMappieDependency(kotlinCompilation) + hasMappiePlugin() } private fun Project.hasMappiePlugin() = plugins.hasPlugin(MappieGradlePlugin::class.java) - private fun Project.hasMappieDependency(kotlinCompilation: KotlinCompilation<*>): Boolean = - runCatching { getMappieDependency(kotlinCompilation) != null }.getOrElse { false } - - private fun Project.getMappieDependency(kotlinCompilation: KotlinCompilation<*>): Dependency? = - configurations.getByName(kotlinCompilation.runtimeDependencyConfigurationName ?: "implementation") - .allDependencies.first { it.group == "tech.mappie" && it.name == "mappie-api" } - private fun Project.checkCompatibility() { val version = getKotlinPluginVersion() if (SUPPORTED_KOTLIN_VERSIONS.none { regex -> regex.matches(version) }) { diff --git a/gradle.properties b/gradle.properties index dabad179..d12cae79 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.9.0 \ No newline at end of file +version=0.9.1 \ No newline at end of file diff --git a/website/src/changelog.md b/website/src/changelog.md index 4c9e928c..9100ef96 100644 --- a/website/src/changelog.md +++ b/website/src/changelog.md @@ -2,6 +2,10 @@ title: "Changelog" layout: "layouts/changelog.html" changelog: + - date: "2024-11-16" + title: "v0.9.1" + items: + - "[#129](https://github.com/Mr-Mappie/mappie/issues/129) fixed bug where mappie will run when the mappie-api comes in as a transitive dependency." - date: "2024-11-16" title: "v0.9.0" items: From 63481da4cca3378ed73e6d23e5f2a269760b54b3 Mon Sep 17 00:00:00 2001 From: stefankoppier Date: Sat, 16 Nov 2024 17:09:21 +0100 Subject: [PATCH 2/5] Typo in changelog --- website/src/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/changelog.md b/website/src/changelog.md index 9100ef96..5cd4c431 100644 --- a/website/src/changelog.md +++ b/website/src/changelog.md @@ -5,7 +5,7 @@ changelog: - date: "2024-11-16" title: "v0.9.1" items: - - "[#129](https://github.com/Mr-Mappie/mappie/issues/129) fixed bug where mappie will run when the mappie-api comes in as a transitive dependency." + - "[#129](https://github.com/Mr-Mappie/mappie/issues/129) fixed bug where mappie will not run when the mappie-api comes in as a transitive dependency." - date: "2024-11-16" title: "v0.9.0" items: From 248fca91aa3b57c19bc6e07e08e29e95fdc41be0 Mon Sep 17 00:00:00 2001 From: stefankoppier Date: Mon, 18 Nov 2024 08:39:31 +0100 Subject: [PATCH 3/5] Test fix --- .../kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler-plugin/src/main/kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt b/compiler-plugin/src/main/kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt index acde5c55..4c811e87 100644 --- a/compiler-plugin/src/main/kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt +++ b/compiler-plugin/src/main/kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi import org.jetbrains.kotlin.config.CompilerConfiguration import tech.mappie.MappieCommandLineProcessor.Companion.ARGUMENT_USE_DEFAULT_ARGUMENTS import tech.mappie.MappieCommandLineProcessor.Companion.ARGUMENT_WARNINGS_AS_ERRORS +import tech.mappie.api.ObjectMappie import tech.mappie.config.MappieConfiguration import tech.mappie.config.StrictnessConfiguration @@ -19,6 +20,10 @@ class MappieCompilerPluginRegistrar : CompilerPluginRegistrar() { override val supportsK2: Boolean = true override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { + if (!isApplicable()) { + return + } + val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) IrGenerationExtension.registerExtension( MappieIrRegistrar( @@ -34,4 +39,7 @@ class MappieCompilerPluginRegistrar : CompilerPluginRegistrar() { ) ) } + + private fun isApplicable() = + runCatching { ObjectMappie::class.java }.map { true }.getOrElse { false } } From d9cfd5ca2df3a2338b7b04d665e99074b8d281b0 Mon Sep 17 00:00:00 2001 From: stefankoppier Date: Mon, 18 Nov 2024 09:24:01 +0100 Subject: [PATCH 4/5] Fix null pointer --- .../kotlin/tech/mappie/preprocessing/DefinitionsCollector.kt | 3 ++- gradle.properties | 2 +- website/src/changelog.md | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler-plugin/src/main/kotlin/tech/mappie/preprocessing/DefinitionsCollector.kt b/compiler-plugin/src/main/kotlin/tech/mappie/preprocessing/DefinitionsCollector.kt index f1c53335..6c786512 100644 --- a/compiler-plugin/src/main/kotlin/tech/mappie/preprocessing/DefinitionsCollector.kt +++ b/compiler-plugin/src/main/kotlin/tech/mappie/preprocessing/DefinitionsCollector.kt @@ -26,7 +26,8 @@ class DefinitionsCollector(val context: MappieContext) { class BuiltinMappieDefinitionsCollector(val context: MappieContext) { fun collect() = MAPPERS - .map { name -> context.pluginContext.referenceClass(ClassId(FqName(PACKAGE), Name.identifier(name)))!!.owner } + .map { name -> context.pluginContext.referenceClass(ClassId(FqName(PACKAGE), Name.identifier(name)))?.owner } + .filterNotNull() .map { MappieDefinition(it) } companion object { diff --git a/gradle.properties b/gradle.properties index d12cae79..6177143b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.9.1 \ No newline at end of file +version=0.9.2 \ No newline at end of file diff --git a/website/src/changelog.md b/website/src/changelog.md index 5cd4c431..509950b4 100644 --- a/website/src/changelog.md +++ b/website/src/changelog.md @@ -2,6 +2,10 @@ title: "Changelog" layout: "layouts/changelog.html" changelog: + - date: "2024-11-18" + title: "v0.9.2" + items: + - "Fixed null pointer in some cases." - date: "2024-11-16" title: "v0.9.1" items: From e6e00395686809491f77c5729f80dc7491594d76 Mon Sep 17 00:00:00 2001 From: stefankoppier Date: Mon, 18 Nov 2024 09:25:12 +0100 Subject: [PATCH 5/5] Fix null pointer --- .../kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/compiler-plugin/src/main/kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt b/compiler-plugin/src/main/kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt index 4c811e87..ae694b7a 100644 --- a/compiler-plugin/src/main/kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt +++ b/compiler-plugin/src/main/kotlin/tech/mappie/MappieCompilerPluginRegistrar.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi import org.jetbrains.kotlin.config.CompilerConfiguration import tech.mappie.MappieCommandLineProcessor.Companion.ARGUMENT_USE_DEFAULT_ARGUMENTS import tech.mappie.MappieCommandLineProcessor.Companion.ARGUMENT_WARNINGS_AS_ERRORS -import tech.mappie.api.ObjectMappie import tech.mappie.config.MappieConfiguration import tech.mappie.config.StrictnessConfiguration @@ -20,9 +19,6 @@ class MappieCompilerPluginRegistrar : CompilerPluginRegistrar() { override val supportsK2: Boolean = true override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { - if (!isApplicable()) { - return - } val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) IrGenerationExtension.registerExtension( @@ -39,7 +35,4 @@ class MappieCompilerPluginRegistrar : CompilerPluginRegistrar() { ) ) } - - private fun isApplicable() = - runCatching { ObjectMappie::class.java }.map { true }.getOrElse { false } }