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 diff --git a/.github/workflows/check-build.yml b/.github/workflows/check-build.yml index 2ac6530..a94ffef 100644 --- a/.github/workflows/check-build.yml +++ b/.github/workflows/check-build.yml @@ -19,10 +19,6 @@ on: - '.idea/**' - 'assets/**' -env: - PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }} - DEMO_MAVEN_MODULE: ${{ github.event.repository.name }}-demo - jobs: build: runs-on: ubuntu-latest @@ -63,13 +59,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 - checkstyle: runs-on: ubuntu-latest if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0bf3805..ff161dc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -96,14 +96,12 @@ jobs: ## [Changelog](https://github.com/${{ github.repository }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) See [Changelog#v${{ steps.version.outputs.release }}](https://github.com/${{ github.repository }}/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 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-maven: diff --git a/.run/Run Demo.run.xml b/.run/Run Demo.run.xml deleted file mode 100644 index 5fb2bc2..0000000 --- a/.run/Run Demo.run.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - \ No newline at end of file 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/CONTRIBUTING.md b/CONTRIBUTING.md index be2a186..c15d98c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,10 +34,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/template-placeholder/release.yml?branch=master)](https://github.com/xdev-software/template-placeholder/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/template-placeholder/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 eccf80b..b034cdf 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,28 @@ -[![Latest version](https://img.shields.io/maven-central/v/software.xdev/template-placeholder?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/template-placeholder) -[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/template-placeholder/check-build.yml?branch=develop)](https://github.com/xdev-software/template-placeholder/actions/workflows/check-build.yml?query=branch%3Adevelop) -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_template-placeholder&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_template-placeholder) +[![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/check-build.yml?branch=develop)](https://github.com/xdev-software/spring-data-eclipse-store-migration/actions/workflows/check-build.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) -# template-placeholder +# 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. -## Installation -[Installation guide for the latest release](https://github.com/xdev-software/template-placeholder/releases/latest#Installation) +## 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, +> 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. ## Dependencies and Licenses -View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/template-placeholder/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 34b9514..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/template-placeholder/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 ce23a37..5600893 100644 --- a/pom.xml +++ b/pom.xml @@ -5,8 +5,8 @@ 4.0.0 software.xdev - template-placeholder-root - 1.0.0-SNAPSHOT + spring-data-eclipse-store-migration-root + 1.0.1-SNAPSHOT pom @@ -15,8 +15,7 @@ - template-placeholder - template-placeholder-demo + spring-data-eclipse-store-migration 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" ], diff --git a/template-placeholder/pom.xml b/spring-data-eclipse-store-migration/pom.xml similarity index 73% rename from template-placeholder/pom.xml rename to spring-data-eclipse-store-migration/pom.xml index b7475cf..b417f47 100644 --- a/template-placeholder/pom.xml +++ b/spring-data-eclipse-store-migration/pom.xml @@ -1,21 +1,21 @@ + 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 - template-placeholder - 1.0.0-SNAPSHOT + spring-data-eclipse-store-migration + 1.0.1-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 @@ -47,6 +47,11 @@ UTF-8 UTF-8 + + 2.9.0 + 3.2.2 + 1.0.2 + 1.18.32 @@ -61,6 +66,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 +108,51 @@ + + + org.openrewrite + rewrite-java + + + org.openrewrite.recipe + rewrite-spring + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + + org.springframework.boot + spring-boot-autoconfigure + runtime + + + software.xdev + spring-data-eclipse-store + ${software.xdev.spring.data.eclipse.store.version} + runtime + + + org.openrewrite + rewrite-java-17 + test + + + org.openrewrite + rewrite-test + test + + + org.slf4j + slf4j-simple + test + + + @@ -135,9 +204,6 @@ 3.13.0 ${maven.compiler.release} - - -proc:none - @@ -172,6 +238,11 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.0 + @@ -218,7 +289,7 @@ - + org.sonatype.plugins nexus-staging-maven-plugin 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 new file mode 100644 index 0000000..2fd1c86 --- /dev/null +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java @@ -0,0 +1,124 @@ +/* + * 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; + +import org.jetbrains.annotations.NotNull; +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; + +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", + 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", + required = false) + 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; + + @Override + public @NotNull String getDisplayName() + { + return "AddAnnotationToOtherAnnotation"; + } + + @Override + public @NotNull String getDescription() + { + return "Add the a new annotation to an existing annotation."; + } + + @Override + public @NotNull TreeVisitor getVisitor() + { + final AnnotationMatcher existingAnnotationMatcher = new AnnotationMatcher(this.existingAnnotationType); + final AnnotationMatcher newAnnotationMatcher = new AnnotationMatcher(this.annotationTypeToAdd); + return new JavaIsoVisitor<>() + { + @Override + public J.@NotNull ClassDeclaration visitClassDeclaration( + final J.@NotNull ClassDeclaration classDecl, + final @NotNull ExecutionContext executionContext) + { + final J.ClassDeclaration cd = super.visitClassDeclaration(classDecl, executionContext); + + if( + cd.getLeadingAnnotations() + .stream() + .filter(existingAnnotationMatcher::matches) + .findAny() + .isEmpty() || cd.getLeadingAnnotations() + .stream() + .anyMatch(newAnnotationMatcher::matches) + ) + { + 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/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 new file mode 100644 index 0000000..57f5fb0 --- /dev/null +++ b/spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExists.java @@ -0,0 +1,113 @@ +/* + * 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.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.java.spring.AddSpringProperty; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +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.", + 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.", + example = "true" + ) + 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 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 = "[\"**/application.yml\"]" + ) + private @Nullable List pathExpressions; + + @Override + public @NotNull String getDisplayName() + { + return "AddSpringPropertyIfClassExists"; + } + + @Override + public @NotNull String getDescription() + { + return "Add a spring property to the properties file if a specific class exists."; + } + + @Override + public @NotNull TreeVisitor getVisitor() + { + if(!this.doesClasspathContainClass(this.className)) + { + return TreeVisitor.noop(); + } + return new AddSpringProperty( + this.property, this.value, this.comment, this.pathExpressions + ).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 new file mode 100644 index 0000000..5cbf598 --- /dev/null +++ b/spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml @@ -0,0 +1,75 @@ +--- +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: + + - 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' + + - 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.' + + - org.openrewrite.maven.AddDependency: + groupId: software.xdev + artifactId: spring-data-eclipse-store + version: 1.0.2 + 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 + + - 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.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/AddAnnotationToOtherAnnotationTest.java b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java new file mode 100644 index 0000000..4ed5c1a --- /dev/null +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotationTest.java @@ -0,0 +1,219 @@ +/* + * 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 software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories; + + +class AddAnnotationToOtherAnnotationTest 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 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() + { + } + } + """ + ) + ); + } + + @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() + { + } + } + """ + ) + ); + } +} 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 new file mode 100644 index 0000000..cf9b8f4 --- /dev/null +++ b/spring-data-eclipse-store-migration/src/test/java/software/xdev/spring/data/eclipse/store/AddSpringPropertyIfClassExistsTest.java @@ -0,0 +1,198 @@ +/* + * 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 static org.openrewrite.yaml.Assertions.yaml; + +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; + + +@SuppressWarnings("checkstyle:LineLength") +class AddSpringPropertyIfClassExistsTest implements RewriteTest +{ + + @Override + public void defaults(final RecipeSpec recipeSpec) + { + recipeSpec + .recipe(new AddSpringPropertyIfClassExists( + HibernateJpaAutoConfiguration.class.getName(), + "spring.autoconfigure.exclude", + DataSourceAutoConfiguration.class.getName() + + "," + + DataSourceTransactionManagerAutoConfiguration.class.getName() + + "," + + HibernateJpaAutoConfiguration.class.getName(), + "", null)); + } + + @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") + ) + ); + } + + @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 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() + { + 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.java.spring.AddSpringProperty} 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 + """, + 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( + """ + 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( + "", + s -> s.path("application.properties") + ) + ); + } +} diff --git a/template-placeholder-demo/pom.xml b/template-placeholder-demo/pom.xml deleted file mode 100644 index 1af633c..0000000 --- a/template-placeholder-demo/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - 4.0.0 - - - software.xdev - template-placeholder-root - 1.0.0-SNAPSHOT - - - template-placeholder-demo - 1.0.0-SNAPSHOT - jar - - - XDEV Software - https://xdev.software - - - - 17 - ${javaVersion} - - UTF-8 - UTF-8 - - software.xdev.Application - - - - - software.xdev - template-placeholder - ${project.version} - - - - - ${project.artifactId} - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.13.0 - - ${maven.compiler.release} - - -proc:none - - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.7.1 - - - - ${mainClass} - - - true - - - - jar-with-dependencies - - false - - - - make-assembly - package - - single - - - - - - -