From f5f99cc020f75f310b9aff860c214c3e45866c8c Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Fri, 26 Jan 2024 10:01:35 +0100 Subject: [PATCH 01/43] Removed Demo and renaming --- .github/workflows/checkBuild.yml | 8 -- .github/workflows/update-from-template.yml | 2 +- .run/Run Demo.run.xml | 16 --- CONTRIBUTING.md | 4 +- README.md | 12 +- SECURITY.md | 2 +- pom.xml | 6 +- .../pom.xml | 12 +- standard-maven-template-demo/pom.xml | 113 ------------------ 9 files changed, 19 insertions(+), 156 deletions(-) delete mode 100644 .run/Run Demo.run.xml rename {standard-maven-template => spring-data-eclipse-store-migration}/pom.xml (93%) delete mode 100644 standard-maven-template-demo/pom.xml diff --git a/.github/workflows/checkBuild.yml b/.github/workflows/checkBuild.yml index c7b324d..83c8056 100644 --- a/.github/workflows/checkBuild.yml +++ b/.github/workflows/checkBuild.yml @@ -19,7 +19,6 @@ on: env: PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }} - DEMO_MAVEN_MODULE: ${{ github.event.repository.name }}-demo jobs: build: @@ -61,13 +60,6 @@ jobs: exit 1 fi - - name: Upload demo files - uses: actions/upload-artifact@v4 - with: - name: demo-files-java-${{ matrix.java }} - path: ${{ env.DEMO_MAVEN_MODULE }}/target/${{ env.DEMO_MAVEN_MODULE }}.jar - if-no-files-found: error - code-style: runs-on: ubuntu-latest diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index a325e2b..adbb78a 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -14,7 +14,7 @@ on: env: UPDATE_BRANCH: update-from-template - REMOTE_URL: https://github.com/xdev-software/standard-maven-template.git + REMOTE_URL: https://github.com/xdev-software/spring-data-eclipse-store-migration.git REMOTE_BRANCH: master permissions: diff --git a/.run/Run Demo.run.xml b/.run/Run Demo.run.xml deleted file mode 100644 index 764b3b9..0000000 --- a/.run/Run Demo.run.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2f8dd90..633554e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,10 +33,10 @@ You should have the following things installed: * Ensure that the JDK/Java-Version is correct -## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/standard-maven-template/release.yml?branch=master)](https://github.com/xdev-software/standard-maven-template/actions/workflows/release.yml) +## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/spring-data-eclipse-store-migration/release.yml?branch=master)](https://github.com/xdev-software/spring-data-eclipse-store-migration/actions/workflows/release.yml) Before releasing: -* Consider doing a [test-deployment](https://github.com/xdev-software/standard-maven-template/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing. +* Consider doing a [test-deployment](https://github.com/xdev-software/spring-data-eclipse-store-migration/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing. * Check the [changelog](CHANGELOG.md) If the ``develop`` is ready for release, create a pull request to the ``master``-Branch and merge the changes diff --git a/README.md b/README.md index b90c3eb..ee3e811 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -[![Latest version](https://img.shields.io/maven-central/v/software.xdev/standard-maven-template?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/standard-maven-template) -[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/standard-maven-template/checkBuild.yml?branch=develop)](https://github.com/xdev-software/standard-maven-template/actions/workflows/checkBuild.yml?query=branch%3Adevelop) -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_standard-maven-template&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_standard-maven-template) +[![Latest version](https://img.shields.io/maven-central/v/software.xdev/spring-data-eclipse-store-migration?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/spring-data-eclipse-store-migration) +[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/spring-data-eclipse-store-migration/checkBuild.yml?branch=develop)](https://github.com/xdev-software/spring-data-eclipse-store-migration/actions/workflows/checkBuild.yml?query=branch%3Adevelop) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_spring-data-eclipse-store-migration&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_spring-data-eclipse-store-migration) -# standard-maven-template +# spring-data-eclipse-store-migration ## Installation -[Installation guide for the latest release](https://github.com/xdev-software/standard-maven-template/releases/latest#Installation) +[Installation guide for the latest release](https://github.com/xdev-software/spring-data-eclipse-store-migration/releases/latest#Installation) ## Support @@ -16,4 +16,4 @@ If you need support as soon as possible and you can't wait for any pull request, See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project. ## Dependencies and Licenses -View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/standard-maven-template/dependencies/) +View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/spring-data-eclipse-store-migration/dependencies/) diff --git a/SECURITY.md b/SECURITY.md index 92188f3..465e980 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,4 +2,4 @@ ## Reporting a Vulnerability -Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/standard-maven-template/security/advisories/new). +Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/spring-data-eclipse-store-migration/security/advisories/new). diff --git a/pom.xml b/pom.xml index 4e48f7a..0d8e4bf 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 software.xdev - standard-maven-template-root + spring-data-eclipse-store-migration-root 1.0.0-SNAPSHOT pom @@ -15,8 +15,8 @@ - standard-maven-template - standard-maven-template-demo + spring-data-eclipse-store-migration + spring-data-eclipse-store-migration-demo diff --git a/standard-maven-template/pom.xml b/spring-data-eclipse-store-migration/pom.xml similarity index 93% rename from standard-maven-template/pom.xml rename to spring-data-eclipse-store-migration/pom.xml index 6b14131..c5323bb 100644 --- a/standard-maven-template/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -5,17 +5,17 @@ 4.0.0 software.xdev - standard-maven-template + spring-data-eclipse-store-migration 1.0.0-SNAPSHOT jar - standard-maven-template - standard-maven-template - https://github.com/xdev-software/standard-maven-template + spring-data-eclipse-store-migration + spring-data-eclipse-store-migration + https://github.com/xdev-software/spring-data-eclipse-store-migration - https://github.com/xdev-software/standard-maven-template - https://github.com/xdev-software/standard-maven-template.git + https://github.com/xdev-software/spring-data-eclipse-store-migration + https://github.com/xdev-software/spring-data-eclipse-store-migration.git 2023 diff --git a/standard-maven-template-demo/pom.xml b/standard-maven-template-demo/pom.xml deleted file mode 100644 index c612333..0000000 --- a/standard-maven-template-demo/pom.xml +++ /dev/null @@ -1,113 +0,0 @@ - - - 4.0.0 - - software.xdev - standard-maven-template-demo - 1.0.0-SNAPSHOT - jar - - 2022 - - - XDEV Software - https://xdev.software - - - - 17 - ${javaVersion} - - UTF-8 - UTF-8 - - software.xdev.Application - - - - - software.xdev - standard-maven-template - ${project.version} - - - - - ${project.artifactId} - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - - ${maven.compiler.release} - - -proc:none - - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.6.0 - - - - ${mainClass} - - - true - - - - jar-with-dependencies - - false - - - - make-assembly - package - - single - - - - - - - - - checkstyle - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.3.1 - - - com.puppycrawl.tools - checkstyle - 10.12.7 - - - - ../.config/checkstyle/checkstyle.xml - - - - - check - - - - - - - - - From c746d2a48af4ee85c3c33af346bd5d186773e4aa Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 29 Jan 2024 07:42:46 +0100 Subject: [PATCH 02/43] Added AddAnnotation Recipe --- README.md | 7 ++ pom.xml | 1 - .../AddAnnotationToOtherAnnotation.java | 117 ++++++++++++++++++ .../resources/META-INF/rewrite/rewrite.yml | 23 ++++ spring-data-eclipse-store-migration/pom.xml | 88 +++++++++++++ ...clipseStoreRepositoriesAnnotationTest.java | 66 ++++++++++ 6 files changed, 301 insertions(+), 1 deletion(-) create mode 100644 spring-data-eclipse-store-migration/main/java/software/xdev/spring.data.eclipse.store/AddAnnotationToOtherAnnotation.java create mode 100644 spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml create mode 100644 spring-data-eclipse-store-migration/test/java/spring.data.eclipse.store/AddEnableEclipseStoreRepositoriesAnnotationTest.java diff --git a/README.md b/README.md index ee3e811..3837edb 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,13 @@ # spring-data-eclipse-store-migration +## Usage + +``` +mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \ + -Drewrite.recipeArtifactCoordinates=software.xdev:spring-data-eclipse-store-migration:1.0-SNAPSHOT \ + -Drewrite.activeRecipes=software.xdev.spring.data.eclipse.store.JpaMigration +``` ## Installation [Installation guide for the latest release](https://github.com/xdev-software/spring-data-eclipse-store-migration/releases/latest#Installation) diff --git a/pom.xml b/pom.xml index 0d8e4bf..3004559 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,6 @@ spring-data-eclipse-store-migration - spring-data-eclipse-store-migration-demo diff --git a/spring-data-eclipse-store-migration/main/java/software/xdev/spring.data.eclipse.store/AddAnnotationToOtherAnnotation.java b/spring-data-eclipse-store-migration/main/java/software/xdev/spring.data.eclipse.store/AddAnnotationToOtherAnnotation.java new file mode 100644 index 0000000..d8e92a3 --- /dev/null +++ b/spring-data-eclipse-store-migration/main/java/software/xdev/spring.data.eclipse.store/AddAnnotationToOtherAnnotation.java @@ -0,0 +1,117 @@ +package software.xdev.spring.data.eclipse.store; + +import java.util.Comparator; + +import org.openrewrite.ExecutionContext; +import org.openrewrite.Option; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.java.AnnotationMatcher; +import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.java.JavaParser; +import org.openrewrite.java.JavaTemplate; +import org.openrewrite.java.tree.J; + + +public class AddAnnotationToOtherAnnotation extends Recipe +{ + + @Option(displayName = "Existing annotation type", + description = "Annotation type that is already existing. Recipe is looking for this annotation to add the new " + + "annotation.", + example = "org.junit.jupiter.api.Test") + String existingAnnotationType; + + @Option(displayName = "Annotation type to add", + description = "Annotation type that should be added to the existing annotation type.", + example = "org.junit.jupiter.api.Test") + String annotationTypeToAdd; + + @Option(displayName = "Class path", + description = "Class path that needs to be added for the new annotation. Can be empty.", + example = "spring-data-eclipse-store") + String classPath; + + @Option(displayName = "Simple name of annotation type to add", + description = "Simple name of annotation type that should be added to the existing annotation type.", + example = "Test") + String annotationTypeToAddSimpleName; + + public AddAnnotationToOtherAnnotation( + final String existingAnnotationType, + final String annotationTypeToAdd, + final String classPath, + final String annotationTypeToAddSimpleName) + { + this.existingAnnotationType = existingAnnotationType; + this.annotationTypeToAdd = annotationTypeToAdd; + this.classPath = classPath; + this.annotationTypeToAddSimpleName = annotationTypeToAddSimpleName; + } + + public AddAnnotationToOtherAnnotation() + { + } + + @Override + public String getDisplayName() + { + return "AddAnnotationToOtherAnnotation"; + } + + @Override + public String getDescription() + { + return "Add the a new annotation to an existing annotation."; + } + + @Override + public TreeVisitor getVisitor() + { + final AnnotationMatcher EXISTING_ANNOTATION_MATCHER = new AnnotationMatcher(this.existingAnnotationType); + final AnnotationMatcher NEW_ANNOTATION_MATCHER = new AnnotationMatcher(this.annotationTypeToAdd); + return new JavaIsoVisitor<>() + { + @Override + public J.ClassDeclaration visitClassDeclaration( + final J.ClassDeclaration classDecl, + final ExecutionContext executionContext) + { + final J.ClassDeclaration cd = super.visitClassDeclaration(classDecl, executionContext); + + if( + cd.getAnnotations() == null || + cd.getLeadingAnnotations() + .stream() + .filter(annotation -> EXISTING_ANNOTATION_MATCHER.matches(annotation)) + .findAny() + .isEmpty() || + cd.getLeadingAnnotations() + .stream() + .filter(annotation -> NEW_ANNOTATION_MATCHER.matches(annotation)) + .findAny() + .isPresent() + ) + { + return cd; + } + + final JavaTemplate componentAnnotationTemplate = + JavaTemplate + .builder("#{}") + .javaParser(JavaParser.fromJavaVersion() + .classpath(AddAnnotationToOtherAnnotation.this.classPath)) + .imports(AddAnnotationToOtherAnnotation.this.annotationTypeToAdd) + .build(); + + this.maybeAddImport(AddAnnotationToOtherAnnotation.this.annotationTypeToAdd); + + return componentAnnotationTemplate.apply( + this.getCursor(), + cd.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName)), + "@" + AddAnnotationToOtherAnnotation.this.annotationTypeToAddSimpleName + ); + } + }; + } +} diff --git a/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml new file mode 100644 index 0000000..733f60a --- /dev/null +++ b/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml @@ -0,0 +1,23 @@ +--- +type: specs.openrewrite.org/v1beta/recipe +name: software.xdev.spring.data.eclipse.store.JpaMigration +displayName: JpaMigration +description: Migrate from Spring Data JPA to latest Spring Data EclipseStore version. +tags: + - spring-data-jpa + - spring-data + - eclipse-store + - eclipsestore +recipeList: + ##################### Add annotation ################## + - software: + xdev: + spring: + data: + eclipse: + store: + .AddAnnotationToOtherAnnotation: + existingAnnotationType: 'org.springframework.boot.autoconfigure.SpringBootApplication' + annotationTypeToAdd: 'software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories' + classPath: 'spring-data-eclipse-store' + annotationTypeToAddSimpleName: 'EnableEclipseStoreRepositories' diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index c5323bb..a4ceba6 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -47,6 +47,12 @@ UTF-8 UTF-8 + 2.6.0 + 3.2.2 + 1.0.0 + 5.10.0 + 3.24.2 + 2.0.5 @@ -61,6 +67,25 @@ + + + + org.openrewrite.recipe + rewrite-recipe-bom + ${org.openrewrite.recipe.version} + pom + import + + + org.springframework.boot + spring-boot-dependencies + ${org.springframework.boot.version} + pom + import + + + + @@ -84,6 +109,69 @@ + + + org.openrewrite + rewrite-java + compile + + + org.openrewrite + rewrite-java-17 + test + + + org.openrewrite + rewrite-maven + compile + + + + org.springframework.boot + spring-boot-autoconfigure + + + + software.xdev + spring-data-eclipse-store + ${software.xdev.spring.data.eclipse.store.version} + + + + org.openrewrite + rewrite-test + test + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-simple + ${slf4j.version} + + + diff --git a/spring-data-eclipse-store-migration/test/java/spring.data.eclipse.store/AddEnableEclipseStoreRepositoriesAnnotationTest.java b/spring-data-eclipse-store-migration/test/java/spring.data.eclipse.store/AddEnableEclipseStoreRepositoriesAnnotationTest.java new file mode 100644 index 0000000..267cd1d --- /dev/null +++ b/spring-data-eclipse-store-migration/test/java/spring.data.eclipse.store/AddEnableEclipseStoreRepositoriesAnnotationTest.java @@ -0,0 +1,66 @@ +package spring.data.eclipse.store; + +import static org.openrewrite.java.Assertions.java; + +import org.junit.jupiter.api.Test; +import org.openrewrite.java.Java17Parser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import software.xdev.spring.data.eclipse.store.AddAnnotationToOtherAnnotation; +import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + +public class AddEnableEclipseStoreRepositoriesAnnotationTest implements RewriteTest +{ + + @Override + public void defaults(final RecipeSpec recipeSpec) + { + recipeSpec + .recipe(new AddAnnotationToOtherAnnotation( + SpringBootApplication.class.getName(), + EnableEclipseStoreRepositories.class.getName(), + "spring-data-eclipse-store", + EnableEclipseStoreRepositories.class.getSimpleName())) + .parser(Java17Parser.builder() + .logCompilationWarningsAndErrors(true) + .classpath("spring-boot-autoconfigure", "spring-data-eclipse-store")); + } + + @Test + void test() + { + this.rewriteRun + ( + java + ( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication + class A + { + public A() + { + } + } + """, + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class A + { + public A() + { + } + } + """ + ) + ); + } +} From 5f1162ef046202cb2a6de45b03474fe14bfea0e9 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 29 Jan 2024 08:29:49 +0100 Subject: [PATCH 03/43] Added AddDependency recipe --- .../main/resources/META-INF/rewrite/rewrite.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml index 733f60a..b0a1519 100644 --- a/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml +++ b/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml @@ -9,7 +9,7 @@ tags: - eclipse-store - eclipsestore recipeList: - ##################### Add annotation ################## + - software: xdev: spring: @@ -21,3 +21,9 @@ recipeList: annotationTypeToAdd: 'software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories' classPath: 'spring-data-eclipse-store' annotationTypeToAddSimpleName: 'EnableEclipseStoreRepositories' + + - org.openrewrite.maven.AddDependency: + groupId: software.xdev + artifactId: spring-data-eclipse-store + version: 1.0.0 + acceptTransitive: true From fac4956b755594e930f7fc6f0078de419a804731 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 29 Jan 2024 08:34:48 +0100 Subject: [PATCH 04/43] Added AddPlugin recipe --- .../main/resources/META-INF/rewrite/rewrite.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml index b0a1519..10543c6 100644 --- a/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml +++ b/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml @@ -27,3 +27,9 @@ recipeList: artifactId: spring-data-eclipse-store version: 1.0.0 acceptTransitive: true + + - org.openrewrite.maven.AddPlugin: + groupId: org.springframework.boot + artifactId: spring-boot-maven-plugin + version: 3.2.2 + configuration: --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED From 03364bdd67ef1b955ad8bc7e306a0ad6942c3d03 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 29 Jan 2024 09:14:26 +0100 Subject: [PATCH 05/43] Fixed structure --- README.md | 2 +- spring-data-eclipse-store-migration/pom.xml | 37 +++---------------- .../AddAnnotationToOtherAnnotation.java | 16 +++++++- .../resources/META-INF/rewrite/rewrite.yml | 8 +--- .../AddAnnotationToOtherAnnotationTest.java} | 22 +++++++++-- 5 files changed, 40 insertions(+), 45 deletions(-) rename spring-data-eclipse-store-migration/{main/java/software/xdev/spring.data.eclipse.store => src/main/java/software/xdev/spring/data/eclipse/store}/AddAnnotationToOtherAnnotation.java (85%) rename spring-data-eclipse-store-migration/{ => src}/main/resources/META-INF/rewrite/rewrite.yml (89%) rename spring-data-eclipse-store-migration/{test/java/spring.data.eclipse.store/AddEnableEclipseStoreRepositoriesAnnotationTest.java => src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java} (65%) diff --git a/README.md b/README.md index 3837edb..b0a67d5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ``` mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \ - -Drewrite.recipeArtifactCoordinates=software.xdev:spring-data-eclipse-store-migration:1.0-SNAPSHOT \ + -Drewrite.recipeArtifactCoordinates=software.xdev:spring-data-eclipse-store-migration:1.0.0-SNAPSHOT \ -Drewrite.activeRecipes=software.xdev.spring.data.eclipse.store.JpaMigration ``` diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index a4ceba6..a1f5833 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -115,11 +115,6 @@ rewrite-java compile - - org.openrewrite - rewrite-java-17 - test - org.openrewrite rewrite-maven @@ -129,47 +124,25 @@ org.springframework.boot spring-boot-autoconfigure + runtime - software.xdev spring-data-eclipse-store ${software.xdev.spring.data.eclipse.store.version} + runtime org.openrewrite - rewrite-test - test - - - org.junit.jupiter - junit-jupiter-api - ${junit.version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit.version} + rewrite-java-17 test - org.assertj - assertj-core - ${assertj.version} + org.openrewrite + rewrite-test test - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - slf4j-simple - ${slf4j.version} - diff --git a/spring-data-eclipse-store-migration/main/java/software/xdev/spring.data.eclipse.store/AddAnnotationToOtherAnnotation.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java similarity index 85% rename from spring-data-eclipse-store-migration/main/java/software/xdev/spring.data.eclipse.store/AddAnnotationToOtherAnnotation.java rename to spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java index d8e92a3..4300524 100644 --- a/spring-data-eclipse-store-migration/main/java/software/xdev/spring.data.eclipse.store/AddAnnotationToOtherAnnotation.java +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java @@ -1,3 +1,18 @@ +/* + * Copyright © 2023 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package software.xdev.spring.data.eclipse.store; import java.util.Comparator; @@ -12,7 +27,6 @@ import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.tree.J; - public class AddAnnotationToOtherAnnotation extends Recipe { diff --git a/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml similarity index 89% rename from spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml rename to spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml index 10543c6..e5535c7 100644 --- a/spring-data-eclipse-store-migration/main/resources/META-INF/rewrite/rewrite.yml +++ b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml @@ -10,13 +10,7 @@ tags: - eclipsestore recipeList: - - software: - xdev: - spring: - data: - eclipse: - store: - .AddAnnotationToOtherAnnotation: + - software.xdev.spring.data.eclipse.store.AddAnnotationToOtherAnnotation: existingAnnotationType: 'org.springframework.boot.autoconfigure.SpringBootApplication' annotationTypeToAdd: 'software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories' classPath: 'spring-data-eclipse-store' diff --git a/spring-data-eclipse-store-migration/test/java/spring.data.eclipse.store/AddEnableEclipseStoreRepositoriesAnnotationTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java similarity index 65% rename from spring-data-eclipse-store-migration/test/java/spring.data.eclipse.store/AddEnableEclipseStoreRepositoriesAnnotationTest.java rename to spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java index 267cd1d..57d3c61 100644 --- a/spring-data-eclipse-store-migration/test/java/spring.data.eclipse.store/AddEnableEclipseStoreRepositoriesAnnotationTest.java +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java @@ -1,4 +1,19 @@ -package spring.data.eclipse.store; +/* + * Copyright © 2023 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store; import static org.openrewrite.java.Assertions.java; @@ -8,11 +23,10 @@ import org.openrewrite.test.RewriteTest; import org.springframework.boot.autoconfigure.SpringBootApplication; -import software.xdev.spring.data.eclipse.store.AddAnnotationToOtherAnnotation; import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; -public class AddEnableEclipseStoreRepositoriesAnnotationTest implements RewriteTest +public class AddAnnotationToOtherAnnotationTest implements RewriteTest { @Override @@ -30,7 +44,7 @@ public void defaults(final RecipeSpec recipeSpec) } @Test - void test() + void testAddingAnnotation() { this.rewriteRun ( From 86595ee9901a0ad40bab8651a892dfbbb6fa9c57 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 29 Jan 2024 09:26:33 +0100 Subject: [PATCH 06/43] Added getter for rewrite-compatibility --- .../store/AddAnnotationToOtherAnnotation.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java index 4300524..43c86d7 100644 --- a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java @@ -43,7 +43,8 @@ public class AddAnnotationToOtherAnnotation extends Recipe @Option(displayName = "Class path", description = "Class path that needs to be added for the new annotation. Can be empty.", - example = "spring-data-eclipse-store") + example = "spring-data-eclipse-store", + required = false) String classPath; @Option(displayName = "Simple name of annotation type to add", @@ -128,4 +129,24 @@ public J.ClassDeclaration visitClassDeclaration( } }; } + + public String getExistingAnnotationType() + { + return this.existingAnnotationType; + } + + public String getAnnotationTypeToAdd() + { + return this.annotationTypeToAdd; + } + + public String getClassPath() + { + return this.classPath; + } + + public String getAnnotationTypeToAddSimpleName() + { + return this.annotationTypeToAddSimpleName; + } } From 4bbd8b530f08195a65529243e7c34105b29079e8 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 29 Jan 2024 10:07:27 +0100 Subject: [PATCH 07/43] Cleanup --- spring-data-eclipse-store-migration/pom.xml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index a1f5833..4ebe921 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 software.xdev @@ -113,12 +113,10 @@ org.openrewrite rewrite-java - compile org.openrewrite rewrite-maven - compile @@ -248,7 +246,7 @@ - + org.sonatype.plugins nexus-staging-maven-plugin From 61b4d43f2f0ab3a72a459dac24e865a166c2138f Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 29 Jan 2024 10:07:37 +0100 Subject: [PATCH 08/43] Remove JPA traces with update --- .../main/resources/META-INF/rewrite/rewrite.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml index e5535c7..f8ae837 100644 --- a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml +++ b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml @@ -27,3 +27,18 @@ recipeList: artifactId: spring-boot-maven-plugin version: 3.2.2 configuration: --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED + + - org.openrewrite.maven.ChangePluginConfiguration: + groupId: org.springframework.boot + artifactId: spring-boot-maven-plugin + configuration: --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED + + - org.openrewrite.maven.RemoveDependency: + groupId: org.springframework.boot + artifactId: spring-boot-starter-data-jpa + + - org.openrewrite.java.RemoveAnnotation: + # https://docs.openrewrite.org/reference/method-patterns + annotationPattern: '@org.springframework.data.jpa.repository.Query *(..)' + + - org.openrewrite.java.RemoveUnusedImports From c76eb8fb5251d1d8a66cac36e65aeb8af3fdfafc Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 29 Jan 2024 10:46:30 +0100 Subject: [PATCH 09/43] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b0a67d5..e0084bb 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \ -Drewrite.activeRecipes=software.xdev.spring.data.eclipse.store.JpaMigration ``` -## Installation -[Installation guide for the latest release](https://github.com/xdev-software/spring-data-eclipse-store-migration/releases/latest#Installation) - +> [!CAUTION] +> Since Spring-Data-Eclipse-Store can't handle ```@Query```-Annotations, +> these annotations are getting removed by the Rewrite-Recipe. ## Support If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support). From 2f08c60aba17db344ac2a2b78469eeca3fb9a777 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 29 Jan 2024 11:06:36 +0100 Subject: [PATCH 10/43] Changed README --- .github/workflows/release.yml | 14 ++++++-------- CHANGELOG.md | 3 +++ README.md | 14 ++++++++------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 534759b..2aced3a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -95,14 +95,12 @@ jobs: ## [Changelog](https://github.com/xdev-software/${{ env.PRIMARY_MAVEN_MODULE }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) See [Changelog#v${{ steps.version.outputs.release }}](https://github.com/xdev-software/${{ env.PRIMARY_MAVEN_MODULE }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) for more information. - ## Installation - Add the following lines to your pom: - ```XML - - software.xdev - ${{ env.PRIMARY_MAVEN_MODULE }} - ${{ steps.version.outputs.release }} - + ## Usage + Execute the following maven command in the maven project that you want to migrate: + ``` + mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \ + -Drewrite.recipeArtifactCoordinates=software.xdev:${{ env.PRIMARY_MAVEN_MODULE }}:${{ steps.version.outputs.release }} \ + -Drewrite.activeRecipes=software.xdev.spring.data.eclipse.store.JpaMigration ``` publish_central: # Publish the code to central diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..72ba701 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# 1.0.0 + +* Initial release diff --git a/README.md b/README.md index e0084bb..0589270 100644 --- a/README.md +++ b/README.md @@ -4,20 +4,22 @@ # spring-data-eclipse-store-migration +Migrates your Spring-Data-JPA-project +to [Spring-Data-Eclipse-Store](https://github.com/xdev-software/spring-data-eclipse-store) +through a [OpenRewrite](https://docs.openrewrite.org/)-Recipe. + ## Usage -``` -mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \ - -Drewrite.recipeArtifactCoordinates=software.xdev:spring-data-eclipse-store-migration:1.0.0-SNAPSHOT \ - -Drewrite.activeRecipes=software.xdev.spring.data.eclipse.store.JpaMigration -``` +[Usage guide for the latest release](https://github.com/xdev-software/spring-data-eclipse-store-migration/releases/latest#Usage > [!CAUTION] > Since Spring-Data-Eclipse-Store can't handle ```@Query```-Annotations, > these annotations are getting removed by the Rewrite-Recipe. ## Support -If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support). + +If you need support as soon as possible, and you can't wait for any pull request, feel free to +use [our support](https://xdev.software/en/services/support). ## Contributing See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project. From c7e609b20ecebd85db1630562a48b8cc1495f989 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 30 Jan 2024 00:31:09 +0000 Subject: [PATCH 11/43] Bump org.openrewrite.recipe:rewrite-recipe-bom from 2.6.0 to 2.6.3 Bumps [org.openrewrite.recipe:rewrite-recipe-bom](https://github.com/openrewrite/rewrite-recipe-bom) from 2.6.0 to 2.6.3. - [Release notes](https://github.com/openrewrite/rewrite-recipe-bom/releases) - [Commits](https://github.com/openrewrite/rewrite-recipe-bom/compare/v2.6.0...v2.6.3) --- updated-dependencies: - dependency-name: org.openrewrite.recipe:rewrite-recipe-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- spring-data-eclipse-store-migration/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 4ebe921..d4ebe96 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -47,7 +47,7 @@ UTF-8 UTF-8 - 2.6.0 + 2.6.3 3.2.2 1.0.0 5.10.0 From 64a0642dd32b5e3d6118044a48ee0abfbaab96a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 30 Jan 2024 00:31:13 +0000 Subject: [PATCH 12/43] Bump com.puppycrawl.tools:checkstyle from 10.12.7 to 10.13.0 Bumps [com.puppycrawl.tools:checkstyle](https://github.com/checkstyle/checkstyle) from 10.12.7 to 10.13.0. - [Release notes](https://github.com/checkstyle/checkstyle/releases) - [Commits](https://github.com/checkstyle/checkstyle/compare/checkstyle-10.12.7...checkstyle-10.13.0) --- updated-dependencies: - dependency-name: com.puppycrawl.tools:checkstyle dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- spring-data-eclipse-store-migration/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 4ebe921..da59b90 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -275,7 +275,7 @@ com.puppycrawl.tools checkstyle - 10.12.7 + 10.13.0 From 07673dd37fcd400954fd2c8faa3f6d5c61e8053b Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Fri, 2 Feb 2024 08:05:46 +0100 Subject: [PATCH 13/43] Cleanup --- spring-data-eclipse-store-migration/pom.xml | 7 +++++ .../store/AddAnnotationToOtherAnnotation.java | 27 ++++++++++--------- .../resources/META-INF/rewrite/rewrite.yml | 2 -- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 4ebe921..cc8cedf 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -141,6 +141,13 @@ rewrite-test test + + org.slf4j + slf4j-simple + 2.0.11 + test + + diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java index 43c86d7..3ee26b0 100644 --- a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java @@ -27,6 +27,7 @@ import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.tree.J; + public class AddAnnotationToOtherAnnotation extends Recipe { @@ -83,8 +84,8 @@ public String getDescription() @Override public TreeVisitor getVisitor() { - final AnnotationMatcher EXISTING_ANNOTATION_MATCHER = new AnnotationMatcher(this.existingAnnotationType); - final AnnotationMatcher NEW_ANNOTATION_MATCHER = new AnnotationMatcher(this.annotationTypeToAdd); + final AnnotationMatcher existingAnnotationMatcher = new AnnotationMatcher(this.existingAnnotationType); + final AnnotationMatcher newAnnotationMatcher = new AnnotationMatcher(this.annotationTypeToAdd); return new JavaIsoVisitor<>() { @Override @@ -95,17 +96,17 @@ public J.ClassDeclaration visitClassDeclaration( final J.ClassDeclaration cd = super.visitClassDeclaration(classDecl, executionContext); if( - cd.getAnnotations() == null || - cd.getLeadingAnnotations() - .stream() - .filter(annotation -> EXISTING_ANNOTATION_MATCHER.matches(annotation)) - .findAny() - .isEmpty() || - cd.getLeadingAnnotations() - .stream() - .filter(annotation -> NEW_ANNOTATION_MATCHER.matches(annotation)) - .findAny() - .isPresent() + cd.getAnnotations() == null + || cd.getLeadingAnnotations() + .stream() + .filter(annotation -> existingAnnotationMatcher.matches(annotation)) + .findAny() + .isEmpty() + || cd.getLeadingAnnotations() + .stream() + .filter(annotation -> newAnnotationMatcher.matches(annotation)) + .findAny() + .isPresent() ) { return cd; diff --git a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml index f8ae837..718b462 100644 --- a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml +++ b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml @@ -40,5 +40,3 @@ recipeList: - org.openrewrite.java.RemoveAnnotation: # https://docs.openrewrite.org/reference/method-patterns annotationPattern: '@org.springframework.data.jpa.repository.Query *(..)' - - - org.openrewrite.java.RemoveUnusedImports From 257f3f66ae0d8d0d5bd11ad3e2f277f7e06223f6 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Fri, 2 Feb 2024 08:44:22 +0100 Subject: [PATCH 14/43] Added tests --- .../store/AddAnnotationToOtherAnnotation.java | 61 +++++-- .../AddAnnotationToOtherAnnotationTest.java | 153 +++++++++++++++++- 2 files changed, 198 insertions(+), 16 deletions(-) diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java index 3ee26b0..e53ca02 100644 --- a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java @@ -16,7 +16,9 @@ package software.xdev.spring.data.eclipse.store; import java.util.Comparator; +import java.util.Objects; +import org.jetbrains.annotations.NotNull; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.Recipe; @@ -30,7 +32,6 @@ public class AddAnnotationToOtherAnnotation extends Recipe { - @Option(displayName = "Existing annotation type", description = "Annotation type that is already existing. Recipe is looking for this annotation to add the new " + "annotation.", @@ -70,43 +71,39 @@ public AddAnnotationToOtherAnnotation() } @Override - public String getDisplayName() + public @NotNull String getDisplayName() { return "AddAnnotationToOtherAnnotation"; } @Override - public String getDescription() + public @NotNull String getDescription() { return "Add the a new annotation to an existing annotation."; } @Override - public TreeVisitor getVisitor() + public @NotNull TreeVisitor getVisitor() { final AnnotationMatcher existingAnnotationMatcher = new AnnotationMatcher(this.existingAnnotationType); final AnnotationMatcher newAnnotationMatcher = new AnnotationMatcher(this.annotationTypeToAdd); return new JavaIsoVisitor<>() { @Override - public J.ClassDeclaration visitClassDeclaration( - final J.ClassDeclaration classDecl, - final ExecutionContext executionContext) + public J.@NotNull ClassDeclaration visitClassDeclaration( + final J.@NotNull ClassDeclaration classDecl, + final @NotNull ExecutionContext executionContext) { final J.ClassDeclaration cd = super.visitClassDeclaration(classDecl, executionContext); if( - cd.getAnnotations() == null - || cd.getLeadingAnnotations() + cd.getLeadingAnnotations() .stream() - .filter(annotation -> existingAnnotationMatcher.matches(annotation)) + .filter(existingAnnotationMatcher::matches) .findAny() - .isEmpty() - || cd.getLeadingAnnotations() + .isEmpty() || cd.getLeadingAnnotations() .stream() - .filter(annotation -> newAnnotationMatcher.matches(annotation)) - .findAny() - .isPresent() + .anyMatch(newAnnotationMatcher::matches) ) { return cd; @@ -150,4 +147,38 @@ public String getAnnotationTypeToAddSimpleName() { return this.annotationTypeToAddSimpleName; } + + @Override + public boolean equals(final Object o) + { + if(this == o) + { + return true; + } + if(o == null || this.getClass() != o.getClass()) + { + return false; + } + if(!super.equals(o)) + { + return false; + } + final AddAnnotationToOtherAnnotation that = (AddAnnotationToOtherAnnotation)o; + return Objects.equals(this.existingAnnotationType, that.existingAnnotationType) && Objects.equals( + this.annotationTypeToAdd, + that.annotationTypeToAdd) && Objects.equals(this.classPath, that.classPath) && Objects.equals( + this.annotationTypeToAddSimpleName, + that.annotationTypeToAddSimpleName); + } + + @Override + public int hashCode() + { + return Objects.hash( + super.hashCode(), + this.existingAnnotationType, + this.annotationTypeToAdd, + this.classPath, + this.annotationTypeToAddSimpleName); + } } diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java index 57d3c61..40ef2e8 100644 --- a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java @@ -44,7 +44,7 @@ public void defaults(final RecipeSpec recipeSpec) } @Test - void testAddingAnnotation() + void testSimpleSingle() { this.rewriteRun ( @@ -77,4 +77,155 @@ public A() ) ); } + + @Test + void testSimpleMultiple() + { + this.rewriteRun + ( + java + ( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication + class A + { + public A() + { + } + } + """, + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class A + { + public A() + { + } + } + """ + ), + java + ( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication + class B + { + public B() + { + } + } + """, + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class B + { + public B() + { + } + } + """ + ) + ); + } + + @Test + void testAlreadyAdded() + { + this.rewriteRun + ( + java + ( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class A + { + public A() + { + } + } + """ + ) + ); + } + + @Test + void testSimpleNoAnnotation() + { + this.rewriteRun + ( + java + ( + """ + class A + { + public A() + { + } + } + """ + ) + ); + } + + @Test + void testSimpleNoAnnotationAndAnnotation() + { + this.rewriteRun + ( + java + ( + """ + class B + { + public B() + { + } + } + """ + ), + java + ( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication + class A + { + public A() + { + } + } + """, + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class A + { + public A() + { + } + } + """ + ) + ); + } } From b96febaac1f942587eb8cec757b410561de3956d Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Fri, 2 Feb 2024 08:45:26 +0100 Subject: [PATCH 15/43] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0589270..551a6f1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ through a [OpenRewrite](https://docs.openrewrite.org/)-Recipe. ## Usage -[Usage guide for the latest release](https://github.com/xdev-software/spring-data-eclipse-store-migration/releases/latest#Usage +[Usage guide for the latest release](https://github.com/xdev-software/spring-data-eclipse-store-migration/releases/latest#Usage) > [!CAUTION] > Since Spring-Data-Eclipse-Store can't handle ```@Query```-Annotations, From f0e390cf33fb73948b6179b96f0d081d60e898e7 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Fri, 2 Feb 2024 08:58:10 +0100 Subject: [PATCH 16/43] Prefix Test methods with public to make them visible to maven --- .../store/AddAnnotationToOtherAnnotationTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java index 40ef2e8..71bd8e4 100644 --- a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java @@ -44,7 +44,7 @@ public void defaults(final RecipeSpec recipeSpec) } @Test - void testSimpleSingle() + public void testSimpleSingle() { this.rewriteRun ( @@ -79,7 +79,7 @@ public A() } @Test - void testSimpleMultiple() + public void testSimpleMultiple() { this.rewriteRun ( @@ -141,7 +141,7 @@ public B() } @Test - void testAlreadyAdded() + public void testAlreadyAdded() { this.rewriteRun ( @@ -165,7 +165,7 @@ public A() } @Test - void testSimpleNoAnnotation() + public void testSimpleNoAnnotation() { this.rewriteRun ( @@ -184,7 +184,7 @@ public A() } @Test - void testSimpleNoAnnotationAndAnnotation() + public void testSimpleNoAnnotationAndAnnotation() { this.rewriteRun ( From 66e0aba116c184b9a71acc67435acc0d256e1bac Mon Sep 17 00:00:00 2001 From: Alex B <45384811+AB-xdev@users.noreply.github.com> Date: Fri, 2 Feb 2024 11:37:05 +0100 Subject: [PATCH 17/43] Update release.yml --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2aced3a..41e648f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -98,7 +98,7 @@ jobs: ## Usage Execute the following maven command in the maven project that you want to migrate: ``` - mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \ + mvn org.openrewrite.maven:rewrite-maven-plugin:run \ -Drewrite.recipeArtifactCoordinates=software.xdev:${{ env.PRIMARY_MAVEN_MODULE }}:${{ steps.version.outputs.release }} \ -Drewrite.activeRecipes=software.xdev.spring.data.eclipse.store.JpaMigration ``` From 38e8799a7f6deac315f7f3a36f2f45a59d25b8c3 Mon Sep 17 00:00:00 2001 From: Alex B <45384811+AB-xdev@users.noreply.github.com> Date: Fri, 2 Feb 2024 11:37:32 +0100 Subject: [PATCH 18/43] Update update-from-template.yml --- .github/workflows/update-from-template.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index adbb78a..a325e2b 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -14,7 +14,7 @@ on: env: UPDATE_BRANCH: update-from-template - REMOTE_URL: https://github.com/xdev-software/spring-data-eclipse-store-migration.git + REMOTE_URL: https://github.com/xdev-software/standard-maven-template.git REMOTE_BRANCH: master permissions: From 1b180ec22a372fedce9a29fd578759f9e426dbd0 Mon Sep 17 00:00:00 2001 From: AB Date: Fri, 2 Feb 2024 11:46:11 +0100 Subject: [PATCH 19/43] Fix some sonar warnings --- .../store/AddAnnotationToOtherAnnotationTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java index 71bd8e4..9cbfba6 100644 --- a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java @@ -26,7 +26,7 @@ import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; -public class AddAnnotationToOtherAnnotationTest implements RewriteTest +class AddAnnotationToOtherAnnotationTest implements RewriteTest { @Override @@ -44,7 +44,7 @@ public void defaults(final RecipeSpec recipeSpec) } @Test - public void testSimpleSingle() + void testSimpleSingle() { this.rewriteRun ( @@ -79,7 +79,7 @@ public A() } @Test - public void testSimpleMultiple() + void testSimpleMultiple() { this.rewriteRun ( @@ -141,7 +141,7 @@ public B() } @Test - public void testAlreadyAdded() + void testAlreadyAdded() { this.rewriteRun ( @@ -165,7 +165,7 @@ public A() } @Test - public void testSimpleNoAnnotation() + void testSimpleNoAnnotation() { this.rewriteRun ( @@ -184,7 +184,7 @@ public A() } @Test - public void testSimpleNoAnnotationAndAnnotation() + void testSimpleNoAnnotationAndAnnotation() { this.rewriteRun ( From f27b25678bac6d6edce06e9807071911d1cc9394 Mon Sep 17 00:00:00 2001 From: AB Date: Fri, 2 Feb 2024 11:52:16 +0100 Subject: [PATCH 20/43] Fix dependencies --- spring-data-eclipse-store-migration/pom.xml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 77deae1..cde3cc7 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -47,12 +47,10 @@ UTF-8 UTF-8 + 2.6.3 3.2.2 1.0.0 - 5.10.0 - 3.24.2 - 2.0.5 @@ -144,7 +142,6 @@ org.slf4j slf4j-simple - 2.0.11 test @@ -224,6 +221,11 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + From 92a1070d8d34469a987987c2ac95f8b00fd3ce6f Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 5 Feb 2024 13:00:18 +0100 Subject: [PATCH 21/43] Update Spring-Data-Eclipse-Store version --- .../src/main/resources/META-INF/rewrite/rewrite.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml index 718b462..b50a44f 100644 --- a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml +++ b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml @@ -19,7 +19,7 @@ recipeList: - org.openrewrite.maven.AddDependency: groupId: software.xdev artifactId: spring-data-eclipse-store - version: 1.0.0 + version: 1.0.1 acceptTransitive: true - org.openrewrite.maven.AddPlugin: From 64fcf4e8d79e33bddb67326d5d3501b43676fe24 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Mon, 5 Feb 2024 13:00:34 +0100 Subject: [PATCH 22/43] Removed recipe to remove jpa dependency --- .../src/main/resources/META-INF/rewrite/rewrite.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml index b50a44f..611e5a0 100644 --- a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml +++ b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml @@ -33,10 +33,6 @@ recipeList: artifactId: spring-boot-maven-plugin configuration: --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED - - org.openrewrite.maven.RemoveDependency: - groupId: org.springframework.boot - artifactId: spring-boot-starter-data-jpa - - org.openrewrite.java.RemoveAnnotation: # https://docs.openrewrite.org/reference/method-patterns annotationPattern: '@org.springframework.data.jpa.repository.Query *(..)' From e9ad1c608814d49ad803b40ee0afaa7f4059b2e0 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Tue, 6 Feb 2024 11:36:21 +0100 Subject: [PATCH 23/43] Added lombok --- spring-data-eclipse-store-migration/pom.xml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index cde3cc7..97eb63b 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -51,6 +51,7 @@ 2.6.3 3.2.2 1.0.0 + 1.18.30 @@ -116,6 +117,13 @@ org.openrewrite rewrite-maven + + org.projectlombok + lombok + ${lombok.version} + provided + + org.springframework.boot @@ -184,9 +192,6 @@ 3.12.1 ${maven.compiler.release} - - -proc:none - From 8315711bb4995879eac33bf83dec1a1fa4a43f57 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Tue, 6 Feb 2024 11:37:28 +0100 Subject: [PATCH 24/43] Try something with AddAttributeToAnnotationIfClassExists --- ...AddAttributeToAnnotationIfClassExists.java | 101 +++++++ .../store/AddOrUpdateAnnotationAttribute.java | 257 ++++++++++++++++++ ...ttributeToAnnotationIfClassExistsTest.java | 85 ++++++ 3 files changed, 443 insertions(+) create mode 100644 spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExists.java create mode 100644 spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddOrUpdateAnnotationAttribute.java create mode 100644 spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExistsTest.java diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExists.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExists.java new file mode 100644 index 0000000..9f2cf46 --- /dev/null +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExists.java @@ -0,0 +1,101 @@ +/* + * Copyright © 2023 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store; + +import org.jetbrains.annotations.NotNull; +import org.openrewrite.ExecutionContext; +import org.openrewrite.Option; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class AddAttributeToAnnotationIfClassExists extends Recipe +{ + @Option(displayName = "::::TODO:::Existing annotation type", + description = + "::::TODO:::Annotation type that is already existing. Recipe is looking for this annotation to add the " + + "new " + + "annotation.", + example = "software.xdev") + String className; + + @Option(displayName = "Annotation Type", + description = "The fully qualified name of the annotation.", + example = "org.junit.Test") + String annotationType; + + @Option(displayName = "Attribute name", + description = "The name of attribute to change. If omitted defaults to 'value'.", + required = false, + example = "timeout") + String attributeName; + + @Option(displayName = "Attribute value", + description = "The value to set the attribute to. Set to `null` to remove the attribute.", + example = "500") + String attributeValue; + + @Override + public @NotNull String getDisplayName() + { + return "AddValueToAnnotationIfDependencyExists"; + } + + @Override + public @NotNull String getDescription() + { + return "::::TODO:::Add the a new annotation to an existing annotation."; + } + + @Override + public @NotNull TreeVisitor getVisitor() + { + if(!this.doesClasspathContainClass(this.className)) + { + return TreeVisitor.noop(); + } + return new AddOrUpdateAnnotationAttribute( + this.annotationType, + this.attributeName, + this.attributeValue, + false + ).getVisitor(); + } + + private boolean doesClasspathContainClass(final String classToCheck) + { + try + { + Class.forName(classToCheck, false, this.getClass().getClassLoader()); + return true; + } + catch(final ClassNotFoundException e) + { + return false; + } + } +} diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddOrUpdateAnnotationAttribute.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddOrUpdateAnnotationAttribute.java new file mode 100644 index 0000000..4af7329 --- /dev/null +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddOrUpdateAnnotationAttribute.java @@ -0,0 +1,257 @@ +/* + * Copyright © 2023 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.openrewrite.ExecutionContext; +import org.openrewrite.Option; +import org.openrewrite.Preconditions; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.internal.ListUtils; +import org.openrewrite.internal.lang.Nullable; +import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.java.JavaTemplate; +import org.openrewrite.java.search.UsesType; +import org.openrewrite.java.tree.Expression; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.JavaType; +import org.openrewrite.java.tree.TypeUtils; + +import lombok.EqualsAndHashCode; +import lombok.Value; + + +@Value +@EqualsAndHashCode(callSuper = true) +public class AddOrUpdateAnnotationAttribute extends Recipe +{ + @Override + public String getDisplayName() + { + return "Add or update annotation attribute"; + } + + @Override + public String getDescription() + { + return "Some annotations accept arguments. This recipe sets an existing argument to the specified value, " + + "or adds the argument if it is not already set."; + } + + @Option(displayName = "Annotation Type", + description = "The fully qualified name of the annotation.", + example = "org.junit.Test") + String annotationType; + + @Option(displayName = "Attribute name", + description = "The name of attribute to change. If omitted defaults to 'value'.", + required = false, + example = "timeout") + @Nullable + String attributeName; + + @Option(displayName = "Attribute value", + description = "The value to set the attribute to. Set to `null` to remove the attribute.", + example = "500") + @Nullable + String attributeValue; + + @Option(displayName = "Add Only", + description = "When set to `true` will not change existing annotation attribute values.") + @Nullable + Boolean addOnly; + + @Override + public TreeVisitor getVisitor() + { + return Preconditions.check(new UsesType<>(this.annotationType, false), new JavaIsoVisitor<>() + { + @Override + public J.Annotation visitAnnotation(J.Annotation a, final ExecutionContext ctx) + { + if(!TypeUtils.isOfClassType(a.getType(), AddOrUpdateAnnotationAttribute.this.annotationType)) + { + return a; + } + + final String newAttributeValue = + maybeQuoteStringArgument(AddOrUpdateAnnotationAttribute.this.attributeName, + AddOrUpdateAnnotationAttribute.this.attributeValue, a); + final List currentArgs = a.getArguments(); + if(currentArgs == null || currentArgs.isEmpty()) + { + if(newAttributeValue == null) + { + return a; + } + + if(AddOrUpdateAnnotationAttribute.this.attributeName == null || "value".equals( + AddOrUpdateAnnotationAttribute.this.attributeName)) + { + return JavaTemplate.builder("#{}") + .contextSensitive() + .build() + .apply(this.getCursor(), a.getCoordinates().replaceArguments(), newAttributeValue); + } + else + { + final String[] classNames = AddOrUpdateAnnotationAttribute.this.attributeValue.replace("{", "") + .replace("}", "") + .split(","); + Arrays.stream(classNames).forEach(className -> + this.maybeAddImport(className)); + return JavaTemplate.builder("#{} = #{}") + .contextSensitive() + .build() + .apply( + this.getCursor(), + a.getCoordinates().replaceArguments(), + AddOrUpdateAnnotationAttribute.this.attributeName, + newAttributeValue); + } + } + else + { + // First assume the value exists amongst the arguments and attempt to update it + final AtomicBoolean foundAttributeWithDesiredValue = new AtomicBoolean(false); + final J.Annotation finalA = a; + final List newArgs = ListUtils.map(currentArgs, it -> { + if(it instanceof J.Assignment) + { + final J.Assignment as = (J.Assignment)it; + final J.Identifier var = (J.Identifier)as.getVariable(); + if(AddOrUpdateAnnotationAttribute.this.attributeName == null + || !AddOrUpdateAnnotationAttribute.this.attributeName.equals(var.getSimpleName())) + { + return it; + } + if(!(as.getAssignment() instanceof J.Literal)) + { + foundAttributeWithDesiredValue.set(true); + return it; + } + final J.Literal value = (J.Literal)as.getAssignment(); + if(newAttributeValue == null) + { + return null; + } + if(newAttributeValue.equals(value.getValueSource()) || Boolean.TRUE.equals( + AddOrUpdateAnnotationAttribute.this.addOnly)) + { + foundAttributeWithDesiredValue.set(true); + return it; + } + return as.withAssignment(value.withValue(newAttributeValue) + .withValueSource(newAttributeValue)); + } + else if(it instanceof J.Literal) + { + // The only way anything except an assignment can appear is if there's an implicit + // assignment to "value" + if(AddOrUpdateAnnotationAttribute.this.attributeName == null || "value".equals( + AddOrUpdateAnnotationAttribute.this.attributeName)) + { + if(newAttributeValue == null) + { + return null; + } + final J.Literal value = (J.Literal)it; + if(newAttributeValue.equals(value.getValueSource()) || Boolean.TRUE.equals( + AddOrUpdateAnnotationAttribute.this.addOnly)) + { + foundAttributeWithDesiredValue.set(true); + return it; + } + return ((J.Literal)it).withValue(newAttributeValue).withValueSource(newAttributeValue); + } + else + { + // noinspection ConstantConditions + return ((J.Annotation)JavaTemplate.builder("value = #{}") + .contextSensitive() + .build() + .apply(this.getCursor(), finalA.getCoordinates().replaceArguments(), it) + ).getArguments().get(0); + } + } + return it; + }); + if(foundAttributeWithDesiredValue.get() || newArgs != currentArgs) + { + return a.withArguments(newArgs); + } + // There was no existing value to update, so add a new value into the argument list + final String effectiveName = (AddOrUpdateAnnotationAttribute.this.attributeName == null) ? + "value" : + AddOrUpdateAnnotationAttribute.this.attributeName; + // noinspection ConstantConditions + final J.Assignment as = (J.Assignment)((J.Annotation)JavaTemplate.builder("#{} = #{}") + .contextSensitive() + .build() + .apply( + this.getCursor(), + a.getCoordinates().replaceArguments(), + effectiveName, + newAttributeValue) + ).getArguments().get(0); + final List newArguments = ListUtils.concat(as, a.getArguments()); + a = a.withArguments(newArguments); + a = this.autoFormat(a, ctx); + } + + return a; + } + }); + } + + @Nullable + private static String maybeQuoteStringArgument( + @Nullable final String attributeName, + @Nullable final String attributeValue, + final J.Annotation annotation) + { + if((attributeValue != null) && attributeIsString(attributeName, annotation)) + { + return "\"" + attributeValue + "\""; + } + else + { + return attributeValue; + } + } + + private static boolean attributeIsString(@Nullable final String attributeName, final J.Annotation annotation) + { + final String actualAttributeName = (attributeName == null) ? "value" : attributeName; + final JavaType.Class annotationType = (JavaType.Class)annotation.getType(); + if(annotationType != null) + { + for(final JavaType.Method m : annotationType.getMethods()) + { + if(m.getName().equals(actualAttributeName)) + { + return TypeUtils.isOfClassType(m.getReturnType(), "java.lang.String"); + } + } + } + return false; + } +} + diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExistsTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExistsTest.java new file mode 100644 index 0000000..98d8c23 --- /dev/null +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExistsTest.java @@ -0,0 +1,85 @@ +/* + * Copyright © 2023 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store; + +import static org.openrewrite.java.Assertions.java; + +import org.junit.jupiter.api.Test; +import org.openrewrite.java.Java17Parser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; + + +class AddAttributeToAnnotationIfClassExistsTest implements RewriteTest +{ + + @Override + public void defaults(final RecipeSpec recipeSpec) + { + recipeSpec + .recipe(new AddAttributeToAnnotationIfClassExists( + HibernateJpaAutoConfiguration.class.getName(), + SpringBootApplication.class.getName(), + "exclude", + "{" + + DataSourceAutoConfiguration.class.getName() + + ".class," + + DataSourceTransactionManagerAutoConfiguration.class.getName() + + ".class," + + HibernateJpaAutoConfiguration.class.getName() + + ".class}")) + .parser(Java17Parser.builder() + .logCompilationWarningsAndErrors(true) + .classpath("spring-boot-autoconfigure")); + } + + @Test + void testSimpleSingle() + { + this.rewriteRun + ( + java + ( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication + class A + { + public A() + { + } + } + """, + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication(exclude = {org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration.class,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.class}) + class A + { + public A() + { + } + } + """ + ) + ); + } +} From fd74f3e768e246827c0639d49cc6399368219463 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Tue, 6 Feb 2024 11:39:50 +0100 Subject: [PATCH 25/43] Removed not working AddAttributeToAnnotationIfClassExists --- ...AddAttributeToAnnotationIfClassExists.java | 101 ------- .../store/AddOrUpdateAnnotationAttribute.java | 257 ------------------ ...ttributeToAnnotationIfClassExistsTest.java | 85 ------ 3 files changed, 443 deletions(-) delete mode 100644 spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExists.java delete mode 100644 spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddOrUpdateAnnotationAttribute.java delete mode 100644 spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExistsTest.java diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExists.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExists.java deleted file mode 100644 index 9f2cf46..0000000 --- a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExists.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright © 2023 XDEV Software (https://xdev.software) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package software.xdev.spring.data.eclipse.store; - -import org.jetbrains.annotations.NotNull; -import org.openrewrite.ExecutionContext; -import org.openrewrite.Option; -import org.openrewrite.Recipe; -import org.openrewrite.TreeVisitor; - -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class AddAttributeToAnnotationIfClassExists extends Recipe -{ - @Option(displayName = "::::TODO:::Existing annotation type", - description = - "::::TODO:::Annotation type that is already existing. Recipe is looking for this annotation to add the " - + "new " - + "annotation.", - example = "software.xdev") - String className; - - @Option(displayName = "Annotation Type", - description = "The fully qualified name of the annotation.", - example = "org.junit.Test") - String annotationType; - - @Option(displayName = "Attribute name", - description = "The name of attribute to change. If omitted defaults to 'value'.", - required = false, - example = "timeout") - String attributeName; - - @Option(displayName = "Attribute value", - description = "The value to set the attribute to. Set to `null` to remove the attribute.", - example = "500") - String attributeValue; - - @Override - public @NotNull String getDisplayName() - { - return "AddValueToAnnotationIfDependencyExists"; - } - - @Override - public @NotNull String getDescription() - { - return "::::TODO:::Add the a new annotation to an existing annotation."; - } - - @Override - public @NotNull TreeVisitor getVisitor() - { - if(!this.doesClasspathContainClass(this.className)) - { - return TreeVisitor.noop(); - } - return new AddOrUpdateAnnotationAttribute( - this.annotationType, - this.attributeName, - this.attributeValue, - false - ).getVisitor(); - } - - private boolean doesClasspathContainClass(final String classToCheck) - { - try - { - Class.forName(classToCheck, false, this.getClass().getClassLoader()); - return true; - } - catch(final ClassNotFoundException e) - { - return false; - } - } -} diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddOrUpdateAnnotationAttribute.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddOrUpdateAnnotationAttribute.java deleted file mode 100644 index 4af7329..0000000 --- a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddOrUpdateAnnotationAttribute.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright © 2023 XDEV Software (https://xdev.software) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package software.xdev.spring.data.eclipse.store; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.openrewrite.ExecutionContext; -import org.openrewrite.Option; -import org.openrewrite.Preconditions; -import org.openrewrite.Recipe; -import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.java.JavaIsoVisitor; -import org.openrewrite.java.JavaTemplate; -import org.openrewrite.java.search.UsesType; -import org.openrewrite.java.tree.Expression; -import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.JavaType; -import org.openrewrite.java.tree.TypeUtils; - -import lombok.EqualsAndHashCode; -import lombok.Value; - - -@Value -@EqualsAndHashCode(callSuper = true) -public class AddOrUpdateAnnotationAttribute extends Recipe -{ - @Override - public String getDisplayName() - { - return "Add or update annotation attribute"; - } - - @Override - public String getDescription() - { - return "Some annotations accept arguments. This recipe sets an existing argument to the specified value, " + - "or adds the argument if it is not already set."; - } - - @Option(displayName = "Annotation Type", - description = "The fully qualified name of the annotation.", - example = "org.junit.Test") - String annotationType; - - @Option(displayName = "Attribute name", - description = "The name of attribute to change. If omitted defaults to 'value'.", - required = false, - example = "timeout") - @Nullable - String attributeName; - - @Option(displayName = "Attribute value", - description = "The value to set the attribute to. Set to `null` to remove the attribute.", - example = "500") - @Nullable - String attributeValue; - - @Option(displayName = "Add Only", - description = "When set to `true` will not change existing annotation attribute values.") - @Nullable - Boolean addOnly; - - @Override - public TreeVisitor getVisitor() - { - return Preconditions.check(new UsesType<>(this.annotationType, false), new JavaIsoVisitor<>() - { - @Override - public J.Annotation visitAnnotation(J.Annotation a, final ExecutionContext ctx) - { - if(!TypeUtils.isOfClassType(a.getType(), AddOrUpdateAnnotationAttribute.this.annotationType)) - { - return a; - } - - final String newAttributeValue = - maybeQuoteStringArgument(AddOrUpdateAnnotationAttribute.this.attributeName, - AddOrUpdateAnnotationAttribute.this.attributeValue, a); - final List currentArgs = a.getArguments(); - if(currentArgs == null || currentArgs.isEmpty()) - { - if(newAttributeValue == null) - { - return a; - } - - if(AddOrUpdateAnnotationAttribute.this.attributeName == null || "value".equals( - AddOrUpdateAnnotationAttribute.this.attributeName)) - { - return JavaTemplate.builder("#{}") - .contextSensitive() - .build() - .apply(this.getCursor(), a.getCoordinates().replaceArguments(), newAttributeValue); - } - else - { - final String[] classNames = AddOrUpdateAnnotationAttribute.this.attributeValue.replace("{", "") - .replace("}", "") - .split(","); - Arrays.stream(classNames).forEach(className -> - this.maybeAddImport(className)); - return JavaTemplate.builder("#{} = #{}") - .contextSensitive() - .build() - .apply( - this.getCursor(), - a.getCoordinates().replaceArguments(), - AddOrUpdateAnnotationAttribute.this.attributeName, - newAttributeValue); - } - } - else - { - // First assume the value exists amongst the arguments and attempt to update it - final AtomicBoolean foundAttributeWithDesiredValue = new AtomicBoolean(false); - final J.Annotation finalA = a; - final List newArgs = ListUtils.map(currentArgs, it -> { - if(it instanceof J.Assignment) - { - final J.Assignment as = (J.Assignment)it; - final J.Identifier var = (J.Identifier)as.getVariable(); - if(AddOrUpdateAnnotationAttribute.this.attributeName == null - || !AddOrUpdateAnnotationAttribute.this.attributeName.equals(var.getSimpleName())) - { - return it; - } - if(!(as.getAssignment() instanceof J.Literal)) - { - foundAttributeWithDesiredValue.set(true); - return it; - } - final J.Literal value = (J.Literal)as.getAssignment(); - if(newAttributeValue == null) - { - return null; - } - if(newAttributeValue.equals(value.getValueSource()) || Boolean.TRUE.equals( - AddOrUpdateAnnotationAttribute.this.addOnly)) - { - foundAttributeWithDesiredValue.set(true); - return it; - } - return as.withAssignment(value.withValue(newAttributeValue) - .withValueSource(newAttributeValue)); - } - else if(it instanceof J.Literal) - { - // The only way anything except an assignment can appear is if there's an implicit - // assignment to "value" - if(AddOrUpdateAnnotationAttribute.this.attributeName == null || "value".equals( - AddOrUpdateAnnotationAttribute.this.attributeName)) - { - if(newAttributeValue == null) - { - return null; - } - final J.Literal value = (J.Literal)it; - if(newAttributeValue.equals(value.getValueSource()) || Boolean.TRUE.equals( - AddOrUpdateAnnotationAttribute.this.addOnly)) - { - foundAttributeWithDesiredValue.set(true); - return it; - } - return ((J.Literal)it).withValue(newAttributeValue).withValueSource(newAttributeValue); - } - else - { - // noinspection ConstantConditions - return ((J.Annotation)JavaTemplate.builder("value = #{}") - .contextSensitive() - .build() - .apply(this.getCursor(), finalA.getCoordinates().replaceArguments(), it) - ).getArguments().get(0); - } - } - return it; - }); - if(foundAttributeWithDesiredValue.get() || newArgs != currentArgs) - { - return a.withArguments(newArgs); - } - // There was no existing value to update, so add a new value into the argument list - final String effectiveName = (AddOrUpdateAnnotationAttribute.this.attributeName == null) ? - "value" : - AddOrUpdateAnnotationAttribute.this.attributeName; - // noinspection ConstantConditions - final J.Assignment as = (J.Assignment)((J.Annotation)JavaTemplate.builder("#{} = #{}") - .contextSensitive() - .build() - .apply( - this.getCursor(), - a.getCoordinates().replaceArguments(), - effectiveName, - newAttributeValue) - ).getArguments().get(0); - final List newArguments = ListUtils.concat(as, a.getArguments()); - a = a.withArguments(newArguments); - a = this.autoFormat(a, ctx); - } - - return a; - } - }); - } - - @Nullable - private static String maybeQuoteStringArgument( - @Nullable final String attributeName, - @Nullable final String attributeValue, - final J.Annotation annotation) - { - if((attributeValue != null) && attributeIsString(attributeName, annotation)) - { - return "\"" + attributeValue + "\""; - } - else - { - return attributeValue; - } - } - - private static boolean attributeIsString(@Nullable final String attributeName, final J.Annotation annotation) - { - final String actualAttributeName = (attributeName == null) ? "value" : attributeName; - final JavaType.Class annotationType = (JavaType.Class)annotation.getType(); - if(annotationType != null) - { - for(final JavaType.Method m : annotationType.getMethods()) - { - if(m.getName().equals(actualAttributeName)) - { - return TypeUtils.isOfClassType(m.getReturnType(), "java.lang.String"); - } - } - } - return false; - } -} - diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExistsTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExistsTest.java deleted file mode 100644 index 98d8c23..0000000 --- a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAttributeToAnnotationIfClassExistsTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright © 2023 XDEV Software (https://xdev.software) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package software.xdev.spring.data.eclipse.store; - -import static org.openrewrite.java.Assertions.java; - -import org.junit.jupiter.api.Test; -import org.openrewrite.java.Java17Parser; -import org.openrewrite.test.RecipeSpec; -import org.openrewrite.test.RewriteTest; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; - - -class AddAttributeToAnnotationIfClassExistsTest implements RewriteTest -{ - - @Override - public void defaults(final RecipeSpec recipeSpec) - { - recipeSpec - .recipe(new AddAttributeToAnnotationIfClassExists( - HibernateJpaAutoConfiguration.class.getName(), - SpringBootApplication.class.getName(), - "exclude", - "{" - + DataSourceAutoConfiguration.class.getName() - + ".class," - + DataSourceTransactionManagerAutoConfiguration.class.getName() - + ".class," - + HibernateJpaAutoConfiguration.class.getName() - + ".class}")) - .parser(Java17Parser.builder() - .logCompilationWarningsAndErrors(true) - .classpath("spring-boot-autoconfigure")); - } - - @Test - void testSimpleSingle() - { - this.rewriteRun - ( - java - ( - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - - @SpringBootApplication - class A - { - public A() - { - } - } - """, - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - - @SpringBootApplication(exclude = {org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration.class,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.class}) - class A - { - public A() - { - } - } - """ - ) - ); - } -} From 95c59698bc9434ac663cc9a3317862f7254af730 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Tue, 6 Feb 2024 11:40:16 +0100 Subject: [PATCH 26/43] Update AddAnnotationToOtherAnnotation with lombok --- .../store/AddAnnotationToOtherAnnotation.java | 82 +++---------------- 1 file changed, 11 insertions(+), 71 deletions(-) diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java index e53ca02..2fd1c86 100644 --- a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java @@ -16,7 +16,6 @@ package software.xdev.spring.data.eclipse.store; import java.util.Comparator; -import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.openrewrite.ExecutionContext; @@ -29,7 +28,18 @@ import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.tree.J; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) public class AddAnnotationToOtherAnnotation extends Recipe { @Option(displayName = "Existing annotation type", @@ -54,22 +64,6 @@ public class AddAnnotationToOtherAnnotation extends Recipe example = "Test") String annotationTypeToAddSimpleName; - public AddAnnotationToOtherAnnotation( - final String existingAnnotationType, - final String annotationTypeToAdd, - final String classPath, - final String annotationTypeToAddSimpleName) - { - this.existingAnnotationType = existingAnnotationType; - this.annotationTypeToAdd = annotationTypeToAdd; - this.classPath = classPath; - this.annotationTypeToAddSimpleName = annotationTypeToAddSimpleName; - } - - public AddAnnotationToOtherAnnotation() - { - } - @Override public @NotNull String getDisplayName() { @@ -127,58 +121,4 @@ public AddAnnotationToOtherAnnotation() } }; } - - public String getExistingAnnotationType() - { - return this.existingAnnotationType; - } - - public String getAnnotationTypeToAdd() - { - return this.annotationTypeToAdd; - } - - public String getClassPath() - { - return this.classPath; - } - - public String getAnnotationTypeToAddSimpleName() - { - return this.annotationTypeToAddSimpleName; - } - - @Override - public boolean equals(final Object o) - { - if(this == o) - { - return true; - } - if(o == null || this.getClass() != o.getClass()) - { - return false; - } - if(!super.equals(o)) - { - return false; - } - final AddAnnotationToOtherAnnotation that = (AddAnnotationToOtherAnnotation)o; - return Objects.equals(this.existingAnnotationType, that.existingAnnotationType) && Objects.equals( - this.annotationTypeToAdd, - that.annotationTypeToAdd) && Objects.equals(this.classPath, that.classPath) && Objects.equals( - this.annotationTypeToAddSimpleName, - that.annotationTypeToAddSimpleName); - } - - @Override - public int hashCode() - { - return Objects.hash( - super.hashCode(), - this.existingAnnotationType, - this.annotationTypeToAdd, - this.classPath, - this.annotationTypeToAddSimpleName); - } } From 502c071966c2ddc962a383216295ed177e3fc946 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Tue, 6 Feb 2024 12:56:28 +0100 Subject: [PATCH 27/43] AddsProperty to exclude JPA now --- spring-data-eclipse-store-migration/pom.xml | 6 +- .../store/AddPropertyIfClassExists.java | 108 ++++++++++++++++ .../resources/META-INF/rewrite/rewrite.yml | 40 +++++- .../store/AddPropertyIfClassExistsTest.java | 119 ++++++++++++++++++ 4 files changed, 268 insertions(+), 5 deletions(-) create mode 100644 spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java create mode 100644 spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExistsTest.java diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 97eb63b..4f1b5c3 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -50,7 +50,7 @@ 2.6.3 3.2.2 - 1.0.0 + 1.0.1 1.18.30 @@ -115,7 +115,7 @@ org.openrewrite - rewrite-maven + rewrite-properties org.projectlombok @@ -136,7 +136,6 @@ ${software.xdev.spring.data.eclipse.store.version} runtime - org.openrewrite rewrite-java-17 @@ -152,7 +151,6 @@ slf4j-simple test - diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java new file mode 100644 index 0000000..895344f --- /dev/null +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java @@ -0,0 +1,108 @@ +/* + * Copyright © 2023 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store; + +import org.jetbrains.annotations.NotNull; +import org.openrewrite.ExecutionContext; +import org.openrewrite.Option; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.internal.lang.Nullable; +import org.openrewrite.properties.AddProperty; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class AddPropertyIfClassExists extends Recipe +{ + @Option(displayName = "Class that must exist in the classpath to add the property", + description = "Name of the class that must exist in the classpath to execute the recipe to add a property in the properties file.", + example = "software.xdev") + private String className; + + @Option( + displayName = "Property key", + description = "The property key to add.", + example = "management.metrics.enable.process.files" + ) + private String property; + @Option( + displayName = "Property value", + description = "The value of the new property key." + ) + private String value; + @Option( + displayName = "Optional comment to be prepended to the property", + description = "A comment that will be added to the new property.", + required = false, + example = "This is a comment" + ) + private @Nullable String comment; + @Option( + displayName = "Optional delimiter", + description = "Property entries support different delimiters (`=`, `:`, or whitespace). The default value is " + + "`=` unless provided the delimiter of the new property entry.", + required = false, + example = ":" + ) + private @Nullable String delimiter; + + @Override + public @NotNull String getDisplayName() + { + return "AddValueToAnnotationIfDependencyExists"; + } + + @Override + public @NotNull String getDescription() + { + return "::::TODO:::Add the a new annotation to an existing annotation."; + } + + @Override + public @NotNull TreeVisitor getVisitor() + { + if(!this.doesClasspathContainClass(this.className)) + { + return TreeVisitor.noop(); + } + return new AddProperty( + this.property, this.value, this.comment, this.delimiter + ).getVisitor(); + } + + private boolean doesClasspathContainClass(final String classToCheck) + { + try + { + Class.forName(classToCheck, false, this.getClass().getClassLoader()); + return true; + } + catch(final ClassNotFoundException e) + { + return false; + } + } +} diff --git a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml index 611e5a0..6608973 100644 --- a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml +++ b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml @@ -16,10 +16,17 @@ recipeList: classPath: 'spring-data-eclipse-store' annotationTypeToAddSimpleName: 'EnableEclipseStoreRepositories' + - software.xdev.spring.data.eclipse.store.AddPropertyIfClassExists: + className: 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration' + property: 'spring.autoconfigure.exclude' + value: 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration' + comment: 'This suppresses the use of JPA in the project. It is needed to let EclipseStore coexist with JPA.' + delimiter: = + - org.openrewrite.maven.AddDependency: groupId: software.xdev artifactId: spring-data-eclipse-store - version: 1.0.1 + version: 1.0.2 acceptTransitive: true - org.openrewrite.maven.AddPlugin: @@ -36,3 +43,34 @@ recipeList: - org.openrewrite.java.RemoveAnnotation: # https://docs.openrewrite.org/reference/method-patterns annotationPattern: '@org.springframework.data.jpa.repository.Query *(..)' + + - org.openrewrite.java.RemoveAnnotation: + annotationPattern: '@org.springframework.data.jpa.repository.config.EnableJpaRepositories *(..)' + + # Change all the spring framework repositories to specifically use EclipseStore repositories. + + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springframework.data.repository.Repository + newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCustomRepository + + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springframework.data.repository.CrudRepository + newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCrudRepository + + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springframework.data.repository.ListCrudRepository + newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListCrudRepository + + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springframework.data.repository.PagingAndSortingRepositoryRepository + newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStorePagingAndSortingRepositoryRepository + + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springframework.data.repository.ListPagingAndSortingRepositoryRepository + newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListPagingAndSortingRepositoryRepository + + # Change all the JPA repositories to specifically use EclipseStore repositories. + + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springframework.data.jpa.repository.JpaRepository + newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExistsTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExistsTest.java new file mode 100644 index 0000000..5d5babd --- /dev/null +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExistsTest.java @@ -0,0 +1,119 @@ +/* + * Copyright © 2023 XDEV Software (https://xdev.software) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package software.xdev.spring.data.eclipse.store; + +import static org.openrewrite.properties.Assertions.properties; + +import org.junit.jupiter.api.Test; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; + + +class AddPropertyIfClassExistsTest implements RewriteTest +{ + + @Override + public void defaults(final RecipeSpec recipeSpec) + { + recipeSpec + .recipe(new AddPropertyIfClassExists( + HibernateJpaAutoConfiguration.class.getName(), + "spring.autoconfigure.exclude", + DataSourceAutoConfiguration.class.getName() + + "," + + DataSourceTransactionManagerAutoConfiguration.class.getName() + + "," + + HibernateJpaAutoConfiguration.class.getName(), + "", + "=")); + } + + @Test + void testSimple() + { + this.rewriteRun + ( + properties( + "", + """ + spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """ + ) + ); + } + + /** + * It's not clear if this is a desired behavior, but since the Open Rewrite Recipe + * {@link org.openrewrite.properties.AddProperty} is doing this, and we are only using this recipe, this is how it + * works now. + *

+ * Might change in the future. + *

+ */ + @Test + void testMultipleProperties() + { + this.rewriteRun + ( + properties( + "", + """ + spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """ + ), + properties( + "", + """ + spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """ + ) + ); + } + + @Test + void testExisting() + { + this.rewriteRun + ( + properties( + """ + spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """ + ) + ); + } + + @Test + void testClassNotExisting() + { + this.rewriteRun + ( + recipeSpec -> + recipeSpec.recipe(new AddPropertyIfClassExists( + "not.existing.Class", + "spring.autoconfigure.exclude", + "DummyValue", + "", + "=")), + properties( + "" + ) + ); + } +} From bbaad195b7b372c86c4db518755d44f565385627 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Tue, 6 Feb 2024 13:02:19 +0100 Subject: [PATCH 28/43] Update AddPropertyIfClassExists.java --- .../spring/data/eclipse/store/AddPropertyIfClassExists.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java index 895344f..804ade8 100644 --- a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java @@ -72,13 +72,13 @@ public class AddPropertyIfClassExists extends Recipe @Override public @NotNull String getDisplayName() { - return "AddValueToAnnotationIfDependencyExists"; + return "AddPropertyIfClassExists"; } @Override public @NotNull String getDescription() { - return "::::TODO:::Add the a new annotation to an existing annotation."; + return "Add a property to the properties file if a specific class exists."; } @Override From d4f73f38c31e11665144ed3014b9bd433b241f96 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 00:31:13 +0000 Subject: [PATCH 29/43] Bump org.openrewrite.recipe:rewrite-recipe-bom from 2.6.3 to 2.6.4 Bumps [org.openrewrite.recipe:rewrite-recipe-bom](https://github.com/openrewrite/rewrite-recipe-bom) from 2.6.3 to 2.6.4. - [Release notes](https://github.com/openrewrite/rewrite-recipe-bom/releases) - [Commits](https://github.com/openrewrite/rewrite-recipe-bom/compare/v2.6.3...v2.6.4) --- updated-dependencies: - dependency-name: org.openrewrite.recipe:rewrite-recipe-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- spring-data-eclipse-store-migration/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 4f1b5c3..f535021 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -48,7 +48,7 @@ UTF-8 UTF-8 - 2.6.3 + 2.6.4 3.2.2 1.0.1 1.18.30 From da2121daad028a5c496318c517daed9ab7b7ff81 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Wed, 7 Feb 2024 07:54:58 +0100 Subject: [PATCH 30/43] Changed AddPropertyIfClassExists to AddSpringPropertyIfClassExists --- spring-data-eclipse-store-migration/pom.xml | 4 +- ...va => AddSpringPropertyIfClassExists.java} | 28 ++++--- .../resources/META-INF/rewrite/rewrite.yml | 3 +- ...> AddSpringPropertyIfClassExistsTest.java} | 76 +++++++++++++++---- 4 files changed, 81 insertions(+), 30 deletions(-) rename spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/{AddPropertyIfClassExists.java => AddSpringPropertyIfClassExists.java} (73%) rename spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/{AddPropertyIfClassExistsTest.java => AddSpringPropertyIfClassExistsTest.java} (65%) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 4f1b5c3..2b2d778 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -114,8 +114,8 @@ rewrite-java - org.openrewrite - rewrite-properties + org.openrewrite.recipe + rewrite-spring org.projectlombok diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExists.java similarity index 73% rename from spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java rename to spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExists.java index 804ade8..9fdebe0 100644 --- a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExists.java +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExists.java @@ -15,13 +15,15 @@ */ package software.xdev.spring.data.eclipse.store; +import java.util.List; + import org.jetbrains.annotations.NotNull; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.properties.AddProperty; +import org.openrewrite.java.spring.AddSpringProperty; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -35,7 +37,7 @@ @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode(callSuper = true) -public class AddPropertyIfClassExists extends Recipe +public class AddSpringPropertyIfClassExists extends Recipe { @Option(displayName = "Class that must exist in the classpath to add the property", description = "Name of the class that must exist in the classpath to execute the recipe to add a property in the properties file.", @@ -50,7 +52,8 @@ public class AddPropertyIfClassExists extends Recipe private String property; @Option( displayName = "Property value", - description = "The value of the new property key." + description = "The value of the new property key.", + example = "true" ) private String value; @Option( @@ -61,24 +64,25 @@ public class AddPropertyIfClassExists extends Recipe ) private @Nullable String comment; @Option( - displayName = "Optional delimiter", - description = "Property entries support different delimiters (`=`, `:`, or whitespace). The default value is " - + "`=` unless provided the delimiter of the new property entry.", + displayName = "Optional list of file path matcher", + description = "Each value in this list represents a glob expression that is used to match which files will be " + + "modified. If this value is not present, this recipe will query the execution context for reasonable " + + "defaults. (\"**/application.yml\", \"**/application.yml\", and \"**/application.properties\".", required = false, - example = ":" + example = "[\"**/application.yml\"]" ) - private @Nullable String delimiter; + private @Nullable List pathExpressions; @Override public @NotNull String getDisplayName() { - return "AddPropertyIfClassExists"; + return "AddSpringPropertyIfClassExists"; } @Override public @NotNull String getDescription() { - return "Add a property to the properties file if a specific class exists."; + return "Add a spring property to the properties file if a specific class exists."; } @Override @@ -88,8 +92,8 @@ public class AddPropertyIfClassExists extends Recipe { return TreeVisitor.noop(); } - return new AddProperty( - this.property, this.value, this.comment, this.delimiter + return new AddSpringProperty( + this.property, this.value, this.comment, this.pathExpressions ).getVisitor(); } diff --git a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml index 6608973..5cbf598 100644 --- a/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml +++ b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml @@ -16,12 +16,11 @@ recipeList: classPath: 'spring-data-eclipse-store' annotationTypeToAddSimpleName: 'EnableEclipseStoreRepositories' - - software.xdev.spring.data.eclipse.store.AddPropertyIfClassExists: + - software.xdev.spring.data.eclipse.store.AddSpringPropertyIfClassExists: className: 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration' property: 'spring.autoconfigure.exclude' value: 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration' comment: 'This suppresses the use of JPA in the project. It is needed to let EclipseStore coexist with JPA.' - delimiter: = - org.openrewrite.maven.AddDependency: groupId: software.xdev diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExistsTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java similarity index 65% rename from spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExistsTest.java rename to spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java index 5d5babd..b9f5d6d 100644 --- a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddPropertyIfClassExistsTest.java +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java @@ -16,6 +16,7 @@ package software.xdev.spring.data.eclipse.store; import static org.openrewrite.properties.Assertions.properties; +import static org.openrewrite.yaml.Assertions.yaml; import org.junit.jupiter.api.Test; import org.openrewrite.test.RecipeSpec; @@ -25,14 +26,14 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; -class AddPropertyIfClassExistsTest implements RewriteTest +class AddSpringPropertyIfClassExistsTest implements RewriteTest { @Override public void defaults(final RecipeSpec recipeSpec) { recipeSpec - .recipe(new AddPropertyIfClassExists( + .recipe(new AddSpringPropertyIfClassExists( HibernateJpaAutoConfiguration.class.getName(), "spring.autoconfigure.exclude", DataSourceAutoConfiguration.class.getName() @@ -40,12 +41,11 @@ public void defaults(final RecipeSpec recipeSpec) + DataSourceTransactionManagerAutoConfiguration.class.getName() + "," + HibernateJpaAutoConfiguration.class.getName(), - "", - "=")); + "", null)); } @Test - void testSimple() + void testSimpleProperties() { this.rewriteRun ( @@ -53,14 +53,57 @@ void testSimple() "", """ spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """ + """, + s -> s.path("application.properties") + ) + ); + } + + @Test + void testSimpleYaml() + { + this.rewriteRun + ( + yaml( + "", + """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("application.yml") + ) + ); + } + + @Test + void testWrongFileNameYaml() + { + this.rewriteRun + ( + yaml( + "", + s -> s.path("random.yml") + ) + ); + } + + @Test + void testWrongFileNameProperties() + { + this.rewriteRun + ( + properties( + "", + s -> s.path("random.properties") ) ); } /** * It's not clear if this is a desired behavior, but since the Open Rewrite Recipe - * {@link org.openrewrite.properties.AddProperty} is doing this, and we are only using this recipe, this is how it + * {@link org.openrewrite.java.spring.AddSpringProperty} is doing this, and we are only using this recipe, this is + * how it * works now. *

* Might change in the future. @@ -75,13 +118,17 @@ void testMultipleProperties() "", """ spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """ + """, + s -> s.path("application.properties") ), - properties( + yaml( "", """ - spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("application.yml") ) ); } @@ -105,14 +152,15 @@ void testClassNotExisting() this.rewriteRun ( recipeSpec -> - recipeSpec.recipe(new AddPropertyIfClassExists( + recipeSpec.recipe(new AddSpringPropertyIfClassExists( "not.existing.Class", "spring.autoconfigure.exclude", "DummyValue", "", - "=")), + null)), properties( - "" + "", + s -> s.path("application.properties") ) ); } From 1487461175f17e0373392ac1ed14c78b955f739e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Feb 2024 00:27:53 +0000 Subject: [PATCH 31/43] Bump software.xdev:spring-data-eclipse-store from 1.0.1 to 1.0.2 Bumps [software.xdev:spring-data-eclipse-store](https://github.com/xdev-software/spring-data-eclipse-store) from 1.0.1 to 1.0.2. - [Release notes](https://github.com/xdev-software/spring-data-eclipse-store/releases) - [Changelog](https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/CHANGELOG.md) - [Commits](https://github.com/xdev-software/spring-data-eclipse-store/compare/v1.0.1...v1.0.2) --- updated-dependencies: - dependency-name: software.xdev:spring-data-eclipse-store dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- spring-data-eclipse-store-migration/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 2b2d778..2152d13 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -50,7 +50,7 @@ 2.6.3 3.2.2 - 1.0.1 + 1.0.2 1.18.30 From 34d62b06e9e4dfad5ec2d1087de0c2070ab5da91 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Fri, 9 Feb 2024 14:35:59 +0100 Subject: [PATCH 32/43] Added Test for AddSpringPropertyIfClassExists --- .../AddSpringPropertyIfClassExistsTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java index b9f5d6d..58cbdb1 100644 --- a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java @@ -76,6 +76,45 @@ void testSimpleYaml() ); } + @Test + void testMultipleYamlAlsoInTestFolder() + { + this.rewriteRun + ( + yaml( + "", + """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("/src/main/resources/application.yml") + ), + yaml( + "", + """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("/src/test/resources/application.yml") + ), + yaml( + "", + """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("application.yml") + ), + yaml( + "", + s -> s.path("no-application.yml") + ) + ); + } + @Test void testWrongFileNameYaml() { From c78c5210bc79a9aa5f0bbb9b686fee1cd1bab251 Mon Sep 17 00:00:00 2001 From: JohannesRabauer Date: Tue, 13 Feb 2024 15:18:18 +0100 Subject: [PATCH 33/43] Fix for Checkstyle --- .../data/eclipse/store/AddSpringPropertyIfClassExists.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExists.java b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExists.java index 9fdebe0..57f5fb0 100644 --- a/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExists.java +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExists.java @@ -40,7 +40,8 @@ public class AddSpringPropertyIfClassExists extends Recipe { @Option(displayName = "Class that must exist in the classpath to add the property", - description = "Name of the class that must exist in the classpath to execute the recipe to add a property in the properties file.", + description = "Name of the class that must exist in the classpath to execute the " + + "recipe to add a property in the properties file.", example = "software.xdev") private String className; From 39482fcd6286ede2b0c90b1558316dbb28747eab Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 13 Feb 2024 14:23:35 +0000 Subject: [PATCH 34/43] Release 1.0.0 --- pom.xml | 2 +- spring-data-eclipse-store-migration/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3004559..0021e9c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ software.xdev spring-data-eclipse-store-migration-root - 1.0.0-SNAPSHOT + 1.0.0 pom diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index f051c35..345ef3a 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -6,7 +6,7 @@ software.xdev spring-data-eclipse-store-migration - 1.0.0-SNAPSHOT + 1.0.0 jar spring-data-eclipse-store-migration From db8452ff1298e0f875f7271563fd3879bf1269da Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 13 Feb 2024 14:25:58 +0000 Subject: [PATCH 35/43] Preparing for next development iteration --- pom.xml | 2 +- spring-data-eclipse-store-migration/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0021e9c..5884e7e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ software.xdev spring-data-eclipse-store-migration-root - 1.0.0 + 1.0.1-SNAPSHOT pom diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 345ef3a..d07a561 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -6,7 +6,7 @@ software.xdev spring-data-eclipse-store-migration - 1.0.0 + 1.0.1-SNAPSHOT jar spring-data-eclipse-store-migration From 08710dad55799cb987c6fd7e81c9fc517b5ec796 Mon Sep 17 00:00:00 2001 From: XDEV Renovate Bot Date: Thu, 11 Apr 2024 07:50:15 +0000 Subject: [PATCH 36/43] Update dependency org.projectlombok:lombok to v1.18.32 --- spring-data-eclipse-store-migration/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index d82a7fe..88a5ef6 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -51,7 +51,7 @@ 2.6.4 3.2.2 1.0.2 - 1.18.30 + 1.18.32 From e1fc90c0696ad8de05418515a090fca1f8776516 Mon Sep 17 00:00:00 2001 From: XDEV Renovate Bot Date: Thu, 11 Apr 2024 07:50:22 +0000 Subject: [PATCH 37/43] Update dependency org.openrewrite.recipe:rewrite-recipe-bom to v2.9.0 --- spring-data-eclipse-store-migration/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index d82a7fe..ddbd5ea 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -48,7 +48,7 @@ UTF-8 UTF-8 - 2.6.4 + 2.9.0 3.2.2 1.0.2 1.18.30 From 53ca21164df50a6bfab7d956dbdf4ebe977c9f0c Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 23 Apr 2024 09:28:27 +0200 Subject: [PATCH 38/43] Rename I --- .run/Run Demo.run.xml | 2 +- CONTRIBUTING.md | 4 ++-- README.md | 12 ++++++------ SECURITY.md | 2 +- pom.xml | 6 +++--- template-placeholder-demo/pom.xml | 4 ++-- template-placeholder/pom.xml | 12 ++++++------ 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.run/Run Demo.run.xml b/.run/Run Demo.run.xml index 5fb2bc2..0518f97 100644 --- a/.run/Run Demo.run.xml +++ b/.run/Run Demo.run.xml @@ -1,7 +1,7 @@ - template-placeholder - template-placeholder-demo + spring-data-eclipse-store-migration + spring-data-eclipse-store-migration-demo diff --git a/template-placeholder-demo/pom.xml b/template-placeholder-demo/pom.xml index 78b4a3e..06625d1 100644 --- a/template-placeholder-demo/pom.xml +++ b/template-placeholder-demo/pom.xml @@ -5,7 +5,7 @@ 4.0.0 software.xdev - template-placeholder-demo + spring-data-eclipse-store-migration-demo 1.0.0-SNAPSHOT jar @@ -27,7 +27,7 @@ software.xdev - template-placeholder + spring-data-eclipse-store-migration ${project.version} diff --git a/template-placeholder/pom.xml b/template-placeholder/pom.xml index b72a766..03a3e37 100644 --- a/template-placeholder/pom.xml +++ b/template-placeholder/pom.xml @@ -5,17 +5,17 @@ 4.0.0 software.xdev - template-placeholder + spring-data-eclipse-store-migration 1.0.0-SNAPSHOT jar - template-placeholder - template-placeholder - https://github.com/xdev-software/template-placeholder + spring-data-eclipse-store-migration + spring-data-eclipse-store-migration + https://github.com/xdev-software/spring-data-eclipse-store-migration - https://github.com/xdev-software/template-placeholder - scm:git:https://github.com/xdev-software/template-placeholder.git + https://github.com/xdev-software/spring-data-eclipse-store-migration + scm:git:https://github.com/xdev-software/spring-data-eclipse-store-migration.git 2023 From 2bd738b17e5310c835850475a9101a2396e46ebb Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 23 Apr 2024 09:28:44 +0200 Subject: [PATCH 39/43] Rename II --- .../pom.xml | 0 .../pom.xml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {template-placeholder-demo => spring-data-eclipse-store-migration-demo}/pom.xml (100%) rename {template-placeholder => spring-data-eclipse-store-migration}/pom.xml (100%) diff --git a/template-placeholder-demo/pom.xml b/spring-data-eclipse-store-migration-demo/pom.xml similarity index 100% rename from template-placeholder-demo/pom.xml rename to spring-data-eclipse-store-migration-demo/pom.xml diff --git a/template-placeholder/pom.xml b/spring-data-eclipse-store-migration/pom.xml similarity index 100% rename from template-placeholder/pom.xml rename to spring-data-eclipse-store-migration/pom.xml From bf95365634429bb89bd5e2096cfe6c694819c375 Mon Sep 17 00:00:00 2001 From: AB Date: Wed, 12 Jun 2024 09:29:17 +0200 Subject: [PATCH 40/43] Fill in template --- .github/ISSUE_TEMPLATE/bug_report.yml | 4 ++-- .github/ISSUE_TEMPLATE/enhancement.yml | 2 +- .github/ISSUE_TEMPLATE/question.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 68299d5..9730e34 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -14,9 +14,9 @@ body: attributes: label: "Checklist" options: - - label: "I am able to reproduce the bug with the [latest version](https://github.com/xdev-software/template-placeholder/releases/latest)" + - label: "I am able to reproduce the bug with the [latest version](https://github.com/xdev-software/spring-data-eclipse-store-migration/releases/latest)" required: true - - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/template-placeholder/issues) or [closed](https://github.com/xdev-software/template-placeholder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." + - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/spring-data-eclipse-store-migration/issues) or [closed](https://github.com/xdev-software/spring-data-eclipse-store-migration/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." required: true - label: "I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise." required: true diff --git a/.github/ISSUE_TEMPLATE/enhancement.yml b/.github/ISSUE_TEMPLATE/enhancement.yml index 7523129..90f7cf9 100644 --- a/.github/ISSUE_TEMPLATE/enhancement.yml +++ b/.github/ISSUE_TEMPLATE/enhancement.yml @@ -12,7 +12,7 @@ body: attributes: label: "Checklist" options: - - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/template-placeholder/issues) or [closed](https://github.com/xdev-software/template-placeholder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." + - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/spring-data-eclipse-store-migration/issues) or [closed](https://github.com/xdev-software/spring-data-eclipse-store-migration/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." required: true - label: "I have taken the time to fill in all the required details. I understand that the feature request will be dismissed otherwise." required: true diff --git a/.github/ISSUE_TEMPLATE/question.yml b/.github/ISSUE_TEMPLATE/question.yml index 6ecd6ad..7a409b0 100644 --- a/.github/ISSUE_TEMPLATE/question.yml +++ b/.github/ISSUE_TEMPLATE/question.yml @@ -12,7 +12,7 @@ body: attributes: label: "Checklist" options: - - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/template-placeholder/issues) or [closed](https://github.com/xdev-software/template-placeholder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." + - label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/spring-data-eclipse-store-migration/issues) or [closed](https://github.com/xdev-software/spring-data-eclipse-store-migration/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to." required: true - label: "I have taken the time to fill in all the required details. I understand that the question will be dismissed otherwise." required: true From b7afcde975192e21512fdaede1cf04f72c8fcf54 Mon Sep 17 00:00:00 2001 From: AB Date: Wed, 12 Jun 2024 09:51:56 +0200 Subject: [PATCH 41/43] Fix checkstyle (in tests) --- .../AddAnnotationToOtherAnnotationTest.java | 310 +++++++++--------- .../AddSpringPropertyIfClassExistsTest.java | 214 ++++++------ 2 files changed, 252 insertions(+), 272 deletions(-) diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java index 9cbfba6..4ed5c1a 100644 --- a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java @@ -46,186 +46,174 @@ public void defaults(final RecipeSpec recipeSpec) @Test void testSimpleSingle() { - this.rewriteRun - ( - java - ( - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - - @SpringBootApplication - class A - { - public A() - { - } - } - """, - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; - - @EnableEclipseStoreRepositories - @SpringBootApplication - class A - { - public A() - { - } - } - """ - ) - ); + this.rewriteRun( + java( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication + class A + { + public A() + { + } + } + """, + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class A + { + public A() + { + } + } + """ + ) + ); } @Test void testSimpleMultiple() { - this.rewriteRun - ( - java - ( - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - - @SpringBootApplication - class A - { - public A() - { - } - } - """, - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; - - @EnableEclipseStoreRepositories - @SpringBootApplication - class A - { - public A() - { - } - } - """ - ), - java - ( - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - - @SpringBootApplication - class B - { - public B() - { - } - } - """, - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; - - @EnableEclipseStoreRepositories - @SpringBootApplication - class B - { - public B() - { - } - } - """ - ) - ); + this.rewriteRun( + java( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication + class A + { + public A() + { + } + } + """, + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class A + { + public A() + { + } + } + """ + ), + java( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication + class B + { + public B() + { + } + } + """, + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class B + { + public B() + { + } + } + """ + ) + ); } @Test void testAlreadyAdded() { - this.rewriteRun - ( - java - ( - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; - - @EnableEclipseStoreRepositories - @SpringBootApplication - class A - { - public A() - { - } - } - """ - ) - ); + this.rewriteRun( + java( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class A + { + public A() + { + } + } + """ + ) + ); } @Test void testSimpleNoAnnotation() { - this.rewriteRun - ( - java - ( - """ - class A - { - public A() - { - } - } - """ - ) - ); + this.rewriteRun( + java( + """ + class A + { + public A() + { + } + } + """ + ) + ); } @Test void testSimpleNoAnnotationAndAnnotation() { - this.rewriteRun - ( - java - ( - """ - class B - { - public B() - { - } - } - """ - ), - java - ( - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - - @SpringBootApplication - class A - { - public A() - { - } - } - """, - """ - import org.springframework.boot.autoconfigure.SpringBootApplication; - import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; - - @EnableEclipseStoreRepositories - @SpringBootApplication - class A - { - public A() - { - } - } - """ - ) - ); + this.rewriteRun( + java( + """ + class B + { + public B() + { + } + } + """ + ), + java( + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + + @SpringBootApplication + class A + { + public A() + { + } + } + """, + """ + import org.springframework.boot.autoconfigure.SpringBootApplication; + import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + @EnableEclipseStoreRepositories + @SpringBootApplication + class A + { + public A() + { + } + } + """ + ) + ); } } diff --git a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java index 58cbdb1..cf9b8f4 100644 --- a/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java @@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; +@SuppressWarnings("checkstyle:LineLength") class AddSpringPropertyIfClassExistsTest implements RewriteTest { @@ -47,103 +48,97 @@ public void defaults(final RecipeSpec recipeSpec) @Test void testSimpleProperties() { - this.rewriteRun - ( - properties( - "", - """ - spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """, - s -> s.path("application.properties") - ) - ); + this.rewriteRun( + properties( + "", + """ + spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("application.properties") + ) + ); } @Test void testSimpleYaml() { - this.rewriteRun - ( - yaml( - "", - """ - spring: - autoconfigure: - exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """, - s -> s.path("application.yml") - ) - ); + this.rewriteRun( + yaml( + "", + """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("application.yml") + ) + ); } @Test void testMultipleYamlAlsoInTestFolder() { - this.rewriteRun - ( - yaml( - "", - """ - spring: - autoconfigure: - exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """, - s -> s.path("/src/main/resources/application.yml") - ), - yaml( - "", - """ - spring: - autoconfigure: - exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """, - s -> s.path("/src/test/resources/application.yml") - ), - yaml( - "", - """ - spring: - autoconfigure: - exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """, - s -> s.path("application.yml") - ), - yaml( - "", - s -> s.path("no-application.yml") - ) - ); + this.rewriteRun( + yaml( + "", + """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("/src/main/resources/application.yml") + ), + yaml( + "", + """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("/src/test/resources/application.yml") + ), + yaml( + "", + """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("application.yml") + ), + yaml( + "", + s -> s.path("no-application.yml") + ) + ); } @Test void testWrongFileNameYaml() { - this.rewriteRun - ( - yaml( - "", - s -> s.path("random.yml") - ) - ); + this.rewriteRun( + yaml( + "", + s -> s.path("random.yml") + ) + ); } @Test void testWrongFileNameProperties() { - this.rewriteRun - ( - properties( - "", - s -> s.path("random.properties") - ) - ); + this.rewriteRun( + properties( + "", + s -> s.path("random.properties") + ) + ); } /** * It's not clear if this is a desired behavior, but since the Open Rewrite Recipe * {@link org.openrewrite.java.spring.AddSpringProperty} is doing this, and we are only using this recipe, this is - * how it - * works now. + * how it works now. *

* Might change in the future. *

@@ -151,56 +146,53 @@ void testWrongFileNameProperties() @Test void testMultipleProperties() { - this.rewriteRun - ( - properties( - "", - """ - spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """, - s -> s.path("application.properties") - ), - yaml( - "", - """ - spring: - autoconfigure: - exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """, - s -> s.path("application.yml") - ) - ); + this.rewriteRun( + properties( + "", + """ + spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("application.properties") + ), + yaml( + "", + """ + spring: + autoconfigure: + exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + """, + s -> s.path("application.yml") + ) + ); } @Test void testExisting() { - this.rewriteRun - ( - properties( + this.rewriteRun( + properties( + """ + spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration """ - spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - """ - ) - ); + ) + ); } @Test void testClassNotExisting() { - this.rewriteRun - ( - recipeSpec -> - recipeSpec.recipe(new AddSpringPropertyIfClassExists( - "not.existing.Class", - "spring.autoconfigure.exclude", - "DummyValue", - "", - null)), - properties( + this.rewriteRun( + recipeSpec -> + recipeSpec.recipe(new AddSpringPropertyIfClassExists( + "not.existing.Class", + "spring.autoconfigure.exclude", + "DummyValue", "", - s -> s.path("application.properties") - ) - ); + null)), + properties( + "", + s -> s.path("application.properties") + ) + ); } } From 464631a84c5cbcd2c6caa4f3974a9f4c5d80aa94 Mon Sep 17 00:00:00 2001 From: AB Date: Fri, 30 Aug 2024 09:05:14 +0200 Subject: [PATCH 42/43] Fill in template --- renovate.json5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/renovate.json5 b/renovate.json5 index 2874d45..e83d435 100644 --- a/renovate.json5 +++ b/renovate.json5 @@ -4,7 +4,7 @@ "packageRules": [ { "description": "Ignore project internal dependencies", - "packagePattern": "^software.xdev:template-placeholder", + "packagePattern": "^software.xdev:spring-data-eclipse-store-migration", "datasources": [ "maven" ], From b5a58a4c91a438b124352c4e04c86db8c1abe6b3 Mon Sep 17 00:00:00 2001 From: XDEV Renovate Bot Date: Fri, 30 Aug 2024 07:14:02 +0000 Subject: [PATCH 43/43] Update dependency org.apache.maven.plugins:maven-surefire-plugin to v3.5.0 --- spring-data-eclipse-store-migration/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-eclipse-store-migration/pom.xml b/spring-data-eclipse-store-migration/pom.xml index 8cfcc5a..46feca0 100644 --- a/spring-data-eclipse-store-migration/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -241,7 +241,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.5 + 3.5.0