Skip to content

Makes ehchache migration multi-module aware for Spring Boot 3 upgrade #374

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 28 commits into from
Sep 5, 2022
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8434328
Updated test container dependency
ashakirin Aug 18, 2022
c6624e4
Revert "Updated test container dependency"
ashakirin Aug 18, 2022
597e140
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal Aug 22, 2022
48e5f8e
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal Aug 24, 2022
ba6da28
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal Aug 25, 2022
4720e24
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal Aug 26, 2022
49e851c
Multi Module example project
sanagaraj-pivotal Aug 22, 2022
0c64843
Itegration test scaffolding
sanagaraj-pivotal Aug 22, 2022
030bfd7
Itegration test scaffolding
sanagaraj-pivotal Aug 22, 2022
427534e
wip
sanagaraj-pivotal Aug 23, 2022
3e90e61
CreateAutoconfigurationAction is multimodule aware
sanagaraj-pivotal Aug 24, 2022
1ab8ba8
Multi maven module builds after migration
sanagaraj-pivotal Aug 24, 2022
aa9000b
Failing test, ehcache does not work with multi maven module spring app
sanagaraj-pivotal Aug 24, 2022
d01be95
Making it finder
sanagaraj-pivotal Aug 24, 2022
297d20c
New approach using context.getModules
sanagaraj-pivotal Aug 26, 2022
d775816
Passing test after merge
sanagaraj-pivotal Aug 26, 2022
dcdee32
using applicationmodule.contains call
sanagaraj-pivotal Aug 26, 2022
6a93903
Clean up integration test
sanagaraj-pivotal Aug 26, 2022
35437e8
Removing unnecessary
sanagaraj-pivotal Aug 26, 2022
6245cb0
clean up
sanagaraj-pivotal Aug 26, 2022
a71124b
Passing test
sanagaraj-pivotal Aug 26, 2022
7a07705
Simplifying
sanagaraj-pivotal Aug 26, 2022
405612b
Completed
sanagaraj-pivotal Aug 26, 2022
61918b7
Removing exception throwing
sanagaraj-pivotal Sep 5, 2022
d353b40
parent pom is bumped in multi module projects
sanagaraj-pivotal Sep 5, 2022
32ada22
Failing test
sanagaraj-pivotal Sep 5, 2022
41a84ad
Updated and fixed integration test for verifying ehcache dependency u…
ashakirin Sep 5, 2022
bbcbf50
Merge branch 'main' into 370-ehchache-multimodule
fabapp2 Sep 5, 2022
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 @@ -16,8 +16,19 @@

package org.springframework.sbm;

import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.openrewrite.maven.MavenParser;
import org.openrewrite.maven.tree.Dependency;
import org.openrewrite.maven.tree.MavenResolutionResult;
import org.openrewrite.xml.tree.Xml;

import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class BootUpgrade_27_30_MultiModule_IntegrationTest extends IntegrationTestBaseClass {
@Override
Expand All @@ -35,6 +46,81 @@ void migrateMultiModuleApplication() {
applyRecipe("boot-2.7-3.0-dependency-version-update");

buildProject();

verifyParentPomVersion();
verifyEhCacheVersionIsUpgraded();
}

private void verifyEhCacheVersionIsUpgraded() {
Optional<Dependency> ehcacheResult = getDependencyByArtifactId("ehcache", "spring-app/");

assertThat(ehcacheResult).isPresent();

Dependency ehcacheDependency = ehcacheResult.get();

assertThat(ehcacheDependency.getArtifactId()).isEqualTo("ehcache");
assertThat(ehcacheDependency.getGav().getGroupId()).isEqualTo("org.ehcache");
assertThat(ehcacheDependency.getGav().getVersion()).isNull();
assertThat(ehcacheDependency.getClassifier()).isEqualTo("jakarta");
}

private Optional<Dependency> getDependencyByArtifactId(String artifactId, String module) {
Xml.Document mavenAsXMLDocument = getBuildFileByModule(module);
List<Dependency> dependencies = getDependencies(mavenAsXMLDocument);
return dependencies
.stream()
.filter(dependency -> dependency.getArtifactId().equals(artifactId))
.findFirst();
}

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

private void verifyParentPomVersion() {
Xml.Document mavenAsXMLDocument = getRootBuildFile();

Xml.Tag parentTag = mavenAsXMLDocument
.getRoot()
.getChildren("parent").get(0);

String version = parentTag.getChildValue("version").get();

String groupId = parentTag.getChildValue("groupId").get();
String artifactId = parentTag.getChildValue("artifactId").get();

assertThat(version).isEqualTo("3.0.0-M3");
assertThat(groupId).isEqualTo("org.springframework.boot");
assertThat(artifactId).isEqualTo("spring-boot-starter-parent");
}

@NotNull
private Xml.Document getRootBuildFile() {
return parsePom(loadFile(Path.of("pom.xml")));
}

@NotNull
private Xml.Document getBuildFileByModule(String app) {

return parseSubmodulePom(loadFile(Path.of("pom.xml")), loadFile(Path.of(app + "pom.xml")));
}


@NotNull
private Xml.Document parsePom(String pomContent) {
MavenParser mavenParser = new MavenParser.Builder().build();
return mavenParser.parse(pomContent).get(0);
}

@NotNull
private Xml.Document parseSubmodulePom(String parentPom, String pomContent) {
MavenParser mavenParser = new MavenParser.Builder().build();
return mavenParser.parse(parentPom, pomContent).get(1);
}

private void buildProject() {
Expand Down