diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f26bd44f32c..87ff2e6aaf7 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -9,48 +9,59 @@ on: jobs: build: runs-on: ubuntu-latest - strategy: - matrix: - java: ['11', '14'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: ${{ matrix.java }} + distribution: temurin + java-version: 17 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + # Publish a Gradle build scan so you can see all the build logs, + # a complete task timeline, test outputs, and the resolved dependencies of your build. + build-scan-publish: true + build-scan-terms-of-use-url: "https://gradle.com/terms-of-service" + build-scan-terms-of-use-agree: "yes" - name: Run Build id: build - uses: gradle/gradle-build-action@v2 + run: ./gradlew build env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - with: - arguments: build + DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} publish: if: github.event_name == 'push' needs: ["build"] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 with: - distribution: 'adopt' - java-version: '11' + build-scan-publish: true + build-scan-terms-of-use-url: "https://gradle.com/terms-of-service" + build-scan-terms-of-use-agree: "yes" - name: Publish to Artifactory (repo.grails.org) - uses: gradle/gradle-build-action@v2 + run: ./gradlew -Dorg.gradle.internal.publish.checksums.insecure=true publish env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} - with: - arguments: -Dorg.gradle.internal.publish.checksums.insecure=true publish trigger-build-gorm-impls: if: github.event_name == 'push' needs: ["build", "publish"] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Extract branch name id: extract_branch run: echo "value=${GITHUB_REF:11}" >> $GITHUB_OUTPUT @@ -64,6 +75,13 @@ jobs: repo: grails/gorm-hibernate5 ref: ${{ steps.extract_branch.outputs.value }} token: ${{ secrets.GH_TOKEN }} + - name: Invoke the Java CI workflow in GORM Hibernate6 + uses: benc-uk/workflow-dispatch@v1.2 + with: + workflow: Java CI + repo: grails/gorm-hibernate6 + ref: ${{ steps.extract_branch.outputs.value }} + token: ${{ secrets.GH_TOKEN }} - name: Invoke the Java CI workflow in GORM MongoDB uses: benc-uk/workflow-dispatch@v1.2 with: diff --git a/.github/workflows/groovy-joint-workflow.yml b/.github/workflows/groovy-joint-workflow.yml index cc105cb8b26..0df66850cbd 100644 --- a/.github/workflows/groovy-joint-workflow.yml +++ b/.github/workflows/groovy-joint-workflow.yml @@ -1,22 +1,4 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - -name: "Grails Joint Validation Build" -# GROOVY_2_5_X == Grails 4.0.x -# GROOVY_3_0_X == grails master -# Groovy master branch does not map to any due to changed package names. +name: "Groovy Joint Validation Build" on: push: branches: @@ -27,116 +9,136 @@ on: workflow_dispatch: permissions: contents: read -env: - CI_GROOVY_VERSION: jobs: build_groovy: - strategy: - fail-fast: true runs-on: ubuntu-latest outputs: groovyVersion: ${{ steps.groovy-version.outputs.value }} steps: - - name: Set up JDK + - name: "☕ïļ Setup JDK" uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: '11.0.6' - - name: Cache local Maven repository & Groovy - uses: actions/cache@v3 + distribution: liberica + java-version: 17 + - name: "🗄ïļ Cache local Maven repository" + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: cache-local-maven-${{ github.sha }} + - name: "ðŸ“Ĩ Checkout this project to fetch Gradle Plugin versions it uses" + uses: actions/checkout@v4 + with: + sparse-checkout-cone-mode: false + sparse-checkout: settings.gradle + - name: "📝 Store the Gradle Plugin versions used in this project" + id: gradle-plugin-versions + run: | + DEVELOCITY_PLUGIN_VERSION=$(grep -m 1 'id\s*\(\"com.gradle.develocity\"\|'"'com.gradle.develocity'"'\)\s*version' settings.gradle | sed -E "s/.*version[[:space:]]*['\"]?([0-9]+\.[0-9]+(\.[0-9]+)?)['\"]?.*/\1/" | tr -d [:space:]) + COMMON_CUSTOM_USER_DATA_PLUGIN_VERSION=$(grep -m 1 'id\s*\(\"com.gradle.common-custom-user-data-gradle-plugin\"\|'"'com.gradle.common-custom-user-data-gradle-plugin'"'\)\s*version' settings.gradle | sed -E "s/.*version[[:space:]]*['\"]?([0-9]+\.[0-9]+(\.[0-9]+)?)['\"]?.*/\1/" | tr -d [:space:]) + echo "Project uses Develocity Plugin version: $DEVELOCITY_PLUGIN_VERSION" + echo "Project uses Common Custom User Data Plugin version: $COMMON_CUSTOM_USER_DATA_PLUGIN_VERSION" + echo "develocity_plugin_version=$DEVELOCITY_PLUGIN_VERSION" >> $GITHUB_OUTPUT + echo "common_custom_user_data_plugin_version=$COMMON_CUSTOM_USER_DATA_PLUGIN_VERSION" >> $GITHUB_OUTPUT + rm settings.gradle + - name: "ðŸ“Ĩ Checkout Groovy 4_0_X (Grails 7 and later)" + run: git clone --depth 1 https://github.com/apache/groovy.git -b GROOVY_4_0_X --single-branch + - name: "🐘 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 with: - path: | - ~/groovy - ~/.m2/repository - key: cache-local-groovy-maven-${{ github.sha }} - - name: Checkout Groovy 3_0_X (Grails 5 and later) - run: cd .. && git clone --depth 1 https://github.com/apache/groovy.git -b GROOVY_3_0_X --single-branch - - name: Set CI_GROOVY_VERSION for Grails + develocity-access-key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + - name: "📝 Store Groovy version to use when building this project" id: groovy-version run: | - cd ../groovy - echo "CI_GROOVY_VERSION=$(cat gradle.properties | grep groovyVersion | cut -d\= -f2 | tr -d '[:space:]')" >> $GITHUB_ENV - echo "value=$(cat gradle.properties | grep groovyVersion | cut -d\= -f2 | tr -d '[:space:]')" >> $GITHUB_OUTPUT - - name: Prepare GE Set-up Configuration - id: ge_conf + cd groovy + GROOVY_VERSION=$(cat gradle.properties | grep groovyVersion | cut -d\= -f2 | tr -d '[:space:]') + echo "Groovy version $GROOVY_VERSION stored" + echo "value=$GROOVY_VERSION" >> $GITHUB_OUTPUT + - name: "🐘 Configure Gradle Plugins (Step 1/3)" + id: develocity-conf-1 run: | echo "VALUE<> $GITHUB_OUTPUT echo "plugins { " >> $GITHUB_OUTPUT - echo " id 'com.gradle.enterprise' version '3.15.1'" >> $GITHUB_OUTPUT - echo " id 'com.gradle.common-custom-user-data-gradle-plugin' version '1.11.3'" >> $GITHUB_OUTPUT + echo " id 'com.gradle.develocity' version '${{ steps.gradle-plugin-versions.outputs.develocity_plugin_version }}'" >> $GITHUB_OUTPUT + echo " id 'com.gradle.common-custom-user-data-gradle-plugin' version '${{ steps.gradle-plugin-versions.outputs.common_custom_user_data_plugin_version }}'" >> $GITHUB_OUTPUT echo "}" >> $GITHUB_OUTPUT echo "" >> $GITHUB_OUTPUT - echo "gradleEnterprise {" >> $GITHUB_OUTPUT - echo " server = 'https://ge.grails.org'" >> $GITHUB_OUTPUT - echo " buildScan {" >> $GITHUB_OUTPUT - echo " publishAlways()" >> $GITHUB_OUTPUT - echo " publishIfAuthenticated()" >> $GITHUB_OUTPUT - echo " uploadInBackground = System.getenv('CI') == null" >> $GITHUB_OUTPUT - echo " capture {" >> $GITHUB_OUTPUT - echo " taskInputFiles = true" >> $GITHUB_OUTPUT - echo " }" >> $GITHUB_OUTPUT - echo " }" >> $GITHUB_OUTPUT - echo "}" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + - name: "🐘 Configure Gradle Plugins (Step 2/3)" + id: develocity-conf-2 + run: | + echo "VALUE<> $GITHUB_OUTPUT + echo "def isAuthenticated = System.getenv('DEVELOCITY_ACCESS_KEY') != null" >> $GITHUB_OUTPUT + echo "def isBuildCacheAuthenticated =" >> $GITHUB_OUTPUT + echo " System.getenv('DEVELOCITY_BUILD_CACHE_NODE_USER') != null &&" >> $GITHUB_OUTPUT + echo " System.getenv('DEVELOCITY_BUILD_CACHE_NODE_KEY') != null" >> $GITHUB_OUTPUT echo "" >> $GITHUB_OUTPUT - echo "buildCache {" >> $GITHUB_OUTPUT - echo " local { enabled = System.getenv('CI') != 'true' }" >> $GITHUB_OUTPUT - echo " remote(gradleEnterprise.buildCache) {" >> $GITHUB_OUTPUT - echo " push = System.getenv('CI') == 'true'" >> $GITHUB_OUTPUT - echo " enabled = true" >> $GITHUB_OUTPUT - echo " }" >> $GITHUB_OUTPUT - echo "}" >> $GITHUB_OUTPUT + echo "develocity {" >> $GITHUB_OUTPUT + echo " server = 'https://ge.grails.org'" >> $GITHUB_OUTPUT + echo " buildScan {" >> $GITHUB_OUTPUT + echo " publishing.onlyIf { isAuthenticated }" >> $GITHUB_OUTPUT + echo " uploadInBackground = false" >> $GITHUB_OUTPUT + echo " }" >> $GITHUB_OUTPUT + echo "}" >> $GITHUB_OUTPUT + echo "" >> $GITHUB_OUTPUT + echo "buildCache {" >> $GITHUB_OUTPUT + echo " local { enabled = false }" >> $GITHUB_OUTPUT + echo " remote(develocity.buildCache) {" >> $GITHUB_OUTPUT + echo " push = isBuildCacheAuthenticated" >> $GITHUB_OUTPUT + echo " enabled = true" >> $GITHUB_OUTPUT + echo " usernameAndPassword(" >> $GITHUB_OUTPUT + echo " System.getenv('DEVELOCITY_BUILD_CACHE_NODE_USER') ?: ''," >> $GITHUB_OUTPUT + echo " System.getenv('DEVELOCITY_BUILD_CACHE_NODE_KEY') ?: ''" >> $GITHUB_OUTPUT + echo " )" >> $GITHUB_OUTPUT + echo " }" >> $GITHUB_OUTPUT + echo "}" >> $GITHUB_OUTPUT echo "" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - - name: Gradle Enterprise Set-up + - name: "🐘 Configure Gradle Plugins (step 3/3)" run: | - cd ../groovy - # Delete exiting plugins and build-scan from settings.gradle file - sed -i '21,31d' settings.gradle - # Add Gradle Enterprise set-up related configuration after line no 20 in settings.gradle - echo "${{ steps.ge_conf.outputs.value}}" | sed -i -e "20r /dev/stdin" settings.gradle - - name: Build and install groovy (no docs) - uses: gradle/gradle-build-action@v2 + cd groovy + # Delete existing plugins from settings.gradle file + sed -i '32,37d' settings.gradle + # Add Develocity setup related configuration after line no 31 in settings.gradle + echo "${{ steps.develocity-conf-1.outputs.value }}" | sed -i -e "31r /dev/stdin" settings.gradle + # Delete existing buildCache configuration from gradle/build-scans.gradle file + sed -i '23,46d' gradle/build-scans.gradle + # Add Develocity setup related configuration after line no 22 in gradle/build-scans.gradle + echo "${{ steps.develocity-conf-2.outputs.value }}" | sed -i -e "22r /dev/stdin" gradle/build-scans.gradle + - name: "ðŸ”Ļ Publish Groovy to local maven repository (no docs)" env: - GRADLE_SCANS_ACCEPT: yes - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - with: - build-root-directory: ../groovy - arguments: | - install - -x groovydoc - -x javadoc - -x javadocAll - -x groovydocAll - -x asciidoc - -x docGDK - build_gorm: + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} + run: | + cd groovy + ./gradlew pTML -x groovydoc -x javadoc -x javadocAll -x groovydocAll -x asciidoc -x docGDK + + build_project: needs: [build_groovy] - strategy: - fail-fast: true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up JDK + - name: "ðŸ“Ĩ Checkout project" + uses: actions/checkout@v4 + - name: "☕ïļ Setup JDK" uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: '11' - - name: Cache local Maven repository & Groovy - uses: actions/cache@v3 + distribution: liberica + java-version: 17 + - name: "🐘 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 with: - path: | - ~/groovy - ~/.m2/repository - key: cache-local-groovy-maven-${{ github.sha }} - - name: Set CI_GROOVY_VERSION for Grails - run: | - echo "CI_GROOVY_VERSION=${{needs.build_groovy.outputs.groovyVersion}}" >> $GITHUB_ENV - - name: Build GORM - id: build_gorm - uses: gradle/gradle-build-action@v2 - env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + develocity-access-key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + - name: "🗄ïļ Restore local Maven repository from cache" + uses: actions/cache@v4 with: - arguments: | - build - -x groovydoc + path: ~/.m2/repository + key: cache-local-maven-${{ github.sha }} + - name: "ðŸŠķ Add mavenLocal repository to build" + run: sed -i 's|// mavenLocal() // Keep|mavenLocal() // Keep|' build.gradle + - name: "ðŸ”Ļ Build and test project using the locally built Groovy snapshot" + env: + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} + run: > + ./gradlew build + -PgroovyVersion=${{needs.build_groovy.outputs.groovyVersion}} + -x groovydoc diff --git a/.github/workflows/release-notes.yml b/.github/workflows/release-notes.yml index b760ce11a29..83520b41601 100644 --- a/.github/workflows/release-notes.yml +++ b/.github/workflows/release-notes.yml @@ -14,7 +14,7 @@ jobs: release_notes: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Check if it has release drafter config file id: check_release_drafter run: | @@ -24,7 +24,7 @@ jobs: id: extract_branch run: echo "value=${GITHUB_REF:11}" >> $GITHUB_OUTPUT # If it has release drafter: - - uses: release-drafter/release-drafter@v5 + - uses: release-drafter/release-drafter@v6 if: steps.check_release_drafter.outputs.has_release_drafter == 'true' env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b0b5392ae72..57f86a8d657 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,18 +9,18 @@ jobs: target_branch: ${{ steps.extract_branch.outputs.value }} runs-on: ubuntu-latest env: - GIT_USER_NAME: puneetbehl - GIT_USER_EMAIL: behlp@unityfoundation.io + GIT_USER_NAME: 'grails-build' + GIT_USER_EMAIL: 'grails-build@users.noreply.github.com' steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: token: ${{ secrets.GH_TOKEN }} - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: 11 + distribution: temurin + java-version: 17 - name: Run pre-release uses: micronaut-projects/github-actions/pre-release@master with: @@ -35,14 +35,22 @@ jobs: - name: Set the current release version id: release_version run: echo "value=${GITHUB_REF:11}" >> $GITHUB_OUTPUT + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + # Publish a Gradle build scan so you can see all the build logs, + # a complete task timeline, test outputs, and the resolved dependencies of your build. + build-scan-publish: true + build-scan-terms-of-use-url: "https://gradle.com/terms-of-service" + build-scan-terms-of-use-agree: "yes" - name: Run Assemble if: success() id: assemble - uses: gradle/gradle-build-action@v2 - with: - arguments: assemble + run: ./gradlew assemble env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} - name: Upload Distribution if: success() uses: actions/upload-artifact@v4 @@ -55,20 +63,20 @@ jobs: run: echo $SECRING_FILE | base64 -d > ${{ github.workspace }}/secring.gpg - name: Publish to Sonatype OSSRH id: publish - uses: gradle/gradle-build-action@v2 + run: > + ./gradlew -Psigning.secretKeyRingFile=${{ github.workspace }}/secring.gpg + publishToSonatype + closeSonatypeStagingRepository env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} SIGNING_KEY: ${{ secrets.SIGNING_KEY }} SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }} SECRING_FILE: ${{ secrets.SECRING_FILE }} - with: - arguments: | - -Psigning.secretKeyRingFile=${{ github.workspace }}/secring.gpg - publishToSonatype - closeSonatypeStagingRepository release: needs: publish runs-on: ubuntu-latest @@ -80,17 +88,23 @@ jobs: with: token: ${{ secrets.GH_TOKEN }} ref: v${{ needs.publish.outputs.release_version }} + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + build-scan-publish: true + build-scan-terms-of-use-url: "https://gradle.com/terms-of-service" + build-scan-terms-of-use-agree: "yes" - name: Nexus Staging Close And Release - uses: gradle/gradle-build-action@v2 + run: > + ./gradlew findSonatypeStagingRepository + releaseSonatypeStagingRepository env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} - with: - arguments: | - findSonatypeStagingRepository - releaseSonatypeStagingRepository - name: Run post-release if: success() uses: micronaut-projects/github-actions/post-release@master diff --git a/.sdkmanrc b/.sdkmanrc index e2a1d58cf8b..215786fc3c2 100644 --- a/.sdkmanrc +++ b/.sdkmanrc @@ -1 +1 @@ -java=11.0.24-librca +java=17.0.12-librca diff --git a/build.gradle b/build.gradle index 352fece9386..7f810285a9f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,14 +4,12 @@ buildscript { maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath "io.github.gradle-nexus:publish-plugin:1.3.0" - classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1' + classpath "io.github.gradle-nexus:publish-plugin:$gradleNexusPublishPluginVersion" + classpath "com.bmuschko:gradle-nexus-plugin:$gradleNexusPluginVersion" } } ext { - groovyVersion = System.getenv('CI_GROOVY_VERSION') ?: project.groovyVersion - // overall project version isCiBuild = System.getenv().get("CI") as Boolean isSnapshot = project.projectVersion.endsWith("-SNAPSHOT") isReleaseVersion = !isSnapshot @@ -20,8 +18,6 @@ ext { nexusPassword = System.getenv("SONATYPE_PASSWORD") ?: project.hasProperty("sonatypeOssPassword") ? project.sonatypeOssPassword : '' } -def spockDependency = "org.spockframework:spock-core:$spockVersion" - def isGroovyProject(project) { !project.name.contains("grails-plugins") } @@ -38,19 +34,18 @@ apply plugin: 'project-report' allprojects { - ext.groovyVersion = System.getenv('CI_GROOVY_VERSION') ?: project.groovyVersion - repositories { - mavenLocal() mavenCentral() maven { url = 'https://repo.grails.org/grails/core' } - if(isSnapshot) { + maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' } + if (isSnapshot) { maven { url = 'https://repo.grails.org/grails/libs-snapshots-local' } } - if(groovyVersion && groovyVersion.endsWith('-SNAPSHOT')) { + // mavenLocal() // Keep, this will be uncommented and used by CI (groovy-joint-workflow) + if (groovyVersion?.endsWith('-SNAPSHOT')) { maven { - name = 'JFrog Groovy snapshot repo' - url = 'https://groovy.jfrog.io/artifactory/libs-snapshot-local' + name = 'ASF Snapshot repo' + url = 'https://repository.apache.org/content/repositories/snapshots' } } } @@ -58,10 +53,12 @@ allprojects { configurations { all { resolutionStrategy { - force "org.codehaus.groovy:groovy:$groovyVersion" - force "org.codehaus.groovy:groovy-dateutil:$groovyVersion" - force "org.codehaus.groovy:groovy-xml:$groovyVersion" - force "org.codehaus.groovy:groovy-templates:$groovyVersion" + eachDependency { DependencyResolveDetails details -> + if ((details.requested.group == 'org.codehaus.groovy' || details.requested.group == 'org.apache.groovy') && details.requested.name != 'groovy-bom') { + details.useTarget(group: 'org.apache.groovy', name: details.requested.name, version: "$groovyVersion") + details.because "The dependency coordinates are changed in Apache Groovy 4, plus ensure version" + } + } } } } @@ -95,10 +92,11 @@ subprojects { apply plugin: 'idea' apply plugin: 'java-library' - sourceCompatibility = 1.11 - targetCompatibility = 1.11 + } + compileJava.options.release = 17 + def isGormDatasource = project.name.startsWith("grails-datastore-gorm-") && !project.name.endsWith("tck") && !project.name.endsWith("-support") && @@ -109,29 +107,33 @@ subprojects { dependencies { - api "javax.annotation:javax.annotation-api:$javaAnnotationApiVersion" + api platform("org.grails:grails-bom:$grailsVersion") + api "jakarta.annotation:jakarta.annotation-api:$jakartaAnnotationApiVersion" + implementation "jakarta.validation:jakarta.validation-api" + compileOnly "com.github.spotbugs:spotbugs-annotations" if (isStandardGroovyMavenProject) { - documentation "org.fusesource.jansi:jansi:2.4.0" - documentation "org.codehaus.groovy:groovy-dateutil:$groovyVersion" - documentation 'info.picocli:picocli:4.6.3' - documentation ("com.github.javaparser:javaparser-core:$javaParserCoreVersion") - - api "org.codehaus.groovy:groovy:$groovyVersion" - testImplementation "org.codehaus.groovy:groovy-test-junit5:$groovyVersion" - testImplementation "org.junit.jupiter:junit-jupiter-api:5.9.1" - testImplementation "org.junit.platform:junit-platform-runner:1.9.1" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.9.1" - - testImplementation(spockDependency) { transitive = false } + documentation platform("org.grails:grails-bom:$grailsVersion") + documentation "org.fusesource.jansi:jansi" + documentation "org.apache.groovy:groovy-dateutil:$groovyVersion" + documentation "info.picocli:picocli:$picocliVersion" + documentation "com.github.javaparser:javaparser-core" + + compileOnly "org.apache.groovy:groovy:$groovyVersion" + testImplementation "org.apache.groovy:groovy-test-junit5:$groovyVersion" + testImplementation "org.junit.jupiter:junit-jupiter-api" + testImplementation "org.junit.jupiter:junit-jupiter-engine" + testImplementation "org.junit.platform:junit-platform-runner" + + testImplementation "org.spockframework:spock-core" } if (project.name == "grails-datastore-gorm-tck") { - api "org.codehaus.groovy:groovy-test-junit5:$groovyVersion" - api "org.junit.jupiter:junit-jupiter-api:5.9.1" - api "org.junit.platform:junit-platform-runner:1.9.1" - runtimeOnly "org.junit.jupiter:junit-jupiter-engine:5.9.1" - implementation(spockDependency) { transitive = false } + api "org.apache.groovy:groovy-test-junit5:$groovyVersion" + api "org.junit.jupiter:junit-jupiter-api" + api "org.junit.platform:junit-platform-runner" + runtimeOnly "org.junit.jupiter:junit-jupiter-engine" + implementation "org.spockframework:spock-core" } } @@ -240,9 +242,9 @@ configurations { } dependencies { - build "com.cenqua.clover:clover:3.3.0" - build "org.apache.ant:ant-junit:1.10.12" - build "org.apache.ant:ant-nodeps:1.8.1" + build "org.openclover:clover:$cloverVersion" + build "org.apache.ant:ant-junit" + build "org.apache.ant:ant" } task install(dependsOn: subprojects*.tasks*.withType(PublishToMavenLocal)) diff --git a/clover.gradle b/clover.gradle index 9bc49686eb0..5d2dc42c643 100644 --- a/clover.gradle +++ b/clover.gradle @@ -19,12 +19,12 @@ class CloverPluginConvention { } dependencies { - testRuntimeOnly "com.cenqua.clover:clover:3.3.0" + testRuntimeOnly "org.openclover:clover:$cloverVersion" } test.doFirst { if (project.hasProperty("withClover")) { - ant.taskdef(name: 'groovyc', classname:"org.codehaus.groovy.ant.Groovyc", classpath:configurations.testRuntimeClasspath.asPath) + ant.taskdef(name: 'groovyc', classname:"org.apache.groovy.ant.Groovyc", classpath:configurations.testRuntimeClasspath.asPath) ant.taskdef(resource:"cloverlib.xml", classpath:configurations.testRuntimeClasspath.asPath) ant.property(name:"clover.license.path", value:cloverConvention.licenseFile) diff --git a/gradle.properties b/gradle.properties index 8bab09fc31f..cc026dc93d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,29 +1,26 @@ +projectVersion=9.0.0-SNAPSHOT title=Grails GORM projectDesc=GORM - Grails Data Access Framework projectUrl=https://gorm.grails.org/ -projectVersion=8.1.3-SNAPSHOT githubSlug=grails/grails-data-mapping -developers=Graeme Rocher,Jeff Brown,Burt Beckwith,James Kleeh,Puneet Behl -hibernateValidatorVersion=6.2.5.Final -jpaVersion=2.2 -jtaVersion=1.1 -javaAnnotationApiVersion=1.3.2 -elVersion=3.0.0 -commonsValidatorVersion=1.8.0 +developers=Graeme Rocher,Jeff Brown,Burt Beckwith,James Kleeh,Puneet Behl,James Fredley + +cloverVersion=4.5.2 +commonsValidatorVersion=1.9.0 hibernateVersion=5.6.15.Final -servletApiVersion=4.0.1 -spockVersion=2.1-groovy-3.0 -springVersion=5.3.33 -caffeineVersion=2.9.3 -grailsVersion=6.2.0 -grailsAsyncVersion=4.0.0 -slf4jVersion=1.7.36 -javaParserCoreVersion=3.15.14 -junitVersion=4.12 -junit-jupiter.version=5.7.0 +jakartaElVersion=4.0.0 +jakartaElGlassfishImplVersion=4.0.2 +gradleNexusPluginVersion=2.3.1 +gradleNexusPublishPluginVersion=1.3.0 +grailsAsyncVersion=6.0.0-SNAPSHOT +grailsVersion=7.0.0-SNAPSHOT +groovyVersion=4.0.24 +hibernateValidatorVersion=7.0.5.Final javassistVersion=3.30.2-GA -groovyVersion=3.0.21 +jakartaAnnotationApiVersion=3.0.0 +picocliVersion=4.7.6 +rxjavaVersion=1.3.8 org.gradle.caching=true org.gradle.parallel=true -org.gradle.daemon=true +org.gradle.daemon=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index afba109285a..a4b76b9530d 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 c7d437bbb47..94113f200e6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 65dcd68d65c..f5feea6d6b1 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,10 +85,9 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +134,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +201,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 6689b85beec..9b42019c791 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/grails-datastore-async/build.gradle b/grails-datastore-async/build.gradle index cca52e99b0f..2a5ee818122 100644 --- a/grails-datastore-async/build.gradle +++ b/grails-datastore-async/build.gradle @@ -1,6 +1,3 @@ dependencies { - api "org.grails:grails-async:$grailsAsyncVersion", { - exclude group:'io.projectreactor',module:'reactor-core' - exclude group:'io.projectreactor',module:'reactor-stream' - } + api "org.grails:grails-async:$grailsAsyncVersion" } diff --git a/grails-datastore-core/build.gradle b/grails-datastore-core/build.gradle index 40ea8af6813..dde44be576f 100644 --- a/grails-datastore-core/build.gradle +++ b/grails-datastore-core/build.gradle @@ -1,35 +1,17 @@ dependencies { - api "javax.transaction:jta:$jtaVersion" - api "org.slf4j:slf4j-api:$slf4jVersion" - api "org.slf4j:jcl-over-slf4j:$slf4jVersion" - api "javax.persistence:javax.persistence-api:$jpaVersion" - api "org.springframework:spring-core:$springVersion" , { - exclude group:'commons-logging',module:'commons-logging' - } - api "org.springframework:spring-beans:$springVersion", { - exclude group:'org.springframework', module:'spring-core' - exclude group:'commons-logging',module:'commons-logging' - } - api "org.springframework:spring-tx:$springVersion", { - exclude group:'commons-logging',module:'commons-logging' - exclude group:'org.springframework', module:'spring-context' - exclude group:'org.springframework', module:'spring-core' - exclude group:'org.springframework', module:'spring-beans' - exclude group:'org.springframework', module:'spring-aop' - } - api "org.springframework:spring-context:$springVersion", { - exclude group:'commons-logging',module:'commons-logging' - exclude group:'org.springframework', module:'spring-core' - exclude group:'org.springframework', module:'spring-expression' - exclude group:'org.springframework', module:'spring-aop' - exclude group:'org.springframework', module:'spring-beans' - exclude group:'org.springframework', module:'spring-asm' - } - implementation "com.github.ben-manes.caffeine:caffeine:$caffeineVersion" + api "jakarta.transaction:jakarta.transaction-api" + api "org.slf4j:slf4j-api" + api "org.slf4j:jcl-over-slf4j" + api "jakarta.persistence:jakarta.persistence-api" + api "org.springframework:spring-core" + api "org.springframework:spring-beans" + api "org.springframework:spring-tx" + api "org.springframework:spring-context" + implementation "com.github.ben-manes.caffeine:caffeine" implementation "org.javassist:javassist:$javassistVersion" testImplementation project(":grails-datastore-gorm") // we need the Grails @Entity annotation to test GORM syntax mapping - testImplementation("org.springframework:spring-context:$springVersion") - testImplementation("org.springframework:spring-web:$springVersion") + testImplementation "org.springframework:spring-context" + testImplementation "org.springframework:spring-web" } diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/collection/PersistentSet.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/collection/PersistentSet.java index 65bf18e6f9a..0b6d7fe536c 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/collection/PersistentSet.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/collection/PersistentSet.java @@ -20,7 +20,6 @@ import java.util.Set; import org.grails.datastore.mapping.core.Session; -import org.grails.datastore.mapping.engine.AssociationIndexer; import org.grails.datastore.mapping.engine.AssociationQueryExecutor; import org.grails.datastore.mapping.model.types.Association; @@ -56,4 +55,5 @@ protected static HashSet createCollection() { public PersistentSet(Serializable associationKey, Session session, AssociationQueryExecutor indexer) { super(associationKey, session, indexer, createCollection()); } -} + +} \ No newline at end of file diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/Property.groovy b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/Property.groovy index cb3f13d8f56..be186bfdfbf 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/Property.groovy +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/Property.groovy @@ -21,10 +21,10 @@ import groovy.transform.builder.SimpleStrategy import org.springframework.beans.MutablePropertyValues import org.springframework.validation.DataBinder -import javax.persistence.AccessType -import javax.persistence.CascadeType -import javax.persistence.EnumType -import javax.persistence.FetchType +import jakarta.persistence.AccessType +import jakarta.persistence.CascadeType +import jakarta.persistence.EnumType +import jakarta.persistence.FetchType /** * Base class for classes returned from {@link org.grails.datastore.mapping.model.PropertyMapping#getMappedForm()} diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractDatastore.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractDatastore.java index b7430833fcd..e4d34bbd4f4 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractDatastore.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractDatastore.java @@ -43,7 +43,7 @@ import org.springframework.core.env.PropertyResolver; import org.springframework.transaction.support.TransactionSynchronizationManager; -import javax.annotation.PreDestroy; +import jakarta.annotation.PreDestroy; import java.util.Map; /** diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractSession.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractSession.java index 56f117837a1..23cf3f7912a 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractSession.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/AbstractSession.java @@ -40,7 +40,7 @@ import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.util.Assert; -import javax.persistence.FlushModeType; +import jakarta.persistence.FlushModeType; import java.io.Serializable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/Session.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/Session.java index 345c9dc8bbd..89ed7cebdb2 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/Session.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/Session.java @@ -18,7 +18,7 @@ import java.util.List; import java.util.Map; -import javax.persistence.FlushModeType; +import jakarta.persistence.FlushModeType; import org.grails.datastore.mapping.engine.Persister; import org.grails.datastore.mapping.model.MappingContext; diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/connections/ConnectionSourceSettings.groovy b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/connections/ConnectionSourceSettings.groovy index abc6d5d499e..58987c3a9dc 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/connections/ConnectionSourceSettings.groovy +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/connections/ConnectionSourceSettings.groovy @@ -8,7 +8,7 @@ import org.grails.datastore.mapping.config.Settings import org.grails.datastore.mapping.engine.types.CustomTypeMarshaller import org.grails.datastore.mapping.multitenancy.MultiTenancySettings -import javax.persistence.FlushModeType +import jakarta.persistence.FlushModeType /** * Default settings shared across all implementations diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckable.groovy b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckable.groovy index b97d9c01d3a..b6a2b234f85 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckable.groovy +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/dirty/checking/DirtyCheckable.groovy @@ -3,7 +3,7 @@ package org.grails.datastore.mapping.dirty.checking import groovy.transform.CompileStatic import org.grails.datastore.mapping.proxy.EntityProxy -import javax.persistence.Transient +import jakarta.persistence.Transient /** * Interface to classes that are able to track changes to their internal state. diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/NativeEntryEntityPersister.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/NativeEntryEntityPersister.java index ea29ea37509..d3d0f7ba1fa 100755 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/NativeEntryEntityPersister.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/engine/NativeEntryEntityPersister.java @@ -28,9 +28,9 @@ import java.util.Set; import java.util.SortedSet; -import javax.persistence.CascadeType; -import javax.persistence.FetchType; -import javax.persistence.FlushModeType; +import jakarta.persistence.CascadeType; +import jakarta.persistence.FetchType; +import jakarta.persistence.FlushModeType; import org.grails.datastore.mapping.cache.TPCacheAdapterRepository; import org.grails.datastore.mapping.collection.AbstractPersistentCollection; diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/config/GormMappingConfigurationStrategy.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/config/GormMappingConfigurationStrategy.java index 45bc35663df..192ae2031e4 100755 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/config/GormMappingConfigurationStrategy.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/config/GormMappingConfigurationStrategy.java @@ -33,7 +33,7 @@ import java.util.Map; import java.util.Set; -import javax.persistence.Entity; +import jakarta.persistence.Entity; import groovy.lang.MetaBeanProperty; import groovy.lang.MetaProperty; diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/config/JpaMappingConfigurationStrategy.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/config/JpaMappingConfigurationStrategy.java index 0786a4531f2..680e3c60aae 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/config/JpaMappingConfigurationStrategy.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/config/JpaMappingConfigurationStrategy.java @@ -15,7 +15,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; -import javax.persistence.*; +import jakarta.persistence.*; @SuppressWarnings({"rawtypes", "unchecked", "Duplicates"}) public class JpaMappingConfigurationStrategy extends GormMappingConfigurationStrategy { diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/types/Association.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/types/Association.java index 0b5fa3a1991..a68efe8a503 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/types/Association.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/types/Association.java @@ -17,8 +17,8 @@ import java.beans.PropertyDescriptor; import java.util.*; -import javax.persistence.CascadeType; -import javax.persistence.FetchType; +import jakarta.persistence.CascadeType; +import jakarta.persistence.FetchType; import org.grails.datastore.mapping.config.Property; import org.grails.datastore.mapping.dirty.checking.DirtyCheckable; diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/types/ToMany.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/types/ToMany.java index 1b8c4924e4f..e0405f41b2b 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/types/ToMany.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/model/types/ToMany.java @@ -19,7 +19,7 @@ import org.grails.datastore.mapping.model.MappingContext; import org.grails.datastore.mapping.model.PersistentEntity; -import javax.persistence.FetchType; +import jakarta.persistence.FetchType; import java.beans.PropertyDescriptor; /** diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/multitenancy/TenantDataSourceConfig.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/multitenancy/TenantDataSourceConfig.java index c19a37d2772..f32b344527b 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/multitenancy/TenantDataSourceConfig.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/multitenancy/TenantDataSourceConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/query/Query.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/query/Query.java index 0a3f48da899..956e3d5d49a 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/query/Query.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/query/Query.java @@ -29,10 +29,10 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import javax.persistence.FetchType; -import javax.persistence.FlushModeType; -import javax.persistence.LockModeType; -import javax.persistence.criteria.JoinType; +import jakarta.persistence.FetchType; +import jakarta.persistence.FlushModeType; +import jakarta.persistence.LockModeType; +import jakarta.persistence.criteria.JoinType; import java.io.Serializable; import java.util.*; import java.util.regex.Pattern; diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/query/api/BuildableCriteria.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/query/api/BuildableCriteria.java index fe95817aea4..be367aa941e 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/query/api/BuildableCriteria.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/query/api/BuildableCriteria.java @@ -18,7 +18,7 @@ import groovy.lang.Closure; import groovy.lang.DelegatesTo; -import javax.persistence.criteria.JoinType; +import jakarta.persistence.criteria.JoinType; import java.util.Map; /** diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/reflect/AstUtils.groovy b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/reflect/AstUtils.groovy index 6d4c40e51bc..b5945ca6b67 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/reflect/AstUtils.groovy +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/reflect/AstUtils.groovy @@ -52,7 +52,7 @@ import org.codehaus.groovy.transform.trait.Traits import org.springframework.util.StringUtils import static org.codehaus.groovy.ast.tools.GenericsUtils.correctToGenericsSpecRecurse -import javax.persistence.Entity +import jakarta.persistence.Entity import java.lang.annotation.Annotation import java.lang.reflect.Modifier import java.util.regex.Pattern diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/transactions/DatastoreTransactionManager.java b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/transactions/DatastoreTransactionManager.java index 859bbfba0f5..6fa6b979a9c 100644 --- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/transactions/DatastoreTransactionManager.java +++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/transactions/DatastoreTransactionManager.java @@ -14,7 +14,7 @@ */ package org.grails.datastore.mapping.transactions; -import javax.persistence.FlushModeType; +import jakarta.persistence.FlushModeType; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; diff --git a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/config/ConfigurationBuilderSpec.groovy b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/config/ConfigurationBuilderSpec.groovy index edf69a3813f..ef8493a7eed 100644 --- a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/config/ConfigurationBuilderSpec.groovy +++ b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/config/ConfigurationBuilderSpec.groovy @@ -7,7 +7,7 @@ import org.springframework.core.env.PropertyResolver import org.springframework.util.ReflectionUtils import spock.lang.Specification -import javax.persistence.FlushModeType +import jakarta.persistence.FlushModeType import java.lang.reflect.Method import java.lang.reflect.Modifier import java.util.concurrent.TimeUnit diff --git a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/GormMappingInheritanceTests.groovy b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/GormMappingInheritanceTests.groovy index d9f20ea5074..0f9d1ad3779 100644 --- a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/GormMappingInheritanceTests.groovy +++ b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/GormMappingInheritanceTests.groovy @@ -1,8 +1,11 @@ package org.grails.datastore.mapping.model +import org.junit.jupiter.api.Disabled + import grails.gorm.annotation.Entity import org.grails.datastore.mapping.model.types.* import org.junit.jupiter.api.Test +import spock.lang.Ignore import static org.junit.jupiter.api.Assertions.* @@ -188,4 +191,4 @@ class DerivedEntityChildB extends DerivedEntity { @Entity class DerivedEntityChildC extends DerivedEntity { -} +} \ No newline at end of file diff --git a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/GormMappingSyntaxTests.groovy b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/GormMappingSyntaxTests.groovy index 574be189946..702aec13028 100644 --- a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/GormMappingSyntaxTests.groovy +++ b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/GormMappingSyntaxTests.groovy @@ -156,7 +156,7 @@ class GormMappingSyntaxTests { } - @javax.persistence.Entity + @jakarta.persistence.Entity class JavaEntity {} } @@ -193,9 +193,9 @@ class TestEntity { SecondEntity second - transient String getTransientMethodProperty() {} + String getTransientMethodProperty() {} - transient void setTransientMethodProperty(String value) {} + void setTransientMethodProperty(String value) {} static hasOne = [second:SecondEntity] static transients = ['bar'] diff --git a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/JpaMappingSyntaxTests.groovy b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/JpaMappingSyntaxTests.groovy index a18a0cc4817..c81eb1087cd 100644 --- a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/JpaMappingSyntaxTests.groovy +++ b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/JpaMappingSyntaxTests.groovy @@ -3,7 +3,7 @@ package org.grails.datastore.mapping.model import org.grails.datastore.mapping.model.config.JpaMappingConfigurationStrategy import org.grails.datastore.mapping.model.types.Association import spock.lang.Specification -import javax.persistence.* +import jakarta.persistence.* /** * Created by jameskleeh on 12/21/16. @@ -262,11 +262,11 @@ class JpaMappingSyntaxTests extends Specification { } - @javax.persistence.Entity + @jakarta.persistence.Entity class JavaEntity {} } -@javax.persistence.Entity +@jakarta.persistence.Entity class JpaPerson { @Id Long id @@ -277,7 +277,7 @@ class JpaPerson { Set roles } -@javax.persistence.Entity +@jakarta.persistence.Entity class JpaAuthority { @Id Long id @@ -289,7 +289,7 @@ class JpaAuthority { } -@javax.persistence.Entity +@jakarta.persistence.Entity class JpaBook { @Id Long id @@ -303,7 +303,7 @@ class JpaBook { JpaSimpleEntity simple } -@javax.persistence.Entity +@jakarta.persistence.Entity class JpaAuthor { @Id Long id @@ -316,7 +316,7 @@ class JpaAuthor { def shouldBeIgnored } -@javax.persistence.Entity +@jakarta.persistence.Entity class JpaPublisher { @Id Long id @@ -325,7 +325,7 @@ class JpaPublisher { Set authors } -@javax.persistence.Entity +@jakarta.persistence.Entity class JpaTestEntity { @Id Long customId @@ -342,7 +342,7 @@ class JpaTestEntity { JpaSecondEntity third } -@javax.persistence.Entity +@jakarta.persistence.Entity class JpaSecondEntity { @Id Long id diff --git a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/types/AssociationCascadeOperationsSpec.groovy b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/types/AssociationCascadeOperationsSpec.groovy index d401f6999f9..542883c0a62 100644 --- a/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/types/AssociationCascadeOperationsSpec.groovy +++ b/grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/model/types/AssociationCascadeOperationsSpec.groovy @@ -6,7 +6,7 @@ import org.grails.datastore.mapping.model.PropertyMapping import spock.lang.Specification import spock.lang.Unroll -import javax.persistence.CascadeType +import jakarta.persistence.CascadeType class AssociationCascadeOperationsSpec extends Specification { diff --git a/grails-datastore-gorm-rx/build.gradle b/grails-datastore-gorm-rx/build.gradle index a8c24237923..71f3618c754 100644 --- a/grails-datastore-gorm-rx/build.gradle +++ b/grails-datastore-gorm-rx/build.gradle @@ -1,5 +1,5 @@ dependencies { - api 'io.reactivex:rxjava:1.3.8' + api "io.reactivex:rxjava:$rxjavaVersion" api project(":grails-datastore-gorm"), { exclude group:"org.grails", module:'grails-async' exclude group:"org.grails", module:'grails-datastore-core' @@ -7,6 +7,6 @@ dependencies { api project(":grails-datastore-core") implementation "org.javassist:javassist:$javassistVersion" compileOnly("org.hibernate:hibernate-validator:$hibernateValidatorVersion") - documentation "org.springframework:spring-beans:$springVersion" + documentation "org.springframework:spring-beans" documentation "org.grails:grails-async:$grailsAsyncVersion" } diff --git a/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/DetachedCriteria.groovy b/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/DetachedCriteria.groovy index b002bfcf7da..1683d22eb82 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/DetachedCriteria.groovy +++ b/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/DetachedCriteria.groovy @@ -15,7 +15,7 @@ import rx.Observable import rx.Subscriber import rx.Subscription -import javax.persistence.FetchType +import jakarta.persistence.FetchType /** * Reactive version of {@link grails.gorm.DetachedCriteria} diff --git a/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/collection/RxPersistentCollection.java b/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/collection/RxPersistentCollection.java index 271222b656d..21df5077cd2 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/collection/RxPersistentCollection.java +++ b/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/collection/RxPersistentCollection.java @@ -11,7 +11,7 @@ * @author Graeme Rocher * @since 6.0 */ -public interface RxPersistentCollection extends PersistentCollection, ObservableCollection { +public interface RxPersistentCollection extends PersistentCollection, ObservableCollection { } diff --git a/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/multitenancy/Tenants.groovy b/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/multitenancy/Tenants.groovy index 2b56e8b9f29..855b8819858 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/multitenancy/Tenants.groovy +++ b/grails-datastore-gorm-rx/src/main/groovy/grails/gorm/rx/multitenancy/Tenants.groovy @@ -17,7 +17,7 @@ import org.grails.gorm.rx.api.RxGormEnhancer */ @CompileStatic @Slf4j -class Tenants extends grails.gorm.multitenancy.Tenants { +class Tenants { /** * Execute the given closure for each tenant. * diff --git a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/AbstractRxDatastoreClient.groovy b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/AbstractRxDatastoreClient.groovy index a027ca1e2fd..8f14e6ee16f 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/AbstractRxDatastoreClient.groovy +++ b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/AbstractRxDatastoreClient.groovy @@ -2,8 +2,6 @@ package org.grails.datastore.rx import grails.gorm.rx.proxy.ObservableProxy import groovy.transform.CompileStatic -import org.grails.datastore.gorm.validation.constraints.registry.DefaultValidatorRegistry -import org.grails.datastore.gorm.validation.javax.JavaxValidatorRegistry import org.grails.datastore.gorm.validation.registry.support.ValidatorRegistries import org.grails.datastore.mapping.collection.PersistentCollection import org.grails.datastore.mapping.config.Property @@ -50,7 +48,7 @@ import org.springframework.context.MessageSourceAware import org.springframework.context.support.StaticMessageSource import rx.Observable -import javax.persistence.CascadeType +import jakarta.persistence.CascadeType /** * Abstract implementation the {@link RxDatastoreClient} interface * diff --git a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxCollection.groovy b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxCollection.groovy index 8e9964fc7d4..c716f60f18b 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxCollection.groovy +++ b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxCollection.groovy @@ -13,7 +13,7 @@ import rx.Subscription * @since 6.0 */ @CompileStatic -trait RxCollection implements ObservableCollection{ +trait RxCollection implements ObservableCollection{ /** * The underlying observable diff --git a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentList.groovy b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentList.groovy index 06dfc267673..6455b1f2277 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentList.groovy +++ b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentList.groovy @@ -25,7 +25,7 @@ import rx.Subscription */ //@CompileStatic @Slf4j -class RxPersistentList extends PersistentList implements RxPersistentCollection, RxUnidirectionalCollection , RxCollection{ +class RxPersistentList extends PersistentList implements RxPersistentCollection, RxUnidirectionalCollection , RxCollection{ final RxDatastoreClient datastoreClient final Association association diff --git a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentSet.groovy b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentSet.groovy index 6df6baedb12..33fa69afc82 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentSet.groovy +++ b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentSet.groovy @@ -24,7 +24,7 @@ import rx.Subscription */ @CompileStatic @Slf4j -class RxPersistentSet extends PersistentSet implements RxPersistentCollection, RxUnidirectionalCollection, RxCollection { +class RxPersistentSet extends PersistentSet implements RxPersistentCollection, RxUnidirectionalCollection, RxCollection { final RxDatastoreClient datastoreClient final Association association diff --git a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentSortedSet.groovy b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentSortedSet.groovy index 75dab79a171..5dc0fdefdca 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentSortedSet.groovy +++ b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/collection/RxPersistentSortedSet.groovy @@ -4,7 +4,7 @@ import grails.gorm.rx.collection.RxPersistentCollection import grails.gorm.rx.collection.RxUnidirectionalCollection import groovy.transform.CompileStatic import groovy.util.logging.Slf4j -import org.grails.datastore.mapping.collection.PersistentSet +import org.grails.datastore.mapping.collection.PersistentSortedSet import org.grails.datastore.mapping.model.types.Association import org.grails.datastore.mapping.query.Query import org.grails.datastore.rx.RxDatastoreClient @@ -25,14 +25,14 @@ import rx.Subscription @CompileStatic @Slf4j -class RxPersistentSortedSet extends PersistentSet implements SortedSet, RxPersistentCollection, RxUnidirectionalCollection, RxCollection { +class RxPersistentSortedSet extends PersistentSortedSet implements RxPersistentCollection, RxUnidirectionalCollection, RxCollection { final RxDatastoreClient datastoreClient final Association association protected final QueryState queryState RxPersistentSortedSet( RxDatastoreClient datastoreClient, Association association, Serializable associationKey, QueryState queryState = null) { - super(association, associationKey, null, new TreeSet()) + super(association, associationKey, null) this.datastoreClient = datastoreClient this.association = association this.queryState = queryState diff --git a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/query/RxQueryUtils.groovy b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/query/RxQueryUtils.groovy index b3b96b4e0df..e3b8bb2207b 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/query/RxQueryUtils.groovy +++ b/grails-datastore-gorm-rx/src/main/groovy/org/grails/datastore/rx/query/RxQueryUtils.groovy @@ -16,7 +16,7 @@ import org.grails.datastore.rx.internal.RxDatastoreClientImplementor import rx.Observable import rx.functions.FuncN -import javax.persistence.FetchType +import jakarta.persistence.FetchType /** * Utility methods for building Query implementations diff --git a/grails-datastore-gorm-rx/src/main/groovy/org/grails/gorm/rx/transform/RxScheduleIOTransformation.groovy b/grails-datastore-gorm-rx/src/main/groovy/org/grails/gorm/rx/transform/RxScheduleIOTransformation.groovy index 80e11ea3677..e3b1e321d8e 100644 --- a/grails-datastore-gorm-rx/src/main/groovy/org/grails/gorm/rx/transform/RxScheduleIOTransformation.groovy +++ b/grails-datastore-gorm-rx/src/main/groovy/org/grails/gorm/rx/transform/RxScheduleIOTransformation.groovy @@ -109,7 +109,7 @@ class RxScheduleIOTransformation extends AbstractMethodDecoratingTransformation } Expression returnExpr = rs?.expression if (returnExpr instanceof CastExpression) { - ((CastExpression) returnExpr).setType(newReturnType) + returnExpr = CastExpression.asExpression(newReturnType, returnExpr) } } } diff --git a/grails-datastore-gorm-rx/src/test/groovy/org/grails/gorm/rx/services/implementers/ObservableServiceTransformSpec.groovy b/grails-datastore-gorm-rx/src/test/groovy/org/grails/gorm/rx/services/implementers/ObservableServiceTransformSpec.groovy index b18a6906d75..7fe208f0ae3 100644 --- a/grails-datastore-gorm-rx/src/test/groovy/org/grails/gorm/rx/services/implementers/ObservableServiceTransformSpec.groovy +++ b/grails-datastore-gorm-rx/src/test/groovy/org/grails/gorm/rx/services/implementers/ObservableServiceTransformSpec.groovy @@ -73,7 +73,7 @@ return Book.classLoader Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* import org.grails.gorm.rx.services.implementers.* @Service(value = Foo, adapters = [ObservableServiceImplementerAdapter]) @@ -384,19 +384,19 @@ return Book.classLoader } } -//@Entity -//class Book { -// String title -//} -// -// -//@Service(Book) -//abstract class BookService { -// abstract Observable find(String title) -// -// Observable findOne(title) { -// RxServiceSupport.create { -// Book.findWhere(title:title) -// } -// } -//} +@Entity +class Book { + String title +} + + +@Service(Book) +abstract class BookService { + abstract Observable find(String title) + + Observable findOne(title) { + RxServiceSupport.create { + Book.findWhere(title:title) + } + } +} diff --git a/grails-datastore-gorm-support/build.gradle b/grails-datastore-gorm-support/build.gradle index dc4b2a3a123..7830c27cc86 100644 --- a/grails-datastore-gorm-support/build.gradle +++ b/grails-datastore-gorm-support/build.gradle @@ -1,53 +1,13 @@ dependencies { api project(':grails-datastore-gorm') - api("org.grails:grails-core:$grailsVersion") { - exclude group:'org.hibernate.javax.persistence', module:'hibernate-jpa-2.1-api' - exclude group:'aopalliance',module:'aopalliance' - exclude group:'commons-logging',module:'commons-logging' - exclude group:'commons-lang',module:'commons-lang' - // TODO: When the commons-collection dependency on grails-core is removed, then uncomment this -// exclude group:'commons-collections',module:'commons-collections' - exclude group:'commons-io',module:'commons-io' - exclude group:'org.grails',module:'grails-spring' - exclude group:'org.grails',module:'grails-bootstrap' - exclude group:'org.aspectj',module:'aspectjweaver' - exclude group:'org.aspectj',module:'aspectjrt' - exclude group:'oro',module:'oro' - exclude group:'asm',module:'asm' - exclude group:'cglib',module:'cglib' - exclude group:'cglib', module:'cglib-nodep' - exclude group:'xalan',module:'serializer' - exclude group:'org.springframework',module:'spring-aspects' - exclude group:'org.springframework',module:'spring-beans' - exclude group:'org.springframework',module:'spring-context' - exclude group:'org.springframework',module:'spring-context-support' - exclude group:'org.springframework',module:'spring-expression' - exclude group:'org.springframework',module:'spring-web' - exclude group:'org.springframework',module:'spring-aop' - exclude group:'commons-logging',module:'commons-logging' - exclude group:'commons-validator',module:'commons-validator' - exclude group:'com.googlecode.concurrentlinkedhashmap',module:'concurrentlinkedhashmap-lru' - } - api("org.grails:grails-bootstrap:$grailsVersion") { - exclude group:'org.codehaus.groovy', module:'groovy-ant' - exclude group:'org.codehaus.groovy', module:'groovy-xml' - exclude group:'org.apache.ant',module:'ant' - exclude group:'org.apache.ant',module:'ant-launcher' - exclude group:'org.apache.ant',module:'ant-trax' - exclude group:'org.apache.ant',module:'ant-junit' - exclude group:'org.apache.ant',module:'ant' - exclude group:'org.apache.ivy',module:'ivy' - exclude group:'org.codehaus.gant',module:'gant_groovy1.8' - exclude group:'jline',module:'jline' - exclude group:'org.fusesource.jansi',module:'jansi' - exclude group:'net.java.dev.jna',module:'jna' - } + api "org.grails:grails-core:$grailsVersion" + api "org.grails:grails-bootstrap:$grailsVersion" - compileOnly "org.springframework:spring-orm:$springVersion" - compileOnly "org.springframework:spring-webmvc:$springVersion" - compileOnly "org.grails:grails-web-url-mappings:$grailsVersion", { transitive = false } - compileOnly "org.grails:grails-web-common:$grailsVersion", { transitive = false } - compileOnly("org.hibernate:hibernate-core:${hibernateVersion}") { + compileOnly "org.springframework:spring-orm" + compileOnly "org.springframework:spring-webmvc" + compileOnly "org.grails:grails-web-url-mappings:" + compileOnly "org.grails:grails-web-common" + compileOnly("org.hibernate:hibernate-core-jakarta:$hibernateVersion") { exclude group:'commons-logging', module:'commons-logging' exclude group:'commons-collections', module:'commons-collections' exclude group:'org.slf4j', module:'slf4j-api' diff --git a/grails-datastore-gorm-tck/build.gradle b/grails-datastore-gorm-tck/build.gradle index c55fbeee717..eb2704c788e 100644 --- a/grails-datastore-gorm-tck/build.gradle +++ b/grails-datastore-gorm-tck/build.gradle @@ -1,10 +1,9 @@ dependencies { - api "org.springframework:spring-expression:$springVersion" - api 'commons-lang:commons-lang:2.6' + api "org.springframework:spring-expression" api project(":grails-datastore-gorm-async") api project(":grails-datastore-gorm-support") - api("javax.servlet:javax.servlet-api:$servletApiVersion") - runtimeOnly "org.codehaus.groovy:groovy-dateutil:$groovyVersion" + api("jakarta.servlet:jakarta.servlet-api") + runtimeOnly "org.apache.groovy:groovy-dateutil:$groovyVersion" } //compileGroovy.groovyOptions.fork = false diff --git a/grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/DirtyCheckingSpec.groovy b/grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/DirtyCheckingSpec.groovy index 4aa7521ea64..ceebc987cc8 100644 --- a/grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/DirtyCheckingSpec.groovy +++ b/grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/DirtyCheckingSpec.groovy @@ -151,7 +151,7 @@ class DirtyCheckingSpec extends GormDatastoreSpec { TestAuthor.deleteAll() } - @IgnoreIf({ Boolean.getBoolean("hibernate5.gorm.suite")}) // because one-to-one association loads eagerly in the Hibernate + @IgnoreIf({ Boolean.getBoolean("hibernate5.gorm.suite") || Boolean.getBoolean("hibernate6.gorm.suite")}) // because one-to-one association loads eagerly in the Hibernate void "test initialized proxy is not marked as dirty"() { given: diff --git a/grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/InheritanceSpec.groovy b/grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/InheritanceSpec.groovy index 697d7677dda..25baee0b190 100644 --- a/grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/InheritanceSpec.groovy +++ b/grails-datastore-gorm-tck/src/main/groovy/grails/gorm/tests/InheritanceSpec.groovy @@ -15,61 +15,61 @@ class InheritanceSpec extends GormDatastoreSpec { void "Test inheritance with dynamic finder"() { given: - def city = new City([code: "UK", name: "London", longitude: 49.1, latitude: 53.1]) - def country = new Country([code: "UK", name: "United Kingdom", population: 10000000]) + def city = new City([code: "UK", name: "London", longitude: 49.1, latitude: 53.1]) + def country = new Country([code: "UK", name: "United Kingdom", population: 10000000]) - city.save() - country.save(flush:true) - session.clear() + city.save() + country.save(flush:true) + session.clear() when: - def locations = Location.findAllByCode("UK") - def cities = City.findAllByCode("UK") - def countries = Country.findAllByCode("UK") + def locations = Location.findAllByCode("UK") + def cities = City.findAllByCode("UK") + def countries = Country.findAllByCode("UK") then: - 2 == locations.size() - 1 == cities.size() - 1 == countries.size() - "London" == cities[0].name - "United Kingdom" == countries[0].name + 2 == locations.size() + 1 == cities.size() + 1 == countries.size() + "London" == cities[0].name + "United Kingdom" == countries[0].name } void "Test querying with inheritance"() { given: - def city = new City([code: "LON", name: "London", longitude: 49.1, latitude: 53.1]) - def location = new Location([code: "XX", name: "The World"]) - def country = new Country([code: "UK", name: "United Kingdom", population: 10000000]) + def city = new City([code: "LON", name: "London", longitude: 49.1, latitude: 53.1]) + def location = new Location([code: "XX", name: "The World"]) + def country = new Country([code: "UK", name: "United Kingdom", population: 10000000]) - country.save() - city.save() - location.save() + country.save() + city.save() + location.save() - session.flush() + session.flush() when: - city = City.get(city.id) - def london = Location.get(city.id) - country = Location.findByName("United Kingdom") - def london2 = Location.findByName("London") + city = City.get(city.id) + def london = Location.get(city.id) + country = Location.findByName("United Kingdom") + def london2 = Location.findByName("London") then: - 1 == City.count() - 1 == Country.count() - 3 == Location.count() - - city != null - city instanceof City - london instanceof City - london2 instanceof City - "London" == london2.name - 49.1 == london2.longitude - "LON" == london2.code - - country instanceof Country - "UK" == country.code - 10000000 == country.population + 1 == City.count() + 1 == Country.count() + 3 == Location.count() + + city != null + city instanceof City + london instanceof City + london2 instanceof City + "London" == london2.name + 49.1 == london2.longitude + "LON" == london2.code + + country instanceof Country + "UK" == country.code + 10000000 == country.population } void "Test hasMany with inheritance should return appropriate class"() { @@ -126,4 +126,4 @@ class Country extends Location { static hasMany = [residents:Person] Set residents -} +} \ No newline at end of file diff --git a/grails-datastore-gorm-test/build.gradle b/grails-datastore-gorm-test/build.gradle index 6c5d5f7cf07..d083ed244f0 100644 --- a/grails-datastore-gorm-test/build.gradle +++ b/grails-datastore-gorm-test/build.gradle @@ -2,12 +2,11 @@ dependencies { api project(":grails-datastore-gorm"), project(":grails-datastore-core") - implementation "com.github.ben-manes.caffeine:caffeine:$caffeineVersion" + implementation "com.github.ben-manes.caffeine:caffeine" testImplementation project(":grails-datastore-gorm-rx") testImplementation project(":grails-datastore-gorm-tck") - testImplementation "org.codehaus.groovy:groovy-json:$groovyVersion" - testRuntimeOnly "org.springframework:spring-aop:$springVersion" - testRuntimeOnly "log4j:log4j:1.2.17" + testImplementation "org.apache.groovy:groovy-json:$groovyVersion" + testRuntimeOnly "org.springframework:spring-aop" } //compileTestGroovy.groovyOptions.forkOptions.jvmArgs = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'] diff --git a/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/RxServiceImplSpec.groovy b/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/RxServiceImplSpec.groovy index 2bbc5240a0e..d89c055822b 100644 --- a/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/RxServiceImplSpec.groovy +++ b/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/RxServiceImplSpec.groovy @@ -4,9 +4,9 @@ import grails.gorm.annotation.Entity import org.grails.datastore.gorm.services.Implemented import org.grails.datastore.gorm.services.implementers.DeleteImplementer import org.grails.datastore.mapping.simple.SimpleMapDatastore -import org.grails.gorm.rx.services.implementers.ObservableServiceImplementerAdapter import rx.Single import spock.lang.AutoCleanup +import spock.lang.PendingFeature import spock.lang.Specification /** @@ -17,7 +17,7 @@ class RxServiceImplSpec extends Specification { Book ) - + @PendingFeature(reason="bookService.countByTitleLike(The%).toBlocking().value() == 1") void "test find method that returns an observable"() { given: new Book(title: "The Stand").save(flush:true) @@ -32,6 +32,7 @@ class RxServiceImplSpec extends Specification { bookService.findByTitleLike("The%").toBlocking().first().title == "The Stand" } + @PendingFeature(reason="org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '1' with class 'java.lang.Long' to class 'rx.Single'") void "test delete method"() { given: new Book(title: "The Stand").save(flush:true) @@ -54,6 +55,7 @@ class RxServiceImplSpec extends Specification { } + @PendingFeature(reason="org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'grails.gorm.services.Book : 1' with class 'grails.gorm.services.Book' to class 'rx.Single'") void "test find and delete method"() { given: new Book(title: "The Stand").save(flush:true) @@ -75,6 +77,7 @@ class RxServiceImplSpec extends Specification { } + @PendingFeature(reason="Expected exception of type 'java.lang.UnsupportedOperationException', but got 'groovy.lang.MissingMethodException'") void "test find with string query method"() { given: new Book(title: "The Stand").save(flush:true) @@ -95,6 +98,7 @@ class RxServiceImplSpec extends Specification { } + @PendingFeature(reason="org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[grails.gorm.services.Book : 2]' with class 'java.util.ArrayList' to class 'rx.Observable' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: rx.Observable(grails.gorm.services.Book)") void "test find with where query method"() { given: new Book(title: "The Stand").save(flush:true) @@ -110,6 +114,7 @@ class RxServiceImplSpec extends Specification { } + @PendingFeature(reason="org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'grails.gorm.services.Book : 1' with class 'grails.gorm.services.Book' to class 'rx.Single'") void "test save method"() { given: BookService bookService = datastore.getService(BookService) @@ -143,6 +148,7 @@ class RxServiceImplSpec extends Specification { } + @PendingFeature(reason="groovy.lang.MissingMethodException: No signature of method: grails.gorm.services.BookServiceImplementation.findBookAuthor() is applicable for argument types: (String) values: [The Stand]") void "test simple projection"() { given: @@ -168,10 +174,14 @@ class Book { @Service(value = Book) interface BookService { - Single findBookAuthor(String title) +// Cannot implement method for argument [title]. No property exists on domain class [java.lang.String] + //Single findBookAuthor(String title) + +// No implementations possible for method 'rx.Observable updateBook(java.lang.String, java.lang.String)'. Please use an abstract class instead and provide an implementation. + //@Query("update ${Book b} set $b.title = $title where $b.title = $oldTitle") - @Query("update ${Book b} set $b.title = $title where $b.title = $oldTitle") - rx.Observable updateBook(String oldTitle, String title) +// No implementations possible for method 'rx.Observable updateBook(java.lang.String, java.lang.String)'. Please use an abstract class instead and provide an implementation. + //rx.Observable updateBook(String oldTitle, String title) Single updateBook(Serializable id, String title) diff --git a/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/ServiceImplSpec.groovy b/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/ServiceImplSpec.groovy index a0f45d71e01..956c577b983 100644 --- a/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/ServiceImplSpec.groovy +++ b/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/ServiceImplSpec.groovy @@ -3,7 +3,8 @@ package grails.gorm.services import grails.gorm.annotation.Entity import grails.gorm.validation.PersistentEntityValidator import grails.validation.ValidationException -import groovy.json.JsonOutput +import groovy.json.DefaultJsonGenerator +import groovy.json.JsonGenerator import org.grails.datastore.gorm.validation.constraints.eval.DefaultConstraintEvaluator import org.grails.datastore.gorm.validation.constraints.registry.DefaultConstraintRegistry import org.grails.datastore.gorm.validation.constraints.registry.DefaultValidatorRegistry @@ -19,7 +20,7 @@ import spock.lang.Specification class ServiceImplSpec extends Specification { @AutoCleanup SimpleMapDatastore datastore = new SimpleMapDatastore( - Product + Product ) def setup() { @@ -167,7 +168,7 @@ class ServiceImplSpec extends Specification { def evaluator = new DefaultConstraintEvaluator(new DefaultConstraintRegistry(messageSource), mappingContext, Collections.emptyMap()) mappingContext.addEntityValidator( entity, - new PersistentEntityValidator(entity, messageSource, evaluator) + new PersistentEntityValidator(entity, messageSource, evaluator) ) ProductService productService = datastore.getService(ProductService) @@ -318,7 +319,9 @@ class ServiceImplSpec extends Specification { ProductInfo info = productService.findProductInfo("Pumpkin", "Vegetable") List infos = productService.findProductInfos( "Vegetable") - def result = JsonOutput.toJson(info) + + // groovy4 will include the generated methods in output of json, which recursively refer to themselves + def result = new DefaultJsonGenerator(new JsonGenerator.Options().excludeFieldsByName("\$target")).toJson(info) then: infos.size() == 2 infos.first().name == "Carrot" @@ -495,4 +498,4 @@ interface ProductService { Iterable findEvenMoreProducts() Iterable findByName(String n) -} +} \ No newline at end of file diff --git a/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/multitenancy/partitioned/PartitionMultiTenancySpec.groovy b/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/multitenancy/partitioned/PartitionMultiTenancySpec.groovy index 392763c8103..05129f34d96 100644 --- a/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/multitenancy/partitioned/PartitionMultiTenancySpec.groovy +++ b/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/multitenancy/partitioned/PartitionMultiTenancySpec.groovy @@ -1,10 +1,8 @@ package grails.gorm.services.multitenancy.partitioned - import grails.gorm.MultiTenant import grails.gorm.annotation.Entity import grails.gorm.multitenancy.CurrentTenant -import grails.gorm.multitenancy.Tenants import grails.gorm.multitenancy.WithoutTenant import grails.gorm.services.Service import grails.gorm.transactions.ReadOnly diff --git a/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/multitenancy/schema/SchemaPerTenantSpec.groovy b/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/multitenancy/schema/SchemaPerTenantSpec.groovy index cc62662f4ca..fc46ff5e544 100644 --- a/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/multitenancy/schema/SchemaPerTenantSpec.groovy +++ b/grails-datastore-gorm-test/src/test/groovy/grails/gorm/services/multitenancy/schema/SchemaPerTenantSpec.groovy @@ -28,6 +28,7 @@ class SchemaPerTenantSpec extends Specification { def setup() { System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, "") } + void 'Test schema per tenant'() { when:"When there is no tenant" Book.count() diff --git a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/BidirectionalOneToManyWithInheritanceSpec.groovy b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/BidirectionalOneToManyWithInheritanceSpec.groovy index 26ce3116739..f7f7a3e8c13 100644 --- a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/BidirectionalOneToManyWithInheritanceSpec.groovy +++ b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/BidirectionalOneToManyWithInheritanceSpec.groovy @@ -1,3 +1,5 @@ +package org.grails.datastore.gorm + import grails.gorm.tests.GormDatastoreSpec import grails.persistence.Entity @@ -9,18 +11,18 @@ class BidirectionalOneToManyWithInheritanceSpec extends GormDatastoreSpec { void "Test a bidirectional one-to-many association with inheritance"() { given: - def doc = new Documentation() + def doc = new Documentation() - doc.addToConfigurationItems(new ChangeRequest()) + doc.addToConfigurationItems(new ChangeRequest()) .addToConfigurationItems(new Documentation()) when: - doc.save(flush:true) - session.clear() - doc = Documentation.get(1) + doc.save(flush:true) + session.clear() + doc = Documentation.get(1) then: - doc.configurationItems.size() == 2 + doc.configurationItems.size() == 2 } @Override @@ -55,4 +57,4 @@ class Documentation extends ConfigurationItem { class ChangeRequest extends ConfigurationItem { Long id Long version -} +} \ No newline at end of file diff --git a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/DetachedCriteriaJpaEntitySpec.groovy b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/DetachedCriteriaJpaEntitySpec.groovy index 301bc71ab54..bef3f041903 100644 --- a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/DetachedCriteriaJpaEntitySpec.groovy +++ b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/DetachedCriteriaJpaEntitySpec.groovy @@ -2,7 +2,7 @@ package org.grails.datastore.gorm import grails.gorm.tests.GormDatastoreSpec -import javax.persistence.Entity +import jakarta.persistence.Entity import org.grails.datastore.gorm.query.transform.ApplyDetachedCriteriaTransform @@ -50,7 +50,7 @@ class DetachedCriteriaJpaEntitySpec extends GormDatastoreSpec { } -@javax.persistence.Entity +@jakarta.persistence.Entity @grails.persistence.Entity class Todo { Long id diff --git a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/InheritanceWithOneToManySpec.groovy b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/InheritanceWithOneToManySpec.groovy index 2cad64d45f9..3cfc5e6a0c9 100644 --- a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/InheritanceWithOneToManySpec.groovy +++ b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/InheritanceWithOneToManySpec.groovy @@ -10,15 +10,15 @@ class InheritanceWithOneToManySpec extends GormDatastoreSpec{ @Issue('GRAILS-9010') void "Test that a one-to-many cascades to an association featuring inheritance"() { when:"A domain model with an association featuring inheritance is saved" - def group = new Group(name:"my group") - def subMember = new SubMember(name:"my name",extraName:"extra name",externalId:'blah') - group.addToMembers subMember - group.save(failOnError:true, flush:true) - session.clear() + def group = new Group(name:"my group") + def subMember = new SubMember(name:"my name",extraName:"extra name",externalId:'blah') + group.addToMembers subMember + group.save(failOnError:true, flush:true) + session.clear() then:"The association is correctly saved" - Group.count() == 1 - SubMember.count() == 1 + Group.count() == 1 + SubMember.count() == 1 } @Override @@ -45,4 +45,4 @@ class Member { @Entity class SubMember extends Member { String extraName -} +} \ No newline at end of file diff --git a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/NestedAssociationQuerySpec.groovy b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/NestedAssociationQuerySpec.groovy index be0de281e55..bb7cbe59ffb 100644 --- a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/NestedAssociationQuerySpec.groovy +++ b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/NestedAssociationQuerySpec.groovy @@ -1,6 +1,6 @@ package org.grails.datastore.gorm -import javax.persistence.Entity +import jakarta.persistence.Entity import grails.gorm.tests.GormDatastoreSpec class NestedAssociationQuerySpec extends GormDatastoreSpec{ diff --git a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/validation/UniqueConstraintSpec.groovy b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/validation/UniqueConstraintSpec.groovy index d8fb67150e1..72b26fcb7f7 100644 --- a/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/validation/UniqueConstraintSpec.groovy +++ b/grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/validation/UniqueConstraintSpec.groovy @@ -1,6 +1,5 @@ package org.grails.datastore.gorm.validation - import grails.gorm.annotation.Entity import grails.gorm.transactions.Transactional import org.grails.datastore.gorm.validation.constraints.MappingContextAwareConstraintFactory diff --git a/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/NullableConstraint.java b/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/NullableConstraint.java index ed988f60973..6bc643e0e0e 100644 --- a/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/NullableConstraint.java +++ b/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/NullableConstraint.java @@ -25,7 +25,7 @@ public boolean isNullable() { } /* (non-Javadoc) - * @see org.codehaus.groovy.grails.validation.Constraint#supports(java.lang.Class) + * @see org.apache.groovy.grails.validation.Constraint#supports(java.lang.Class) */ @SuppressWarnings("rawtypes") public boolean supports(Class type) { diff --git a/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/RangeConstraint.java b/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/RangeConstraint.java index d9b5a7b28c4..2c16b87ea5d 100644 --- a/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/RangeConstraint.java +++ b/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/RangeConstraint.java @@ -29,7 +29,7 @@ public Range getRange() { } /* (non-Javadoc) - * @see org.codehaus.groovy.grails.validation.Constraint#supports(java.lang.Class) + * @see org.apache.groovy.grails.validation.Constraint#supports(java.lang.Class) */ public boolean supports(Class type) { return type != null && (Comparable.class.isAssignableFrom(type) || diff --git a/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/ScaleConstraint.java b/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/ScaleConstraint.java index 8a16ddc1bf5..e0301754186 100644 --- a/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/ScaleConstraint.java +++ b/grails-datastore-gorm-validation/src/main/groovy/org/grails/datastore/gorm/validation/constraints/ScaleConstraint.java @@ -42,7 +42,7 @@ public ScaleConstraint(Class constraintOwningClass, String constraintProperty /* * {@inheritDoc} - * @see org.codehaus.groovy.grails.validation.Constraint#supports(java.lang.Class) + * @see org.apache.groovy.grails.validation.Constraint#supports(java.lang.Class) */ @SuppressWarnings("rawtypes") public boolean supports(Class type) { @@ -54,7 +54,7 @@ public boolean supports(Class type) { /* * {@inheritDoc} - * @see org.codehaus.groovy.grails.validation.Constraint#getName() + * @see org.apache.groovy.grails.validation.Constraint#getName() */ public String getName() { return ConstrainedProperty.SCALE_CONSTRAINT; diff --git a/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/ImportFromSpec.groovy b/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/ImportFromSpec.groovy index a58e9ba6c1c..518d91773a3 100644 --- a/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/ImportFromSpec.groovy +++ b/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/ImportFromSpec.groovy @@ -8,7 +8,7 @@ import org.grails.datastore.mapping.model.MappingContext import org.grails.datastore.mapping.validation.ValidatorRegistry import spock.lang.Specification -import javax.persistence.Entity +import jakarta.persistence.Entity class ImportFromSpec extends Specification { diff --git a/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/PersistentEntityValidatorSpec.groovy b/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/PersistentEntityValidatorSpec.groovy index d198a08682a..a9a057c3983 100644 --- a/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/PersistentEntityValidatorSpec.groovy +++ b/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/PersistentEntityValidatorSpec.groovy @@ -16,8 +16,8 @@ import spock.lang.Issue import spock.lang.Shared import spock.lang.Specification -import javax.persistence.Entity -import javax.persistence.Transient +import jakarta.persistence.Entity +import jakarta.persistence.Transient class PersistentEntityValidatorSpec extends Specification { @Shared Validator authorValidator diff --git a/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/ValidatorRegistrySpec.groovy b/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/ValidatorRegistrySpec.groovy index 7869945c230..977dac9c897 100644 --- a/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/ValidatorRegistrySpec.groovy +++ b/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/ValidatorRegistrySpec.groovy @@ -9,7 +9,7 @@ import org.grails.datastore.mapping.validation.ValidatorRegistry import org.springframework.validation.Validator import spock.lang.Specification -import javax.persistence.Entity +import jakarta.persistence.Entity /** * Created by graemerocher on 09/06/16. diff --git a/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/cascade/NoDuplicateCascadeSpec.groovy b/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/cascade/NoDuplicateCascadeSpec.groovy index c7424363e31..0c21574591e 100644 --- a/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/cascade/NoDuplicateCascadeSpec.groovy +++ b/grails-datastore-gorm-validation/src/test/groovy/grails/gorm/validation/cascade/NoDuplicateCascadeSpec.groovy @@ -1,7 +1,7 @@ package grails.gorm.validation.cascade -import javax.persistence.Entity -import javax.persistence.Transient +import jakarta.persistence.Entity +import jakarta.persistence.Transient import org.grails.datastore.gorm.validation.constraints.registry.DefaultValidatorRegistry import org.grails.datastore.mapping.core.connections.ConnectionSourceSettings diff --git a/grails-datastore-gorm-validation/src/test/groovy/org/grails/datastore/gorm/validation/constraints/BlankConstraintSpec.groovy b/grails-datastore-gorm-validation/src/test/groovy/org/grails/datastore/gorm/validation/constraints/BlankConstraintSpec.groovy index e25fa7304c7..050568e5352 100644 --- a/grails-datastore-gorm-validation/src/test/groovy/org/grails/datastore/gorm/validation/constraints/BlankConstraintSpec.groovy +++ b/grails-datastore-gorm-validation/src/test/groovy/org/grails/datastore/gorm/validation/constraints/BlankConstraintSpec.groovy @@ -6,7 +6,7 @@ import org.springframework.context.MessageSourceResolvable import org.springframework.context.NoSuchMessageException import spock.lang.Specification -import javax.persistence.Entity +import jakarta.persistence.Entity /** * Created by gonmarques on 23/12/17. diff --git a/grails-datastore-gorm/build.gradle b/grails-datastore-gorm/build.gradle index 984be25619e..6c9d62bb6fd 100644 --- a/grails-datastore-gorm/build.gradle +++ b/grails-datastore-gorm/build.gradle @@ -2,16 +2,19 @@ dependencies { api project(":grails-datastore-core") api project(":grails-datastore-gorm-validation") - implementation "org.slf4j:slf4j-api:$slf4jVersion" - implementation("javax.el:javax.el-api:$elVersion") - runtimeOnly('org.glassfish:javax.el:3.0.1-b12') + implementation "org.slf4j:slf4j-api" + + // :grails-datastore-gorm:compileGroovy requires jakarta.el.ExpressionFactory + // required by gorm-hibernate5 test compilation + compileOnlyApi("jakarta.el:jakarta.el-api:$jakartaElVersion") + runtimeOnly "org.glassfish:jakarta.el:$jakartaElGlassfishImplVersion" compileOnly("org.hibernate:hibernate-validator:$hibernateValidatorVersion") - compileOnly("org.springframework:spring-jdbc:$springVersion") - compileOnly("org.springframework:spring-web:$springVersion") - testImplementation("org.springframework:spring-jdbc:$springVersion") + compileOnly("org.springframework:spring-jdbc") + compileOnly("org.springframework:spring-web") + testImplementation("org.springframework:spring-jdbc") testImplementation("org.hibernate:hibernate-validator:$hibernateValidatorVersion") - testRuntimeOnly('com.h2database:h2:2.2.224') + testRuntimeOnly("com.h2database:h2") } //compileGroovy.groovyOptions.forkOptions.jvmArgs = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'] diff --git a/grails-datastore-gorm/src/main/groovy/grails/gorm/CriteriaBuilder.java b/grails-datastore-gorm/src/main/groovy/grails/gorm/CriteriaBuilder.java index 39f656569f9..c7dbd1a4cbf 100644 --- a/grails-datastore-gorm/src/main/groovy/grails/gorm/CriteriaBuilder.java +++ b/grails-datastore-gorm/src/main/groovy/grails/gorm/CriteriaBuilder.java @@ -26,7 +26,7 @@ import org.grails.datastore.mapping.query.api.Criteria; import org.grails.datastore.mapping.query.api.ProjectionList; -import javax.persistence.criteria.JoinType; +import jakarta.persistence.criteria.JoinType; import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/grails-datastore-gorm/src/main/groovy/grails/gorm/DetachedCriteria.groovy b/grails-datastore-gorm/src/main/groovy/grails/gorm/DetachedCriteria.groovy index d31b56d4477..b83bd9e0063 100644 --- a/grails-datastore-gorm/src/main/groovy/grails/gorm/DetachedCriteria.groovy +++ b/grails-datastore-gorm/src/main/groovy/grails/gorm/DetachedCriteria.groovy @@ -30,7 +30,7 @@ import org.grails.datastore.mapping.query.api.QueryAliasAwareSession import org.grails.datastore.mapping.query.api.QueryArgumentsAware import org.grails.datastore.mapping.query.api.QueryableCriteria -import javax.persistence.criteria.JoinType +import jakarta.persistence.criteria.JoinType /** * Represents criteria that is not bound to the current connection and can be built up and re-used at a later date. diff --git a/grails-datastore-gorm/src/main/groovy/grails/gorm/multitenancy/Tenants.groovy b/grails-datastore-gorm/src/main/groovy/grails/gorm/multitenancy/Tenants.groovy index 1998316ebd3..d0e09ed1ba7 100644 --- a/grails-datastore-gorm/src/main/groovy/grails/gorm/multitenancy/Tenants.groovy +++ b/grails-datastore-gorm/src/main/groovy/grails/gorm/multitenancy/Tenants.groovy @@ -227,11 +227,11 @@ class Tenants { } /** - * Execute the given closure with given tenant id for the given datastore. This method will create a new datastore session for the scope of the call and hence is designed to be used to manage the connection life cycle - * @param tenantId The tenant id - * @param callable The closure - * @return The result of the closure - */ + * Execute the given closure with given tenant id for the given datastore. This method will create a new datastore session for the scope of the call and hence is designed to be used to manage the connection life cycle + * @param tenantId The tenant id + * @param callable The closure + * @return The result of the closure + */ static T withId(MultiTenantCapableDatastore multiTenantCapableDatastore, Serializable tenantId, Closure callable) { return CurrentTenant.withTenant(tenantId) { if(multiTenantCapableDatastore.getMultiTenancyMode().isSharedConnection()) { diff --git a/grails-datastore-gorm/src/main/groovy/grails/gorm/services/Join.java b/grails-datastore-gorm/src/main/groovy/grails/gorm/services/Join.java index 7da1e04625b..4bb8d7a6cbf 100644 --- a/grails-datastore-gorm/src/main/groovy/grails/gorm/services/Join.java +++ b/grails-datastore-gorm/src/main/groovy/grails/gorm/services/Join.java @@ -1,6 +1,6 @@ package grails.gorm.services; -import javax.persistence.criteria.JoinType; +import jakarta.persistence.criteria.JoinType; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/grails-datastore-gorm/src/main/groovy/grails/gorm/transactions/ReadOnly.java b/grails-datastore-gorm/src/main/groovy/grails/gorm/transactions/ReadOnly.java index 7aaba0dd12e..fef3d250a00 100644 --- a/grails-datastore-gorm/src/main/groovy/grails/gorm/transactions/ReadOnly.java +++ b/grails-datastore-gorm/src/main/groovy/grails/gorm/transactions/ReadOnly.java @@ -84,7 +84,7 @@ * a transaction rollback. *

This can be a substring, with no wildcard support at present. * A value of "ServletException" would match - * javax.servlet.ServletException and subclasses, for example. + * jakarta.servlet.ServletException and subclasses, for example. *

NB: Consider carefully how specific the pattern is, and whether * to include package information (which isn't mandatory). For example, * "Exception" will match nearly anything, and will probably hide other rules. diff --git a/grails-datastore-gorm/src/main/groovy/grails/gorm/transactions/Transactional.java b/grails-datastore-gorm/src/main/groovy/grails/gorm/transactions/Transactional.java index 284b8b85be8..d658898cef1 100644 --- a/grails-datastore-gorm/src/main/groovy/grails/gorm/transactions/Transactional.java +++ b/grails-datastore-gorm/src/main/groovy/grails/gorm/transactions/Transactional.java @@ -118,7 +118,7 @@ * a transaction rollback. *

This can be a substring, with no wildcard support at present. * A value of "ServletException" would match - * javax.servlet.ServletException and subclasses, for example. + * jakarta.servlet.ServletException and subclasses, for example. *

NB: Consider carefully how specific the pattern is, and whether * to include package information (which isn't mandatory). For example, * "Exception" will match nearly anything, and will probably hide other rules. diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/DirtyCheckingTransformer.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/DirtyCheckingTransformer.groovy index 372b08ea583..9a501684067 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/DirtyCheckingTransformer.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/DirtyCheckingTransformer.groovy @@ -50,9 +50,9 @@ class DirtyCheckingTransformer implements CompilationUnitAware { public static final AnnotationNode DIRTY_CHECKED_PROPERTY_ANNOTATION_NODE = new AnnotationNode(DIRTY_CHECKED_PROPERTY_CLASS_NODE) static { - if(ClassUtils.isPresent("javax.validation.Constraint")) { + if(ClassUtils.isPresent("jakarta.validation.Constraint")) { try { - VALIDATION_CONSTRAINT_NODE = ClassHelper.make(Class.forName("javax.validation.Constraint")) + VALIDATION_CONSTRAINT_NODE = ClassHelper.make(Class.forName("jakarta.validation.Constraint")) } catch (Throwable e) { VALIDATION_CONSTRAINT_NODE = null } @@ -127,7 +127,7 @@ class DirtyCheckingTransformer implements CompilationUnitAware { } else if (isGetter(methodName, mn)) { String propertyName = NameUtils.getPropertyNameForGetterOrSetter(methodName) - // if there are any javax.validation constraints present + // if there are any jakarta.validation constraints present def annotationNodes = mn.annotations if(!isJavaValidateable && isAnnotatedWithJavaValidationApi(annotationNodes)) { addAnnotationIfNecessary(classNode, Validated) diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GlobalJpaEntityTransform.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GlobalJpaEntityTransform.groovy index 22e2bdbeece..8f35a29a3df 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GlobalJpaEntityTransform.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GlobalJpaEntityTransform.groovy @@ -13,7 +13,7 @@ import org.codehaus.groovy.transform.ASTTransformation import org.codehaus.groovy.transform.AbstractASTTransformation import org.codehaus.groovy.transform.GroovyASTTransformation -import javax.persistence.Entity +import jakarta.persistence.Entity /** * Makes all entities annotated with @Entity JPA into GORM entities diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GlobalTraitRepairTransformation.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GlobalTraitRepairTransformation.groovy deleted file mode 100644 index 43a477ea58c..00000000000 --- a/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GlobalTraitRepairTransformation.groovy +++ /dev/null @@ -1,75 +0,0 @@ -package org.grails.compiler.gorm - -import groovy.transform.CompileStatic -import org.codehaus.groovy.ast.ASTNode -import org.codehaus.groovy.ast.ClassHelper -import org.codehaus.groovy.ast.ClassNode -import org.codehaus.groovy.ast.GenericsType -import org.codehaus.groovy.ast.MethodNode -import org.codehaus.groovy.ast.ModuleNode -import org.codehaus.groovy.control.CompilePhase -import org.codehaus.groovy.control.SourceUnit -import org.codehaus.groovy.transform.ASTTransformation -import org.codehaus.groovy.transform.GroovyASTTransformation -import org.grails.datastore.gorm.query.transform.DetachedCriteriaTransformer -import org.grails.datastore.mapping.reflect.AstUtils - -/** - * Repairs the AST due to bugs in the way {@link org.codehaus.groovy.transform.trait.TraitComposer} works. See https://issues.apache.org/jira/browse/GROOVY-7846 - * - * Once those issues are addressed this can be removed - * - * @author Graeme Rocher - * @since 6.0 - */ -@CompileStatic -@GroovyASTTransformation(phase= CompilePhase.CANONICALIZATION) -class GlobalTraitRepairTransformation implements ASTTransformation { - - private static final Object TRANSFORM_APPLIED_MARKER = new Object() - - private static final boolean ENABLED - - static { - String groovyVersion = GroovySystem.version - if(groovyVersion.startsWith("2.4.")) { - try { - ENABLED = groovyVersion.split(/\./)[2].toInteger() < 7 - } catch (Throwable e) { - ENABLED = false - } - } - else { - ENABLED = false - } - } - @Override - void visit(ASTNode[] nodes, SourceUnit source) { - if(ENABLED) { - ModuleNode ast = source.getAST(); - List classes = ast.getClasses(); - for (ClassNode aClass : classes) { - visitClass(aClass) - } - } - } - - void visitClass(ClassNode aClass) { - if (ENABLED && aClass.getNodeMetaData(TRANSFORM_APPLIED_MARKER) == null) { - - if (AstUtils.implementsInterface(aClass, "org.grails.datastore.gorm.GormEntity") || AstUtils.implementsInterface(aClass, "grails.gorm.rx.RxEntity")) { - aClass.putNodeMetaData(TRANSFORM_APPLIED_MARKER, Boolean.TRUE) - def allMethods = aClass.getMethods() - for (MethodNode mn in allMethods) { - for (GenericsType gt in mn.returnType.genericsTypes) { - if (gt.name == aClass.name) { - gt.setType(ClassHelper.make(aClass.name).getPlainNodeReference()) - } else if (gt.name == 'T') { - mn.setReturnType(ClassHelper.make(Object).getPlainNodeReference()) - } - } - } - } - } - } -} \ No newline at end of file diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GormEntityTransformation.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GormEntityTransformation.groovy index 593aa35880a..fa327b46901 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GormEntityTransformation.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/compiler/gorm/GormEntityTransformation.groovy @@ -63,12 +63,12 @@ import org.grails.datastore.mapping.reflect.AstUtils import org.grails.datastore.mapping.reflect.ClassUtils import org.grails.datastore.mapping.reflect.NameUtils import static org.codehaus.groovy.ast.tools.GeneralUtils.* -import javax.persistence.Embeddable -import javax.persistence.Id -import javax.persistence.ManyToMany -import javax.persistence.OneToMany -import javax.persistence.Transient -import javax.persistence.Version +import jakarta.persistence.Embeddable +import jakarta.persistence.Id +import jakarta.persistence.ManyToMany +import jakarta.persistence.OneToMany +import jakarta.persistence.Transient +import jakarta.persistence.Version import java.lang.annotation.Annotation import java.lang.reflect.Modifier @@ -90,7 +90,7 @@ import java.lang.reflect.Modifier @GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION) class GormEntityTransformation extends AbstractASTTransformation implements CompilationUnitAware,ASTTransformation { private static final ClassNode MY_TYPE = new ClassNode(Entity.class); - protected static final ClassNode JPA_ENTITY_CLASS_NODE = ClassHelper.make(javax.persistence.Entity) + protected static final ClassNode JPA_ENTITY_CLASS_NODE = ClassHelper.make(jakarta.persistence.Entity) public static final AnnotationNode JPA_ENTITY_ANNOTATION_NODE = new AnnotationNode(JPA_ENTITY_CLASS_NODE) public static final AnnotationNode JPA_VERSION_ANNOTATION_NODE = new AnnotationNode(ClassHelper.make(Version)) public static final AnnotationNode JPA_ID_ANNOTATION_NODE = new AnnotationNode(ClassHelper.make(Id)) diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy index 866156d27ae..5e3691a3c4a 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy @@ -470,7 +470,7 @@ class GormEnhancer implements Closeable { @CompileDynamic protected void removeConstraints() { try { - String className = "org.codehaus.groovy.grails.validation.ConstrainedProperty" + String className = "org.apache.groovy.grails.validation.ConstrainedProperty" ClassLoader classLoader = getClass().getClassLoader() if(ClassUtils.isPresent(className, classLoader)) { classLoader.loadClass(className).removeConstraint('unique') diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntity.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntity.groovy index efc2f949ee6..62eb910b8d1 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntity.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntity.groovy @@ -33,7 +33,7 @@ import org.grails.datastore.mapping.query.api.Criteria import org.grails.datastore.mapping.reflect.EntityReflector import org.springframework.transaction.TransactionDefinition -import javax.persistence.Transient +import jakarta.persistence.Transient /** * diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntityApi.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntityApi.groovy index f670e6304eb..9cd03c6b2be 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntityApi.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntityApi.groovy @@ -8,53 +8,53 @@ package org.grails.datastore.gorm * * @param The entity type */ -interface GormEntityApi { +trait GormEntityApi { /** * Proxy aware instanceOf implementation. */ - boolean instanceOf(Class cls) + abstract boolean instanceOf(Class cls) /** * Upgrades an existing persistence instance to a write lock * @return The instance */ - D lock() + abstract D lock() /** * Locks the instance for updates for the scope of the passed closure * * @param callable The closure * @return The result of the closure */ - def mutex(Closure callable) + abstract def mutex(Closure callable) /** * Refreshes the state of the current instance * @return The instance */ - D refresh() + abstract D refresh() /** * Saves an object the datastore * @return Returns the instance */ - D save() + abstract D save() /** * Forces an insert of an object to the datastore * @return Returns the instance */ - D insert() + abstract D insert() /** * Forces an insert of an object to the datastore * @return Returns the instance */ - D insert(Map params) + abstract D insert(Map params) /** * Saves an object the datastore * @return Returns the instance */ - D merge() + abstract D merge() /** * Saves an object the datastore * @return Returns the instance */ - D merge(Map params) + abstract D merge(Map params) /** * Save method that takes a boolean which indicates whether to perform validation or not * @@ -62,39 +62,39 @@ interface GormEntityApi { * * @return The instance or null if validation fails */ - D save(boolean validate) + abstract D save(boolean validate) /** * Saves an object with the given parameters * @param instance The instance * @param params The parameters * @return The instance */ - D save(Map params) + abstract D save(Map params) /** * Returns the objects identifier */ - Serializable ident() + abstract Serializable ident() /** * Attaches an instance to an existing session. Requries a session-based model * @return */ - D attach() + abstract D attach() /** * No concept of session-based model so defaults to true */ - boolean isAttached() + abstract boolean isAttached() /** * Discards any pending changes. Requires a session-based model. */ - void discard() + abstract void discard() /** * Deletes an instance from the datastore */ - void delete() + abstract void delete() /** * Deletes an instance from the datastore */ - void delete(Map params) + abstract void delete(Map params) /** * Checks whether a field is dirty * @@ -103,12 +103,12 @@ interface GormEntityApi { * * @return true if the field is dirty */ - boolean isDirty(String fieldName) + abstract boolean isDirty(String fieldName) /** * Checks whether an entity is dirty * * @param instance The instance * @return true if it is dirty */ - boolean isDirty() + abstract boolean isDirty() } \ No newline at end of file diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntityDirtyCheckable.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntityDirtyCheckable.groovy index 5c34a964482..bdbba9f0f1d 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntityDirtyCheckable.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntityDirtyCheckable.groovy @@ -22,7 +22,7 @@ import org.grails.datastore.mapping.dirty.checking.DirtyCheckable import org.grails.datastore.mapping.model.PersistentEntity import org.grails.datastore.mapping.model.PersistentProperty -import javax.annotation.Generated +import jakarta.annotation.Generated /** * diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormStaticApi.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormStaticApi.groovy index 4f7080d7549..05bd7a480e5 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormStaticApi.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormStaticApi.groovy @@ -98,7 +98,7 @@ class GormStaticApi extends AbstractGormApi implements GormAllOperations getGormDynamicFinders() { gormDynamicFinders } @@ -253,7 +253,7 @@ class GormStaticApi extends AbstractGormApi implements GormAllOperations saveAll(Object... objectsToSave) { (List)execute({ Session session -> - session.persist Arrays.asList(objectsToSave) + session.persist Arrays.asList(objectsToSave) } as SessionCallback) } @@ -337,7 +337,7 @@ class GormStaticApi extends AbstractGormApi implements GormAllOperations - session.retrieve((Class)persistentClass, id) + session.retrieve((Class)persistentClass, id) } as SessionCallback) } @@ -349,7 +349,7 @@ class GormStaticApi extends AbstractGormApi implements GormAllOperations - session.retrieve((Class)persistentClass, id) + session.retrieve((Class)persistentClass, id) } as SessionCallback) } @@ -358,7 +358,7 @@ class GormStaticApi extends AbstractGormApi implements GormAllOperations - session.proxy((Class)persistentClass, id) + session.proxy((Class)persistentClass, id) } as SessionCallback) } @@ -368,7 +368,7 @@ class GormStaticApi extends AbstractGormApi implements GormAllOperations extends AbstractGormApi implements GormAllOperations getAll(Serializable... ids) { (List)execute ({ Session session -> - session.retrieveAll(persistentClass, ids.flatten()) + session.retrieveAll(persistentClass, ids.flatten()) } as SessionCallback) } @@ -446,7 +446,7 @@ class GormStaticApi extends AbstractGormApi implements GormAllOperations - session.lock((Class)persistentClass, id) + session.lock((Class)persistentClass, id) } as SessionCallback) } @@ -709,14 +709,14 @@ class GormStaticApi extends AbstractGormApi implements GormAllOperations extends AbstractGormApi implements GormAllOperations persistentClass, String methodName, Class[] parameterTypes) { super(apiDelegate, methodName, parameterTypes) - Class[] metaMethodParams = ([persistentClass] + (parameterTypes as List)) as Class[] + List params = parameterTypes.toList() + params.add(persistentClass) + + Class[] metaMethodParams = params.toArray() as Class[] super.metaMethod = pickMetaMethod(apiDelegate.getMetaClass(), methodName, metaMethodParams, false) } diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/query/criteria/AbstractDetachedCriteria.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/query/criteria/AbstractDetachedCriteria.groovy index e5609b5c8b6..ed29743b5dd 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/query/criteria/AbstractDetachedCriteria.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/query/criteria/AbstractDetachedCriteria.groovy @@ -16,8 +16,8 @@ import org.grails.datastore.mapping.query.api.Criteria import org.grails.datastore.mapping.query.api.ProjectionList import org.grails.datastore.mapping.query.api.QueryableCriteria -import javax.persistence.FetchType -import javax.persistence.criteria.JoinType +import jakarta.persistence.FetchType +import jakarta.persistence.criteria.JoinType /** * Abstract super class for DetachedCriteria implementations diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/FindAllStringQueryImplementer.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/FindAllStringQueryImplementer.groovy index c9ede59a674..a239b5cff00 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/FindAllStringQueryImplementer.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/FindAllStringQueryImplementer.groovy @@ -5,6 +5,7 @@ import org.codehaus.groovy.ast.ClassNode import org.codehaus.groovy.ast.MethodNode import org.codehaus.groovy.ast.expr.Expression import org.codehaus.groovy.ast.stmt.Statement +import org.grails.datastore.gorm.GormEntity import org.grails.datastore.mapping.reflect.AstUtils import static org.codehaus.groovy.ast.tools.GeneralUtils.callX @@ -19,7 +20,7 @@ import static org.grails.datastore.mapping.reflect.AstUtils.implementsInterface * @since 6.1 */ @CompileStatic -class FindAllStringQueryImplementer extends AbstractStringQueryImplementer implements IterableServiceImplementer { +class FindAllStringQueryImplementer extends AbstractStringQueryImplementer implements IterableServiceImplementer { @Override protected boolean isCompatibleReturnType(ClassNode domainClass, MethodNode methodNode, ClassNode returnType, String prefix) { boolean isCompatibleReturnType = false diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/FindOneInterfaceProjectionImplementer.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/FindOneInterfaceProjectionImplementer.groovy index a14b65d7195..70df248999e 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/FindOneInterfaceProjectionImplementer.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/FindOneInterfaceProjectionImplementer.groovy @@ -5,6 +5,7 @@ import org.codehaus.groovy.ast.ClassNode import org.codehaus.groovy.ast.MethodNode import org.codehaus.groovy.ast.expr.Expression import org.codehaus.groovy.ast.stmt.Statement +import org.grails.datastore.gorm.GormEntity /** * Interface projection finder @@ -13,7 +14,7 @@ import org.codehaus.groovy.ast.stmt.Statement * @since 6.1 */ @CompileStatic -class FindOneInterfaceProjectionImplementer extends FindOneImplementer implements SingleResultInterfaceProjectionBuilder, SingleResultServiceImplementer { +class FindOneInterfaceProjectionImplementer extends FindOneImplementer implements SingleResultInterfaceProjectionBuilder, SingleResultServiceImplementer { @Override protected ClassNode resolveDomainClassFromSignature(ClassNode currentDomainClassNode, MethodNode methodNode) { diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/IterableProjectionServiceImplementer.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/IterableProjectionServiceImplementer.groovy index f40e85ebe02..d7d886461ec 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/IterableProjectionServiceImplementer.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/IterableProjectionServiceImplementer.groovy @@ -2,6 +2,7 @@ package org.grails.datastore.gorm.services.implementers import org.codehaus.groovy.ast.ClassNode import org.codehaus.groovy.ast.MethodNode +import org.grails.datastore.gorm.GormEntity /** * For projections that return an iterable @@ -9,7 +10,7 @@ import org.codehaus.groovy.ast.MethodNode * @author Graeme Rocher * @since 6.1.1 */ -interface IterableProjectionServiceImplementer extends IterableServiceImplementer { +interface IterableProjectionServiceImplementer extends IterableServiceImplementer { /** * Is the return type compatible with the projection query * diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/SingleResultProjectionServiceImplementer.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/SingleResultProjectionServiceImplementer.groovy index 58dece23b56..d5264533b45 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/SingleResultProjectionServiceImplementer.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/implementers/SingleResultProjectionServiceImplementer.groovy @@ -2,6 +2,7 @@ package org.grails.datastore.gorm.services.implementers import org.codehaus.groovy.ast.ClassNode import org.codehaus.groovy.ast.MethodNode +import org.grails.datastore.gorm.GormEntity /** * Represents a projection implementer @@ -9,7 +10,7 @@ import org.codehaus.groovy.ast.MethodNode * @author Graeme Rocher * @since 6.1.1 */ -interface SingleResultProjectionServiceImplementer extends SingleResultServiceImplementer { +interface SingleResultProjectionServiceImplementer extends SingleResultServiceImplementer { /** * Is the return type compatible with the projection query diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/transform/ServiceTransformation.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/transform/ServiceTransformation.groovy index f3f2f4701da..345a139d8c0 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/transform/ServiceTransformation.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/services/transform/ServiceTransformation.groovy @@ -75,7 +75,7 @@ import org.grails.datastore.gorm.services.implementers.FindOneWhereImplementer import org.grails.datastore.gorm.services.implementers.UpdateStringQueryImplementer import org.grails.datastore.gorm.transactions.transform.TransactionalTransform import org.grails.datastore.gorm.transform.AbstractTraitApplyingGormASTTransformation -import org.grails.datastore.gorm.validation.javax.services.implementers.MethodValidationImplementer +import org.grails.datastore.gorm.validation.jakarta.services.implementers.MethodValidationImplementer import org.grails.datastore.mapping.core.Datastore import org.grails.datastore.mapping.core.order.OrderedComparator diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/support/AbstractDatastorePersistenceContextInterceptor.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/support/AbstractDatastorePersistenceContextInterceptor.java index ba3b7d469cc..5817bb6aba6 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/support/AbstractDatastorePersistenceContextInterceptor.java +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/support/AbstractDatastorePersistenceContextInterceptor.java @@ -14,7 +14,7 @@ */ package org.grails.datastore.gorm.support; -import javax.persistence.FlushModeType; +import jakarta.persistence.FlushModeType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/transform/AbstractMethodDecoratingTransformation.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/transform/AbstractMethodDecoratingTransformation.groovy index ac000b8a702..cf7c9410b46 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/transform/AbstractMethodDecoratingTransformation.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/transform/AbstractMethodDecoratingTransformation.groovy @@ -28,8 +28,8 @@ import org.codehaus.groovy.transform.sc.StaticCompileTransformation import org.codehaus.groovy.transform.trait.Traits import org.grails.datastore.mapping.reflect.NameUtils -import javax.annotation.PostConstruct -import javax.annotation.PreDestroy +import jakarta.annotation.PostConstruct +import jakarta.annotation.PreDestroy import java.beans.Introspector import java.lang.reflect.Modifier diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AbstractRecursiveAnnotationVisitor.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AbstractRecursiveAnnotationVisitor.java new file mode 100644 index 00000000000..a372208261a --- /dev/null +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AbstractRecursiveAnnotationVisitor.java @@ -0,0 +1,107 @@ +/* + * Copyright 2002-2024 the original author or 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. + */ +package org.grails.datastore.gorm.utils; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.asm.AnnotationVisitor; +import org.springframework.asm.SpringAsmInfo; +import org.springframework.asm.Type; +import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.lang.Nullable; +import org.springframework.util.ClassUtils; +import org.springframework.util.ReflectionUtils; + +import java.lang.reflect.Field; +import java.security.AccessControlException; + +/** + * {@link AnnotationVisitor} to recursively visit annotations. + + *

Note: This class was ported to Grails 7 from Spring Framework 5.3 as it was + * removed in Spring 6 without a public replacement. + * + * @author Chris Beams + * @author Juergen Hoeller + * @author Phillip Webb + * @author Sam Brannen + * @since 3.1.1 + * @deprecated As of Spring Framework 5.2, this class and related classes in this + * package have been replaced by SimpleAnnotationMetadataReadingVisitor + * and related classes for internal use within the framework. + */ +@Deprecated +abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor { + + protected final Log logger = LogFactory.getLog(getClass()); + + protected final AnnotationAttributes attributes; + + @Nullable + protected final ClassLoader classLoader; + + + public AbstractRecursiveAnnotationVisitor(@Nullable ClassLoader classLoader, AnnotationAttributes attributes) { + super(SpringAsmInfo.ASM_VERSION); + this.classLoader = classLoader; + this.attributes = attributes; + } + + + @Override + public void visit(String attributeName, Object attributeValue) { + this.attributes.put(attributeName, attributeValue); + } + + @Override + public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) { + String annotationType = Type.getType(asmTypeDescriptor).getClassName(); + AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader); + this.attributes.put(attributeName, nestedAttributes); + return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader); + } + + @Override + public AnnotationVisitor visitArray(String attributeName) { + return new RecursiveAnnotationArrayVisitor(attributeName, this.attributes, this.classLoader); + } + + @Override + public void visitEnum(String attributeName, String asmTypeDescriptor, String attributeValue) { + Object newValue = getEnumValue(asmTypeDescriptor, attributeValue); + visit(attributeName, newValue); + } + + protected Object getEnumValue(String asmTypeDescriptor, String attributeValue) { + Object valueToUse = attributeValue; + try { + Class enumType = ClassUtils.forName(Type.getType(asmTypeDescriptor).getClassName(), this.classLoader); + Field enumConstant = ReflectionUtils.findField(enumType, attributeValue); + if (enumConstant != null) { + ReflectionUtils.makeAccessible(enumConstant); + valueToUse = enumConstant.get(null); + } + } + catch (ClassNotFoundException | NoClassDefFoundError ex) { + logger.debug("Failed to classload enum type while reading annotation metadata", ex); + } + catch (IllegalAccessException | AccessControlException ex) { + logger.debug("Could not access enum value while reading annotation metadata", ex); + } + return valueToUse; + } + +} diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationAttributesReadingVisitor.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationAttributesReadingVisitor.java new file mode 100644 index 00000000000..16821594ab1 --- /dev/null +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationAttributesReadingVisitor.java @@ -0,0 +1,131 @@ +/* + * Copyright 2002-2024 the original author or 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. + */ +package org.grails.datastore.gorm.utils; + +import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; +import org.springframework.util.MultiValueMap; +import org.springframework.util.ObjectUtils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Modifier; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * ASM visitor which looks for annotations defined on a class or method, + * including meta-annotations. + * + *

This visitor is fully recursive, taking into account any nested + * annotations or nested annotation arrays. + * + *

Note: This class was ported to Grails 7 from Spring Framework 5.3 as it was + * removed in Spring 6 without a public replacement. + * + * @author Juergen Hoeller + * @author Chris Beams + * @author Phillip Webb + * @author Sam Brannen + * @since 3.0 + * @deprecated As of Spring Framework 5.2, this class and related classes in this + * package have been replaced by SimpleAnnotationMetadataReadingVisitor + * and related classes for internal use within the framework. + */ +@Deprecated +final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttributesVisitor { + + private final MultiValueMap attributesMap; + + private final Map> metaAnnotationMap; + + + public AnnotationAttributesReadingVisitor(String annotationType, + MultiValueMap attributesMap, Map> metaAnnotationMap, + @Nullable ClassLoader classLoader) { + + super(annotationType, new AnnotationAttributes(annotationType, classLoader), classLoader); + this.attributesMap = attributesMap; + this.metaAnnotationMap = metaAnnotationMap; + } + + + @Override + public void visitEnd() { + super.visitEnd(); + + Class annotationClass = this.attributes.annotationType(); + if (annotationClass != null) { + List attributeList = this.attributesMap.get(this.annotationType); + if (attributeList == null) { + this.attributesMap.add(this.annotationType, this.attributes); + } + else { + attributeList.add(0, this.attributes); + } + if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationClass.getName())) { + try { + Annotation[] metaAnnotations = annotationClass.getAnnotations(); + if (!ObjectUtils.isEmpty(metaAnnotations)) { + Set visited = new LinkedHashSet<>(); + for (Annotation metaAnnotation : metaAnnotations) { + recursivelyCollectMetaAnnotations(visited, metaAnnotation); + } + if (!visited.isEmpty()) { + Set metaAnnotationTypeNames = new LinkedHashSet<>(visited.size()); + for (Annotation ann : visited) { + metaAnnotationTypeNames.add(ann.annotationType().getName()); + } + this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames); + } + } + } + catch (Throwable ex) { + if (logger.isDebugEnabled()) { + logger.debug("Failed to introspect meta-annotations on " + annotationClass + ": " + ex); + } + } + } + } + } + + private void recursivelyCollectMetaAnnotations(Set visited, Annotation annotation) { + Class annotationType = annotation.annotationType(); + String annotationName = annotationType.getName(); + if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) && visited.add(annotation)) { + try { + // Only do attribute scanning for public annotations; we'd run into + // IllegalAccessExceptions otherwise, and we don't want to mess with + // accessibility in a SecurityManager environment. + if (Modifier.isPublic(annotationType.getModifiers())) { + this.attributesMap.add(annotationName, + AnnotationUtils.getAnnotationAttributes(annotation, false, true)); + } + for (Annotation metaMetaAnnotation : annotationType.getAnnotations()) { + recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation); + } + } + catch (Throwable ex) { + if (logger.isDebugEnabled()) { + logger.debug("Failed to introspect meta-annotations on " + annotation + ": " + ex); + } + } + } + } + +} diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationMetadataReader.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationMetadataReader.java index b6b9c373b95..785d0410db7 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationMetadataReader.java +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationMetadataReader.java @@ -1,6 +1,5 @@ -package org.grails.datastore.gorm.utils; /* - * Copyright 2016 original authors + * Copyright 2016-2024 original authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +14,14 @@ * limitations under the License. */ +package org.grails.datastore.gorm.utils; + import org.springframework.asm.AnnotationVisitor; import org.springframework.asm.SpringAsmInfo; import org.springframework.asm.Type; -import org.springframework.core.NestedIOException; import org.springframework.core.io.Resource; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.ClassMetadata; -import org.springframework.core.type.classreading.AnnotationMetadataReadingVisitor; import org.springframework.core.type.classreading.MetadataReader; import java.io.BufferedInputStream; @@ -50,14 +49,14 @@ public class AnnotationMetadataReader implements MetadataReader { * @param readAttributeValues Whether to read the attributes in addition or just the annotation class names * @throws IOException */ - AnnotationMetadataReader(Resource resource, ClassLoader classLoader, boolean readAttributeValues) throws IOException { + public AnnotationMetadataReader(Resource resource, ClassLoader classLoader, boolean readAttributeValues) throws IOException { InputStream is = new BufferedInputStream(resource.getInputStream()); ClassReader classReader; try { classReader = new ClassReader(is); } catch (IllegalArgumentException ex) { - throw new NestedIOException("ASM ClassReader failed to parse class file - " + + throw new IOException("ASM ClassReader failed to parse class file - " + "probably due to a new Java class file version that isn't supported yet: " + resource, ex); } finally { diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationMetadataReadingVisitor.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationMetadataReadingVisitor.groovy new file mode 100644 index 00000000000..f876c7317ec --- /dev/null +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationMetadataReadingVisitor.groovy @@ -0,0 +1,208 @@ +/* + * Copyright 2002-2024 the original author or 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. + */ +package org.grails.datastore.gorm.utils + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.springframework.asm.AnnotationVisitor; +import org.springframework.asm.MethodVisitor; +import org.springframework.asm.Opcodes; +import org.springframework.asm.Type; +import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.annotation.MergedAnnotations; +import org.springframework.core.type.AnnotationMetadata; +import org.springframework.core.type.MethodMetadata; +import org.springframework.lang.Nullable; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +/** + * ASM class visitor which looks for the class name and implemented types as + * well as for the annotations defined on the class, exposing them through + * the {@link org.springframework.core.type.AnnotationMetadata} interface. + * + *

Note: This class was ported to Grails 7 from Spring Framework 5.3 as it was + * removed in Spring 6 without a public replacement. + * + * @author Juergen Hoeller + * @author Mark Fisher + * @author Costin Leau + * @author Phillip Webb + * @author Sam Brannen + * @since 2.5 + * @deprecated As of Spring Framework 5.2, this class has been replaced by + * SimpleAnnotationMetadataReadingVisitor for internal use within the + * framework, but there is no public replacement for + * {@code AnnotationMetadataReadingVisitor}. + */ +@Deprecated +public class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor implements AnnotationMetadata { + + @Nullable + protected final ClassLoader classLoader; + + protected final Set annotationSet = new LinkedHashSet<>(4); + + protected final Map> metaAnnotationMap = new LinkedHashMap<>(4); + + /** + * Declared as a {@link LinkedMultiValueMap} instead of a {@link MultiValueMap} + * to ensure that the hierarchical ordering of the entries is preserved. + * @see AnnotationReadingVisitorUtils#getMergedAnnotationAttributes + */ + protected final LinkedMultiValueMap attributesMap = new LinkedMultiValueMap<>(3); + + protected final Set methodMetadataSet = new LinkedHashSet<>(4); + + + public AnnotationMetadataReadingVisitor(@Nullable ClassLoader classLoader) { + this.classLoader = classLoader; + } + + + @Override + public MergedAnnotations getAnnotations() { + throw new UnsupportedOperationException(); + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + // Skip bridge methods - we're only interested in original annotation-defining user methods. + // On JDK 8, we'd otherwise run into double detection of the same annotated method... + if ((access & Opcodes.ACC_BRIDGE) != 0) { + return super.visitMethod(access, name, desc, signature, exceptions); + } + return new MethodMetadataReadingVisitor(name, access, getClassName(), + Type.getReturnType(desc).getClassName(), this.classLoader, this.methodMetadataSet); + } + + @Override + @Nullable + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + if (!visible) { + return null; + } + String className = Type.getType(desc).getClassName(); + if (AnnotationUtils.isInJavaLangAnnotationPackage(className)) { + return null; + } + this.annotationSet.add(className); + return new AnnotationAttributesReadingVisitor( + className, this.attributesMap, this.metaAnnotationMap, this.classLoader); + } + + + @Override + public Set getAnnotationTypes() { + return this.annotationSet; + } + + @Override + public Set getMetaAnnotationTypes(String annotationName) { + Set metaAnnotationTypes = this.metaAnnotationMap.get(annotationName); + return (metaAnnotationTypes != null ? metaAnnotationTypes : Collections.emptySet()); + } + + @Override + public boolean hasMetaAnnotation(String metaAnnotationType) { + if (AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotationType)) { + return false; + } + Collection> allMetaTypes = this.metaAnnotationMap.values(); + for (Set metaTypes : allMetaTypes) { + if (metaTypes.contains(metaAnnotationType)) { + return true; + } + } + return false; + } + + @Override + public boolean isAnnotated(String annotationName) { + return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) && + this.attributesMap.containsKey(annotationName)); + } + + @Override + public boolean hasAnnotation(String annotationName) { + return getAnnotationTypes().contains(annotationName); + } + + @Override + @Nullable + public AnnotationAttributes getAnnotationAttributes(String annotationName, boolean classValuesAsString) { + AnnotationAttributes raw = AnnotationReadingVisitorUtils.getMergedAnnotationAttributes( + this.attributesMap, this.metaAnnotationMap, annotationName); + if (raw == null) { + return null; + } + return AnnotationReadingVisitorUtils.convertClassValues( + "class '" + getClassName() + "'", this.classLoader, raw, classValuesAsString); + } + + @Override + @Nullable + public MultiValueMap getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { + MultiValueMap allAttributes = new LinkedMultiValueMap<>(); + List attributes = this.attributesMap.get(annotationName); + if (attributes == null) { + return null; + } + String annotatedElement = "class '" + getClassName() + "'"; + for (AnnotationAttributes raw : attributes) { + for (Map.Entry entry : AnnotationReadingVisitorUtils.convertClassValues( + annotatedElement, this.classLoader, raw, classValuesAsString).entrySet()) { + allAttributes.add(entry.getKey(), entry.getValue()); + } + } + return allAttributes; + } + + @Override + public boolean hasAnnotatedMethods(String annotationName) { + for (MethodMetadata methodMetadata : this.methodMetadataSet) { + if (methodMetadata.isAnnotated(annotationName)) { + return true; + } + } + return false; + } + + @Override + public Set getAnnotatedMethods(String annotationName) { + Set annotatedMethods = new LinkedHashSet<>(4); + for (MethodMetadata methodMetadata : this.methodMetadataSet) { + if (methodMetadata.isAnnotated(annotationName)) { + annotatedMethods.add(methodMetadata); + } + } + return annotatedMethods; + } + + @Override + public Set getDeclaredMethods() { + return Set.of(); + } + +} + diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationReadingVisitorUtils.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationReadingVisitorUtils.java new file mode 100644 index 00000000000..4c185fb61d9 --- /dev/null +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationReadingVisitorUtils.java @@ -0,0 +1,171 @@ +/* + * Copyright 2002-2024 the original author or 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. + */ +package org.grails.datastore.gorm.utils; + +import org.springframework.asm.Type; +import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; +import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.ObjectUtils; + +import java.util.*; + +/** + * Internal utility class used when reading annotations via ASM. + * + *

Note: This class was ported to Grails 7 from Spring Framework 5.3 as it was + * removed in Spring 6 without a public replacement. + * + * @author Juergen Hoeller + * @author Mark Fisher + * @author Costin Leau + * @author Phillip Webb + * @author Sam Brannen + * @since 4.0 + * @deprecated As of Spring Framework 5.2, this class and related classes in this + * package have been replaced by SimpleAnnotationMetadataReadingVisitor + * and related classes for internal use within the framework. + */ +@Deprecated +abstract class AnnotationReadingVisitorUtils { + + public static AnnotationAttributes convertClassValues(Object annotatedElement, + @Nullable ClassLoader classLoader, AnnotationAttributes original, boolean classValuesAsString) { + + AnnotationAttributes result = new AnnotationAttributes(original); + AnnotationUtils.postProcessAnnotationAttributes(annotatedElement, result, classValuesAsString); + + for (Map.Entry entry : result.entrySet()) { + try { + Object value = entry.getValue(); + if (value instanceof AnnotationAttributes) { + value = convertClassValues( + annotatedElement, classLoader, (AnnotationAttributes) value, classValuesAsString); + } + else if (value instanceof AnnotationAttributes[]) { + AnnotationAttributes[] values = (AnnotationAttributes[]) value; + for (int i = 0; i < values.length; i++) { + values[i] = convertClassValues(annotatedElement, classLoader, values[i], classValuesAsString); + } + value = values; + } + else if (value instanceof Type) { + value = (classValuesAsString ? ((Type) value).getClassName() : + ClassUtils.forName(((Type) value).getClassName(), classLoader)); + } + else if (value instanceof Type[]) { + Type[] array = (Type[]) value; + Object[] convArray = + (classValuesAsString ? new String[array.length] : new Class[array.length]); + for (int i = 0; i < array.length; i++) { + convArray[i] = (classValuesAsString ? array[i].getClassName() : + ClassUtils.forName(array[i].getClassName(), classLoader)); + } + value = convArray; + } + else if (classValuesAsString) { + if (value instanceof Class) { + value = ((Class) value).getName(); + } + else if (value instanceof Class[]) { + Class[] clazzArray = (Class[]) value; + String[] newValue = new String[clazzArray.length]; + for (int i = 0; i < clazzArray.length; i++) { + newValue[i] = clazzArray[i].getName(); + } + value = newValue; + } + } + entry.setValue(value); + } + catch (Throwable ex) { + // Class not found - can't resolve class reference in annotation attribute. + result.put(entry.getKey(), ex); + } + } + + return result; + } + + /** + * Retrieve the merged attributes of the annotation of the given type, + * if any, from the supplied {@code attributesMap}. + *

Annotation attribute values appearing lower in the annotation + * hierarchy (i.e., closer to the declaring class) will override those + * defined higher in the annotation hierarchy. + * @param attributesMap the map of annotation attribute lists, keyed by + * annotation type name + * @param metaAnnotationMap the map of meta annotation relationships, + * keyed by annotation type name + * @param annotationName the fully qualified class name of the annotation + * type to look for + * @return the merged annotation attributes, or {@code null} if no + * matching annotation is present in the {@code attributesMap} + * @since 4.0.3 + */ + @Nullable + public static AnnotationAttributes getMergedAnnotationAttributes( + LinkedMultiValueMap attributesMap, + Map> metaAnnotationMap, String annotationName) { + + // Get the unmerged list of attributes for the target annotation. + List attributesList = attributesMap.get(annotationName); + if (CollectionUtils.isEmpty(attributesList)) { + return null; + } + + // To start with, we populate the result with a copy of all attribute values + // from the target annotation. A copy is necessary so that we do not + // inadvertently mutate the state of the metadata passed to this method. + AnnotationAttributes result = new AnnotationAttributes(attributesList.get(0)); + + Set overridableAttributeNames = new HashSet<>(result.keySet()); + overridableAttributeNames.remove(AnnotationUtils.VALUE); + + // Since the map is a LinkedMultiValueMap, we depend on the ordering of + // elements in the map and reverse the order of the keys in order to traverse + // "down" the annotation hierarchy. + List annotationTypes = new ArrayList<>(attributesMap.keySet()); + Collections.reverse(annotationTypes); + + // No need to revisit the target annotation type: + annotationTypes.remove(annotationName); + + for (String currentAnnotationType : annotationTypes) { + List currentAttributesList = attributesMap.get(currentAnnotationType); + if (!ObjectUtils.isEmpty(currentAttributesList)) { + Set metaAnns = metaAnnotationMap.get(currentAnnotationType); + if (metaAnns != null && metaAnns.contains(annotationName)) { + AnnotationAttributes currentAttributes = currentAttributesList.get(0); + for (String overridableAttributeName : overridableAttributeNames) { + Object value = currentAttributes.get(overridableAttributeName); + if (value != null) { + // Store the value, potentially overriding a value from an attribute + // of the same name found higher in the annotation hierarchy. + result.put(overridableAttributeName, value); + } + } + } + } + } + + return result; + } + +} diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/ClassMetadataReadingVisitor.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/ClassMetadataReadingVisitor.java new file mode 100644 index 00000000000..8d0d79f6e9b --- /dev/null +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/ClassMetadataReadingVisitor.java @@ -0,0 +1,241 @@ +/* + * Copyright 2002-2024 the original author or 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. + */ +package org.grails.datastore.gorm.utils; + +import org.springframework.asm.Attribute; +import org.springframework.asm.*; +import org.springframework.core.type.ClassMetadata; +import org.springframework.lang.Nullable; +import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; + +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * ASM class visitor which looks only for the class name and implemented types, + * exposing them through the {@link ClassMetadata} + * interface. + * + *

Note: This class was ported to Grails 7 from Spring Framework 5.3 as it was + * removed in Spring 6 without a public replacement. + * + * @author Rod Johnson + * @author Costin Leau + * @author Mark Fisher + * @author Ramnivas Laddad + * @author Chris Beams + * @since 2.5 + * @deprecated As of Spring Framework 5.2, this class and related classes in this + * package have been replaced by SimpleAnnotationMetadataReadingVisitor + * and related classes for internal use within the framework. + */ +@Deprecated +class ClassMetadataReadingVisitor extends ClassVisitor implements ClassMetadata { + + private String className = ""; + + private boolean isInterface; + + private boolean isAnnotation; + + private boolean isAbstract; + + private boolean isFinal; + + @Nullable + private String enclosingClassName; + + private boolean independentInnerClass; + + @Nullable + private String superClassName; + + private String[] interfaces = new String[0]; + + private Set memberClassNames = new LinkedHashSet<>(4); + + + public ClassMetadataReadingVisitor() { + super(SpringAsmInfo.ASM_VERSION); + } + + + @Override + public void visit( + int version, int access, String name, String signature, @Nullable String supername, String[] interfaces) { + + this.className = ClassUtils.convertResourcePathToClassName(name); + this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0); + this.isAnnotation = ((access & Opcodes.ACC_ANNOTATION) != 0); + this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0); + this.isFinal = ((access & Opcodes.ACC_FINAL) != 0); + if (supername != null && !this.isInterface) { + this.superClassName = ClassUtils.convertResourcePathToClassName(supername); + } + this.interfaces = new String[interfaces.length]; + for (int i = 0; i < interfaces.length; i++) { + this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]); + } + } + + @Override + public void visitOuterClass(String owner, String name, String desc) { + this.enclosingClassName = ClassUtils.convertResourcePathToClassName(owner); + } + + @Override + public void visitInnerClass(String name, @Nullable String outerName, String innerName, int access) { + if (outerName != null) { + String fqName = ClassUtils.convertResourcePathToClassName(name); + String fqOuterName = ClassUtils.convertResourcePathToClassName(outerName); + if (this.className.equals(fqName)) { + this.enclosingClassName = fqOuterName; + this.independentInnerClass = ((access & Opcodes.ACC_STATIC) != 0); + } + else if (this.className.equals(fqOuterName)) { + this.memberClassNames.add(fqName); + } + } + } + + @Override + public void visitSource(String source, String debug) { + // no-op + } + + @Override + @Nullable + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + // no-op + return new EmptyAnnotationVisitor(); + } + + @Override + public void visitAttribute(Attribute attr) { + // no-op + } + + @Override + public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { + // no-op + return new EmptyFieldVisitor(); + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + // no-op + return new EmptyMethodVisitor(); + } + + @Override + public void visitEnd() { + // no-op + } + + + @Override + public String getClassName() { + return this.className; + } + + @Override + public boolean isInterface() { + return this.isInterface; + } + + @Override + public boolean isAnnotation() { + return this.isAnnotation; + } + + @Override + public boolean isAbstract() { + return this.isAbstract; + } + + @Override + public boolean isFinal() { + return this.isFinal; + } + + @Override + public boolean isIndependent() { + return (this.enclosingClassName == null || this.independentInnerClass); + } + + @Override + public boolean hasEnclosingClass() { + return (this.enclosingClassName != null); + } + + @Override + @Nullable + public String getEnclosingClassName() { + return this.enclosingClassName; + } + + @Override + @Nullable + public String getSuperClassName() { + return this.superClassName; + } + + @Override + public String[] getInterfaceNames() { + return this.interfaces; + } + + @Override + public String[] getMemberClassNames() { + return StringUtils.toStringArray(this.memberClassNames); + } + + + private static class EmptyAnnotationVisitor extends AnnotationVisitor { + + public EmptyAnnotationVisitor() { + super(SpringAsmInfo.ASM_VERSION); + } + + @Override + public AnnotationVisitor visitAnnotation(String name, String desc) { + return this; + } + + @Override + public AnnotationVisitor visitArray(String name) { + return this; + } + } + + + private static class EmptyMethodVisitor extends MethodVisitor { + + public EmptyMethodVisitor() { + super(SpringAsmInfo.ASM_VERSION); + } + } + + + private static class EmptyFieldVisitor extends FieldVisitor { + + public EmptyFieldVisitor() { + super(SpringAsmInfo.ASM_VERSION); + } + } + +} diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/ClasspathEntityScanner.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/ClasspathEntityScanner.groovy index f9a6a2cb072..5e6d05536fa 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/ClasspathEntityScanner.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/ClasspathEntityScanner.groovy @@ -1,4 +1,5 @@ -/* Copyright 2016 the original author or authors. +/* + * Copyright 2016-2024 original authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +38,7 @@ class ClasspathEntityScanner { /** * The annotations to scan */ - List> annotations = [Entity, javax.persistence.Entity] + List> annotations = [Entity, jakarta.persistence.Entity] /** * The classloader to use */ @@ -45,8 +46,9 @@ class ClasspathEntityScanner { /** * Packages that won't be scanned for performance reasons + * javax still exists for select packages */ - List ignoredPackages = ['com', 'net', '', 'org', 'java', 'javax', 'groovy'] + List ignoredPackages = ['com', 'net', '', 'org', 'java', 'javax', 'jakarta', 'groovy'] ClasspathEntityScanner() { if(ClassUtils.isPresent("grails.persistence.Entity")) { diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/FilteredAnnotationMetadata.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/FilteredAnnotationMetadata.java new file mode 100644 index 00000000000..4162eb15ea0 --- /dev/null +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/FilteredAnnotationMetadata.java @@ -0,0 +1,137 @@ +/* + * Copyright 2002-2021 the original author or 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. + */ + +package org.grails.datastore.gorm.utils; + +import org.springframework.core.annotation.*; +import org.springframework.core.type.*; +import org.springframework.lang.Nullable; +import org.springframework.util.MultiValueMap; +import org.springframework.util.ReflectionUtils; + +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +/** + * {@link AnnotationMetadata} implementation that uses standard reflection + * to introspect a given {@link Class}. + * + *

Note: this class was ported to GORM 9 from Spring Framework 6.1 since the package filter can't be passed to the spring version.

+ * + * @author Juergen Hoeller + * @author Mark Fisher + * @author Chris Beams + * @author Phillip Webb + * @author Sam Brannen + * @since 2.5 + * @deprecated As of Spring Framework 6.1, this class does not allow specifying the annotation filter. An upstream pull request should be opened so this can be removed. + */ +@Deprecated +public class FilteredAnnotationMetadata extends StandardClassMetadata implements AnnotationMetadata { + private final MergedAnnotations mergedAnnotations; + + @Nullable + private Set annotationTypes; + + + /** + * Create a new {@code StandardAnnotationMetadata} wrapper for the given Class. + * @param introspectedClass the Class to introspect + */ + public FilteredAnnotationMetadata(Class introspectedClass, AnnotationFilter filter) { + super(introspectedClass); + this.mergedAnnotations = MergedAnnotations.from(introspectedClass, + MergedAnnotations.SearchStrategy.INHERITED_ANNOTATIONS, RepeatableContainers.none(), filter); + } + + + @Override + public MergedAnnotations getAnnotations() { + return this.mergedAnnotations; + } + + @Override + public Set getAnnotationTypes() { + Set annotationTypes = this.annotationTypes; + if (annotationTypes == null) { + annotationTypes = Collections.unmodifiableSet(AnnotationMetadata.super.getAnnotationTypes()); + this.annotationTypes = annotationTypes; + } + return annotationTypes; + } + + @Override + @Nullable + public Map getAnnotationAttributes(String annotationName, boolean classValuesAsString) { + return AnnotatedElementUtils.getMergedAnnotationAttributes( + getIntrospectedClass(), annotationName, classValuesAsString, false); + } + + @Override + @Nullable + public MultiValueMap getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { + return AnnotatedElementUtils.getAllAnnotationAttributes( + getIntrospectedClass(), annotationName, classValuesAsString, false); + } + + @Override + public boolean hasAnnotatedMethods(String annotationName) { + if (AnnotationUtils.isCandidateClass(getIntrospectedClass(), annotationName)) { + try { + Method[] methods = org.springframework.util.ReflectionUtils.getDeclaredMethods(getIntrospectedClass()); + for (Method method : methods) { + if (isAnnotatedMethod(method, annotationName)) { + return true; + } + } + } + catch (Throwable ex) { + throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); + } + } + return false; + } + + @Override + public Set getAnnotatedMethods(String annotationName) { + Set result = new LinkedHashSet<>(4); + if (AnnotationUtils.isCandidateClass(getIntrospectedClass(), annotationName)) { + org.springframework.util.ReflectionUtils.doWithLocalMethods(getIntrospectedClass(), method -> { + if (isAnnotatedMethod(method, annotationName)) { + result.add(new StandardMethodMetadata(method)); + } + }); + } + return result; + } + + @Override + public Set getDeclaredMethods() { + Set result = new LinkedHashSet<>(16); + ReflectionUtils.doWithLocalMethods(getIntrospectedClass(), method -> + result.add(new StandardMethodMetadata(method))); + return result; + } + + + private static boolean isAnnotatedMethod(Method method, String annotationName) { + return !method.isBridge() && method.getAnnotations().length > 0 && + AnnotatedElementUtils.isAnnotated(method, annotationName); + } +} diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/MethodMetadataReadingVisitor.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/MethodMetadataReadingVisitor.java new file mode 100644 index 00000000000..8cb1322db76 --- /dev/null +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/MethodMetadataReadingVisitor.java @@ -0,0 +1,172 @@ +/* + * Copyright 2002-2024 the original author or 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. + */ +package org.grails.datastore.gorm.utils; + +import org.springframework.asm.*; +import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.core.annotation.MergedAnnotations; +import org.springframework.core.type.MethodMetadata; +import org.springframework.lang.Nullable; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * ASM method visitor which looks for the annotations defined on a method, + * exposing them through the {@link MethodMetadata} + * interface. + * + *

Note: This class was ported to Grails 7 from Spring Framework 5.3 as it was + * removed in Spring 6 without a public replacement. + * + * @author Juergen Hoeller + * @author Mark Pollack + * @author Costin Leau + * @author Chris Beams + * @author Phillip Webb + * @since 3.0 + * @deprecated As of Spring Framework 5.2, this class and related classes in this + * package have been replaced by SimpleAnnotationMetadataReadingVisitor + * and related classes for internal use within the framework. + */ +@Deprecated +public class MethodMetadataReadingVisitor extends MethodVisitor implements MethodMetadata { + + protected final String methodName; + + protected final int access; + + protected final String declaringClassName; + + protected final String returnTypeName; + + @Nullable + protected final ClassLoader classLoader; + + protected final Set methodMetadataSet; + + protected final Map> metaAnnotationMap = new LinkedHashMap<>(4); + + protected final LinkedMultiValueMap attributesMap = new LinkedMultiValueMap<>(3); + + + public MethodMetadataReadingVisitor(String methodName, int access, String declaringClassName, + String returnTypeName, @Nullable ClassLoader classLoader, Set methodMetadataSet) { + + super(SpringAsmInfo.ASM_VERSION); + this.methodName = methodName; + this.access = access; + this.declaringClassName = declaringClassName; + this.returnTypeName = returnTypeName; + this.classLoader = classLoader; + this.methodMetadataSet = methodMetadataSet; + } + + + @Override + public MergedAnnotations getAnnotations() { + throw new UnsupportedOperationException(); + } + + @Override + @Nullable + public AnnotationVisitor visitAnnotation(final String desc, boolean visible) { + if (!visible) { + return null; + } + this.methodMetadataSet.add(this); + String className = Type.getType(desc).getClassName(); + return new AnnotationAttributesReadingVisitor( + className, this.attributesMap, this.metaAnnotationMap, this.classLoader); + } + + + @Override + public String getMethodName() { + return this.methodName; + } + + @Override + public boolean isAbstract() { + return ((this.access & Opcodes.ACC_ABSTRACT) != 0); + } + + @Override + public boolean isStatic() { + return ((this.access & Opcodes.ACC_STATIC) != 0); + } + + @Override + public boolean isFinal() { + return ((this.access & Opcodes.ACC_FINAL) != 0); + } + + @Override + public boolean isOverridable() { + return (!isStatic() && !isFinal() && ((this.access & Opcodes.ACC_PRIVATE) == 0)); + } + + @Override + public boolean isAnnotated(String annotationName) { + return this.attributesMap.containsKey(annotationName); + } + + @Override + @Nullable + public AnnotationAttributes getAnnotationAttributes(String annotationName, boolean classValuesAsString) { + AnnotationAttributes raw = AnnotationReadingVisitorUtils.getMergedAnnotationAttributes( + this.attributesMap, this.metaAnnotationMap, annotationName); + if (raw == null) { + return null; + } + return AnnotationReadingVisitorUtils.convertClassValues( + "method '" + getMethodName() + "'", this.classLoader, raw, classValuesAsString); + } + + @Override + @Nullable + public MultiValueMap getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { + if (!this.attributesMap.containsKey(annotationName)) { + return null; + } + MultiValueMap allAttributes = new LinkedMultiValueMap<>(); + List attributesList = this.attributesMap.get(annotationName); + if (attributesList != null) { + String annotatedElement = "method '" + getMethodName() + '\''; + for (AnnotationAttributes annotationAttributes : attributesList) { + AnnotationAttributes convertedAttributes = AnnotationReadingVisitorUtils.convertClassValues( + annotatedElement, this.classLoader, annotationAttributes, classValuesAsString); + convertedAttributes.forEach(allAttributes::add); + } + } + return allAttributes; + } + + @Override + public String getDeclaringClassName() { + return this.declaringClassName; + } + + @Override + public String getReturnTypeName() { + return this.returnTypeName; + } + +} diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/RecursiveAnnotationArrayVisitor.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/RecursiveAnnotationArrayVisitor.java new file mode 100644 index 00000000000..5e86dc66b95 --- /dev/null +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/RecursiveAnnotationArrayVisitor.java @@ -0,0 +1,112 @@ +/* + * Copyright 2002-2024 the original author or 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. + */ +package org.grails.datastore.gorm.utils; + +import org.springframework.asm.AnnotationVisitor; +import org.springframework.asm.Type; +import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.lang.Nullable; +import org.springframework.util.ObjectUtils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + +/** + * {@link AnnotationVisitor} to recursively visit annotation arrays. + * + *

Note: This class was ported to Grails 7 from Spring Framework 5.3 as it was + * removed in Spring 6 without a public replacement. + * + * @author Chris Beams + * @author Juergen Hoeller + * @since 3.1.1 + * @deprecated As of Spring Framework 5.2, this class and related classes in this + * package have been replaced by SimpleAnnotationMetadataReadingVisitor + * and related classes for internal use within the framework. + */ +@Deprecated +class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationVisitor { + + private final String attributeName; + + private final List allNestedAttributes = new ArrayList<>(); + + + public RecursiveAnnotationArrayVisitor( + String attributeName, AnnotationAttributes attributes, @Nullable ClassLoader classLoader) { + + super(classLoader, attributes); + this.attributeName = attributeName; + } + + + @Override + public void visit(String attributeName, Object attributeValue) { + Object newValue = attributeValue; + Object existingValue = this.attributes.get(this.attributeName); + if (existingValue != null) { + newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue); + } + else { + Class arrayClass = newValue.getClass(); + if (Enum.class.isAssignableFrom(arrayClass)) { + while (arrayClass.getSuperclass() != null && !arrayClass.isEnum()) { + arrayClass = arrayClass.getSuperclass(); + } + } + Object[] newArray = (Object[]) Array.newInstance(arrayClass, 1); + newArray[0] = newValue; + newValue = newArray; + } + this.attributes.put(this.attributeName, newValue); + } + + @Override + public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) { + String annotationType = Type.getType(asmTypeDescriptor).getClassName(); + AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader); + this.allNestedAttributes.add(nestedAttributes); + return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader); + } + + @Override + public void visitEnd() { + if (!this.allNestedAttributes.isEmpty()) { + this.attributes.put(this.attributeName, this.allNestedAttributes.toArray(new AnnotationAttributes[0])); + } + else if (!this.attributes.containsKey(this.attributeName)) { + Class annotationType = this.attributes.annotationType(); + if (annotationType != null) { + try { + Class attributeType = annotationType.getMethod(this.attributeName).getReturnType(); + if (attributeType.isArray()) { + Class elementType = attributeType.getComponentType(); + if (elementType.isAnnotation()) { + elementType = AnnotationAttributes.class; + } + this.attributes.put(this.attributeName, Array.newInstance(elementType, 0)); + } + } + catch (NoSuchMethodException ex) { + // Corresponding attribute method not found: cannot expose empty array. + } + } + } + } + +} diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/RecursiveAnnotationAttributesVisitor.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/RecursiveAnnotationAttributesVisitor.java new file mode 100644 index 00000000000..b93f70a1140 --- /dev/null +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/utils/RecursiveAnnotationAttributesVisitor.java @@ -0,0 +1,55 @@ +/* + * Copyright 2002-2024 the original author or 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. + */ +package org.grails.datastore.gorm.utils; + +import org.springframework.asm.AnnotationVisitor; +import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.lang.Nullable; + +/** + * {@link AnnotationVisitor} to recursively visit annotation attributes. + * + *

Note: This class was ported to Grails 7 from Spring Framework 5.3 as it was + * removed in Spring 6 without a public replacement. + * + * @author Chris Beams + * @author Juergen Hoeller + * @since 3.1.1 + * @deprecated As of Spring Framework 5.2, this class and related classes in this + * package have been replaced by SimpleAnnotationMetadataReadingVisitor + * and related classes for internal use within the framework. + */ +@Deprecated +class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVisitor { + + protected final String annotationType; + + + public RecursiveAnnotationAttributesVisitor( + String annotationType, AnnotationAttributes attributes, @Nullable ClassLoader classLoader) { + + super(classLoader, attributes); + this.annotationType = annotationType; + } + + + @Override + public void visitEnd() { + AnnotationUtils.registerDefaultValues(this.attributes); + } + +} diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/ConfigurableParameterNameProvider.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/ConfigurableParameterNameProvider.groovy similarity index 95% rename from grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/ConfigurableParameterNameProvider.groovy rename to grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/ConfigurableParameterNameProvider.groovy index b667ee9e7d4..00b96f1288a 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/ConfigurableParameterNameProvider.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/ConfigurableParameterNameProvider.groovy @@ -1,8 +1,8 @@ -package org.grails.datastore.gorm.validation.javax +package org.grails.datastore.gorm.validation.jakarta import groovy.transform.CompileStatic -import javax.validation.ParameterNameProvider +import jakarta.validation.ParameterNameProvider import java.lang.reflect.Constructor import java.lang.reflect.Method diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/ConstraintViolationUtils.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/ConstraintViolationUtils.groovy similarity index 84% rename from grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/ConstraintViolationUtils.groovy rename to grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/ConstraintViolationUtils.groovy index 4552b0d2d32..04a865c13dc 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/ConstraintViolationUtils.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/ConstraintViolationUtils.groovy @@ -1,13 +1,12 @@ -package org.grails.datastore.gorm.validation.javax +package org.grails.datastore.gorm.validation.jakarta import grails.gorm.services.Service import groovy.transform.CompileStatic -import org.grails.datastore.mapping.validation.ValidationErrors import org.springframework.validation.Errors import org.springframework.validation.MapBindingResult -import javax.validation.ConstraintViolation -import javax.validation.ConstraintViolationException +import jakarta.validation.ConstraintViolation +import jakarta.validation.ConstraintViolationException /** * Utility methods for handling ConstraintViolationException @@ -26,7 +25,7 @@ class ConstraintViolationUtils { * @return The errors */ static Errors asErrors(Object object, ConstraintViolationException e) { - Set constraintViolations = e.constraintViolations + Set> constraintViolations = e.constraintViolations return asErrors(object, constraintViolations) } diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/GormValidatorAdapter.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/GormValidatorAdapter.groovy similarity index 83% rename from grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/GormValidatorAdapter.groovy rename to grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/GormValidatorAdapter.groovy index 590e08b6eb7..e1b33f54a5e 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/GormValidatorAdapter.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/GormValidatorAdapter.groovy @@ -1,14 +1,13 @@ -package org.grails.datastore.gorm.validation.javax +package org.grails.datastore.gorm.validation.jakarta import groovy.transform.CompileDynamic import groovy.transform.CompileStatic -import groovy.transform.InheritConstructors import org.grails.datastore.gorm.GormValidateable import org.springframework.validation.beanvalidation.SpringValidatorAdapter -import javax.validation.ConstraintViolation -import javax.validation.Validator -import javax.validation.executable.ExecutableValidator +import jakarta.validation.ConstraintViolation +import jakarta.validation.Validator +import jakarta.validation.executable.ExecutableValidator /** * A validator adapter that applies translates the constraint errors into the Errors object of a GORM entity diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/GormValidatorFactoryAdapter.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/GormValidatorFactoryAdapter.groovy similarity index 86% rename from grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/GormValidatorFactoryAdapter.groovy rename to grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/GormValidatorFactoryAdapter.groovy index b4bee8f03d9..78b30a0001d 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/GormValidatorFactoryAdapter.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/GormValidatorFactoryAdapter.groovy @@ -1,16 +1,16 @@ -package org.grails.datastore.gorm.validation.javax +package org.grails.datastore.gorm.validation.jakarta import groovy.transform.CompileStatic -import javax.validation.ClockProvider -import javax.validation.ConstraintValidatorFactory -import javax.validation.MessageInterpolator -import javax.validation.ParameterNameProvider -import javax.validation.TraversableResolver -import javax.validation.Validator -import javax.validation.ValidatorContext -import javax.validation.ValidatorFactory -import javax.validation.valueextraction.ValueExtractor +import jakarta.validation.ClockProvider +import jakarta.validation.ConstraintValidatorFactory +import jakarta.validation.MessageInterpolator +import jakarta.validation.ParameterNameProvider +import jakarta.validation.TraversableResolver +import jakarta.validation.Validator +import jakarta.validation.ValidatorContext +import jakarta.validation.ValidatorFactory +import jakarta.validation.valueextraction.ValueExtractor /** * A ValidatorFactory that creates adapted validators diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/JavaxValidatorRegistry.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/JakartaValidatorRegistry.groovy similarity index 83% rename from grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/JavaxValidatorRegistry.groovy rename to grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/JakartaValidatorRegistry.groovy index 0e0e38fbb30..a9302f72656 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/JavaxValidatorRegistry.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/JakartaValidatorRegistry.groovy @@ -1,4 +1,4 @@ -package org.grails.datastore.gorm.validation.javax +package org.grails.datastore.gorm.validation.jakarta import groovy.transform.CompileStatic import org.grails.datastore.gorm.validation.constraints.registry.DefaultValidatorRegistry @@ -7,7 +7,6 @@ import org.grails.datastore.mapping.model.MappingContext import org.grails.datastore.mapping.model.PersistentEntity import org.grails.datastore.mapping.reflect.ClassUtils import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator -import org.springframework.beans.factory.config.AutowireCapableBeanFactory import org.springframework.context.ApplicationContext import org.springframework.context.MessageSource import org.springframework.context.support.StaticMessageSource @@ -16,15 +15,15 @@ import org.springframework.validation.annotation.Validated import org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator import org.springframework.validation.beanvalidation.SpringConstraintValidatorFactory -import javax.validation.ClockProvider -import javax.validation.Configuration -import javax.validation.ConstraintValidatorFactory -import javax.validation.MessageInterpolator -import javax.validation.ParameterNameProvider -import javax.validation.TraversableResolver -import javax.validation.Validation -import javax.validation.ValidatorContext -import javax.validation.ValidatorFactory +import jakarta.validation.ClockProvider +import jakarta.validation.Configuration +import jakarta.validation.ConstraintValidatorFactory +import jakarta.validation.MessageInterpolator +import jakarta.validation.ParameterNameProvider +import jakarta.validation.TraversableResolver +import jakarta.validation.Validation +import jakarta.validation.ValidatorContext +import jakarta.validation.ValidatorFactory /** * A validator registry that creates validators @@ -33,14 +32,14 @@ import javax.validation.ValidatorFactory * @since 6.1 */ @CompileStatic -class JavaxValidatorRegistry extends DefaultValidatorRegistry implements ValidatorFactory { +class JakartaValidatorRegistry extends DefaultValidatorRegistry implements ValidatorFactory { /** * The validator factory */ final ValidatorFactory validatorFactory - JavaxValidatorRegistry(MappingContext mappingContext, ConnectionSourceSettings settings, MessageSource messageSource = new StaticMessageSource()) { + JakartaValidatorRegistry(MappingContext mappingContext, ConnectionSourceSettings settings, MessageSource messageSource = new StaticMessageSource()) { super(mappingContext, settings, messageSource) Configuration validatorConfiguration = buildConfiguration() @@ -108,7 +107,7 @@ class JavaxValidatorRegistry extends DefaultValidatorRegistry implements Validat } @Override - javax.validation.Validator getValidator() { + jakarta.validation.Validator getValidator() { return validatorFactory.getValidator() } @@ -153,9 +152,9 @@ class JavaxValidatorRegistry extends DefaultValidatorRegistry implements Validat } /** - * @return Whether javax.validation is available + * @return Whether jakarta.validation is available */ static boolean isAvailable() { - ClassUtils.isPresent("javax.validation.Validation") + ClassUtils.isPresent("jakarta.validation.Validation") } } diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/MappingContextTraversableResolver.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/MappingContextTraversableResolver.groovy similarity index 94% rename from grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/MappingContextTraversableResolver.groovy rename to grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/MappingContextTraversableResolver.groovy index 91b8b581311..e3e6eb8c927 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/MappingContextTraversableResolver.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/MappingContextTraversableResolver.groovy @@ -1,4 +1,4 @@ -package org.grails.datastore.gorm.validation.javax +package org.grails.datastore.gorm.validation.jakarta import groovy.transform.CompileStatic import org.grails.datastore.mapping.model.MappingContext @@ -7,8 +7,8 @@ import org.grails.datastore.mapping.model.PersistentProperty import org.grails.datastore.mapping.model.types.Association import org.grails.datastore.mapping.proxy.ProxyHandler -import javax.validation.Path -import javax.validation.TraversableResolver +import jakarta.validation.Path +import jakarta.validation.TraversableResolver import java.lang.annotation.ElementType /** diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/MethodKey.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/MethodKey.java similarity index 94% rename from grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/MethodKey.java rename to grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/MethodKey.java index bf7b31ee184..decc49d780f 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/MethodKey.java +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/MethodKey.java @@ -1,4 +1,4 @@ -package org.grails.datastore.gorm.validation.javax; +package org.grails.datastore.gorm.validation.jakarta; import java.util.Arrays; diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/services/ValidatedService.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/services/ValidatedService.groovy similarity index 81% rename from grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/services/ValidatedService.groovy rename to grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/services/ValidatedService.groovy index a57445aa204..62fc1ae63d3 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/services/ValidatedService.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/services/ValidatedService.groovy @@ -1,24 +1,23 @@ -package org.grails.datastore.gorm.validation.javax.services +package org.grails.datastore.gorm.validation.jakarta.services import groovy.transform.CompileStatic -import org.grails.datastore.gorm.validation.javax.ConstraintViolationUtils -import org.grails.datastore.gorm.validation.javax.JavaxValidatorRegistry +import org.grails.datastore.gorm.validation.jakarta.ConstraintViolationUtils +import org.grails.datastore.gorm.validation.jakarta.JakartaValidatorRegistry import org.grails.datastore.mapping.services.Service -import org.grails.datastore.mapping.validation.ValidationErrors import org.grails.datastore.mapping.validation.ValidationException import org.springframework.validation.Errors -import javax.validation.Configuration -import javax.validation.ConstraintViolation -import javax.validation.ConstraintViolationException -import javax.validation.ParameterNameProvider -import javax.validation.Validation -import javax.validation.ValidatorFactory -import javax.validation.executable.ExecutableValidator +import jakarta.validation.Configuration +import jakarta.validation.ConstraintViolation +import jakarta.validation.ConstraintViolationException +import jakarta.validation.ParameterNameProvider +import jakarta.validation.Validation +import jakarta.validation.ValidatorFactory +import jakarta.validation.executable.ExecutableValidator import java.lang.reflect.Method /** - * A service that is validated by javax.validation + * A service that is validated by jakarta.validation * * @author Graeme Rocher */ @@ -47,7 +46,7 @@ trait ValidatedService extends Service { Configuration configuration if(datastore != null) { - configuration = JavaxValidatorRegistry.buildConfigurationFor( + configuration = JakartaValidatorRegistry.buildConfigurationFor( datastore.mappingContext, datastore.mappingContext.validatorRegistry.messageSource ) @@ -74,7 +73,7 @@ trait ValidatedService extends Service { * * @throws ConstraintViolationException If a validation error occurs */ - void javaxValidate(Object instance, Method method, Object...args) throws ConstraintViolationException { + void jakartaValidate(Object instance, Method method, Object...args) throws ConstraintViolationException { ExecutableValidator validator = executableValidatorMap.get(method) Set constraintViolations = validator.validateParameters(instance, method, args) if(!constraintViolations.isEmpty()) { diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/services/implementers/MethodValidationImplementer.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/services/implementers/MethodValidationImplementer.groovy similarity index 92% rename from grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/services/implementers/MethodValidationImplementer.groovy rename to grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/services/implementers/MethodValidationImplementer.groovy index 462a6872e4b..f49c987e535 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/javax/services/implementers/MethodValidationImplementer.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/jakarta/services/implementers/MethodValidationImplementer.groovy @@ -1,4 +1,4 @@ -package org.grails.datastore.gorm.validation.javax.services.implementers +package org.grails.datastore.gorm.validation.jakarta.services.implementers import groovy.transform.CompileStatic import org.codehaus.groovy.ast.* @@ -7,13 +7,13 @@ import org.codehaus.groovy.ast.stmt.BlockStatement import org.codehaus.groovy.ast.stmt.Statement import org.grails.datastore.gorm.services.ServiceEnhancer import org.grails.datastore.gorm.transform.AbstractTraitApplyingGormASTTransformation -import org.grails.datastore.gorm.validation.javax.ConfigurableParameterNameProvider -import org.grails.datastore.gorm.validation.javax.services.ValidatedService +import org.grails.datastore.gorm.validation.jakarta.ConfigurableParameterNameProvider +import org.grails.datastore.gorm.validation.jakarta.services.ValidatedService import org.grails.datastore.mapping.reflect.ClassUtils -import javax.validation.Constraint -import javax.validation.ConstraintViolationException -import javax.validation.ParameterNameProvider +import jakarta.validation.Constraint +import jakarta.validation.ConstraintViolationException +import jakarta.validation.ParameterNameProvider import java.lang.reflect.Method import java.lang.reflect.Modifier @@ -45,7 +45,7 @@ class MethodValidationImplementer implements ServiceEnhancer { @Override boolean doesEnhance(ClassNode domainClass, MethodNode methodNode) { - if(ClassUtils.isPresent("javax.validation.Validation")) { + if(ClassUtils.isPresent("jakarta.validation.Validation")) { for(Parameter p in methodNode.parameters) { if( p.annotations.any() { AnnotationNode ann -> def constraintAnn = findAnnotation(ann.classNode, Constraint) @@ -98,7 +98,7 @@ class MethodValidationImplementer implements ServiceEnhancer { // add a first line to the method body that validates the method ArrayExpression argArray = new ArrayExpression(OBJECT_TYPE, validateArgsList) - String validateMethodName = abstractMethodNode.exceptions?.contains( make(ConstraintViolationException) ) ? "javaxValidate" : "validate" + String validateMethodName = abstractMethodNode.exceptions?.contains( make(ConstraintViolationException) ) ? "jakartaValidate" : "validate" MethodCallExpression validateCall = callThisD(ValidatedService, validateMethodName, args(varThis(), varX(methodField),argArray)) if(body instanceof BlockStatement) { ((BlockStatement)body).statements.add(0, stmt( validateCall )) diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/listener/ValidationEventListener.groovy b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/listener/ValidationEventListener.groovy index f9133bfe56f..8973be8e5fc 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/listener/ValidationEventListener.groovy +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/listener/ValidationEventListener.groovy @@ -13,7 +13,7 @@ import org.grails.datastore.mapping.engine.event.PreInsertEvent import org.grails.datastore.mapping.engine.event.PreUpdateEvent import org.springframework.context.ApplicationEvent -import javax.persistence.FlushModeType +import jakarta.persistence.FlushModeType /** * An event listener for ensuring entities are valid before saving or updating diff --git a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/registry/support/ValidatorRegistries.java b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/registry/support/ValidatorRegistries.java index 98309e551ec..7795cb50b81 100644 --- a/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/registry/support/ValidatorRegistries.java +++ b/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/validation/registry/support/ValidatorRegistries.java @@ -1,7 +1,7 @@ package org.grails.datastore.gorm.validation.registry.support; import org.grails.datastore.gorm.validation.constraints.registry.DefaultValidatorRegistry; -import org.grails.datastore.gorm.validation.javax.JavaxValidatorRegistry; +import org.grails.datastore.gorm.validation.jakarta.JakartaValidatorRegistry; import org.grails.datastore.mapping.core.connections.ConnectionSourceSettings; import org.grails.datastore.mapping.model.MappingContext; import org.grails.datastore.mapping.reflect.ClassUtils; @@ -41,8 +41,8 @@ public static ValidatorRegistry createValidatorRegistry(MappingContext mappingCo */ public static ValidatorRegistry createValidatorRegistry(MappingContext mappingContext, ConnectionSourceSettings settings, MessageSource messageSource ) { ValidatorRegistry validatorRegistry; - if(isJavaxValidationAvailable()) { - validatorRegistry = new JavaxValidatorRegistry(mappingContext, settings, messageSource); + if(isJakartaValidationAvailable()) { + validatorRegistry = new JakartaValidatorRegistry(mappingContext, settings, messageSource); } else { validatorRegistry = new DefaultValidatorRegistry(mappingContext, settings, messageSource); @@ -51,9 +51,9 @@ public static ValidatorRegistry createValidatorRegistry(MappingContext mappingCo } /** - * @return Whether javax.validation is available + * @return Whether jakarta.validation is available */ - static boolean isJavaxValidationAvailable() { - return ClassUtils.isPresent("javax.validation.Validation"); + static boolean isJakartaValidationAvailable() { + return ClassUtils.isPresent("jakarta.validation.Validation"); } } diff --git a/grails-datastore-gorm/src/main/resources/META-INF/services/org.codehaus.groovy.transform.ASTTransformation b/grails-datastore-gorm/src/main/resources/META-INF/services/org.codehaus.groovy.transform.ASTTransformation index b3b04435d0b..7b1e2316fa3 100644 --- a/grails-datastore-gorm/src/main/resources/META-INF/services/org.codehaus.groovy.transform.ASTTransformation +++ b/grails-datastore-gorm/src/main/resources/META-INF/services/org.codehaus.groovy.transform.ASTTransformation @@ -1,3 +1,2 @@ org.grails.datastore.gorm.query.transform.GlobalDetachedCriteriaASTTransformation -org.grails.compiler.gorm.GlobalTraitRepairTransformation org.grails.compiler.gorm.GlobalJpaEntityTransform diff --git a/grails-datastore-gorm/src/test/groovy/grails/gorm/annotation/transactions/TransactionalTransformSpec.groovy b/grails-datastore-gorm/src/test/groovy/grails/gorm/annotation/transactions/TransactionalTransformSpec.groovy index 897cb44e767..40baf5fd788 100644 --- a/grails-datastore-gorm/src/test/groovy/grails/gorm/annotation/transactions/TransactionalTransformSpec.groovy +++ b/grails-datastore-gorm/src/test/groovy/grails/gorm/annotation/transactions/TransactionalTransformSpec.groovy @@ -19,7 +19,7 @@ import org.springframework.util.ReflectionUtils import spock.lang.Issue import spock.lang.Specification -import javax.annotation.PostConstruct +import jakarta.annotation.PostConstruct import javax.sql.DataSource /** */ diff --git a/grails-datastore-gorm/src/test/groovy/grails/gorm/services/MethodValidationTransformSpec.groovy b/grails-datastore-gorm/src/test/groovy/grails/gorm/services/MethodValidationTransformSpec.groovy index 7e3685fd104..560011f6215 100644 --- a/grails-datastore-gorm/src/test/groovy/grails/gorm/services/MethodValidationTransformSpec.groovy +++ b/grails-datastore-gorm/src/test/groovy/grails/gorm/services/MethodValidationTransformSpec.groovy @@ -1,11 +1,13 @@ package grails.gorm.services -import org.grails.datastore.gorm.validation.javax.services.ValidatedService +import grails.gorm.annotation.Entity +import jakarta.validation.constraints.NotNull +import org.grails.datastore.gorm.validation.jakarta.services.ValidatedService import org.grails.datastore.mapping.validation.ValidationException import spock.lang.Specification -import javax.validation.ConstraintViolationException -import javax.validation.ParameterNameProvider +import jakarta.validation.ConstraintViolationException +import jakarta.validation.ParameterNameProvider /** * Created by graemerocher on 14/02/2017. @@ -17,13 +19,13 @@ class MethodValidationTransformSpec extends Specification { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import javax.validation.constraints.* +import jakarta.validation.constraints.* @Service(Foo) interface MyService { @grails.gorm.transactions.NotTransactional - Foo find(@NotNull String title) throws javax.validation.ConstraintViolationException + Foo find(@NotNull String title) throws jakarta.validation.ConstraintViolationException @grails.gorm.transactions.NotTransactional Foo findAgain(@NotNull @org.hibernate.validator.constraints.NotBlank String title) @@ -64,7 +66,7 @@ class Foo { then: def e = thrown( ConstraintViolationException) e.constraintViolations.size() == 1 - e.constraintViolations.first().messageTemplate == '{javax.validation.constraints.NotNull.message}' + e.constraintViolations.first().messageTemplate == '{jakarta.validation.constraints.NotNull.message}' e.constraintViolations.first().propertyPath.toString() == 'find.title' when: @@ -79,12 +81,12 @@ class Foo { } } -//@Service(Foo) -//interface MyService { -// -// Foo find(@NotNull String title) -//} -//@Entity -//class Foo { -// String title -//} +@Service(Foo) +interface MyService { + + Foo find(@NotNull String title) +} +@Entity +class Foo { + String title +} diff --git a/grails-datastore-gorm/src/test/groovy/grails/gorm/services/ServiceTransformSpec.groovy b/grails-datastore-gorm/src/test/groovy/grails/gorm/services/ServiceTransformSpec.groovy index a005887c316..0b22100655d 100644 --- a/grails-datastore-gorm/src/test/groovy/grails/gorm/services/ServiceTransformSpec.groovy +++ b/grails-datastore-gorm/src/test/groovy/grails/gorm/services/ServiceTransformSpec.groovy @@ -217,7 +217,7 @@ class Foo { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* @Service(Foo) interface MyService { @@ -250,7 +250,7 @@ interface IFoo { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* @Service(Foo) interface MyService { @@ -283,7 +283,7 @@ interface IFoo { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* @Service(Foo) interface MyService { @@ -317,7 +317,7 @@ interface IFoo { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* @Service(Foo) interface MyService { @@ -350,7 +350,7 @@ interface IFoo { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* @Service(Foo) interface MyService { @@ -384,7 +384,7 @@ interface IFoo { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* @Service(Foo) interface MyService { @@ -420,7 +420,7 @@ class Foo { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* @Service(Foo) interface MyService { @@ -452,7 +452,7 @@ class Foo { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* @Service(Foo) interface MyService { @@ -483,7 +483,7 @@ class Foo { Class service = new GroovyClassLoader().parseClass(''' import grails.gorm.services.* import grails.gorm.annotation.Entity -import static javax.persistence.criteria.JoinType.* +import static jakarta.persistence.criteria.JoinType.* @Service(Foo) interface MyService { diff --git a/grails-datastore-gorm/src/test/groovy/org/grails/compiler/gorm/JpaEntityTransformSpec.groovy b/grails-datastore-gorm/src/test/groovy/org/grails/compiler/gorm/JpaEntityTransformSpec.groovy index 3be22e090c0..d3c394e9133 100644 --- a/grails-datastore-gorm/src/test/groovy/org/grails/compiler/gorm/JpaEntityTransformSpec.groovy +++ b/grails-datastore-gorm/src/test/groovy/org/grails/compiler/gorm/JpaEntityTransformSpec.groovy @@ -6,7 +6,7 @@ import org.grails.datastore.mapping.reflect.ClassPropertyFetcher import org.springframework.validation.annotation.Validated import spock.lang.Specification -import javax.persistence.Transient +import jakarta.persistence.Transient /** @@ -18,8 +18,8 @@ class JpaEntityTransformSpec extends Specification { given: GroovyClassLoader gcl = new GroovyClassLoader() Class customerClass = gcl.parseClass(''' -import javax.persistence.* -import javax.validation.constraints.Digits +import jakarta.persistence.* +import jakarta.validation.constraints.Digits @Entity class Customer { @@ -30,7 +30,7 @@ class Customer { String firstName; String lastName; - @javax.persistence.OneToMany + @jakarta.persistence.OneToMany Set related } diff --git a/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/dirty/checking/DirtyCheckTransformationSpec.groovy b/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/dirty/checking/DirtyCheckTransformationSpec.groovy index 22c246eb535..316fd823def 100644 --- a/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/dirty/checking/DirtyCheckTransformationSpec.groovy +++ b/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/dirty/checking/DirtyCheckTransformationSpec.groovy @@ -75,7 +75,7 @@ abstract class AbstractGraphDomain { ''') - def child = cls.newInstance() + def child = cls.getDeclaredConstructor().newInstance() then:"The generic types are retained" child != null @@ -205,8 +205,8 @@ class Author { void "Test dirty check with generic types"() { when:"A Dirty checkable class with generic types is parsed" - def gcl = new GroovyClassLoader() - Class cls = gcl.parseClass(''' + def gcl = new GroovyClassLoader() + Class cls = gcl.parseClass(''' package org.grails.datastore.gorm.dirty.checking import grails.gorm.dirty.checking.DirtyCheck @@ -224,14 +224,14 @@ class ChildAuthor extends Author { ''') then:"The generic types are retained" - cls.getMethod("getBooks").getReturnType().getGenericInterfaces() + cls.getMethod("getBooks").getReturnType().getGenericInterfaces() } @Issue('GRAILS-10433') void "Test that properties with single character getters generate the correct getter and setter combo"() { when:"A Dirty checkable class with generic types is parsed" - def gcl = new GroovyClassLoader() - Class cls = gcl.parseClass(''' + def gcl = new GroovyClassLoader() + Class cls = gcl.parseClass(''' class FundProduct { String gSeriesOptionCode @@ -244,69 +244,69 @@ class FundProduct { ''') then:"The generic types are retained" - cls.getMethod("getgSeriesOptionCode") + cls.getMethod("getgSeriesOptionCode") when:"An invalid getter is used" - cls.getMethod('getGSeriesOptionCode') + cls.getMethod('getGSeriesOptionCode') then:"an error is thrown" - thrown(NoSuchMethodException) + thrown(NoSuchMethodException) } void "Test that the dirty checking transformations allows you to track changes to a class"() { when:"A new dirty checking instance is created" - def b = new Book() + def b = new Book() then:"It implements the DirtyCheckable interface" - b instanceof DirtyCheckable - b.hasChanged() - b.hasChanged("title") + b instanceof DirtyCheckable + b.hasChanged() + b.hasChanged("title") when:"The title is changed" - b.title = "My Title" + b.title = "My Title" then:"No tracking started yet so return true by default" - b.hasChanged() - b.hasChanged("title") + b.hasChanged() + b.hasChanged("title") when:"We start tracking and change the title" - b.trackChanges() + b.trackChanges() then:"If no changes a present then hasChanges returns false" - !b.hasChanged() - !b.hasChanged("title") + !b.hasChanged() + !b.hasChanged("title") when:"The a property is changed" - b.title = "Changed" + b.title = "Changed" then:"The changes are tracked" - b.hasChanged() - b.hasChanged("title") - b.getOriginalValue('title') == "My Title" - b.listDirtyPropertyNames() == ['title'] - !b.hasChanged("author") + b.hasChanged() + b.hasChanged("title") + b.getOriginalValue('title') == "My Title" + b.listDirtyPropertyNames() == ['title'] + !b.hasChanged("author") when:"A property with a getter and setter is changed" - b.title = "Some other value" - b.author = "Some Bloke" + b.title = "Some other value" + b.author = "Some Bloke" then:"We track that change too" - b.hasChanged("title") - b.getOriginalValue('title') == "My Title" - b.listDirtyPropertyNames() == ['title', 'author'] - b.hasChanged("author") + b.hasChanged("title") + b.getOriginalValue('title') == "My Title" + b.listDirtyPropertyNames() == ['title', 'author'] + b.hasChanged("author") } void "Test that dirty checking transformation doesn't allow for NPE for new objects"(){ - given: "A new book is created" - def book = new Book() + given: "A new book is created" + def book = new Book() - when: "Title is set" - book.title = "Title" + when: "Title is set" + book.title = "Title" - then: "getOrginal Value returns null" - book.getOriginalValue('title') == null + then: "getOrginal Value returns null" + book.getOriginalValue('title') == null } @Issue('https://github.com/grails/grails-data-mapping/issues/629') @@ -367,29 +367,29 @@ class FundProduct { void "Test dirty check with inheritance"() { when:"An inherited property is updated" - def b = new KidsBook() - b.age = 10 - b.trackChanges() - b.age = 12 + def b = new KidsBook() + b.age = 10 + b.trackChanges() + b.age = 12 then:"It is dirty" - b.hasChanged() - b.hasChanged("age") + b.hasChanged() + b.hasChanged("age") } @Issue("https://github.com/grails/grails-data-mapping/issues/744") void "Test that listDirtyPropertyNames does not include the entity name"() { when: "A new book is created" - def book = new Book(title: "Book Title", releaseDate: new Date()) - book.trackChanges() + def book = new Book(title: "Book Title", releaseDate: new Date()) + book.trackChanges() then:"The object has no changes" - !book.hasChanged() + !book.hasChanged() when: "The title is updated" - book.title = "Title (Edited)" + book.title = "Title (Edited)" then: "The listDirtyPropertyNames should not include the class name" - book.hasChanged() - book.hasChanged("title") - !(book.class.name in book.listDirtyPropertyNames()) - book.listDirtyPropertyNames().size() == 1 + book.hasChanged() + book.hasChanged("title") + !(book.class.name in book.listDirtyPropertyNames()) + book.listDirtyPropertyNames().size() == 1 } void "Test that dirty checking should not track changes to transients"() { @@ -423,7 +423,7 @@ class Practice { !child.hasChanged() child.message == "Test Message" } - + void "Test dirty check with belongsTo"() { when: Child child = new Child() @@ -476,6 +476,7 @@ class Parent { String name } +@DirtyCheck @Entity class Child { String name diff --git a/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/javax/MappingContextTraversableResolverSpec.groovy b/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/jakarta/MappingContextTraversableResolverSpec.groovy similarity index 98% rename from grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/javax/MappingContextTraversableResolverSpec.groovy rename to grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/jakarta/MappingContextTraversableResolverSpec.groovy index 7311d8aa621..2f67207a346 100644 --- a/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/javax/MappingContextTraversableResolverSpec.groovy +++ b/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/jakarta/MappingContextTraversableResolverSpec.groovy @@ -1,4 +1,4 @@ -package org.grails.datastore.gorm.validation.javax +package org.grails.datastore.gorm.validation.jakarta import grails.gorm.annotation.Entity import org.grails.datastore.mapping.core.Session @@ -6,7 +6,7 @@ import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingConte import org.grails.datastore.mapping.model.MappingContext import spock.lang.Specification -import javax.validation.Path +import jakarta.validation.Path import java.lang.annotation.ElementType /** diff --git a/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/support/GormValidatorAdapterSpec.groovy b/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/support/GormValidatorAdapterSpec.groovy index 1cfcc286824..6e4cc9234cf 100644 --- a/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/support/GormValidatorAdapterSpec.groovy +++ b/grails-datastore-gorm/src/test/groovy/org/grails/datastore/gorm/validation/support/GormValidatorAdapterSpec.groovy @@ -1,12 +1,12 @@ package org.grails.datastore.gorm.validation.support import org.grails.datastore.gorm.GormValidateable -import org.grails.datastore.gorm.validation.javax.GormValidatorAdapter +import org.grails.datastore.gorm.validation.jakarta.GormValidatorAdapter import spock.lang.Specification -import javax.validation.Validation -import javax.validation.Validator -import javax.validation.constraints.Digits +import jakarta.validation.Validation +import jakarta.validation.Validator +import jakarta.validation.constraints.Digits /** * Created by graemerocher on 30/12/2016. @@ -14,7 +14,7 @@ import javax.validation.constraints.Digits class GormValidatorAdapterSpec extends Specification { - void "test propagate javax.valdiation errors to gorm object"() { + void "test propagate jakarta.valdiation errors to gorm object"() { given: def factory = Validation.byDefaultProvider().configure().buildValidatorFactory() diff --git a/grails-datastore-web/build.gradle b/grails-datastore-web/build.gradle index be028716dfb..57ea159c712 100644 --- a/grails-datastore-web/build.gradle +++ b/grails-datastore-web/build.gradle @@ -1,22 +1,9 @@ dependencies { api project(":grails-datastore-core") - api "org.springframework:spring-web:$springVersion", { - exclude group:'commons-logging',module:'commons-logging' - exclude group:'org.springframework', module:'spring-context' - exclude group:'org.springframework', module:'spring-core' - exclude group:'org.springframework', module:'spring-beans' - exclude group:'org.springframework', module:'spring-aop' - } - api "org.springframework:spring-context:$springVersion", { - exclude group:'commons-logging',module:'commons-logging' - exclude group:'org.springframework', module:'spring-core' - exclude group:'org.springframework', module:'spring-expression' - exclude group:'org.springframework', module:'spring-aop' - exclude group:'org.springframework', module:'spring-beans' - exclude group:'org.springframework', module:'spring-asm' - } - compileOnly("javax.servlet:javax.servlet-api:$servletApiVersion") + api "org.springframework:spring-web" + api "org.springframework:spring-context" + compileOnly "jakarta.servlet:jakarta.servlet-api" - testImplementation("javax.servlet:javax.servlet-api:$servletApiVersion") - testImplementation "org.springframework:spring-test:$springVersion" + testImplementation "jakarta.servlet:jakarta.servlet-api" + testImplementation "org.springframework:spring-test" } diff --git a/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/CookieTenantResolver.groovy b/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/CookieTenantResolver.groovy index 8fbb0dd52d9..627abbcaf9a 100644 --- a/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/CookieTenantResolver.groovy +++ b/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/CookieTenantResolver.groovy @@ -8,8 +8,8 @@ import org.springframework.web.context.request.RequestAttributes import org.springframework.web.context.request.RequestContextHolder import org.springframework.web.context.request.ServletWebRequest -import javax.servlet.http.Cookie -import javax.servlet.http.HttpServletRequest +import jakarta.servlet.http.Cookie +import jakarta.servlet.http.HttpServletRequest /** * Resolves the tenant id from a cookie diff --git a/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/HttpHeaderTenantResolver.groovy b/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/HttpHeaderTenantResolver.groovy index 405e26ce1e7..a52641eff45 100644 --- a/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/HttpHeaderTenantResolver.groovy +++ b/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/HttpHeaderTenantResolver.groovy @@ -7,7 +7,7 @@ import org.springframework.web.context.request.RequestAttributes import org.springframework.web.context.request.RequestContextHolder import org.springframework.web.context.request.ServletWebRequest -import javax.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletRequest /** * A tenant resolver that resolves the tenant from the request HTTP Header diff --git a/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/SubDomainTenantResolver.groovy b/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/SubDomainTenantResolver.groovy index bf6f10ae895..0125b5ac6f0 100644 --- a/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/SubDomainTenantResolver.groovy +++ b/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/multitenancy/web/SubDomainTenantResolver.groovy @@ -8,7 +8,7 @@ import org.springframework.web.context.request.RequestAttributes import org.springframework.web.context.request.RequestContextHolder import org.springframework.web.context.request.ServletWebRequest -import javax.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletRequest /** * A tenant resolver that resolves the tenant from the Subdomain diff --git a/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/web/support/OpenSessionInViewInterceptor.java b/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/web/support/OpenSessionInViewInterceptor.java index c90bb37e1eb..02149d6d94c 100644 --- a/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/web/support/OpenSessionInViewInterceptor.java +++ b/grails-datastore-web/src/main/groovy/org/grails/datastore/mapping/web/support/OpenSessionInViewInterceptor.java @@ -15,7 +15,7 @@ package org.grails.datastore.mapping.web.support; -import javax.persistence.FlushModeType; +import jakarta.persistence.FlushModeType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/grails-datastore-web/src/test/groovy/org/grails/datastore/mapping/multitenancy/web/CookieTenantResolverSpec.groovy b/grails-datastore-web/src/test/groovy/org/grails/datastore/mapping/multitenancy/web/CookieTenantResolverSpec.groovy index 9c0f89410a8..9e08cfcdb79 100644 --- a/grails-datastore-web/src/test/groovy/org/grails/datastore/mapping/multitenancy/web/CookieTenantResolverSpec.groovy +++ b/grails-datastore-web/src/test/groovy/org/grails/datastore/mapping/multitenancy/web/CookieTenantResolverSpec.groovy @@ -6,7 +6,7 @@ import org.springframework.web.context.request.RequestContextHolder import org.springframework.web.context.request.ServletWebRequest import spock.lang.Specification -import javax.servlet.http.Cookie +import jakarta.servlet.http.Cookie /** * Created by graemerocher on 15/07/2016. diff --git a/settings.gradle b/settings.gradle index f36276087d3..746472f6da8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,27 +1,32 @@ plugins { - id "com.gradle.enterprise" version "3.17.1" - id 'com.gradle.common-custom-user-data-gradle-plugin' version '1.13' + id 'com.gradle.develocity' version '3.18.1' + id 'com.gradle.common-custom-user-data-gradle-plugin' version '2.0.2' } -gradleEnterprise { +def isCI = System.getenv('CI') != null +def isLocal = !isCI +def isAuthenticated = System.getenv('DEVELOCITY_ACCESS_KEY') != null +def isBuildCacheAuthenticated = + System.getenv('DEVELOCITY_BUILD_CACHE_NODE_USER') != null && + System.getenv('DEVELOCITY_BUILD_CACHE_NODE_KEY') != null + +develocity { server = 'https://ge.grails.org' buildScan { - publishAlwaysIf(System.getenv('CI') == 'true') - publishIfAuthenticated() - uploadInBackground = System.getenv("CI") == null - capture { - taskInputFiles = true - } + publishing.onlyIf { isAuthenticated } + uploadInBackground = isLocal } - } buildCache { - local { enabled = System.getenv('CI') != 'true' } - remote(gradleEnterprise.buildCache) { - def isAuthenticated = System.getenv('GRADLE_ENTERPRISE_ACCESS_KEY') - push = System.getenv('CI') == 'true' && isAuthenticated + local { enabled = isLocal } + remote(develocity.buildCache) { + push = isCI && isBuildCacheAuthenticated enabled = true + usernameAndPassword( + System.getenv('DEVELOCITY_BUILD_CACHE_NODE_USER') ?: '', + System.getenv('DEVELOCITY_BUILD_CACHE_NODE_KEY') ?: '' + ) } }