Skip to content

286 integrate json b #343

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
Aug 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,36 @@ void migrateSimpleApplication() {
verifyCrudRepoAddition();
verifyAutoConfigurationIsRefactored();
verifyEhCacheVersionIsUpgraded();
verifyJohnzonCoreDependencyIsUpgraded();
}

private void buildProject() {
executeMavenGoals(getTestDir(), "clean", "verify");
}

private void verifyEhCacheVersionIsUpgraded() {
String pomContent = loadFile(Path.of("pom.xml"));
private void verifyJohnzonCoreDependencyIsUpgraded() {
Optional<Dependency> johnzonResult = getDependencyByArtifactId("johnzon-core");

Xml.Document mavenAsXMLDocument = parsePom(pomContent);
assertThat(johnzonResult.isPresent()).isTrue();

List<Dependency> dependencies = mavenAsXMLDocument
.getMarkers()
.findFirst(MavenResolutionResult.class)
.get()
.getPom()
.getRequestedDependencies();
Dependency johnzonDependency = johnzonResult.get();

Optional<Dependency> ehcacheResult = dependencies
assertThat(johnzonDependency.getClassifier()).isEqualTo("jakarta");
assertThat(johnzonDependency.getArtifactId()).isEqualTo("johnzon-core");
assertThat(johnzonDependency.getVersion()).isEqualTo("1.2.18");
}

@NotNull
private Optional<Dependency> getDependencyByArtifactId(String artifactId) {
Xml.Document mavenAsXMLDocument = getRootBuildFile();
List<Dependency> dependencies = getDependencies(mavenAsXMLDocument);
return dependencies
.stream()
.filter(dependency -> dependency.getArtifactId().equals("ehcache"))
.filter(dependency -> dependency.getArtifactId().equals(artifactId))
.findFirst();
}

private void verifyEhCacheVersionIsUpgraded() {
Optional<Dependency> ehcacheResult = getDependencyByArtifactId("ehcache");

assertThat(ehcacheResult).isPresent();

Expand All @@ -86,6 +94,22 @@ private void verifyEhCacheVersionIsUpgraded() {
assertThat(ehcacheDependency.getClassifier()).isEqualTo("jakarta");
}

@NotNull
private List<Dependency> getDependencies(Xml.Document mavenAsXMLDocument) {
return mavenAsXMLDocument
.getMarkers()
.findFirst(MavenResolutionResult.class)
.get()
.getPom()
.getRequestedDependencies();
}

@NotNull
private Xml.Document getRootBuildFile() {

return parsePom(loadFile(Path.of("pom.xml")));
}

private void verifyAutoConfigurationIsRefactored() {
String autoConfig = loadFile(Path.of("src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports"));
assertThat(autoConfig).isEqualTo("com.hello.GreetingConfig");
Expand Down Expand Up @@ -235,9 +259,7 @@ private void verifyPropertyConfigurationUpdate() {
}

private void verifyParentPomVersion() {
String pomContent = loadFile(Path.of("pom.xml"));

Xml.Document mavenAsXMLDocument = parsePom(pomContent);
Xml.Document mavenAsXMLDocument = getRootBuildFile();

Xml.Tag parentTag =mavenAsXMLDocument
.getRoot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<artifactId>rxjava</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ public class Boot_27_30_UpgradeReplaceJohnzonDependencies extends AbstractAction

@Override
public void apply(ProjectContext context) {

context.getApplicationModules()
.stream()
.map(ApplicationModule::getBuildFile)
.peek(bf -> bf.removeDependenciesMatchingRegex(JOHNZON_DEPENDENCY_PATTERN))
.forEach(bf -> bf.addDependency(Dependency.fromCoordinates(JOHNZON_DEPENDENCY)));
.forEach(bf -> {
bf.removeDependenciesMatchingRegex(JOHNZON_DEPENDENCY_PATTERN);
bf.addDependency(Dependency.fromCoordinates(JOHNZON_DEPENDENCY));
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
condition:
type: org.springframework.sbm.boot.upgrade.common.conditions.BootHasAutoconfigurationCondition

- type: org.springframework.sbm.boot.upgrade_27_30.actions.Boot_27_30_UpgradeReplaceJohnzonDependencies
condition:
type: org.springframework.sbm.boot.upgrade_27_30.conditions.JohnzonDependencyCondition
description: Changing JohnzonDependency version and classifier

- type: org.springframework.sbm.engine.recipe.OpenRewriteDeclarativeRecipeAdapter
condition:
type: org.springframework.sbm.boot.upgrade.common.conditions.HasSpringBootParentOfVersion
Expand All @@ -52,7 +57,7 @@
- org.openrewrite.maven.ChangeDependencyClassifier:
groupId: org.ehcache
artifactId: ehcache
newClassifier: jakarta
newClassifier: jakarta
- org.openrewrite.maven.ChangeDependencyVersion:
dependencyPattern: org.ehcache:ehcache
newVersion: 3.10.0
Expand Down