-
Notifications
You must be signed in to change notification settings - Fork 43
SetupJenkinsfile fails for plugin kryptowire #1611
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
base: main
Are you sure you want to change the base?
Changes from all commits
8eecf43
00db2c2
94482d5
fb61f86
dce83fb
aa33f94
226f6e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -367,4 +367,149 @@ private Recipe createMockRecipe(String name, String description) { | |
| when(recipe.getDescription()).thenReturn(description); | ||
| return recipe; | ||
| } | ||
|
|
||
| @Test | ||
| void testCollectMetadata_WithExistingJdks_ShouldUseMinimumJdk() throws Exception { | ||
| // Setup | ||
| Plugin plugin = mock(Plugin.class); | ||
| io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata metadata = | ||
| mock(io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata.class); | ||
| when(plugin.getMetadata()).thenReturn(metadata); | ||
| when(plugin.getName()).thenReturn("test-plugin"); | ||
|
|
||
| // Plugin metadata has JDK 8 and JDK 11 | ||
| when(metadata.getJdks()) | ||
| .thenReturn(java.util.Set.of( | ||
| io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_8, | ||
| io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_11)); | ||
| when(plugin.hasErrors()).thenReturn(false); | ||
|
|
||
| // Execute - Invoke collectMetadata using reflection | ||
| java.lang.reflect.Method method = | ||
| PluginModernizer.class.getDeclaredMethod("collectMetadata", Plugin.class, boolean.class); | ||
| method.setAccessible(true); | ||
| method.invoke(pluginModernizer, plugin, false); | ||
|
|
||
| // Verify that plugin was set to use JDK 8 (minimum of 8 and 11) | ||
| verify(plugin).withJDK(io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_8); | ||
| verify(plugin).collectMetadata(mavenInvoker); | ||
| verify(plugin).copyMetadata(cacheManager); | ||
| verify(plugin).loadMetadata(cacheManager); | ||
| verify(plugin).enrichMetadata(pluginService); | ||
| } | ||
|
|
||
| @Test | ||
| void testCollectMetadata_WithNoJdks_ShouldUseJdk25() throws Exception { | ||
| // Setup | ||
| Plugin plugin = mock(Plugin.class); | ||
| io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata metadata = | ||
| mock(io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata.class); | ||
| when(plugin.getMetadata()).thenReturn(metadata); | ||
| when(plugin.getName()).thenReturn("test-plugin"); | ||
|
|
||
| // Plugin metadata has no JDKs initially | ||
| when(metadata.getJdks()).thenReturn(java.util.Set.of()); | ||
| when(plugin.hasErrors()).thenReturn(false); | ||
|
|
||
| // Execute | ||
| java.lang.reflect.Method method = | ||
| PluginModernizer.class.getDeclaredMethod("collectMetadata", Plugin.class, boolean.class); | ||
| method.setAccessible(true); | ||
| method.invoke(pluginModernizer, plugin, false); | ||
|
|
||
| // Verify that plugin was set to use JDK 25 (default for initial collection) | ||
| verify(plugin).withJDK(io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_25); | ||
| verify(plugin).collectMetadata(mavenInvoker); | ||
| } | ||
|
Comment on lines
+401
to
+423
|
||
|
|
||
| @Test | ||
| void testCollectMetadata_WithRetry_ShouldUseMinimumJdkAfterJdk8Build() throws Exception { | ||
| // Setup | ||
| Plugin plugin = mock(Plugin.class); | ||
| io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata metadata = | ||
| mock(io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata.class); | ||
| when(plugin.getMetadata()).thenReturn(metadata); | ||
| when(plugin.getName()).thenReturn("test-plugin"); | ||
|
|
||
| // Initially empty, then has JDK 8 after verifyQuickBuild | ||
| // Return empty for first few calls, then JDK 8 for subsequent calls | ||
| java.util.Set<io.jenkins.tools.pluginmodernizer.core.model.JDK> emptySet = java.util.Set.of(); | ||
| java.util.Set<io.jenkins.tools.pluginmodernizer.core.model.JDK> jdk8Set = | ||
| java.util.Set.of(io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_8); | ||
|
|
||
| when(metadata.getJdks()) | ||
| .thenReturn(emptySet) // First check in collectMetadata | ||
| .thenReturn(emptySet) // Second part of isEmpty check | ||
| .thenReturn(jdk8Set) // After verifyQuickBuild, min() call | ||
| .thenReturn(jdk8Set); // Any additional calls | ||
|
|
||
| // hasErrors() is checked after verifyQuickBuild | ||
| when(plugin.hasErrors()).thenReturn(false); | ||
|
|
||
| // Mock the exception on first collectMetadata attempt | ||
| doThrow(new io.jenkins.tools.pluginmodernizer.core.model.ModernizerException("Build failed")) | ||
| .doNothing() | ||
| .when(plugin) | ||
| .collectMetadata(mavenInvoker); | ||
|
|
||
| // Execute - with retry flag | ||
| java.lang.reflect.Method method = | ||
| PluginModernizer.class.getDeclaredMethod("collectMetadata", Plugin.class, boolean.class); | ||
| method.setAccessible(true); | ||
| method.invoke(pluginModernizer, plugin, true); | ||
|
|
||
| // Verify sequence: | ||
| // 1. First try with JDK 25 (empty metadata) | ||
| // 2. Build with JDK 8 to generate classes | ||
| // 3. Then collect metadata with JDK 8 (minimum from metadata) | ||
| verify(plugin).withJDK(io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_25); | ||
| verify(plugin).verifyQuickBuild(mavenInvoker, io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_8); | ||
| verify(plugin).withJDK(io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_8); | ||
| verify(plugin, times(2)).collectMetadata(mavenInvoker); | ||
| } | ||
|
|
||
| @Test | ||
| void testCollectMetadata_WithEmptyJdksInRetry_ShouldUseMavenDefault() throws Exception { | ||
| // Setup | ||
| Plugin plugin = mock(Plugin.class); | ||
| io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata metadata = | ||
| mock(io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata.class); | ||
| when(plugin.getMetadata()).thenReturn(metadata); | ||
| when(plugin.getName()).thenReturn("test-plugin"); | ||
|
|
||
| // getJdks() returns empty throughout (simulating a plugin with no JDK info) | ||
| when(metadata.getJdks()).thenReturn(java.util.Set.of()); | ||
| when(plugin.hasErrors()).thenReturn(false); | ||
|
|
||
| // Execute | ||
| java.lang.reflect.Method method = | ||
| PluginModernizer.class.getDeclaredMethod("collectMetadata", Plugin.class, boolean.class); | ||
| method.setAccessible(true); | ||
| method.invoke(pluginModernizer, plugin, false); | ||
|
|
||
| // Verify that plugin defaults to JDK 25 when no JDK info exists | ||
| verify(plugin).withJDK(io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_25); | ||
| verify(plugin).collectMetadata(mavenInvoker); | ||
| } | ||
|
|
||
| @Test | ||
| void testCollectMetadata_WithNullMetadata_ShouldUseJdk25() throws Exception { | ||
| // Setup | ||
| Plugin plugin = mock(Plugin.class); | ||
| when(plugin.getName()).thenReturn("test-plugin"); | ||
|
|
||
| // Plugin metadata is null (simulating first collection before metadata exists) | ||
| when(plugin.getMetadata()).thenReturn(null); | ||
| when(plugin.hasErrors()).thenReturn(false); | ||
|
|
||
| // Execute | ||
| java.lang.reflect.Method method = | ||
| PluginModernizer.class.getDeclaredMethod("collectMetadata", Plugin.class, boolean.class); | ||
| method.setAccessible(true); | ||
| method.invoke(pluginModernizer, plugin, false); | ||
|
|
||
| // Verify that plugin defaults to JDK 25 when metadata is null | ||
| verify(plugin).withJDK(io.jenkins.tools.pluginmodernizer.core.model.JDK.JAVA_25); | ||
| verify(plugin).collectMetadata(mavenInvoker); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the post-modernization metadata recollection, this uses JDK.min(plugin.getMetadata().getJdks()) which may select an older/unsupported JDK (and also ignores the Jenkins version compatibility logic used elsewhere in verifyPlugin/compilePlugin). This can cause the subsequent metadata recollection build to run under a JDK that cannot verify/compile the modernized plugin. Consider reusing the JDK that successfully verified the plugin (returned by verifyPlugin) or computing a compatible JDK via JDK.min(metadata.getJdks(), metadata.getJenkinsVersion()) plus the same supported() adjustment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot is right about JDK version