Skip to content

Commit a69f9a3

Browse files
committed
Ensure preconditions for API plugins
1 parent 9901384 commit a69f9a3

6 files changed

Lines changed: 120 additions & 6 deletions

File tree

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
target/
22
!.mvn/wrapper/maven-wrapper.jar
3-
!**/src/main/**/target/
4-
!**/src/test/**/target/
53

64
### Log file ###
75
logs/

plugin-modernizer-cli/src/test/java/io/jenkins/tools/pluginmodernizer/cli/CommandLineITCase.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ private static Stream<Arguments> testsPlugins() {
6666
setPluginName("empty");
6767
setJenkinsVersion("2.440.3");
6868
}
69+
70+
{
71+
setPluginName("replace-by-api-plugins");
72+
setJenkinsVersion("2.452.4");
73+
}
6974
}));
7075
}
7176

@@ -227,7 +232,7 @@ public void testBuildMetadata(PluginMetadata expectedMetadata, WireMockRuntimeIn
227232
.anyMatch(line -> line.matches("(.*)GitHub owner: fake-owner(.*)"))),
228233
() -> assertTrue(Files.readAllLines(outputPath.resolve("stdout.txt")).stream()
229234
.anyMatch(line ->
230-
line.matches(".*Metadata was fetched for plugin empty and is available at.*"))));
235+
line.matches(".*Metadata was fetched for plugin (.*) and is available at.*"))));
231236

232237
// Assert some metadata
233238
PluginMetadata metadata = JsonUtils.fromJson(
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.jenkins-ci.plugins</groupId>
7+
<artifactId>plugin</artifactId>
8+
<version>4.88</version>
9+
<relativePath />
10+
</parent>
11+
12+
<groupId>io.jenkins.plugins</groupId>
13+
<artifactId>replace-by-api-plugin</artifactId>
14+
<version>${revision}${changelist}</version>
15+
<packaging>hpi</packaging>
16+
17+
<name>TODO Plugin</name>
18+
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
19+
<licenses>
20+
<license>
21+
<name>MIT License</name>
22+
<url>https://opensource.org/license/mit/</url>
23+
</license>
24+
</licenses>
25+
<scm child.scm.connection.inherit.append.path="false" child.scm.developerConnection.inherit.append.path="false" child.scm.url.inherit.append.path="false">
26+
<connection>scm:git:https://github.com/${gitHubRepo}</connection>
27+
<developerConnection>scm:git:https://github.com/${gitHubRepo}</developerConnection>
28+
<tag>${scmTag}</tag>
29+
<url>https://github.com/${gitHubRepo}</url>
30+
</scm>
31+
32+
<properties>
33+
<revision>1.0</revision>
34+
<changelist>-SNAPSHOT</changelist>
35+
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
36+
<jenkins.baseline>2.452</jenkins.baseline>
37+
<jenkins.version>${jenkins.baseline}.4</jenkins.version>
38+
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
39+
40+
<spotless.check.skip>false</spotless.check.skip>
41+
</properties>
42+
43+
<dependencyManagement>
44+
<dependencies>
45+
<dependency>
46+
<groupId>io.jenkins.tools.bom</groupId>
47+
<artifactId>bom-${jenkins.baseline}.x</artifactId>
48+
<version>3814.v9563d972079a_</version>
49+
<type>pom</type>
50+
<scope>import</scope>
51+
</dependency>
52+
</dependencies>
53+
</dependencyManagement>
54+
55+
<!-- This should be replaced -->
56+
<dependencies>
57+
<dependency>
58+
<groupId>com.google.code.gson</groupId>
59+
<artifactId>gson</artifactId>
60+
<version>2.10.1</version>
61+
</dependency>
62+
63+
<!-- This should not be replaced -->
64+
<dependency>
65+
<groupId>org.apache.commons</groupId>
66+
<artifactId>commons-compress</artifactId>
67+
<version>1.26.1</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.json</groupId>
71+
<artifactId>json</artifactId>
72+
<version>20240303</version>
73+
</dependency>
74+
</dependencies>
75+
76+
<repositories>
77+
<repository>
78+
<id>repo.jenkins-ci.org</id>
79+
<url>https://repo.jenkins-ci.org/public/</url>
80+
</repository>
81+
</repositories>
82+
<pluginRepositories>
83+
<pluginRepository>
84+
<id>repo.jenkins-ci.org</id>
85+
<url>https://repo.jenkins-ci.org/public/</url>
86+
</pluginRepository>
87+
</pluginRepositories>
88+
</project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?jelly escape-by-default='true'?>
2+
<div>
3+
TODO
4+
</div>

plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Recipe.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public class Recipe {
1616
@JsonIgnore
1717
private Object recipeList; // Use Object to avoid mapping complex nested structures.
1818

19+
@JsonIgnore
20+
private Object preconditions; // Use Object to avoid mapping complex nested structures.
21+
1922
public String getName() {
2023
return name;
2124
}
@@ -63,4 +66,8 @@ public Object getRecipeList() {
6366
public void setRecipeList(Object recipeList) {
6467
this.recipeList = recipeList;
6568
}
69+
70+
public Object getPreconditions() {
71+
return preconditions;
72+
}
6673
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,15 @@ name: io.jenkins.tools.pluginmodernizer.UseJsonApiPlugin
107107
displayName: Use JSON API plugin instead of direct dependency
108108
description: Use JSON API plugin instead of direct dependency
109109
tags: ['developer']
110+
preconditions:
111+
- org.openrewrite.maven.FindDependency:
112+
groupId: org.jenkins-ci.main
113+
artifactId: jenkins-core
114+
version: ">=2.452.4"
110115
recipeList:
111116
- org.openrewrite.jenkins.ReplaceLibrariesWithApiPlugin:
112117
pluginGroupId: io.jenkins.plugins
113118
pluginArtifactId: json-api
114-
# TODO: version from bom and filtered here ? or managed by renovate ?
115119
pluginVersion: 20240303-41.v94e11e6de726
116120
replaces:
117121
- groupId: org.json
@@ -122,11 +126,15 @@ name: io.jenkins.tools.pluginmodernizer.UseGsonApiPlugin
122126
displayName: Use GSON API plugin instead of direct dependency
123127
description: Use GSON API plugin instead of direct dependency
124128
tags: ['developer']
129+
preconditions:
130+
- org.openrewrite.maven.FindDependency:
131+
groupId: org.jenkins-ci.main
132+
artifactId: jenkins-core
133+
version: ">=2.452.4"
125134
recipeList:
126135
- org.openrewrite.jenkins.ReplaceLibrariesWithApiPlugin:
127136
pluginGroupId: io.jenkins.plugins
128137
pluginArtifactId: gson-api
129-
# TODO: version from bom and filtered here ? or managed by renovate ?
130138
pluginVersion: 2.11.0-85.v1f4e87273c33
131139
replaces:
132140
- groupId: com.google.code.gson
@@ -137,11 +145,15 @@ name: io.jenkins.tools.pluginmodernizer.UseCompressApiPlugin
137145
displayName: Use Compress API plugin instead of direct dependency
138146
description: Use Compress API plugin instead of direct dependency
139147
tags: ['developer']
148+
preconditions:
149+
- org.openrewrite.maven.FindDependency:
150+
groupId: org.jenkins-ci.main
151+
artifactId: jenkins-core
152+
version: ">=2.489"
140153
recipeList:
141154
- org.openrewrite.jenkins.ReplaceLibrariesWithApiPlugin:
142155
pluginGroupId: io.jenkins.plugins
143156
pluginArtifactId: commons-compress-api
144-
# TODO: version from bom and filtered here ? or managed by renovate ?
145157
pluginVersion: 1.26.1-2
146158
replaces:
147159
- groupId: org.apache.commons

0 commit comments

Comments
 (0)