Skip to content

Commit ec56d0b

Browse files
committed
Added upgrade bouncycastle, added test for migration
1 parent 4976063 commit ec56d0b

File tree

4 files changed

+297
-0
lines changed

4 files changed

+297
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# Copyright 2025 the original author or authors.
3+
# <p>
4+
# Licensed under the Moderne Source Available License (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+
# <p>
8+
# https://docs.moderne.io/licensing/moderne-source-available-license
9+
# <p>
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+
---
18+
type: specs.openrewrite.org/v1beta/recipe
19+
name: org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On
20+
displayName: Migrate BouncyCastle to jdk18on
21+
description: >-
22+
This recipe will upgrade BouncyCastle dependencies from -jdk15on to -jdk18on.
23+
tags:
24+
- bouncycastle
25+
recipeList:
26+
- org.openrewrite.java.dependencies.ChangeDependency:
27+
oldGroupId: org.bouncycastle
28+
oldArtifactId: bcprov-jdk15on
29+
newArtifactId: bcprov-jdk18on
30+
newVersion: latest.release
31+
- org.openrewrite.java.dependencies.ChangeDependency:
32+
oldGroupId: org.bouncycastle
33+
oldArtifactId: bcutil-jdk15on
34+
newArtifactId: bcutil-jdk18on
35+
newVersion: latest.release
36+
- org.openrewrite.java.dependencies.ChangeDependency:
37+
oldGroupId: org.bouncycastle
38+
oldArtifactId: bcpkix-jdk15on
39+
newArtifactId: bcpkix-jdk18on
40+
newVersion: latest.release
41+
- org.openrewrite.java.dependencies.ChangeDependency:
42+
oldGroupId: org.bouncycastle
43+
oldArtifactId: bcmail-jdk15on
44+
newArtifactId: bcmail-jdk18on
45+
newVersion: latest.release
46+
- org.openrewrite.java.dependencies.ChangeDependency:
47+
oldGroupId: org.bouncycastle
48+
oldArtifactId: bcjmail-jdk15on
49+
newArtifactId: bcjmail-jdk18on
50+
newVersion: latest.release
51+
- org.openrewrite.java.dependencies.ChangeDependency:
52+
oldGroupId: org.bouncycastle
53+
oldArtifactId: bcpg-jdk15on
54+
newArtifactId: bcpg-jdk18on
55+
newVersion: latest.release
56+
- org.openrewrite.java.dependencies.ChangeDependency:
57+
oldGroupId: org.bouncycastle
58+
oldArtifactId: bctls-jdk15on
59+
newArtifactId: bctls-jdk18on
60+
newVersion: latest.release

src/main/resources/META-INF/rewrite/java-version-8.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ tags:
2626
recipeList:
2727
- org.openrewrite.java.migrate.UpgradeToJava7
2828
- org.openrewrite.java.migrate.MXBeanRule
29+
- org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On
30+
- org.openrewrite.java.migrate.UpgradeJavaVersion:
31+
version: 8
2932
- org.openrewrite.java.RemoveMethodInvocations:
3033
methodPattern: java.lang.Thread destroy()
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (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+
* <p>
8+
* https://docs.moderne.io/licensing/moderne-source-available-license
9+
* <p>
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+
package org.openrewrite.java.migrate;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.params.ParameterizedTest;
20+
import org.junit.jupiter.params.provider.CsvSource;
21+
import org.junit.jupiter.params.provider.ValueSource;
22+
import org.openrewrite.DocumentExample;
23+
import org.openrewrite.config.Environment;
24+
import org.openrewrite.test.RecipeSpec;
25+
import org.openrewrite.test.RewriteTest;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.openrewrite.java.Assertions.*;
29+
import static org.openrewrite.maven.Assertions.pomXml;
30+
31+
class BouncyCastleTest implements RewriteTest {
32+
33+
@Override
34+
public void defaults(RecipeSpec spec) {
35+
spec.recipe(Environment.builder()
36+
.scanRuntimeClasspath("org.openrewrite.java.migrate")
37+
.build()
38+
.activateRecipes("org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On"));
39+
}
40+
41+
@DocumentExample
42+
@Test
43+
void updateBouncyCastle() {
44+
rewriteRun(
45+
mavenProject("project",
46+
//language=xml
47+
pomXml(
48+
"""
49+
<project>
50+
<modelVersion>4.0.0</modelVersion>
51+
52+
<groupId>com.mycompany.app</groupId>
53+
<artifactId>my-app</artifactId>
54+
<version>1</version>
55+
56+
<dependencies>
57+
<dependency>
58+
<groupId>org.bouncycastle</groupId>
59+
<artifactId>bcprov-jdk15on</artifactId>
60+
<version>1.70</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.bouncycastle</groupId>
64+
<artifactId>bcpkix-jdk15on</artifactId>
65+
<version>1.70</version>
66+
</dependency>
67+
</dependencies>
68+
</project>
69+
""",
70+
spec -> spec.after(str -> assertThat(str)
71+
.doesNotContainPattern("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>bcprov-jdk15on<\\/artifactId>\\s+<version>.*<\\/version>")
72+
.doesNotContainPattern("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>bcpkix-jdk15on<\\/artifactId>\\s+<version>.*<\\/version>")
73+
.containsPattern("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>bcprov-jdk18on<\\/artifactId>\\s+<version>.*<\\/version>")
74+
.containsPattern("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>bcpkix-jdk18on<\\/artifactId>\\s+<version>.*<\\/version>")
75+
.actual())
76+
)
77+
)
78+
);
79+
}
80+
81+
82+
@ParameterizedTest
83+
@ValueSource(strings={"bcprov", "bcutil", "bcpkix", "bcmail", "bcjmail", "bcpg", "bctls"})
84+
void testUpdateBouncyCastle(String value) {
85+
rewriteRun(
86+
mavenProject("project",
87+
//language=xml
88+
pomXml(
89+
String.format("""
90+
<project>
91+
<modelVersion>4.0.0</modelVersion>
92+
93+
<groupId>com.mycompany.app</groupId>
94+
<artifactId>my-app</artifactId>
95+
<version>1</version>
96+
97+
<dependencies>
98+
<dependency>
99+
<groupId>org.bouncycastle</groupId>
100+
<artifactId>%s-jdk15on</artifactId>
101+
<version>1.70</version>
102+
</dependency>
103+
</dependencies>
104+
</project>
105+
""", value),
106+
spec -> spec.after(str -> assertThat(str)
107+
.doesNotContainPattern(String.format("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>%s-jdk15on<\\/artifactId>\\s+<version>.*<\\/version>", value))
108+
.containsPattern(String.format("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>%s-jdk18on<\\/artifactId>\\s+<version>.*<\\/version>", value))
109+
.actual())
110+
)
111+
)
112+
);
113+
}
114+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (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+
* <p>
8+
* https://docs.moderne.io/licensing/moderne-source-available-license
9+
* <p>
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+
package org.openrewrite.java.migrate;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.config.Environment;
21+
import org.openrewrite.test.RecipeSpec;
22+
import org.openrewrite.test.RewriteTest;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
import static org.openrewrite.java.Assertions.*;
26+
import static org.openrewrite.java.Assertions.mavenProject;
27+
import static org.openrewrite.java.Assertions.srcMainJava;
28+
import static org.openrewrite.maven.Assertions.pomXml;
29+
30+
class UpgradeToJava8Test implements RewriteTest {
31+
32+
@Override
33+
public void defaults(RecipeSpec spec) {
34+
spec.recipe(Environment.builder()
35+
.scanRuntimeClasspath("org.openrewrite.java.migrate")
36+
.build()
37+
.activateRecipes("org.openrewrite.java.migrate.UpgradeToJava8"))
38+
.allSources(src -> src.markers(javaVersion(8)));
39+
}
40+
41+
@DocumentExample
42+
@Test
43+
void upgradeFromJava7ToJava8() {
44+
rewriteRun(
45+
version(
46+
mavenProject("project",
47+
//language=xml
48+
pomXml(
49+
"""
50+
<project>
51+
<modelVersion>4.0.0</modelVersion>
52+
53+
<groupId>com.mycompany.app</groupId>
54+
<artifactId>my-app</artifactId>
55+
<version>1</version>
56+
57+
<dependencies>
58+
<dependency>
59+
<groupId>org.bouncycastle</groupId>
60+
<artifactId>bcprov-jdk15on</artifactId>
61+
<version>1.70</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.bouncycastle</groupId>
65+
<artifactId>bcpkix-jdk15on</artifactId>
66+
<version>1.70</version>
67+
</dependency>
68+
</dependencies>
69+
</project>
70+
""",
71+
spec -> spec.after(str -> assertThat(str)
72+
.doesNotContainPattern("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>bcprov-jdk15on<\\/artifactId>\\s+<version>.*<\\/version>")
73+
.doesNotContainPattern("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>bcpkix-jdk15on<\\/artifactId>\\s+<version>.*<\\/version>")
74+
.containsPattern("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>bcprov-jdk18on<\\/artifactId>\\s+<version>.*<\\/version>")
75+
.containsPattern("\\h*<groupId>org\\.bouncycastle<\\/groupId>\\s+<artifactId>bcpkix-jdk18on<\\/artifactId>\\s+<version>.*<\\/version>")
76+
.actual())
77+
),
78+
//language=java
79+
srcMainJava(
80+
java(
81+
"""
82+
package com.abc;
83+
84+
interface SomeMBean {
85+
String test();
86+
}
87+
""",
88+
"""
89+
package com.abc;
90+
91+
public interface SomeMBean {
92+
String test();
93+
}
94+
"""
95+
)
96+
),
97+
//language=java
98+
srcMainJava(
99+
java(
100+
"""
101+
package com.abc;
102+
103+
interface SomeMXBean {
104+
String test();
105+
}
106+
""",
107+
"""
108+
package com.abc;
109+
110+
public interface SomeMXBean {
111+
String test();
112+
}
113+
"""
114+
)
115+
)
116+
),
117+
8)
118+
);
119+
}
120+
}

0 commit comments

Comments
 (0)