-
Notifications
You must be signed in to change notification settings - Fork 90
384 migrate explicit depependencies #393
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
fabapp2
merged 60 commits into
spring-projects-experimental:main
from
sanagaraj-pivotal:384_migrate_explicit_depependencies
Sep 18, 2022
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
8434328
Updated test container dependency
ashakirin c6624e4
Revert "Updated test container dependency"
ashakirin 597e140
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal 48e5f8e
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal ba6da28
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal 4720e24
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal 2f9c293
Merge branch 'spring-projects-experimental:main' into main
ashakirin 216fcb4
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal 6117071
Added test for explicit dependencies
ashakirin 0f1b00d
Passing test
sanagaraj-pivotal 82647c0
Passing test little bit better
sanagaraj-pivotal 5b67aba
Improvement to calculate dependency map only once
ashakirin 9328e77
Removed static identifier for dependnecy map
ashakirin 8b2e5d0
formatting updates
ashakirin 64cb4d0
Return foreach instead collector for readability
ashakirin 2397446
Failing test
sanagaraj-pivotal 835c089
Fixed non springboot dependecy test
ashakirin 625d7eb
Ping old SpringBoot version test
ashakirin 65915f2
Improved old SpringBoot version test
ashakirin 62cb6ca
Passing test
sanagaraj-pivotal fccc3e2
Clean up
sanagaraj-pivotal 1c63690
Ping SpringBoot parent test
ashakirin 131738f
Passing test
sanagaraj-pivotal 89baa3b
PING... Failing test
sanagaraj-pivotal 268f679
Fixed dependency import test
ashakirin 709b888
Ping test for import dependencies condition
ashakirin 7df90f3
Passing test
sanagaraj-pivotal 0ff11a3
Clean up
sanagaraj-pivotal 38703e7
Failing test case. ping ..
sanagaraj-pivotal 6b8e90b
Ping test for import dependencies condition, still failed
ashakirin 6103628
Ping SpringBoot Parent test
ashakirin 6715a2e
Passing test
sanagaraj-pivotal afc9527
Parameterising test
sanagaraj-pivotal e264536
tests pass
sanagaraj-pivotal 0a15685
Added test for Spring Project
ashakirin 83cf9a9
Ping test for dependencyManagement
ashakirin d174d8e
Passing test
sanagaraj-pivotal 975fb77
Failed test.. Ping..
sanagaraj-pivotal b113ab8
Fixed version property test
ashakirin b134ec8
Ping test for managed dependnecies condition
ashakirin 0a20ae2
Passed test
sanagaraj-pivotal 44fcf95
Passed integration teset
sanagaraj-pivotal e820dc1
Merge branch 'spring-projects-experimental:main' into main
ashakirin 5578ff9
Updated SpringBoot 3.0 migration configuration; manually managed inte…
ashakirin 50b05fe
Merge branch 'main' into 384_migrate_explicit_depependencies
ashakirin 1f33f9d
Added repositories to download SrpingBoot dependencies
ashakirin bd5661a
Fixed ExplicitVersionTest
ashakirin 78bc776
Removed temporary test file
ashakirin 3b8f797
Added parent pom into parsing
ashakirin e66a97e
Removed unnecessary pom download
ashakirin 4f499e8
Variable name refactoring
ashakirin bdcf2eb
Fixing PR comments for manually managed dependencies
ashakirin 839bca7
Fixing failing tests
sanagaraj-pivotal 02de4f1
Fixed recipes and integration tests
ashakirin 4a04426
Formatting
ashakirin 911ec76
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal 88c99b9
Merge branch 'main' into 384_migrate_explicit_depependencies
sanagaraj-pivotal 88d8636
Fixing failing tests
sanagaraj-pivotal 91e3e7a
Merge branch 'main' into 384_migrate_explicit_depependencies
fabapp2 20cd303
Merge branch 'main' into 384_migrate_explicit_depependencies
fabapp2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
175 changes: 175 additions & 0 deletions
175
.../test/java/org/springframework/sbm/BootUpgrade_27_30_ManuallyManaged_IntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* Copyright 2021 - 2022 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; | ||
|
||
import org.intellij.lang.annotations.Language; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.InMemoryExecutionContext; | ||
import org.openrewrite.maven.MavenParser; | ||
import org.openrewrite.maven.internal.MavenPomDownloader; | ||
import org.openrewrite.maven.tree.Dependency; | ||
import org.openrewrite.maven.tree.MavenResolutionResult; | ||
import org.openrewrite.maven.tree.ResolvedManagedDependency; | ||
import org.openrewrite.xml.tree.Xml; | ||
|
||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
public class BootUpgrade_27_30_ManuallyManaged_IntegrationTest extends IntegrationTestBaseClass { | ||
@Override | ||
protected String getTestSubDir() { | ||
return "boot-migration-27-30-manual-managed"; | ||
} | ||
|
||
@Test | ||
@Tag("integration") | ||
void migrateManuallyManagedApplication() { | ||
intializeTestProject(); | ||
|
||
scanProject(); | ||
|
||
applyRecipe("boot-2.7-3.0-dependency-version-update"); | ||
|
||
buildProject(); | ||
|
||
Xml.Document rootBuildFile = getRootBuildFile(); | ||
verifyManagedDependency(rootBuildFile, "spring-boot-starter-test", "3.0.0-M3"); | ||
verifyManagedDependency(rootBuildFile, "metrics-annotation", "4.2.9"); | ||
|
||
Xml.Document applicationBuildFile = getApplicationBuildFile(); | ||
verifyProperty(applicationBuildFile, "spring-boot-starter-web.version", "3.0.0-M3"); | ||
verifyDependencyWithClassifier(applicationBuildFile, "ehcache", "3.10.0", "jakarta"); | ||
|
||
verifyConstructorBindingRemoval(); | ||
} | ||
|
||
private void verifyManagedDependency(Xml.Document mavenAsXMLDocument, String artifactId, String version) { | ||
Optional<ResolvedManagedDependency> managedDependency = getManagedDependencyByArtifactId(mavenAsXMLDocument, artifactId); | ||
assertThat(managedDependency).isPresent(); | ||
assertThat(managedDependency.get().getVersion()).isEqualTo(version); | ||
} | ||
|
||
private void verifyDependency(Xml.Document mavenAsXMLDocument, String artifactId, String version) { | ||
verifyDependencyWithClassifier(mavenAsXMLDocument, artifactId, version, null); | ||
} | ||
|
||
private void verifyDependencyWithClassifier(Xml.Document mavenAsXMLDocument, String artifactId, String version, String classifier) { | ||
Optional<Dependency> dependency = getDependencyByArtifactId(mavenAsXMLDocument, artifactId); | ||
assertThat(dependency).isPresent(); | ||
assertThat(dependency.get().getVersion()).isEqualTo(version); | ||
if (classifier != null) { | ||
assertThat(dependency.get().getClassifier()).isEqualTo(classifier); | ||
} | ||
} | ||
|
||
@NotNull | ||
private Optional<Dependency> getDependencyByArtifactId(Xml.Document mavenAsXMLDocument, String artifactId) { | ||
List<Dependency> dependencies = getDependencies(mavenAsXMLDocument); | ||
return dependencies | ||
.stream() | ||
.filter(dependency -> dependency.getArtifactId().equals(artifactId)) | ||
.findAny(); | ||
} | ||
|
||
@NotNull | ||
private List<Dependency> getDependencies(Xml.Document mavenAsXMLDocument) { | ||
return mavenAsXMLDocument | ||
.getMarkers() | ||
.findFirst(MavenResolutionResult.class) | ||
.get() | ||
.getPom() | ||
.getRequestedDependencies(); | ||
} | ||
|
||
private void verifyProperty(Xml.Document mavenAsXMLDocument, String name, String value) { | ||
Map<String, String> props = getProperties(mavenAsXMLDocument); | ||
assertThat(props.containsKey(name)).isTrue(); | ||
assertThat(props.get(name)).isEqualTo(value); | ||
} | ||
|
||
@NotNull | ||
private Map<String, String> getProperties(Xml.Document mavenAsXMLDocument) { | ||
return mavenAsXMLDocument | ||
.getMarkers() | ||
.findFirst(MavenResolutionResult.class) | ||
.get() | ||
.getPom() | ||
.getProperties(); | ||
} | ||
|
||
@NotNull | ||
Optional<ResolvedManagedDependency> getManagedDependencyByArtifactId(Xml.Document mavenAsXMLDocument, String artifactId) { | ||
return getManagedDependencies(mavenAsXMLDocument) | ||
.stream() | ||
.filter(md -> md.getArtifactId().equals(artifactId)) | ||
.findAny(); | ||
} | ||
|
||
@NotNull | ||
private List<ResolvedManagedDependency> getManagedDependencies(Xml.Document mavenAsXMLDocument) { | ||
return mavenAsXMLDocument | ||
.getMarkers() | ||
.findFirst(MavenResolutionResult.class) | ||
.get() | ||
.getPom() | ||
.getDependencyManagement(); | ||
} | ||
|
||
@NotNull | ||
private Xml.Document getRootBuildFile() { | ||
return parsePom(loadFile(Path.of("pom.xml"))); | ||
} | ||
|
||
@NotNull | ||
private Xml.Document getApplicationBuildFile() { | ||
return parsePom(loadFile(Path.of("spring-app/pom.xml")), loadFile(Path.of("pom.xml"))); | ||
} | ||
|
||
@NotNull | ||
private Xml.Document parsePom(@Language("xml") String... pomContents) { | ||
MavenParser mavenParser = new MavenParser.Builder().build(); | ||
return mavenParser.parse(pomContents).get(0); | ||
} | ||
|
||
private void verifyConstructorBindingRemoval() { | ||
String constructorBindingConfigClass = loadJavaFileFromSubmodule("spring-app/", "org.springboot.example.upgrade", "ConstructorBindingConfig"); | ||
assertThat(constructorBindingConfigClass).isEqualTo("package org.springboot.example.upgrade;\n" + | ||
"\n" + | ||
"import org.springframework.boot.context.properties.ConfigurationProperties;\n" + | ||
"\n" + | ||
"@ConfigurationProperties(prefix = \"mail\")\n" + | ||
"public class ConstructorBindingConfig {\n" + | ||
" private String hostName;\n" + | ||
"\n" + | ||
" public ConstructorBindingConfig(String hostName) {\n" + | ||
" this.hostName = hostName;\n" + | ||
" }\n" + | ||
"}" + | ||
"\n"); | ||
} | ||
|
||
private void buildProject() { | ||
executeMavenGoals(getTestDir(), "clean", "verify"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...shell/src/test/resources/testcode/boot-migration-27-30-manual-managed/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
**Features used in the current project** | ||
|
||
* ehcache in pom is mentioned this helps validate our migration to spring 3 where ehcache classifier has to be used to resolve version. | ||
* Uses Constructor binding on classes which will be removed when migrating to Spring 3 | ||
* Uses PagingAndSortingRepo interface where CrudRepo has been removed. | ||
* Uses properties that will be removed/moved on spring 3 migration | ||
* Uses micrometer packages which are moved to a new structure. | ||
|
63 changes: 63 additions & 0 deletions
63
...ions/spring-shell/src/test/resources/testcode/boot-migration-27-30-manual-managed/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>spring-app</module> | ||
</modules> | ||
|
||
<groupId>com.example</groupId> | ||
<artifactId>boot-upgrade-27_30</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>boot-upgrade-27_30</name> | ||
<description>boot-upgrade-27_30</description> | ||
<properties> | ||
<java.version>17</java.version> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spring-snapshot</id> | ||
<url>https://repo.spring.io/snapshot</url> | ||
<releases> | ||
<enabled>false</enabled> | ||
</releases> | ||
</repository> | ||
<repository> | ||
<id>spring-milestone</id> | ||
<url>https://repo.spring.io/milestone</url> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
<repository> | ||
<id>spring-release</id> | ||
<url>https://repo.spring.io/release</url> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.dropwizard.metrics</groupId> | ||
<artifactId>metrics-annotation</artifactId> | ||
<version>4.2.8</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<version>2.7.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jaxb</groupId> | ||
<artifactId>jaxb-runtime</artifactId> | ||
<version>2.3.6</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
</project> |
61 changes: 61 additions & 0 deletions
61
...-shell/src/test/resources/testcode/boot-migration-27-30-manual-managed/spring-app/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2021 - 2022 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>boot-upgrade-27_30</artifactId> | ||
<groupId>com.example</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-app</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The given Java version should be below 17 so we can test the migration from given (something <17) to 17 by the recipe? |
||
<maven.compiler.target>17</maven.compiler.target> | ||
<spring-boot-starter-web.version>2.7.0</spring-boot-starter-web.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.ehcache</groupId> | ||
<artifactId>ehcache</artifactId> | ||
<version>3.0.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>${spring-boot-starter-web.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
12 changes: 12 additions & 0 deletions
12
...d/spring-app/src/main/java/org/springboot/example/upgrade/BootUpgrade2730Application.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.springboot.example.upgrade; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class BootUpgrade2730Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(BootUpgrade2730Application.class, args); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ged/spring-app/src/main/java/org/springboot/example/upgrade/ConstructorBindingConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.springboot.example.upgrade; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.ConstructorBinding; | ||
|
||
@ConfigurationProperties(prefix = "mail") | ||
@ConstructorBinding | ||
public class ConstructorBindingConfig { | ||
private String hostName; | ||
|
||
public ConstructorBindingConfig(String hostName) { | ||
this.hostName = hostName; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the test work if we remove these repositories?
The given application doesn't need them and I think we should remove them here.
If I see this correct and this is the given pom.xml, the recipe should add the repositories and this should be asserted instead?