Skip to content

Commit

Permalink
Lifecycle.supportsDynamicLoad (#9013)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Mar 10, 2024
1 parent 2dca2b1 commit 46b0db7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/hudson/PluginManager.java
Expand Up @@ -41,6 +41,7 @@
import hudson.init.InitMilestone;
import hudson.init.InitStrategy;
import hudson.init.InitializerFinder;
import hudson.lifecycle.Lifecycle;
import hudson.model.AbstractItem;
import hudson.model.AbstractModelObject;
import hudson.model.AdministrativeMonitor;
Expand Down Expand Up @@ -924,6 +925,9 @@ public void dynamicLoad(File arc, boolean removeExisting, @CheckForNull List<Plu
throw new RestartRequiredException(Messages._PluginManager_PluginIsAlreadyInstalled_RestartRequired(sn));
}
}
if (!Lifecycle.get().supportsDynamicLoad()) {
throw new RestartRequiredException(Messages._PluginManager_LifecycleDoesNotSupportDynamicLoad_RestartRequired());
}
if (p == null) {
p = strategy.createPluginWrapper(arc);
}
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/hudson/lifecycle/Lifecycle.java
Expand Up @@ -28,6 +28,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.ExtensionPoint;
import hudson.Functions;
import hudson.PluginManager;
import hudson.Util;
import hudson.init.InitMilestone;
import hudson.init.Initializer;
Expand All @@ -39,10 +40,12 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.RestartRequiredException;
import jenkins.model.Jenkins;
import jenkins.util.SystemProperties;
import org.apache.commons.io.FileUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
Expand Down Expand Up @@ -310,6 +313,17 @@ public void onStatusUpdate(String status) {
LOGGER.log(Level.INFO, status);
}

/**
* Whether {@link PluginManager#dynamicLoad(File)} should be supported at all.
* If not, {@link RestartRequiredException} will always be thrown.
* @return true by default
* @since TODO
*/
@Restricted(Beta.class)
public boolean supportsDynamicLoad() {
return true;
}

@Restricted(NoExternalUse.class)
public static final class PlaceholderLifecycle extends ExitLifecycle {

Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/hudson/Messages.properties
Expand Up @@ -37,6 +37,7 @@ FilePath.validateRelativePath.notDirectory=‘{0}’ is not a directory
FilePath.validateRelativePath.noSuchFile=No such file: ‘{0}’
FilePath.validateRelativePath.noSuchDirectory=No such directory: ‘{0}’

PluginManager.LifecycleDoesNotSupportDynamicLoad.RestartRequired=This Jenkins lifecycle does not support dynamic loading of plugins. Jenkins needs to be restarted for the update to take effect.
PluginManager.PluginDoesntSupportDynamicLoad.RestartRequired={0} plugin doesn’t support dynamic loading. Jenkins needs to be restarted for the update to take effect.
PluginManager.PluginIsAlreadyInstalled.RestartRequired={0} plugin is already installed. Jenkins needs to be restarted for the update to take effect.
Util.millisecond={0} ms
Expand Down

0 comments on commit 46b0db7

Please sign in to comment.