diff --git a/.editorconfig b/.editorconfig index 023ea56..a6820b5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,5 @@ ij_kotlin_allow_trailing_comma_on_call_site = true ktlint_code_style = intellij_idea ktlint_standard_property-naming = disabled ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 2 +ktlint_function_naming_ignore_when_annotated_with = Composable +ktlint_compose_unstable-collections = disabled \ No newline at end of file diff --git a/.github/workflows/publish_snapshots.yml b/.github/workflows/publish_snapshots.yml new file mode 100644 index 0000000..56e66a3 --- /dev/null +++ b/.github/workflows/publish_snapshots.yml @@ -0,0 +1,49 @@ +name: Publish Project Snapshot + +on: + push: + branches: + - 'master' + schedule: + - cron: '0 3 * * 1,4' + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + diffuse: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Write Gradle build properties to `~/.gradle/gradle.properties` + run: | + mkdir -p ~/.gradle + printf "org.gradle.jvmargs=-Xmx3G -XX:+UseParallelGC\n" >> ~/.gradle/gradle.properties + printf "org.gradle.vfs.watch=false\n" >> ~/.gradle/gradle.properties + shell: bash + + - uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 21 + + - uses: gradle/gradle-build-action@v2 + + - run: ./gradlew assemble -PskipJarVersion + + - name: Upload diffuse base artifact + uses: actions/cache@v3 + with: + path: diffuse-base-file + key: diffuse-${{ github.sha }} + + - name: Check size + run: du -h ktlint-gradle-plugin/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 + shell: bash diff --git a/build.gradle b/build.gradle index f855a9b..6df57a6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapperKt plugins { alias(libs.plugins.starter.config) @@ -11,6 +12,14 @@ commonConfig { allprojects { pluginManager.withPlugin("kotlin") { plugin -> + def kotlinVersion = KotlinPluginWrapperKt.getKotlinPluginVersion(project) + configurations.matching { it.name != "detekt" }.configureEach { + resolutionStrategy.eachDependency { + if (requested.group == 'org.jetbrains.kotlin' && requested.name.startsWith("kotlin")) { + useVersion kotlinVersion + } + } + } kotlin { jvmToolchain(21) } @@ -18,7 +27,7 @@ allprojects { pluginManager.withPlugin("java") { if (project.hasProperty("skipJarVersion")) { tasks.named("jar") { - archiveFile.set(new File(project.buildDir, "libs/${project.name}.jar")) + archiveFile.set(project.layout.buildDirectory.map { it.file("libs/${project.name}.jar")}) } } } diff --git a/core/build.gradle.kts b/core/build.gradle.kts deleted file mode 100644 index f7c1711..0000000 --- a/core/build.gradle.kts +++ /dev/null @@ -1,26 +0,0 @@ -plugins { - kotlin("jvm") version "1.9.20" - kotlin("plugin.serialization") version "1.9.20" -} - - -group = "se.premex.gross" -version = "1.0" - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - vendor.set(JvmVendorSpec.AZUL) - } -} - -dependencies { - implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json) - implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json.okio) - implementation(libs.com.squareup.okio) - - testImplementation(libs.org.jetbrains.kotlin.kotlin.test.junit) - testImplementation(libs.org.jetbrains.kotlinx.kotlinx.coroutines.test) - - detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.1") -} diff --git a/gradle.properties b/gradle.properties index 8607c87..c140154 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,3 @@ -android.useAndroidX=true -android.nonTransitiveRClass=true kotlin.code.style=official org.gradle.caching=true org.gradle.parallel=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f769c29..ef71580 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,61 +8,16 @@ maven-kotlin = "1.9.20" maven-junit = "5.10.1" maven-assertj = "3.24.2" -activity-compose = "1.8.0" -androidx-compose-compiler = "1.4.7" -androidx-core = "1.12.0" -androidx-test-ext-junit = "1.1.5" -com-android-application = "8.1.3" -com-squareup-moshi = "1.15.0" -compose-bom = "2023.10.01" -core-ktx = "1.12.0" -espresso-core = "3.5.1" -junit = "4.13.2" -lifecycle-runtime-ktx = "2.6.2" - [libraries] junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "maven-junit" } 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" } 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" } - -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" } -androidx-test-ext-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-test-ext-junit" } -com-android-tools-build-gradle = { module = "com.android.tools.build:gradle", version.ref = "com-android-application" } -com-squareup-moshi = { module = "com.squareup.moshi:moshi", version.ref = "com-squareup-moshi" } -com-squareup-moshi-moshi-kotlin-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "com-squareup-moshi" } -androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "compose-bom" } -androidx-compose-animation = { module = "androidx.compose.animation:animation" } -androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" } -androidx-compose-foundation-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" } -androidx-compose-material3 = { module = "androidx.compose.material3:material3" } -androidx-compose-material-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" } -androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" } -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" } -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" } +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-jvm = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-jvm", 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" } -ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" } -ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" } -ui-tooling = { module = "androidx.compose.ui:ui-tooling" } -ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" } [plugins] starter-config = { id = "com.starter.config", version.ref = "gradle-starter" } @@ -72,4 +27,3 @@ starter-library-android = { id = "com.starter.library.android", version.ref = "g gradle-pluginpublish = { id = "com.gradle.plugin-publish", version.ref = "gradle-pluginpublish" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "maven-kotlin-serialization" } osacky-doctor = { id = "com.osacky.doctor", version.ref = "gradle-doctor" } -app-cash-licensee = "app.cash.licensee:1.8.0" diff --git a/licensee-for-android/build.gradle b/licensee-for-android/build.gradle index 40c2f94..b4229b6 100644 --- a/licensee-for-android/build.gradle +++ b/licensee-for-android/build.gradle @@ -11,7 +11,7 @@ plugins { dependencies { compileOnly(libs.agp.gradle.api) compileOnly(libs.kotlin.gradle.api) - implementation("com.squareup:kotlinpoet:1.14.2") { + implementation(libs.com.squareup.kotlinpoet) { exclude(module: "kotlin-reflect") } diff --git a/sample/build.gradle b/sample/build.gradle new file mode 100644 index 0000000..3a5ff7e --- /dev/null +++ b/sample/build.gradle @@ -0,0 +1,20 @@ +plugins { + alias(libs.plugins.starter.config) + alias(libs.plugins.starter.library.android) apply false +} + +commonConfig { + javaVersion = JavaVersion.VERSION_1_8 +} + +subprojects { + pluginManager.withPlugin("io.gitlab.arturbosch.detekt") { + detekt { + baseline = file("config/baseline.xml") + } + tasks.named("detektBaseline") { + jvmTarget = "20" + } + } + +} diff --git a/core/.gitignore b/sample/core/.gitignore similarity index 100% rename from core/.gitignore rename to sample/core/.gitignore diff --git a/sample/core/build.gradle b/sample/core/build.gradle new file mode 100644 index 0000000..36ca456 --- /dev/null +++ b/sample/core/build.gradle @@ -0,0 +1,14 @@ +plugins { + alias(libs.plugins.starter.library.android) + 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.com.squareup.okio) +} diff --git a/core/src/main/java/se/premex/gross/core/Artifact.kt b/sample/core/src/main/kotlin/se/premex/gross/core/Artifact.kt similarity index 71% rename from core/src/main/java/se/premex/gross/core/Artifact.kt rename to sample/core/src/main/kotlin/se/premex/gross/core/Artifact.kt index dca7d53..e88404c 100644 --- a/core/src/main/java/se/premex/gross/core/Artifact.kt +++ b/sample/core/src/main/kotlin/se/premex/gross/core/Artifact.kt @@ -3,13 +3,20 @@ package se.premex.gross.core import kotlinx.serialization.Serializable @Serializable -data class SpdxLicenses(val identifier: String, val name: String, val url: String) +data class SpdxLicenses( + val identifier: String, + val name: String, + val url: String, +) @Serializable data class Scm(val url: String) @Serializable -data class UnknownLicenses(val name: String, val url: String) +data class UnknownLicenses( + val name: String, + val url: String, +) @Serializable data class Artifact( diff --git a/core/src/main/java/se/premex/gross/core/LicenseParser.kt b/sample/core/src/main/kotlin/se/premex/gross/core/LicenseParser.kt similarity index 70% rename from core/src/main/java/se/premex/gross/core/LicenseParser.kt rename to sample/core/src/main/kotlin/se/premex/gross/core/LicenseParser.kt index bffab84..24f1f1a 100644 --- a/core/src/main/java/se/premex/gross/core/LicenseParser.kt +++ b/sample/core/src/main/kotlin/se/premex/gross/core/LicenseParser.kt @@ -7,7 +7,5 @@ import okio.BufferedSource interface LicenseParser { @ExperimentalSerializationApi - fun decode(source: BufferedSource): List { - return Json.decodeFromBufferedSource(source) - } + fun decode(source: BufferedSource): List = Json.decodeFromBufferedSource(source) } diff --git a/sample/gradle.properties b/sample/gradle.properties new file mode 100644 index 0000000..8607c87 --- /dev/null +++ b/sample/gradle.properties @@ -0,0 +1,6 @@ +android.useAndroidX=true +android.nonTransitiveRClass=true +kotlin.code.style=official +org.gradle.caching=true +org.gradle.parallel=true +org.gradle.jvmargs="-XX:+UseParallelGC" diff --git a/sample/gradle/libs.versions.toml b/sample/gradle/libs.versions.toml new file mode 100644 index 0000000..c6cc7c4 --- /dev/null +++ b/sample/gradle/libs.versions.toml @@ -0,0 +1,67 @@ +[versions] +gradle-starter = "0.65.0" +maven-kotlin-serialization = "1.6.0" +maven-kotlin = "1.9.20" +maven-junit = "5.10.1" +maven-assertj = "3.24.2" + +activity-compose = "1.8.0" +androidx-compose-compiler = "1.5.4" +androidx-core = "1.12.0" +androidx-test-ext-junit = "1.1.5" +com-android-application = "8.1.3" +com-squareup-moshi = "1.15.0" +compose-bom = "2023.10.01" +core-ktx = "1.12.0" +espresso-core = "3.5.1" +junit = "4.13.2" +lifecycle-runtime-ktx = "2.6.2" + +[libraries] +junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "maven-junit" } +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" } + +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" } +androidx-test-ext-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-test-ext-junit" } +com-android-tools-build-gradle = { module = "com.android.tools.build:gradle", version.ref = "com-android-application" } +com-squareup-moshi = { module = "com.squareup.moshi:moshi", version.ref = "com-squareup-moshi" } +com-squareup-moshi-moshi-kotlin-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "com-squareup-moshi" } +androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "compose-bom" } +androidx-compose-animation = { module = "androidx.compose.animation:animation" } +androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" } +androidx-compose-foundation-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" } +androidx-compose-material3 = { module = "androidx.compose.material3:material3" } +androidx-compose-material-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" } +androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" } +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" } +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" } +ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" } +ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" } +ui-tooling = { module = "androidx.compose.ui:ui-tooling" } +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" } +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" } +starter-library-android = { id = "com.starter.library.android", version.ref = "gradle-starter" } diff --git a/sample/gradle/wrapper/gradle-wrapper.jar b/sample/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7f93135 Binary files /dev/null and b/sample/gradle/wrapper/gradle-wrapper.jar differ diff --git a/sample/gradle/wrapper/gradle-wrapper.properties b/sample/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3fa8f86 --- /dev/null +++ b/sample/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/sample/gradlew b/sample/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/sample/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/sample/gradlew.bat b/sample/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/sample/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/sample/settings.gradle b/sample/settings.gradle new file mode 100644 index 0000000..40cf901 --- /dev/null +++ b/sample/settings.gradle @@ -0,0 +1,33 @@ +import org.gradle.api.initialization.resolve.RepositoriesMode + +pluginManagement { + includeBuild("..") + repositories { + google { + content { + includeGroupByRegex "com\\.android.*" + includeGroupByRegex "androidx.*" + includeGroupByRegex "android.arch.*" + includeGroupByRegex "com\\.google.*" + } + } + gradlePluginPortal { + content { + excludeModule("io.github.usefulness", "lincensee-for-android") + } + } + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} +rootProject.name = "io.github.usefulness.sample" + +include(":core") +//include("app") +include(":ui") diff --git a/sample/ui/.gitignore b/sample/ui/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/sample/ui/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/sample/ui/build.gradle b/sample/ui/build.gradle new file mode 100644 index 0000000..7b5f561 --- /dev/null +++ b/sample/ui/build.gradle @@ -0,0 +1,44 @@ +plugins { + alias(libs.plugins.starter.library.android) + alias(libs.plugins.kotlin.serialization) +} + +android { + namespace "io.githhub.usefulness.licensee.android.ui" + + compileSdk = 34 + defaultConfig { + minSdk = 26 + } + buildFeatures { + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get() + } +} +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.core.core.ktx) + testImplementation(libs.org.jetbrains.kotlin.kotlin.test.junit) + testImplementation(libs.org.jetbrains.kotlinx.kotlinx.coroutines.test) + ktlintRuleSet(libs.io.nlopez.compose) +} diff --git a/sample/ui/config/baseline.xml b/sample/ui/config/baseline.xml new file mode 100644 index 0000000..3869c16 --- /dev/null +++ b/sample/ui/config/baseline.xml @@ -0,0 +1,19 @@ + + + + + FunctionNaming:ErrorView.kt$@Composable fun ErrorView(errorString: String, errorMessage: String, modifier: Modifier = Modifier) + FunctionNaming:ErrorView.kt$@Composable fun ErrorView(modifier: Modifier = Modifier, content: @Composable () -> Unit) + FunctionNaming:ErrorView.kt$@Preview @Composable private fun ErrorViewPreview() + FunctionNaming:LoadingView.kt$@Composable fun LoadingView(loadingTitle: String, modifier: Modifier = Modifier) + FunctionNaming:LoadingView.kt$@Composable fun LoadingView(modifier: Modifier = Modifier, content: @Composable () -> Unit = {}) + FunctionNaming:LoadingView.kt$@Preview @Composable private fun PreviewLoadingView() + FunctionNaming:OssView.kt$@Composable fun CharacterHeader(initial: String, modifier: Modifier = Modifier) + FunctionNaming:OssView.kt$@Composable fun LicenseSelector(title: String, licenses: List<License>, close: () -> Unit) + FunctionNaming:OssView.kt$@Composable fun OssView(artifacts: List<Artifact>, modifier: Modifier = Modifier) + FunctionNaming:OssView.kt$@Preview(showSystemUi = true) @Composable private fun LicenseSelectorPreview() + UnusedPrivateMember:ErrorView.kt$@Preview @Composable private fun ErrorViewPreview() + UnusedPrivateMember:LoadingView.kt$@Preview @Composable private fun PreviewLoadingView() + UnusedPrivateMember:OssView.kt$@Preview(showSystemUi = true) @Composable private fun LicenseSelectorPreview() + + diff --git a/sample/ui/src/main/kotlin/se/premex/gross/ui/AssetLicenseParser.kt b/sample/ui/src/main/kotlin/se/premex/gross/ui/AssetLicenseParser.kt new file mode 100644 index 0000000..4dc375a --- /dev/null +++ b/sample/ui/src/main/kotlin/se/premex/gross/ui/AssetLicenseParser.kt @@ -0,0 +1,28 @@ +package se.premex.gross.ui + +import android.content.res.AssetManager +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import kotlinx.serialization.ExperimentalSerializationApi +import okio.buffer +import okio.source +import se.premex.gross.core.Artifact +import se.premex.gross.core.LicenseParser +import se.premex.gross.core.SpdxLicenses +import se.premex.gross.core.UnknownLicenses + +class AssetLicenseParser(private val assetManager: AssetManager) : LicenseParser { + @ExperimentalSerializationApi + suspend fun readFromAssets(): List = withContext(Dispatchers.IO) { + val source = assetManager.open("artifacts.json").source().buffer() + decode(source) + } +} + +internal fun List?.unknownToLicenses(): List = orEmpty().map { unknown -> unknown.asLicense() } + +internal fun UnknownLicenses.asLicense(): License = License(name, url) + +internal fun List?.spdxToLicenses(): List = orEmpty().map { spdx -> spdx.asLicense() } + +internal fun SpdxLicenses.asLicense() = License(title = name, url = url) diff --git a/sample/ui/src/main/kotlin/se/premex/gross/ui/ErrorView.kt b/sample/ui/src/main/kotlin/se/premex/gross/ui/ErrorView.kt new file mode 100644 index 0000000..5c113e1 --- /dev/null +++ b/sample/ui/src/main/kotlin/se/premex/gross/ui/ErrorView.kt @@ -0,0 +1,48 @@ +package se.premex.gross.ui + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Error +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import io.githhub.usefulness.licensee.android.ui.R + +@Composable +fun ErrorView(errorString: String, errorMessage: String, modifier: Modifier = Modifier) = ErrorView(modifier = modifier) { + Text(text = errorString) + Text(text = errorMessage) +} + +@Composable +fun ErrorView(modifier: Modifier = Modifier, content: @Composable () -> Unit) { + Column( + modifier = modifier.fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + ) { + Icon( + imageVector = Icons.Filled.Error, + contentDescription = stringResource( + id = R.string.error, + ), + ) + Spacer(Modifier.height(16.dp)) + content() + } +} + +@Preview +@Composable +private fun ErrorViewPreview() { + ErrorView("ErrorString", "ErrorMessage") +} diff --git a/sample/ui/src/main/kotlin/se/premex/gross/ui/LoadingView.kt b/sample/ui/src/main/kotlin/se/premex/gross/ui/LoadingView.kt new file mode 100644 index 0000000..368486f --- /dev/null +++ b/sample/ui/src/main/kotlin/se/premex/gross/ui/LoadingView.kt @@ -0,0 +1,38 @@ +package se.premex.gross.ui + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp + +@Composable +fun LoadingView(loadingTitle: String, modifier: Modifier = Modifier) = LoadingView(modifier) { + Text(text = loadingTitle) +} + +@Composable +fun LoadingView(modifier: Modifier = Modifier, content: @Composable () -> Unit = {}) { + Column( + modifier = modifier.fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + ) { + CircularProgressIndicator() + Spacer(Modifier.height(32.dp)) + content() + } +} + +@Preview +@Composable +private fun PreviewLoadingView() { + LoadingView("LoadingTitle") +} diff --git a/sample/ui/src/main/kotlin/se/premex/gross/ui/OssView.kt b/sample/ui/src/main/kotlin/se/premex/gross/ui/OssView.kt new file mode 100644 index 0000000..8b34297 --- /dev/null +++ b/sample/ui/src/main/kotlin/se/premex/gross/ui/OssView.kt @@ -0,0 +1,160 @@ +@file:OptIn(ExperimentalFoundationApi::class) + +package se.premex.gross.ui + +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Link +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Icon +import androidx.compose.material3.ListItem +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshots.SnapshotStateList +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalUriHandler +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import io.githhub.usefulness.licensee.android.ui.R +import se.premex.gross.core.Artifact + +@Composable +fun OssView(artifacts: List, modifier: Modifier = Modifier) { + val viewData = artifacts.map { artifact -> + val licenses = + artifact.spdxLicenses.spdxToLicenses() + artifact.unknownLicenses.unknownToLicenses() + + val nameOrPackage = + artifact.name ?: ("${artifact.groupId}:${artifact.artifactId}:${artifact.version}") + + ViewArtifact(nameOrPackage, licenses) + }.sortedBy { it.title } + + val licenses: SnapshotStateList = remember { mutableStateListOf() } + var alertTitle by remember { mutableStateOf("") } + LicenseSelector(alertTitle, licenses) { + licenses.clear() + } + + LazyColumn( + modifier = modifier.fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + ) { + item { + Column( + modifier = Modifier + .fillMaxSize() + .padding(16.dp), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + textAlign = TextAlign.Center, + modifier = Modifier.padding(horizontal = 40.dp), + text = stringResource(id = R.string.oss_description), + ) + } + } + + val grouped: Map> = + viewData.groupBy { it.title[0].uppercaseChar().toString() } + grouped.forEach { (title, list) -> + stickyHeader { + CharacterHeader(title) + } + items(list) { artifact -> + ListItem( + headlineContent = { + Text(text = artifact.title) + }, + modifier = Modifier.clickable { + alertTitle = artifact.title + licenses.addAll(artifact.licenses) + }, + ) + } + } + } +} + +@Composable +fun CharacterHeader(initial: String, modifier: Modifier = Modifier) { + Text( + modifier = modifier.padding( + start = 16.dp, + top = 16.dp, + end = 16.dp, + bottom = 4.dp, + ), + text = initial, + ) +} + +@Preview(showSystemUi = true) +@Composable +private fun LicenseSelectorPreview() { + Column(Modifier.fillMaxSize()) { + LicenseSelector("Licenses", listOf(License("aaa", "http://google.se"))) { + } + } +} + +@Composable +fun LicenseSelector(title: String, licenses: List, close: () -> Unit) { + val uriHandler = LocalUriHandler.current + + if (licenses.isNotEmpty()) { + AlertDialog( + onDismissRequest = { + close() + }, + title = { + Text(text = title) + }, + text = { + Column { + licenses.forEach { license -> + ListItem( + headlineContent = { + Text(text = license.title) + }, + leadingContent = { + Icon( + imageVector = Icons.Filled.Link, + contentDescription = null, + ) + }, + modifier = Modifier.clickable { + uriHandler.openUri(license.url) + }, + ) + } + } + }, + confirmButton = { + TextButton( + onClick = close, + ) { + Text(stringResource(id = R.string.close)) + } + }, + ) + } +} diff --git a/sample/ui/src/main/kotlin/se/premex/gross/ui/OssViewModel.kt b/sample/ui/src/main/kotlin/se/premex/gross/ui/OssViewModel.kt new file mode 100644 index 0000000..66d667c --- /dev/null +++ b/sample/ui/src/main/kotlin/se/premex/gross/ui/OssViewModel.kt @@ -0,0 +1,21 @@ +package se.premex.gross.ui + +import se.premex.gross.core.Artifact + +sealed class State { + class Loading : State() + data class Success(val data: T) : State() + data class Failed(val errorMessage: String) : State() +} + +data class OssViewState(val viewState: State> = State.Loading()) + +data class ViewArtifact( + val title: String, + val licenses: List, +) + +data class License( + val title: String, + val url: String, +) diff --git a/sample/ui/src/main/res/values/strings.xml b/sample/ui/src/main/res/values/strings.xml new file mode 100644 index 0000000..4751e70 --- /dev/null +++ b/sample/ui/src/main/res/values/strings.xml @@ -0,0 +1,8 @@ + + + Open source licenses + Error + Loading + This application is built with the following open source projects. + Close + \ No newline at end of file diff --git a/sample/ui/src/test/kotlin/se/premex/gross/oss/LicenseParserTest.kt b/sample/ui/src/test/kotlin/se/premex/gross/oss/LicenseParserTest.kt new file mode 100644 index 0000000..a895268 --- /dev/null +++ b/sample/ui/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()) + } +}