Skip to content

Commit

Permalink
Merge pull request #71 from boschglobal/feature-45
Browse files Browse the repository at this point in the history
Add VSS Processor Plugin
  • Loading branch information
wba2hi authored Feb 28, 2024
2 parents 5b92b2b + f591fb5 commit f41d383
Show file tree
Hide file tree
Showing 46 changed files with 1,334 additions and 132 deletions.
4 changes: 2 additions & 2 deletions .github/actions/setup-project/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ description: Setups the gradle and java environment
runs:
using: "composite"
steps:
- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v3
2 changes: 1 addition & 1 deletion .github/workflows/build-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Project
uses: ./.github/actions/setup-project
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: "Run Docker Container of Databroker in detached mode"
run: docker run --pull=always --rm --publish 55556:55556/tcp --detach --name databroker ghcr.io/eclipse/kuksa.val/databroker:master --port 55556 --insecure
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-license.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# required to grab the history of the PR
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/commitlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: wagoid/commitlint-github-action@v5
2 changes: 1 addition & 1 deletion .github/workflows/dash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Project
uses: ./.github/actions/setup-project
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Project
uses: ./.github/actions/setup-project
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Project
uses: ./.github/actions/setup-project
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ within an Android App. The main functionality consists of fetching, updating and

## Integration

*build.gradle*
*app/build.gradle.kts*
```
implementation("org.eclipse.kuksa:kuksa-sdk:<VERSION>")
```
Expand Down
16 changes: 12 additions & 4 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 org.eclipse.kuksa.property.PropertiesLoader
import org.eclipse.kuksa.version.SemanticVersion
import org.eclipse.kuksa.version.VERSION_FILE_DEFAULT_PATH_KEY

plugins {
id("com.android.application")
id("com.google.devtools.ksp")
id("org.eclipse.kuksa.vss-processor-plugin") // Always take the newest version since it's locally included
kotlin("plugin.serialization")
kotlin("android")
}
Expand Down Expand Up @@ -55,11 +60,14 @@ android {
applicationId = "org.eclipse.kuksa.testapp"
minSdk = 27
targetSdk = 34
versionCode = rootProject.extra["projectVersionCode"].toString().toInt()
versionName = rootProject.extra["projectVersion"].toString()
vectorDrawables {
useSupportLibrary = true
}

val versionPath = rootProject.ext[VERSION_FILE_DEFAULT_PATH_KEY] as String
val semanticVersion = SemanticVersion(versionPath)
versionCode = semanticVersion.versionCode
versionName = semanticVersion.versionName
}
signingConfigs {
create("release") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import org.eclipse.kuksa.testapp.ui.theme.KuksaAppAndroidTheme
import org.eclipse.kuksa.vsscore.annotation.VssDefinition
import org.eclipse.kuksa.vsscore.model.VssSpecification

@VssDefinition("vss_rel_4.0.yaml")
@VssDefinition
class KuksaDataBrokerActivity : ComponentActivity() {
private lateinit var connectionInfoRepository: ConnectionInfoRepository

Expand Down
49 changes: 34 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@
*
*/

import org.jetbrains.kotlin.incremental.createDirectory
import org.eclipse.kuksa.version.VERSION_FILE_DEFAULT_NAME
import org.eclipse.kuksa.version.VERSION_FILE_DEFAULT_PATH_KEY
import java.nio.file.FileVisitResult
import java.nio.file.Path
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.bufferedWriter
import kotlin.io.path.createDirectories
import kotlin.io.path.createFile
import kotlin.io.path.deleteIfExists
import kotlin.io.path.name
import kotlin.io.path.useLines
import kotlin.io.path.visitFileTree

val versionDefaultPath = "$rootDir/$VERSION_FILE_DEFAULT_NAME"
rootProject.ext[VERSION_FILE_DEFAULT_PATH_KEY] = versionDefaultPath

plugins {
base
Expand Down Expand Up @@ -47,6 +61,7 @@ subprojects {
}
}

@OptIn(ExperimentalPathApi::class)
tasks.register("mergeDashFiles") {
group = "oss"

Expand All @@ -56,26 +71,30 @@ tasks.register("mergeDashFiles") {
},
)

val buildDir = layout.buildDirectory.asFile.get()
val buildDirPath = Path.of(buildDir.path)

doLast {
val sortedLinesSet = sortedSetOf<String>()
files("build/oss").asFileTree.forEach { file ->
if (file.name != "dependencies.txt") return@forEach
val ossDir = buildDirPath.resolve("oss").createDirectories()
val ossAllDir = ossDir.resolve("all").createDirectories()
val ossDependenciesFile = ossAllDir.resolve("all-dependencies.txt")
ossDependenciesFile.deleteIfExists()
ossDependenciesFile.createFile()

file.useLines {
sortedLinesSet.addAll(it)
}
}
val sortedLinesSet = sortedSetOf<String>()
ossDir.visitFileTree {
onVisitFile { file, _ ->
if (file.name != "dependencies.txt") return@onVisitFile FileVisitResult.CONTINUE

val folder = File("$rootDir/build/oss/all")
folder.createDirectory()
file.useLines {
sortedLinesSet.addAll(it)
}

val file = File("$folder/all-dependencies.txt")
if (file.exists()) {
file.delete()
FileVisitResult.CONTINUE
}
}
file.createNewFile()

val bufferedWriter = file.bufferedWriter()
val bufferedWriter = ossDependenciesFile.bufferedWriter()
bufferedWriter.use { writer ->
sortedLinesSet.forEach { line ->
writer.write(line + System.lineSeparator())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@

package org.eclipse.kuksa.version

import java.io.File
import java.util.Locale

class SemanticVersion(semanticVersion: String) {
const val VERSION_FILE_DEFAULT_PATH_KEY = "versionFilePathKey"
const val VERSION_FILE_DEFAULT_NAME = "version.txt"

class SemanticVersion(versionFilePath: String) {
val major: Int
val minor: Int
val patch: Int
var suffix: String = ""

val versionString: String
val versionFile: File

val versionName: String
get() {
var version = "$major.$minor.$patch"
if (suffix.isNotEmpty()) {
Expand All @@ -47,6 +53,9 @@ class SemanticVersion(semanticVersion: String) {
}

init {
versionFile = File(versionFilePath)

val semanticVersion = versionFile.readText()
val versions = semanticVersion.trim()
.substringBefore("-") // Ignore suffixes like -SNAPSHOT
.split(".")
Expand All @@ -56,7 +65,5 @@ class SemanticVersion(semanticVersion: String) {
minor = versions[1].toInt()
patch = versions[2].toInt()
this.suffix = suffix

print("Current SemanticVersion($versionString)\n")
}
}
16 changes: 5 additions & 11 deletions buildSrc/src/main/kotlin/publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,12 @@ afterEvaluate {
)

sign(publishing.publications)
}
}

gradle.taskGraph.whenReady {
tasks.withType(Sign::class) {
val publishToMavenLocalTask = allTasks.find { it.name.contains("publishToMavenLocal") }
val isPublishingToMavenLocal = publishToMavenLocalTask != null

if (isPublishingToMavenLocal) {
println(":${project.name}:$name - Signing is disabled (publishToMavenLocal)")
}
setRequired({
val publishToMavenLocalTask = gradle.taskGraph.allTasks.find { it.name.contains("ToMavenLocal") }
val isPublishingToMavenLocal = publishToMavenLocalTask != null

onlyIf { !isPublishingToMavenLocal } // disable signing when publishing to MavenLocal
!isPublishingToMavenLocal // disable signing when publishing to MavenLocal
})
}
}
65 changes: 37 additions & 28 deletions buildSrc/src/main/kotlin/version.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,60 @@
*/

import org.eclipse.kuksa.version.SemanticVersion
import org.eclipse.kuksa.version.VERSION_FILE_DEFAULT_NAME

val file = File("$rootDir/version.txt")
val fileContent = file.readText()
val semanticVersion = SemanticVersion(fileContent)
private val versionPath = "$rootDir/$VERSION_FILE_DEFAULT_NAME"
private val semanticVersion = SemanticVersion(versionPath)

updateExtras()
/**
* Writes the given [suffix] into the given [inputFileProperty] while keeping the semantic version intact.
* E.g. 1.2.3 -> 1.2.3-SNAPSHOT (suffix = SNAPSHOT). Leave the suffix empty to restore the initial version.
*/
abstract class SetVersionSuffixTask : DefaultTask() {
@get:Input
abstract val suffix: Property<String>

@get:Incremental
@get:InputFile
abstract val inputFileProperty: RegularFileProperty

@TaskAction
fun addVersionSuffix() {
val inputFile = inputFileProperty.asFile.get()

val newSemanticVersion = SemanticVersion(inputFile.path)
newSemanticVersion.suffix = suffix.get()

println("Applying version suffix: ${suffix.get()}")

inputFile.writeText(newSemanticVersion.versionName)
}
}

// Do not chain this command because it writes into a file which needs to be re-read inside the next gradle command
tasks.register("setReleaseVersion") {
tasks.register<SetVersionSuffixTask>("setSnapshotVersion") {
group = "version"
doLast {
semanticVersion.suffix = ""

updateVersion()
}
inputFileProperty = semanticVersion.versionFile
suffix = "SNAPSHOT"
}

// Do not chain this command because it writes into a file which needs to be re-read inside the next gradle command
tasks.register("setSnapshotVersion") {
tasks.register<SetVersionSuffixTask>("setReleaseVersion") {
group = "version"
doLast {
semanticVersion.suffix = "SNAPSHOT"

updateVersion()
}
inputFileProperty = semanticVersion.versionFile
suffix = ""
}

tasks.register("printVersion") {
group = "version"
doLast {
val version = semanticVersion.versionString

println("VERSION=$version")
val versionFilePath = versionPath
doLast { // Prints the correct version if chained with SetVersionSuffix tasks
val currentSemanticVersion = SemanticVersion(versionFilePath)
println("Current version: ${currentSemanticVersion.versionName}")
}

mustRunAfter("setReleaseVersion", "setSnapshotVersion")
}

fun updateExtras() {
rootProject.extra["projectVersion"] = semanticVersion.versionString
rootProject.extra["projectVersionCode"] = semanticVersion.versionCode
}

fun updateVersion() {
updateExtras()

file.writeText(semanticVersion.versionString)
}
Loading

0 comments on commit f41d383

Please sign in to comment.