Skip to content

Commit 0fae9b9

Browse files
committed
Add precondition check for Jersey (closes #160)
1 parent 5c941ae commit 0fae9b9

File tree

5 files changed

+301
-122
lines changed

5 files changed

+301
-122
lines changed

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/asciidoctor/RelevantChangeSection.java

Lines changed: 0 additions & 122 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.boot.upgrade_27_30.checks;
18+
19+
import org.jetbrains.annotations.NotNull;
20+
import org.springframework.sbm.build.api.ApplicationModule;
21+
import org.springframework.sbm.engine.context.ProjectContext;
22+
import org.springframework.stereotype.Component;
23+
24+
import java.util.Set;
25+
import java.util.stream.Collectors;
26+
27+
@Component
28+
public class JerseyTemporarilyRemovedFinder implements Sbm30_Finder<Set<ApplicationModule>> {
29+
@Override
30+
public @NotNull Set<ApplicationModule> findMatches(ProjectContext context) {
31+
return context.getApplicationModules().stream()
32+
.filter(m -> m.getBuildFile().hasDeclaredDependencyMatchingRegex("org\\.glassfish\\.jersey.*\\:.*\\:.*"))
33+
.collect(Collectors.toSet());
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.boot.upgrade_27_30.checks;
18+
19+
import lombok.RequiredArgsConstructor;
20+
import org.springframework.sbm.boot.asciidoctor.ChangeSection;
21+
import org.springframework.sbm.boot.asciidoctor.Section;
22+
import org.springframework.sbm.boot.asciidoctor.TodoList;
23+
import org.springframework.sbm.boot.upgrade_27_30.Sbu30_UpgradeSectionBuilder;
24+
import org.springframework.sbm.engine.context.ProjectContext;
25+
import org.springframework.stereotype.Component;
26+
27+
@Component
28+
@RequiredArgsConstructor
29+
public class JerseyTemporarilyRemovedSectionBuilder implements Sbu30_UpgradeSectionBuilder {
30+
31+
private final JerseyTemporarilyRemovedFinder finder;
32+
33+
@Override
34+
public boolean isApplicable(ProjectContext projectContext) {
35+
return !finder.findMatches(projectContext).isEmpty();
36+
}
37+
38+
@Override
39+
public Section build(ProjectContext projectContext) {
40+
return ChangeSection.RelevantChangeSection.builder()
41+
.title("Support for Jersey has been temporarily removed")
42+
.paragraph("Support for Jersey has been temporarily removed as it does not yet support Spring Framework 6.")
43+
.relevanceSection()
44+
.paragraph("""
45+
The scan found one or more dependencies to jersey.
46+
Support for Jersey has been temporarily removed as it does not yet support Spring Framework 6.
47+
Please try again when Jersey is support.
48+
"""
49+
)
50+
.todoSection()
51+
.todoList(
52+
TodoList.builder()
53+
.todo(
54+
TodoList.Todo.builder()
55+
.text("Remove/replace Jersey or wait for a release with Jersey support added.")
56+
.build()
57+
)
58+
.build()
59+
)
60+
.build();
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.boot.upgrade_27_30.checks;
18+
19+
import org.assertj.core.api.Assertions;
20+
import org.intellij.lang.annotations.Language;
21+
import org.junit.jupiter.api.Test;
22+
import org.openrewrite.maven.tree.Scope;
23+
import org.springframework.sbm.build.api.ApplicationModule;
24+
import org.springframework.sbm.engine.context.ProjectContext;
25+
import org.springframework.sbm.project.resource.TestProjectContext;
26+
27+
import java.util.Set;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
public class JerseyTemporarilyRemovedFinderTest {
32+
33+
@Test
34+
void finderShouldFindAnyJerseyDependency() {
35+
String dependencyCoordinates = "org.glassfish.jersey.connectors:jersey-jdk-connector:2.35";
36+
ProjectContext context = TestProjectContext.buildProjectContext()
37+
.withBuildFileHavingDependencies(dependencyCoordinates)
38+
.build();
39+
40+
JerseyTemporarilyRemovedFinder sut = new JerseyTemporarilyRemovedFinder();
41+
Set<ApplicationModule> matches = sut.findMatches(context);
42+
assertThat(matches).isNotEmpty();
43+
assertThat(matches).hasSize(1);
44+
assertThat(matches.iterator().next().getBuildFile().getDeclaredDependencies(Scope.Compile).get(0).getCoordinates()).isEqualTo(dependencyCoordinates);
45+
}
46+
47+
@Test
48+
void finderShouldFindOnlyJerseyDependency() {
49+
50+
@Language("xml")
51+
String parentPomXml =
52+
"""
53+
<?xml version="1.0" encoding="UTF-8"?>
54+
<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">
55+
<modelVersion>4.0.0</modelVersion>
56+
<groupId>com.example</groupId>
57+
<artifactId>parent</artifactId>
58+
<version>0.1.0-SNAPSHOT</version>
59+
<packaging>pom</packaging>
60+
<modules>
61+
<module>module1</module>
62+
<module>module2</module>
63+
</modules>
64+
</project>
65+
""";
66+
67+
68+
@Language("xml")
69+
String module1PomXml =
70+
"""
71+
<?xml version="1.0" encoding="UTF-8"?>
72+
<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">
73+
<modelVersion>4.0.0</modelVersion>
74+
<parent>
75+
<groupId>com.example</groupId>
76+
<artifactId>parent</artifactId>
77+
<version>0.1.0-SNAPSHOT</version>
78+
</parent>
79+
<artifactId>module1</artifactId>
80+
<packaging>jar</packaging>
81+
<dependencies>
82+
<dependency>
83+
<groupId>org.glassfish</groupId>
84+
<artifactId>javax.el</artifactId>
85+
<version>3.0.0</version>
86+
</dependency>
87+
</dependencies>
88+
</project>
89+
""";
90+
91+
@Language("xml")
92+
String module2PomXml =
93+
"""
94+
<?xml version="1.0" encoding="UTF-8"?>
95+
<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">
96+
<modelVersion>4.0.0</modelVersion>
97+
<parent>
98+
<groupId>com.example</groupId>
99+
<version>0.1.0-SNAPSHOT</version>
100+
<artifactId>parent</artifactId>
101+
</parent>
102+
<artifactId>module2</artifactId>
103+
<packaging>jar</packaging>
104+
<dependencies>
105+
<dependency>
106+
<groupId>org.glassfish.jersey.connectors</groupId>
107+
<artifactId>jersey-jdk-connector</artifactId>
108+
<version>2.35</version>
109+
</dependency>
110+
111+
</dependencies>
112+
</project>
113+
""";
114+
115+
String jerseyDependencyCoordinates = "org.glassfish.jersey.connectors:jersey-jdk-connector:2.35";
116+
ProjectContext context = TestProjectContext.buildProjectContext()
117+
.withMavenBuildFileSource("", parentPomXml)
118+
.withMavenBuildFileSource("module1", module1PomXml)
119+
.withMavenBuildFileSource("module2", module2PomXml)
120+
.build();
121+
122+
JerseyTemporarilyRemovedFinder sut = new JerseyTemporarilyRemovedFinder();
123+
Set<ApplicationModule> matches = sut.findMatches(context);
124+
assertThat(context.getApplicationModules().list()).hasSize(3);
125+
assertThat(matches).isNotEmpty();
126+
assertThat(matches).hasSize(1);
127+
assertThat(matches.iterator().next().getBuildFile().getDeclaredDependencies(Scope.Compile).get(0).getCoordinates()).isEqualTo(jerseyDependencyCoordinates);
128+
}
129+
130+
}

0 commit comments

Comments
 (0)