Skip to content

Commit 9c212ec

Browse files
committed
Merge branch 'master' of https://github.com/eclipse-thingweb/kotlin-wot into master
# Conflicts: # build.gradle.kts
2 parents 4db0926 + 3109408 commit 9c212ec

File tree

9 files changed

+190
-100
lines changed

9 files changed

+190
-100
lines changed

.github/workflows/gradle-pr.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: build-pr
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- 'master'
7+
8+
jobs:
9+
CI:
10+
uses: eclipse-lmos/.github/.github/workflows/gradle-ci.yml@main
11+
permissions:
12+
contents: read

.github/workflows/gradle.yml

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,21 @@
99
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
1010
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
1111

12-
name: Java CI with Gradle
12+
name: build-publish
1313

1414
on:
1515
push:
16-
branches: [ "master" ]
17-
pull_request:
18-
branches: [ "master" ]
16+
branches: [ master ]
1917

2018
jobs:
21-
validation:
22-
name: "Gradle wrapper validation"
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/[email protected]
26-
- uses: gradle/actions/[email protected]
27-
build:
28-
29-
runs-on: ubuntu-latest
30-
permissions:
31-
contents: read
32-
33-
steps:
34-
- uses: actions/checkout@v4
35-
- name: Set up JDK 21
36-
uses: actions/setup-java@v4
37-
with:
38-
java-version: '21'
39-
distribution: 'temurin'
40-
- name: Setup Gradle
41-
uses: gradle/actions/setup-gradle@0d30c9111cf47a838eb69c06d13f3f51ab2ed76f # v3.1.0
42-
- name: Build with Gradle Wrapper
43-
run: ./gradlew build
44-
45-
dependency-submission:
46-
runs-on: ubuntu-latest
19+
build-publish:
20+
uses: eclipse-lmos/.github/.github/workflows/gradle-ci-main.yml@main
4721
permissions:
4822
contents: write
49-
steps:
50-
- uses: actions/checkout@v4
51-
- name: Set up JDK 21
52-
uses: actions/setup-java@v4
53-
with:
54-
java-version: '21'
55-
distribution: 'temurin'
56-
57-
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
58-
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
59-
- name: Generate and submit dependency graph
60-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
61-
uses: gradle/actions/dependency-submission@0d30c9111cf47a838eb69c06d13f3f51ab2ed76f # v3.1.0
23+
packages: write
24+
secrets:
25+
oss-username: ${{ secrets.OSSRH_USERNAME }}
26+
oss-password: ${{ secrets.OSSRH_PASSWORD }}
27+
signing-key-id: ${{ secrets.GPG_SUBKEY_ID }}
28+
signing-key: ${{ secrets.GPG_PRIVATE_KEY }}
29+
signing-key-password: ${{ secrets.GPG_PASSPHRASE }}

.github/workflows/release.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release-type:
7+
type: choice
8+
description: What do you want to release?
9+
options:
10+
- Milestone
11+
- Release
12+
workflow_call:
13+
inputs:
14+
release-type:
15+
default: "Milestone"
16+
required: true
17+
type: string
18+
registry-name:
19+
default: eclipse-lmos
20+
type: string
21+
required: false
22+
secrets:
23+
oss-username:
24+
required: true
25+
oss-password:
26+
required: true
27+
signing-key-id:
28+
required: true
29+
signing-key:
30+
required: true
31+
signing-key-password:
32+
required: true
33+
bot-token:
34+
required: true
35+
registry-username:
36+
required: false
37+
registry-password:
38+
required: false
39+
outputs:
40+
version:
41+
value: ${{ jobs.build-and-release.outputs.version }}
42+
43+
jobs:
44+
build-and-release:
45+
runs-on: ubuntu-latest
46+
permissions:
47+
contents: write
48+
packages: write
49+
outputs:
50+
version: ${{ steps.Publish.outputs.version }}
51+
steps:
52+
- name: Checkout
53+
uses: actions/[email protected]
54+
with:
55+
ref: master
56+
token: ${{ secrets.bot-token }}
57+
- name: REUSE Compliance Check
58+
uses: fsfe/[email protected]
59+
- name: Set up JDK 21
60+
uses: actions/[email protected]
61+
with:
62+
java-version: '21'
63+
distribution: 'temurin'
64+
- name: Setup Gradle
65+
uses: gradle/actions/[email protected]
66+
- name: Publish
67+
id: Publish
68+
env:
69+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.oss-username }}
70+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.oss-password }}
71+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.signing-key-id }}
72+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.signing-key }}
73+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.signing-key-password }}
74+
REGISTRY_URL: ghcr.io
75+
REGISTRY_USERNAME: ${{ secrets.registry-username }}
76+
REGISTRY_PASSWORD: ${{ secrets.registry-password }}
77+
REGISTRY_NAMESPACE: ${{ inputs.registry-name }}
78+
GH_TOKEN: ${{ secrets.bot-token }}
79+
run: |
80+
git config --global user.email "[email protected]"
81+
git config --global user.name "CICD"
82+
git fetch -t -q
83+
84+
# Extract version without -SNAPSHOT suffix from gradle.properties
85+
version=$(sed -n -E 's/^version[[:blank:]]*=[[:blank:]]*(.*)-SNAPSHOT$/\1/p' gradle.properties)
86+
oldSnapshotVersion="${version}-SNAPSHOT"
87+
88+
# In case of milestone release, set milestone release version based on previous milestone release versions
89+
if [ "${{ github.event.inputs.release-type }}" == "Milestone" ]; then
90+
oldMilestone=$(git tag -l "${version}-M*" --sort=v:refname | tail -n 1)
91+
if [ "${oldMilestone}" == "" ]; then
92+
version=${version}-M1
93+
else
94+
version=${version}-M$((10#${oldMilestone##*-M}+1))
95+
fi
96+
fi
97+
98+
# In case of non-milestone releses, increase the snapshot version in master branch
99+
if [ "${{ github.event.inputs.release-type }}" == "Milestone" ]; then
100+
nextSnapshotVersion="${oldSnapshotVersion}"
101+
else
102+
major=$(echo $version | cut -d. -f1)
103+
minor=$(echo $version | cut -d. -f2)
104+
nextSnapshotVersion="${major}.$((minor+1)).0-SNAPSHOT"
105+
fi
106+
107+
echo "Releasing ${version}"
108+
echo "version=${version}" >> $GITHUB_OUTPUT
109+
110+
# Update version, build, publish release jars and (optionally) docker image and helm chart
111+
./gradlew :release -Prelease.useAutomaticVersion=true "-Prelease.releaseVersion=${version}" "-Prelease.newVersion=${nextSnapshotVersion}" --no-parallel
112+
git checkout "${version}"
113+
./gradlew publish --no-configuration-cache
114+
115+
# Generate release notes
116+
if [ "${{ github.event.inputs.release-type }}" == "Milestone" ]; then
117+
gh release create "${version}" --generate-notes --prerelease
118+
else
119+
gh release create "${version}" --generate-notes --latest
120+
fi

build.gradle.kts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
import com.vanniktech.maven.publish.SonatypeHost
2+
13
plugins {
24
kotlin("jvm") version "2.0.20"
35
id("org.jetbrains.kotlinx.kover") version "0.8.3"
46
id("org.cadixdev.licenser") version "0.6.1"
5-
id("com.jaredsburrows.license") version "0.9.8"
6-
`maven-publish`
7+
id("com.vanniktech.maven.publish") version "0.31.0"
8+
id("org.cyclonedx.bom") version "2.2.0" apply false
79
}
810

911
subprojects {
1012
apply(plugin = "org.jetbrains.kotlin.jvm")
1113
apply(plugin = "org.jetbrains.kotlinx.kover")
1214
apply(plugin = "maven-publish")
1315
apply(plugin = "org.cadixdev.licenser")
14-
apply(plugin = "com.jaredsburrows.license")
16+
apply(plugin = "com.vanniktech.maven.publish")
17+
apply(plugin = "org.cyclonedx.bom")
1518

1619
group = "org.eclipse.thingweb"
17-
version = "0.1.3-SNAPSHOT"
20+
version = "0.1.0-SNAPSHOT"
1821

1922
license {
2023
header(rootProject.file("LICENSE"))
@@ -48,21 +51,34 @@ subprojects {
4851
add("archives", tasks["javadocJar"])
4952
}
5053

51-
publishing {
52-
publications {
53-
create<MavenPublication>("mavenKotlin") {
54-
from(components["java"])
55-
artifact(tasks["sourcesJar"])
56-
artifact(tasks["javadocJar"])
57-
artifactId = project.name
54+
mavenPublishing {
55+
publishToMavenCentral(SonatypeHost.DEFAULT, automaticRelease = true)
56+
signAllPublications()
57+
58+
pom {
59+
name = "kotlin-wot"
60+
description = "A Framework for implementing Web of Things in Kotlin."
61+
url = "https://github.com/eclipse-thingweb/kotlin-wot"
62+
licenses {
63+
license {
64+
name = "Apache-2.0"
65+
distribution = "repo"
66+
url = "https://github.com/eclipse-thingweb/kotlin-wot/blob/master/LICENSES/Apache-2.0.txt"
67+
}
68+
}
69+
developers {
70+
developer {
71+
id = "robwin"
72+
name = "Robert Winkler"
73+
74+
}
75+
}
76+
scm {
77+
url = "https://github.com/eclipse-thingweb/kotlin-wot.git"
5878
}
59-
}
60-
repositories {
61-
mavenLocal()
6279
}
6380
}
6481

65-
6682
tasks.test {
6783
useJUnitPlatform()
6884

kotlin-wot-reflection/src/main/kotlin/reflection/ExposedThingBuilder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ object ExposedThingBuilder {
7373
title = thingAnnotation.title
7474
objectType = Type(thingAnnotation.type)
7575
val contexts = clazz.findAnnotations<Context>()
76-
if(contexts.isNotEmpty()){
76+
if (contexts.isNotEmpty()) {
7777
val context = org.eclipse.thingweb.thing.schema.Context(DEFAULT_CONTEXT)
7878
contexts.forEach {
79-
context.addContext(it.prefix, it.url)
79+
if (it.prefix.isEmpty()) context.addContext(it.url) else context.addContext(it.prefix, it.url)
8080
}
8181
objectContext = context
8282
}

kotlin-wot-reflection/src/main/kotlin/reflection/annotations/Annotations.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ annotation class Thing(val id: String, val title: String, val description: Strin
1515
@Target(AnnotationTarget.CLASS)
1616
@Retention(AnnotationRetention.RUNTIME)
1717
@Repeatable
18-
annotation class Context(val prefix: String, val url : String)
18+
annotation class Context(val prefix: String = "", val url : String)
1919

2020
@Target(AnnotationTarget.CLASS)
2121
@Retention(AnnotationRetention.RUNTIME)

kotlin-wot/src/main/kotlin/thing/ContextSerializer.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ internal class ContextSerializer : JsonSerializer<Context>() {
2323
gen: JsonGenerator,
2424
serializers: SerializerProvider
2525
) {
26-
val defaultUrl: String? = context.defaultUrl
26+
val defaultUrls: List<String> = context.defaultUrls
2727
val prefixedUrls: Map<String, String> = context.prefixedUrls
28-
val hasDefaultUrl = defaultUrl != null
28+
val hasMoreThanOneDefaultUrl = defaultUrls.size > 1
2929
val hasPrefixedUrls = prefixedUrls.isNotEmpty()
30-
if (hasDefaultUrl && hasPrefixedUrls) {
30+
if (hasMoreThanOneDefaultUrl || hasPrefixedUrls) {
3131
gen.writeStartArray()
3232
}
33-
if (hasDefaultUrl) {
34-
gen.writeString(defaultUrl)
33+
defaultUrls.forEach {
34+
gen.writeString(it)
3535
}
3636
if (hasPrefixedUrls) {
3737
gen.writeObject(prefixedUrls)
3838
}
39-
if (hasDefaultUrl && hasPrefixedUrls) {
39+
if (hasMoreThanOneDefaultUrl || hasPrefixedUrls) {
4040
gen.writeEndArray()
4141
}
4242
}

kotlin-wot/src/main/kotlin/thing/ThingDescription.kt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,6 @@ data class ThingDescription @JsonCreator constructor(
126126
securityDefinitions[name] = securityScheme
127127
}
128128

129-
fun getPropertiesByObjectType(objectType: String): Map<String, PropertyAffordance<*>> {
130-
return getPropertiesByExpandedObjectType(getExpandedObjectType(objectType))
131-
}
132-
133-
private fun getPropertiesByExpandedObjectType(objectType: String): Map<String, PropertyAffordance<*>> {
134-
return properties.filter { (_, property) ->
135-
property.objectType?.defaultType?.let { getExpandedObjectType(it) } == objectType
136-
}.toMap()
137-
}
138-
139-
fun getExpandedObjectType(objectType: String): String {
140-
141-
val parts = objectType.split(":", limit = 2)
142-
val prefix = if (parts.size == 2) parts[0] else null
143-
val suffix = parts.last()
144-
145-
return objectContext?.getUrl(prefix)?.let { "$it#$suffix" } ?: objectType
146-
}
147-
148129
fun toJson() : String{
149130
return try {
150131
JsonMapper.instance.writeValueAsString(this)

kotlin-wot/src/main/kotlin/thing/schema/Context.kt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,28 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize
1616
*/
1717
@JsonDeserialize(using = ContextDeserializer::class)
1818
@JsonSerialize(using = ContextSerializer::class)
19-
//@Serializable(with = ContextSerializer::class)
20-
data class Context(private val urls: MutableMap<String?, String> = HashMap()) {
19+
data class Context(val defaultUrls: MutableList<String> = mutableListOf(), private val prefixeUrls: MutableMap<String, String> = HashMap()) {
2120

2221
constructor(url: String) : this() {
2322
addContext(url)
2423
}
2524

26-
constructor(prefix: String?, url: String) : this() {
25+
constructor(prefix: String, url: String) : this() {
2726
addContext(prefix, url)
2827
}
2928

3029
fun addContext(url: String): Context {
31-
return addContext(null, url)
32-
}
33-
34-
fun getUrl(prefix: String?): String? {
35-
return urls[prefix]
30+
defaultUrls.add(url)
31+
return this
3632
}
3733

38-
fun addContext(prefix: String?, url: String): Context {
39-
urls[prefix] = url
34+
fun addContext(prefix: String, url: String): Context {
35+
prefixeUrls[prefix] = url
4036
return this
4137
}
4238

43-
val defaultUrl: String?
44-
get() = urls[null] // Directly accessing the map
45-
4639
val prefixedUrls: Map<String, String>
47-
get() = urls.entries
40+
get() = prefixeUrls.entries
4841
.filter { (key, _) -> key != null }
4942
.associate { (key, value) -> key!! to value }
5043
}

0 commit comments

Comments
 (0)