From 7aa4055e40b24d2cec4d827f216b2f930d30f66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20W=C3=BCrl?= Date: Sun, 13 Oct 2024 22:34:36 +0200 Subject: [PATCH] use sonarcloud (#2) * use sonarcloud * update versions * update * add missing token * downgrade to kotlin 1.9 * small fix * wupdate --- .github/workflows/ci.yml | 21 ++++++++++-------- .travis.yml | 9 -------- build.gradle.kts | 22 ++++++++++--------- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../jsonschema/mapper/SchemaPropertyMapper.kt | 6 +++-- .../jsonschema/property/PropertyTypeMapper.kt | 4 ++-- .../jsonschema/SchemaGeneratorTest.kt | 4 ++-- 8 files changed, 34 insertions(+), 36 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 925d01a..c9abc07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,10 @@ name: Basic CI on: push: branches: - - master + - main pull_request: branches: - - master + - main jobs: gradle: @@ -15,37 +15,40 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-java@v4 with: distribution: temurin - java-version: 11 + java-version: 21 - name: Setup Gradle - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v3 - name: Execute Gradle build run: ./gradlew build - name: Cache SonarQube packages - uses: actions/cache@v1 + uses: actions/cache@v4 if: matrix.os == 'ubuntu-latest' with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages - uses: actions/cache@v1 + uses: actions/cache@v4 if: matrix.os == 'ubuntu-latest' with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} restore-keys: ${{ runner.os }}-gradle + - name: Analyze with Sonar if: matrix.os == 'ubuntu-latest' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} SONAR_SCANNER_OPTS: "-Xmx2048m" run: ./gradlew sonar --info \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dc164cd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: java - -jdk: - - oraclejdk11 - - openjdk11 - - openjdk17 - -after_success: - - ./gradlew jacocoTestReport coveralls diff --git a/build.gradle.kts b/build.gradle.kts index feed839..eedbf64 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,8 @@ plugins { - kotlin("jvm") version "1.9.0" - id("com.github.kt3k.coveralls") version "2.12.0" + kotlin("jvm") version "1.9.25" `java-library` `maven-publish` - id("org.sonarqube") version "3.5.0.2730" + id("org.sonarqube") version "5.1.0.4882" idea id("jacoco") } @@ -18,18 +17,19 @@ repositories { } java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } -tasks.withType { - kotlinOptions { - jvmTarget = "11" +kotlin { + jvmToolchain(17) + compilerOptions { + apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9) } } jacoco { - toolVersion = "0.8.10" + toolVersion = "0.8.12" } tasks.test { @@ -47,7 +47,9 @@ tasks.jacocoTestReport { sonar { properties { - property("sonar.projectKey", "wuan_json-schema_AYVNclMSU_dM7amWRil-") + property("sonar.projectKey", "wuan_json-schema") + property("sonar.organization", "wuan") + property("sonar.host.url", "https://sonarcloud.io") } } diff --git a/gradle.properties b/gradle.properties index df61571..9d31505 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ version=0.1.1-SNAPSHOT -org.gradle.jvmargs=-Xms128m -Xmx1024m +org.gradle.jvmargs=-Xms128m -Xmx2048m diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ec915a8..afa1e8e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip diff --git a/src/main/java/com/mercateo/jsonschema/mapper/SchemaPropertyMapper.kt b/src/main/java/com/mercateo/jsonschema/mapper/SchemaPropertyMapper.kt index 783d465..b4d0f2b 100644 --- a/src/main/java/com/mercateo/jsonschema/mapper/SchemaPropertyMapper.kt +++ b/src/main/java/com/mercateo/jsonschema/mapper/SchemaPropertyMapper.kt @@ -21,13 +21,15 @@ class SchemaPropertyMapper(private val referencedElements: Set) { return if (context.reference != null) { nodeFactory.objectNode().apply { put("\$ref", context.reference) } } else { - propertyMappers[context.propertyDescriptor.propertyType]!!.toJson(context).apply { + val propertyType = context.propertyDescriptor.propertyType + val jsonPropertyMapper = propertyMappers[propertyType] + jsonPropertyMapper?.toJson(context)?.apply { val name = context.property.path if (referencedElements.contains(name)) { put("id", name) } - } + } ?: error("did not find property mapper for $propertyType") } } diff --git a/src/main/java/com/mercateo/jsonschema/property/PropertyTypeMapper.kt b/src/main/java/com/mercateo/jsonschema/property/PropertyTypeMapper.kt index bcbc054..7a1dfec 100644 --- a/src/main/java/com/mercateo/jsonschema/property/PropertyTypeMapper.kt +++ b/src/main/java/com/mercateo/jsonschema/property/PropertyTypeMapper.kt @@ -8,7 +8,7 @@ import java.util.* object PropertyTypeMapper { - private val TYPE_MAP = mapOf( + private val TYPE_MAP: Map, PropertyType> = mapOf( Pair(String::class.java, PropertyType.STRING), Pair(Boolean::class.java, PropertyType.BOOLEAN), Pair(java.lang.Boolean::class.java, PropertyType.BOOLEAN), @@ -33,7 +33,7 @@ object PropertyTypeMapper { return PropertyType.ARRAY } - val clazz = type.rawType + val clazz: Class = type.rawType if (Enum::class.java.isAssignableFrom(clazz)) { return PropertyType.STRING } diff --git a/src/test/java/com/mercateo/jsonschema/SchemaGeneratorTest.kt b/src/test/java/com/mercateo/jsonschema/SchemaGeneratorTest.kt index f600bf9..b0d28f2 100644 --- a/src/test/java/com/mercateo/jsonschema/SchemaGeneratorTest.kt +++ b/src/test/java/com/mercateo/jsonschema/SchemaGeneratorTest.kt @@ -63,9 +63,9 @@ class SchemaGeneratorTest { defaultValue.qux = 5.1 defaultValue.quux = true - val schema = schemaGenerator.generateSchema(schemaClass, defaultValue = defaultValue) + val generateSchema = schemaGenerator.generateSchema(schemaClass, defaultValue = defaultValue) - assertThat(schema.toString()).isEqualTo("{\"type\":\"object\",\"properties\":{\"baar\":{\"type\":\"integer\",\"default\":100},\"bar\":{\"type\":\"integer\",\"default\":10},\"baz\":{\"type\":\"number\",\"default\":4.8},\"foo\":{\"type\":\"string\",\"default\":\"foo\"},\"quux\":{\"type\":\"boolean\",\"default\":true},\"qux\":{\"type\":\"number\",\"default\":5.1}}}") + assertThat(generateSchema.toString()).isEqualTo("{\"type\":\"object\",\"properties\":{\"baar\":{\"type\":\"integer\",\"default\":100},\"bar\":{\"type\":\"integer\",\"default\":10},\"baz\":{\"type\":\"number\",\"default\":4.8},\"foo\":{\"type\":\"string\",\"default\":\"foo\"},\"quux\":{\"type\":\"boolean\",\"default\":true},\"qux\":{\"type\":\"number\",\"default\":5.1}}}") } @Test