Skip to content

Commit 7f3f6ff

Browse files
authored
feat: Add project parser for OpenRewrite (#832)
* Reimplementation of OpenRewrite AST parser for Maven Two implementations currently exist: - RewriteMavenProjectParser - RewriteProjectParser RewriteMavenProjectParser creates Maven Plexus container to retrieve the Maven instance. A Maven instance is used to call `clean` and `package` while registering a listener to the lifecycle event when the goals are finished. The MavenSession provided to the listener allows executing the same OR classes as used when running in the rewrite-maven plugin. The created AST should be exactly the same as with the Maven plugin. RewriteProjectParser replicates the RewriteMavenProjectParser while split into smaller components. The RewriteMavenProjectParser is used to create the target AST which should be identically when parsing the same project with RewriteProjectParser. The RewriteProjectParser is meant to replace the RewriteMavenProjectParser.
1 parent dc85c20 commit 7f3f6ff

File tree

72 files changed

+6421
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+6421
-7
lines changed

components/sbm-core/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
<version>0.14.1-SNAPSHOT</version>
3434
</dependency>
3535

36+
<dependency>
37+
<groupId>org.springframework.sbm</groupId>
38+
<artifactId>sbm-utils</artifactId>
39+
<version>0.14.1-SNAPSHOT</version>
40+
</dependency>
41+
3642
<dependency>
3743
<groupId>org.springframework.boot</groupId>
3844
<artifactId>spring-boot-starter-freemarker</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

components/sbm-support-boot/pom.xml

-7
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@
7777
<groupId>org.springframework.sbm</groupId>
7878
<artifactId>recipe-test-support</artifactId>
7979
</dependency>
80-
<dependency>
81-
<groupId>org.springframework.sbm</groupId>
82-
<artifactId>sbm-core</artifactId>
83-
<classifier>tests</classifier>
84-
<version>0.14.1-SNAPSHOT</version>
85-
<scope>test</scope>
86-
</dependency>
8780
<dependency>
8881
<groupId>com.tngtech.archunit</groupId>
8982
<artifactId>archunit-junit5</artifactId>

components/sbm-utils/.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

components/sbm-utils/pom.xml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.springframework.sbm</groupId>
8+
<artifactId>spring-boot-migrator</artifactId>
9+
<version>0.14.1-SNAPSHOT</version>
10+
<relativePath>../../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>sbm-utils</artifactId>
14+
15+
<properties>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework</groupId>
24+
<artifactId>spring-core</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-test</artifactId>
29+
</dependency>
30+
</dependencies>
31+
32+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
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+
* https://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 org.springframework.sbm.utils;
17+
18+
import org.springframework.core.io.Resource;
19+
20+
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
import java.util.List;
25+
26+
public class ResourceUtil {
27+
public ResourceUtil() {
28+
}
29+
30+
public static Path getPath(Resource resource) {
31+
try {
32+
return resource.getFile().toPath();
33+
} catch (IOException var2) {
34+
throw new RuntimeException(var2);
35+
}
36+
}
37+
38+
public static InputStream getInputStream(Resource resource) {
39+
try {
40+
return resource.getInputStream();
41+
} catch (IOException var2) {
42+
throw new RuntimeException(var2);
43+
}
44+
}
45+
46+
public static void write(Path basePath, List<Resource> resources) {
47+
resources.stream()
48+
.forEach(r -> ResourceUtil.persistResource(basePath, r));
49+
}
50+
51+
private static void persistResource(Path basePath, Resource r) {
52+
Path resourcePath = ResourceUtil.getPath(r);
53+
if(resourcePath.isAbsolute()) {
54+
Path relativize = resourcePath.relativize(basePath);
55+
} else {
56+
resourcePath = basePath.resolve(resourcePath).toAbsolutePath().normalize();
57+
}
58+
if(resourcePath.toFile().exists()) {
59+
return;
60+
}
61+
try {
62+
if(!resourcePath.getParent().toFile().exists()) {
63+
Files.createDirectories(resourcePath.getParent());
64+
}
65+
Files.writeString(resourcePath, ResourceUtil.getContent(r));
66+
} catch (IOException e) {
67+
throw new RuntimeException(e);
68+
}
69+
}
70+
71+
public static String getContent(Resource r) {
72+
try {
73+
return new String(getInputStream(r).readAllBytes());
74+
} catch (IOException e) {
75+
throw new RuntimeException(e);
76+
}
77+
}
78+
}

pom.xml

+11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@
8888
<artifactId>lombok</artifactId>
8989
<version>${lombok.version}</version>
9090
</dependency>
91+
<dependency>
92+
<groupId>org.apache.maven.wagon</groupId>
93+
<artifactId>wagon-http</artifactId>
94+
<version>3.5.3</version>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.apache.maven.resolver</groupId>
98+
<artifactId>maven-resolver-transport-wagon</artifactId>
99+
<version>${resolverVersion}</version>
100+
</dependency>
91101
<dependency>
92102
<groupId>org.springframework.sbm</groupId>
93103
<artifactId>test-helper</artifactId>
@@ -336,6 +346,7 @@
336346
<module>components/sbm-core</module>
337347
<module>components/test-helper</module>
338348
<module>components/recipe-test-support</module>
349+
<module>components/sbm-utils</module>
339350
</modules>
340351
<build>
341352
<finalName>${jar.name}</finalName>

0 commit comments

Comments
 (0)