Skip to content

Commit 03c1f49

Browse files
Merge pull request #7 from xdev-software/develop
v1.0.0
2 parents f0e390c + c78c521 commit 03c1f49

File tree

8 files changed

+394
-97
lines changed

8 files changed

+394
-97
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
## Usage
9999
Execute the following maven command in the maven project that you want to migrate:
100100
```
101-
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
101+
mvn org.openrewrite.maven:rewrite-maven-plugin:run \
102102
-Drewrite.recipeArtifactCoordinates=software.xdev:${{ env.PRIMARY_MAVEN_MODULE }}:${{ steps.version.outputs.release }} \
103103
-Drewrite.activeRecipes=software.xdev.spring.data.eclipse.store.JpaMigration
104104
```

.github/workflows/update-from-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
env:
1616
UPDATE_BRANCH: update-from-template
17-
REMOTE_URL: https://github.com/xdev-software/spring-data-eclipse-store-migration.git
17+
REMOTE_URL: https://github.com/xdev-software/standard-maven-template.git
1818
REMOTE_BRANCH: master
1919

2020
permissions:

spring-data-eclipse-store-migration/pom.xml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@
4747

4848
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4949
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
50-
<org.openrewrite.recipe.version>2.6.3</org.openrewrite.recipe.version>
50+
51+
<org.openrewrite.recipe.version>2.6.4</org.openrewrite.recipe.version>
5152
<org.springframework.boot.version>3.2.2</org.springframework.boot.version>
52-
<software.xdev.spring.data.eclipse.store.version>1.0.0</software.xdev.spring.data.eclipse.store.version>
53-
<junit.version>5.10.0</junit.version>
54-
<assertj.version>3.24.2</assertj.version>
55-
<slf4j.version>2.0.5</slf4j.version>
53+
<software.xdev.spring.data.eclipse.store.version>1.0.2</software.xdev.spring.data.eclipse.store.version>
54+
<lombok.version>1.18.30</lombok.version>
5655
</properties>
5756

5857
<repositories>
@@ -115,9 +114,16 @@
115114
<artifactId>rewrite-java</artifactId>
116115
</dependency>
117116
<dependency>
118-
<groupId>org.openrewrite</groupId>
119-
<artifactId>rewrite-maven</artifactId>
117+
<groupId>org.openrewrite.recipe</groupId>
118+
<artifactId>rewrite-spring</artifactId>
120119
</dependency>
120+
<dependency>
121+
<groupId>org.projectlombok</groupId>
122+
<artifactId>lombok</artifactId>
123+
<version>${lombok.version}</version>
124+
<scope>provided</scope>
125+
</dependency>
126+
121127

122128
<dependency>
123129
<groupId>org.springframework.boot</groupId>
@@ -130,7 +136,6 @@
130136
<version>${software.xdev.spring.data.eclipse.store.version}</version>
131137
<scope>runtime</scope>
132138
</dependency>
133-
134139
<dependency>
135140
<groupId>org.openrewrite</groupId>
136141
<artifactId>rewrite-java-17</artifactId>
@@ -144,10 +149,8 @@
144149
<dependency>
145150
<groupId>org.slf4j</groupId>
146151
<artifactId>slf4j-simple</artifactId>
147-
<version>2.0.11</version>
148152
<scope>test</scope>
149153
</dependency>
150-
151154
</dependencies>
152155

153156
<build>
@@ -187,9 +190,6 @@
187190
<version>3.12.1</version>
188191
<configuration>
189192
<release>${maven.compiler.release}</release>
190-
<compilerArgs>
191-
<arg>-proc:none</arg>
192-
</compilerArgs>
193193
</configuration>
194194
</plugin>
195195
<plugin>
@@ -224,6 +224,11 @@
224224
</execution>
225225
</executions>
226226
</plugin>
227+
<plugin>
228+
<groupId>org.apache.maven.plugins</groupId>
229+
<artifactId>maven-surefire-plugin</artifactId>
230+
<version>3.2.5</version>
231+
</plugin>
227232
</plugins>
228233
</build>
229234
<profiles>

spring-data-eclipse-store-migration/src/main/java/software/xdev/spring/data/eclipse/store/AddAnnotationToOtherAnnotation.java

Lines changed: 11 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package software.xdev.spring.data.eclipse.store;
1717

1818
import java.util.Comparator;
19-
import java.util.Objects;
2019

2120
import org.jetbrains.annotations.NotNull;
2221
import org.openrewrite.ExecutionContext;
@@ -29,7 +28,18 @@
2928
import org.openrewrite.java.JavaTemplate;
3029
import org.openrewrite.java.tree.J;
3130

31+
import lombok.AllArgsConstructor;
32+
import lombok.EqualsAndHashCode;
33+
import lombok.Getter;
34+
import lombok.NoArgsConstructor;
35+
import lombok.Setter;
3236

37+
38+
@Getter
39+
@Setter
40+
@AllArgsConstructor
41+
@NoArgsConstructor
42+
@EqualsAndHashCode(callSuper = true)
3343
public class AddAnnotationToOtherAnnotation extends Recipe
3444
{
3545
@Option(displayName = "Existing annotation type",
@@ -54,22 +64,6 @@ public class AddAnnotationToOtherAnnotation extends Recipe
5464
example = "Test")
5565
String annotationTypeToAddSimpleName;
5666

57-
public AddAnnotationToOtherAnnotation(
58-
final String existingAnnotationType,
59-
final String annotationTypeToAdd,
60-
final String classPath,
61-
final String annotationTypeToAddSimpleName)
62-
{
63-
this.existingAnnotationType = existingAnnotationType;
64-
this.annotationTypeToAdd = annotationTypeToAdd;
65-
this.classPath = classPath;
66-
this.annotationTypeToAddSimpleName = annotationTypeToAddSimpleName;
67-
}
68-
69-
public AddAnnotationToOtherAnnotation()
70-
{
71-
}
72-
7367
@Override
7468
public @NotNull String getDisplayName()
7569
{
@@ -127,58 +121,4 @@ public AddAnnotationToOtherAnnotation()
127121
}
128122
};
129123
}
130-
131-
public String getExistingAnnotationType()
132-
{
133-
return this.existingAnnotationType;
134-
}
135-
136-
public String getAnnotationTypeToAdd()
137-
{
138-
return this.annotationTypeToAdd;
139-
}
140-
141-
public String getClassPath()
142-
{
143-
return this.classPath;
144-
}
145-
146-
public String getAnnotationTypeToAddSimpleName()
147-
{
148-
return this.annotationTypeToAddSimpleName;
149-
}
150-
151-
@Override
152-
public boolean equals(final Object o)
153-
{
154-
if(this == o)
155-
{
156-
return true;
157-
}
158-
if(o == null || this.getClass() != o.getClass())
159-
{
160-
return false;
161-
}
162-
if(!super.equals(o))
163-
{
164-
return false;
165-
}
166-
final AddAnnotationToOtherAnnotation that = (AddAnnotationToOtherAnnotation)o;
167-
return Objects.equals(this.existingAnnotationType, that.existingAnnotationType) && Objects.equals(
168-
this.annotationTypeToAdd,
169-
that.annotationTypeToAdd) && Objects.equals(this.classPath, that.classPath) && Objects.equals(
170-
this.annotationTypeToAddSimpleName,
171-
that.annotationTypeToAddSimpleName);
172-
}
173-
174-
@Override
175-
public int hashCode()
176-
{
177-
return Objects.hash(
178-
super.hashCode(),
179-
this.existingAnnotationType,
180-
this.annotationTypeToAdd,
181-
this.classPath,
182-
this.annotationTypeToAddSimpleName);
183-
}
184124
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright © 2023 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store;
17+
18+
import java.util.List;
19+
20+
import org.jetbrains.annotations.NotNull;
21+
import org.openrewrite.ExecutionContext;
22+
import org.openrewrite.Option;
23+
import org.openrewrite.Recipe;
24+
import org.openrewrite.TreeVisitor;
25+
import org.openrewrite.internal.lang.Nullable;
26+
import org.openrewrite.java.spring.AddSpringProperty;
27+
28+
import lombok.AllArgsConstructor;
29+
import lombok.EqualsAndHashCode;
30+
import lombok.Getter;
31+
import lombok.NoArgsConstructor;
32+
import lombok.Setter;
33+
34+
35+
@Getter
36+
@Setter
37+
@AllArgsConstructor
38+
@NoArgsConstructor
39+
@EqualsAndHashCode(callSuper = true)
40+
public class AddSpringPropertyIfClassExists extends Recipe
41+
{
42+
@Option(displayName = "Class that must exist in the classpath to add the property",
43+
description = "Name of the class that must exist in the classpath to execute the "
44+
+ "recipe to add a property in the properties file.",
45+
example = "software.xdev")
46+
private String className;
47+
48+
@Option(
49+
displayName = "Property key",
50+
description = "The property key to add.",
51+
example = "management.metrics.enable.process.files"
52+
)
53+
private String property;
54+
@Option(
55+
displayName = "Property value",
56+
description = "The value of the new property key.",
57+
example = "true"
58+
)
59+
private String value;
60+
@Option(
61+
displayName = "Optional comment to be prepended to the property",
62+
description = "A comment that will be added to the new property.",
63+
required = false,
64+
example = "This is a comment"
65+
)
66+
private @Nullable String comment;
67+
@Option(
68+
displayName = "Optional list of file path matcher",
69+
description = "Each value in this list represents a glob expression that is used to match which files will be "
70+
+ "modified. If this value is not present, this recipe will query the execution context for reasonable "
71+
+ "defaults. (\"**/application.yml\", \"**/application.yml\", and \"**/application.properties\".",
72+
required = false,
73+
example = "[\"**/application.yml\"]"
74+
)
75+
private @Nullable List<String> pathExpressions;
76+
77+
@Override
78+
public @NotNull String getDisplayName()
79+
{
80+
return "AddSpringPropertyIfClassExists";
81+
}
82+
83+
@Override
84+
public @NotNull String getDescription()
85+
{
86+
return "Add a spring property to the properties file if a specific class exists.";
87+
}
88+
89+
@Override
90+
public @NotNull TreeVisitor<?, ExecutionContext> getVisitor()
91+
{
92+
if(!this.doesClasspathContainClass(this.className))
93+
{
94+
return TreeVisitor.noop();
95+
}
96+
return new AddSpringProperty(
97+
this.property, this.value, this.comment, this.pathExpressions
98+
).getVisitor();
99+
}
100+
101+
private boolean doesClasspathContainClass(final String classToCheck)
102+
{
103+
try
104+
{
105+
Class.forName(classToCheck, false, this.getClass().getClassLoader());
106+
return true;
107+
}
108+
catch(final ClassNotFoundException e)
109+
{
110+
return false;
111+
}
112+
}
113+
}

spring-data-eclipse-store-migration/src/main/resources/META-INF/rewrite/rewrite.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ recipeList:
1616
classPath: 'spring-data-eclipse-store'
1717
annotationTypeToAddSimpleName: 'EnableEclipseStoreRepositories'
1818

19+
- software.xdev.spring.data.eclipse.store.AddSpringPropertyIfClassExists:
20+
className: 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration'
21+
property: 'spring.autoconfigure.exclude'
22+
value: 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration'
23+
comment: 'This suppresses the use of JPA in the project. It is needed to let EclipseStore coexist with JPA.'
24+
1925
- org.openrewrite.maven.AddDependency:
2026
groupId: software.xdev
2127
artifactId: spring-data-eclipse-store
22-
version: 1.0.0
28+
version: 1.0.2
2329
acceptTransitive: true
2430

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

36-
- org.openrewrite.maven.RemoveDependency:
37-
groupId: org.springframework.boot
38-
artifactId: spring-boot-starter-data-jpa
39-
4042
- org.openrewrite.java.RemoveAnnotation:
4143
# https://docs.openrewrite.org/reference/method-patterns
4244
annotationPattern: '@org.springframework.data.jpa.repository.Query *(..)'
45+
46+
- org.openrewrite.java.RemoveAnnotation:
47+
annotationPattern: '@org.springframework.data.jpa.repository.config.EnableJpaRepositories *(..)'
48+
49+
# Change all the spring framework repositories to specifically use EclipseStore repositories.
50+
51+
- org.openrewrite.java.ChangeType:
52+
oldFullyQualifiedTypeName: org.springframework.data.repository.Repository
53+
newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCustomRepository
54+
55+
- org.openrewrite.java.ChangeType:
56+
oldFullyQualifiedTypeName: org.springframework.data.repository.CrudRepository
57+
newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreCrudRepository
58+
59+
- org.openrewrite.java.ChangeType:
60+
oldFullyQualifiedTypeName: org.springframework.data.repository.ListCrudRepository
61+
newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListCrudRepository
62+
63+
- org.openrewrite.java.ChangeType:
64+
oldFullyQualifiedTypeName: org.springframework.data.repository.PagingAndSortingRepositoryRepository
65+
newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStorePagingAndSortingRepositoryRepository
66+
67+
- org.openrewrite.java.ChangeType:
68+
oldFullyQualifiedTypeName: org.springframework.data.repository.ListPagingAndSortingRepositoryRepository
69+
newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreListPagingAndSortingRepositoryRepository
70+
71+
# Change all the JPA repositories to specifically use EclipseStore repositories.
72+
73+
- org.openrewrite.java.ChangeType:
74+
oldFullyQualifiedTypeName: org.springframework.data.jpa.repository.JpaRepository
75+
newFullyQualifiedTypeName: software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository

0 commit comments

Comments
 (0)