Skip to content

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
merged 60 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
60 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
2f9c293
Merge branch 'spring-projects-experimental:main' into main
ashakirin Sep 5, 2022
216fcb4
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal Sep 6, 2022
6117071
Added test for explicit dependencies
ashakirin Sep 6, 2022
0f1b00d
Passing test
sanagaraj-pivotal Sep 6, 2022
82647c0
Passing test little bit better
sanagaraj-pivotal Sep 6, 2022
5b67aba
Improvement to calculate dependency map only once
ashakirin Sep 7, 2022
9328e77
Removed static identifier for dependnecy map
ashakirin Sep 7, 2022
8b2e5d0
formatting updates
ashakirin Sep 7, 2022
64cb4d0
Return foreach instead collector for readability
ashakirin Sep 7, 2022
2397446
Failing test
sanagaraj-pivotal Sep 7, 2022
835c089
Fixed non springboot dependecy test
ashakirin Sep 7, 2022
625d7eb
Ping old SpringBoot version test
ashakirin Sep 7, 2022
65915f2
Improved old SpringBoot version test
ashakirin Sep 7, 2022
62cb6ca
Passing test
sanagaraj-pivotal Sep 7, 2022
fccc3e2
Clean up
sanagaraj-pivotal Sep 7, 2022
1c63690
Ping SpringBoot parent test
ashakirin Sep 7, 2022
131738f
Passing test
sanagaraj-pivotal Sep 7, 2022
89baa3b
PING... Failing test
sanagaraj-pivotal Sep 7, 2022
268f679
Fixed dependency import test
ashakirin Sep 7, 2022
709b888
Ping test for import dependencies condition
ashakirin Sep 7, 2022
7df90f3
Passing test
sanagaraj-pivotal Sep 7, 2022
0ff11a3
Clean up
sanagaraj-pivotal Sep 7, 2022
38703e7
Failing test case. ping ..
sanagaraj-pivotal Sep 7, 2022
6b8e90b
Ping test for import dependencies condition, still failed
ashakirin Sep 7, 2022
6103628
Ping SpringBoot Parent test
ashakirin Sep 8, 2022
6715a2e
Passing test
sanagaraj-pivotal Sep 8, 2022
afc9527
Parameterising test
sanagaraj-pivotal Sep 8, 2022
e264536
tests pass
sanagaraj-pivotal Sep 8, 2022
0a15685
Added test for Spring Project
ashakirin Sep 8, 2022
83cf9a9
Ping test for dependencyManagement
ashakirin Sep 8, 2022
d174d8e
Passing test
sanagaraj-pivotal Sep 8, 2022
975fb77
Failed test.. Ping..
sanagaraj-pivotal Sep 8, 2022
b113ab8
Fixed version property test
ashakirin Sep 8, 2022
b134ec8
Ping test for managed dependnecies condition
ashakirin Sep 8, 2022
0a20ae2
Passed test
sanagaraj-pivotal Sep 8, 2022
44fcf95
Passed integration teset
sanagaraj-pivotal Sep 8, 2022
e820dc1
Merge branch 'spring-projects-experimental:main' into main
ashakirin Sep 12, 2022
5578ff9
Updated SpringBoot 3.0 migration configuration; manually managed inte…
ashakirin Sep 12, 2022
50b05fe
Merge branch 'main' into 384_migrate_explicit_depependencies
ashakirin Sep 12, 2022
1f33f9d
Added repositories to download SrpingBoot dependencies
ashakirin Sep 12, 2022
bd5661a
Fixed ExplicitVersionTest
ashakirin Sep 12, 2022
78bc776
Removed temporary test file
ashakirin Sep 12, 2022
3b8f797
Added parent pom into parsing
ashakirin Sep 13, 2022
e66a97e
Removed unnecessary pom download
ashakirin Sep 13, 2022
4f499e8
Variable name refactoring
ashakirin Sep 14, 2022
bdcf2eb
Fixing PR comments for manually managed dependencies
ashakirin Sep 15, 2022
839bca7
Fixing failing tests
sanagaraj-pivotal Sep 15, 2022
02de4f1
Fixed recipes and integration tests
ashakirin Sep 15, 2022
4a04426
Formatting
ashakirin Sep 15, 2022
911ec76
Merge branch 'spring-projects-experimental:main' into main
sanagaraj-pivotal Sep 15, 2022
88c99b9
Merge branch 'main' into 384_migrate_explicit_depependencies
sanagaraj-pivotal Sep 15, 2022
88d8636
Fixing failing tests
sanagaraj-pivotal Sep 15, 2022
91e3e7a
Merge branch 'main' into 384_migrate_explicit_depependencies
fabapp2 Sep 18, 2022
20cd303
Merge branch 'main' into 384_migrate_explicit_depependencies
fabapp2 Sep 18, 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
@@ -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");
}
}
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.

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>
Copy link
Contributor

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?

<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>
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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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?
Actually, do we need these at all? Not sure, but I'd think these properties are set with the parent's java.version?

<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>
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);
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public interface BuildFile extends ProjectResource {

List<Dependency> getDependencyManagement();

List<Dependency> getRequestedManagedDependencies();

void addToDependencyManagement(Dependency dependency);

void addToDependencyManagementInner(Dependency dependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,19 @@ public List<Dependency> getDependencyManagement() {
.collect(Collectors.toList());
}

@Override
public List<Dependency> getRequestedManagedDependencies() {
return this.getPom().getPom().getRequested()
.getDependencyManagement()
.stream()
.map(k -> Dependency.builder()
.artifactId(k.getArtifactId())
.version(k.getVersion())
.groupId(k.getGroupId())
.build())
.collect(Collectors.toList());
}

private Dependency getDependency(ResolvedManagedDependency d) {
return Dependency.builder()
.groupId(d.getGroupId())
Expand Down
Loading