Skip to content

Commit 0b66e95

Browse files
authored
875 new parser fails due to checkstyle (#891)
* Trying to reproduce #875 * Correct path when parsing resources, fixes #875 * Disable broken steps * Trigger build again
1 parent 5c45c01 commit 0b66e95

File tree

9 files changed

+123
-34
lines changed

9 files changed

+123
-34
lines changed

.github/workflows/build-sbm-support-rewrite.yml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,30 @@ jobs:
2626
- name: Maven Build
2727
run: mvn --batch-mode clean package
2828

29-
- name: Setup JFrog CLI
30-
uses: jfrog/setup-jfrog-cli@v3
31-
with:
32-
version: 2.46.2
33-
env:
34-
JF_ARTIFACTORY_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }}
35-
MAVEN_REPO_ID: repo.spring.io
36-
MAVEN_REPO_URL: https://repo.spring.io/libs-snapshot-local
37-
# This command adds a new server configuration to the JFrog CLI
38-
- run: |
39-
export SERVER_ID="repo.spring.io"
40-
jf c add $SERVER_ID --url=https://repo.spring.io/libs-snapshot-local --access-token=${{ secrets.JF_ARTIFACTORY_SPRING }} --interactive=false
41-
42-
- name: Deploy to Artifactory
43-
run: |
44-
jfrog mvnc \
45-
--server-id-deploy $SERVER_ID \
46-
--repo-deploy-releases release \
47-
--repo-deploy-snapshots snapshot
48-
echo JFROG_CLI_BUILD_NAME=sbm-support-rewrite >> $GITHUB_ENV
49-
echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV
50-
- name: Build and Publish
51-
env:
52-
DISABLE_SAMPLES: true
53-
run: |
54-
jfrog mvn clean install --repo=repo.spring.io
55-
jfrog build-publish
29+
# - name: Setup JFrog CLI
30+
# uses: jfrog/setup-jfrog-cli@v3
31+
# with:
32+
# version: 2.46.2
33+
# env:
34+
# JF_ARTIFACTORY_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }}
35+
# MAVEN_REPO_ID: repo.spring.io
36+
# MAVEN_REPO_URL: https://repo.spring.io/libs-snapshot-local
37+
# # This command adds a new server configuration to the JFrog CLI
38+
# - run: |
39+
# export SERVER_ID="repo.spring.io"
40+
# jf c add $SERVER_ID --url=https://repo.spring.io/libs-snapshot-local --access-token=${{ secrets.JF_ARTIFACTORY_SPRING }} --interactive=false
41+
#
42+
# - name: Deploy to Artifactory
43+
# run: |
44+
# jfrog mvnc \
45+
# --server-id-deploy $SERVER_ID \
46+
# --repo-deploy-releases release \
47+
# --repo-deploy-snapshots snapshot
48+
# echo JFROG_CLI_BUILD_NAME=sbm-support-rewrite >> $GITHUB_ENV
49+
# echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV
50+
# - name: Build and Publish
51+
# env:
52+
# DISABLE_SAMPLES: true
53+
# run: |
54+
# jfrog mvn clean install --repo=repo.spring.io
55+
# jfrog build-publish

sbm-support-rewrite/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,4 @@ limitations under the License.
468468
</distributionManagement>
469469
</profile>
470470
</profiles>
471-
</project>
471+
</project>

sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/SourceFileParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,14 @@ private List<SourceFile> parseModuleSourceFiles(List<Resource> resources, MavenP
106106
List<SourceFile> testSources = parseTestSources(baseDir, mavenProject, moduleBuildFile, javaParserBuilder.clone(), rp, provenanceMarkers, alreadyParsed, executionContext);
107107

108108
// 171:175
109-
Stream<SourceFile> parsedResourceFiles = rp.parse(baseDir.resolve(moduleBuildFile.getSourcePath()).resolve("src/main/resources"), alreadyParsed )
109+
Stream<SourceFile> parsedResourceFiles = rp.parse(baseDir.resolve(moduleBuildFile.getSourcePath()).getParent(), alreadyParsed )
110110
// FIXME: handle generated sources
111111
.map(mavenMojoProjectParserPrivateMethods.addProvenance(baseDir, provenanceMarkers, null));
112112

113113
// 157:169
114114
List<SourceFile> resourceSourceFiles = mergeAndFilterExcluded(baseDir, parserSettings.getExclusions(), mainSources, testSources);
115-
sourceFiles.addAll(parsedResourceFiles.toList());
115+
List<SourceFile> resourceFilesList = parsedResourceFiles.toList();
116+
sourceFiles.addAll(resourceFilesList);
116117
sourceFiles.addAll(resourceSourceFiles);
117118

118119
return sourceFiles;

sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParserTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.junit.jupiter.api.DisplayName;
2121
import org.junit.jupiter.api.Test;
2222
import org.junit.jupiter.api.io.TempDir;
23+
import org.junitpioneer.jupiter.Issue;
2324
import org.openrewrite.ExecutionContext;
2425
import org.openrewrite.InMemoryExecutionContext;
2526
import org.openrewrite.Parser;
@@ -233,7 +234,7 @@ void shouldParseMavenConfigProject() {
233234
@DisplayName("Parse multi-module-1")
234235
void parseMultiModule1_withIntegratedParser() {
235236
ExecutionContext ctx = new InMemoryExecutionContext(t -> t.printStackTrace());
236-
Path baseDir = getProject("multi-module-1");
237+
Path baseDir = getMavenProject("multi-module-1");
237238
parserSettings.setExclusions(Set.of("README.adoc"));
238239
RewriteProjectParsingResult parsingResult = sut.parse(
239240
baseDir,
@@ -244,7 +245,7 @@ void parseMultiModule1_withIntegratedParser() {
244245

245246
@Test
246247
void parseMultiModule1_WithCustomParser() {
247-
Path baseDir = getProject("multi-module-1");
248+
Path baseDir = getMavenProject("multi-module-1");
248249
ExecutionContext ctx;
249250
ctx = new InMemoryExecutionContext(t -> t.printStackTrace());
250251
MavenModelReader mavenModelReader = new MavenModelReader();
@@ -300,6 +301,16 @@ void parseComplexMavenReactorProject() {
300301
.forEach(System.out::println);
301302
}
302303

304+
@Test
305+
@DisplayName("parseCheckstyle")
306+
@Issue("https://github.com/spring-projects-experimental/spring-boot-migrator/issues/875")
307+
void parseCheckstyle() {
308+
Path baseDir = getMavenProject("checkstyle");
309+
RewriteProjectParsingResult parsingResult = sut.parse(baseDir);
310+
assertThat(parsingResult.sourceFiles().stream().map(sf -> sf.getSourcePath().toString()).toList()).contains("checkstyle/rules.xml");
311+
assertThat(parsingResult.sourceFiles().stream().map(sf -> sf.getSourcePath().toString()).toList()).contains("checkstyle/suppressions.xml");
312+
}
313+
303314
private static void verifyExecutionContext(RewriteProjectParsingResult parsingResult) {
304315
ExecutionContext resultingExecutionContext = parsingResult.executionContext();
305316
assertThat(resultingExecutionContext).isNotNull();
@@ -459,7 +470,7 @@ private <T extends SourceFile> void verify(SourceFile sourceFile, Class<T> clazz
459470
}
460471
}
461472

462-
private Path getProject(String s) {
473+
private Path getMavenProject(String s) {
463474
return Path.of("./testcode/maven-projects/").resolve(s).toAbsolutePath().normalize();
464475
}
465476

sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserIntegrationTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.junit.jupiter.api.DisplayName;
1919
import org.junit.jupiter.api.Test;
20+
import org.junitpioneer.jupiter.Issue;
2021
import org.openrewrite.ExecutionContext;
2122
import org.openrewrite.InMemoryExecutionContext;
2223
import org.springframework.beans.factory.annotation.Autowired;
@@ -97,4 +98,20 @@ public void onFinishedParsingProjectEvent(FinishedParsingProjectEvent event) {
9798
}
9899
}
99100

101+
@Test
102+
@DisplayName("parseCheckstyle")
103+
@Issue("https://github.com/spring-projects-experimental/spring-boot-migrator/issues/875")
104+
void parseCheckstyle() {
105+
Path baseDir = getMavenProject("checkstyle");
106+
List<Resource> resources = projectScanner.scan(baseDir, Set.of());
107+
RewriteProjectParsingResult parsingResult = sut.parse(baseDir, resources, new InMemoryExecutionContext(t -> {throw new RuntimeException(t);}));
108+
assertThat(parsingResult.sourceFiles().stream().map(sf -> sf.getSourcePath().toString()).toList()).contains("checkstyle/rules.xml");
109+
assertThat(parsingResult.sourceFiles().stream().map(sf -> sf.getSourcePath().toString()).toList()).contains("checkstyle/suppressions.xml");
110+
}
111+
112+
private Path getMavenProject(String s) {
113+
return Path.of("./testcode/maven-projects/").resolve(s).toAbsolutePath().normalize();
114+
}
115+
116+
100117
}

sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.junit.jupiter.api.DisplayName;
2020
import org.junit.jupiter.api.Test;
2121
import org.junit.jupiter.api.io.TempDir;
22+
import org.junitpioneer.jupiter.Issue;
2223
import org.openrewrite.ExecutionContext;
2324
import org.openrewrite.InMemoryExecutionContext;
2425
import org.openrewrite.Parser;
@@ -124,5 +125,4 @@ void parseComplexMavenReactorProject2(@TempDir Path tempDir) {
124125
RewriteProjectParsingResult parsingResult = projectParser.parse(basePath, resources, executionContext);
125126
assertThat(parsingResult.sourceFiles()).hasSize(2);
126127
}
127-
128128
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE module PUBLIC
2+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
3+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
4+
<module name="Checker">
5+
<module name="TreeWalker">
6+
<module name="AvoidStarImport">
7+
<property name="severity" value="warning" />
8+
</module>
9+
</module>
10+
</module>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE suppressions PUBLIC
4+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
5+
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
6+
7+
<suppressions>
8+
<!-- don't validate generated files -->
9+
<suppress id="lineLengthXml" files="releasenotes_old_8\-0_8\-34\.xml"/>
10+
<suppress id="lineLengthXml" files="releasenotes_old_6\-0_7\-8\.xml"/>
11+
<suppress id="lineLengthXml" files="releasenotes_old_1\-0_5\-9\.xml"/>
12+
<suppress id="lineLengthXml" files="[\\/]meta[\\/]"/>
13+
</suppressions>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.example</groupId>
6+
<artifactId>application</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<properties>
9+
<maven.compiler.target>17</maven.compiler.target>
10+
<maven.compiler.source>17</maven.compiler.source>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
</properties>
13+
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-checkstyle-plugin</artifactId>
19+
<version>3.1.0</version>
20+
<configuration>
21+
<configLocation>checkstyle/rules.xml</configLocation>
22+
<consoleOutput>true</consoleOutput>
23+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
24+
</configuration>
25+
<executions>
26+
<execution>
27+
<phase>validate</phase>
28+
<goals>
29+
<goal>check</goal>
30+
</goals>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
37+
</project>

0 commit comments

Comments
 (0)