Skip to content

Commit

Permalink
use sonarcloud (#2)
Browse files Browse the repository at this point in the history
* use sonarcloud

* update versions

* update

* add missing token

* downgrade to kotlin 1.9

* small fix

* wupdate
  • Loading branch information
wuan authored Oct 13, 2024
1 parent 5386ca2 commit 7aa4055
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 36 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Basic CI
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

jobs:
gradle:
Expand All @@ -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
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

22 changes: 12 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Expand All @@ -18,18 +17,19 @@ repositories {
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
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 {
Expand All @@ -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")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=0.1.1-SNAPSHOT
org.gradle.jvmargs=-Xms128m -Xmx1024m
org.gradle.jvmargs=-Xms128m -Xmx2048m
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class SchemaPropertyMapper(private val referencedElements: Set<String>) {
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")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.*

object PropertyTypeMapper {

private val TYPE_MAP = mapOf(
private val TYPE_MAP: Map<Class<out Any?>, PropertyType> = mapOf(
Pair(String::class.java, PropertyType.STRING),
Pair(Boolean::class.java, PropertyType.BOOLEAN),
Pair(java.lang.Boolean::class.java, PropertyType.BOOLEAN),
Expand All @@ -33,7 +33,7 @@ object PropertyTypeMapper {
return PropertyType.ARRAY
}

val clazz = type.rawType
val clazz: Class<out Any?> = type.rawType
if (Enum::class.java.isAssignableFrom(clazz)) {
return PropertyType.STRING
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/mercateo/jsonschema/SchemaGeneratorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7aa4055

Please sign in to comment.