diff --git a/.github/templates.yaml b/.github/templates.yaml index dbbc438e..ae509bd8 100644 --- a/.github/templates.yaml +++ b/.github/templates.yaml @@ -1,15 +1,13 @@ version: v32.0.1 files: - - .github/.kodiak.toml - - .github/workflows/format-kotlin.yaml - - .github/workflows/release.yaml - - .github/workflows/verify-release.yaml - .autorc.json - - .github/workflows/pr-help.yaml - - .github/workflows/assign-random-codeowner.yaml + - .github/.kodiak.toml - .github/workflows/build-and-test.yaml - .github/workflows/codeql-analysis.yaml + - .github/workflows/pr-help.yaml + - .github/workflows/release.yaml + - .github/workflows/verify-release.yaml values: autoRelease: true diff --git a/.github/workflows/assign-random-codeowner.yaml b/.github/workflows/assign-random-codeowner.yaml deleted file mode 100644 index 67939add..00000000 --- a/.github/workflows/assign-random-codeowner.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# THIS CODE WAS AUTOGENERATED. DO NOT MODIFY THIS FILE DIRECTLY -# THE SOURCE CODE LIVES IN A DIFFERENT REPOSITORY: -# - centralized-templates -# FILE STEWARD: @pleo-io/devx,@pleo-bot-auto-approver - -name: Assign Random CODEOWNERS - -on: - pull_request: - types: - - review_requested - - ready_for_review - - opened - -concurrency: - group: ci-${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - assign-codeowners: - name: Assign CODEOWNERS - timeout-minutes: 5 - if: github.event.pull_request.draft == false - runs-on: ubuntu-latest - - steps: - # Checkout the repository in order to detect and parse CODEOWNERS - - name: Checkout code - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - - # Elevate token permissions to allow assigning people to PRs - - name: Allow assigning reviewers - id: get-assigning-token - uses: peter-murray/workflow-application-token-action@v2 - with: - application_id: ${{ secrets.PLEO_GH_APP_TOKEN_SIGNER_APP_ID }} - application_private_key: ${{ secrets.PLEO_GH_APP_TOKEN_SIGNER_PRIVATE_KEY }} - - # Assign random CODEOWNERS unless reviewers have been assigned manually - - name: Assign CODEOWNERS - uses: pleo-io/assign-random-codeowners@v0.3.27 - with: - reviewers-to-assign: 2 - assign-from-changed-files: true - assign-individuals-from-teams: true - env: - GITHUB_TOKEN: ${{ steps.get-assigning-token.outputs.token }} diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 9a682ced..c8f63b57 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -128,24 +128,6 @@ jobs: check_name: Unit Tests report report_paths: "**/build/test-results/test/TEST-*.xml" - # Run Detekt - - name: Run Detekt - continue-on-error: true - if: ${{ github.ref == 'refs/heads/main' }} - run: ./gradlew detekt --stacktrace - env: - GITHUB_TOKEN: ${{ secrets.GH_REGISTRY_GRADLE_TOKEN }} - GRADLE_READ_KEY: ${{ secrets.GH_REGISTRY_GRADLE_TOKEN }} - JOB_RUNR_REPO_PASSWORD: ${{ secrets.JOB_RUNR_REPO_PASSWORD }} - - # Publish Detekt results to GitHub. - - name: Publish Detekt SARIF report to GitHub - continue-on-error: true - if: ${{ github.ref == 'refs/heads/main' }} - uses: github/codeql-action/upload-sarif@v2 - with: - sarif_file: build/reports/detekt/detekt.sarif - - name: Trigger release if: ${{ github.ref == 'refs/heads/main' }} uses: peter-evans/repository-dispatch@v2 diff --git a/.github/workflows/format-kotlin.yaml b/.github/workflows/format-kotlin.yaml deleted file mode 100644 index d885451e..00000000 --- a/.github/workflows/format-kotlin.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# THIS CODE WAS AUTOGENERATED. DO NOT MODIFY THIS FILE DIRECTLY -# THE SOURCE CODE LIVES IN A DIFFERENT REPOSITORY: -# - centralized-templates -# FILE STEWARD: @pleo-io/devx,@pleo-bot-auto-approver - -name: Format Kotlin -on: - push: - branches-ignore: - - main - - master - - "depencencies/**" - pull_request: - branches: - - main - - master - -concurrency: - group: ci-${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - format: - name: Format Kotlin - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - # Generate temporary token for allowing CI to run on the formatted files. - - name: Generate temporary CI token - id: get-admin-token - uses: peter-murray/workflow-application-token-action@v2 - with: - application_id: ${{ secrets.PLEO_GH_APP_TOKEN_SIGNER_APP_ID }} - application_private_key: ${{ secrets.PLEO_GH_APP_TOKEN_SIGNER_PRIVATE_KEY }} - - # Checkout code with push privileges. - - name: Checkout code - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - token: ${{ steps.get-admin-token.outputs.token }} - - # Set up a JDK environment for building, testing and releasing. - - name: Set up JDK 17 - uses: actions/setup-java@v3.13.0 - with: - java-version: 17 - distribution: temurin - - # Allow caching Gradle executions to further speed up CI/CD steps invoking Gradle. - - name: Setup Gradle - uses: gradle/gradle-build-action@v2.10.0 - with: - gradle-executable: ./gradlew - gradle-version: wrapper - cache-read-only: true - - # Format code via the formatkotlin Gradle task. - - name: Format files - run: | - ./gradlew formatkotlin - env: - GRADLE_READ_KEY: ${{ secrets.GH_REGISTRY_GRADLE_TOKEN }} - JOB_RUNR_REPO_PASSWORD: ${{ secrets.JOB_RUNR_REPO_PASSWORD }} - - # Add and commit any formatted files. - - name: Add formatted files - uses: EndBug/add-and-commit@v9.1.3 - with: - author_name: github-actions[bot] - author_email: github-actions@pleo.io - message: Format Kotlin - commit: --no-verify diff --git a/build.gradle b/build.gradle index d29b6cc0..a9a0c517 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { repositories { @@ -22,6 +23,7 @@ plugins { id 'jacoco' alias(libs.plugins.coveralls.jacoco) apply false alias(libs.plugins.jacocolog) apply false + alias(libs.plugins.jmailen.kotlinter) apply false } allprojects { @@ -29,6 +31,7 @@ allprojects { apply plugin: libs.plugins.coveralls.jacoco.get().pluginId apply plugin: libs.plugins.jacocolog.get().pluginId + apply plugin: libs.plugins.jmailen.kotlinter.get().pluginId jacoco { toolVersion = "0.8.7" @@ -52,11 +55,11 @@ subprojects { sourceCompatibility = 17 targetCompatibility = 17 - tasks.withType(JavaCompile) { + tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } - tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { + tasks.withType(KotlinCompile).configureEach { kotlinOptions { jvmTarget = "17" javaParameters = true @@ -77,14 +80,18 @@ subprojects { testRuntimeOnly(libs.junit.jupiter.engine) } - task sourcesJar(type: Jar) { + tasks.register('sourcesJar', Jar) { from sourceSets.main.allJava - classifier = 'sources' + archiveClassifier = 'sources' } - task javadocJar(type: Jar) { + tasks.register('javadocJar', Jar) { from javadoc - classifier = 'javadoc' + archiveClassifier = 'javadoc' + } + + tasks.named('check') { + finalizedBy 'formatKotlin' } javadoc { @@ -184,3 +191,7 @@ coverallsJacoco { tasks.named('coverallsJacoco') { dependsOn jacocoAggregatedReport } + +//tasks.named('check') { +// dependsOn 'installKotlinterPrePushHook' +//} diff --git a/gradle.properties b/gradle.properties index 61101f3a..05593a83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,6 @@ -#Thu Feb 02 09:01:06 UTC 2023 +#Some properties were automatically set by the Pleo Gradle plugin. +#Thu Dec 21 10:26:54 EET 2023 +org.gradle.configuration-cache=true +org.gradle.configuration-cache.problems=warn +org.gradle.jvmargs=-Xmx4096m "-XX\:MaxMetaspaceSize\=1024m" version=6.0.28 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c2837558..56954788 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,7 +8,7 @@ jacksonVersion = "2.14.2" junitVersion = "5.9.3" kotlinGuiceVersion = "1.6.0" kotlinVersion = "1.8.0" -kotlinterGradleVersion = "3.13.0" +kotlinterGradleVersion = "3.16.0" logbackClassicVersion = "1.4.5" mockkVersion = "1.13.4" monetaVersion = "1.4.2" @@ -36,10 +36,9 @@ slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4jVersion" } [plugins] java-library = { id = "java-library" } -jmailen-kotlinter = { id = "org.jmailen.kotlinter" } +jmailen-kotlinter = { id = "org.jmailen.kotlinter", version.ref = "kotlinterGradleVersion" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlinVersion" } kotlin-library = { id = "kotlin" } maven-publish = { id = "maven-publish" } coveralls-jacoco = { id = "com.github.nbaztec.coveralls-jacoco", version = "1.2.15" } jacocolog = { id = "org.barfuin.gradle.jacocolog", version = "3.0.0" } - diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e5832..7f93135c 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 ae04661e..878fe049 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index a69d9cb6..1aa94a42 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# 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/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${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"' +# 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 @@ -133,22 +131,29 @@ 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. + 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 @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# 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" \ diff --git a/gradlew.bat b/gradlew.bat index 53a6b238..6689b85b 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -26,6 +26,7 @@ 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% diff --git a/prop-all/src/test/kotlin/io/pleo/prop/PropTest.kt b/prop-all/src/test/kotlin/io/pleo/prop/PropTest.kt index e18a0845..9dfd0e3b 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/PropTest.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/PropTest.kt @@ -40,19 +40,21 @@ import javax.sql.DataSource class PropTest { @Test fun `can read complex properties`() { - val injector = createInjector( - Module { binder: Binder -> - binder.bind(ComplexObjects::class.java) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind(ComplexObjects::class.java) + }, + ) - val mappedEnumExpected = mapOf( - ComplexObjects.ParsingStage.PENDING_HUMAN_REVIEW to "This is pending human review", - ComplexObjects.ParsingStage.UNDER_HUMAN_REVIEW to "This is under human review", - ComplexObjects.ParsingStage.OUTPUT to "This is output", - ComplexObjects.ParsingStage.FINISHED to "This is finished", - ComplexObjects.ParsingStage.ERROR to "This is error" - ) + val mappedEnumExpected = + mapOf( + ComplexObjects.ParsingStage.PENDING_HUMAN_REVIEW to "This is pending human review", + ComplexObjects.ParsingStage.UNDER_HUMAN_REVIEW to "This is under human review", + ComplexObjects.ParsingStage.OUTPUT to "This is output", + ComplexObjects.ParsingStage.FINISHED to "This is finished", + ComplexObjects.ParsingStage.ERROR to "This is error", + ) val complexObjects = injector.getInstance(ComplexObjects::class.java) val complexObjectPropValue = complexObjects.myComplexObjectProp() @@ -75,11 +77,12 @@ class PropTest { @Test fun `can read CurrencyUnit`() { - val injector = createInjector( - Module { binder: Binder -> - binder.bind(CurrencyUnitProp::class.java) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind(CurrencyUnitProp::class.java) + }, + ) val currency: CurrencyUnitProp = injector.getInstance(CurrencyUnitProp::class.java) @@ -89,12 +92,13 @@ class PropTest { @Test fun `can bind non prop objects`() { val dataSource = mockk() - val injector = createInjector( - Module { binder: Binder -> - binder.bind(DataSource::class.java).toInstance(dataSource) - binder.bind(NoPropObject::class.java) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind(DataSource::class.java).toInstance(dataSource) + binder.bind(NoPropObject::class.java) + }, + ) val actual = injector.getInstance(NoPropObject::class.java) @@ -104,13 +108,14 @@ class PropTest { @Test fun `throws on null values`() { assertThrows { - val injector = createInjector( - Module { binder: Binder -> - binder.bind( - NullValue::class.java - ) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind( + NullValue::class.java, + ) + }, + ) injector.getInstance(NullValue::class.java) } @@ -118,13 +123,14 @@ class PropTest { @Test fun `uses default value on missing value`() { - val injector = createInjector( - Module { binder: Binder -> - binder.bind( - DefaultValue::class.java - ) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind( + DefaultValue::class.java, + ) + }, + ) val defaultValue = injector.getInstance(DefaultValue::class.java) @@ -134,11 +140,12 @@ class PropTest { @Test fun `throws on unnamed prop`() { assertThrows { - val injector = createInjector( - Module { binder: Binder -> - binder.bind(UnnamedProp::class.java) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind(UnnamedProp::class.java) + }, + ) injector.getInstance(UnnamedProp::class.java) } @@ -147,11 +154,12 @@ class PropTest { @Test fun `throws on invalid default value`() { assertThrows { - val injector = createInjector( - Module { binder: Binder -> - binder.bind(InvalidDefaultValue::class.java) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind(InvalidDefaultValue::class.java) + }, + ) injector.getInstance(InvalidDefaultValue::class.java) } @@ -160,11 +168,12 @@ class PropTest { @Test fun `throws on invalid default value even if there is a valid value in config`() { assertThrows { - val injector = createInjector( - Module { binder: Binder -> - binder.bind(InvalidDefaultValueButValidValue::class.java) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind(InvalidDefaultValueButValidValue::class.java) + }, + ) injector.getInstance(InvalidDefaultValueButValidValue::class.java) } @@ -172,12 +181,13 @@ class PropTest { @Test fun `can have multiple objects using the same prop`() { - val injector = createInjector( - Module { binder: Binder -> - binder.bind(ComplexObjects::class.java) - binder.bind(SamePropertyAsComplexObjects::class.java) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind(ComplexObjects::class.java) + binder.bind(SamePropertyAsComplexObjects::class.java) + }, + ) val complexObjects = injector.getInstance(ComplexObjects::class.java) val samePropertyAsComplexObjects = injector.getInstance(SamePropertyAsComplexObjects::class.java) @@ -188,13 +198,14 @@ class PropTest { @Test fun `can use twice same prop in same object`() { - val injector = createInjector( - Module { binder: Binder -> - binder.bind( - UsesTwiceSameProp::class.java - ) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind( + UsesTwiceSameProp::class.java, + ) + }, + ) val samePropTwice = injector.getInstance(UsesTwiceSameProp::class.java) @@ -203,13 +214,14 @@ class PropTest { @Test fun `can use both named annotations`() { - val injector = createInjector( - Module { binder: Binder -> - binder.bind( - BothNamedAnnotations::class.java - ) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind( + BothNamedAnnotations::class.java, + ) + }, + ) val bothNamedAnnotations = injector.getInstance(BothNamedAnnotations::class.java) @@ -220,11 +232,12 @@ class PropTest { @Test fun `throws if deserialization fails`() { assertThrows { - val injector = createInjector( - Module { binder: Binder -> - binder.bind(InvalidJSON::class.java) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind(InvalidJSON::class.java) + }, + ) injector.getInstance(InvalidJSON::class.java) } @@ -242,11 +255,12 @@ class PropTest { @Test fun `module with provider`() { - val injector = createInjector( - Module { binder: Binder -> - binder.bind(MyInterface::class.java).toProvider(MyInterfaceProvider::class.java) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.bind(MyInterface::class.java).toProvider(MyInterfaceProvider::class.java) + }, + ) val myInterface = injector.getInstance(MyInterface::class.java) @@ -259,19 +273,22 @@ class PropTest { createInjector( Module { binder: Binder -> binder.bind(EmptyNamedAnnotation::class.java) - } + }, ) } } @Test fun `private module support`() { - val injector = createInjector(object : PrivateModule() { - override fun configure() { - bind(ComplexObjects::class.java) - expose(ComplexObjects::class.java) - } - }) + val injector = + createInjector( + object : PrivateModule() { + override fun configure() { + bind(ComplexObjects::class.java) + expose(ComplexObjects::class.java) + } + }, + ) injector.getInstance(ComplexObjects::class.java) } @@ -283,42 +300,46 @@ class PropTest { @Test fun `assisted inject support`() { - val injector = createInjector( - Module { binder: Binder -> - binder.install( - FactoryModuleBuilder().build( - MyAssistedInjectFactoryModule::class.java + val injector = + createInjector( + Module { binder: Binder -> + binder.install( + FactoryModuleBuilder().build( + MyAssistedInjectFactoryModule::class.java, + ), ) - ) - } - ) + }, + ) injector.getInstance(MyAssistedInjectFactoryModule::class.java) } @Test fun `assisted inject support multiple factory functions`() { - val injector = createInjector( - Module { binder: Binder -> - binder.install(FactoryModuleBuilder().build(MyAssistedInjectFactoryModuleMultiple::class.java)) - } - ) + val injector = + createInjector( + Module { binder: Binder -> + binder.install(FactoryModuleBuilder().build(MyAssistedInjectFactoryModuleMultiple::class.java)) + }, + ) injector.getInstance(MyAssistedInjectFactoryModuleMultiple::class.java) } private fun createInjector(vararg modules: Module): Injector { - val autoPropModule = AutoPropModule( - "io.pleo", - modules.toList(), - CommonsConfigPropFactory(), - JacksonParserFactory() - ) - - val allModules: List = buildList { - add(autoPropModule) - addAll(modules) - } + val autoPropModule = + AutoPropModule( + "io.pleo", + modules.toList(), + CommonsConfigPropFactory(), + JacksonParserFactory(), + ) + + val allModules: List = + buildList { + add(autoPropModule) + addAll(modules) + } return try { Guice.createInjector(allModules) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/BothNamedAnnotations.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/BothNamedAnnotations.kt index 04bbe1a5..a7b73662 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/BothNamedAnnotations.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/BothNamedAnnotations.kt @@ -5,7 +5,9 @@ import javax.inject.Inject import com.google.inject.name.Named as GoogleNamed import javax.inject.Named as JavaxNamed -class BothNamedAnnotations @Inject constructor( +class BothNamedAnnotations +@Inject +constructor( @JavaxNamed("io.pleo.test.prop3") val stringProp1: Prop, - @GoogleNamed("io.pleo.test.prop4") val stringProp2: Prop + @GoogleNamed("io.pleo.test.prop4") val stringProp2: Prop, ) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/ComplexObjects.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/ComplexObjects.kt index c776555c..648e613a 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/ComplexObjects.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/ComplexObjects.kt @@ -5,12 +5,14 @@ import javax.inject.Inject import javax.inject.Named @Suppress("unused") -class ComplexObjects @Inject constructor( +class ComplexObjects +@Inject +constructor( @Named("io.pleo.test.prop1") val myComplexObjectProp: Prop, @Named("io.pleo.test.prop1") val withConstructor: Prop, @Named("io.pleo.test.prop2") val myListOfComplexObjectProp: Prop>, @Named("io.pleo.test.prop3") val myStringProp: Prop, - @Named("io.pleo.test.prop7") val myMappedEnumProp: Prop> + @Named("io.pleo.test.prop7") val myMappedEnumProp: Prop>, ) { enum class ParsingStage { UPLOADED, @@ -19,6 +21,6 @@ class ComplexObjects @Inject constructor( UNDER_HUMAN_REVIEW, OUTPUT, FINISHED, - ERROR + ERROR, } } diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/CurrencyUnitProp.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/CurrencyUnitProp.kt index 45223eef..f86e0365 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/CurrencyUnitProp.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/CurrencyUnitProp.kt @@ -5,5 +5,8 @@ import javax.inject.Inject import javax.inject.Named import javax.money.CurrencyUnit -@Suppress("unused_parameter") -class CurrencyUnitProp @Inject constructor(@Named("io.pleo.test.prop8") val currency: Prop) +class CurrencyUnitProp +@Inject +constructor( + @Named("io.pleo.test.prop8") val currency: Prop, +) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/DefaultValue.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/DefaultValue.kt index c335e388..ce1ab4de 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/DefaultValue.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/DefaultValue.kt @@ -5,10 +5,12 @@ import io.pleo.prop.core.Prop import javax.inject.Inject import javax.inject.Named -class DefaultValue @Inject constructor( +class DefaultValue +@Inject +constructor( @Default(DEFAULT_VALUE) @Named("io.pleo.undefined.property") - val usesDefaultValue: Prop + val usesDefaultValue: Prop, ) { companion object { const val DEFAULT_VALUE = "This is the default value!" diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/EmptyNamedAnnotation.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/EmptyNamedAnnotation.kt index f3fbc7fe..12814f26 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/EmptyNamedAnnotation.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/EmptyNamedAnnotation.kt @@ -5,4 +5,8 @@ import javax.inject.Inject import javax.inject.Named @Suppress("UNUSED_PARAMETER") -class EmptyNamedAnnotation @Inject constructor(@Named myProp: Prop) +class EmptyNamedAnnotation +@Inject +constructor( + @Named myProp: Prop, +) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/InjectedObjectWithConstructor.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/InjectedObjectWithConstructor.kt index 5c641e26..061ba749 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/InjectedObjectWithConstructor.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/InjectedObjectWithConstructor.kt @@ -4,9 +4,11 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty @Suppress("unused", "unused_parameter") -class InjectedObjectWithConstructor @JsonCreator constructor( +class InjectedObjectWithConstructor +@JsonCreator +constructor( @JsonProperty("name") var name: String, - @JsonProperty("age") age: Int + @JsonProperty("age") age: Int, ) { var age = 0 } diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/InlineProviderModule.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/InlineProviderModule.kt index 796f61a8..9bc53e02 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/InlineProviderModule.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/InlineProviderModule.kt @@ -11,7 +11,9 @@ import javax.inject.Named class InlineProviderModule : AbstractModule() { @Provides @Singleton - fun hardwell(@Named("io.pleo.test.prop3") w_w: Prop): InjectedObject { + fun hardwell( + @Named("io.pleo.test.prop3") w_w: Prop, + ): InjectedObject { return InjectedObject() } @@ -21,7 +23,7 @@ class InlineProviderModule : AbstractModule() { fun tiesto( io: InjectedObject?, @Named("io.pleo.test.prop4") w_w: Prop, - @Named("io.pleo.test.prop3") u_u: Prop + @Named("io.pleo.test.prop3") u_u: Prop, ): InjectedObject { return InjectedObject() } diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidDefaultValue.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidDefaultValue.kt index bf799333..b1c1073f 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidDefaultValue.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidDefaultValue.kt @@ -6,10 +6,12 @@ import javax.inject.Inject import javax.inject.Named @Suppress("unused") -class InvalidDefaultValue @Inject constructor( +class InvalidDefaultValue +@Inject +constructor( @Default(DEFAULT_VALUE) @Named("io.pleo.undefined.property") - val usesDefaultValue: Prop + val usesDefaultValue: Prop, ) { companion object { const val DEFAULT_VALUE = "This is not a double!" diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidDefaultValueButValidValue.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidDefaultValueButValidValue.kt index 69877681..ffc39c62 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidDefaultValueButValidValue.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidDefaultValueButValidValue.kt @@ -6,12 +6,13 @@ import javax.inject.Inject import javax.inject.Named @Suppress("unused") -class InvalidDefaultValueButValidValue @Inject constructor( +class InvalidDefaultValueButValidValue +@Inject +constructor( @Default(DEFAULT_VALUE) @Named("io.pleo.test.prop6") - val usesDefaultValue: Prop + val usesDefaultValue: Prop, ) { - companion object { const val DEFAULT_VALUE = "This is not a double!" } diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidJSON.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidJSON.kt index 1989db92..bab11fef 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidJSON.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/InvalidJSON.kt @@ -5,4 +5,8 @@ import javax.inject.Inject import javax.inject.Named @Suppress("UNUSED_PARAMETER") -class InvalidJSON @Inject constructor(@Named("io.pleo.prop5") objectProp: Prop) +class InvalidJSON +@Inject +constructor( + @Named("io.pleo.prop5") objectProp: Prop, +) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryImp.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryImp.kt index 662232ef..7a64199b 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryImp.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryImp.kt @@ -6,7 +6,9 @@ import io.pleo.prop.core.Prop import javax.inject.Named @Suppress("unused") -class MyAssistedInjectFactoryImp @Inject constructor( +class MyAssistedInjectFactoryImp +@Inject +constructor( @Named("io.pleo.test.prop3") private val prop: Prop, - @Assisted private val assistedArg: String + @Assisted private val assistedArg: String, ) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryImp2.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryImp2.kt index d614e308..02738e7a 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryImp2.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryImp2.kt @@ -6,7 +6,9 @@ import io.pleo.prop.core.Prop import javax.inject.Named @Suppress("unused") -class MyAssistedInjectFactoryImp2 @Inject constructor( +class MyAssistedInjectFactoryImp2 +@Inject +constructor( @Named("io.pleo.test.prop4") private val prop: Prop, - @Assisted private val assistedArg: Int + @Assisted private val assistedArg: Int, ) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryModuleMultiple.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryModuleMultiple.kt index 07ae0ae3..ae676e96 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryModuleMultiple.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/MyAssistedInjectFactoryModuleMultiple.kt @@ -3,5 +3,6 @@ package io.pleo.prop.objects @Suppress("unused") interface MyAssistedInjectFactoryModuleMultiple { fun create(assistedArg: String): MyAssistedInjectFactoryImp + fun create(assistedArg: Int): MyAssistedInjectFactoryImp2 } diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/MyInterfaceProvider.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/MyInterfaceProvider.kt index 31ec5812..7f55267b 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/MyInterfaceProvider.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/MyInterfaceProvider.kt @@ -5,8 +5,10 @@ import javax.inject.Inject import javax.inject.Named import javax.inject.Provider -class MyInterfaceProvider @Inject constructor( - @Named("io.pleo.test.prop3") val prop: Prop +class MyInterfaceProvider +@Inject +constructor( + @Named("io.pleo.test.prop3") val prop: Prop, ) : Provider { override fun get(): MyInterface = object : MyInterface { diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/NoPropObject.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/NoPropObject.kt index c0bd0db6..1cec31c5 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/NoPropObject.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/NoPropObject.kt @@ -3,4 +3,6 @@ package io.pleo.prop.objects import javax.inject.Inject import javax.sql.DataSource -class NoPropObject @Inject constructor(val dataSource: DataSource) +class NoPropObject +@Inject +constructor(val dataSource: DataSource) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/NullValue.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/NullValue.kt index 75833b67..5f98d37e 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/NullValue.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/NullValue.kt @@ -4,5 +4,9 @@ import io.pleo.prop.core.Prop import javax.inject.Inject import javax.inject.Named -@Suppress("unused_parameter") -class NullValue @Inject constructor(@Named("io.pleo.undefined.property") thisThrows: Prop) +@Suppress("unused") +class NullValue +@Inject +constructor( + @Named("io.pleo.undefined.property") thisThrows: Prop, +) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/SamePropertyAsComplexObjects.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/SamePropertyAsComplexObjects.kt index 5950674e..a1de7ce3 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/SamePropertyAsComplexObjects.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/SamePropertyAsComplexObjects.kt @@ -4,6 +4,8 @@ import io.pleo.prop.core.Prop import javax.inject.Inject import javax.inject.Named -class SamePropertyAsComplexObjects @Inject constructor( - @Named("io.pleo.test.prop1") val myComplexObjectProp: Prop +class SamePropertyAsComplexObjects +@Inject +constructor( + @Named("io.pleo.test.prop1") val myComplexObjectProp: Prop, ) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/UnnamedProp.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/UnnamedProp.kt index 8d619ed0..a23a7bc2 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/UnnamedProp.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/UnnamedProp.kt @@ -3,5 +3,7 @@ package io.pleo.prop.objects import io.pleo.prop.core.Prop import javax.inject.Inject -@Suppress("unused_parameter") -class UnnamedProp @Inject constructor(unnamedProp: Prop) +@Suppress("unused") +class UnnamedProp +@Inject +constructor(unnamedProp: Prop) diff --git a/prop-all/src/test/kotlin/io/pleo/prop/objects/UsesTwiceSameProp.kt b/prop-all/src/test/kotlin/io/pleo/prop/objects/UsesTwiceSameProp.kt index 062193a7..b80b3a7b 100644 --- a/prop-all/src/test/kotlin/io/pleo/prop/objects/UsesTwiceSameProp.kt +++ b/prop-all/src/test/kotlin/io/pleo/prop/objects/UsesTwiceSameProp.kt @@ -4,7 +4,9 @@ import io.pleo.prop.core.Prop import javax.inject.Inject import javax.inject.Named -class UsesTwiceSameProp @Inject constructor( +class UsesTwiceSameProp +@Inject +constructor( @Named("io.pleo.test.prop3") val stringProp1: Prop, - @Named("io.pleo.test.prop3") val stringProp2: Prop + @Named("io.pleo.test.prop3") val stringProp2: Prop, ) diff --git a/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/CommonsConfigProp.kt b/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/CommonsConfigProp.kt index 8e79371e..011be52e 100644 --- a/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/CommonsConfigProp.kt +++ b/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/CommonsConfigProp.kt @@ -5,16 +5,19 @@ import io.pleo.prop.core.Prop import java.time.Instant class CommonsConfigProp( - private val parsingProperty: ParsingProperty + private val parsingProperty: ParsingProperty, ) : Prop { override val name: String get() = parsingProperty.name override fun get(): T = parsingProperty.getValue() + override val changedTimestamp: Instant get() = parsingProperty.changedTimestamp override fun addCallback(callback: Callback) = parsingProperty.addCallback(callback) + override fun removeAllCallbacks() = parsingProperty.removeAllCallbacks() + override fun toString(): String = "$name=${get()}" } diff --git a/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/CommonsConfigPropFactory.kt b/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/CommonsConfigPropFactory.kt index 957c93a9..599fd8d7 100644 --- a/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/CommonsConfigPropFactory.kt +++ b/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/CommonsConfigPropFactory.kt @@ -8,23 +8,22 @@ import org.apache.commons.configuration2.builder.fluent.Configurations import java.io.File class CommonsConfigPropFactory( - private val builder: ConfigurationBuilder<*>? = null + private val builder: ConfigurationBuilder<*>? = null, ) : PropFactory { override fun createProp( propName: String, parse: Parser, - defaultValue: T? + defaultValue: T?, ): Prop = CommonsConfigProp( ParsingProperty( builder = builder ?: createDefaultBuilder(), name = propName, parser = parse, - defaultValue = defaultValue - ) + defaultValue = defaultValue, + ), ) @Suppress("MemberVisibilityCanBePrivate") - fun createDefaultBuilder(): ConfigurationBuilder<*> = - Configurations().propertiesBuilder(File("config.properties")) + fun createDefaultBuilder(): ConfigurationBuilder<*> = Configurations().propertiesBuilder(File("config.properties")) } diff --git a/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/ParsingProperty.kt b/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/ParsingProperty.kt index fc5f97d4..c73ec291 100644 --- a/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/ParsingProperty.kt +++ b/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/ParsingProperty.kt @@ -14,7 +14,7 @@ class ParsingProperty( private val builder: ConfigurationBuilder<*>, val name: String, private val parser: Parser, - private val defaultValue: T? + private val defaultValue: T?, ) { @Volatile private var value: T = parseProperty() @@ -64,7 +64,7 @@ class ParsingProperty( logger.warn( "Failed to parse property '{}'. Keeping last valid value.", name, - ex + ex, ) } } diff --git a/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/utils/CompositeConfigurationBuilder.kt b/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/utils/CompositeConfigurationBuilder.kt index 9b827397..e2ae1fec 100644 --- a/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/utils/CompositeConfigurationBuilder.kt +++ b/prop-commons-config/src/main/kotlin/io/pleo/prop/commonsconfig/utils/CompositeConfigurationBuilder.kt @@ -15,10 +15,12 @@ import org.apache.commons.configuration2.event.EventType class CompositeConfigurationBuilder : ConfigurationBuilder { sealed interface BuilderOrConfiguration { fun isEqual(item: ConfigurationBuilder<*>) = this is BuilderWrapper && builder === item + fun isEqual(item: Configuration) = this is ConfigurationWrapper && configuration === item } private class BuilderWrapper(val builder: ConfigurationBuilder<*>) : BuilderOrConfiguration + private class ConfigurationWrapper(val configuration: Configuration) : BuilderOrConfiguration private lateinit var result: CompositeConfiguration @@ -27,19 +29,16 @@ class CompositeConfigurationBuilder : ConfigurationBuilder.wrap() = BuilderWrapper(this) + private fun Configuration.wrap() = ConfigurationWrapper(this) - private operator fun MutableList.contains(item: ConfigurationBuilder<*>) = - any { it.isEqual(item) } + private operator fun MutableList.contains(item: ConfigurationBuilder<*>) = any { it.isEqual(item) } - private operator fun MutableList.contains(item: Configuration) = - any { it.isEqual(item) } + private operator fun MutableList.contains(item: Configuration) = any { it.isEqual(item) } - private fun MutableList.remove(item: ConfigurationBuilder<*>) = - removeIf { it.isEqual(item) } + private fun MutableList.remove(item: ConfigurationBuilder<*>) = removeIf { it.isEqual(item) } - private fun MutableList.remove(item: Configuration) = - removeIf { it.isEqual(item) } + private fun MutableList.remove(item: Configuration) = removeIf { it.isEqual(item) } fun add(item: ConfigurationBuilder<*>): Boolean = synchronized(items) { @@ -60,16 +59,23 @@ class CompositeConfigurationBuilder : ConfigurationBuilder): Boolean = synchronized(items) { items.remove(item) } + fun remove(item: Configuration): Boolean = synchronized(items) { items.remove(item) } - override fun addEventListener(eventType: EventType, listener: EventListener) { + override fun addEventListener( + eventType: EventType, + listener: EventListener, + ) { eventListeners.addEventListener(eventType, listener) if (isResultInitialised) { result.addEventListener(eventType, listener) } } - override fun removeEventListener(eventType: EventType?, listener: EventListener?): Boolean { + override fun removeEventListener( + eventType: EventType?, + listener: EventListener?, + ): Boolean { if (isResultInitialised) { result.removeEventListener(eventType, listener) } @@ -102,15 +108,15 @@ class CompositeConfigurationBuilder : ConfigurationBuilder registerListener( eventSource: EventSource, - registrationData: EventListenerRegistrationData + registrationData: EventListenerRegistrationData, ) { eventSource.addEventListener(registrationData.eventType, registrationData.listener) } diff --git a/prop-commons-config/src/test/kotlin/io/pleo/prop/commonsconfig/ParsingPropertyTest.kt b/prop-commons-config/src/test/kotlin/io/pleo/prop/commonsconfig/ParsingPropertyTest.kt index d399a449..ecdc088f 100644 --- a/prop-commons-config/src/test/kotlin/io/pleo/prop/commonsconfig/ParsingPropertyTest.kt +++ b/prop-commons-config/src/test/kotlin/io/pleo/prop/commonsconfig/ParsingPropertyTest.kt @@ -32,10 +32,12 @@ class ParsingPropertyTest { fun `can change value`() { propertyValue = "value1" - val reloadingDetector = object : ReloadingDetector { - override fun isReloadingRequired(): Boolean = true - override fun reloadingPerformed() {} - } + val reloadingDetector = + object : ReloadingDetector { + override fun isReloadingRequired(): Boolean = true + + override fun reloadingPerformed() = Unit + } val reloadingController = ReloadingController(reloadingDetector) val builder = BasicConfigurationBuilder(TestConfiguration::class.java, emptyMap(), false) diff --git a/prop-core/src/main/kotlin/io/pleo/prop/core/Default.kt b/prop-core/src/main/kotlin/io/pleo/prop/core/Default.kt index debfed20..70260011 100644 --- a/prop-core/src/main/kotlin/io/pleo/prop/core/Default.kt +++ b/prop-core/src/main/kotlin/io/pleo/prop/core/Default.kt @@ -4,5 +4,5 @@ package io.pleo.prop.core @Target(AnnotationTarget.VALUE_PARAMETER) annotation class Default( /** The default value */ - val value: String = "" + val value: String = "", ) diff --git a/prop-core/src/main/kotlin/io/pleo/prop/core/Prop.kt b/prop-core/src/main/kotlin/io/pleo/prop/core/Prop.kt index 1c098e17..ff39236e 100644 --- a/prop-core/src/main/kotlin/io/pleo/prop/core/Prop.kt +++ b/prop-core/src/main/kotlin/io/pleo/prop/core/Prop.kt @@ -14,6 +14,7 @@ interface Prop { val name: String operator fun invoke(): T = get() + fun get(): T /** Gets the time when the property was last set/changed. */ diff --git a/prop-core/src/main/kotlin/io/pleo/prop/core/PropException.kt b/prop-core/src/main/kotlin/io/pleo/prop/core/PropException.kt index dfd89bcd..58786989 100644 --- a/prop-core/src/main/kotlin/io/pleo/prop/core/PropException.kt +++ b/prop-core/src/main/kotlin/io/pleo/prop/core/PropException.kt @@ -2,5 +2,5 @@ package io.pleo.prop.core open class PropException( message: String? = null, - cause: Throwable? = null + cause: Throwable? = null, ) : RuntimeException(message, cause) diff --git a/prop-core/src/main/kotlin/io/pleo/prop/core/internal/LocalProp.kt b/prop-core/src/main/kotlin/io/pleo/prop/core/internal/LocalProp.kt index 8edd173e..44ce772f 100644 --- a/prop-core/src/main/kotlin/io/pleo/prop/core/internal/LocalProp.kt +++ b/prop-core/src/main/kotlin/io/pleo/prop/core/internal/LocalProp.kt @@ -6,21 +6,23 @@ import io.pleo.prop.core.Supplier import java.time.Instant class LocalProp( - private val supplier: Supplier + private val supplier: Supplier, ) : Prop { private val created: Instant = Instant.now() constructor(value: T) : this({ value }) override fun invoke() = supplier() + override fun get() = invoke() override val name get() = toString() override val changedTimestamp get() = created /** Static properties can't change. No callbacks.*/ - override fun addCallback(callback: Callback) {} - override fun removeAllCallbacks() {} + override fun addCallback(callback: Callback) = Unit + + override fun removeAllCallbacks() = Unit override fun toString() = "LocalProp=${get()}" } diff --git a/prop-core/src/main/kotlin/io/pleo/prop/core/internal/PropFactory.kt b/prop-core/src/main/kotlin/io/pleo/prop/core/internal/PropFactory.kt index 9999e59f..687fe2ea 100644 --- a/prop-core/src/main/kotlin/io/pleo/prop/core/internal/PropFactory.kt +++ b/prop-core/src/main/kotlin/io/pleo/prop/core/internal/PropFactory.kt @@ -8,6 +8,6 @@ interface PropFactory { fun createProp( propName: String, parse: Parser, - defaultValue: T? + defaultValue: T?, ): Prop } diff --git a/prop-guice/src/main/kotlin/io/pleo/prop/guice/AutoPropModule.kt b/prop-guice/src/main/kotlin/io/pleo/prop/guice/AutoPropModule.kt index ddfdea67..44bfb9ac 100644 --- a/prop-guice/src/main/kotlin/io/pleo/prop/guice/AutoPropModule.kt +++ b/prop-guice/src/main/kotlin/io/pleo/prop/guice/AutoPropModule.kt @@ -11,19 +11,19 @@ class AutoPropModule( private val packagePrefix: String, private val modulesToScan: Iterable, private val propFactory: PropFactory, - private val parserFactory: ParserFactory + private val parserFactory: ParserFactory, ) : Module { override fun configure(binder: Binder) { PropMappingVisitor( { it.rawType.getPackage().name.startsWith(packagePrefix) }, propFactory, - parserFactory + parserFactory, ) .visit(Elements.getElements(modulesToScan)) .forEach { (key, value) -> value.fold( { binder.bind(key).toInstance(it) }, - { binder.addError(it) } + { binder.addError(it) }, ) } } diff --git a/prop-guice/src/main/kotlin/io/pleo/prop/guice/internal/PropMappingVisitor.kt b/prop-guice/src/main/kotlin/io/pleo/prop/guice/internal/PropMappingVisitor.kt index 4465f9ef..9f9bd348 100644 --- a/prop-guice/src/main/kotlin/io/pleo/prop/guice/internal/PropMappingVisitor.kt +++ b/prop-guice/src/main/kotlin/io/pleo/prop/guice/internal/PropMappingVisitor.kt @@ -31,7 +31,7 @@ typealias PropResult = Result> class PropMappingVisitor( filter: Predicate>, private val propFactory: PropFactory, - private val parserFactory: ParserFactory + private val parserFactory: ParserFactory, ) : DefaultElementVisitor>, PropResult>>() { private val injectionPointExtractor: InjectionPointExtractor = InjectionPointExtractor(filter) @@ -69,10 +69,11 @@ class PropMappingVisitor( private fun extractProps(injectionPoint: InjectionPoint?): Map>, PropResult> = buildMap { - val parameters = (injectionPoint?.member as? Executable) - ?.parameters - ?.toList() - ?: return@buildMap + val parameters = + (injectionPoint?.member as? Executable) + ?.parameters + ?.toList() + ?: return@buildMap injectionPoint.dependencies .filterIsPropDependency() @@ -90,8 +91,10 @@ class PropMappingVisitor( it.key.typeLiteral.type is ParameterizedType } as List>> - private fun MutableMap>.buildAndSet(key: K, builder: () -> V) = - set(key, runCatching(builder)) + private fun MutableMap>.buildAndSet( + key: K, + builder: () -> V, + ) = set(key, runCatching(builder)) private fun Parameter.toProp(key: Key<*>): Prop<*> { val propertyName: String = getNamedAnnotationValue(annotations.toList(), key) @@ -99,16 +102,17 @@ class PropMappingVisitor( try { val annotation = getAnnotation(Default::class.java) - val defaultValue = ofNullable(annotation) - .map(Default::value) - .map(parser) - .orElse(null) + val defaultValue = + ofNullable(annotation) + .map(Default::value) + .map(parser) + .orElse(null) @Suppress("UNCHECKED_CAST") return propFactory.createProp( propertyName, parser as Parser, - defaultValue + defaultValue, ) } catch (ex: RuntimeException) { throw FailedToCreatePropException(propertyName, ex) @@ -121,7 +125,10 @@ class PropMappingVisitor( return parserFactory.createParserForType(type) } - private fun getNamedAnnotationValue(annotations: List, key: Key<*>): String = + private fun getNamedAnnotationValue( + annotations: List, + key: Key<*>, + ): String = annotations.mapNotNull(::annotationValueIfNamed).lastOrNull() ?: throw RequiredNamedAnnotationException(key) diff --git a/prop-guice/src/main/kotlin/io/pleo/prop/guice/internal/PropParameters.kt b/prop-guice/src/main/kotlin/io/pleo/prop/guice/internal/PropParameters.kt index ffe5952b..f8bc7d3e 100644 --- a/prop-guice/src/main/kotlin/io/pleo/prop/guice/internal/PropParameters.kt +++ b/prop-guice/src/main/kotlin/io/pleo/prop/guice/internal/PropParameters.kt @@ -4,5 +4,5 @@ import com.google.inject.TypeLiteral class PropParameters( val typeLiteral: TypeLiteral, - val annotations: List + val annotations: List, ) diff --git a/prop-jackson/src/main/kotlin/io/pleo/prop/jackson/JacksonParserFactory.kt b/prop-jackson/src/main/kotlin/io/pleo/prop/jackson/JacksonParserFactory.kt index 233cf2ad..ca7255ba 100644 --- a/prop-jackson/src/main/kotlin/io/pleo/prop/jackson/JacksonParserFactory.kt +++ b/prop-jackson/src/main/kotlin/io/pleo/prop/jackson/JacksonParserFactory.kt @@ -22,50 +22,53 @@ import java.time.ZoneOffset import java.time.ZonedDateTime import javax.money.Monetary -class JacksonParserFactory @JvmOverloads constructor( - private val objectMapper: ObjectMapper = ObjectMapper() +class JacksonParserFactory +@JvmOverloads +constructor( + private val objectMapper: ObjectMapper = ObjectMapper(), ) : ParserFactory { @Suppress("MemberVisibilityCanBePrivate") - private val knownParsers: MutableMap Any> = mutableMapOf( - // The list of Prop types that will not be parsed using Jackson and JSON parsing - buildParserRef { it }, - buildParserRef(String::toBoolean), - buildParserRef(String::toInt), - buildParserRef(String::toFloat), - buildParserRef(String::toDouble), - buildParserRef(String::toBigDecimal), - buildParserRef(Instant::parse), - buildParserRef(OffsetDateTime::parse), - buildParserRef(ZonedDateTime::parse), - buildParserRef(Duration::parse), - buildParserRef(LocalDateTime::parse), - buildParserRef(LocalDate::parse), - buildParserRef(LocalTime::parse), - buildParserRef(MonthDay::parse), - buildParserRef(OffsetTime::parse), - buildParserRef(Period::parse), - buildParserRef(Year::parse), - buildParserRef(YearMonth::parse), - buildParserRef(ZoneId::of), - buildParserRef(ZoneOffset::of), - buildParserRef(Monetary::getCurrency) - ) + private val knownParsers: MutableMap Any> = + mutableMapOf( + // The list of Prop types that will not be parsed using Jackson and JSON parsing + buildParserRef { it }, + buildParserRef(String::toBoolean), + buildParserRef(String::toInt), + buildParserRef(String::toFloat), + buildParserRef(String::toDouble), + buildParserRef(String::toBigDecimal), + buildParserRef(Instant::parse), + buildParserRef(OffsetDateTime::parse), + buildParserRef(ZonedDateTime::parse), + buildParserRef(Duration::parse), + buildParserRef(LocalDateTime::parse), + buildParserRef(LocalDate::parse), + buildParserRef(LocalTime::parse), + buildParserRef(MonthDay::parse), + buildParserRef(OffsetTime::parse), + buildParserRef(Period::parse), + buildParserRef(Year::parse), + buildParserRef(YearMonth::parse), + buildParserRef(ZoneId::of), + buildParserRef(ZoneOffset::of), + buildParserRef(Monetary::getCurrency), + ) - override fun createParserForType(type: Type): Parser<*> = - knownParsers.getOrPut(type, buildParserBuilder(type)) + override fun createParserForType(type: Type): Parser<*> = knownParsers.getOrPut(type, buildParserBuilder(type)) - private fun buildParserBuilder(type: Type): (() -> Parser) = { - { rawString: String -> - try { - objectMapper.readValue(rawString, TypeFactory.defaultInstance().constructType(type)) - } catch (ex: IOException) { - throw FailedToParsePropValueException(ex) - } catch (ex: RuntimeException) { - throw FailedToParsePropValueException(ex) + private fun buildParserBuilder(type: Type): (() -> Parser) = + { + { + rawString: String -> + try { + objectMapper.readValue(rawString, TypeFactory.defaultInstance().constructType(type)) + } catch (ex: IOException) { + throw FailedToParsePropValueException(ex) + } catch (ex: RuntimeException) { + throw FailedToParsePropValueException(ex) + } } } - } - private inline fun buildParserRef(noinline parser: Parser) = - T::class.java to parser + private inline fun buildParserRef(noinline parser: Parser) = T::class.java to parser }