mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 20:12:14 +00:00
PluginManager#whichPlugin does not work for JenkinsRule (#6982)
Co-authored-by: Jesse Glick <jglick@cloudbees.com>
This commit is contained in:
1 parent
26c924b39d
commit
a837997e68
2 files changed
+81
No files matched your search
@@ -79,7 +79,10 @@ import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.security.CodeSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -1324,6 +1327,39 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
|
||||
oneAndOnly = p;
|
||||
}
|
||||
}
|
||||
if (oneAndOnly == null && Main.isUnitTest) {
|
||||
// compare jenkins.security.ClassFilterImpl
|
||||
CodeSource cs = c.getProtectionDomain().getCodeSource();
|
||||
if (cs != null) {
|
||||
URL loc = cs.getLocation();
|
||||
if (loc != null) {
|
||||
if ("file".equals(loc.getProtocol())) {
|
||||
File file;
|
||||
try {
|
||||
file = Paths.get(loc.toURI()).toFile();
|
||||
} catch (InvalidPathException | URISyntaxException e) {
|
||||
LOGGER.log(Level.WARNING, "could not inspect " + loc, e);
|
||||
return null;
|
||||
}
|
||||
if (file.isFile()) { // ignore directories
|
||||
try (JarFile jf = new JarFile(file)) {
|
||||
Manifest mf = jf.getManifest();
|
||||
if (mf != null) {
|
||||
java.util.jar.Attributes attr = mf.getMainAttributes();
|
||||
if (attr.getValue("Plugin-Version") != null) {
|
||||
String shortName = attr.getValue("Short-Name");
|
||||
LOGGER.fine(() -> "found " + shortName + " for " + c);
|
||||
return getPlugin(shortName);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.WARNING, "could not inspect " + loc, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return oneAndOnly;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user