Skip to content

Commit

Permalink
Merge pull request #7 from xdev-software/develop
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
JohannesRabauer authored Feb 13, 2024
2 parents f0e390c + c78c521 commit 03c1f49
Show file tree
Hide file tree
Showing 8 changed files with 394 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-from-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 18 additions & 13 deletions spring-data-eclipse-store-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<org.openrewrite.recipe.version>2.6.3</org.openrewrite.recipe.version>

<org.openrewrite.recipe.version>2.6.4</org.openrewrite.recipe.version>
<org.springframework.boot.version>3.2.2</org.springframework.boot.version>
<software.xdev.spring.data.eclipse.store.version>1.0.0</software.xdev.spring.data.eclipse.store.version>
<junit.version>5.10.0</junit.version>
<assertj.version>3.24.2</assertj.version>
<slf4j.version>2.0.5</slf4j.version>
<software.xdev.spring.data.eclipse.store.version>1.0.2</software.xdev.spring.data.eclipse.store.version>
<lombok.version>1.18.30</lombok.version>
</properties>

<repositories>
Expand Down Expand Up @@ -115,9 +114,16 @@
<artifactId>rewrite-java</artifactId>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-maven</artifactId>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -130,7 +136,6 @@
<version>${software.xdev.spring.data.eclipse.store.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java-17</artifactId>
Expand All @@ -144,10 +149,8 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.11</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -187,9 +190,6 @@
<version>3.12.1</version>
<configuration>
<release>${maven.compiler.release}</release>
<compilerArgs>
<arg>-proc:none</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -224,6 +224,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand All @@ -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()
{
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<String> 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<?, ExecutionContext> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ recipeList:
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.0
version: 1.0.2
acceptTransitive: true

- org.openrewrite.maven.AddPlugin:
Expand All @@ -33,10 +39,37 @@ recipeList:
artifactId: spring-boot-maven-plugin
configuration: <jvmArguments>--add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED</jvmArguments>

- 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.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
Loading

0 comments on commit 03c1f49

Please sign in to comment.