Skip to content

Commit a3a5591

Browse files
fabapp2ammachado
andauthored
Fix/958 fix build with windows (#969)
- Build runs under Windows - All tests green - Shell application works - Spring Boot 3 Upgrade Report app works Changes - Change line endings to sue `\n` and adjust string comparisons in tests - Fix GH action - Add new method `get...Path()` to `ProjectResource` closes #958 --------- Co-authored-by: Adriano Machado <[email protected]> Co-authored-by: Adriano Machado <[email protected]> Co-authored-by: Adriano Machado <[email protected]>
1 parent e3da031 commit a3a5591

File tree

68 files changed

+1159
-3197
lines changed

Some content is hidden

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

68 files changed

+1159
-3197
lines changed

.github/workflows/build-sbm-legacy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Build
22
on:
3+
pull_request:
4+
branches-ignore:
5+
- "**revamp**"
36
push:
47
branches:
58
- "**"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ pom.xml.versionsBackup
2121
**/src/generated/java/META-INF
2222
**.java-version
2323
.rewrite-cache
24+
.vscode/

applications/spring-shell/src/test/java/org/springframework/sbm/MigrateJpaApplicationIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void migrateJpaApplication() {
4747
assertThat(super.loadJavaFile("org.superbiz.injection.h3jpa", "SpringBootApp")).isNotEmpty();
4848
assertThat(super.loadTestJavaFile("org.superbiz.injection.h3jpa", "SpringBootAppTest")).isNotEmpty();
4949
String movies = loadJavaFile("org.superbiz.injection.h3jpa", "Movies");
50-
assertThat(movies).contains(
50+
assertThat(movies.replace("\r\n", "\n").replace("\r", "\n")).contains(
5151
"""
5252
package org.superbiz.injection.h3jpa;
5353

applications/spring-shell/src/test/java/org/springframework/sbm/recipes/MigrateJaxRsAnnotationsRecipeIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ void happyPath() {
139139
String javaFile = super.loadJavaFile("com.example.jee.app", "PersonController");
140140
assertThat(javaFile)
141141
.as(TestDiff.of(javaFile, expectedJavaSource))
142-
.isEqualTo(expectedJavaSource);
142+
.isEqualToNormalizingNewlines(expectedJavaSource);
143143

144144
String pomSource = super.loadFile(Path.of("pom.xml"));
145145
assertThat(pomSource)
146146
.as(TestDiff.of(pomSource, expectedPomSource))
147-
.isEqualTo(expectedPomSource);
147+
.isEqualToNormalizingNewlines(expectedPomSource);
148148
}
149149
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2021 - 2023 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;
17+
18+
public interface SbmConstants {
19+
20+
/**
21+
* Line separator to use
22+
*/
23+
String LS = "\n";
24+
}

components/sbm-core/src/main/java/org/springframework/sbm/build/migration/MavenPomCacheProvider.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,27 @@
1515
*/
1616
package org.springframework.sbm.build.migration;
1717

18+
import lombok.Getter;
1819
import org.jetbrains.annotations.NotNull;
19-
import org.openrewrite.maven.cache.InMemoryMavenPomCache;
2020
import org.openrewrite.maven.cache.MavenPomCache;
2121
import org.openrewrite.maven.cache.RocksdbMavenPomCache;
2222
import org.springframework.sbm.engine.annotations.StatefulComponent;
2323

24-
import javax.annotation.PostConstruct;
2524
import java.nio.file.Path;
25+
import java.util.Optional;
2626

27+
@Getter
2728
@StatefulComponent
2829
public class MavenPomCacheProvider {
2930

30-
private MavenPomCache pomCache;
31+
private final MavenPomCache pomCache;
3132

32-
@PostConstruct
33-
void postConstruct() {
34-
pomCache = rocksdb();
35-
}
36-
37-
public MavenPomCache getPomCache() {
38-
return pomCache == null ? inMemory() : pomCache;
39-
}
40-
41-
private MavenPomCache inMemory() {
42-
return new InMemoryMavenPomCache();
33+
public MavenPomCacheProvider(Optional<MavenPomCache> mavenPomCacheProvider) {
34+
this.pomCache = mavenPomCacheProvider.orElseGet(this::rocksdb);
4335
}
4436

4537
@NotNull
4638
private RocksdbMavenPomCache rocksdb() {
4739
return new RocksdbMavenPomCache(Path.of(".").toAbsolutePath());
4840
}
49-
5041
}

components/sbm-core/src/main/java/org/springframework/sbm/build/migration/actions/AddMinimalPomXml.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public class AddMinimalPomXml extends AbstractAction {
5858

5959
@Override
6060
public void apply(ProjectContext context) {
61-
String projectDir = context.getProjectRootDirectory().toString();
62-
String projectName = projectDir.replace(" ", "-").substring(projectDir.lastIndexOf("/") + 1);
61+
String projectName = context.getProjectRootDirectory().getFileName().toString();
6362
Map<String, String> params = new HashMap<>();
6463
params.put("groupId", "com.example.change");
6564
params.put("artifactId", projectName);

components/sbm-core/src/main/java/org/springframework/sbm/common/filter/PathPatternMatchingProjectResourceFinder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public PathPatternMatchingProjectResourceFinder(String... matchingPatterns) {
4444
}
4545

4646
private void validateMatchingPatterns(List<String> matchingPatterns) {
47-
for(String pattern : matchingPatterns) {
48-
if( ! matcher.isPattern(pattern)) {
47+
for (String pattern : matchingPatterns) {
48+
if (!matcher.isPattern(pattern)) {
4949
throw new RuntimeException("The provided pattern '"+pattern+"' is invalid. Please check AntPathMatcher javadoc for examples of valid patterns.");
5050
}
5151
}

components/sbm-core/src/main/java/org/springframework/sbm/common/util/OsAgnosticPathMatcher.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
*/
3434
public class OsAgnosticPathMatcher implements PathMatcher {
3535

36-
private PathMatcher pathMatcher = new AntPathMatcher();
37-
private LinuxWindowsPathUnifier pathUnifier = new LinuxWindowsPathUnifier();
36+
private final PathMatcher pathMatcher = new AntPathMatcher();
3837

3938
@Override
4039
public boolean isPattern(String s) {
@@ -43,42 +42,35 @@ public boolean isPattern(String s) {
4342

4443
@Override
4544
public boolean match(String pattern, String path) {
46-
path = unifyPath(path);
47-
return pathMatcher.match(pattern, path);
45+
return pathMatcher.match(pattern, unifyPath(path));
4846
}
4947

5048
private String unifyPath(String path) {
51-
return pathUnifier.unifyPath(path);
49+
return LinuxWindowsPathUnifier.transformToLinuxPath(path);
5250
}
5351

5452
@Override
5553
public boolean matchStart(String pattern, String path) {
56-
path = unifyPath(path);
57-
return pathMatcher.matchStart(pattern, path);
54+
return pathMatcher.matchStart(pattern, unifyPath(path));
5855
}
5956

6057
@Override
6158
public String extractPathWithinPattern(String pattern, String path) {
62-
path = unifyPath(path);
63-
return pathMatcher.extractPathWithinPattern(pattern, path);
59+
return pathMatcher.extractPathWithinPattern(pattern, unifyPath(path));
6460
}
6561

6662
@Override
6763
public Map<String, String> extractUriTemplateVariables(String pattern, String path) {
68-
path = unifyPath(path);
69-
return pathMatcher.extractUriTemplateVariables(pattern, path);
64+
return pathMatcher.extractUriTemplateVariables(pattern, unifyPath(path));
7065
}
7166

7267
@Override
7368
public Comparator<String> getPatternComparator(String path) {
74-
path = unifyPath(path);
75-
return pathMatcher.getPatternComparator(path);
69+
return pathMatcher.getPatternComparator(unifyPath(path));
7670
}
7771

7872
@Override
7973
public String combine(String pattern1, String pattern2) {
8074
return pathMatcher.combine(pattern1, pattern2);
8175
}
82-
83-
8476
}

components/sbm-core/src/main/java/org/springframework/sbm/engine/context/ProjectContext.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ public ProjectContext(JavaRefactoringFactory javaRefactoringFactory, Path projec
6363
this.resultMerger = resultMerger;
6464
}
6565

66-
public ProjectResourceSet getProjectResources() {
67-
return projectResources;
68-
}
69-
7066
/**
7167
* @deprecated
7268
* Use {@link #getApplicationModules()} instead.
@@ -89,7 +85,7 @@ private Module mapToModule(BuildFile buildFile) {
8985
* This is a legacy way of retrieving applications build file.
9086
* This function does not generalise for situations where application is under a multi-module maven structure
9187
* Use {@link #getApplicationModules()} instead of getBuildFile()
92-
* If one would want to retrieve the root build file use:
88+
* If one wants to retrieve the root build file use:
9389
* {@link #getApplicationModules()} and then call to get root module using: {@link ApplicationModules#getRootModule()}
9490
* */
9591
@Deprecated(forRemoval = true)

0 commit comments

Comments
 (0)