Skip to content

Commit 3488216

Browse files
sanagaraj-pivotalfabapp2
authored andcommitted
* Fix paths to use os path separator * Fix tests in `core` module when building with Windows * Removing event publisher call in Catch statement * Fixing parser reset() error on duplicated fully qualified names Co-authored-by: Fabian Krüger <[email protected]>
1 parent 6b251e5 commit 3488216

File tree

8 files changed

+31
-22
lines changed

8 files changed

+31
-22
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.springframework.sbm.project.resource.filter.ProjectResourceFinder;
2121
import org.springframework.util.AntPathMatcher;
2222

23+
import java.io.File;
2324
import java.util.Arrays;
2425
import java.util.List;
2526
import java.util.stream.Collectors;
@@ -31,7 +32,7 @@ public class PathMatchingProjectResourceFilter implements ProjectResourceFinder<
3132
*/
3233
private final List<String> matchingPatterns;
3334

34-
private final AntPathMatcher matcher = new AntPathMatcher();
35+
private final AntPathMatcher matcher = new AntPathMatcher(File.separator);
3536

3637
public PathMatchingProjectResourceFilter(List<String> matchingPatterns) {
3738
this.matchingPatterns = matchingPatterns;

components/sbm-core/src/main/java/org/springframework/sbm/engine/precondition/JavaSourceDirExistsPreconditionCheck.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
@Component
2727
class JavaSourceDirExistsPreconditionCheck extends PreconditionCheck {
2828

29-
private static final String PATTERN = "/**/src/main/java/**";
29+
private static final String PATTERN = "**" + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator + "**";
3030
private final String JAVA_SRC_DIR = "src/main/java";
3131
private AntPathMatcher antPathMatcher = new AntPathMatcher(File.separator);
3232

3333
@Override
3434
public PreconditionCheckResult verify(Path projectRoot, List<Resource> projectResources) {
35+
String pattern = projectRoot.resolve(PATTERN).toAbsolutePath().normalize().toString();
3536
if (projectResources.stream()
36-
.noneMatch(r -> antPathMatcher.match(projectRoot.resolve(PATTERN).normalize().toString(), getPath(r).toAbsolutePath().toString()))) {
37+
.noneMatch(r -> antPathMatcher.match(pattern, getPath(r).toAbsolutePath().toString()))) {
3738
return new PreconditionCheckResult(ResultState.FAILED, "PreconditionCheck check could not find a '" + JAVA_SRC_DIR + "' dir. This dir is required.");
3839
}
3940
return new PreconditionCheckResult(ResultState.PASSED, "Found required source dir 'src/main/java'.");

components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/Action.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ default void applyWithStatusEvent(ProjectContext context) {
3636
try {
3737
apply(context);
3838
} catch(Exception e) {
39-
eventPublisher.publishEvent(new ActionFailedEvent(getDescription()));
4039
throw new ActionFailedException("'"+this.getDescription()+"' failed: " + e.getMessage(), e);
4140
}
4241
if (eventPublisher != null) {

components/sbm-core/src/main/java/org/springframework/sbm/java/impl/DependenciesChangedEventHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import java.io.ByteArrayInputStream;
3030
import java.nio.charset.StandardCharsets;
3131
import java.nio.file.Path;
32+
import java.util.ArrayList;
3233
import java.util.List;
34+
import java.util.Set;
3335
import java.util.stream.Collectors;
3436

3537
@Component
@@ -42,10 +44,11 @@ public class DependenciesChangedEventHandler {
4244
public void onDependenciesChanged(DependenciesChangedEvent event) {
4345
if (projectContextHolder.getProjectContext() != null) {
4446
JavaParser currentJavaParser = JavaParserFactory.getCurrentJavaParser();
45-
List<Parser.Input> compilationUnits = projectContextHolder.getProjectContext().getProjectJavaSources().asStream()
47+
Set<Parser.Input> compilationUnitsSet = projectContextHolder.getProjectContext().getProjectJavaSources().asStream()
4648
.map(js -> js.getResource().getSourceFile())
4749
.map(js -> new Parser.Input(js.getSourcePath(), () -> new ByteArrayInputStream(js.printAll().getBytes(StandardCharsets.UTF_8))))
48-
.collect(Collectors.toList());
50+
.collect(Collectors.toSet());
51+
List<Parser.Input> compilationUnits = new ArrayList<>(compilationUnitsSet);
4952

5053
Path projectRootDirectory = projectContextHolder.getProjectContext().getProjectRootDirectory();
5154
List<J.CompilationUnit> parsedCompilationUnits = currentJavaParser.parseInputs(compilationUnits, projectRootDirectory, new RewriteExecutionContext(applicationEventPublisher));

components/sbm-core/src/test/java/org/springframework/sbm/common/migration/actions/MoveFilesActionTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
*/
1616
package org.springframework.sbm.common.migration.actions;
1717

18+
import org.junit.jupiter.api.DisplayName;
19+
import org.junit.jupiter.api.Test;
20+
import org.springframework.sbm.common.filter.PathMatchingProjectResourceFilter;
1821
import org.springframework.sbm.engine.context.ProjectContext;
1922
import org.springframework.sbm.project.resource.InternalProjectResource;
2023
import org.springframework.sbm.project.resource.ProjectResource;
2124
import org.springframework.sbm.project.resource.TestProjectContext;
22-
import org.springframework.sbm.common.filter.PathMatchingProjectResourceFilter;
23-
import org.junit.jupiter.api.DisplayName;
24-
import org.junit.jupiter.api.Test;
2525

2626
import java.nio.file.Path;
27-
import java.util.List;
2827
import java.util.stream.Collectors;
2928

3029
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,11 +39,11 @@ void moveFile() {
4039
Path projectRoot = TestProjectContext.getDefaultProjectRoot();
4140

4241
// file 1
43-
String someFilePath = "src/main/resources/a/SomeFile.foo";
42+
String someFilePath = Path.of("src/main/resources/a/SomeFile.foo").toString();
4443
String fileContent1 = "file content";
4544

4645
// file 2
47-
String anotherFilePath = "src/main/resources/b/AnotherFile.foo";
46+
String anotherFilePath = Path.of("src/main/resources/b/AnotherFile.foo").toString();
4847
String fileContent2 = "file content 2";
4948

5049
// target dir
@@ -56,8 +55,8 @@ void moveFile() {
5655
.addProjectResource(anotherFilePath, fileContent2)
5756
.build();
5857

59-
ProjectResource someFile = projectContext.search(new PathMatchingProjectResourceFilter(List.of("/**/SomeFile.foo"))).get(0);
60-
ProjectResource anotherFile = projectContext.search(new PathMatchingProjectResourceFilter(List.of("/**/AnotherFile.foo"))).get(0);
58+
ProjectResource someFile = projectContext.search(new PathMatchingProjectResourceFilter("/**/SomeFile.foo")).get(0);
59+
ProjectResource anotherFile = projectContext.search(new PathMatchingProjectResourceFilter("/**/AnotherFile.foo")).get(0);
6160

6261
verifyPrecondition(someFile, projectRoot.resolve(someFilePath), fileContent1);
6362
verifyPrecondition(anotherFile, projectRoot.resolve(anotherFilePath), fileContent2);

components/sbm-core/src/test/java/org/springframework/sbm/java/impl/RewriteJavaParserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void shouldDelegateParsingErrorsToExceptionHandler() throws ClassNotFoundExcepti
4343
String out = sysOutBuffer.toString();
4444
System.setOut(realSysOut);
4545
assertThat(out).containsPattern(
46-
".*org.openrewrite.java.Java11Parser.*compile error\n");
46+
".*org.openrewrite.java.Java11Parser.*compile error.*");
4747
// System.out.println(out);
4848
}
4949

components/sbm-core/src/test/java/org/springframework/sbm/project/ApplicationModules_getTopmostApplicationModulesTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616
package org.springframework.sbm.project;
1717

18-
import org.springframework.sbm.build.api.ApplicationModule;
19-
import org.springframework.sbm.engine.context.ProjectContext;
20-
import org.springframework.sbm.project.resource.TestProjectContext;
2118
import org.junit.jupiter.api.BeforeEach;
2219
import org.junit.jupiter.api.Nested;
2320
import org.junit.jupiter.api.Test;
21+
import org.springframework.sbm.build.api.ApplicationModule;
22+
import org.springframework.sbm.engine.context.ProjectContext;
23+
import org.springframework.sbm.project.resource.TestProjectContext;
2424

25+
import java.nio.file.Path;
2526
import java.util.List;
2627
import java.util.stream.Collectors;
2728

@@ -111,7 +112,7 @@ void beforeEach() {
111112
void whenGetTopmostApplicationModulesThenChildModuleShouldBeReturned() {
112113
List<ApplicationModule> topmostApplicationModules = projectContext.getApplicationModules().getTopmostApplicationModules();
113114
assertThat(topmostApplicationModules).hasSize(1);
114-
assertThat(topmostApplicationModules.get(0).getBuildFile().getSourcePath().toString()).isEqualTo("module1/pom.xml");
115+
assertThat(topmostApplicationModules.get(0).getBuildFile().getSourcePath()).isEqualTo(Path.of("module1/pom.xml"));
115116
}
116117
}
117118

@@ -185,7 +186,7 @@ void beforeEach() {
185186
void whenGetTopmostApplicationModulesThenChildPom1ShouldBeReturned() {
186187
List<ApplicationModule> topmostApplicationModules = projectContext.getApplicationModules().getTopmostApplicationModules();
187188
assertThat(topmostApplicationModules).hasSize(1);
188-
assertThat(topmostApplicationModules.get(0).getBuildFile().getSourcePath().toString()).isEqualTo("module1/pom.xml");
189+
assertThat(topmostApplicationModules.get(0).getBuildFile().getSourcePath().toString()).isEqualTo(Path.of("module1/pom.xml").toString());
189190
}
190191
}
191192

@@ -283,7 +284,7 @@ void whenGetTopmostApplicationModulesThenPom1AndPom3ShouldBeReturned() {
283284
List<ApplicationModule> topmostApplicationModules = projectContext.getApplicationModules().getTopmostApplicationModules();
284285
assertThat(topmostApplicationModules).hasSize(2);
285286
List<String> topmostApplicationModulePaths = topmostApplicationModules.stream().map(m -> m.getBuildFile().getSourcePath().toString()).collect(Collectors.toList());
286-
assertThat(topmostApplicationModulePaths).contains("module1/pom.xml", "module3/pom.xml");
287+
assertThat(topmostApplicationModulePaths).contains(Path.of("module1/pom.xml").toString(), Path.of("module3/pom.xml").toString());
287288
}
288289
}
289290
}

components/sbm-support-weblogic/src/main/java/org/springframework/sbm/jee/wls/actions/MigrateWlsEjbDeploymentDescriptor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,17 @@ private boolean incorporateIntoSourceFile(BuildFile buildFile, JavaSourceWithEjb
6262
if (transactionTimeoutSeconds != null) {
6363
int timeoutInMillis = calclateTimeoutForSpringBoot(transactionTimeoutSeconds);
6464
if (!javaSourceWithEjb.getType().hasAnnotation("org.springframework.transaction.annotation.Transactional")) {
65-
// TODO: provide some means to print this information on CLI as it takes a while, see #175
65+
66+
this.startProcess("Annotate " + javaSourceWithEjb.getType().getFullyQualifiedName() + " with @Transactional");
67+
6668
// FIXME: #466
6769
if (!buildFile.hasDeclaredDependencyMatchingRegex("org\\.springframework\\:spring-tx\\:.*")) {
6870
addDataJpaDependency = true;
6971
}
7072
javaSourceWithEjb.getType().addAnnotation("@Transactional(timeout=" + timeoutInMillis + ")", "org.springframework.transaction.annotation.Transactional");
73+
74+
this.endProcess();
75+
7176
} else {
7277
Annotation annotation = javaSourceWithEjb.getType().getAnnotation("org.springframework.transaction.annotation.Transactional");
7378
annotation.setAttribute("timeout", timeoutInMillis, Integer.class);

0 commit comments

Comments
 (0)