From 5153077d7331fd9f808cf4fa69cf5b74e8508833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Hu=CC=88sers?= Date: Fri, 24 Nov 2023 13:08:33 +0100 Subject: [PATCH 1/3] fix: Fix exception on empty VssDefinition asset file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the VssDefinition annotation is missing but the processor is executed then the necessary asset file can't be found. - Removes a redundant `maven-publish` plugin close #43 Signed-Off-By: Mark Hüsers --- vss-processor/build.gradle.kts | 1 - .../eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vss-processor/build.gradle.kts b/vss-processor/build.gradle.kts index bad60ce4..c7f46ca6 100644 --- a/vss-processor/build.gradle.kts +++ b/vss-processor/build.gradle.kts @@ -1,6 +1,5 @@ plugins { kotlin("jvm") - `maven-publish` publish } diff --git a/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt b/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt index b4a9a7f7..c189f632 100644 --- a/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt +++ b/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt @@ -85,7 +85,7 @@ class VssDefinitionProcessor( val vssDefinitionPath = vssDefinition.vssDefinitionPath val definitionFile = loadAssetFile(vssDefinitionPath) - if (!definitionFile.exists()) { + if (definitionFile == null || !definitionFile.exists()) { logger.error("No VSS definition file was found!") return } @@ -97,13 +97,14 @@ class VssDefinitionProcessor( } // Uses the default file path for generated files (from the code generator) and searches for the given file. - private fun loadAssetFile(fileName: String): File { - val generationPath = codeGenerator.generatedFile.first().absolutePath + private fun loadAssetFile(fileName: String): File? { + val generatedFile = codeGenerator.generatedFile.firstOrNull() ?: return null + val generationPath = generatedFile.absolutePath val buildPath = generationPath.replaceAfter(BUILD_FOLDER_NAME, "") val assetsFilePath = "$buildPath/$ASSETS_BUILD_DIRECTORY" val assetsFolder = File(assetsFilePath) - return assetsFolder.walk().first { it.name == fileName } + return assetsFolder.walk().firstOrNull { it.name == fileName } } private fun generateModelFiles(vssPathToSpecification: Map) { From 170bd3830cbe595ac192cdeee5816e9649f6bd11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Hu=CC=88sers?= Date: Fri, 24 Nov 2023 13:13:36 +0100 Subject: [PATCH 2/3] chore: Gracefully return if no annotation was found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-Off-By: Mark Hüsers --- .../org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt b/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt index c189f632..ae9436b1 100644 --- a/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt +++ b/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt @@ -81,7 +81,7 @@ class VssDefinitionProcessor( annotatedProcessorFileName, ) - val vssDefinition = classDeclaration.getAnnotationsByType(VssDefinition::class).first() + val vssDefinition = classDeclaration.getAnnotationsByType(VssDefinition::class).firstOrNull() ?: return val vssDefinitionPath = vssDefinition.vssDefinitionPath val definitionFile = loadAssetFile(vssDefinitionPath) From c0b4ebe575c144de08ac6007b8cb14f2ac063196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Hu=CC=88sers?= Date: Fri, 24 Nov 2023 14:10:10 +0100 Subject: [PATCH 3/3] chore: Only log info instead of error The current loadAssets workaround will result into a ksp error if only tasks like kspDebug are executed. The reason is that the build folder does not have the information from the assets folder (from the tests or apps build command) yet. --- .../org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt b/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt index ae9436b1..237a97f9 100644 --- a/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt +++ b/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/VssDefinitionProcessor.kt @@ -86,7 +86,7 @@ class VssDefinitionProcessor( val definitionFile = loadAssetFile(vssDefinitionPath) if (definitionFile == null || !definitionFile.exists()) { - logger.error("No VSS definition file was found!") + logger.info("No VSS definition file was found!") return } @@ -113,7 +113,7 @@ class VssDefinitionProcessor( .filter { it.value.size > 1 } .keys - logger.logging("Ambiguous specifications - Generate nested classes: $duplicateSpecificationNames") + logger.info("Ambiguous specifications - Generate nested classes: $duplicateSpecificationNames") for ((vssPath, specModel) in vssPathToSpecification) { // Every duplicate is produced as a nested class - No separate file should be generated