From 76da7a9af9c16265c6796c80291ca43dd8931425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kwiecin=CC=81ski?= Date: Fri, 10 Nov 2023 21:38:21 +0100 Subject: [PATCH] yoloing, part3 --- .github/workflows/publish_snapshots.yml | 4 +- gradle.properties | 1 + gradle/libs.versions.toml | 8 +- licensee-for-android/build.gradle | 4 +- sample/build.gradle | 1 + sample/core/build.gradle | 13 ++- .../se/premex/gross/core/LicenseParser.kt | 2 +- .../se/premex/gross/oss/LicenseParserTest.kt | 94 +++++++++++++++++++ sample/gradle/libs.versions.toml | 9 +- sample/ui/build.gradle | 12 +-- 10 files changed, 119 insertions(+), 29 deletions(-) create mode 100644 sample/core/src/test/kotlin/se/premex/gross/oss/LicenseParserTest.kt diff --git a/.github/workflows/publish_snapshots.yml b/.github/workflows/publish_snapshots.yml index 56e66a3..bfc31c9 100644 --- a/.github/workflows/publish_snapshots.yml +++ b/.github/workflows/publish_snapshots.yml @@ -41,9 +41,9 @@ jobs: key: diffuse-${{ github.sha }} - name: Check size - run: du -h ktlint-gradle-plugin/build/libs/licensee-for-android.jar + run: du -h licensee-for-android/build/libs/licensee-for-android.jar shell: bash - name: Copy diffuse base artifact to be picked by cache save - run: cp ktlint-gradle-plugin/build/libs/licensee-for-android.jar diffuse-base-file + run: cp licensee-for-android/build/libs/licensee-for-android.jar diffuse-base-file shell: bash diff --git a/gradle.properties b/gradle.properties index c140154..e5699c5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,3 +2,4 @@ kotlin.code.style=official org.gradle.caching=true org.gradle.parallel=true org.gradle.jvmargs="-XX:+UseParallelGC" +kotlin.stdlib.default.dependency=false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ef71580..e68aa22 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,10 +14,10 @@ junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", vers assertj-core = { module = "org.assertj:assertj-core", version.ref = "maven-assertj" } agp-gradle-api = { module = "com.android.tools.build:gradle-api", version.ref = "google-agp" } kotlin-gradle-api = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api", version.ref = "maven-kotlin" } -com-squareup-okio = "com.squareup.okio:okio:3.6.0" com-squareup-kotlinpoet = "com.squareup:kotlinpoet:1.14.2" -org-jetbrains-kotlinx-kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "maven-kotlin-serialization" } -org-jetbrains-kotlinx-kotlinx-serialization-json-okio = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio", version.ref = "maven-kotlin-serialization" } +kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "maven-kotlin-serialization" } +kotlinx-serialization-json-okio = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio", version.ref = "maven-kotlin-serialization" } +com-squareup-okio = "com.squareup.okio:okio:3.6.0" [plugins] starter-config = { id = "com.starter.config", version.ref = "gradle-starter" } @@ -25,5 +25,5 @@ starter-versioning = { id = "com.starter.versioning", version.ref = "gradle-star starter-library-kotlin = { id = "com.starter.library.kotlin", version.ref = "gradle-starter" } starter-library-android = { id = "com.starter.library.android", version.ref = "gradle-starter" } gradle-pluginpublish = { id = "com.gradle.plugin-publish", version.ref = "gradle-pluginpublish" } -kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "maven-kotlin-serialization" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "maven-kotlin" } osacky-doctor = { id = "com.osacky.doctor", version.ref = "gradle-doctor" } diff --git a/licensee-for-android/build.gradle b/licensee-for-android/build.gradle index b4229b6..7cf201e 100644 --- a/licensee-for-android/build.gradle +++ b/licensee-for-android/build.gradle @@ -15,8 +15,8 @@ dependencies { exclude(module: "kotlin-reflect") } - implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json) - implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json.okio) + implementation(libs.kotlinx.serialization.json) + implementation(libs.kotlinx.serialization.json.okio) implementation(libs.com.squareup.okio) testRuntimeOnly(libs.junit.jupiter.engine) diff --git a/sample/build.gradle b/sample/build.gradle index 3a5ff7e..0d94363 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,6 +1,7 @@ plugins { alias(libs.plugins.starter.config) alias(libs.plugins.starter.library.android) apply false + alias(libs.plugins.starter.library.kotlin) apply false } commonConfig { diff --git a/sample/core/build.gradle b/sample/core/build.gradle index 36ca456..a8334af 100644 --- a/sample/core/build.gradle +++ b/sample/core/build.gradle @@ -1,14 +1,13 @@ plugins { - alias(libs.plugins.starter.library.android) + alias(libs.plugins.starter.library.kotlin) alias(libs.plugins.kotlin.serialization) } -android { - namespace "io.githhub.usefulness.licensee.android.core" -} - dependencies { - implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json) - implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json.okio) + api(libs.kotlinx.serialization.json) + implementation(libs.kotlinx.serialization.json.okio) api(libs.com.squareup.okio) + + testImplementation(libs.org.jetbrains.kotlin.kotlin.test.junit) + testImplementation(libs.org.jetbrains.kotlinx.kotlinx.coroutines.test) } diff --git a/sample/core/src/main/kotlin/se/premex/gross/core/LicenseParser.kt b/sample/core/src/main/kotlin/se/premex/gross/core/LicenseParser.kt index 24f1f1a..4a135ff 100644 --- a/sample/core/src/main/kotlin/se/premex/gross/core/LicenseParser.kt +++ b/sample/core/src/main/kotlin/se/premex/gross/core/LicenseParser.kt @@ -7,5 +7,5 @@ import okio.BufferedSource interface LicenseParser { @ExperimentalSerializationApi - fun decode(source: BufferedSource): List = Json.decodeFromBufferedSource(source) + fun decode(source: BufferedSource) = Json.decodeFromBufferedSource>(source) } diff --git a/sample/core/src/test/kotlin/se/premex/gross/oss/LicenseParserTest.kt b/sample/core/src/test/kotlin/se/premex/gross/oss/LicenseParserTest.kt new file mode 100644 index 0000000..a895268 --- /dev/null +++ b/sample/core/src/test/kotlin/se/premex/gross/oss/LicenseParserTest.kt @@ -0,0 +1,94 @@ +package se.premex.gross.oss + +import kotlinx.coroutines.test.runTest +import kotlinx.serialization.ExperimentalSerializationApi +import okio.buffer +import okio.source +import se.premex.gross.core.LicenseParser +import kotlin.test.Test + +private const val ARTIFACTS_SMALL = """[ + { + "groupId": "androidx.activity", + "artifactId": "activity", + "version": "1.7.0", + "name": "Activity", + "spdxLicenses": [ + { + "identifier": "Apache-2.0", + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0" + } + ], + "scm": { + "url": "https://cs.android.com/androidx/platform/frameworks/support" + } + } +]""" + +private const val ARTIFACTS_MEDIUM = """[ + { + "groupId": "androidx.activity", + "artifactId": "activity", + "version": "1.7.0", + "name": "Activity", + "spdxLicenses": [ + { + "identifier": "Apache-2.0", + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0" + } + ], + "scm": { + "url": "https://cs.android.com/androidx/platform/frameworks/support" + } + }, + { + "groupId": "androidx.activity", + "artifactId": "activity-compose", + "version": "1.7.0", + "name": "Activity Compose", + "spdxLicenses": [ + { + "identifier": "Apache-2.0", + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0" + } + ], + "scm": { + "url": "https://cs.android.com/androidx/platform/frameworks/support" + } + }, + { + "groupId": "androidx.activity", + "artifactId": "activity-ktx", + "version": "1.7.0", + "name": "Activity Kotlin Extensions", + "spdxLicenses": [ + { + "identifier": "Apache-2.0", + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0" + } + ], + "scm": { + "url": "https://cs.android.com/androidx/platform/frameworks/support" + } + } +]""" + +class LicenseParserTest { + @Test + @ExperimentalSerializationApi + fun testSmall() = runTest { + val licenseParser = object : LicenseParser {} + licenseParser.decode(ARTIFACTS_SMALL.byteInputStream().source().buffer()) + } + + @Test + @ExperimentalSerializationApi + fun testMedium() = runTest { + val licenseParser = object : LicenseParser {} + licenseParser.decode(ARTIFACTS_MEDIUM.byteInputStream().source().buffer()) + } +} diff --git a/sample/gradle/libs.versions.toml b/sample/gradle/libs.versions.toml index c6cc7c4..d19112f 100644 --- a/sample/gradle/libs.versions.toml +++ b/sample/gradle/libs.versions.toml @@ -22,6 +22,10 @@ junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.re junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "maven-junit" } assertj-core = { module = "org.assertj:assertj-core", version.ref = "maven-assertj" } +kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "maven-kotlin-serialization" } +kotlinx-serialization-json-okio = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio", version.ref = "maven-kotlin-serialization" } +com-squareup-okio = "com.squareup.okio:okio:3.6.0" + activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity-compose" } org-jetbrains-kotlin-kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "maven-kotlin" } androidx-lifecycle-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle-runtime-ktx" } @@ -40,7 +44,6 @@ androidx-compose-ui = { module = "androidx.compose.ui:ui" } androidx-compose-ui-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } androidx-compose-runtime-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata" } androidx-compose-ui-ui-text = { module = "androidx.compose.ui:ui-text" } -com-squareup-okio = "com.squareup.okio:okio:3.6.0" androidx-core-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core" } core-ktx = { module = "androidx.core:core-ktx", version.ref = "core-ktx" } espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso-core" } @@ -48,8 +51,6 @@ junit = { module = "junit:junit", version.ref = "junit" } org-jetbrains-kotlinx-kotlinx-coroutines-test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3" lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle-runtime-ktx" } material3 = { module = "androidx.compose.material3:material3" } -org-jetbrains-kotlinx-kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "maven-kotlin-serialization" } -org-jetbrains-kotlinx-kotlinx-serialization-json-okio = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio", version.ref = "maven-kotlin-serialization" } org-jetbrains-kotlin-kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "maven-kotlin" } ui = { module = "androidx.compose.ui:ui" } ui-graphics = { module = "androidx.compose.ui:ui-graphics" } @@ -60,7 +61,7 @@ ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" } io-nlopez-compose = "io.nlopez.compose.rules:ktlint:0.3.3" [plugins] -kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "maven-kotlin-serialization" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "maven-kotlin" } starter-config = { id = "com.starter.config", version.ref = "gradle-starter" } starter-versioning = { id = "com.starter.versioning", version.ref = "gradle-starter" } starter-library-kotlin = { id = "com.starter.library.kotlin", version.ref = "gradle-starter" } diff --git a/sample/ui/build.gradle b/sample/ui/build.gradle index 7b5f561..7914211 100644 --- a/sample/ui/build.gradle +++ b/sample/ui/build.gradle @@ -1,6 +1,5 @@ plugins { alias(libs.plugins.starter.library.android) - alias(libs.plugins.kotlin.serialization) } android { @@ -19,26 +18,21 @@ android { } dependencies { api(project(":core")) - implementation(libs.com.squareup.okio) implementation(platform(libs.androidx.compose.bom)) implementation(libs.androidx.compose.runtime) implementation(libs.androidx.compose.ui) implementation(libs.androidx.compose.foundation.foundation.layout) implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.foundation) - - implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json) - - implementation(libs.androidx.compose.material.material.icons.extended) - implementation(libs.androidx.compose.animation) - implementation(libs.androidx.compose.ui.ui.tooling) implementation(libs.androidx.compose.runtime.runtime.livedata) implementation(libs.androidx.compose.ui.ui.text) - + implementation(libs.androidx.compose.material.material.icons.extended) implementation(libs.androidx.core.core.ktx) + testImplementation(libs.org.jetbrains.kotlin.kotlin.test.junit) testImplementation(libs.org.jetbrains.kotlinx.kotlinx.coroutines.test) + ktlintRuleSet(libs.io.nlopez.compose) }