Skip to content

Commit

Permalink
Merge remote-tracking branch 'eclipse/main' into task-70
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrylo committed Mar 7, 2024
2 parents 25d5447 + f5ca5f1 commit a1d0025
Show file tree
Hide file tree
Showing 29 changed files with 26,905 additions and 80 deletions.
2 changes: 2 additions & 0 deletions docs/QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ For a more convenient usage you can opt in to auto generate Kotlin models via [S
of the same specification the Databroker uses. For starters you can retrieve an extensive default specification from the
release page of the [COVESA Vehicle Signal Specification GitHub repository](https://github.com/COVESA/vehicle_signal_specification/releases).

Currently VSS specification files in .yaml and .json format are supported by the vss-processor.

*app/build.gradle.kts*
```kotlin
plugins {
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ datastore = "1.0.0"
constraintlayoutCompose = "1.0.1"
datastorePreferences = "1.0.0"
dokka = "1.9.10"
gson = "2.10.1"
kotlin = "1.9.22"
kotlinpoet = "1.16.0"
kotlinxSerializationJson = "1.6.1"
Expand Down Expand Up @@ -36,6 +37,7 @@ androidx-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedat
grpc-okhttp = { group = "io.grpc", name = "grpc-okhttp", version.ref = "grpc" }
grpc-protobuf = { group = "io.grpc", name = "grpc-protobuf-lite", version.ref = "grpc" }
grpc-stub = { group = "io.grpc", name = "grpc-stub", version.ref = "grpc" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" }
kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ package org.eclipse.kuksa.connectivity.authentication

import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe
import org.eclipse.kuksa.connectivity.databroker.DataBrokerConnectionTest
import org.eclipse.kuksa.connectivity.databroker.DataBrokerConnectorProvider
import org.eclipse.kuksa.connectivity.databroker.request.FetchRequest
import org.eclipse.kuksa.connectivity.databroker.request.UpdateRequest
import org.eclipse.kuksa.proto.v1.Types
import org.eclipse.kuksa.test.TestResourceFile
import org.eclipse.kuksa.test.kotest.Authentication
import org.eclipse.kuksa.test.kotest.CustomDatabroker
import org.eclipse.kuksa.test.kotest.Insecure
Expand Down Expand Up @@ -170,6 +170,7 @@ enum class JwtType(private val fileName: String) {
;

fun asInputStream(): InputStream {
return DataBrokerConnectionTest::class.java.classLoader?.getResourceAsStream(fileName)!!
val resourceFile = TestResourceFile(fileName)
return resourceFile.inputStream()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.eclipse.kuksa.connectivity.databroker

import io.kotest.core.spec.style.BehaviorSpec
import org.eclipse.kuksa.test.TestResourceFile
import org.eclipse.kuksa.test.kotest.CustomDatabroker
import org.eclipse.kuksa.test.kotest.Integration
import org.eclipse.kuksa.test.kotest.Secure
Expand All @@ -32,8 +33,9 @@ class DataBrokerConnectorSecureTest : BehaviorSpec({
val dataBrokerConnectorProvider = DataBrokerConnectorProvider()

and("a secure DataBrokerConnector with valid Host, Port and TLS certificate") {
val certificate = DataBrokerConnectionTest::class.java.classLoader?.getResourceAsStream("CA.pem")!!
val dataBrokerConnector = dataBrokerConnectorProvider.createSecure(rootCertFileStream = certificate)
val certificate = TestResourceFile("CA.pem")
val dataBrokerConnector =
dataBrokerConnectorProvider.createSecure(rootCertFileStream = certificate.inputStream())

`when`("Trying to establish a secure connection") {
val connection = dataBrokerConnector.connect()
Expand Down
23 changes: 1 addition & 22 deletions test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,8 @@
* SPDX-License-Identifier: Apache-2.0
*
*/

@Suppress("DSL_SCOPE_VIOLATION") // Remove once KTIJ-19369 is fixed
plugins {
id("com.android.library")
kotlin("android")
}

android {
namespace = "org.eclipse.kuksa.test"
compileSdk = 33

defaultConfig {
minSdk = 24
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}
kotlin("jvm")
}

dependencies {
Expand Down
28 changes: 28 additions & 0 deletions test/src/main/java/org/eclipse/kuksa/test/TestResourceFile.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 - 2024 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.test

import java.io.File

private val classLoader: ClassLoader? = TestResourceFile::class.java.classLoader

class TestResourceFile(path: String) : File(
classLoader!!.getResource(path)?.file ?: error("File does not exist: '$path'"),
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ 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 file by the "vss-processor-plugin". Only .yaml files are currently supported.
* Vehicle Signal Specification definition file by the "vss-processor-plugin". Currently VSS files in
* .yaml and .json format are supported by the vss-processor.
* Use the "VSS Processor Plugin" to provide the Symbol Processor with the necessary VSS file(s).
*
* ### Plugin Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ private abstract class ProvideVssFilesTask : DefaultTask() {
}

companion object {
private val validVssExtension = setOf("yml", "yaml")
private val validVssExtension = setOf("yml", "yaml", "json") // keep VssFileExtension aligned
}
}
3 changes: 3 additions & 0 deletions vss-processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))

implementation(libs.gson)
implementation(libs.kotlinpoet)
implementation(libs.kotlinpoet.ksp)
implementation(libs.symbol.processing.api)

testImplementation(project(":test"))

testImplementation(libs.kotest)
testImplementation(libs.mockk)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import com.squareup.kotlinpoet.ksp.toClassName
import com.squareup.kotlinpoet.ksp.writeTo
import org.eclipse.kuksa.vsscore.annotation.VssModelGenerator
import org.eclipse.kuksa.vsscore.model.parentClassName
import org.eclipse.kuksa.vssprocessor.parser.YamlVssParser
import org.eclipse.kuksa.vssprocessor.parser.factory.VssParserFactory
import org.eclipse.kuksa.vssprocessor.spec.VssNodeSpecModel
import org.eclipse.kuksa.vssprocessor.spec.VssPath
import java.io.File
Expand All @@ -55,7 +55,7 @@ class VssModelGeneratorProcessor(
private val logger: KSPLogger,
) : SymbolProcessor {
private val visitor = VssModelGeneratorVisitor()
private val yamlParser = YamlVssParser()
private val vssParserFactory = VssParserFactory()

override fun process(resolver: Resolver): List<KSAnnotated> {
val symbols = resolver.getSymbolsWithAnnotation(VssModelGenerator::class.qualifiedName.toString())
Expand Down Expand Up @@ -85,14 +85,20 @@ class VssModelGeneratorProcessor(
return
}

vssFiles.forEach { vssFile ->
val simpleVssNodeElements = yamlParser.parseNodes(vssFile)
val vssPathToVssNodeElement = simpleVssNodeElements
.associateBy({ VssPath(it.vssPath) }, { it })
val simpleNodeElements = mutableListOf<VssNodeSpecModel>()
vssFiles.forEach { definitionFile ->
logger.info("Parsing models for definition file: ${definitionFile.name}")
val vssParser = vssParserFactory.create(definitionFile)
val specModels = vssParser.parseNodes(definitionFile)

logger.info("Generating models for VSS file: ${vssFile.name}")
generateModelFiles(vssPathToVssNodeElement)
simpleNodeElements.addAll(specModels)
}

val vssPathToVssNodeElement = simpleNodeElements
.distinctBy { it.uuid }
.associateBy({ VssPath(it.vssPath) }, { it })

generateModelFiles(vssPathToVssNodeElement)
}

// Uses the default file path for generated files (from the code generator) and searches for the given file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023 - 2024 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.
Expand All @@ -24,11 +24,9 @@ import java.io.File

internal interface VssParser {
/**
* @param definitionFile to parse [VssNodeSpecModel] with
* @param elementDelimiter which is the separator string between the elements. The default is an empty line.
* Uses the given [vssFile] to parse [VssNodeSpecModel] with.
*
* @throws java.io.IOException will be thrown when parsing the SpecModels failed
*/
fun parseNodes(
definitionFile: File,
elementDelimiter: String = "",
): List<VssNodeSpecModel>
fun parseNodes(vssFile: File): List<VssNodeSpecModel>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 - 2024 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.parser.factory

// keep VssProcessorPlFugin#validVssExtensions aligned
internal enum class VssFileExtension(vararg val fileExtensions: String) {
JSON("json"),
YAML("yaml", "yml"),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2023 - 2024 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.parser.factory

import org.eclipse.kuksa.vssprocessor.parser.VssParser
import org.eclipse.kuksa.vssprocessor.parser.factory.VssFileExtension.JSON
import org.eclipse.kuksa.vssprocessor.parser.factory.VssFileExtension.YAML
import org.eclipse.kuksa.vssprocessor.parser.json.JsonVssParser
import org.eclipse.kuksa.vssprocessor.parser.yaml.YamlVssParser
import java.io.File

internal class VssParserFactory {

/**
* @throws IllegalStateException when the specified extension is not supported
*/
fun create(extension: String): VssParser {
return when {
JSON.fileExtensions.contains(extension) -> {
JsonVssParser()
}

YAML.fileExtensions.contains(extension) -> {
YamlVssParser()
}

else -> {
error("Could not create VssDefinitionParser: File Extension '$extension' not supported")
}
}
}

/**
* @throws IllegalStateException when the extension of the specified file is not supported
*/
fun create(file: File): VssParser {
val fileName = file.name // with extension
val fileExtension = fileName.substringAfterLast(".")

return create(fileExtension)
}
}
Loading

0 comments on commit a1d0025

Please sign in to comment.