diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..38a91ce --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,134 @@ +name-template: $RESOLVED_VERSION +tag-template: v$RESOLVED_VERSION +pull-request: + title-templates: + fix: '🐛 $TITLE (#$NUMBER)' + feat: '🚀 $TITLE (#$NUMBER)' + default: '$TITLE (#$NUMBER)' +autolabeler: + - label: 'bug' + branch: + - '/fix\/.+/' + title: + - '/fix/i' + - label: 'improvement' + branch: + - '/improv\/.+/' + title: + - '/improv/i' + - label: 'feature' + branch: + - '/feature\/.+/' + title: + - '/feat/i' + - label: 'documentation' + branch: + - '/docs\/.+/' + title: + - '/docs/i' + - label: 'maintenance' + branch: + - '/(chore|refactor|style|test|ci|perf|build)\/.+/' + title: + - '/(chore|refactor|style|test|ci|perf|build)/i' + - label: 'chore' + branch: + - '/chore\/.+/' + title: + - '/chore/i' + - label: 'refactor' + branch: + - '/refactor\/.+/' + title: + - '/refactor/i' + - label: 'style' + branch: + - '/style\/.+/' + title: + - '/style/i' + - label: 'test' + branch: + - '/test\/.+/' + title: + - '/test/i' + - label: 'ci' + branch: + - '/ci\/.+/' + title: + - '/ci/i' + - label: 'perf' + branch: + - '/perf\/.+/' + title: + - '/perf/i' + - label: 'build' + branch: + - '/build\/.+/' + title: + - '/build/i' + - label: 'deps' + branch: + - '/deps\/.+/' + title: + - '/deps/i' + - label: 'revert' + branch: + - '/revert\/.+/' + title: + - '/revert/i' +categories: + - title: '🚀 Features' + labels: + - 'feature' + - "type: enhancement" + - "type: new feature" + - "type: major" + - "type: minor" + - title: '💡 Improvements' + labels: + - 'improvement' + - "type: improvement" + + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bug' + - "type: bug" + - title: '📚 Documentation' + labels: + - 'docs' + - title: '🔧 Maintenance' + labels: + - 'maintenance' + - 'chore' + - 'refactor' + - 'style' + - 'test' + - 'ci' + - 'perf' + - 'build' + - "type: ci" + - "type: build" + - title: '⏪ Reverts' + labels: + - 'revert' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +version-resolver: + major: + labels: + - 'type: major' + minor: + labels: + - 'type: minor' + patch: + labels: + - 'type: patch' + default: patch +template: | + ## What's Changed + + $CHANGES + + ## Contributors + + $CONTRIBUTORS \ No newline at end of file diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..30740f8 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,61 @@ +{ + "extends": [ + "config:base" + ], + "labels": ["type: dependency upgrade"], + "packageRules": [ + { + "matchUpdateTypes": ["major"], + "enabled": false + }, + { + "matchPackagePatterns": ["*"], + "allowedVersions": "!/SNAPSHOT$/" + }, + { + "matchPackagePatterns": [ + "^org\\.codehaus\\.groovy" + ], + "groupName": "groovy monorepo" + }, + { + "matchPackageNames": [ + "org.grails:grails-bom", + "org.grails:grails-bootstrap", + "org.grails:grails-codecs", + "org.grails:grails-console", + "org.grails:grails-core", + "org.grails:grails-databinding", + "org.grails:grails-dependencies", + "org.grails:grails-docs", + "org.grails:grails-encoder", + "org.grails:grails-gradle-model", + "org.grails:grails-logging", + "org.grails:grails-plugin-codecs", + "org.grails:grails-plugin-controllers", + "org.grails:grails-plugin-databinding", + "org.grails:grails-plugin-datasource", + "org.grails:grails-plugin-domain-class", + "org.grails:grails-plugin-i18n", + "org.grails:grails-plugin-interceptors", + "org.grails:grails-plugin-mimetypes", + "org.grails:grails-plugin-rest", + "org.grails:grails-plugin-services", + "org.grails:grails-plugin-url-mappings", + "org.grails:grails-plugin-url-validation", + "org.grails:grails-shell", + "org.grails:grails-spring", + "org.grails:grails-test", + "org.grails:grails-validation", + "org.grails:grails-web", + "org.grails:grails-web-boot", + "org.grails:grails-web-common", + "org.grails:grails-web-databinding", + "org.grails:grails-web-fileupload", + "org.grails:grails-web-mvc", + "org.grails:grails-web-url-mappings" + ], + "groupName": "grails monorepo" + } + ] +} \ No newline at end of file diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..668dda4 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,71 @@ +name: "Java CI" +on: + push: + branches: + - '[4-9]+.[0-9]+.x' + pull_request: + branches: + - '[4-9]+.[0-9]+.x' + workflow_dispatch: +jobs: + test_project: + name: "Test Project" + runs-on: ubuntu-24.04 + strategy: + fail-fast: true + matrix: + java: [17] + steps: + - name: "📥 Checkout repository" + uses: actions/checkout@v4 + - name: "☕️ Setup JDK" + uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.java }} + distribution: liberica + - name: "🐘 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 + with: + develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} + - name: "🏃 Run tests" + run: ./gradlew check + - name: "🏃 Run integration tests" + working-directory: ./examples/testapp1 + run: ./gradlew integrationTest + publish_snapshot: + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' + name: "Build Project and Publish Snapshot release" + needs: test_project + runs-on: ubuntu-24.04 + permissions: + contents: write # updates gh-pages branch + packages: write # publishes snapshot to GitHub Packages + steps: + - name: "📥 Checkout repository" + uses: actions/checkout@v4 + - name: "☕️ Setup JDK" + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: liberica + - name: "🐘 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 + with: + develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} + - name: "🔨 Build Project" + run: ./gradlew build + - name: "📤 Publish Snapshot version to Artifactory (repo.grails.org)" + env: + GRAILS_PUBLISH_RELEASE: 'false' + MAVEN_PUBLISH_USERNAME: ${{ secrets.MAVEN_PUBLISH_USERNAME }} + MAVEN_PUBLISH_PASSWORD: ${{ secrets.MAVEN_PUBLISH_PASSWORD }} + MAVEN_PUBLISH_URL: 'https://repo.grails.org/artifactory/plugins3-snapshots-local' + run: ./gradlew publish + - name: "📖 Generate Snapshot Documentation" + run: ./gradlew docs + - name: "📤 Publish Snapshot Documentation to Github Pages" + uses: apache/grails-github-actions/deploy-github-pages@asf + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GRADLE_PUBLISH_RELEASE: 'false' + SOURCE_FOLDER: build/docs \ No newline at end of file diff --git a/.github/workflows/release-notes.yml b/.github/workflows/release-notes.yml new file mode 100644 index 0000000..e41d6b4 --- /dev/null +++ b/.github/workflows/release-notes.yml @@ -0,0 +1,23 @@ +name: "Release Drafter" +on: + issues: + types: [closed, reopened] + push: + branches: + - master + - '[4-9]+.[0-9]+.x' + pull_request: + types: [opened, reopened, synchronize] + pull_request_target: + types: [opened, reopened, synchronize] +jobs: + update_release_draft: + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-24.04 + steps: + - name: "📝 Update Release Draft" + uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..254bf96 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +name: "Release" +on: + release: + types: [published] +jobs: + release: + name: "Publish Release" + runs-on: ubuntu-24.04 + permissions: + packages: read # for pre-release workflow + contents: write # to commit changes related to the release and publish documentation to gh-pages + issues: write # to modify milestones + steps: + - name: "📥 Checkout repository" + uses: actions/checkout@v4 + - name: "☕️ Setup JDK" + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: liberica + - name: "🐘 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 + with: + develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} + - name: "📝 Store the current release version" + run: | + echo "Release version: ${GITHUB_REF:11}" + echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV + - name: "⚙ Run pre-release" + uses: apache/grails-github-actions/pre-release@asf + - name: "🔐 Generate key file for artifact signing" + env: + SECRING_FILE: ${{ secrets.SECRING_FILE }} + run: echo $SECRING_FILE | base64 -d > ${{ github.workspace }}/secring.gpg + - name: "📤 Publish artifacts to Sonatype" + env: + GRAILS_PUBLISH_RELEASE: 'true' + NEXUS_PUBLISH_USERNAME: ${{ secrets.NEXUS_PUBLISH_USERNAME }} + NEXUS_PUBLISH_PASSWORD: ${{ secrets.NEXUS_PUBLISH_PASSWORD }} + NEXUS_PUBLISH_URL: ${{ secrets.NEXUS_PUBLISH_RELEASE_URL }} + NEXUS_PUBLISH_STAGING_PROFILE_ID: ${{ secrets.NEXUS_PUBLISH_STAGING_PROFILE_ID }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY_ID }} + SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }} + run: > + ./gradlew + -Psigning.secretKeyRingFile=${{ github.workspace }}/secring.gpg + publishToSonatype + closeAndReleaseSonatypeStagingRepository + - name: "📖 Generate Documentation" + run: ./gradlew docs + - name: "📤 Publish Documentation to Github Pages" + uses: apache/grails-github-actions/deploy-github-pages@asf + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GRADLE_PUBLISH_RELEASE: 'true' + SOURCE_FOLDER: build/docs + VERSION: ${{ env.RELEASE_VERSION }} + - name: "⚙️ Run post-release" + uses: apache/grails-github-actions/post-release@asf \ No newline at end of file diff --git a/.gitignore b/.gitignore index 611ee88..1ed03b5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ build/ .project .settings .classpath +/bin/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 814b511..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: groovy -services: - - redis -jdk: -- oraclejdk7 -before_script: -- rm -rf target -script: ./travis-build.sh -env: - global: - - GIT_NAME="Graeme Rocher" - - GIT_EMAIL="graeme.rocher@gmail.com" - - secure: fqSTYxSnMQk2AQx45HeJYrsG5zowbcxTd045ShK0Z33gjshF1XxgorqNX2U7+QHfZLZv+ZKKNvMhBR0QkNFxV9mIwbPLVPU5JucvCtvQzwKMhBo/Wo4D6Bc9aT40SfG3kcoWpVUN5kLImARzSerlSZcFvT9yRQlSnPuw202BEY0= - - secure: M9t/F/L6KQ2g4zw3GN9sTeEHnOX2en/Sq01vl4jTF7iikp2gHhrkkItZ4PvHspiQ7q3+qvoOkC1Cyhu1yjC5MfgLVn9ahR/cKfzGd7RerGltasc+Lb1Y6tq56GVL+OXVMRdbISMz8Zp7glCU54b43UlU9ma0aHtjpNbiQXBvuFg= - - secure: a2aa7LrU3C0sm6Rr1dOcOK/Jbqv8OKBXJPdVwQpM4kc++6foXSaHakJxX+vMVQKfAjURextmmHCoB4bDj2ZUMVTafvywTSFB/GTTPYggVxiu5OomcTiZOFuk8twRP9MDJIyZDHbxpDPQn3hb5xRT/3+yyTEhlsfDqGe3aPsqqBE= diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d69106b --- /dev/null +++ b/LICENSE @@ -0,0 +1,203 @@ +/* +* Apache License +* Version 2.0, January 2004 +* http://www.apache.org/licenses/ +* +* TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +* +* 1. Definitions. +* +* "License" shall mean the terms and conditions for use, reproduction, +* and distribution as defined by Sections 1 through 9 of this document. +* +* "Licensor" shall mean the copyright owner or entity authorized by +* the copyright owner that is granting the License. +* +* "Legal Entity" shall mean the union of the acting entity and all +* other entities that control, are controlled by, or are under common +* control with that entity. For the purposes of this definition, +* "control" means (i) the power, direct or indirect, to cause the +* direction or management of such entity, whether by contract or +* otherwise, or (ii) ownership of fifty percent (50%) or more of the +* outstanding shares, or (iii) beneficial ownership of such entity. +* +* "You" (or "Your") shall mean an individual or Legal Entity +* exercising permissions granted by this License. +* +* "Source" form shall mean the preferred form for making modifications, +* including but not limited to software source code, documentation +* source, and configuration files. +* +* "Object" form shall mean any form resulting from mechanical +* transformation or translation of a Source form, including but +* not limited to compiled object code, generated documentation, +* and conversions to other media types. +* +* "Work" shall mean the work of authorship, whether in Source or +* Object form, made available under the License, as indicated by a +* copyright notice that is included in or attached to the work +* (an example is provided in the Appendix below). +* +* "Derivative Works" shall mean any work, whether in Source or Object +* form, that is based on (or derived from) the Work and for which the +* editorial revisions, annotations, elaborations, or other modifications +* represent, as a whole, an original work of authorship. For the purposes +* of this License, Derivative Works shall not include works that remain +* separable from, or merely link (or bind by name) to the interfaces of, +* the Work and Derivative Works thereof. +* +* "Contribution" shall mean any work of authorship, including +* the original version of the Work and any modifications or additions +* to that Work or Derivative Works thereof, that is intentionally +* submitted to Licensor for inclusion in the Work by the copyright owner +* or by an individual or Legal Entity authorized to submit on behalf of +* the copyright owner. For the purposes of this definition, "submitted" +* means any form of electronic, verbal, or written communication sent +* to the Licensor or its representatives, including but not limited to +* communication on electronic mailing lists, source code control systems, +* and issue tracking systems that are managed by, or on behalf of, the +* Licensor for the purpose of discussing and improving the Work, but +* excluding communication that is conspicuously marked or otherwise +* designated in writing by the copyright owner as "Not a Contribution." +* +* "Contributor" shall mean Licensor and any individual or Legal Entity +* on behalf of whom a Contribution has been received by Licensor and +* subsequently incorporated within the Work. +* +* 2. Grant of Copyright License. Subject to the terms and conditions of +* this License, each Contributor hereby grants to You a perpetual, +* worldwide, non-exclusive, no-charge, royalty-free, irrevocable +* copyright license to reproduce, prepare Derivative Works of, +* publicly display, publicly perform, sublicense, and distribute the +* Work and such Derivative Works in Source or Object form. +* +* 3. Grant of Patent License. Subject to the terms and conditions of +* this License, each Contributor hereby grants to You a perpetual, +* worldwide, non-exclusive, no-charge, royalty-free, irrevocable +* (except as stated in this section) patent license to make, have made, +* use, offer to sell, sell, import, and otherwise transfer the Work, +* where such license applies only to those patent claims licensable +* by such Contributor that are necessarily infringed by their +* Contribution(s) alone or by combination of their Contribution(s) +* with the Work to which such Contribution(s) was submitted. If You +* institute patent litigation against any entity (including a +* cross-claim or counterclaim in a lawsuit) alleging that the Work +* or a Contribution incorporated within the Work constitutes direct +* or contributory patent infringement, then any patent licenses +* granted to You under this License for that Work shall terminate +* as of the date such litigation is filed. +* +* 4. Redistribution. You may reproduce and distribute copies of the +* Work or Derivative Works thereof in any medium, with or without +* modifications, and in Source or Object form, provided that You +* meet the following conditions: +* +* (a) You must give any other recipients of the Work or +* Derivative Works a copy of this License; and +* +* (b) You must cause any modified files to carry prominent notices +* stating that You changed the files; and +* +* (c) You must retain, in the Source form of any Derivative Works +* that You distribute, all copyright, patent, trademark, and +* attribution notices from the Source form of the Work, +* excluding those notices that do not pertain to any part of +* the Derivative Works; and +* +* (d) If the Work includes a "NOTICE" text file as part of its +* distribution, then any Derivative Works that You distribute must +* include a readable copy of the attribution notices contained +* within such NOTICE file, excluding those notices that do not +* pertain to any part of the Derivative Works, in at least one +* of the following places: within a NOTICE text file distributed +* as part of the Derivative Works; within the Source form or +* documentation, if provided along with the Derivative Works; or, +* within a display generated by the Derivative Works, if and +* wherever such third-party notices normally appear. The contents +* of the NOTICE file are for informational purposes only and +* do not modify the License. You may add Your own attribution +* notices within Derivative Works that You distribute, alongside +* or as an addendum to the NOTICE text from the Work, provided +* that such additional attribution notices cannot be construed +* as modifying the License. +* +* You may add Your own copyright statement to Your modifications and +* may provide additional or different license terms and conditions +* for use, reproduction, or distribution of Your modifications, or +* for any such Derivative Works as a whole, provided Your use, +* reproduction, and distribution of the Work otherwise complies with +* the conditions stated in this License. +* +* 5. Submission of Contributions. Unless You explicitly state otherwise, +* any Contribution intentionally submitted for inclusion in the Work +* by You to the Licensor shall be under the terms and conditions of +* this License, without any additional terms or conditions. +* Notwithstanding the above, nothing herein shall supersede or modify +* the terms of any separate license agreement you may have executed +* with Licensor regarding such Contributions. +* +* 6. Trademarks. This License does not grant permission to use the trade +* names, trademarks, service marks, or product names of the Licensor, +* except as required for reasonable and customary use in describing the +* origin of the Work and reproducing the content of the NOTICE file. +* +* 7. Disclaimer of Warranty. Unless required by applicable law or +* agreed to in writing, Licensor provides the Work (and each +* Contributor provides its Contributions) on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied, including, without limitation, any warranties or conditions +* of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +* PARTICULAR PURPOSE. You are solely responsible for determining the +* appropriateness of using or redistributing the Work and assume any +* risks associated with Your exercise of permissions under this License. +* +* 8. Limitation of Liability. In no event and under no legal theory, +* whether in tort (including negligence), contract, or otherwise, +* unless required by applicable law (such as deliberate and grossly +* negligent acts) or agreed to in writing, shall any Contributor be +* liable to You for damages, including any direct, indirect, special, +* incidental, or consequential damages of any character arising as a +* result of this License or out of the use or inability to use the +* Work (including but not limited to damages for loss of goodwill, +* work stoppage, computer failure or malfunction, or any and all +* other commercial damages or losses), even if such Contributor +* has been advised of the possibility of such damages. +* +* 9. Accepting Warranty or Additional Liability. While redistributing +* the Work or Derivative Works thereof, You may choose to offer, +* and charge a fee for, acceptance of support, warranty, indemnity, +* or other liability obligations and/or rights consistent with this +* License. However, in accepting such obligations, You may act only +* on Your own behalf and on Your sole responsibility, not on behalf +* of any other Contributor, and only if You agree to indemnify, +* defend, and hold each Contributor harmless for any liability +* incurred by, or claims asserted against, such Contributor by reason +* of your accepting any such warranty or additional liability. +* +* END OF TERMS AND CONDITIONS +* +* APPENDIX: How to apply the Apache License to your work. +* +* To apply the Apache License to your work, attach the following +* boilerplate notice, with the fields enclosed by brackets "[]" +* replaced with your own identifying information. (Don't include +* the brackets!) The text should be enclosed in the appropriate +* comment syntax for the file format. We also recommend that a +* file or class name and description of purpose be included on the +* same "printed page" as the copyright notice for easier +* identification within third-party archives. +* +* Copyright 2009 SpringSource +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ diff --git a/README.md b/README.md index 35a498c..3a50d47 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,29 @@ -[![Build Status](https://travis-ci.org/grails-plugins/grails-cache-redis.svg)](https://travis-ci.org/grails-plugins/grails-cache-redis) +[![Maven Central](https://img.shields.io/maven-central/v/org.grails.plugins/grails-cache-redis.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/org.grails.plugins/grails-cache-redis) +[![Java CI](https://github.com/grails-plugins/grails-cache-redis/actions/workflows/gradle.yml/badge.svg?event=push)](https://github.com/grails-plugins/grails-cache-redis/actions/workflows/gradle.yml) -Cache Redis Plugin -================== +# Cache Redis Plugin -For more information see [the plugin page](http://grails.org/plugin/cache-redis) +## Versions + +| Branch | Grails Version | +|--------|----------------| +| 1.x | 2 | +| 2.x | 3 | +| 6.x | 6 | + +## Documentation + +- [Latest Release](https://grails-plugins.github.io/grails-cache-redis/latest/) +- [Development Snapshot](https://grails-plugins.github.io/grails-cache-redis/snapshot/) + +## Issues + +Issues can be raised via [GitHub Issues](https://github.com/grails-plugins/grails-cache-redis/issues). + +## Contributing + +Pull requests are the preferred way to submit contributions. Before submitting, please create an issue using +the [issue tracker](https://github.com/grails-plugins/grails-cache-redis/issues), outlining the problem your contribution +addresses. + +For documentation contributions, creating an issue is not required. diff --git a/build.gradle b/build.gradle index beb14e3..34410a0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,94 +1,63 @@ -buildscript { - ext { - grailsVersion = project.grailsVersion - } - repositories { - mavenLocal() - maven { url "https://repo.grails.org/grails/core" } - } - dependencies { - classpath "org.grails:grails-gradle-plugin:$grailsVersion" - classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2" - classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3' - } +plugins { + id 'groovy' + id 'java-library' + id 'io.github.gradle-nexus.publish-plugin' + id 'maven-publish' + id 'signing' + id 'org.asciidoctor.jvm.convert' } -version '2.0.0.BUILD-SNAPSHOT' -group 'org.grails.plugins' +version = projectVersion +group = 'org.grails.plugins' +ext.set('grailsVersion', libs.versions.grails.asProvider().get()) +ext.set('isReleaseVersion', !version.toString().endsWith('-SNAPSHOT')) +ext.set('isSnapshot', !isReleaseVersion) -apply plugin:"eclipse" -apply plugin:"idea" -apply plugin:"org.grails.grails-plugin" -apply plugin:"org.grails.grails-plugin-publish" -apply plugin:"org.grails.grails-gsp" -apply plugin: 'org.asciidoctor.convert' +apply plugin: 'org.grails.grails-plugin' // Needs to be applied after grailsVersion has been set -ext { - grailsVersion = project.grailsVersion - gradleWrapperVersion = project.gradleWrapperVersion -} repositories { - mavenLocal() - maven { url "https://repo.grails.org/grails/core" } -} - -dependencyManagement { - imports { - mavenBom "org.grails:grails-bom:$grailsVersion" - } - applyMavenExclusions false + mavenCentral() + maven { url "https://repo.grails.org/grails/core/" } } dependencies { - provided 'org.springframework.boot:spring-boot-starter-logging' - provided 'org.springframework.boot:spring-boot-autoconfigure' - provided 'org.springframework.boot:spring-boot-starter-actuator' - provided 'org.springframework.boot:spring-boot-starter-tomcat' - provided "org.grails:grails-dependencies" - provided "org.grails:grails-web-boot" - compile "org.grails:grails-core" - compile "org.grails.plugins:cache" - console "org.grails:grails-console" - profile "org.grails.profiles:web-plugin:3.1.8" - provided "org.grails:grails-plugin-services" - provided "org.grails:grails-plugin-domain-class" - testCompile "org.grails:grails-plugin-testing" + api libs.jedis.client + api libs.spring.data.redis - compile 'redis.clients:jedis:2.8.0' - compile 'org.springframework.data:spring-data-redis:1.6.2.RELEASE' -} + implementation libs.groovy.core + implementation libs.spring.context + implementation libs.spring.context.support -task wrapper(type: Wrapper) { - gradleVersion = gradleWrapperVersion -} -grailsPublish { - // TODO: Provide values here - user = 'user' - key = 'key' - githubSlug = 'foo/bar' - license { - name = 'Apache-2.0' - } - title = "My Plugin" - desc = "Full plugin description" - developers = [johndoe:"John Doe"] - portalUser = "" - portalPassword = "" + implementation libs.grails.core + implementation libs.grails.cache + + implementation libs.spring.beans + implementation libs.springboot.autoconfigure + + implementation libs.jedis.client + implementation libs.spring.data.redis + + testImplementation libs.grails.testing.support.core + testImplementation libs.spock.core + + integrationTestImplementation libs.spring.web + + integrationTestRuntimeOnly libs.slf4j.nop // Get rid of warning about missing slf4j implementation during test task + integrationTestRuntimeOnly libs.springboot.starter.tomcat + + testImplementation libs.bytebudy } -asciidoctor { - resources { - from('src/docs/images') - into "./images" - } - attributes 'experimental' : 'true', - 'compat-mode' : 'true', - 'toc' : 'left', - 'icons' : 'font', - 'version' : project.version, - 'sourcedir' : "/src/main/groovy" +tasks.withType(Test).configureEach { + useJUnitPlatform() + testLogging { + events 'passed', 'skipped', 'failed' + } } -task docs(dependsOn:[asciidoctor]) +apply from: layout.projectDirectory.file('gradle/java-config.gradle') +apply from: layout.projectDirectory.file('gradle/grails-plugin-config.gradle') +apply from: layout.projectDirectory.file('gradle/docs-config.gradle') +apply from: layout.projectDirectory.file('gradle/publishing.gradle') diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000..7695ccf --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,10 @@ +repositories { + mavenCentral() + maven { url = 'https://repo.grails.org/grails/core' } +} +dependencies { + implementation buildsrcLibs.nexus.publish.gradle.plugin + implementation buildsrcLibs.grails.gradle.plugin + implementation buildsrcLibs.asciidoctor.gradle.plugin + +} \ No newline at end of file diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle new file mode 100644 index 0000000..6cd9ab1 --- /dev/null +++ b/buildSrc/settings.gradle @@ -0,0 +1,7 @@ +dependencyResolutionManagement { + versionCatalogs { + buildsrcLibs { + from(files('../gradle/buildsrc.libs.versions.toml')) + } + } +} \ No newline at end of file diff --git a/functional-tests/.gitignore b/functional-tests/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/functional-tests/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/functional-tests/build.gradle b/functional-tests/build.gradle index def7192..e28cd4b 100644 --- a/functional-tests/build.gradle +++ b/functional-tests/build.gradle @@ -1,75 +1,59 @@ buildscript { - ext { - grailsVersion = project.grailsVersion - } repositories { - mavenLocal() maven { url "https://repo.grails.org/grails/core" } + mavenCentral() } - dependencies { - classpath "org.grails:grails-gradle-plugin:$grailsVersion" - classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2" - classpath "org.grails.plugins:hibernate4:5.0.6" + dependencies { // Not Published to Gradle Plugin Portal + classpath "org.grails:grails-gradle-plugin:6.2.4" + classpath "org.grails.plugins:hibernate5:8.1.0" } } -version "0.1" -group "functional.tests" - -apply plugin:"eclipse" -apply plugin:"idea" -apply plugin:"war" -apply plugin:"org.grails.grails-web" -apply plugin:"org.grails.grails-gsp" -apply plugin:"asset-pipeline" - -ext { - grailsVersion = project.grailsVersion - gradleWrapperVersion = project.gradleWrapperVersion +plugins { + id "groovy" + id "war" + id "idea" + id "application" + id "eclipse" } +// Not Published to Gradle Plugin Portal +apply plugin: "org.grails.grails-web" +apply plugin: "org.grails.grails-gsp" + repositories { mavenLocal() + mavenCentral() maven { url "https://repo.grails.org/grails/core" } } -dependencyManagement { - imports { - mavenBom "org.grails:grails-bom:$grailsVersion" - } - applyMavenExclusions false -} - dependencies { - compile "org.springframework.boot:spring-boot-starter-logging" - compile "org.springframework.boot:spring-boot-autoconfigure" - compile "org.grails:grails-core" - compile "org.springframework.boot:spring-boot-starter-actuator" - compile "org.springframework.boot:spring-boot-starter-tomcat" - compile "org.grails:grails-dependencies" - compile "org.grails:grails-web-boot" - compile "org.grails.plugins:cache" - compile "org.grails.plugins:scaffolding" - compile "org.grails.plugins:hibernate4" - compile "org.hibernate:hibernate-ehcache" - compile rootProject + implementation "org.springframework.boot:spring-boot-starter-logging" + implementation "org.springframework.boot:spring-boot-autoconfigure" + implementation "org.grails:grails-core" + implementation "org.springframework.boot:spring-boot-starter-actuator" + implementation "org.springframework.boot:spring-boot-starter-tomcat" + implementation "org.grails:grails-dependencies" + implementation "org.grails:grails-web-boot" + implementation "org.grails.plugins:cache" + implementation "org.grails.plugins:hibernate5" + implementation "org.hibernate:hibernate-ehcache" + implementation rootProject console "org.grails:grails-console" - compile 'org.grails.plugins:grails-console:2.0.5' - profile "org.grails.profiles:web:3.1.8" - runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2" - runtime "com.h2database:h2" - testCompile "org.grails:grails-plugin-testing" - testCompile "org.grails.plugins:geb" - testCompile 'org.grails:grails-datastore-rest-client' - testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1" - testRuntime "net.sourceforge.htmlunit:htmlunit:2.18" -} - -task wrapper(type: Wrapper) { - gradleVersion = gradleWrapperVersion + profile "org.grails.profiles:web" + runtimeOnly "com.h2database:h2" + testImplementation "org.grails:grails-test" + testImplementation "io.micronaut:micronaut-inject-groovy" + testImplementation "io.micronaut:micronaut-http-client" + testImplementation "org.grails:grails-web-testing-support" + testImplementation "org.spockframework:spock-core" + + testImplementation 'org.testcontainers:spock:1.21.1' } -assets { - minifyJs = true - minifyCss = true +java { + sourceCompatibility = JavaVersion.toVersion("11") } +tasks.withType(Test).configureEach { + useJUnitPlatform() +} \ No newline at end of file diff --git a/functional-tests/gradle.properties b/functional-tests/gradle.properties index 5ef1562..4327193 100644 --- a/functional-tests/gradle.properties +++ b/functional-tests/gradle.properties @@ -1,2 +1,7 @@ -grailsVersion=3.1.8 -gradleWrapperVersion=2.13 +grailsVersion=6.2.3 +grailsGradlePluginVersion=6.2.4 +version=0.1 +org.gradle.caching=true +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx1024M diff --git a/functional-tests/gradle/wrapper/gradle-wrapper.jar b/functional-tests/gradle/wrapper/gradle-wrapper.jar index ca78035..7454180 100644 Binary files a/functional-tests/gradle/wrapper/gradle-wrapper.jar and b/functional-tests/gradle/wrapper/gradle-wrapper.jar differ diff --git a/functional-tests/gradle/wrapper/gradle-wrapper.properties b/functional-tests/gradle/wrapper/gradle-wrapper.properties index 5c07352..3994438 100644 --- a/functional-tests/gradle/wrapper/gradle-wrapper.properties +++ b/functional-tests/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Jun 16 14:27:12 CDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip diff --git a/functional-tests/gradlew b/functional-tests/gradlew index 27309d9..1b6c787 100755 --- a/functional-tests/gradlew +++ b/functional-tests/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env bash +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for 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/master/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_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +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="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum -warn ( ) { +warn () { echo "$*" -} +} >&2 -die ( ) { +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 + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + 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 @@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + 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. Please set the JAVA_HOME variable in your environment to match the @@ -89,76 +140,95 @@ location of your Java installation." 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*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + 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" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; 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 # 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=$((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 -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# 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. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# 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/functional-tests/gradlew.bat b/functional-tests/gradlew.bat index 832fdb6..107acd3 100644 --- a/functional-tests/gradlew.bat +++ b/functional-tests/gradlew.bat @@ -1,3 +1,19 @@ +@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 @@ -13,15 +29,18 @@ 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= +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 init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,34 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - :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 %CMD_LINE_ARGS% +"%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 diff --git a/functional-tests/grails-app/conf/TestCacheConfig.groovy b/functional-tests/grails-app/conf/TestCacheConfig.groovy deleted file mode 100644 index 0f6b972..0000000 --- a/functional-tests/grails-app/conf/TestCacheConfig.groovy +++ /dev/null @@ -1,9 +0,0 @@ -config = { - cache { - name 'message' - eternal false - overflowToDisk true - maxElementsInMemory 10000 - maxElementsOnDisk 10000000 - } -} \ No newline at end of file diff --git a/functional-tests/grails-app/conf/application.yml b/functional-tests/grails-app/conf/application.yml index 35498a2..47da5e3 100644 --- a/functional-tests/grails-app/conf/application.yml +++ b/functional-tests/grails-app/conf/application.yml @@ -5,27 +5,26 @@ hibernate: use_second_level_cache: true use_query_cache: false region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory' - dataSource: - pooled: true - jmxExport: true driverClassName: org.h2.Driver username: sa - password: - + password: '' + pooled: true + jmxExport: true environments: development: dataSource: dbCreate: create-drop - url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE + url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE test: dataSource: - dbCreate: update - url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE + dbCreate: create-drop + # For unknown reasons the mem:testDb does not work. + url: jdbc:h2:file:./build/testDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE production: dataSource: - dbCreate: update - url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE + dbCreate: none + url: jdbc:h2:./prodDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE properties: jmxEnabled: true initialSize: 5 @@ -43,9 +42,7 @@ environments: testWhileIdle: true testOnReturn: false jdbcInterceptors: ConnectionState - defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED - ---- + defaultTransactionIsolation: 2 --- grails: profile: web diff --git a/functional-tests/grails-app/conf/logback.groovy b/functional-tests/grails-app/conf/logback.groovy deleted file mode 100644 index 2f7c41c..0000000 --- a/functional-tests/grails-app/conf/logback.groovy +++ /dev/null @@ -1,23 +0,0 @@ -import grails.util.BuildSettings -import grails.util.Environment - -// See http://logback.qos.ch/manual/groovy.html for details on configuration -appender('STDOUT', ConsoleAppender) { - encoder(PatternLayoutEncoder) { - pattern = "%level %logger - %msg%n" - } -} - -root(ERROR, ['STDOUT']) - -def targetDir = BuildSettings.TARGET_DIR -if (Environment.isDevelopmentMode() && targetDir) { - appender("FULL_STACKTRACE", FileAppender) { - file = "${targetDir}/stacktrace.log" - append = true - encoder(PatternLayoutEncoder) { - pattern = "%level %logger - %msg%n" - } - } - logger("StackTrace", ERROR, ['FULL_STACKTRACE'], false) -} diff --git a/functional-tests/grails-app/conf/logback.xml b/functional-tests/grails-app/conf/logback.xml new file mode 100644 index 0000000..a91be2b --- /dev/null +++ b/functional-tests/grails-app/conf/logback.xml @@ -0,0 +1,18 @@ + + + + + + + + true + + UTF-8 + %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex + + + + + + + diff --git a/functional-tests/grails-app/controllers/functional/tests/CacheAdminController.groovy b/functional-tests/grails-app/controllers/functional/tests/CacheAdminController.groovy index 8899d53..4ae66da 100644 --- a/functional-tests/grails-app/controllers/functional/tests/CacheAdminController.groovy +++ b/functional-tests/grails-app/controllers/functional/tests/CacheAdminController.groovy @@ -1,6 +1,5 @@ package functional.tests -import grails.plugin.cache.web.PageInfo import org.springframework.cache.Cache @@ -27,7 +26,7 @@ class CacheAdminController { for (key in cache.allKeys) { def value = cache.get(key)?.get() String html - if (value instanceof PageInfo) { + if (value instanceof Object) { html = new String(value.ungzippedBody, response.characterEncoding) } data << [key: key, value: value, html: html] diff --git a/functional-tests/grails-app/controllers/functional/tests/CachingServiceController.groovy b/functional-tests/grails-app/controllers/functional/tests/CachingServiceController.groovy index 9718717..416717c 100644 --- a/functional-tests/grails-app/controllers/functional/tests/CachingServiceController.groovy +++ b/functional-tests/grails-app/controllers/functional/tests/CachingServiceController.groovy @@ -5,23 +5,23 @@ class CachingServiceController { def cachingService def cachingServiceInvocationCount() { - render 'Basic Caching Service Invocation Count Is ' + cachingService.invocationCounter + render text: "Basic Caching Service Invocation Count Is $cachingService.invocationCounter" } def cachingService() { - render "Value From Service Is '$cachingService.data'" + render text: "Value From Service Is '$cachingService.data'" } def cachePut(String key, String value) { - render 'Result: ' + cachingService.getData(key, value) + render text: "Result: ${cachingService.getData(key, value)}" } def cacheGet(String key) { - render 'Result: ' + cachingService.getData(key) + render text: "Result: ${cachingService.getData(key)}" } def clear() { cachingService.clear() - render 'OK' + render text: 'OK' } } diff --git a/functional-tests/grails-app/controllers/functional/tests/TestController.groovy b/functional-tests/grails-app/controllers/functional/tests/TestController.groovy index be0cd35..e3e29a2 100644 --- a/functional-tests/grails-app/controllers/functional/tests/TestController.groovy +++ b/functional-tests/grails-app/controllers/functional/tests/TestController.groovy @@ -5,9 +5,11 @@ import grails.plugin.cache.Cacheable class TestController extends AbstractCacheController { + LogEntryDataService logEntryDataService + @Cacheable('message') def index() { - new LogEntry(message: 'Called index() action').save(failOnError: true, flush: true) + logEntryDataService.save(new LogEntry(message: 'Called index() action')) render 'index' } @@ -18,7 +20,7 @@ class TestController extends AbstractCacheController { @CacheEvict(value='message', allEntries=true) def evict() { - new LogEntry(message: 'Called evict() action').save(failOnError: true, flush: true) + logEntryDataService.save(new LogEntry(message: 'Called evict() action')) render 'evict' } } diff --git a/functional-tests/grails-app/services/functional/tests/CachingService.groovy b/functional-tests/grails-app/services/functional/tests/CachingService.groovy index c339cc2..6346843 100644 --- a/functional-tests/grails-app/services/functional/tests/CachingService.groovy +++ b/functional-tests/grails-app/services/functional/tests/CachingService.groovy @@ -1,34 +1,39 @@ package functional.tests + +import grails.plugin.cache.CacheEvict import grails.plugin.cache.CachePut import grails.plugin.cache.Cacheable -import grails.plugin.cache.CacheEvict class CachingService { - static transactional = false + private int invocationCounter = 0 - private int invocationCounter = 0 + int getInvocationCounter() { + invocationCounter + } - int getInvocationCounter() { - invocationCounter - } + void resetInvocationCounter() { + invocationCounter = 0 + } - @Cacheable('basic') - String getData() { - ++invocationCounter - 'Hello World!' - } + @Cacheable('basic') + String getData() { + ++invocationCounter + 'Hello World!' + } - @Cacheable(value='basic', key='#key') - def getData(String key) { - } + @Cacheable(value = 'basic', key = { key }) + String getData(String key) { + null + } - @CachePut(value='basic', key='#key') - String getData(String key, String value) { - "** ${value} **" - } + @CachePut(value = 'basic', key = { key }) + String getData(String key, String value) { + "** ${value} **" + } - @CacheEvict(value='basic', allEntries=true) - void clear() {} + @CacheEvict(value = 'basic', allEntries = true) + void clear() {} + } diff --git a/functional-tests/grails-app/services/functional/tests/LogEntryDataService.groovy b/functional-tests/grails-app/services/functional/tests/LogEntryDataService.groovy new file mode 100644 index 0000000..0b86ad9 --- /dev/null +++ b/functional-tests/grails-app/services/functional/tests/LogEntryDataService.groovy @@ -0,0 +1,9 @@ +package functional.tests + +import grails.gorm.services.Service + +@Service(LogEntry) +interface LogEntryDataService { + + LogEntry save(LogEntry logEntry) +} diff --git a/functional-tests/grails-cli.yml b/functional-tests/grails-cli.yml new file mode 100644 index 0000000..3ef2bf6 --- /dev/null +++ b/functional-tests/grails-cli.yml @@ -0,0 +1,8 @@ +applicationType: plugin +defaultPackage: g623.plugin +testFramework: spock +sourceLanguage: groovy +buildTool: gradle +gormImpl: gorm-hibernate5 +servletImpl: spring-boot-starter-tomcat +features: [app-name, base, gorm-hibernate5, gradle, grails-application, grails-console, grails-dependencies, grails-gorm-testing-support, grails-gradle-plugin, grails-profiles, grails-wrapper, h2, logback, micronaut-inject-groovy, readme, spock, spring-boot-autoconfigure, spring-boot-starter, spring-resources, yaml] diff --git a/functional-tests/grails-wrapper.jar b/functional-tests/grails-wrapper.jar new file mode 100644 index 0000000..1fbada5 Binary files /dev/null and b/functional-tests/grails-wrapper.jar differ diff --git a/functional-tests/grailsw b/functional-tests/grailsw new file mode 100755 index 0000000..8d0cc12 --- /dev/null +++ b/functional-tests/grailsw @@ -0,0 +1,152 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Grails start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRAILS_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-XX:+TieredCompilation" "-XX:TieredStopAtLevel=1" "-XX:CICompilerCount=3"' + + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# 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 +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +JAR_PATH=$APP_HOME/grails-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || 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 + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "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 +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + JAVACMD=`cygpath --unix "$JAVACMD"` + JAR_PATH=`cygpath --path --mixed "$JAR_PATH"` + + # 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 [ "$GRAILS_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRAILS_CYGPATTERN)" + fi + # 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\"" + fi + i=$((i+1)) + 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 + +# Split up the JVM_OPTS And GRAILS_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRAILS_OPTS + +exec "$JAVACMD" -jar "${JVM_OPTS[@]}" "$JAR_PATH" "$@" diff --git a/functional-tests/grailsw.bat b/functional-tests/grailsw.bat new file mode 100644 index 0000000..14734e4 --- /dev/null +++ b/functional-tests/grailsw.bat @@ -0,0 +1,89 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Grails startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRAILS_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-XX:+TieredCompilation" "-XX:TieredStopAtLevel=1" "-XX:CICompilerCount=3" + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@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 init + +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 init + +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 + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line +set JAR_PATH=%APP_HOME%/grails-wrapper.jar + +@rem Execute Grails +"%JAVA_EXE%" -jar %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRAILS_OPTS% %JAR_PATH% %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRAILS_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRAILS_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/functional-tests/src/integration-test/groovy/functional/tests/CacheSpec.groovy b/functional-tests/src/integration-test/groovy/functional/tests/CacheSpec.groovy index beb3d80..d7f2fdd 100644 --- a/functional-tests/src/integration-test/groovy/functional/tests/CacheSpec.groovy +++ b/functional-tests/src/integration-test/groovy/functional/tests/CacheSpec.groovy @@ -1,161 +1,153 @@ package functional.tests -import geb.spock.GebSpec -import grails.plugins.rest.client.RestBuilder -import grails.plugins.rest.client.RestResponse -import grails.test.mixin.integration.Integration -import grails.transaction.* +import functional.tests.helpers.HttpClientSpec +import functional.tests.helpers.RedisContainerHelper +import grails.gorm.transactions.Rollback +import grails.testing.mixin.integration.Integration +import io.micronaut.http.HttpResponse import spock.lang.Ignore +import spock.lang.Specification @Integration @Rollback -class CacheSpec extends GebSpec { +class CacheSpec extends HttpClientSpec implements RedisContainerHelper { - def setup() { - RestBuilder restBuilder = new RestBuilder() - RestResponse response = restBuilder.get("${baseUrl}/test/evict") - response.text == 'evict' + HttpResponse response - response = restBuilder.get("${baseUrl}/test/clearCache?cacheName=message") - response.text == "cleared cache 'message'" + void setup() { + response = get("/test/evict") + response.body() == 'evict' - response = restBuilder.get("${baseUrl}/test/clearLogEntries") - response.text == 'deleted all LogEntry instances' + response = get("/test/clearCache?cacheName=message") + response.body() == "cleared cache 'message'" + + response = get("/test/clearLogEntries") + response.body() == 'deleted all LogEntry instances' } - def cleanup() { - RestBuilder restBuilder = new RestBuilder() - RestResponse response = restBuilder.get("${baseUrl}/test/clearCache?cacheName=message") - response.text == "cleared cache 'message'" + void cleanup() { + response.body() == "cleared cache 'message'" - response = restBuilder.get("${baseUrl}/test/clearLogEntries") - response.text == 'deleted all LogEntry instances' + response = get("/test/clearLogEntries") + response.body() == 'deleted all LogEntry instances' } @Ignore void testCacheAndEvict() { - given: - RestBuilder restBuilder = new RestBuilder() - RestResponse response - when: "check that there are no log entries" - response = restBuilder.get("${baseUrl}/test/logEntryCount") + response = get("/test/logEntryCount") then: - response.text == '0' + response.body() == '0' when: - response = restBuilder.get("${baseUrl}/test/mostRecentLogEntry") + response = get("/test/mostRecentLogEntry") then: - response.text == 'none' + response.body() == 'none' when: "get the index action which should trigger caching" - response = restBuilder.get("${baseUrl}/test/index") + response = get("/test/index") then: - response.text == 'index' + response.body() == 'index' when: - response = restBuilder.get("${baseUrl}/test/logEntryCount") + response = get("/test/logEntryCount") then: - response.text == '1' + response.body() == '1' when: - response = restBuilder.get("${baseUrl}/test/mostRecentLogEntry") + response = get("/test/mostRecentLogEntry", Map) then: - response.json.message == 'Called index() action' + response.body().message == 'Called index() action' - long id = response.json.id - long dateCreated = response.json.dateCreated + long id = response.body().id + long dateCreated = response.body().dateCreated when: "get the index action again, should be cached" - response = restBuilder.get("${baseUrl}/test/index") + response = get("/test/index") then: - response.text == 'index' + response.body() == 'index' when: - response = restBuilder.get("${baseUrl}/test/logEntryCount") + response = get("/test/logEntryCount") then: - response.text == '1' + response.body() == '1' when: - response = restBuilder.get("${baseUrl}/test/mostRecentLogEntry") + response = get("/test/mostRecentLogEntry", Map) then: - response.json.message == 'Called index() action' - response.json.id == id - response.json.dateCreated == dateCreated + response.body().message == 'Called index() action' + response.body().id == id + response.body().dateCreated == dateCreated when: "evict" - response = restBuilder.get("${baseUrl}/test/evict") + response = get("/test/evict") then: - response.text == 'evict' + response.body() == 'evict' when: - response = restBuilder.get("${baseUrl}/test/logEntryCount") + response = get("/test/logEntryCount") then: - response.text == '2' + response.body() == '2' when: - response = restBuilder.get("${baseUrl}/test/mostRecentLogEntry") + response = get("/test/mostRecentLogEntry", Map) then: - response.json.message == 'Called evict() action' - response.json.id == id + 1 - response.json.dateCreated > dateCreated + response.body().message == 'Called evict() action' + response.body().id == id + 1 + response.body().dateCreated > dateCreated when: "save the values to compare" - id++ - dateCreated = response.json.dateCreated + id++ + dateCreated = response.json.dateCreated and: "get the index action again, should not be cached" - response = restBuilder.get("${baseUrl}/test/index") + response = get("/test/index") then: - response.text == 'index' + response.body() == 'index' when: - response = restBuilder.get("${baseUrl}/test/logEntryCount") + response = get("/test/logEntryCount") then: - response.text == '3' + response.body() == '3' when: - response = restBuilder.get("${baseUrl}/test/mostRecentLogEntry") + response = get("/test/mostRecentLogEntry", Map) then: - response.json.message == 'Called index() action' - response.json.id == id + 1 - response.json.dateCreated > dateCreated + response.body().message == 'Called index() action' + response.body().id == id + 1 + response.body().dateCreated > dateCreated } void testParams() { - given: - RestBuilder restBuilder = new RestBuilder() - RestResponse response - when: - response = restBuilder.get("${baseUrl}/test/withParams?foo=baz&bar=123") + response = get("/test/withParams?foo=baz&bar=123") then: - response.text == 'withParams baz 123' + response.body() == 'withParams baz 123' when: - response = restBuilder.get("${baseUrl}/test/withParams?foo=baz2&bar=1234") + response = get("/test/withParams?foo=baz2&bar=1234") then: - response.text == 'withParams baz2 1234' + response.body() == 'withParams baz2 1234' when: - response = restBuilder.get("${baseUrl}/test/withParams?foo=baz&bar=123") + response = get("/test/withParams?foo=baz&bar=123") then: - response.text == 'withParams baz 123' + response.body() == 'withParams baz 123' when: "try again with UrlMappings" - response = restBuilder.get("${baseUrl}/withParams/baz/123") + response = get("/withParams/baz/123") then: - response.text == 'withParams baz 123' + response.body() == 'withParams baz 123' when: - response = restBuilder.get("${baseUrl}/withParams/baz2/1234") + response = get("/withParams/baz2/1234") then: - response.text == 'withParams baz2 1234' + response.body() == 'withParams baz2 1234' when: - response = restBuilder.get("${baseUrl}/withParams/baz/123") + response = get("/withParams/baz/123") then: - response.text == 'withParams baz 123' + response.body() == 'withParams baz 123' } } diff --git a/functional-tests/src/integration-test/groovy/functional/tests/CachingServiceIntegrationSpec.groovy b/functional-tests/src/integration-test/groovy/functional/tests/CachingServiceIntegrationSpec.groovy new file mode 100644 index 0000000..abdcb23 --- /dev/null +++ b/functional-tests/src/integration-test/groovy/functional/tests/CachingServiceIntegrationSpec.groovy @@ -0,0 +1,69 @@ +package functional.tests + + +import functional.tests.helpers.RedisContainerHelper +import grails.plugin.cache.redis.GrailsRedisCacheManager +import grails.testing.mixin.integration.Integration +import org.grails.plugin.cache.GrailsCacheManager +import spock.lang.Specification + +@Integration +class CachingServiceIntegrationSpec extends Specification implements RedisContainerHelper { + + GrailsCacheManager grailsCacheManager + CachingService cachingService + + void cleanup() { + cachingService.resetInvocationCounter() + } + + void "type of cache manager"() { + expect: + grailsCacheManager instanceof GrailsRedisCacheManager + } + + + void "use a cacheable object"() { + expect: + cachingService.invocationCounter == 0 + + when: 'accessing the method first time' + String value = cachingService.data + + then: 'the expected value is returned and accessCount is incremented' + value == 'Hello World!' + cachingService.invocationCounter == 1 + + when: 'accessing the method again' + value = cachingService.data + + then: 'the expected value is returned, but accessCount is not incremented, thus using the cache' + value == 'Hello World!' + cachingService.invocationCounter == 1 + } + + + void "use cacheable object with key"() { + expect: 'That getting key-1 will yield null' + !cachingService.getData('key-1') + + when: 'putting a value into the cache' + String value = cachingService.getData('key-1', 'value-1') + + then: 'the value is returned' + value == '** value-1 **' + + when: 'getting the key' + value = cachingService.getData('key-1') + + then: 'the value is still in the cache' + value == '** value-1 **' + + when: 'clearing the cache' + cachingService.clear() + + then: 'getting the key will yield null' + !cachingService.getData('key-1') + } + +} diff --git a/functional-tests/src/integration-test/groovy/functional/tests/CachingServiceSpec.groovy b/functional-tests/src/integration-test/groovy/functional/tests/CachingServiceSpec.groovy index a4a0640..098dd06 100644 --- a/functional-tests/src/integration-test/groovy/functional/tests/CachingServiceSpec.groovy +++ b/functional-tests/src/integration-test/groovy/functional/tests/CachingServiceSpec.groovy @@ -1,108 +1,111 @@ package functional.tests -import geb.spock.GebSpec -import grails.plugins.rest.client.RestBuilder -import grails.plugins.rest.client.RestResponse -import grails.test.mixin.integration.Integration +import functional.tests.helpers.HttpClientSpec +import functional.tests.helpers.RedisContainerHelper +import grails.testing.mixin.integration.Integration +import io.micronaut.http.HttpResponse +import io.micronaut.http.HttpStatus +import spock.lang.Specification @Integration -class CachingServiceSpec extends GebSpec { +class CachingServiceSpec extends HttpClientSpec implements RedisContainerHelper { - RestBuilder restBuilder - RestResponse response - def setup() { - restBuilder = new RestBuilder() - response = restBuilder.get("${baseUrl}/cachingService/clear") + HttpResponse response + + void setup() { + response = this.blockingClient.exchange("/cachingService/clear") } void testBasicCachingService() { when: - response = restBuilder.get("${baseUrl}/cachingService/cachingServiceInvocationCount") + response = get("/cachingService/cachingServiceInvocationCount") + then: - response.status == 200 - response.text.contains('Basic Caching Service Invocation Count Is 0') + response.status() == HttpStatus.OK + response.body().contains('Basic Caching Service Invocation Count Is 0') when: - response = restBuilder.get("${baseUrl}/cachingService/cachingService") + response = get('/cachingService/cachingService') then: - response.status == 200 - response.text.contains("Value From Service Is 'Hello World!'") + response.status() == HttpStatus.OK + response.body().contains("Value From Service Is 'Hello World!'") when: - response = restBuilder.get("${baseUrl}/cachingService/cachingServiceInvocationCount") + response = get('/cachingService/cachingServiceInvocationCount') then: - response.status == 200 - response.text.contains("Basic Caching Service Invocation Count Is 1") + response.status() == HttpStatus.OK + response.body().contains("Basic Caching Service Invocation Count Is 1") when: - response = restBuilder.get("${baseUrl}/cachingService/cachingService") + response = get('/cachingService/cachingService') then: - response.status == 200 - response.text.contains("Value From Service Is 'Hello World!'") + response.status() == HttpStatus.OK + response.body().contains("Value From Service Is 'Hello World!'") when: - response = restBuilder.get("${baseUrl}/cachingService/cachingServiceInvocationCount") + response = get('/cachingService/cachingServiceInvocationCount') then: - response.status == 200 - response.text.contains("Basic Caching Service Invocation Count Is 1") + response.status() == HttpStatus.OK + response.body().contains("Basic Caching Service Invocation Count Is 1") } void testBasicCachePutService() { when: - response = restBuilder.get("${baseUrl}/cachingService/cacheGet?key=band") + response = get('/cachingService/cacheGet?key=band') then: - response.status == 200 - response.text == 'Result: null' + response.status() == HttpStatus.OK + response.body() == 'Result: null' when: - response = restBuilder.get("${baseUrl}/cachingService/cachePut?key=band&value=Thin Lizzy") + response = get('/cachingService/cachePut?key=band&value=Thin+Lizzy') then: - response.status == 200 - response.text == 'Result: ** Thin Lizzy **' + response.status() == HttpStatus.OK + response.body() == 'Result: ** Thin Lizzy **' when: - response = restBuilder.get("${baseUrl}/cachingService/cacheGet?key=band") + response = get('/cachingService/cacheGet?key=band') then: - response.status == 200 - response.text == 'Result: ** Thin Lizzy **' + response.status() == HttpStatus.OK + response.body() == 'Result: ** Thin Lizzy **' when: - response = restBuilder.get("${baseUrl}/cachingService/cacheGet?key=singer") + response = get('/cachingService/cacheGet?key=singer') then: - response.status == 200 - response.text == 'Result: null' + response.status() == HttpStatus.OK + response.body() == 'Result: null' when: - response = restBuilder.get("${baseUrl}/cachingService/cachePut?key=singer&value=Phil Lynott") + response = get('/cachingService/cachePut?key=singer&value=Phil+Lynott') then: - response.status == 200 - response.text == 'Result: ** Phil Lynott **' + response.status() == HttpStatus.OK + response.body() == 'Result: ** Phil Lynott **' when: - response = restBuilder.get("${baseUrl}/cachingService/cacheGet?key=singer") + response = get('/cachingService/cacheGet?key=singer') then: - response.status == 200 - response.text == 'Result: ** Phil Lynott **' + response.status() == HttpStatus.OK + response.body() == 'Result: ** Phil Lynott **' when: - response = restBuilder.get("${baseUrl}/cachingService/cachePut?key=singer&value=John Sykes") + response = get('/cachingService/cachePut?key=singer&value=John+Sykes') then: - response.status == 200 - response.text == 'Result: ** John Sykes **' + response.status() == HttpStatus.OK + response.body() == 'Result: ** John Sykes **' when: - response = restBuilder.get("${baseUrl}/cachingService/cacheGet?key=singer") + response = get('/cachingService/cacheGet?key=singer') then: - response.status == 200 - response.text == 'Result: ** John Sykes **' + response.status() == HttpStatus.OK + response.body() == 'Result: ** John Sykes **' when: - response = restBuilder.get("${baseUrl}/cachingService/cacheGet?key=band") + response = get('/cachingService/cacheGet?key=band') then: - response.status == 200 - response.text == 'Result: ** Thin Lizzy **' + response.status() == HttpStatus.OK + response.body() == 'Result: ** Thin Lizzy **' } -} + +} \ No newline at end of file diff --git a/functional-tests/src/integration-test/groovy/functional/tests/SimpleCacheIntegrationSpec.groovy b/functional-tests/src/integration-test/groovy/functional/tests/SimpleCacheIntegrationSpec.groovy new file mode 100644 index 0000000..0c5fd43 --- /dev/null +++ b/functional-tests/src/integration-test/groovy/functional/tests/SimpleCacheIntegrationSpec.groovy @@ -0,0 +1,34 @@ +package functional.tests + +import functional.tests.helpers.RedisContainerHelper +import grails.testing.mixin.integration.Integration +import org.grails.plugin.cache.GrailsCacheManager +import spock.lang.Specification + +@Integration +class SimpleCacheIntegrationSpec extends Specification implements RedisContainerHelper { + + GrailsCacheManager grailsCacheManager + + void "get cache from cache manager"() { + expect: + grailsCacheManager.getCache('dummy') + } + + void "put element directly into cache"() { + given: + def cache = grailsCacheManager.getCache('dummy') + + expect: 'the cache is empty' + !cache.get('first') + + when: + cache.put('first', '#1') + + then: + cache.get('first', String) == '#1' + } + +} + + diff --git a/functional-tests/src/integration-test/groovy/functional/tests/TaglibCachingSpec.groovy b/functional-tests/src/integration-test/groovy/functional/tests/TaglibCachingSpec.groovy index c530c1c..6ee45be 100644 --- a/functional-tests/src/integration-test/groovy/functional/tests/TaglibCachingSpec.groovy +++ b/functional-tests/src/integration-test/groovy/functional/tests/TaglibCachingSpec.groovy @@ -1,152 +1,141 @@ package functional.tests -import geb.spock.GebSpec -import grails.plugins.rest.client.RestBuilder -import grails.plugins.rest.client.RestResponse -import grails.test.mixin.integration.Integration +import functional.tests.helpers.HttpClientSpec +import functional.tests.helpers.RedisContainerHelper +import grails.testing.mixin.integration.Integration +import io.micronaut.http.HttpResponse +import io.micronaut.http.HttpStatus @Integration -class TaglibCachingSpec extends GebSpec{ - RestBuilder restBuilder - RestResponse response - - def setup() { - restBuilder = new RestBuilder() - response = restBuilder.get("${baseUrl}/taglib/clearBlocksCache") - println response.text - response = restBuilder.get("${baseUrl}/taglib/clearTemplatesCache") - println response.text +class TaglibCachingSpec extends HttpClientSpec implements RedisContainerHelper { + HttpResponse response + + void setup() { + response = get("/taglib/clearBlocksCache") + println response.body() + response = get("/taglib/clearTemplatesCache") + println response.body() } void testBlockTag() { - given: - RestBuilder restBuilder = new RestBuilder() - RestResponse response - when: - response = restBuilder.get("${baseUrl}/taglib/blockCache?counter=5") + response = get("/taglib/blockCache?counter=5") then: - response.status == 200 - response.text.contains('First block counter 6') - response.text.contains('Second block counter 7') - response.text.contains('Third block counter 8') + response.status() == HttpStatus.OK + response.body().contains('First block counter 6') + response.body().contains('Second block counter 7') + response.body().contains('Third block counter 8') when: - response = restBuilder.get("${baseUrl}/taglib/blockCache?counter=42") + response = get("/taglib/blockCache?counter=42") then: - response.status == 200 - response.text.contains('First block counter 6') - response.text.contains('Second block counter 7') - response.text.contains('Third block counter 8') + response.status() == HttpStatus.OK + response.body().contains('First block counter 6') + response.body().contains('Second block counter 7') + response.body().contains('Third block counter 8') } void testClearingBlocksCache() { - given: - RestBuilder restBuilder = new RestBuilder() - RestResponse response when: - response = restBuilder.get("${baseUrl}/taglib/clearBlocksCache") + response = get("/taglib/clearBlocksCache") then: - response.status == 200 - response.text.contains('cleared blocks cache') + response.status() == HttpStatus.OK + response.body().contains('cleared blocks cache') when: - response = restBuilder.get("${baseUrl}/taglib/blockCache?counter=100") + response = get("/taglib/blockCache?counter=100") then: - response.status == 200 - response.text.contains('First block counter 101') - response.text.contains('Second block counter 102') - response.text.contains('Third block counter 103') + response.status() == HttpStatus.OK + response.body().contains('First block counter 101') + response.body().contains('Second block counter 102') + response.body().contains('Third block counter 103') when: - response = restBuilder.get("${baseUrl}/taglib/blockCache?counter=42") + response = get("/taglib/blockCache?counter=42") then: - response.status == 200 - response.text.contains('First block counter 101') - response.text.contains('Second block counter 102') - response.text.contains('Third block counter 103') + response.status() == HttpStatus.OK + response.body().contains('First block counter 101') + response.body().contains('Second block counter 102') + response.body().contains('Third block counter 103') when: - response = restBuilder.get("${baseUrl}/taglib/clearBlocksCache") + response = get("/taglib/clearBlocksCache") then: - response.status == 200 - response.text.contains('cleared blocks cache') + response.status() == HttpStatus.OK + response.body().contains('cleared blocks cache') when: - response = restBuilder.get("${baseUrl}/taglib/blockCache?counter=50") + response = get("/taglib/blockCache?counter=50") then: - response.status == 200 - response.text.contains('First block counter 51') - response.text.contains('Second block counter 52') - response.text.contains('Third block counter 53') + response.status() == HttpStatus.OK + response.body().contains('First block counter 51') + response.body().contains('Second block counter 52') + response.body().contains('Third block counter 53') when: - response = restBuilder.get("${baseUrl}/taglib/blockCache?counter=150") + response = get("/taglib/blockCache?counter=150") then: - response.status == 200 - response.text.contains('First block counter 51') - response.text.contains('Second block counter 52') - response.text.contains('Third block counter 53') + response.status() == HttpStatus.OK + response.body().contains('First block counter 51') + response.body().contains('Second block counter 52') + response.body().contains('Third block counter 53') } void testRenderTag() { - given: - RestBuilder restBuilder = new RestBuilder() - RestResponse response when: - response = restBuilder.get("${baseUrl}/taglib/clearTemplatesCache") + response = get("/taglib/clearTemplatesCache") then: - response.status == 200 - response.text.contains('cleared templates cache') + response.status() == HttpStatus.OK + response.body().contains('cleared templates cache') when: - response = restBuilder.get("${baseUrl}/taglib/renderTag?counter=1") + response = get("/taglib/renderTag?counter=1") then: - response.status == 200 + response.status() == HttpStatus.OK - response.text.contains('First invocation: Counter value: 1') - response.text.contains('Second invocation: Counter value: 1') - response.text.contains('Third invocation: Counter value: 3') - response.text.contains('Fourth invocation: Counter value: 3') - response.text.contains('Fifth invocation: Counter value: 1') + response.body().contains('First invocation: Counter value: 1') + response.body().contains('Second invocation: Counter value: 1') + response.body().contains('Third invocation: Counter value: 3') + response.body().contains('Fourth invocation: Counter value: 3') + response.body().contains('Fifth invocation: Counter value: 1') when: - response = restBuilder.get("${baseUrl}/taglib/renderTag?counter=5") + response = get("/taglib/renderTag?counter=5") then: - response.status == 200 + response.status() == HttpStatus.OK - response.text.contains('First invocation: Counter value: 1') - response.text.contains('Second invocation: Counter value: 1') - response.text.contains('Third invocation: Counter value: 3') - response.text.contains('Fourth invocation: Counter value: 3') - response.text.contains('Fifth invocation: Counter value: 1') + response.body().contains('First invocation: Counter value: 1') + response.body().contains('Second invocation: Counter value: 1') + response.body().contains('Third invocation: Counter value: 3') + response.body().contains('Fourth invocation: Counter value: 3') + response.body().contains('Fifth invocation: Counter value: 1') when: - response = restBuilder.get("${baseUrl}/taglib/clearTemplatesCache") + response = get("/taglib/clearTemplatesCache") then: - response.status == 200 - response.text.contains('cleared templates cache') + response.status() == HttpStatus.OK + response.body().contains('cleared templates cache') when: - response = restBuilder.get("${baseUrl}/taglib/renderTag?counter=5") + response = get("/taglib/renderTag?counter=5") then: - response.status == 200 + response.status() == HttpStatus.OK - response.text.contains('First invocation: Counter value: 5') - response.text.contains('Second invocation: Counter value: 5') - response.text.contains('Third invocation: Counter value: 7') - response.text.contains('Fourth invocation: Counter value: 7') - response.text.contains('Fifth invocation: Counter value: 5') + response.body().contains('First invocation: Counter value: 5') + response.body().contains('Second invocation: Counter value: 5') + response.body().contains('Third invocation: Counter value: 7') + response.body().contains('Fourth invocation: Counter value: 7') + response.body().contains('Fifth invocation: Counter value: 5') when: - response = restBuilder.get("${baseUrl}/taglib/renderTag?counter=1") + response = get("/taglib/renderTag?counter=1") then: - response.status == 200 + response.status() == HttpStatus.OK - response.text.contains('First invocation: Counter value: 5') - response.text.contains('Second invocation: Counter value: 5') - response.text.contains('Third invocation: Counter value: 7') - response.text.contains('Fourth invocation: Counter value: 7') - response.text.contains('Fifth invocation: Counter value: 5') + response.body().contains('First invocation: Counter value: 5') + response.body().contains('Second invocation: Counter value: 5') + response.body().contains('Third invocation: Counter value: 7') + response.body().contains('Fourth invocation: Counter value: 7') + response.body().contains('Fifth invocation: Counter value: 5') } } diff --git a/functional-tests/src/integration-test/groovy/functional/tests/helpers/HttpClientSpec.groovy b/functional-tests/src/integration-test/groovy/functional/tests/helpers/HttpClientSpec.groovy new file mode 100644 index 0000000..0dc3dfb --- /dev/null +++ b/functional-tests/src/integration-test/groovy/functional/tests/helpers/HttpClientSpec.groovy @@ -0,0 +1,26 @@ +package functional.tests.helpers + +import io.micronaut.http.HttpResponse +import io.micronaut.http.client.BlockingHttpClient +import io.micronaut.http.client.HttpClient +import org.junit.Before +import spock.lang.Shared +import spock.lang.Specification + +abstract class HttpClientSpec extends Specification { + + @Shared + BlockingHttpClient blockingClient + + void setup() { + if (!blockingClient) { + HttpClient client = HttpClient.create(new URL("http://localhost:${serverPort}")) + blockingClient = client.toBlocking() + } + } + + def HttpResponse get(String uri, Class type = String) { + this.blockingClient.exchange(uri, type) + } + +} \ No newline at end of file diff --git a/functional-tests/src/integration-test/groovy/functional/tests/helpers/RedisContainerHelper.groovy b/functional-tests/src/integration-test/groovy/functional/tests/helpers/RedisContainerHelper.groovy new file mode 100644 index 0000000..2d6038b --- /dev/null +++ b/functional-tests/src/integration-test/groovy/functional/tests/helpers/RedisContainerHelper.groovy @@ -0,0 +1,20 @@ +package functional.tests.helpers + +import groovy.transform.SelfType +import org.testcontainers.containers.GenericContainer +import org.testcontainers.utility.DockerImageName +import spock.lang.Specification + +@SelfType(Specification) +trait RedisContainerHelper { + + static { + new GenericContainer(DockerImageName.parse("redis:8-alpine")).tap { + addExposedPort(6379) + start() + System.setProperty("grails.cache.redis.host", host) + System.setProperty("grails.cache.redis.port", getMappedPort(6379).toString()) + } + } + +} diff --git a/gradle.properties b/gradle.properties index 5ef1562..d90795d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,11 @@ -grailsVersion=3.1.8 -gradleWrapperVersion=2.13 +projectVersion=6.0.0-SNAPSHOT +grailsVersion=6.2.3 +javaVersion=17 +asciidoctorGradlePluginVersion=4.0.4 + +grailsGradlePluginVersion=6.2.4 +version=0.1 +org.gradle.caching=true +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx1024M diff --git a/gradle/buildsrc.libs.versions.toml b/gradle/buildsrc.libs.versions.toml new file mode 100644 index 0000000..924ced8 --- /dev/null +++ b/gradle/buildsrc.libs.versions.toml @@ -0,0 +1,9 @@ +[versions] +grails-gradle-plugin = '6.2.0' +nexus-publish-gradle-plugin = '1.3.0' +asciidoctor-gradle-plugin = '4.0.2' + +[libraries] +grails-gradle-plugin = { module = 'org.grails:grails-gradle-plugin', version.ref = 'grails-gradle-plugin' } +nexus-publish-gradle-plugin = { module = 'io.github.gradle-nexus:publish-plugin', version.ref = 'nexus-publish-gradle-plugin' } +asciidoctor-gradle-plugin = {module = 'org.asciidoctor.jvm.convert:org.asciidoctor.jvm.convert.gradle.plugin', version.ref = 'asciidoctor-gradle-plugin'} \ No newline at end of file diff --git a/gradle/docs-config.gradle b/gradle/docs-config.gradle new file mode 100644 index 0000000..0752285 --- /dev/null +++ b/gradle/docs-config.gradle @@ -0,0 +1,67 @@ +import org.asciidoctor.gradle.jvm.AsciidoctorTask + +apply plugin: 'org.asciidoctor.jvm.convert' + +tasks.withType(Groovydoc).configureEach { + access = GroovydocAccess.PROTECTED + processScripts = false + includeMainForScripts = false + includeAuthor = false + destinationDir = layout.buildDirectory.dir('docs/api').get().asFile +} + +tasks.withType(AsciidoctorTask).configureEach { + baseDir = layout.projectDirectory.dir('src/docs') + sourceDir = layout.projectDirectory.dir('src/docs') + outputDir = layout.buildDirectory.dir('docs/manual') + sources { + include 'index.adoc' + } + jvm { + jvmArgs += [ + '--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED', + '--add-opens', 'java.base/java.io=ALL-UNNAMED' + ] + } + attributes = [ + copyright : 'Apache License, Version 2.0', + docinfo1 : 'true', + doctype : 'book', + encoding : 'utf-8', + icons : 'font', + id : "$rootProject.name:$projectVersion", + idprefix : '', + idseparator : '-', + lang : 'en', + linkattrs : true, + numbered : '', + producer : 'Asciidoctor', + revnumber : projectVersion, + setanchors : true, + 'source-highlighter' : 'prettify', + toc : 'left', + toc2 : '', + toclevels : '2', + projectVersion : projectVersion + ] +} + +tasks.register('docs') { + group = 'documentation' + def outputFile = layout.buildDirectory.file('docs/index.html') + inputs.files(tasks.named('asciidoctor'), tasks.named('groovydoc')) + outputs.file(outputFile) + doLast { + File redirectPage = outputFile.get().asFile + redirectPage.delete() + redirectPage.text = ''' + + + Redirecting... + + + + + '''.stripIndent(8) + } +} \ No newline at end of file diff --git a/gradle/grails-plugin-config.gradle b/gradle/grails-plugin-config.gradle new file mode 100644 index 0000000..e516cd9 --- /dev/null +++ b/gradle/grails-plugin-config.gradle @@ -0,0 +1,8 @@ +tasks.named('bootJar') { + enabled = false // Plugins should not create a bootJar +} +tasks.named('jar', Jar) { + enabled = true // Enable the jar task again, as the bootJar task has been disabled + archiveClassifier = '' // Remove '-plain' suffix from jar file name + exclude('_testemails', 'messages*.properties') +} \ No newline at end of file diff --git a/gradle/java-config.gradle b/gradle/java-config.gradle new file mode 100644 index 0000000..f536319 --- /dev/null +++ b/gradle/java-config.gradle @@ -0,0 +1,5 @@ +java { + sourceCompatibility = JavaVersion.VERSION_11 + withSourcesJar() + withJavadocJar() +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..d172f9b --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,29 @@ +[versions] +grails = '6.2.0' +grails-testing-support = '3.2.1' +groovy = '3.0.21' +cache = '5.0.1' +spring-data-redis = '2.7.18' +jedis = '5.2.0' +bytebudy = '1.14.18' +slf4j = '1.7.36' +spring = '5.3.34' +springboot = '2.7.18' +spock = '2.3-groovy-3.0' + +[libraries] +grails-core = { module = 'org.grails:grails-core', version.ref = 'grails' } +grails-cache = { module = 'org.grails.plugins:cache', version.ref = 'cache' } +spring-data-redis = { module = 'org.springframework.data:spring-data-redis', version.ref = 'spring-data-redis' } +jedis-client = { module = 'redis.clients:jedis', version.ref = 'jedis' } +bytebudy = { module = 'net.bytebuddy:byte-buddy', version.ref = 'bytebudy' } +groovy-core = { module = 'org.codehaus.groovy:groovy', version.ref = 'groovy' } +slf4j-nop = { module = 'org.slf4j:slf4j-nop', version.ref = 'slf4j' } +spring-beans = { module = 'org.springframework:spring-beans', version.ref = 'spring' } +spring-context = { module = 'org.springframework:spring-context', version.ref = 'spring' } +spring-context-support = { module = 'org.springframework:spring-context-support', version.ref = 'spring' } +spring-web = { module = 'org.springframework:spring-web', version.ref = 'spring' } +springboot-autoconfigure = { module = 'org.springframework.boot:spring-boot-autoconfigure', version.ref = 'springboot' } +springboot-starter-tomcat = { module = 'org.springframework.boot:spring-boot-starter-tomcat', version.ref = 'springboot' } +spock-core = { module = 'org.spockframework:spock-core', version.ref = 'spock' } +grails-testing-support-core = { module = 'org.grails:grails-testing-support', version.ref = 'grails-testing-support' } diff --git a/gradle/publishing.gradle b/gradle/publishing.gradle new file mode 100644 index 0000000..71cdfee --- /dev/null +++ b/gradle/publishing.gradle @@ -0,0 +1,132 @@ +import io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository + +ext.set('signing.keyId', findProperty('signing.keyId') ?: System.getenv('SIGNING_KEY')) +ext.set('signing.password', findProperty('signing.password') ?: System.getenv('SIGNING_PASSPHRASE')) + +def javaComponent = components.named('java') +publishing { + publications { + register('grailsMailPlugin', MavenPublication) { + from javaComponent.get() + versionMapping { + usage('java-api') { fromResolutionOf('runtimeClasspath') } + usage('java-runtime') { fromResolutionResult() } + } + pom { + name = 'Grails Cache Redis plugin' + description = 'Provides setup for Redis caching' + url = 'https://github.com/grails/grails-cache-redis' + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'https://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'graemerocher' + name = 'Graeme Rocher' + email = 'graeme.rocher@gmail.com' + } + developer { + id = 'donbeave' + name = 'Alexey Zhokhov' + email = 'alexey@zhokhov.com' + } + developer { + id = 'iamedu' + name = 'Eduardo Díaz' + email = 'iamedu@gmail.com' + } + developer { + id = 'jeff-blaisdell' + name = 'Jeff Blaisdell' + email = 'jeff.blaisdell@gmail.com' + } + developer { + id = 'jeffscottbrown' + name = 'Jeff Scott Brown' + email = 'brownj@ociweb.com' + } + developer { + id = 'johnSpiekerpoint' + name = 'John Spiekerpoint' + email = 'john@spiekerpoint.com' + } + developer { + id = 'erik-h' + name = 'Erik Haugrud' + email = 'erik-h@users.noreply.github.com' + } + developer { + id = 'ColinHarrington' + name = 'Colin Harrington' + email = 'colin.harrington@gmail.com' + } + developer { + id = 'sbglasius' + name = 'Søren Berg Glasius' + email = 'soeren@glasius.dk' + } + + + } + scm { + connection = 'scm:git:git://github.com/grails/grails-cache-redis.git' + developerConnection = 'scm:git:ssh://github.com:grails/grails-cache-redis.git' + url = 'https://github.com/grails/grails-cache-redis' + } + } + // dependency management shouldn't be included + pom.withXml { + def root = it.asElement() + root.getElementsByTagName('dependencyManagement').each { root.removeChild(it) } + } + } + } + + if (isSnapshot) { + repositories { + maven { + credentials { + username = findProperty('artifactoryPublishUsername') ?: '' + password = findProperty('artifactoryPublishPassword') ?: '' + } + url = uri('https://repo.grails.org/grails/plugins3-snapshots-local') + } + } + } +} + +def mavenPublication = extensions.findByType(PublishingExtension).publications.named('grailsMailPlugin') +tasks.withType(Sign).configureEach { + onlyIf { isReleaseVersion } +} +afterEvaluate { + signing { + required = { isReleaseVersion } + sign(mavenPublication.get()) + } +} + +if (isReleaseVersion) { + nexusPublishing { + String sonatypeUsername = findProperty('sonatypeUsername') ?: '' + String sonatypePassword = findProperty('sonatypePassword') ?: '' + String sonatypeStagingProfileId = findProperty('sonatypeStagingProfileId') ?: '' + repositories { + sonatype { + nexusUrl = uri('https://s01.oss.sonatype.org/service/local/') + username = sonatypeUsername + password = sonatypePassword + stagingProfileId = sonatypeStagingProfileId + } + } + } +} + + +//do not generate extra load on Nexus with new staging repository if signing fails +tasks.withType(InitializeNexusStagingRepository).configureEach { + shouldRunAfter = tasks.withType(Sign) +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ca78035..7454180 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 1de8229..3994438 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 10 10:02:09 CDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip diff --git a/gradlew b/gradlew index 27309d9..1b6c787 100755 --- a/gradlew +++ b/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env bash +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for 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/master/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_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +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="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum -warn ( ) { +warn () { echo "$*" -} +} >&2 -die ( ) { +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 + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + 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 @@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + 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. Please set the JAVA_HOME variable in your environment to match the @@ -89,76 +140,95 @@ location of your Java installation." 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*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + 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" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; 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 # 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=$((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 -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# 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. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# 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 832fdb6..107acd3 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@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 @@ -13,15 +29,18 @@ 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= +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 init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,34 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - :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 %CMD_LINE_ARGS% +"%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 diff --git a/grails-app/conf/logback.groovy b/grails-app/conf/logback.groovy deleted file mode 100644 index 2f7c41c..0000000 --- a/grails-app/conf/logback.groovy +++ /dev/null @@ -1,23 +0,0 @@ -import grails.util.BuildSettings -import grails.util.Environment - -// See http://logback.qos.ch/manual/groovy.html for details on configuration -appender('STDOUT', ConsoleAppender) { - encoder(PatternLayoutEncoder) { - pattern = "%level %logger - %msg%n" - } -} - -root(ERROR, ['STDOUT']) - -def targetDir = BuildSettings.TARGET_DIR -if (Environment.isDevelopmentMode() && targetDir) { - appender("FULL_STACKTRACE", FileAppender) { - file = "${targetDir}/stacktrace.log" - append = true - encoder(PatternLayoutEncoder) { - pattern = "%level %logger - %msg%n" - } - } - logger("StackTrace", ERROR, ['FULL_STACKTRACE'], false) -} diff --git a/grails-app/conf/logback.xml b/grails-app/conf/logback.xml new file mode 100644 index 0000000..70b1484 --- /dev/null +++ b/grails-app/conf/logback.xml @@ -0,0 +1,19 @@ + + + + + + + + true + + UTF-8 + %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex + + + + + + + + diff --git a/settings.gradle b/settings.gradle index 52e11d3..213ff21 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,25 @@ +plugins { + id 'com.gradle.develocity' version '3.17.1' + id 'com.gradle.common-custom-user-data-gradle-plugin' version '2.0' +} + +def isCI = System.getenv('CI') == 'true' + +develocity { + server = 'https://ge.grails.org' + buildScan { + publishing.onlyIf { isCI } + uploadInBackground = !isCI + } +} + +buildCache { + local { enabled = !isCI } + remote(develocity.buildCache) { + enabled = true + push = isCI && System.getenv('DEVELOCITY_ACCESS_KEY') + } +} + rootProject.name = "cache-redis" include 'functional-tests' \ No newline at end of file diff --git a/src/docs/asciidoc/introduction/changeLog.adoc b/src/docs/asciidoc/introduction/changeLog.adoc deleted file mode 100644 index 9755a43..0000000 --- a/src/docs/asciidoc/introduction/changeLog.adoc +++ /dev/null @@ -1,6 +0,0 @@ - -=== Version 1.0.0 - July 4, 2012 - - -=== Version 1.0.0.M2 - May 12, 2012 - diff --git a/src/docs/asciidoc/usage.adoc b/src/docs/asciidoc/usage.adoc deleted file mode 100644 index 2746dd5..0000000 --- a/src/docs/asciidoc/usage.adoc +++ /dev/null @@ -1,2 +0,0 @@ -Although this plugin uses a different backing store than the core plugin, its usage and configuration are the same. You annotate service methods, controller action methods, and taglib closures with the three caching annotations, and configure caches in `Config.groovy` and/or `\*CacheConfig.groovy` artifacts in `grails-app/conf`. See the http://grails-plugins.github.com/grails-cache/[core plugin docs] for general usage information. - diff --git a/src/docs/configuration.adoc b/src/docs/configuration.adoc new file mode 100644 index 0000000..389f48c --- /dev/null +++ b/src/docs/configuration.adoc @@ -0,0 +1,89 @@ +The following configurations are available: + +All configuration values are prefixed with `grails.cache.redis` +|=== +|Key |Default | Type |Description + +|`enabled` +|`true` +|`boolean` +|Disables or enables the Redis cache implementation (aka. initiates the needed services) + +|`database` +|`true` +|`integer` +|Redis database to use + +|`usePool` +|`true` +|`boolean` +|Use the Redis connection pool + +|`hostName` +|`localhost` +|`String` +|Server name to connect to + +|`port` +|`6379` +|`integer` +|Server port to connect to + +|`username` +|(not set) +|`String` +|Server username (only if required) + +|`password` +|(not set) +|`String` +|Server password (only if required) + +|`timeout` +|`2000` +|`integer` +|Connection timeout + +|`ttl` +|`0` (never expires) +|`integer` +|All caches timeout in seconds + +|`keySerializer` +|(not set) +|`String` +|Name of Key Serializer bean. + +|`hashKeySerializerBean` +|(not set) +|`String` +|Name of Hash Key Serializer bean. + +|`usePrefix` +|`false` +|`boolean` +|Use key prefix and delimiter + + +|`cachePrefixDelimiter` +|`::` +|`String` +|Key prefix delimiter (only used if `usePrefix` is set to `true`) + +|`prefix` +| +|`String` +|Key prefix (only used if `usePrefix` is set to `true`) + +|=== + +*Note:* There is currently no way of setting each cache configuration individually. + +=== Advanced configuration + +The standard configuration will use `org.springframework.data.redis.connection.RedisStandaloneConfiguration` and will connect to a single server. This configuration is instanticated as a the `grailsCacheRedisConfiguration` bean. If more advance configuration is needed, consider using `org.springframework.data.redis.connection.RedisClusterConfiguration` or `org.springframework.data.redis.connection.RedisSentinelConfiguration` instead. + +This should be archiveable by adding: + +---- +grailsCacheRedisConfiguration(RedisClusterConfiguration,) \ No newline at end of file diff --git a/src/docs/asciidoc/index.adoc b/src/docs/index.adoc similarity index 80% rename from src/docs/asciidoc/index.adoc rename to src/docs/index.adoc index 0d1e604..1a21a1f 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/index.adoc @@ -18,8 +18,13 @@ include::introduction/changeLog.adoc[] include::usage.adoc[] +[[configuration]] +== Configuration + +include::configuration.adoc[] + [[dsl]] -=== Cache DSL +== Cache DSL include::usage/dsl.adoc[] diff --git a/src/docs/asciidoc/introduction.adoc b/src/docs/introduction.adoc similarity index 100% rename from src/docs/asciidoc/introduction.adoc rename to src/docs/introduction.adoc diff --git a/src/docs/introduction/changeLog.adoc b/src/docs/introduction/changeLog.adoc new file mode 100644 index 0000000..488e799 --- /dev/null +++ b/src/docs/introduction/changeLog.adoc @@ -0,0 +1,12 @@ + +=== Version 1.0.0 - July 4, 2012 + + +=== Version 1.0.0.M2 - May 12, 2012 + +=== Version 6.0.0 - June 2, 2025 + +* Upgraded to Grails 6.2.x +* Removed `JedisShardInfo` in plugin descriptor in favor of `RedisStandaloneConfiguration` +* Updated documentation + diff --git a/src/docs/usage.adoc b/src/docs/usage.adoc new file mode 100644 index 0000000..f24215c --- /dev/null +++ b/src/docs/usage.adoc @@ -0,0 +1,4 @@ +Although this plugin uses a different backing store than the core plugin, its usage and configuration are the same. You annotate service methods, controller action methods, and taglib closures with the three caching annotations. See the http://grails-plugins.github.com/grails-cache/[core plugin docs] for general usage information. + + + diff --git a/src/docs/asciidoc/usage/dsl.adoc b/src/docs/usage/dsl.adoc similarity index 100% rename from src/docs/asciidoc/usage/dsl.adoc rename to src/docs/usage/dsl.adoc diff --git a/src/integration-test/groovy/grails/plugin/cache/ConfigLoaderTests.groovy b/src/integration-test/groovy/grails/plugin/cache/ConfigLoaderTests.groovy deleted file mode 100644 index 4bbaa45..0000000 --- a/src/integration-test/groovy/grails/plugin/cache/ConfigLoaderTests.groovy +++ /dev/null @@ -1,119 +0,0 @@ -/* Copyright 2012 SpringSource. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package grails.plugin.cache - -import grails.test.mixin.TestMixin -import grails.test.mixin.integration.IntegrationTestMixin - -import static org.junit.Assert.* - -/** - * From the core plugin to ensure things work the same way in this plugin. - * - * @author Burt Beckwith - */ -@TestMixin(IntegrationTestMixin) -class ConfigLoaderTests { - - def grailsApplication - def grailsCacheConfigLoader - def grailsCacheManager - - void testConfigClasses() { - def configClasses = grailsApplication.cacheConfigClasses - assertEquals 2, configClasses.length - assertTrue configClasses.clazz.name.contains('DefaultCacheConfig') - assertTrue configClasses.clazz.name.contains('TestCacheConfig') - } - - void testLoadConfigs() { - - grailsCacheConfigLoader.reload grailsApplication.mainContext - - assertEquals(['basic', 'fromConfigGroovy1', 'fromConfigGroovy2', - 'grailsBlocksCache', 'grailsTemplatesCache'], - grailsCacheManager.cacheNames.sort()) - - // simulate editing Config.groovy - grailsApplication.config.grails.cache.config = { - cache { - name 'fromConfigGroovy1' - } - cache { - name 'fromConfigGroovy_new' - } - } - - grailsCacheConfigLoader.reload grailsApplication.mainContext - - assertEquals(['basic', 'fromConfigGroovy1', 'fromConfigGroovy_new', - 'grailsBlocksCache', 'grailsTemplatesCache'], - grailsCacheManager.cacheNames.sort()) - } - - void testOrder() { - - grailsCacheConfigLoader.reload grailsApplication.mainContext - - assertEquals(['basic', 'fromConfigGroovy1', 'fromConfigGroovy2', - 'grailsBlocksCache', 'grailsTemplatesCache'], - grailsCacheManager.cacheNames.sort()) - - // simulate editing Config.groovy - grailsApplication.config.grails.cache.config = { - cache { - name 'fromConfigGroovy1' - } - cache { - name 'fromConfigGroovy_new2' - } - } - - grailsCacheConfigLoader.reload grailsApplication.mainContext - - assertEquals(['basic', 'fromConfigGroovy1', 'fromConfigGroovy_new2', - 'grailsBlocksCache', 'grailsTemplatesCache'], - grailsCacheManager.cacheNames.sort()) - } - - public void setUp() { - reset() - } - - public void tearDown() { - reset() - } - - private void clearCaches() { - for (String name in grailsCacheManager.cacheNames) { - assertTrue grailsCacheManager.destroyCache(name) - } - } - - private void reset() { - - clearCaches() - - grailsApplication.config.grails.cache.config = { - cache { - name 'fromConfigGroovy1' - } - cache { - name 'fromConfigGroovy2' - } - } - } -} - diff --git a/src/main/groovy/grails/plugin/cache/redis/CacheRedisGrailsPlugin.groovy b/src/main/groovy/grails/plugin/cache/redis/CacheRedisGrailsPlugin.groovy index 1c7306f..206acd6 100644 --- a/src/main/groovy/grails/plugin/cache/redis/CacheRedisGrailsPlugin.groovy +++ b/src/main/groovy/grails/plugin/cache/redis/CacheRedisGrailsPlugin.groovy @@ -1,17 +1,21 @@ package grails.plugin.cache.redis -import grails.core.GrailsApplication -import grails.plugins.* -import grails.plugin.cache.redis.GrailsRedisCache -import grails.plugin.cache.redis.GrailsRedisCacheManager -import grails.plugin.cache.web.filter.redis.* +import grails.config.Config +import grails.plugin.cache.redis.internal.DelimiterCacheKeyPrefix +import grails.plugin.cache.redis.internal.GrailsDeserializer +import grails.plugin.cache.redis.internal.GrailsDeserializingConverter +import grails.plugin.cache.redis.internal.GrailsRedisKeySerializer +import grails.plugin.cache.redis.internal.GrailsRedisSerializer +import grails.plugin.cache.redis.internal.GrailsSerializer +import grails.plugin.cache.redis.internal.GrailsSerializingConverter +import grails.plugins.Plugin import org.slf4j.Logger import org.slf4j.LoggerFactory -import org.springframework.data.redis.cache.DefaultRedisCachePrefix +import org.springframework.data.redis.cache.CacheKeyPrefix +import org.springframework.data.redis.connection.RedisStandaloneConfiguration import org.springframework.data.redis.connection.jedis.JedisConnectionFactory import org.springframework.data.redis.core.RedisTemplate import redis.clients.jedis.JedisPoolConfig -import redis.clients.jedis.JedisShardInfo import redis.clients.jedis.Protocol /** @@ -21,7 +25,7 @@ class CacheRedisGrailsPlugin extends Plugin { private final Logger log = LoggerFactory.getLogger('grails.plugin.cache.CacheRedisGrailsPlugin') - def grailsVersion = "3.0.0 > *" + def grailsVersion = "6.2.0 > *" def loadAfter = ['cache'] def pluginExcludes = [ 'grails-app/conf/*CacheConfig.groovy', @@ -35,7 +39,7 @@ class CacheRedisGrailsPlugin extends Plugin { def author = "Burt Beckwith" def authorEmail = "burt@burtbeckwith.com" - + def profiles = ['web'] String documentation = 'http://grails-plugins.github.io/grails-cache-redis/' @@ -43,49 +47,49 @@ class CacheRedisGrailsPlugin extends Plugin { def developers = [ [name: "Burt Beckwith", email: 'burt@burtbeckwith.com'], [name: 'Costin Leau'], - [name: 'Colin Harrington', email:'colin.harrington@gmail.com'] + [name: 'Colin Harrington', email: 'colin.harrington@gmail.com'], + [name: 'Søren Berg Glasius', email: 'soeren@glasius.dk'], ] def issueManagement = [system: 'github', url: 'https://github.com/grails-plugins/grails-cache-redis/issues'] def scm = [url: 'https://github.com/grails-plugins/grails-cache-redis'] Closure doWithSpring() { - {-> - if (!enabled) { + { -> + Config config = grailsApplication.config + + boolean pluginEnabled = config.getProperty('grails.cache.redis.enabled', Boolean, Boolean.TRUE) + if (!pluginEnabled) { log.warn 'Redis Cache plugin is disabled' return } - def cacheConfig = grailsApplication.config.grails.cache - def redisCacheConfig = cacheConfig.redis - int configDatabase = redisCacheConfig.database ?: 0 - boolean configUsePool = (redisCacheConfig.usePool instanceof Boolean) ? redisCacheConfig.usePool : true - String configHostName = redisCacheConfig.hostName ?: 'localhost' - int configPort = redisCacheConfig.port ?: Protocol.DEFAULT_PORT - int configTimeout = redisCacheConfig.timeout ?: Protocol.DEFAULT_TIMEOUT - String configPassword = redisCacheConfig.password ?: null - Long ttlInSeconds = cacheConfig.ttl ?: GrailsRedisCache.NEVER_EXPIRE - Boolean isUsePrefix = (redisCacheConfig.usePrefix instanceof Boolean) ? redisCacheConfig.usePrefix : false - String keySerializerBean = redisCacheConfig.keySerializer instanceof String ? - redisCacheConfig.keySerializer : null - String hashKeySerializerBean = redisCacheConfig.hashKeySerializer instanceof String ? - redisCacheConfig.hashKeySerializer : null - - grailsCacheJedisPoolConfig(JedisPoolConfig) - - grailsCacheJedisShardInfo(JedisShardInfo, configHostName, configPort) { - password = configPassword - connectionTimeout = configTimeout + int configDatabase = config.getProperty('grails.cache.redis.database', Integer, 0) + boolean configUsePool = config.getProperty('grails.cache.redis.usePool', Boolean, true) + String configHostName = config.getProperty('grails.cache.redis.hostName', 'localhost') + int configPort = config.getProperty('grails.cache.redis.port', Integer, Protocol.DEFAULT_PORT) + int configTimeout = config.getProperty('grails.cache.redis.timeout', Integer, Protocol.DEFAULT_TIMEOUT) + String configUsername = config.getProperty('grails.cache.redis.username') + String configPassword = config.getProperty('grails.cache.redis.password') + Long ttlInSeconds = config.getProperty('grails.cache.redis.ttl', Long, GrailsRedisCache.NEVER_EXPIRE) + boolean isUsePrefix = config.getProperty('grails.cache.redis.usePrefix', Boolean, false) + + String keySerializerBean = config.getProperty('grails.cache.redis.keySerializer') + String hashKeySerializerBean = config.getProperty('grails.cache.redis.hashKeySerializer') + + grailsCacheRedisPoolConfig(JedisPoolConfig) + + grailsCacheRedisConfiguration(RedisStandaloneConfiguration, configHostName, configPort) { + username = configUsername + if(configPassword) { + password = configPassword + } + database = configDatabase } - grailsCacheJedisConnectionFactory(JedisConnectionFactory) { + grailsCacheJedisConnectionFactory(JedisConnectionFactory, ref('grailsCacheRedisConfiguration')) { usePool = configUsePool - database = configDatabase - hostName = configHostName - port = configPort timeout = configTimeout - password = configPassword - poolConfig = ref('grailsCacheJedisPoolConfig') - shardInfo = ref('grailsCacheJedisShardInfo') + poolConfig = ref('grailsCacheRedisPoolConfig') } grailsRedisCacheSerializer(GrailsSerializer) @@ -116,29 +120,17 @@ class CacheRedisGrailsPlugin extends Plugin { hashKeySerializer = ref(hashKeySerializerBean) } - String delimiter = redisCacheConfig.cachePrefixDelimiter ?: ':' - redisCachePrefix(DefaultRedisCachePrefix, delimiter) + String delimiter = config.getProperty('grails.cache.redis.cachePrefixDelimiter', CacheKeyPrefix.SEPARATOR) + String prefix = config.getProperty('grails.cache.redis.cachePrefix', '') + + grailsRedisCachePrefix(DelimiterCacheKeyPrefix, delimiter, prefix) grailsCacheManager(GrailsRedisCacheManager, ref('grailsCacheRedisTemplate')) { - cachePrefix = ref('redisCachePrefix') + cachePrefix = ref('grailsRedisCachePrefix', false) timeToLive = ttlInSeconds usePrefix = isUsePrefix } - - grailsCacheFilter(RedisPageFragmentCachingFilter) { - cacheManager = ref('grailsCacheManager') - nativeCacheManager = ref('grailsCacheRedisTemplate') - // TODO this name might be brittle - perhaps do by type? - cacheOperationSource = ref('org.springframework.cache.annotation.AnnotationCacheOperationSource#0') - keyGenerator = ref('webCacheKeyGenerator') - expressionEvaluator = ref('webExpressionEvaluator') - } } } - private boolean isEnabled(GrailsApplication application) { - //TODO cache plugin enabled and this one is.. - def enabled = application.config.grails.cache.enabled - enabled == null || enabled != false - } } diff --git a/src/main/groovy/grails/plugin/cache/redis/GrailsRedisCache.java b/src/main/groovy/grails/plugin/cache/redis/GrailsRedisCache.java index f2dc2f0..fba154e 100644 --- a/src/main/groovy/grails/plugin/cache/redis/GrailsRedisCache.java +++ b/src/main/groovy/grails/plugin/cache/redis/GrailsRedisCache.java @@ -17,6 +17,7 @@ import grails.plugin.cache.GrailsCache; import grails.plugin.cache.GrailsValueWrapper; import org.springframework.dao.DataAccessException; +import org.springframework.data.redis.cache.CacheKeyPrefix; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.core.RedisCallback; import org.springframework.data.redis.core.RedisTemplate; @@ -28,6 +29,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.Callable; /** * Based on package-scope org.springframework.data.redis.cache.RedisCache. @@ -44,7 +46,7 @@ public class GrailsRedisCache implements GrailsCache { protected final String name; @SuppressWarnings("rawtypes") protected final RedisTemplate template; - protected final byte[] prefix; + protected final CacheKeyPrefix prefix; protected final byte[] setName; protected final byte[] cacheLockName; protected long WAIT_FOR_LOCK = 300; @@ -54,17 +56,17 @@ public class GrailsRedisCache implements GrailsCache { * Constructor. * * @param name cache name - * @param prefix - * @param template - * @param ttl + * @param prefix prefix to use + * @param template Spring template + * @param ttl time to live for cache */ - public GrailsRedisCache(String name, byte[] prefix, RedisTemplate template, Long ttl) { + public GrailsRedisCache(String name, CacheKeyPrefix prefix, RedisTemplate template, Long ttl) { Assert.hasText(name, "non-empty cache name is required"); this.name = name; this.template = template; this.prefix = prefix; - this.ttl = ttl == null ? NEVER_EXPIRE : ttl.longValue(); + this.ttl = ttl == null ? NEVER_EXPIRE : ttl; StringRedisSerializer stringSerializer = new StringRedisSerializer(); @@ -112,6 +114,17 @@ public T doInRedis(RedisConnection connection) throws DataAccessException { }, true); } + @Override + public T get(final Object key, Callable valueLoader) { + /* + * FIXME: I had to add this method override in order to satisfy + * the Spring Cache interface. It looks like this method signature + * including the Callable parameter was added sometime after the + * original cache-redis plugin was developed (?). + */ + return (T) this.get(key); + } + @SuppressWarnings("unchecked") @Override public void put(final Object key, final Object value) { @@ -247,15 +260,17 @@ public Set doInRedis(RedisConnection connection) throws DataAccessExcept public byte[] computeKey(Object key) { @SuppressWarnings("unchecked") - byte[] k = template.getKeySerializer().serialize(key); + byte[] serializedKey = template.getKeySerializer().serialize(key); + assert serializedKey != null; - if (prefix == null || prefix.length == 0) { - return k; + if (prefix == null) { + return serializedKey; } + byte[] prefixBytes = prefix.compute(name).getBytes(); // ok to use Arrays.copyOf since spring-data-redis requires Java 6 - byte[] result = Arrays.copyOf(prefix, prefix.length + k.length); - System.arraycopy(k, 0, result, prefix.length, k.length); + byte[] result = Arrays.copyOf(prefixBytes, prefixBytes.length + serializedKey.length); + System.arraycopy(serializedKey, 0, result, prefixBytes.length, serializedKey.length); return result; } diff --git a/src/main/groovy/grails/plugin/cache/redis/GrailsRedisCacheManager.java b/src/main/groovy/grails/plugin/cache/redis/GrailsRedisCacheManager.java index ffe38bd..3c90e34 100644 --- a/src/main/groovy/grails/plugin/cache/redis/GrailsRedisCacheManager.java +++ b/src/main/groovy/grails/plugin/cache/redis/GrailsRedisCacheManager.java @@ -14,10 +14,9 @@ */ package grails.plugin.cache.redis; -import grails.plugin.cache.GrailsCacheManager; +import org.grails.plugin.cache.GrailsCacheManager; import org.springframework.cache.Cache; -import org.springframework.data.redis.cache.DefaultRedisCachePrefix; -import org.springframework.data.redis.cache.RedisCachePrefix; +import org.springframework.data.redis.cache.CacheKeyPrefix; import org.springframework.data.redis.core.RedisTemplate; import java.util.Collection; @@ -39,7 +38,7 @@ public class GrailsRedisCacheManager implements GrailsCacheManager { @SuppressWarnings("rawtypes") protected final RedisTemplate redisTemplate; protected boolean usePrefix; - protected RedisCachePrefix cachePrefix = new DefaultRedisCachePrefix(); + protected CacheKeyPrefix cachePrefix = CacheKeyPrefix.simple(); protected Long ttl; public GrailsRedisCacheManager(@SuppressWarnings("rawtypes") RedisTemplate template) { @@ -48,15 +47,16 @@ public GrailsRedisCacheManager(@SuppressWarnings("rawtypes") RedisTemplate templ @SuppressWarnings("unchecked") public Cache getCache(String name) { - Cache c = caches.get(name); - if (c == null) { - c = new GrailsRedisCache(name, (usePrefix ? cachePrefix.prefix(name) : null), redisTemplate, ttl); - caches.put(name, c); + Cache cache = caches.get(name); + if (cache == null) { + cache = new GrailsRedisCache(name, usePrefix ? cachePrefix : null, redisTemplate, ttl); + caches.put(name, cache); } - return c; + return cache; } + @Override public Collection getCacheNames() { return names; } @@ -80,12 +80,14 @@ public boolean destroyCache(String name) { * * @param prefix the prefix */ - public void setCachePrefix(RedisCachePrefix prefix) { + public void setCachePrefix(CacheKeyPrefix prefix) { cachePrefix = prefix; } /** * Enable the cache prefix. + * + * @param use True if using prefix */ public void setUsePrefix(Boolean use) { usePrefix = use; diff --git a/src/main/groovy/grails/plugin/cache/redis/internal/DelimiterCacheKeyPrefix.java b/src/main/groovy/grails/plugin/cache/redis/internal/DelimiterCacheKeyPrefix.java new file mode 100644 index 0000000..61a4327 --- /dev/null +++ b/src/main/groovy/grails/plugin/cache/redis/internal/DelimiterCacheKeyPrefix.java @@ -0,0 +1,19 @@ +package grails.plugin.cache.redis.internal; + +import org.springframework.data.redis.cache.CacheKeyPrefix; + +public class DelimiterCacheKeyPrefix implements CacheKeyPrefix { + private final String delimiter; + private final String prefix; + + public DelimiterCacheKeyPrefix(String delimiter, String prefix) { + this.delimiter = delimiter; + this.prefix = prefix; + } + + @Override + public String compute(String cacheName) { + return (prefix == null ? "" : prefix)+cacheName+(delimiter == null ? CacheKeyPrefix.SEPARATOR : delimiter); + } + +} diff --git a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsDeserializer.java b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsDeserializer.java similarity index 89% rename from src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsDeserializer.java rename to src/main/groovy/grails/plugin/cache/redis/internal/GrailsDeserializer.java index a016db4..4e2f5b2 100644 --- a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsDeserializer.java +++ b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsDeserializer.java @@ -12,9 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package grails.plugin.cache.web.filter.redis; +package grails.plugin.cache.redis.internal; -import org.springframework.core.NestedIOException; import org.springframework.core.serializer.Deserializer; import java.io.IOException; @@ -42,7 +41,7 @@ protected Class resolveClass(ObjectStreamClass osc) throws IOException, Class try { return ois.readObject(); } catch (ClassNotFoundException e) { - throw new NestedIOException("Failed to deserialize object type", e); + throw new IOException("Failed to deserialize object type", e); } } diff --git a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsDeserializingConverter.java b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsDeserializingConverter.java similarity index 95% rename from src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsDeserializingConverter.java rename to src/main/groovy/grails/plugin/cache/redis/internal/GrailsDeserializingConverter.java index a4020fb..78eeca2 100644 --- a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsDeserializingConverter.java +++ b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsDeserializingConverter.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package grails.plugin.cache.web.filter.redis; +package grails.plugin.cache.redis.internal; import org.springframework.core.convert.converter.Converter; import org.springframework.core.serializer.Deserializer; @@ -40,7 +40,7 @@ public Object convert(byte[] source) { /** * Dependency injection for the deserializer. * - * @param deserializer + * @param deserializer to use */ public void setDeserializer(Deserializer deserializer) { this.deserializer = deserializer; diff --git a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsRedisKeySerializer.java b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsRedisKeySerializer.java similarity index 97% rename from src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsRedisKeySerializer.java rename to src/main/groovy/grails/plugin/cache/redis/internal/GrailsRedisKeySerializer.java index b3c581e..53c44c4 100644 --- a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsRedisKeySerializer.java +++ b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsRedisKeySerializer.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package grails.plugin.cache.web.filter.redis; +package grails.plugin.cache.redis.internal; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.SerializationException; diff --git a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsRedisSerializer.java b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsRedisSerializer.java similarity index 94% rename from src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsRedisSerializer.java rename to src/main/groovy/grails/plugin/cache/redis/internal/GrailsRedisSerializer.java index 111b7ca..5fef363 100644 --- a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsRedisSerializer.java +++ b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsRedisSerializer.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package grails.plugin.cache.web.filter.redis; +package grails.plugin.cache.redis.internal; import org.springframework.core.convert.converter.Converter; import org.springframework.data.redis.serializer.RedisSerializer; @@ -55,7 +55,7 @@ public byte[] serialize(Object object) { /** * Dependency injection for the serializer. * - * @param serializer + * @param serializer to use */ public void setSerializer(Converter serializer) { this.serializer = serializer; @@ -64,7 +64,7 @@ public void setSerializer(Converter serializer) { /** * Dependency injection for the deserializer. * - * @param deserializer + * @param deserializer to use */ public void setDeserializer(Converter deserializer) { this.deserializer = deserializer; diff --git a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsSerializer.java b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsSerializer.java similarity index 96% rename from src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsSerializer.java rename to src/main/groovy/grails/plugin/cache/redis/internal/GrailsSerializer.java index e84b690..a9bb8ed 100644 --- a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsSerializer.java +++ b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsSerializer.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package grails.plugin.cache.web.filter.redis; +package grails.plugin.cache.redis.internal; import org.springframework.core.serializer.Serializer; diff --git a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsSerializingConverter.java b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsSerializingConverter.java similarity index 95% rename from src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsSerializingConverter.java rename to src/main/groovy/grails/plugin/cache/redis/internal/GrailsSerializingConverter.java index e1d3fa2..3db582a 100644 --- a/src/main/groovy/grails/plugin/cache/web/filter/redis/GrailsSerializingConverter.java +++ b/src/main/groovy/grails/plugin/cache/redis/internal/GrailsSerializingConverter.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package grails.plugin.cache.web.filter.redis; +package grails.plugin.cache.redis.internal; import org.springframework.core.convert.converter.Converter; import org.springframework.core.serializer.Serializer; @@ -44,7 +44,7 @@ public byte[] convert(Object source) { /** * Dependency injection for the serializer. * - * @param serializer + * @param serializer to use */ public void setSerializer(Serializer serializer) { this.serializer = serializer; diff --git a/src/main/groovy/grails/plugin/cache/web/filter/redis/RedisPageFragmentCachingFilter.java b/src/main/groovy/grails/plugin/cache/web/filter/redis/RedisPageFragmentCachingFilter.java deleted file mode 100644 index 0f57769..0000000 --- a/src/main/groovy/grails/plugin/cache/web/filter/redis/RedisPageFragmentCachingFilter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright 2012 SpringSource. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package grails.plugin.cache.web.filter.redis; - -import grails.plugin.cache.web.PageInfo; -import grails.plugin.cache.web.filter.PageFragmentCachingFilter; -import org.springframework.cache.Cache; -import org.springframework.cache.Cache.ValueWrapper; -import org.springframework.data.redis.cache.RedisCacheManager; - -/** - * Redis-based implementation of PageFragmentCachingFilter. - * - * @author Burt Beckwith - */ -public class RedisPageFragmentCachingFilter extends PageFragmentCachingFilter { - - @Override - protected int getTimeToLive(ValueWrapper wrapper) { - // ttl not supported - return Integer.MAX_VALUE; - } - - @Override - protected RedisCacheManager getNativeCacheManager() { - return (RedisCacheManager) super.getNativeCacheManager(); - } - - @Override - protected void put(Cache cache, String key, PageInfo pageInfo, Integer timeToLiveSeconds) { - // just store, ttl not supported - cache.put(key, pageInfo); - } - -} diff --git a/src/test/groovy/grails/plugin/cache/redis/GrailsRedisCacheManagerSpec.groovy b/src/test/groovy/grails/plugin/cache/redis/GrailsRedisCacheManagerSpec.groovy index f9eaf57..51716ae 100644 --- a/src/test/groovy/grails/plugin/cache/redis/GrailsRedisCacheManagerSpec.groovy +++ b/src/test/groovy/grails/plugin/cache/redis/GrailsRedisCacheManagerSpec.groovy @@ -1,37 +1,70 @@ package grails.plugin.cache.redis +import grails.plugin.cache.redis.internal.DelimiterCacheKeyPrefix +import org.grails.testing.GrailsUnitTest import org.springframework.data.redis.core.RedisTemplate +import org.springframework.data.redis.serializer.RedisSerializer import spock.lang.Specification -class GrailsRedisCacheManagerSpec extends Specification { +class GrailsRedisCacheManagerSpec extends Specification implements GrailsUnitTest { - def 'it should default expiration to never expire for all created caches when creating a cache manager with a null ttl value.'() { + void 'it should default expiration to never expire for all created caches when creating a cache manager with a null ttl value.'() { given: - Long ttl = null - RedisTemplate template = Mock(RedisTemplate) - GrailsRedisCacheManager cacheManager = new GrailsRedisCacheManager(template) + Long ttl = null + RedisTemplate template = Stub(RedisTemplate) + GrailsRedisCacheManager cacheManager = new GrailsRedisCacheManager(template) when: - cacheManager.setTimeToLive(ttl) + cacheManager.timeToLive = ttl and: - GrailsRedisCache cache = cacheManager.getCache('book') + GrailsRedisCache cache = cacheManager.getCache('book') then: - assert cache.ttl == GrailsRedisCache.NEVER_EXPIRE + cache.ttl == GrailsRedisCache.NEVER_EXPIRE } - def 'it should set expiration on all caches with configured ttl when creating a cache manager.'() { + void 'it should set expiration on all caches with configured ttl when creating a cache manager.'() { given: - Long ttl = 5 - RedisTemplate template = Mock(RedisTemplate) - GrailsRedisCacheManager cacheManager = new GrailsRedisCacheManager(template) + Long ttl = 5 + RedisTemplate template = Stub(RedisTemplate) + GrailsRedisCacheManager cacheManager = new GrailsRedisCacheManager(template) when: - cacheManager.setTimeToLive(ttl) + cacheManager.timeToLive = ttl and: - GrailsRedisCache cache = cacheManager.getCache('book') + GrailsRedisCache cache = cacheManager.getCache('book') then: - assert cache.ttl == ttl + cache.ttl == ttl } + + void 'it should generate a key with a prefix, if usePrefix is set'() { + given: + RedisTemplate template = Stub(RedisTemplate) { + getKeySerializer() >> RedisSerializer.string() + } + GrailsRedisCacheManager cacheManager = new GrailsRedisCacheManager(template) + + when: + cacheManager.usePrefix = usePrefix + cacheManager.cachePrefix = cachePrefixGenerator + and: + GrailsRedisCache cache = cacheManager.getCache('book') + and: + String computedKey = new String(cache.computeKey('key')) + + then: + computedKey == expectedKey + + where: + usePrefix | delimiter | prefix || expectedKey + false | null | null || 'key' + true | null | null || 'book::key' + true | '_' | null || 'book_key' + true | null | 'cache_' || 'cache_book::key' + true | '_' | 'cache_' || 'cache_book_key' + + cachePrefixGenerator = new DelimiterCacheKeyPrefix(delimiter, prefix) + } + } diff --git a/src/test/groovy/grails/plugin/cache/redis/GrailsRedisCacheSpec.groovy b/src/test/groovy/grails/plugin/cache/redis/GrailsRedisCacheSpec.groovy index 40788e5..f1f6aa6 100644 --- a/src/test/groovy/grails/plugin/cache/redis/GrailsRedisCacheSpec.groovy +++ b/src/test/groovy/grails/plugin/cache/redis/GrailsRedisCacheSpec.groovy @@ -1,41 +1,34 @@ package grails.plugin.cache.redis -import org.springframework.data.redis.cache.DefaultRedisCachePrefix -import org.springframework.data.redis.cache.RedisCachePrefix import org.springframework.data.redis.core.RedisTemplate import spock.lang.Specification class GrailsRedisCacheSpec extends Specification { - def 'it should default expiration to never expire when creating a cache with a null ttl value.'() { + void 'it should default expiration to never expire when creating a cache with a null ttl value.'() { given: - RedisCachePrefix cachePrefix = new DefaultRedisCachePrefix() - String cacheName = 'book' - byte[] prefix = cachePrefix.prefix(cacheName) - RedisTemplate template = Mock(RedisTemplate) - Long ttl = null + String cacheName = 'book' + RedisTemplate template = Mock(RedisTemplate) + Long ttl = null when: - GrailsRedisCache cache = new GrailsRedisCache(cacheName, prefix, template, ttl) + GrailsRedisCache cache = new GrailsRedisCache(cacheName, null, template, ttl) then: - assert cache.ttl == GrailsRedisCache.NEVER_EXPIRE + cache.ttl == GrailsRedisCache.NEVER_EXPIRE } - def 'it should set expiration with configured ttl when creating a cache.'() { + void 'it should set expiration with configured ttl when creating a cache.'() { given: - RedisCachePrefix cachePrefix = new DefaultRedisCachePrefix() - String cacheName = 'book' - byte[] prefix = cachePrefix.prefix(cacheName) - RedisTemplate template = Mock(RedisTemplate) - Long ttl = 500 + String cacheName = 'book' + RedisTemplate template = Mock(RedisTemplate) + Long ttl = 500 when: - GrailsRedisCache cache = new GrailsRedisCache(cacheName, prefix, template, ttl) + GrailsRedisCache cache = new GrailsRedisCache(cacheName, null, template, ttl) then: - assert cache.ttl == ttl + cache.ttl == ttl } - - + } diff --git a/src/test/groovy/grails/plugin/cache/web/filter/redis/DelimiterCacheKeyPrefixSpec.groovy b/src/test/groovy/grails/plugin/cache/web/filter/redis/DelimiterCacheKeyPrefixSpec.groovy new file mode 100644 index 0000000..442f917 --- /dev/null +++ b/src/test/groovy/grails/plugin/cache/web/filter/redis/DelimiterCacheKeyPrefixSpec.groovy @@ -0,0 +1,23 @@ +package grails.plugin.cache.web.filter.redis + +import grails.plugin.cache.redis.internal.DelimiterCacheKeyPrefix +import spock.lang.Specification + +class DelimiterCacheKeyPrefixSpec extends Specification { + + void 'prefix is generated as expected depending on input'() { + given: + DelimiterCacheKeyPrefix cacheKeyPrefix = new DelimiterCacheKeyPrefix(delimiter, prefix) + + expect: + cacheKeyPrefix.compute('book') == expectedPrefix + + where: + delimiter | prefix || expectedPrefix + null | null || 'book::' + '_' | null || 'book_' + null | 'cache_' || 'cache_book::' + '_' | 'cache_' || 'cache_book_' + } + +} diff --git a/travis-build.sh b/travis-build.sh deleted file mode 100755 index 52a31d3..0000000 --- a/travis-build.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash -set -e -rm -rf *.zip -./gradlew clean test assemble - -filename=$(find build/libs -name "*.jar" | head -1) -filename=$(basename "$filename") - -EXIT_STATUS=0 -echo "Publishing archives for branch $TRAVIS_BRANCH" -if [[ -n $TRAVIS_TAG ]] || [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then - - echo "Publishing archives" - - if [[ -n $TRAVIS_TAG ]]; then - ./gradlew bintrayUpload || EXIT_STATUS=$? - else - ./gradlew publish || EXIT_STATUS=$? - fi - - ./gradlew docs || EXIT_STATUS=$? - - git config --global user.name "$GIT_NAME" - git config --global user.email "$GIT_EMAIL" - git config --global credential.helper "store --file=~/.git-credentials" - echo "https://$GH_TOKEN:@github.com" > ~/.git-credentials - - git clone https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git -b gh-pages gh-pages --single-branch > /dev/null - cd gh-pages - - # If this is the master branch then update the snapshot - if [[ $TRAVIS_BRANCH == 'master' ]]; then - mkdir -p snapshot - cp -r ../build/docs/manual/. ./snapshot/ - - git add snapshot/* - fi - - # If there is a tag present then this becomes the latest - if [[ -n $TRAVIS_TAG ]]; then - git rm -rf latest/ - mkdir -p latest - cp -r ../build/docs/manual/. ./latest/ - git add latest/* - - version="$TRAVIS_TAG" - version=${version:1} - majorVersion=${version:0:4} - majorVersion="${majorVersion}x" - - mkdir -p "$version" - cp -r ../build/docs/manual/. "./$version/" - git add "$version/*" - - mkdir -p "$majorVersion" - cp -r ../build/docs/manual/. "./$majorVersion/" - git add "$majorVersion/*" - - fi - - git commit -a -m "Updating docs for Travis build: https://travis-ci.org/$TRAVIS_REPO_SLUG/builds/$TRAVIS_BUILD_ID" - git push origin HEAD - cd .. - rm -rf gh-pages -fi - -exit $EXIT_STATUS