Skip to content

Commit 2b84997

Browse files
committed
Add recipe to include ban-deprecated-stapler.skip in pom
1 parent 5372734 commit 2b84997

6 files changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@import io.jenkins.tools.pluginmodernizer.core.model.Plugin
2+
@import io.jenkins.tools.pluginmodernizer.core.model.Recipe
3+
@param Plugin plugin
4+
@param Recipe recipe
5+
Hello `${plugin.getName()}` developers! :wave:
6+
7+
This is an automated pull request created by the [Jenkins Plugin Modernizer](https://github.com/jenkins-infra/plugin-modernizer-tool) tool. The tool has applied the following recipes to modernize the plugin:
8+
<details aria-label="Recipe details for ${recipe.getDisplayName()}">
9+
<summary>${recipe.getDisplayName()}</summary>
10+
<p><em>${recipe.getName()}</em></p>
11+
<blockquote>${recipe.getDescription()}</blockquote>
12+
</details>
13+
14+
## Why is this important?
15+
16+
The `javax.servlet` API is deprecated in Jenkins plugins.
17+
18+
Ensure to update the pom.xml with `<ban-deprecated-stapler.skip>false</ban-deprecated-stapler.skip>` to prevent regressions.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ban deprecated javax.servlet classes

plugin-modernizer-core/src/main/resources/META-INF/rewrite/recipes.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,3 +860,13 @@ recipeList:
860860
- io.jenkins.tools.pluginmodernizer.core.recipes.AddProperty:
861861
key: hpi.strictBundledArtifacts
862862
value: true
863+
---
864+
type: specs.openrewrite.org/v1beta/recipe
865+
name: io.jenkins.tools.pluginmodernizer.BanJavaxServletClasses
866+
displayName: Ensure the pom.xml contains the property `ban-deprecated-stapler.skip` set to `false`
867+
description: Ensure the pom.xml contains the property `ban-deprecated-stapler.skip` set to `false`.
868+
tags: ['dependencies', 'migration']
869+
recipeList:
870+
- io.jenkins.tools.pluginmodernizer.core.recipes.AddProperty:
871+
key: ban-deprecated-stapler.skip
872+
value: false

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/DeclarativeRecipesTest.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,6 +4385,66 @@ void shouldSetStrictBundledArtifacts() {
43854385
"""));
43864386
}
43874387

4388+
@Test
4389+
void shouldSetBanJavaxServletProperty() {
4390+
rewriteRun(
4391+
spec -> spec.recipeFromResource(
4392+
"/META-INF/rewrite/recipes.yml", "io.jenkins.tools.pluginmodernizer.BanJavaxServletClasses"),
4393+
// language=xml
4394+
pomXml("""
4395+
<?xml version="1.0" encoding="UTF-8"?>
4396+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4397+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4398+
<modelVersion>4.0.0</modelVersion>
4399+
<parent>
4400+
<groupId>org.jenkins-ci.plugins</groupId>
4401+
<artifactId>plugin</artifactId>
4402+
<version>4.87</version>
4403+
<relativePath />
4404+
</parent>
4405+
<artifactId>plugin</artifactId>
4406+
<version>0.0.1-SNAPSHOT</version>
4407+
<packaging>hpi</packaging>
4408+
<name>Test Plugin</name>
4409+
<properties>
4410+
<jenkins.version>2.452.4</jenkins.version>
4411+
</properties>
4412+
<repositories>
4413+
<repository>
4414+
<id>repo.jenkins-ci.org</id>
4415+
<url>https://repo.jenkins-ci.org/public/</url>
4416+
</repository>
4417+
</repositories>
4418+
</project>
4419+
""", """
4420+
<?xml version="1.0" encoding="UTF-8"?>
4421+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4422+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4423+
<modelVersion>4.0.0</modelVersion>
4424+
<parent>
4425+
<groupId>org.jenkins-ci.plugins</groupId>
4426+
<artifactId>plugin</artifactId>
4427+
<version>4.87</version>
4428+
<relativePath />
4429+
</parent>
4430+
<artifactId>plugin</artifactId>
4431+
<version>0.0.1-SNAPSHOT</version>
4432+
<packaging>hpi</packaging>
4433+
<name>Test Plugin</name>
4434+
<properties>
4435+
<jenkins.version>2.452.4</jenkins.version>
4436+
<ban-deprecated-stapler.skip>false</ban-deprecated-stapler.skip>
4437+
</properties>
4438+
<repositories>
4439+
<repository>
4440+
<id>repo.jenkins-ci.org</id>
4441+
<url>https://repo.jenkins-ci.org/public/</url>
4442+
</repository>
4443+
</repositories>
4444+
</project>
4445+
"""));
4446+
}
4447+
43884448
/**
43894449
* Note this test need to be adapted to fix the .gitignore to ensure entries are merged
43904450
*/

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtilsTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,47 @@ public void testFriendlyPrTitleStrictBunldedArtifacts() {
626626
assertEquals("Strict bundled artifacts", result);
627627
}
628628

629+
@Test
630+
public void testFriendlyPrBodyBanJavaxServletClasses() {
631+
632+
// Mocks
633+
Plugin plugin = mock(Plugin.class);
634+
PluginMetadata metadata = mock(PluginMetadata.class);
635+
Recipe recipe = mock(Recipe.class);
636+
637+
doReturn(metadata).when(plugin).getMetadata();
638+
doReturn("io.jenkins.tools.pluginmodernizer.BanJavaxServletClasses")
639+
.when(recipe)
640+
.getName();
641+
642+
// Test
643+
String result = TemplateUtils.renderPullRequestBody(plugin, recipe);
644+
645+
// Assert
646+
assertTrue(result.contains("Why is this important?"), "Missing 'Why is this important?' section");
647+
assertTrue(result.contains("ban-deprecated-stapler.skip"), "Missing property name");
648+
}
649+
650+
@Test
651+
public void testFriendlyPrTitleBanJavaxServletClasses() {
652+
653+
// Mocks
654+
Plugin plugin = mock(Plugin.class);
655+
PluginMetadata metadata = mock(PluginMetadata.class);
656+
Recipe recipe = mock(Recipe.class);
657+
658+
doReturn(metadata).when(plugin).getMetadata();
659+
doReturn("io.jenkins.tools.pluginmodernizer.BanJavaxServletClasses")
660+
.when(recipe)
661+
.getName();
662+
663+
// Test
664+
String result = TemplateUtils.renderPullRequestTitle(plugin, recipe);
665+
666+
// Assert
667+
assertEquals("Ban deprecated javax.servlet classes", result);
668+
}
669+
629670
@Test
630671
public void testFriendlyPrTitleEnsureRelativePath() {
631672

scripts/validate_metadata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"io.jenkins.tools.pluginmodernizer.EnableCD",
118118
"io.jenkins.tools.pluginmodernizer.AutoMergeWorkflows",
119119
"io.jenkins.tools.pluginmodernizer.StrictBundledArtifacts",
120+
"io.jenkins.tools.pluginmodernizer.BanJavaxServletClasses",
120121
]
121122

122123

0 commit comments

Comments
 (0)