From dddeb6f7214f702d56c0c7be06f80f3c79c57e4d Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Tue, 26 Jan 2021 14:26:07 +0100 Subject: [PATCH] Make plugin manager customizable via system properties --- .../jenkins/jenkinsfile/runner/JenkinsEmbedder.java | 5 +++-- .../jenkins/jenkinsfile/runner/JenkinsLauncher.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/setup/src/main/java/io/jenkins/jenkinsfile/runner/JenkinsEmbedder.java b/setup/src/main/java/io/jenkins/jenkinsfile/runner/JenkinsEmbedder.java index 281ec40c..008d15d6 100644 --- a/setup/src/main/java/io/jenkins/jenkinsfile/runner/JenkinsEmbedder.java +++ b/setup/src/main/java/io/jenkins/jenkinsfile/runner/JenkinsEmbedder.java @@ -350,12 +350,13 @@ public PluginManager getPluginManager() { * Sets the {@link PluginManager} to be used when creating a new {@link Jenkins} instance. * * @param pluginManager - * null to let Jenkins create a new instance of default plugin manager, like it normally does when running as a webapp outside the test. + * {@code null} to let Jenkins create a new instance of default plugin manager, like it normally does when running as a webapp outside the test. */ public void setPluginManager(PluginManager pluginManager) { this.pluginManager = pluginManager; - if (jenkins!=null) + if (jenkins!=null) { throw new IllegalStateException("Too late to override the plugin manager"); + } } public JenkinsEmbedder with(PluginManager pluginManager) { diff --git a/setup/src/main/java/io/jenkins/jenkinsfile/runner/JenkinsLauncher.java b/setup/src/main/java/io/jenkins/jenkinsfile/runner/JenkinsLauncher.java index 74299554..f0df624a 100644 --- a/setup/src/main/java/io/jenkins/jenkinsfile/runner/JenkinsLauncher.java +++ b/setup/src/main/java/io/jenkins/jenkinsfile/runner/JenkinsLauncher.java @@ -1,12 +1,15 @@ package io.jenkins.jenkinsfile.runner; import hudson.ClassicPluginStrategy; +import hudson.PluginManager; import hudson.util.PluginServletFilter; import io.jenkins.jenkinsfile.runner.bootstrap.commands.JenkinsLauncherCommand; import io.jenkins.jenkinsfile.runner.bootstrap.commands.JenkinsLauncherOptions; import io.jenkins.jenkinsfile.runner.util.JenkinsHomeLoader; import jenkins.model.Jenkins; +import jenkins.util.SystemProperties; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import org.eclipse.jetty.security.AbstractLoginService; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.Server; @@ -84,7 +87,15 @@ protected ServletContext createWebServer() throws Exception { localPort = -1; - setPluginManager(new PluginManagerImpl(context.getServletContext(), launcherOptions.pluginsDir)); + String pluginManagerClass = SystemProperties.getString(PluginManager.CUSTOM_PLUGIN_MANAGER); + if (pluginManagerClass == null) { + // Standard plugin manager for JFR + setPluginManager(new PluginManagerImpl(context.getServletContext(), launcherOptions.pluginsDir)); + } else { + LOGGER.log(Level.INFO, "Will use a custom plugin manager {0}. " + + "Note that the --pluginsDir option is not used in this case. ", pluginManagerClass); + setPluginManager(null); + } return context.getServletContext(); }