Skip to content

Commit

Permalink
Merge branch 'main' into improve-remove-annotation-recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 authored Dec 21, 2023
2 parents c45df20 + c96893f commit 92024a8
Show file tree
Hide file tree
Showing 77 changed files with 1,368 additions and 3,486 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-sbm-legacy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Build
on:
pull_request:
branches-ignore:
- "**revamp**"
push:
branches:
- "**"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ pom.xml.versionsBackup
**/src/generated/java/META-INF
**.java-version
.rewrite-cache
.vscode/
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ ____

== Documentation

- https://spring-projects-experimental.github.io/spring-boot-migrator/user-documentation.html[User documentation,window=_blank]
- https://spring-projects-experimental.github.io/spring-boot-migrator/developer-documentation.html[Developer documentation,window=_blank]
- https://github.com/spring-projects-experimental/spring-boot-migrator/blob/main/docs/reference/user-documentation.adoc[User documentation]
- https://github.com/spring-projects-experimental/spring-boot-migrator/blob/main/docs/reference/developer-documentation.adoc[Developer documentation]


== Spring Boot 3.0 Upgrade - Interactive Web UI
Expand Down Expand Up @@ -134,7 +134,7 @@ NOTE: **SBM requires a JDK 17.**
* Clone the repository
* Change into root dir
* Run `mvn clean install`
* Find the jar in `applications/spring-shell/spring-boot-migrator.jar`
* Find the jar in `applications/spring-shell/target/spring-boot-migrator.jar`

WARNING: **Some integration tests use Docker so you'll need Docker to run them. +
You can pass the `-DskipTests` flag to the `mvn` command to ignore tests.**
Expand Down
2 changes: 1 addition & 1 deletion applications/spring-shell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.3</version>
<!-- Necessary to have test resource projects on the classpath-->
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ private void verifyJohnzonCoreDependencyIsUpgraded() {

assertThat(johnzonDependency.getClassifier()).isEqualTo("jakarta");
assertThat(johnzonDependency.getArtifactId()).isEqualTo("johnzon-core");
Optional<String> expectedJohnzonVersion = DependencyVersionHelper.getLatestReleaseVersion(johnzonDependency.getGroupId(), johnzonDependency.getArtifactId());
assertThat(johnzonDependency.getVersion()).isEqualTo(expectedJohnzonVersion.get());
assertThat(johnzonDependency.getVersion()).isEqualTo("1.2.21");
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void migrateJpaApplication() {
assertThat(super.loadJavaFile("org.superbiz.injection.h3jpa", "SpringBootApp")).isNotEmpty();
assertThat(super.loadTestJavaFile("org.superbiz.injection.h3jpa", "SpringBootAppTest")).isNotEmpty();
String movies = loadJavaFile("org.superbiz.injection.h3jpa", "Movies");
assertThat(movies).contains(
assertThat(movies.replace("\r\n", "\n").replace("\r", "\n")).contains(
"""
package org.superbiz.injection.h3jpa;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ void happyPath() {
String javaFile = super.loadJavaFile("com.example.jee.app", "PersonController");
assertThat(javaFile)
.as(TestDiff.of(javaFile, expectedJavaSource))
.isEqualTo(expectedJavaSource);
.isEqualToNormalizingNewlines(expectedJavaSource);

String pomSource = super.loadFile(Path.of("pom.xml"));
assertThat(pomSource)
.as(TestDiff.of(pomSource, expectedPomSource))
.isEqualTo(expectedPomSource);
.isEqualToNormalizingNewlines(expectedPomSource);
}
}
2 changes: 1 addition & 1 deletion components/sbm-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2021 - 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.sbm;

public interface SbmConstants {

/**
* Line separator to use
*/
String LS = "\n";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,27 @@
*/
package org.springframework.sbm.build.migration;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.openrewrite.maven.cache.InMemoryMavenPomCache;
import org.openrewrite.maven.cache.MavenPomCache;
import org.openrewrite.maven.cache.RocksdbMavenPomCache;
import org.springframework.sbm.engine.annotations.StatefulComponent;

import javax.annotation.PostConstruct;
import java.nio.file.Path;
import java.util.Optional;

@Getter
@StatefulComponent
public class MavenPomCacheProvider {

private MavenPomCache pomCache;
private final MavenPomCache pomCache;

@PostConstruct
void postConstruct() {
pomCache = rocksdb();
}

public MavenPomCache getPomCache() {
return pomCache == null ? inMemory() : pomCache;
}

private MavenPomCache inMemory() {
return new InMemoryMavenPomCache();
public MavenPomCacheProvider(Optional<MavenPomCache> mavenPomCacheProvider) {
this.pomCache = mavenPomCacheProvider.orElseGet(this::rocksdb);
}

@NotNull
private RocksdbMavenPomCache rocksdb() {
return new RocksdbMavenPomCache(Path.of(".").toAbsolutePath());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public class AddMinimalPomXml extends AbstractAction {

@Override
public void apply(ProjectContext context) {
String projectDir = context.getProjectRootDirectory().toString();
String projectName = projectDir.replace(" ", "-").substring(projectDir.lastIndexOf("/") + 1);
String projectName = context.getProjectRootDirectory().getFileName().toString();
Map<String, String> params = new HashMap<>();
params.put("groupId", "com.example.change");
params.put("artifactId", projectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public PathPatternMatchingProjectResourceFinder(String... matchingPatterns) {
}

private void validateMatchingPatterns(List<String> matchingPatterns) {
for(String pattern : matchingPatterns) {
if( ! matcher.isPattern(pattern)) {
for (String pattern : matchingPatterns) {
if (!matcher.isPattern(pattern)) {
throw new RuntimeException("The provided pattern '"+pattern+"' is invalid. Please check AntPathMatcher javadoc for examples of valid patterns.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
*/
public class OsAgnosticPathMatcher implements PathMatcher {

private PathMatcher pathMatcher = new AntPathMatcher();
private LinuxWindowsPathUnifier pathUnifier = new LinuxWindowsPathUnifier();
private final PathMatcher pathMatcher = new AntPathMatcher();

@Override
public boolean isPattern(String s) {
Expand All @@ -43,42 +42,35 @@ public boolean isPattern(String s) {

@Override
public boolean match(String pattern, String path) {
path = unifyPath(path);
return pathMatcher.match(pattern, path);
return pathMatcher.match(pattern, unifyPath(path));
}

private String unifyPath(String path) {
return pathUnifier.unifyPath(path);
return LinuxWindowsPathUnifier.transformToLinuxPath(path);
}

@Override
public boolean matchStart(String pattern, String path) {
path = unifyPath(path);
return pathMatcher.matchStart(pattern, path);
return pathMatcher.matchStart(pattern, unifyPath(path));
}

@Override
public String extractPathWithinPattern(String pattern, String path) {
path = unifyPath(path);
return pathMatcher.extractPathWithinPattern(pattern, path);
return pathMatcher.extractPathWithinPattern(pattern, unifyPath(path));
}

@Override
public Map<String, String> extractUriTemplateVariables(String pattern, String path) {
path = unifyPath(path);
return pathMatcher.extractUriTemplateVariables(pattern, path);
return pathMatcher.extractUriTemplateVariables(pattern, unifyPath(path));
}

@Override
public Comparator<String> getPatternComparator(String path) {
path = unifyPath(path);
return pathMatcher.getPatternComparator(path);
return pathMatcher.getPatternComparator(unifyPath(path));
}

@Override
public String combine(String pattern1, String pattern2) {
return pathMatcher.combine(pattern1, pattern2);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ public ProjectContext(JavaRefactoringFactory javaRefactoringFactory, Path projec
this.resultMerger = resultMerger;
}

public ProjectResourceSet getProjectResources() {
return projectResources;
}

/**
* @deprecated
* Use {@link #getApplicationModules()} instead.
Expand All @@ -89,7 +85,7 @@ private Module mapToModule(BuildFile buildFile) {
* This is a legacy way of retrieving applications build file.
* This function does not generalise for situations where application is under a multi-module maven structure
* Use {@link #getApplicationModules()} instead of getBuildFile()
* If one would want to retrieve the root build file use:
* If one wants to retrieve the root build file use:
* {@link #getApplicationModules()} and then call to get root module using: {@link ApplicationModules#getRootModule()}
* */
@Deprecated(forRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jetbrains.annotations.NotNull;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.SbmApplicationProperties;
import org.springframework.sbm.utils.LinuxWindowsPathUnifier;
import org.springframework.stereotype.Component;

import java.io.File;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void add(File dirUnderGit, String... filePatterns) {
try {
Git git = getGit(dirUnderGit);
AddCommand add = git.add();
processFilePatterns(dirUnderGit, git, s -> add.addFilepattern(s), filePatterns);
processFilePatterns(dirUnderGit, git, add::addFilepattern, filePatterns);
DirCache call = add.call();
} catch (GitAPIException e) {
throw new RuntimeException(e);
Expand All @@ -94,11 +95,11 @@ private void processFilePatterns(File dirUnderGit, Git git, Consumer<String> add
Path repoDir = git.getRepository().getDirectory().toPath().getParent();
Path pathFromGit = repoDir.relativize(dirUnderGit.toPath());
for (String filePattern : filePatterns) {
if(filePattern.equals(".")) {
if (filePattern.equals(".")) {
add.accept(".");
} else {
filePattern = pathFromGit.resolve(filePattern).toString();
add.accept(filePattern);
add.accept(LinuxWindowsPathUnifier.unifyPath(filePattern));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ class JavaSourceDirExistsPreconditionCheck extends PreconditionCheck {
private static final String JAVA_SRC_DIR = "src/main/java";
private static final String PATTERN = "/**/src/main/java/**";
private final PathMatcher pathMatcher = new OsAgnosticPathMatcher();
private final LinuxWindowsPathUnifier pathUnifier = new LinuxWindowsPathUnifier();

@Override
public PreconditionCheckResult verify(Path projectRoot, List<Resource> projectResources) {
if (projectResources.stream()
.noneMatch(r -> pathMatcher.match(PATTERN, pathUnifier.unifyPath(getPath(r).toAbsolutePath().toString())))) {
.noneMatch(r -> pathMatcher.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 @@ -39,7 +39,6 @@
import org.springframework.sbm.build.impl.RewriteMavenParser;
import org.springframework.sbm.engine.events.*;
import org.springframework.sbm.scopes.ProjectMetadata;
import org.springframework.sbm.utils.LinuxWindowsPathUnifier;
import org.springframework.stereotype.Component;

import java.io.IOException;
Expand Down Expand Up @@ -75,9 +74,7 @@ public List<SourceFile> parse(Path projectDirectory, List<Resource> resources) {
MavenExecutionContextView mavenExecutionContext = MavenExecutionContextView.view(executionContext);
mavenExecutionContext.setMavenSettings(mavenSettings);
Path localRepo = Path.of(System.getProperty("user.home")).resolve(".m2/repository");
String unifiedLocalRepo = LinuxWindowsPathUnifier.unifyPath(localRepo);
String uri = "%s://%s".formatted("file", unifiedLocalRepo);
MavenExecutionContextView.view(executionContext).setLocalRepository(new MavenRepository("local", uri, null, null, false, null, null, null));
MavenExecutionContextView.view(executionContext).setLocalRepository(new MavenRepository("local", localRepo.toUri().toString(), null, null, false, null, null, null));
// default local repo provided by MavenExecutionContextView misses two '/' in the path
mavenConfigHandler.injectMavenConfigIntoSystemProperties(resources);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.springframework.sbm.common.util.OsAgnosticPathMatcher;
import org.springframework.sbm.project.resource.SbmApplicationProperties;
import org.springframework.sbm.project.resource.ResourceHelper;
import org.springframework.sbm.utils.LinuxWindowsPathUnifier;
import org.springframework.stereotype.Service;
import org.springframework.util.PathMatcher;

Expand All @@ -37,15 +36,12 @@ public class PathScanner {
private final SbmApplicationProperties sbmApplicationProperties;
private final ResourceHelper resourceHelper;
private final PathMatcher pathMatcher = new OsAgnosticPathMatcher();
private final LinuxWindowsPathUnifier pathUnifier = new LinuxWindowsPathUnifier();

public List<Resource> scan(Path projectRoot) {
Path absoluteRootPath = projectRoot.toAbsolutePath();
String pattern = new LinuxWindowsPathUnifier().unifyPath(absoluteRootPath.toString() + "/**");
Resource[] resources = resourceHelper.loadResources("file:" + pattern);
String pattern = "%s/**".formatted(projectRoot.toAbsolutePath().toUri());
Resource[] resources = resourceHelper.loadResources(pattern);

return Arrays.asList(resources)
.stream()
return Arrays.stream(resources)
.filter(p -> this.isRelevant(projectRoot, getPath(p)))
.collect(Collectors.toList());
}
Expand All @@ -55,8 +51,7 @@ private boolean isRelevant(Path projectRoot, Path givenResource) {
return false;
}
return sbmApplicationProperties.getIgnoredPathsPatterns().stream()
.noneMatch(ir -> pathMatcher.match(ir,
pathUnifier.unifyPath(projectRoot.relativize(givenResource))));
.noneMatch(ir -> pathMatcher.match(ir, projectRoot.relativize(givenResource).toString()));
}

private Path getPath(Resource r) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.io.Resource;
import org.springframework.sbm.engine.events.StartedScanningProjectResourceEvent;
import org.springframework.sbm.utils.LinuxWindowsPathUnifier;
import org.springframework.stereotype.Component;

import java.io.IOException;
Expand Down Expand Up @@ -149,7 +150,7 @@ private List<? extends SourceFile> parseSingleResource(Path baseDir, ExecutionCo
try {
return e.getKey().parseInputs(List.of(resource), baseDir, ctx);
} catch(Exception ex) {
if(resource.getPath().toString().contains("src/test/resources")) {
if(LinuxWindowsPathUnifier.unifyPath(resource.getPath()).contains("src/test/resources")) {
log.error("Could not parse resource '%s' using parser %s. Exception was: %s".formatted(resource.getPath(), e.getKey().getClass().getName(), ex.getMessage()));
return null;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ public interface ProjectResource {
*/
Path getSourcePath();

/**
* @return the OS agnostic path representation of {@link #getSourcePath()}.
*/
String getSourcePathString();

Path getAbsolutePath();

/**
* @return the OS agnostic path representation of {@link #getAbsolutePath()}.
*/
String getAbsolutePathString();

void delete();

boolean isDeleted();

void moveTo(Path newPath);

}
Loading

0 comments on commit 92024a8

Please sign in to comment.