diff --git a/.github/workflows/deploy-snapshot.yaml b/.github/workflows/deploy-snapshot.yaml index 89c05d83..e2288bb1 100644 --- a/.github/workflows/deploy-snapshot.yaml +++ b/.github/workflows/deploy-snapshot.yaml @@ -5,7 +5,7 @@ concurrency: snapshot on: push: branches: - - main + - feature-45-work jobs: deployment: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ed65af46..285c2d96 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -19,9 +19,7 @@ @file:Suppress("UnstableApiUsage") -import com.google.devtools.ksp.gradle.KspTask import org.eclipse.kuksa.property.PropertiesLoader -import org.eclipse.kuksa.vssprocessor.plugin.ProvideVssDefinitionTask plugins { id("com.android.application") @@ -126,14 +124,9 @@ android { } } -tasks.register("ProvideVssDefinition") { - val vssDefinitionFilePath = "$projectDir/src/main/assets/vss_rel_4.0.yaml" - val regularFile = RegularFile { File(vssDefinitionFilePath) } - vssDefinitionFile.add(regularFile) -} - -tasks.withType { - dependsOn(tasks.withType()) +vssProcessor { + searchPath = "$projectDir/src/main/assets" + fileName = "vss_rel_4.0.yaml" } tasks.withType().configureEach { diff --git a/build.gradle.kts b/build.gradle.kts index 7ff5817d..72ec308b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -83,3 +83,33 @@ tasks.register("mergeDashFiles") { } } } + +// Tasks for included composite builds need to be called separately. For convenience sake we depend on the most used +// tasks. Every task execution of the main project will then be forwarded to the included build project. +// +// We have to manually define the task names because the task() method of the included build throws an error for any +// unknown task. +val dependentCompositeTasks = setOf( + "setSnapshotVersion", + "setReleaseVersion", + "publishToMavenLocal", + "publishAllPublicationsToOSSRHSnapshotRepository", + "publishAllPublicationsToOSSRHReleaseRepository", +) + +gradle.projectsEvaluated { + val subProjectTasks = tasks + subprojects.flatMap { it.tasks } + + subProjectTasks + .filter { dependentCompositeTasks.contains(it.name) } + .forEach { task -> + val compositeTask = gradle.includedBuilds.map { compositeBuild -> + val compositeTaskPath = task.path.substringAfterLast(":") + println("Linking composite task - ${compositeBuild.name} <-> ${task.project}:${task.name}") + + compositeBuild.task(":$compositeTaskPath") + } + + task.dependsOn(compositeTask) + } +} diff --git a/kuksa-sdk/build.gradle.kts b/kuksa-sdk/build.gradle.kts index 975726d9..d26ed2ce 100644 --- a/kuksa-sdk/build.gradle.kts +++ b/kuksa-sdk/build.gradle.kts @@ -92,7 +92,7 @@ dependencies { testImplementation(libs.mockk) } -configure { +publish { mavenPublicationName = "release" componentName = "release" description = "Android Connectivity Library for the KUKSA Databroker" @@ -123,25 +123,4 @@ protobuf { } } -// Tasks for included composite builds need to be called separately. For convenience sake we depend on the most used -// tasks. Every task execution of the main project will then be forwarded to the included build project. -// -// We have to manually define the task names because the task() method of the included build throws an error for any -// unknown task. -val dependentCompositeTasks = setOf( - "setSnapshotVersion", - "setReleaseVersion", - "publishToMavenLocal", - "publishAllPublicationsToOSSRHSnapshotRepository", - "publishAllPublicationsToOSSRHReleaseRepository", -) -tasks - .filter { dependentCompositeTasks.contains(it.name) } - .forEach { task -> - val compositeTask = gradle.includedBuilds.map { compositeBuild -> - val compositeTaskPath = task.path.substringAfter(":kuksa-sdk") - compositeBuild.task(compositeTaskPath) - } - task.dependsOn(compositeTask) - } diff --git a/samples/build.gradle.kts b/samples/build.gradle.kts index b553fa64..be77d87c 100644 --- a/samples/build.gradle.kts +++ b/samples/build.gradle.kts @@ -1,6 +1,3 @@ -import com.google.devtools.ksp.gradle.KspTask -import org.eclipse.kuksa.vssprocessor.plugin.ProvideVssDefinitionTask - /* * Copyright (c) 2023 Contributors to the Eclipse Foundation * @@ -58,14 +55,9 @@ android { } } -tasks.register("ProvideVssDefinition") { - val vssDefinitionFilePath = "$projectDir/src/main/assets/vss_rel_4.0.yaml" - val regularFile = RegularFile { File(vssDefinitionFilePath) } - vssDefinitionFile.add(regularFile) -} - -tasks.withType { - dependsOn(tasks.withType()) +vssProcessor { + searchPath = "$projectDir/src/main/assets" + fileName = "vss_rel_4.0.yaml" } dependencies { diff --git a/vss-core/build.gradle.kts b/vss-core/build.gradle.kts index bc5ce547..8896e09a 100644 --- a/vss-core/build.gradle.kts +++ b/vss-core/build.gradle.kts @@ -48,7 +48,7 @@ tasks.withType().configureEach { } } -configure { +publish { mavenPublicationName = "release" componentName = "java" description = "Vehicle Signal Specification (VSS) Core Module of the KUKSA SDK" diff --git a/vss-processor-plugin/build.gradle.kts b/vss-processor-plugin/build.gradle.kts index c6460623..e373bab5 100644 --- a/vss-processor-plugin/build.gradle.kts +++ b/vss-processor-plugin/build.gradle.kts @@ -46,6 +46,6 @@ dependencies { implementation(kotlin("stdlib")) } -configure { +publish { description = "Vehicle Signal Specification (VSS) Plugin of the KUKSA SDK" } diff --git a/vss-processor-plugin/src/main/java/org/eclipse/kuksa/vssprocessor/plugin/VssProcessorPlugin.kt b/vss-processor-plugin/src/main/java/org/eclipse/kuksa/vssprocessor/plugin/VssProcessorPlugin.kt index 86807b26..de7d828d 100644 --- a/vss-processor-plugin/src/main/java/org/eclipse/kuksa/vssprocessor/plugin/VssProcessorPlugin.kt +++ b/vss-processor-plugin/src/main/java/org/eclipse/kuksa/vssprocessor/plugin/VssProcessorPlugin.kt @@ -22,40 +22,144 @@ import org.gradle.api.DefaultTask import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.RegularFile +import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.ListProperty +import org.gradle.api.provider.Property import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.TaskAction +import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.register import java.io.File +import javax.inject.Inject +open class VssProcessorPluginExtension +@Inject +internal constructor(objectFactory: ObjectFactory) { + val searchPath: Property = objectFactory.property(String::class.java).convention("") + val fileName: Property = objectFactory.property(String::class.java).convention("") +} + +/** + * This Plugin searches for compatible specification files and copies them into an input folder for the + * KSP VSS Processor. This is necessary because the Symbol Processor does not have access to the android assets folder. + * The default search path is the main assets folder. + * + */ class VssProcessorPlugin : Plugin { override fun apply(project: Project) { - // Configuration done by the custom task + val extension = project.extensions.create(EXTENSION_NAME) + + val buildDirPath = project.buildDir.absolutePath + val mainAssetsDirectory = "${project.projectDir}${fileSeparator}$mainAssetsDirectory" + val searchDirectory = extension.searchPath.get().ifEmpty { mainAssetsDirectory } + + val compatibleFiles = findFiles( + directory = searchDirectory, + fileName = extension.fileName.get(), + validExtensions = compatibleExtensions + ) + +// compatibleFiles.forEach { vssDefinitionInputFile -> +// val vssDefinitionBuildFile = File( +// "$buildDirPath$fileSeparator" + +// "${KSP_INPUT_BUILD_DIRECTORY}$fileSeparator" + +// vssDefinitionInputFile.name, +// ) +// +//// println( +//// "Found VSS definition input file: ${vssDefinitionInputFile.name}, " + +//// "copying to: $vssDefinitionBuildFile", +//// ) +// +// vssDefinitionInputFile.copyTo(vssDefinitionBuildFile, true) +// } + + val provideVssDefinitionTask = project.tasks.register("ProvideVssDefinition") { + compatibleFiles.forEach { definitionFile -> + val regularFile = RegularFile { definitionFile } + vssDefinitionFiles.add(regularFile) + } + } + + project.tasks.getByName("preBuild").finalizedBy( + provideVssDefinitionTask.get() + ) + +// project.afterEvaluate { + project.tasks.forEach { +// println("HIHI $it") +// } + } + +// provideVssDefinitionTask.get(). + } + + private fun findFiles( + directory: String, + fileName: String = "", + validExtensions: Collection, + ): Sequence { + val mainAssetsFolder = File(directory) + + return mainAssetsFolder + .walk() + .filter { validExtensions.contains(it.extension) } + .filter { file -> + if (fileName.isEmpty()) return@filter true + + file.name == fileName + } + } + + companion object { + private const val EXTENSION_NAME = "vssProcessor" + + private val compatibleExtensions = setOf("yaml") + private val fileSeparator = File.separator + private val mainAssetsDirectory = "src$fileSeparator" + "main$fileSeparator" + "assets" } } -/** - * This task takes a list of files and copies them into an input folder for the KSP VSS Processor. This is necessary - * because the Symbol Processor does not have access to the android assets folder. - */ abstract class ProvideVssDefinitionTask : DefaultTask() { @get:InputFiles - abstract val vssDefinitionFile: ListProperty + abstract val vssDefinitionFiles: ListProperty @TaskAction fun provideFile() { +// val buildDirPath = project.buildDir.absolutePath +// val mainAssets = "${project.projectDir}$fileSeparator$mainAssetsDirectory" +// val mainAssetsFolder = File(mainAssets) + +// mainAssetsFolder +// .walk() +// .filter { compatibleExtensions.contains(it.extension) } +// .forEach { vssDefinitionInputFile -> +// val vssDefinitionBuildFile = File( +// "$buildDirPath$fileSeparator" + +// "$KSP_INPUT_BUILD_DIRECTORY$fileSeparator" + +// vssDefinitionInputFile.name, +// ) +// +// println( +// "Found VSS definition input file: ${vssDefinitionInputFile.name}, " + +// "copying to: $vssDefinitionBuildFile", +// ) +// +// vssDefinitionInputFile.copyTo(vssDefinitionBuildFile, true) +// } + val buildDirPath = project.buildDir.absolutePath - vssDefinitionFile.get().forEach { file -> + vssDefinitionFiles.get().forEach { file -> val vssDefinitionInputFile = file.asFile + println("Searching for VSS file: ${vssDefinitionInputFile.absolutePath}") val vssDefinitionBuildFile = File( "$buildDirPath$fileSeparator" + "$KSP_INPUT_BUILD_DIRECTORY$fileSeparator" + vssDefinitionInputFile.name, ) - println( - "Found VSS definition input file: ${vssDefinitionInputFile.name}, copying to: $vssDefinitionBuildFile", - ) + println("Found VSS input file: ${vssDefinitionInputFile.name}, copying to: $vssDefinitionBuildFile") vssDefinitionInputFile.copyTo(vssDefinitionBuildFile, true) } diff --git a/vss-processor/build.gradle.kts b/vss-processor/build.gradle.kts index 2b242f33..3b03b284 100644 --- a/vss-processor/build.gradle.kts +++ b/vss-processor/build.gradle.kts @@ -52,7 +52,7 @@ tasks.withType().configureEach { } } -configure { +publish { mavenPublicationName = "release" componentName = "java" description = "Vehicle Signal Specification (VSS) Code Generator for the KUKSA SDK" 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 f9786f1c..42ffd1e3 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 @@ -100,7 +100,7 @@ class VssDefinitionProcessor( private fun loadAssetFile(fileName: String): File? { val generatedFile = codeGenerator.generatedFile.firstOrNull() ?: return null val generationPath = generatedFile.absolutePath - val buildPath = generationPath.replaceAfter("$BUILD_FOLDER_NAME$fileSeparator", "") + val buildPath = generationPath.replaceAfterLast("$BUILD_FOLDER_NAME$fileSeparator", "") val kspInputFilePath = "$buildPath$fileSeparator$KSP_INPUT_BUILD_DIRECTORY" val kspInputFolder = File(kspInputFilePath)