diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..023ea56 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +insert_final_newline = true + +[*.{kt,kts}] +max_line_length = 140 +indent_size = 4 +ij_kotlin_allow_trailing_comma = true +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 diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 3ac8de9..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "gradle" - directory: "/" - schedule: - interval: "daily" - time: "05:00" - timezone: "Europe/Stockholm" - open-pull-requests-limit: 10 - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "daily" - time: "05:00" - timezone: "Europe/Stockholm" - open-pull-requests-limit: 10 \ No newline at end of file diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml deleted file mode 100644 index fe1351d..0000000 --- a/.github/release-drafter.yml +++ /dev/null @@ -1,31 +0,0 @@ -name-template: 'v$RESOLVED_VERSION 🌈' -tag-template: 'v$RESOLVED_VERSION' -categories: - - title: '🚀 Features' - labels: - - 'feature' - - 'enhancement' - - title: '🐛 Bug Fixes' - labels: - - 'fix' - - 'bugfix' - - 'bug' - - title: '🧰 Maintenance' - label: 'chore' -change-template: '- $TITLE @$AUTHOR (#$NUMBER)' -change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. -version-resolver: - major: - labels: - - 'major' - minor: - labels: - - 'minor' - patch: - labels: - - 'patch' - default: patch -template: | - ## Changes - - $CHANGES \ No newline at end of file diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml new file mode 100644 index 0000000..79b646f --- /dev/null +++ b/.github/workflows/default.yml @@ -0,0 +1,56 @@ +name: Build Project + +on: + pull_request: + push: + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest, windows-latest ] + name: '[${{ matrix.os }}] build plugin' + 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/wrapper-validation-action@v1 + + - uses: gradle/gradle-build-action@v2 + + - run: ./gradlew assemble + + - run: ./gradlew check + + - run: ./gradlew publishToMavenLocal + + - run: ./gradlew publishPlugins -m + + - run: git diff --exit-code + + - uses: actions/upload-artifact@v3 + if: ${{ always() }} + with: + name: test-results-${{ matrix.os }} + path: "${{ github.workspace }}/**/build/reports/tests" diff --git a/.github/workflows/post-merge.yml b/.github/workflows/post-merge.yml deleted file mode 100644 index c693f05..0000000 --- a/.github/workflows/post-merge.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Post Merge verifications - -on: - push: - branches: [ main ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: '0' - - - uses: actions/setup-java@v3 - with: - distribution: zulu - java-version: 17 - - - name: Setup Gradle - uses: gradle/gradle-build-action@v2 - # gradle-home-cache-cleanup: true - - - name: Run verifications - run: ./gradlew check --scan - - - name: Run validate on ui - run: ./gradlew :ui:check --scan - - - name: Run validate on core - run: ./gradlew :core:check --scan - - - name: Run validate on plugin - run: ./gradlew :gross-plugin:check :gross-plugin:validatePlugins --scan - - - name: Upload reports - uses: actions/upload-artifact@v3 - if: failure() - with: - name: Reports - path: '**/build/test-results/test/*' \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml deleted file mode 100644 index 85ca8ec..0000000 --- a/.github/workflows/pull-request.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: PR Checks - -on: - pull_request: - branches: [ main ] - -# Ensures that only one deploy task per branch/environment will run at a time. -concurrency: - group: ${{ github.head_ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: '0' - - - uses: actions/setup-java@v3 - with: - distribution: zulu - java-version: 17 - - - name: Setup Gradle - uses: gradle/gradle-build-action@v2 - - - name: Run verifications - run: ./gradlew check --scan - - - name: Run validate on ui - run: ./gradlew :ui:check --scan - - - name: Run validate on core - run: ./gradlew :core:check --scan - - - name: Run validate on plugin - run: ./gradlew :gross-plugin:check :gross-plugin:validatePlugins --scan - - - name: Upload reports - uses: actions/upload-artifact@v3 - if: failure() - with: - name: Reports - path: '**/build/test-results/test/*' \ No newline at end of file diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml deleted file mode 100644 index 90bd56a..0000000 --- a/.github/workflows/release-drafter.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Release Drafter - -on: - push: - branches: - - main - pull_request: - types: [opened, reopened, synchronize] - -permissions: - contents: read - -jobs: - update_release_draft: - permissions: - contents: write - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: release-drafter/release-drafter@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release-gross-plugin.yml b/.github/workflows/release-gross-plugin.yml deleted file mode 100644 index fd2211e..0000000 --- a/.github/workflows/release-gross-plugin.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Gross plugin release - -on: - release: - types: [ published ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: '0' - - - name: Release tag - run: | - git describe --tags --always --first-parent - git tag - - - name: Setup java - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: zulu - - - name: Run verifications - run: ./gradlew check --scan - - - name: Run validate on ui - run: ./gradlew :ui:check --scan - - - name: Run validate on core - run: ./gradlew :core:check --scan - - - name: Run validate on plugin - run: ./gradlew :gross-plugin:check :gross-plugin:validatePlugins --scan - - - name: Upload reports - uses: actions/upload-artifact@v3 - if: failure() - with: - name: Reports - path: '**/build/test-results/test/*' - - - name: Publish Gradle Plugin - env: - KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} - SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} - run: | - ./gradlew -Dgradle.publish.key=$KEY -Dgradle.publish.secret=$SECRET :gross-plugin:publishPlugins \ No newline at end of file diff --git a/.gitignore b/.gitignore index aa724b7..43dfc7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,12 @@ +build +out +*.iws +*.ipr *.iml +TODO.md +.idea .gradle -/local.properties -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml -.DS_Store -/build -/captures -.externalNativeBuild -.cxx +# Gradle files +.gradle/ +build/ local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 89ffb81..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Gross \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index b589d56..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 9c7d8f1..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 0fc3113..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 8978d23..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..5fce411 --- /dev/null +++ b/build.gradle @@ -0,0 +1,18 @@ + +plugins { + alias(libs.plugins.starter.config) + alias(libs.plugins.starter.versioning) + alias(libs.plugins.starter.library.kotlin) apply false +} + +commonConfig { + javaVersion JavaVersion.VERSION_11 +} + +allprojects { + pluginManager.withPlugin("kotlin") { plugin -> + kotlin { + jvmToolchain(21) + } + } +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index f2c7a10..f7c1711 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,15 +1,8 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - kotlin("jvm") version "1.8.21" - kotlin("plugin.serialization") version "1.8.21" - id("io.gitlab.arturbosch.detekt") version "1.23.0" - + kotlin("jvm") version "1.9.20" + kotlin("plugin.serialization") version "1.9.20" } -detekt { - autoCorrect = true - buildUponDefaultConfig = true -} group = "se.premex.gross" version = "1.0" diff --git a/core/gradle.properties b/core/gradle.properties deleted file mode 100644 index 8c99103..0000000 --- a/core/gradle.properties +++ /dev/null @@ -1,22 +0,0 @@ -# Project-wide Gradle settings. -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -org.gradle.parallel=true -# Kotlin code style for this project: "official" or "obsolete": -kotlin.code.style=official - -# Seems to be an issue with licensee? We should try to reenable... -# https://github.com/gradle/gradle/issues/17821 -org.gradle.unsafe.configuration-cache=false -org.gradle.unsafe.configuration-cache-problems=warn - -org.gradle.caching=true -org.gradle.configureondemand=true \ No newline at end of file diff --git a/core/settings.gradle.kts b/core/settings.gradle.kts deleted file mode 100644 index 758c2d8..0000000 --- a/core/settings.gradle.kts +++ /dev/null @@ -1,38 +0,0 @@ -rootProject.name = "core" - -pluginManagement { - repositories { - gradlePluginPortal() - mavenCentral() - google() - } -} - -plugins { - id("com.gradle.enterprise") version "3.14.1" - id("org.gradle.toolchains.foojay-resolver-convention") version("0.4.0") -} - -gradleEnterprise { - buildScan { - termsOfServiceUrl = "https://gradle.com/terms-of-service" - termsOfServiceAgree = "yes" - } -} - -dependencyResolutionManagement { - versionCatalogs { - create("libs") { - from(files("../gradle/libs.versions.toml")) - } - } - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - google() - mavenCentral() - gradlePluginPortal() - } -} - -enableFeaturePreview("STABLE_CONFIGURATION_CACHE") - \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 2e5fddb..8607c87 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,31 +1,6 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app's APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true -# Kotlin code style for this project: "official" or "obsolete": -kotlin.code.style=official -# Enables namespacing of each library's R class so that its R class includes only the -# resources declared in the library itself and none from the library's dependencies, -# thereby reducing the size of the R class for that library android.nonTransitiveRClass=true - -# Seems to be an issue with licensee? We should try to reenable... -# https://github.com/gradle/gradle/issues/17821 -org.gradle.unsafe.configuration-cache=false -org.gradle.unsafe.configuration-cache-problems=warn - +kotlin.code.style=official org.gradle.caching=true -org.gradle.configureondemand=true \ No newline at end of file +org.gradle.parallel=true +org.gradle.jvmargs="-XX:+UseParallelGC" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6e57b27..f769c29 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,20 +1,35 @@ [versions] -activity-compose = "1.7.0" +gradle-starter = "0.65.0" +gradle-pluginpublish = "1.2.1" +gradle-doctor = "0.9.0" +google-agp = "8.1.3" +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.4.7" -androidx-core = "1.9.0" +androidx-core = "1.12.0" androidx-test-ext-junit = "1.1.5" -com-android-application = "8.0.0" +com-android-application = "8.1.3" com-squareup-moshi = "1.15.0" -compose-bom = "2023.03.00" -core-ktx = "1.9.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.1" -org-jetbrains-kotlin-android = "1.8.21" +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" } -androidx-lifecycle-lifecycle-viewmodel-ktx = "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.0-beta01" +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" } @@ -30,7 +45,7 @@ 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.5.0" +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" } @@ -38,11 +53,10 @@ 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-kotlin-kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "org-jetbrains-kotlin-android" } -org-jetbrains-kotlinx-kotlinx-serialization-json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1" -org-jetbrains-kotlinx-kotlinx-serialization-json-jvm = "org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.5.1" -org-jetbrains-kotlinx-kotlinx-serialization-json-okio = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio:1.5.1" -org-jetbrains-kotlin-kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "org-jetbrains-kotlin-android" } +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" } @@ -51,9 +65,11 @@ ui-tooling = { module = "androidx.compose.ui:ui-tooling" } ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" } [plugins] -app-cash-licensee = "app.cash.licensee:1.7.0" -com-android-application = { id = "com.android.application", version.ref = "com-android-application" } -com-android-library = { id = "com.android.library", version.ref = "com-android-application" } -com-github-ben-manes-versions = "com.github.ben-manes.versions:0.47.0" -nl-littlerobots-version-catalog-update = "nl.littlerobots.version-catalog-update:0.8.0" -org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "org-jetbrains-kotlin-android" } +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" } +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/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..7f93135 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index da8127d..3fa8f86 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Thu Mar 30 09:17:16 CEST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +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/gradlew b/gradlew index 4f906e0..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# 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. @@ -17,67 +17,99 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# 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 -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +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 -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# 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"' +# 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" +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 - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +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 @@ -87,9 +119,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 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" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + 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" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +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 -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -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" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +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 - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + 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 - i=`expr $i + 1` + # 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 - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# 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/gradlew.bat b/gradlew.bat index 107acd3..6689b85 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,89 +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=. -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%" == "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%"=="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! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@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/gross-plugin/build.gradle.kts b/gross-plugin/build.gradle.kts deleted file mode 100644 index 5f0504f..0000000 --- a/gross-plugin/build.gradle.kts +++ /dev/null @@ -1,94 +0,0 @@ -plugins { - `kotlin-dsl` - kotlin("plugin.serialization") version "1.8.21" - id("java-gradle-plugin") - id("com.gradle.plugin-publish") version "0.21.0" - id("maven-publish") - id("com.gladed.androidgitversion") version "0.4.14" - id("io.gitlab.arturbosch.detekt") version "1.23.0" -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - vendor.set(JvmVendorSpec.AZUL) - } -} - -androidGitVersion { - tagPattern = "^v[0-9]+.*" -} - -detekt { - autoCorrect = true - buildUponDefaultConfig = true -} - -buildscript { - dependencies { - classpath(libs.com.android.tools.build.gradle) - } -} - -dependencies { - implementation(libs.com.android.tools.build.gradle) - implementation(libs.org.jetbrains.kotlin.kotlin.gradle.plugin) - implementation("com.squareup:kotlinpoet:1.14.2") { - exclude(module = "kotlin-reflect") - } - - implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json) - implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json.okio) - implementation(libs.com.squareup.okio) - - // https://github.com/gradle/gradle/issues/15383 - implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) - - detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.1") - - testImplementation(kotlin("test")) -} - -tasks.test { - useJUnitPlatform() -} - -version = androidGitVersion.name().replace("v", "") -group = "se.premex" - - -gradlePlugin { - plugins { - create("gross") { - id = "se.premex.gross" - implementationClass = "se.premex.gross.GrossPlugin" - } - } -} - -pluginBundle { - website = "https://github.com/premex-ab/gross" - vcsUrl = "https://github.com/premex-ab/gross.git" - description = "A plugin that generates a list of open source licenses you depend on" - tags = mutableListOf("tooling", "open source", "premex") - - (plugins) { - "gross" { - displayName = "Generates a list of open source licenses you depend on" - description = - """Generates a list of open source licenses you depend on. Depends on the output of licensee from cashapp - https://github.com/cashapp/licensee. - | - |Can generate a static list or copy licenses to android assets. - | - |As licensee supports KMM the plugin could support more platforms but current only supports android. - """.trimMargin() - } - } -} - - -allprojects { - tasks.withType().configureEach { - enableStricterValidation.set(true) - } -} \ No newline at end of file diff --git a/gross-plugin/src/test/kotlin/se/premex/gross/CodeGenerationTaskTest.kt b/gross-plugin/src/test/kotlin/se/premex/gross/CodeGenerationTaskTest.kt deleted file mode 100644 index 3e12cea..0000000 --- a/gross-plugin/src/test/kotlin/se/premex/gross/CodeGenerationTaskTest.kt +++ /dev/null @@ -1,11 +0,0 @@ -package se.premex.gross - -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals - -class CodeGenerationTaskTest { - @Test - fun example() { - assertEquals(3, 1 + 2) - } -} diff --git a/gross-plugin/.gitignore b/licensee-for-android/.gitignore similarity index 100% rename from gross-plugin/.gitignore rename to licensee-for-android/.gitignore diff --git a/licensee-for-android/build.gradle b/licensee-for-android/build.gradle new file mode 100644 index 0000000..40c2f94 --- /dev/null +++ b/licensee-for-android/build.gradle @@ -0,0 +1,51 @@ +import org.gradle.kotlin.dsl.ProjectExtensionsKt +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("java-gradle-plugin") + alias(libs.plugins.gradle.pluginpublish) + alias(libs.plugins.starter.library.kotlin) + alias(libs.plugins.kotlin.serialization) +} + +dependencies { + compileOnly(libs.agp.gradle.api) + compileOnly(libs.kotlin.gradle.api) + implementation("com.squareup:kotlinpoet:1.14.2") { + exclude(module: "kotlin-reflect") + } + + implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json) + implementation(libs.org.jetbrains.kotlinx.kotlinx.serialization.json.okio) + implementation(libs.com.squareup.okio) + + testRuntimeOnly(libs.junit.jupiter.engine) + testImplementation(libs.junit.jupiter.api) + testImplementation(libs.assertj.core) +} + +tasks.withType(KotlinCompile).configureEach { + kotlinOptions { + apiVersion = "1.8" + languageVersion = "1.8" + } +} +tasks.withType(Test).configureEach { + useJUnitPlatform() +} + +description = "A plugin that generates a list of open source licenses you depend on" + +gradlePlugin { + plugins { + create("gross") { + id = "io.github.usefulness.licensee-for-android" + displayName = "ktlint Gradle plugin" + description = project.description + tags.addAll(["tooling", "open source", "premex"]) + implementationClass = "se.premex.gross.GrossPlugin" + } + } +} + + diff --git a/gross-plugin/src/main/kotlin/se/premex/gross/ArtifactCodeGenerator.kt b/licensee-for-android/src/main/kotlin/se/premex/gross/ArtifactCodeGenerator.kt similarity index 94% rename from gross-plugin/src/main/kotlin/se/premex/gross/ArtifactCodeGenerator.kt rename to licensee-for-android/src/main/kotlin/se/premex/gross/ArtifactCodeGenerator.kt index a3c7260..ebd02ac 100644 --- a/gross-plugin/src/main/kotlin/se/premex/gross/ArtifactCodeGenerator.kt +++ b/licensee-for-android/src/main/kotlin/se/premex/gross/ArtifactCodeGenerator.kt @@ -10,13 +10,11 @@ class ArtifactCodeGenerator( private val packageName: String, private val spdxLicensesTypeSpec: TypeSpec, private val scmTypeSpec: TypeSpec, - private val unknownLicensesTypeSpec: TypeSpec + private val unknownLicensesTypeSpec: TypeSpec, ) { @Suppress("SpreadOperator") - fun artifactCodeBlock( - artifact: Artifact, - ): CodeBlock { + fun artifactCodeBlock(artifact: Artifact): CodeBlock { val arguments = mutableListOf() val statement = buildString { @@ -25,7 +23,7 @@ class ArtifactCodeGenerator( |groupId = %S, |artifactId = %S, |version = %S, - """.trimMargin() + """.trimMargin(), ) arguments.add(artifact.groupId) arguments.add(artifact.artifactId) diff --git a/gross-plugin/src/main/kotlin/se/premex/gross/AssetCopyTask.kt b/licensee-for-android/src/main/kotlin/se/premex/gross/AssetCopyTask.kt similarity index 93% rename from gross-plugin/src/main/kotlin/se/premex/gross/AssetCopyTask.kt rename to licensee-for-android/src/main/kotlin/se/premex/gross/AssetCopyTask.kt index 343ee91..868eebc 100644 --- a/gross-plugin/src/main/kotlin/se/premex/gross/AssetCopyTask.kt +++ b/licensee-for-android/src/main/kotlin/se/premex/gross/AssetCopyTask.kt @@ -30,9 +30,9 @@ abstract class AssetCopyTask : DefaultTask() { inputFile.get().asFile.copyTo( target = File( outputDirectory.get().asFile, - targetFileName.get() + targetFileName.get(), ), - overwrite = true + overwrite = true, ) } } diff --git a/gross-plugin/src/main/kotlin/se/premex/gross/CodeGenerationTask.kt b/licensee-for-android/src/main/kotlin/se/premex/gross/CodeGenerationTask.kt similarity index 97% rename from gross-plugin/src/main/kotlin/se/premex/gross/CodeGenerationTask.kt rename to licensee-for-android/src/main/kotlin/se/premex/gross/CodeGenerationTask.kt index f7beeb4..43ee3ca 100644 --- a/gross-plugin/src/main/kotlin/se/premex/gross/CodeGenerationTask.kt +++ b/licensee-for-android/src/main/kotlin/se/premex/gross/CodeGenerationTask.kt @@ -48,7 +48,7 @@ abstract class CodeGenerationTask : DefaultTask() { packageName = packageName, spdxLicensesTypeSpec = licenseeTypesGenerator.spdxLicensesTypeSpec, scmTypeSpec = licenseeTypesGenerator.scmTypeSpec, - unknownLicensesTypeSpec = licenseeTypesGenerator.unknownLicensesTypeSpec + unknownLicensesTypeSpec = licenseeTypesGenerator.unknownLicensesTypeSpec, ) val artifactList = CodeBlock.builder().apply { @@ -63,7 +63,7 @@ abstract class CodeGenerationTask : DefaultTask() { val grossType = TypeSpec.objectBuilder("Gross") .addProperty( PropertySpec.builder("artifacts", licenseeTypesGenerator.artifactListType) - .initializer(artifactList).build() + .initializer(artifactList).build(), ) .build() diff --git a/gross-plugin/src/main/kotlin/se/premex/gross/GrossExtension.kt b/licensee-for-android/src/main/kotlin/se/premex/gross/GrossExtension.kt similarity index 100% rename from gross-plugin/src/main/kotlin/se/premex/gross/GrossExtension.kt rename to licensee-for-android/src/main/kotlin/se/premex/gross/GrossExtension.kt diff --git a/gross-plugin/src/main/kotlin/se/premex/gross/GrossPlugin.kt b/licensee-for-android/src/main/kotlin/se/premex/gross/GrossPlugin.kt similarity index 53% rename from gross-plugin/src/main/kotlin/se/premex/gross/GrossPlugin.kt rename to licensee-for-android/src/main/kotlin/se/premex/gross/GrossPlugin.kt index 045b5b1..652db51 100644 --- a/gross-plugin/src/main/kotlin/se/premex/gross/GrossPlugin.kt +++ b/licensee-for-android/src/main/kotlin/se/premex/gross/GrossPlugin.kt @@ -1,20 +1,12 @@ package se.premex.gross import com.android.build.api.variant.ApplicationAndroidComponentsExtension -import com.android.build.gradle.internal.tasks.factory.dependsOn import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.reporting.ReportingExtension -import org.gradle.kotlin.dsl.register import java.util.Locale -private enum class AndroidPlugin { - Application, - Library, - DynamicFeature, -} - -class GrossPlugin : Plugin { +public class GrossPlugin : Plugin { override fun apply(project: Project) { val extension = project.extensions.create("gross", GrossExtension::class.java) extension.enableKotlinCodeGeneration.convention(true) @@ -24,26 +16,19 @@ class GrossPlugin : Plugin { val reportingExtension: ReportingExtension = project.extensions.getByType(ReportingExtension::class.java) - val androidPlugin = if (project.plugins.hasPlugin("com.android.application")) { - AndroidPlugin.Application - } else if (project.plugins.hasPlugin("com.android.library")) { - AndroidPlugin.Library - } else if (project.plugins.hasPlugin("com.android.dynamic-feature")) { - AndroidPlugin.DynamicFeature - } else { - null - } - - if (androidPlugin != null) { - configureAndroidPlugin(project, extension, reportingExtension) - } + listOf( + "com.android.application", + "com.android.library", + "com.android.dynamic-feature", + ) + .forEach { pluginId -> + project.pluginManager.withPlugin(pluginId) { + configureAndroidPlugin(project, extension, reportingExtension) + } + } } - private fun configureAndroidPlugin( - project: Project, - extension: GrossExtension, - reportingExtension: ReportingExtension - ) { + private fun configureAndroidPlugin(project: Project, extension: GrossExtension, reportingExtension: ReportingExtension) { val androidComponentsExtension = project.extensions.getByName("androidComponents") as ApplicationAndroidComponentsExtension @@ -59,29 +44,29 @@ class GrossPlugin : Plugin { val artifactsFile = reportingExtension.file("licensee/${variant.name}/artifacts.json") if (extension.enableAndroidAssetGeneration.get()) { val copyArtifactsTask = - project.tasks.register("copy${capitalizedVariantName}LicenseeReportToAssets") { - inputFile.set(artifactsFile) - targetFileName.set(extension.androidAssetFileName.get()) + project.tasks.register("copy${capitalizedVariantName}LicenseeReportToAssets", AssetCopyTask::class.java) { + it.inputFile.set(artifactsFile) + it.targetFileName.set(extension.androidAssetFileName.get()) } variant.sources.assets!!.addGeneratedSourceDirectory( copyArtifactsTask, - AssetCopyTask::outputDirectory + AssetCopyTask::outputDirectory, ) - copyArtifactsTask.dependsOn("licensee$capitalizedVariantName") + copyArtifactsTask.configure { it.dependsOn("licensee$capitalizedVariantName") } } if (extension.enableKotlinCodeGeneration.get()) { val codeGenerationTask = - project.tasks.register("${capitalizedVariantName}LicenseeReportToKotlin") { - inputFile.set(artifactsFile) + project.tasks.register("${capitalizedVariantName}LicenseeReportToKotlin", CodeGenerationTask::class.java) { + it.inputFile.set(artifactsFile) } variant.sources.java!!.addGeneratedSourceDirectory( codeGenerationTask, - CodeGenerationTask::outputDirectory + CodeGenerationTask::outputDirectory, ) - codeGenerationTask.dependsOn("licensee$capitalizedVariantName") + codeGenerationTask.configure { it.dependsOn("licensee$capitalizedVariantName") } } } } diff --git a/gross-plugin/src/main/kotlin/se/premex/gross/LicenseeTypesGenerator.kt b/licensee-for-android/src/main/kotlin/se/premex/gross/LicenseeTypesGenerator.kt similarity index 89% rename from gross-plugin/src/main/kotlin/se/premex/gross/LicenseeTypesGenerator.kt rename to licensee-for-android/src/main/kotlin/se/premex/gross/LicenseeTypesGenerator.kt index 2391b76..74de23a 100644 --- a/gross-plugin/src/main/kotlin/se/premex/gross/LicenseeTypesGenerator.kt +++ b/licensee-for-android/src/main/kotlin/se/premex/gross/LicenseeTypesGenerator.kt @@ -19,21 +19,21 @@ class LicenseeTypesGenerator(private val packageName: String) { .addParameter("identifier", String::class) .addParameter("name", String::class) .addParameter("url", String::class) - .build() + .build(), ).addProperty( PropertySpec.builder("identifier", String::class) .initializer("identifier") - .build() + .build(), ) .addProperty( PropertySpec.builder("name", String::class) .initializer("name") - .build() + .build(), ) .addProperty( PropertySpec.builder("url", String::class) .initializer("url") - .build() + .build(), ) .build() @@ -42,11 +42,11 @@ class LicenseeTypesGenerator(private val packageName: String) { .primaryConstructor( FunSpec.constructorBuilder() .addParameter("url", String::class) - .build() + .build(), ).addProperty( PropertySpec.builder("url", String::class) .initializer("url") - .build() + .build(), ) .build() @@ -56,16 +56,16 @@ class LicenseeTypesGenerator(private val packageName: String) { FunSpec.constructorBuilder() .addParameter("name", String::class) .addParameter("url", String::class) - .build() + .build(), ).addProperty( PropertySpec.builder("name", String::class) .initializer("name") - .build() + .build(), ) .addProperty( PropertySpec.builder("url", String::class) .initializer("url") - .build() + .build(), ) .build() @@ -88,45 +88,45 @@ class LicenseeTypesGenerator(private val packageName: String) { .addParameter("spdxLicenses", spdxListType) .addParameter("scm", scmType) .addParameter("unknownLicenses", unknownLicensesType) - .build() + .build(), ).addProperty( PropertySpec.builder("groupId", String::class) .initializer("groupId") - .build() + .build(), ).addProperty( PropertySpec.builder("artifactId", String::class) .initializer("artifactId") - .build() + .build(), ).addProperty( PropertySpec.builder("version", String::class) .initializer("version") - .build() + .build(), ).addProperty( PropertySpec.builder( "name", - String::class.asTypeName().copy(nullable = true) + String::class.asTypeName().copy(nullable = true), ) .initializer("name") - .build() + .build(), ).addProperty( PropertySpec.builder("spdxLicenses", spdxListType) .initializer("spdxLicenses") - .build() + .build(), ).addProperty( PropertySpec.builder("scm", scmType.copy(nullable = true)) .initializer("scm") - .build() + .build(), ).addProperty( PropertySpec.builder("unknownLicenses", unknownLicensesType) .initializer("unknownLicenses") - .build() + .build(), ) .build() val artifactListType = LIST.parameterizedBy( ClassName( packageName, - artifactTypeSpec.name!! - ) + artifactTypeSpec.name!!, + ), ) } diff --git a/gross-plugin/src/main/kotlin/se/premex/gross/core/Artifact.kt b/licensee-for-android/src/main/kotlin/se/premex/gross/core/Artifact.kt similarity index 71% rename from gross-plugin/src/main/kotlin/se/premex/gross/core/Artifact.kt rename to licensee-for-android/src/main/kotlin/se/premex/gross/core/Artifact.kt index dca7d53..e88404c 100644 --- a/gross-plugin/src/main/kotlin/se/premex/gross/core/Artifact.kt +++ b/licensee-for-android/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/gross-plugin/src/main/kotlin/se/premex/gross/core/LicenseParser.kt b/licensee-for-android/src/main/kotlin/se/premex/gross/core/LicenseParser.kt similarity index 70% rename from gross-plugin/src/main/kotlin/se/premex/gross/core/LicenseParser.kt rename to licensee-for-android/src/main/kotlin/se/premex/gross/core/LicenseParser.kt index 7cdfa4f..817c3e7 100644 --- a/gross-plugin/src/main/kotlin/se/premex/gross/core/LicenseParser.kt +++ b/licensee-for-android/src/main/kotlin/se/premex/gross/core/LicenseParser.kt @@ -8,7 +8,5 @@ import okio.BufferedSource class LicenseParser { @ExperimentalSerializationApi - fun decode(source: BufferedSource): List { - return Json.decodeFromBufferedSource(source) - } + fun decode(source: BufferedSource): List = Json.decodeFromBufferedSource(source) } diff --git a/gross-plugin/src/test/kotlin/se/premex/gross/ArtifactGeneratorTest.kt b/licensee-for-android/src/test/kotlin/se/premex/gross/ArtifactGeneratorTest.kt similarity index 88% rename from gross-plugin/src/test/kotlin/se/premex/gross/ArtifactGeneratorTest.kt rename to licensee-for-android/src/test/kotlin/se/premex/gross/ArtifactGeneratorTest.kt index 8b3202e..7a5d81e 100644 --- a/gross-plugin/src/test/kotlin/se/premex/gross/ArtifactGeneratorTest.kt +++ b/licensee-for-android/src/test/kotlin/se/premex/gross/ArtifactGeneratorTest.kt @@ -1,11 +1,11 @@ package se.premex.gross +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import se.premex.gross.core.Artifact import se.premex.gross.core.Scm import se.premex.gross.core.SpdxLicenses import se.premex.gross.core.UnknownLicenses -import kotlin.test.assertEquals class ArtifactGeneratorTest { @@ -32,10 +32,10 @@ class ArtifactGeneratorTest { null, null, null, - null - ) + null, + ), ) - assertEquals( + assertThat(artifactCodeBlock).asString().isEqualTo( """Artifact( groupId = "testGroup", artifactId = "testArtifact", @@ -49,7 +49,6 @@ class ArtifactGeneratorTest { ) """, - artifactCodeBlock.toString() ) } @@ -63,10 +62,10 @@ class ArtifactGeneratorTest { "testName", listOf(), Scm("testUrl"), - listOf() - ) + listOf(), + ), ) - assertEquals( + assertThat(artifactCodeBlock).asString().isEqualTo( """Artifact( groupId = "testGroup", artifactId = "testArtifact", @@ -80,7 +79,6 @@ class ArtifactGeneratorTest { ) """, - artifactCodeBlock.toString() ) } @@ -99,11 +97,11 @@ class ArtifactGeneratorTest { Scm("testUrl"), listOf( UnknownLicenses("unknown1", "unknown1"), - UnknownLicenses("unknown2", "unknown2") - ) - ) + UnknownLicenses("unknown2", "unknown2"), + ), + ), ) - assertEquals( + assertThat(artifactCodeBlock).asString().isEqualTo( """Artifact( groupId = "testGroup", artifactId = "testArtifact", @@ -121,7 +119,6 @@ class ArtifactGeneratorTest { ) """, - artifactCodeBlock.toString() ) } } diff --git a/gross-plugin/src/test/kotlin/se/premex/gross/LicenseeTypesGeneratorTest.kt b/licensee-for-android/src/test/kotlin/se/premex/gross/LicenseeTypesGeneratorTest.kt similarity index 76% rename from gross-plugin/src/test/kotlin/se/premex/gross/LicenseeTypesGeneratorTest.kt rename to licensee-for-android/src/test/kotlin/se/premex/gross/LicenseeTypesGeneratorTest.kt index ab33a90..0d7d1db 100644 --- a/gross-plugin/src/test/kotlin/se/premex/gross/LicenseeTypesGeneratorTest.kt +++ b/licensee-for-android/src/test/kotlin/se/premex/gross/LicenseeTypesGeneratorTest.kt @@ -1,7 +1,7 @@ package se.premex.gross +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import kotlin.test.assertEquals class LicenseeTypesGeneratorTest { @@ -18,7 +18,7 @@ class LicenseeTypesGeneratorTest { ) """ - assertEquals(spdxDefinition, licenseeTypesGenerator.spdxLicensesTypeSpec.toString()) + assertThat(licenseeTypesGenerator.spdxLicensesTypeSpec.toString()).isEqualTo(spdxDefinition) } @Test @@ -30,7 +30,7 @@ class LicenseeTypesGeneratorTest { ) """ - assertEquals(spdxDefinition, licenseeTypesGenerator.scmTypeSpec.toString()) + assertThat(licenseeTypesGenerator.scmTypeSpec.toString()).isEqualTo(spdxDefinition) } @Test @@ -43,7 +43,7 @@ class LicenseeTypesGeneratorTest { ) """ - assertEquals(unknownLicensesDefinition, licenseeTypesGenerator.unknownLicensesTypeSpec.toString()) + assertThat(licenseeTypesGenerator.unknownLicensesTypeSpec.toString()).isEqualTo(unknownLicensesDefinition) } @Test @@ -60,6 +60,6 @@ class LicenseeTypesGeneratorTest { public val unknownLicenses: kotlin.collections.List, ) """ - assertEquals(artifactDefinition, licenseeTypesGenerator.artifactTypeSpec.toString()) + assertThat(licenseeTypesGenerator.artifactTypeSpec.toString()).isEqualTo(artifactDefinition) } } diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..c236600 --- /dev/null +++ b/renovate.json @@ -0,0 +1,9 @@ +{ + "includeForks": true, + "assignees": [ + "mateuszkwiecinski" + ], + "extends": [ + "config:base" + ] +} diff --git a/sample/app/.gitignore b/sample/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/sample/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/sample/app/build.gradle.kts b/sample/app/build.gradle.kts new file mode 100644 index 0000000..46e0eb8 --- /dev/null +++ b/sample/app/build.gradle.kts @@ -0,0 +1,93 @@ +plugins { + alias(libs.plugins.com.android.application) + alias(libs.plugins.org.jetbrains.kotlin.android) + alias(libs.plugins.app.cash.licensee) + id("se.premex.gross") +} + +licensee { + allow("Apache-2.0") +} + +gross { + enableKotlinCodeGeneration.set(true) + enableAndroidAssetGeneration.set(true) +} +android { + namespace = "se.premex.gross" + compileSdk = 33 + + defaultConfig { + applicationId = "se.premex.gross" + minSdk = 24 + targetSdk = 33 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary = true + } + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + buildFeatures { + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get() + } + packagingOptions { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + vendor.set(JvmVendorSpec.AZUL) + } +} + +dependencies { + + implementation(libs.core.ktx) + implementation(libs.lifecycle.runtime.ktx) + implementation(libs.activity.compose) + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.ui) + implementation(libs.ui.graphics) + implementation(libs.ui.tooling.preview) + implementation(libs.material3) + + // In theory we should be able to refer to "se.premex.gross:ui-oss" here and set a mapping up + // in the includeBuild like this + // dependencySubstitution { substitute(module("se.premex.gross:ui-oss")).using(project(":oss")) } + // Unfortunately this does not work - maybe same issue as https://youtrack.jetbrains.com/issue/KTIJ-13435 + implementation("se.premex.gross:ui:1.0") + + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.test.ext.junit) + androidTestImplementation(libs.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.ui.test.junit4) + debugImplementation(libs.ui.tooling) + debugImplementation(libs.ui.test.manifest) +} \ No newline at end of file diff --git a/sample/app/proguard-rules.pro b/sample/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/sample/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/sample/app/src/androidTest/java/se/premex/gross/ExampleInstrumentedTest.kt b/sample/app/src/androidTest/java/se/premex/gross/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..32c4448 --- /dev/null +++ b/sample/app/src/androidTest/java/se/premex/gross/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package se.premex.gross + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("se.premex.gross", appContext.packageName) + } +} \ No newline at end of file diff --git a/sample/app/src/main/AndroidManifest.xml b/sample/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..c2a6060 --- /dev/null +++ b/sample/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/app/src/main/java/se/premex/gross/MainActivity.kt b/sample/app/src/main/java/se/premex/gross/MainActivity.kt new file mode 100644 index 0000000..5e1f438 --- /dev/null +++ b/sample/app/src/main/java/se/premex/gross/MainActivity.kt @@ -0,0 +1,78 @@ +package se.premex.gross + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.AddCircle +import androidx.compose.material.icons.rounded.Create +import androidx.compose.material3.BottomAppBar +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import se.premex.gross.ui.theme.GrossTheme + +enum class Views { + Programmatic, AssetBased +} + +class MainActivity : ComponentActivity() { + @OptIn(ExperimentalMaterial3Api::class) + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + val selectedView = remember { mutableStateOf(Views.Programmatic) } + GrossTheme { + Scaffold( + bottomBar = { + BottomAppBar { + NavigationBarItem( + selected = false, + onClick = { + selectedView.value = Views.Programmatic + }, + icon = { + Icon( + imageVector = Icons.Rounded.Create, + contentDescription = stringResource(id = R.string.programmatic) + ) + }) + NavigationBarItem( + selected = false, + onClick = { + selectedView.value = Views.AssetBased + }, + icon = { + Icon( + imageVector = Icons.Rounded.AddCircle, + contentDescription = stringResource(id = R.string.assetBased) + ) + }) + } + } + ) { paddingValues -> + Surface( + modifier = Modifier + .fillMaxSize() + .padding(paddingValues), + color = MaterialTheme.colorScheme.background + ) { + when (selectedView.value) { + Views.Programmatic -> ProgrammaticOssView() + Views.AssetBased -> AssetsOssView() + } + } + } + } + } + } +} \ No newline at end of file diff --git a/sample/app/src/main/java/se/premex/gross/OssArtifactView.kt b/sample/app/src/main/java/se/premex/gross/OssArtifactView.kt new file mode 100644 index 0000000..b20f015 --- /dev/null +++ b/sample/app/src/main/java/se/premex/gross/OssArtifactView.kt @@ -0,0 +1,53 @@ +package se.premex.gross + +import androidx.compose.foundation.layout.Column +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import se.premex.gross.oss.R +import se.premex.gross.ui.AssetLicenseParser +import se.premex.gross.ui.ErrorView +import se.premex.gross.ui.LoadingView +import se.premex.gross.ui.OssView +import se.premex.gross.ui.OssViewState +import se.premex.gross.ui.State +import java.io.IOException + +@Composable +fun AssetsOssView() { + val assetManager = LocalContext.current.assets + + val licenseParser = remember { AssetLicenseParser(assetManager) } + + val uiState = remember { mutableStateOf(OssViewState()) } + + LaunchedEffect(key1 = assetManager) { + try { + uiState.value = + OssViewState(viewState = State.Success(data = licenseParser.readFromAssets())) + } catch (ioException: IOException) { + uiState.value = + OssViewState( + viewState = State.Failed( + errorMessage = ioException.localizedMessage ?: "" + ) + ) + } + } + + when (val state = uiState.value.viewState) { + is State.Failed -> ErrorView(stringResource(id = R.string.error), state.errorMessage) + is State.Loading -> LoadingView(stringResource(id = R.string.loading)) + is State.Success -> { + Column { + Text(text = stringResource(id = se.premex.gross.R.string.assetBased)) + + OssView(state.data) + } + } + } +} \ No newline at end of file diff --git a/sample/app/src/main/java/se/premex/gross/OssKotlinCodeView.kt b/sample/app/src/main/java/se/premex/gross/OssKotlinCodeView.kt new file mode 100644 index 0000000..d800ee4 --- /dev/null +++ b/sample/app/src/main/java/se/premex/gross/OssKotlinCodeView.kt @@ -0,0 +1,39 @@ +package se.premex.gross + +import androidx.compose.foundation.layout.Column +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import se.premex.gross.core.Artifact +import se.premex.gross.core.Scm +import se.premex.gross.core.SpdxLicenses +import se.premex.gross.core.UnknownLicenses +import se.premex.gross.ui.OssView + +@Composable +fun ProgrammaticOssView() { + Column { + Text(text = stringResource(id = R.string.programmatic)) + OssView(Gross.artifacts.map { artifact -> + Artifact( + name = artifact.name, + groupId = artifact.groupId, + artifactId = artifact.artifactId, + version = artifact.version, + scm = if (artifact.scm?.url != null) { + Scm(artifact.scm.url) + } else { + null + }, + spdxLicenses = artifact.spdxLicenses.map { + SpdxLicenses( + identifier = it.identifier, + name = it.name, + url = it.url + ) + }, unknownLicenses = artifact.unknownLicenses.map { + UnknownLicenses(name = it.name, url = it.url) + }) + }) + } +} \ No newline at end of file diff --git a/sample/app/src/main/java/se/premex/gross/ui/theme/Color.kt b/sample/app/src/main/java/se/premex/gross/ui/theme/Color.kt new file mode 100644 index 0000000..d1dda7a --- /dev/null +++ b/sample/app/src/main/java/se/premex/gross/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package se.premex.gross.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/sample/app/src/main/java/se/premex/gross/ui/theme/Theme.kt b/sample/app/src/main/java/se/premex/gross/ui/theme/Theme.kt new file mode 100644 index 0000000..9266d67 --- /dev/null +++ b/sample/app/src/main/java/se/premex/gross/ui/theme/Theme.kt @@ -0,0 +1,70 @@ +package se.premex.gross.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun GrossTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/sample/app/src/main/java/se/premex/gross/ui/theme/Type.kt b/sample/app/src/main/java/se/premex/gross/ui/theme/Type.kt new file mode 100644 index 0000000..c78bce2 --- /dev/null +++ b/sample/app/src/main/java/se/premex/gross/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package se.premex.gross.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/sample/app/src/main/res/drawable/ic_launcher_background.xml b/sample/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/sample/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sample/app/src/main/res/drawable/ic_launcher_foreground.xml b/sample/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/sample/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/sample/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/sample/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/sample/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sample/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/sample/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/sample/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sample/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/sample/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/sample/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/sample/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/sample/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/sample/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/sample/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/sample/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/sample/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/sample/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/sample/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/sample/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/sample/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/sample/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/sample/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/sample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/sample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/sample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/sample/app/src/main/res/values/colors.xml b/sample/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/sample/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/sample/app/src/main/res/values/strings.xml b/sample/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..ed25f78 --- /dev/null +++ b/sample/app/src/main/res/values/strings.xml @@ -0,0 +1,7 @@ + + Gross + Programmatic oss view + Asset baset oss view + Error + Loading + \ No newline at end of file diff --git a/sample/app/src/main/res/values/themes.xml b/sample/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..b8582c9 --- /dev/null +++ b/sample/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +