Skip to content

Windows support #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
### [0.10.0](https://github.com/spring-projects-experimental/spring-boot-migrator/releases/tag/0.10.0) - 2022-03-28
## [0.11.0](https://github.com/spring-projects-experimental/spring-boot-migrator/releases/tag/0.10.0) -

### Adds
- Unmarshalling ejb-jar.xml for EJB 2.1 (#62)

### Fixes
- Paths and CLI rendering under Windows (#58)

## [0.10.0](https://github.com/spring-projects-experimental/spring-boot-migrator/releases/tag/0.10.0) - 2022-03-28

### Adds
- Support to migrate to Spring Cloud Config Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.sbm.project.resource.filter.ProjectResourceFinder;
import org.springframework.util.AntPathMatcher;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -31,7 +32,7 @@ public class PathMatchingProjectResourceFilter implements ProjectResourceFinder<
*/
private final List<String> matchingPatterns;

private final AntPathMatcher matcher = new AntPathMatcher();
private final AntPathMatcher matcher = new AntPathMatcher(File.separator);

public PathMatchingProjectResourceFilter(List<String> matchingPatterns) {
this.matchingPatterns = matchingPatterns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
@Component
class JavaSourceDirExistsPreconditionCheck extends PreconditionCheck {

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

@Override
public PreconditionCheckResult verify(Path projectRoot, List<Resource> projectResources) {
String pattern = projectRoot.resolve(PATTERN).toAbsolutePath().normalize().toString();
if (projectResources.stream()
.noneMatch(r -> antPathMatcher.match(projectRoot.resolve(PATTERN).normalize().toString(), getPath(r).toAbsolutePath().toString()))) {
.noneMatch(r -> antPathMatcher.match(pattern, getPath(r).toAbsolutePath().toString()))) {
return new PreconditionCheckResult(ResultState.FAILED, "PreconditionCheck check could not find a '" + JAVA_SRC_DIR + "' dir. This dir is required.");
}
return new PreconditionCheckResult(ResultState.PASSED, "Found required source dir 'src/main/java'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ default void applyWithStatusEvent(ProjectContext context) {
try {
apply(context);
} catch(Exception e) {
eventPublisher.publishEvent(new ActionFailedEvent(getDescription()));
throw new ActionFailedException("'"+this.getDescription()+"' failed: " + e.getMessage(), e);
}
if (eventPublisher != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

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

Path projectRootDirectory = projectContextHolder.getProjectContext().getProjectRootDirectory();
List<J.CompilationUnit> parsedCompilationUnits = currentJavaParser.parseInputs(compilationUnits, projectRootDirectory, new RewriteExecutionContext(applicationEventPublisher));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
*/
package org.springframework.sbm.common.migration.actions;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.sbm.common.filter.PathMatchingProjectResourceFilter;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.InternalProjectResource;
import org.springframework.sbm.project.resource.ProjectResource;
import org.springframework.sbm.project.resource.TestProjectContext;
import org.springframework.sbm.common.filter.PathMatchingProjectResourceFilter;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

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

// file 1
String someFilePath = "src/main/resources/a/SomeFile.foo";
String someFilePath = Path.of("src/main/resources/a/SomeFile.foo").toString();
String fileContent1 = "file content";

// file 2
String anotherFilePath = "src/main/resources/b/AnotherFile.foo";
String anotherFilePath = Path.of("src/main/resources/b/AnotherFile.foo").toString();
String fileContent2 = "file content 2";

// target dir
Expand All @@ -56,8 +55,8 @@ void moveFile() {
.addProjectResource(anotherFilePath, fileContent2)
.build();

ProjectResource someFile = projectContext.search(new PathMatchingProjectResourceFilter(List.of("/**/SomeFile.foo"))).get(0);
ProjectResource anotherFile = projectContext.search(new PathMatchingProjectResourceFilter(List.of("/**/AnotherFile.foo"))).get(0);
ProjectResource someFile = projectContext.search(new PathMatchingProjectResourceFilter("/**/SomeFile.foo")).get(0);
ProjectResource anotherFile = projectContext.search(new PathMatchingProjectResourceFilter("/**/AnotherFile.foo")).get(0);

verifyPrecondition(someFile, projectRoot.resolve(someFilePath), fileContent1);
verifyPrecondition(anotherFile, projectRoot.resolve(anotherFilePath), fileContent2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void shouldDelegateParsingErrorsToExceptionHandler() throws ClassNotFoundExcepti
String out = sysOutBuffer.toString();
System.setOut(realSysOut);
assertThat(out).containsPattern(
".*org.openrewrite.java.Java11Parser.*compile error\n");
".*org.openrewrite.java.Java11Parser.*compile error.*");
// System.out.println(out);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/
package org.springframework.sbm.project;

import org.springframework.sbm.build.api.ApplicationModule;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.TestProjectContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.sbm.build.api.ApplicationModule;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.TestProjectContext;

import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -111,7 +112,7 @@ void beforeEach() {
void whenGetTopmostApplicationModulesThenChildModuleShouldBeReturned() {
List<ApplicationModule> topmostApplicationModules = projectContext.getApplicationModules().getTopmostApplicationModules();
assertThat(topmostApplicationModules).hasSize(1);
assertThat(topmostApplicationModules.get(0).getBuildFile().getSourcePath().toString()).isEqualTo("module1/pom.xml");
assertThat(topmostApplicationModules.get(0).getBuildFile().getSourcePath()).isEqualTo(Path.of("module1/pom.xml"));
}
}

Expand Down Expand Up @@ -185,7 +186,7 @@ void beforeEach() {
void whenGetTopmostApplicationModulesThenChildPom1ShouldBeReturned() {
List<ApplicationModule> topmostApplicationModules = projectContext.getApplicationModules().getTopmostApplicationModules();
assertThat(topmostApplicationModules).hasSize(1);
assertThat(topmostApplicationModules.get(0).getBuildFile().getSourcePath().toString()).isEqualTo("module1/pom.xml");
assertThat(topmostApplicationModules.get(0).getBuildFile().getSourcePath().toString()).isEqualTo(Path.of("module1/pom.xml").toString());
}
}

Expand Down Expand Up @@ -283,7 +284,7 @@ void whenGetTopmostApplicationModulesThenPom1AndPom3ShouldBeReturned() {
List<ApplicationModule> topmostApplicationModules = projectContext.getApplicationModules().getTopmostApplicationModules();
assertThat(topmostApplicationModules).hasSize(2);
List<String> topmostApplicationModulePaths = topmostApplicationModules.stream().map(m -> m.getBuildFile().getSourcePath().toString()).collect(Collectors.toList());
assertThat(topmostApplicationModulePaths).contains("module1/pom.xml", "module3/pom.xml");
assertThat(topmostApplicationModulePaths).contains(Path.of("module1/pom.xml").toString(), Path.of("module3/pom.xml").toString());
}
}
}
Loading