Skip to content

Commit

Permalink
feature: Add VSS Processor Plugin
Browse files Browse the repository at this point in the history
The plugin is a composite project which means a higher separation to
the other modules and common buildSrc plugins can't be used here. So
plugins like publish / version had to be copied. The publish script
had to be adapted for publishing a plugin

close #45

Signed-Off-By: Mark Hüsers <mark.huesers@etas.com>
  • Loading branch information
Chrylo committed Jan 31, 2024
1 parent 79e7a19 commit aa3d2d2
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 21 deletions.
18 changes: 16 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.eclipse.kuksa.property.PropertiesLoader

/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
Expand All @@ -19,9 +17,16 @@ import org.eclipse.kuksa.property.PropertiesLoader
*
*/

@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")
id("com.google.devtools.ksp")
id("org.eclipse.kuksa.vss-processor-plugin")
kotlin("plugin.serialization")
kotlin("android")
}
Expand Down Expand Up @@ -121,6 +126,15 @@ android {
}
}

tasks.register<ProvideVssDefinitionTask>("ProvideVssDefinition") {
val vssDefinitionFilePath = "$projectDir/src/main/assets/vss_rel_4.0.yaml"
vssDefinitionFile = File(vssDefinitionFilePath)
}

tasks.withType<KspTask> {
dependsOn(tasks.withType<ProvideVssDefinitionTask>())
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()

Expand Down
9 changes: 5 additions & 4 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" ?>
<?xml version='1.0' encoding='UTF-8'?>
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
</CurrentIssues>
<ManuallySuppressedIssues>
<ID>EmptyFunctionBlock:VssProcessorPlugin.kt$VssProcessorPlugin${ }</ID>
</ManuallySuppressedIssues>
<CurrentIssues/>
</SmellBaseline>
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonTransitiveRClass=true
android.useAndroidX=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
activityKtx = "1.8.0"
androidGradlePlugin = "8.1.3" # Check with detekt table first: https://detekt.dev/docs/introduction/compatibility/
androidGradlePlugin = "8.2.0" # Check with detekt table first: https://detekt.dev/docs/introduction/compatibility/
datastore = "1.0.0"
constraintlayoutCompose = "1.0.1"
datastorePreferences = "1.0.0"
Expand Down
13 changes: 13 additions & 0 deletions samples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import com.google.devtools.ksp.gradle.KspTask
import org.eclipse.kuksa.vssprocessor.plugin.ProvideVssDefinitionTask

/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
Expand All @@ -20,6 +23,7 @@
plugins {
id("com.android.application")
id("com.google.devtools.ksp")
id("org.eclipse.kuksa.vss-processor-plugin")
kotlin("android")
}

Expand Down Expand Up @@ -54,6 +58,15 @@ android {
}
}

tasks.register<ProvideVssDefinitionTask>("ProvideVssDefinition") {
val vssDefinitionFilePath = "$projectDir/src/main/assets/vss_rel_4.0.yaml"
vssDefinitionFile = File(vssDefinitionFilePath)
}

tasks.withType<KspTask> {
dependsOn(tasks.withType<ProvideVssDefinitionTask>())
}

dependencies {
implementation(project(":kuksa-sdk")) // org.eclipse.kuksa.kuksa-sdk:<VERSION>
ksp(project(":vss-processor")) // org.eclipse.kuksa.vss-processor:<VERSION>
Expand Down
5 changes: 5 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

pluginManagement {
includeBuild("vss-processor-plugin")

repositories {
gradlePluginPortal()
google()
Expand All @@ -26,6 +28,7 @@ pluginManagement {

plugins {
id("com.google.devtools.ksp") version "1.9.0-1.0.11"
id("org.eclipse.kuksa.vss-processor-plugin") version "0.1.2"
kotlin("jvm") version "1.9.0-1.0.11"
kotlin("plugin.serialization") version "1.9.0"
}
Expand All @@ -40,6 +43,8 @@ dependencyResolutionManagement {
}
}

rootProject.name = "kuksa-android-sdk"

include(":app")
include(":kuksa-sdk")
include(":samples")
Expand Down
1 change: 0 additions & 1 deletion vss-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

plugins {
kotlin("jvm")
`maven-publish`
publish
alias(libs.plugins.dokka)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,28 @@ package org.eclipse.kuksa.vsscore.annotation

/**
* Add this annotation to any class to trigger the model generation (Kotlin Symbol Processing) for the given
* Vehicle Signal Specification definition file. Only .yaml files are currently supported. The searched root folder
* is the assets folder (example path: app/src/main/assets).
* Vehicle Signal Specification definition file. Only .yaml files are currently supported. Use the
* "VSS Processor Plugin" to provide the Symbol Processor with the necessary definition file. Then provide the file name
* via the [vssDefinitionName] parameter (The path can be ignored).
*
* ### Example
* ### Plugin Example
*
* ```
* plugins {
* id("org.eclipse.kuksa.vss-processor-plugin") version "<VERSION>"
* }
*
* tasks.register<ProvideVssDefinitionTask>("ProvideVssDefinition") {
* val vssDefinitionFilePath = "$projectDir/src/main/assets/vss_rel_4.0.yaml"
* vssDefinitionFile = File(vssDefinitionFilePath)
* }
*
* tasks.withType<KspTask> {
* dependsOn(tasks.withType<ProvideVssDefinitionTask>())
* }
* ```
*
* ### Annotation Example
*
* ```
* @VssDefinition("vss_rel_4.0.yaml")
Expand All @@ -36,10 +54,8 @@ package org.eclipse.kuksa.vsscore.annotation
* then the incremental compiler for KSP needs to be disabled explicitly in the gradle properties.
* ```
* <ksp.incremental=false>
*
* @param vssDefinitionPath the path to the definition file
* ```
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class VssDefinition(val vssDefinitionPath: String)
annotation class VssDefinition(val vssDefinitionName: String)
1 change: 1 addition & 0 deletions vss-processor-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
55 changes: 55 additions & 0 deletions vss-processor-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

repositories {
gradlePluginPortal()
google()
mavenCentral()
}

plugins {
`kotlin-dsl`
`java-gradle-plugin`
`maven-publish`
// publish
}

gradlePlugin {
plugins {
create("VssProcessorPlugin") {
id = "org.eclipse.kuksa.vss-processor-plugin"
implementationClass = "org.eclipse.kuksa.vssprocessor.plugin.VssProcessorPlugin"
}
}
}

group = "org.eclipse.kuksa"
version = "0.1.2"

dependencies {
implementation(kotlin("stdlib"))
}

//configure<Publish_gradle.PublishPluginExtension> {
// mavenPublicationName = "release"
// componentName = "java"
// description = "Vehicle Signal Specification (VSS) Plugin of the KUKSA SDK"
//}


21 changes: 21 additions & 0 deletions vss-processor-plugin/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.eclipse.kuksa.vssprocessor.plugin

import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.TaskAction
import java.io.File

class VssProcessorPlugin : Plugin<Project> {
override fun apply(project: Project) {
}
}

abstract class ProvideVssDefinitionTask : DefaultTask() {

@get:InputFile
abstract val vssDefinitionFile: RegularFileProperty

@TaskAction
fun provideFile() {
val vssDefinitionInputFile = vssDefinitionFile.get().asFile
val buildDirPath = project.buildDir.absolutePath
val vssDefinitionBuildFile = File("$buildDirPath/$KSP_INPUT_BUILD_DIRECTORY/${vssDefinitionInputFile.name}")

println("Found VSS definition input file: ${vssDefinitionInputFile.name}, copying to: $vssDefinitionBuildFile")

vssDefinitionInputFile.copyTo(vssDefinitionBuildFile, true)
}

companion object {
private const val KSP_INPUT_BUILD_DIRECTORY = "kspInput/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ class VssDefinitionProcessor(
)

val vssDefinition = classDeclaration.getAnnotationsByType(VssDefinition::class).firstOrNull() ?: return
val vssDefinitionPath = vssDefinition.vssDefinitionPath
val vssDefinitionPath = vssDefinition.vssDefinitionName

val definitionFile = loadAssetFile(vssDefinitionPath)
if (definitionFile == null || !definitionFile.exists()) {
logger.info("No VSS definition file was found!")
logger.error("No VSS definition file was found! Is the plugin correctly configured?")
return
}

Expand All @@ -100,11 +100,11 @@ class VssDefinitionProcessor(
private fun loadAssetFile(fileName: String): File? {
val generatedFile = codeGenerator.generatedFile.firstOrNull() ?: return null
val generationPath = generatedFile.absolutePath
val buildPath = generationPath.replaceAfterLast(buildDir, "")
val assetsFilePath = buildPath + fileSeparator + assetsDir
val assetsFolder = File(assetsFilePath)
val buildPath = generationPath.replaceAfter(BUILD_FOLDER_NAME, "")
val kspInputFilePath = "$buildPath/$KSP_INPUT_BUILD_DIRECTORY"
val kspInputFolder = File(kspInputFilePath)

return assetsFolder.walk().firstOrNull { it.name == fileName }
return kspInputFolder.walk().firstOrNull { it.name == fileName }
}

private fun generateModelFiles(vssPathToSpecification: Map<VssPath, VssSpecificationSpecModel>) {
Expand Down Expand Up @@ -140,6 +140,8 @@ class VssDefinitionProcessor(
private companion object {
private const val PACKAGE_NAME = "org.eclipse.kuksa.vss"
private const val FILE_NAME_PROCESSOR_POSTFIX = "Processor"
private const val KSP_INPUT_BUILD_DIRECTORY = "kspInput/"
private const val BUILD_FOLDER_NAME = "build/"

private val fileSeparator = File.separator
private val assetsDir = "intermediates" + fileSeparator + "assets" + fileSeparator
Expand Down

0 comments on commit aa3d2d2

Please sign in to comment.