mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-07 09:06:03 +00:00
[FIXED JENKINS-24046]
Warn users if the pinning is preventing Jenkins from overwriting older versions with bundled versions.
This commit is contained in:
1 parent
65e2a757f9
commit
19f9b63d74
6 files changed
+138
-17
No files matched your search
@@ -41,6 +41,7 @@ import hudson.security.PermissionScope;
|
||||
import hudson.util.CyclicGraphDetector;
|
||||
import hudson.util.CyclicGraphDetector.CycleDetectedException;
|
||||
import hudson.util.IOException2;
|
||||
import hudson.util.IOUtils;
|
||||
import hudson.util.PersistedList;
|
||||
import hudson.util.Service;
|
||||
import hudson.util.VersionNumber;
|
||||
@@ -75,10 +76,12 @@ import org.kohsuke.stapler.export.Exported;
|
||||
import org.kohsuke.stapler.export.ExportedBean;
|
||||
import org.kohsuke.stapler.interceptor.RequirePOST;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -86,6 +89,7 @@ import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -103,6 +107,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.xml.sax.Attributes;
|
||||
@@ -174,6 +179,11 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
|
||||
*/
|
||||
private final PluginStrategy strategy;
|
||||
|
||||
/**
|
||||
* Manifest of the plugin binaries that are bundled with core.
|
||||
*/
|
||||
private final Map<String,Manifest> bundledPluginManifests = new HashMap<String, Manifest>();
|
||||
|
||||
public PluginManager(ServletContext context, File rootDir) {
|
||||
this.context = context;
|
||||
|
||||
@@ -405,6 +415,13 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
|
||||
|| bundledPlugins.contains(name.replaceAll("\\.jpi",".hpi"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the manifest of a bundled but not-extracted plugin.
|
||||
*/
|
||||
public @CheckForNull Manifest getBundledPluginManifest(String shortName) {
|
||||
return bundledPluginManifests.get(shortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: revisit where/how to expose this. This is an experiment.
|
||||
*/
|
||||
@@ -490,6 +507,34 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
|
||||
// - to make sure the value is not changed after each restart, so we can avoid
|
||||
// unpacking the plugin itself in ClassicPluginStrategy.explode
|
||||
}
|
||||
if (pinFile.exists())
|
||||
parsePinnedBundledPluginManifest(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* When a pin file prevented a bundled plugin from getting extracted, check if the one we currently have
|
||||
* is older than we bundled.
|
||||
*/
|
||||
private void parsePinnedBundledPluginManifest(URL bundledJpi) {
|
||||
try {
|
||||
URLClassLoader cl = new URLClassLoader(new URL[]{bundledJpi});
|
||||
InputStream in=null;
|
||||
try {
|
||||
URL res = cl.findResource(PluginWrapper.MANIFEST_FILENAME);
|
||||
if (res!=null) {
|
||||
in = res.openStream();
|
||||
Manifest manifest = new Manifest(in);
|
||||
String shortName = PluginWrapper.computeShortName(manifest, FilenameUtils.getName(bundledJpi.getPath()));
|
||||
bundledPluginManifests.put(shortName, manifest);
|
||||
}
|
||||
} finally {
|
||||
IOUtils.closeQuietly(in);
|
||||
if (cl instanceof Closeable)
|
||||
((Closeable)cl).close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(WARNING, "Failed to parse manifest of "+bundledJpi, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user