Skip to content

Commit

Permalink
use moshi (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredsburrows authored Apr 25, 2022
1 parent 1908d6f commit 468cdc1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle-license-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
implementation(platform(libs.kotlin.bom))
implementation libs.kotlin.stdlib
implementation libs.kotlinx.html
implementation libs.gson
implementation libs.moshi
implementation libs.maven.model

testRuntimeOnly files(createClasspathManifest)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jaredsburrows.license.internal.report

import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import org.apache.maven.model.Model

/**
Expand Down Expand Up @@ -42,7 +42,14 @@ class JsonReport(private val projects: List<Model>) : Report {
)
}

return gson.toJson(reportList, object : TypeToken<MutableList<Map<String, Any?>>>() {}.type)
return moshi.adapter<List<Map<String, Any?>>>(
Types.newParameterizedType(
List::class.java,
Map::class.java,
String::class.java,
Any::class.java
)
).serializeNulls().toJson(reportList)
}

override fun emptyReport(): String = EMPTY_JSON
Expand All @@ -61,9 +68,6 @@ class JsonReport(private val projects: List<Model>) : Report {
private const val LICENSE_URL = "license_url"
private const val DEPENDENCY = "dependency"
private const val EMPTY_JSON = "[]"
private val gson = GsonBuilder()
.setPrettyPrinting()
.serializeNulls()
.create()
private val moshi = Moshi.Builder().build()
}
}
8 changes: 5 additions & 3 deletions gradle-license-plugin/src/test/groovy/test/TestUtils.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package test

import com.google.gson.JsonParser
import com.jaredsburrows.license.internal.report.HtmlReport
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import org.apache.commons.csv.CSVFormat
import org.gradle.testkit.runner.GradleRunner
import org.xmlunit.builder.DiffBuilder
Expand Down Expand Up @@ -30,8 +31,9 @@ final class TestUtils {
}

static def assertJson(def expected, def actual) {
def parser = new JsonParser()
return parser.parseString(actual).toString() == parser.parseString(expected).toString()
def moshi = new Moshi.Builder().build()
def jsonAdapter = moshi.adapter(Types.newParameterizedType(List.class, Map.class, String.class, Object.class))
return jsonAdapter.fromJson(expected) == jsonAdapter.fromJson(actual)
}

static def gradleWithCommand(def file, String... commands) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ versions = { id = "com.github.ben-manes.versions", version = "0.42.0" }
[libraries]
android-plugin = { module = "com.android.tools.build:gradle", version = "3.6.4" }
commons = { module = "org.apache.commons:commons-csv", version = "1.9.0" }
gson = { module = "com.google.code.gson:gson", version = "2.9.0" }
moshi = { module = "com.squareup.moshi:moshi", version = "1.13.0" }
kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
kotlinx-html = { module = "org.jetbrains.kotlinx:kotlinx-html-jvm", version = "0.7.5" }
Expand Down

0 comments on commit 468cdc1

Please sign in to comment.