mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-28 20:15:22 +00:00
[JENKINS-21486] Fix plugin dependencies resolution
* Check that dependencies are enabled. A disabled optional dependency will not prevent a plugin from loading. * Check versions of dependencies declared by a plugin before loading it. If any dependency (even optional) is older than what is required, then the plugin isn't loaded. This should prevent use cases where a plugin is loaded but one of its dependencies is too old so that : * its @Extension annotated classes cannot be loaded, causing the full Jenkins to blow up with crapload of exceptions which are tedious to investigate to understand the root cause. * NoSuchMethodError and the likes at runtime even though boot has completed. Version check (for setups where version list is manually crafted but yet works) can be disabled by starting Jenkins with -Dhudson.PluginWrapper.dependenciesVersionCheck.enabled=true Minor fixes done while implementing this change : * Fix version parsing in PluginWrapper.Dependency * Dynamic plugin load didn't check for disabled flag
This commit is contained in:
1 parent
83f51e0782
commit
d57db1b1f2
8 files changed
+172
-11
No files matched your search
@@ -87,6 +87,12 @@ import javax.annotation.Nonnull;
|
||||
*/
|
||||
@ExportedBean
|
||||
public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
/**
|
||||
* A plugin won't be loaded unless his declared dependencies are present and match the required minimal version.
|
||||
* This can be set to false to disable the version check (legacy behaviour)
|
||||
*/
|
||||
public static final boolean ENABLE_PLUGIN_DEPENDENCIES_VERSION_CHECK = Boolean.parseBoolean(System.getProperty(PluginWrapper.class.getName()+"." + "dependenciesVersionCheck.enabled", "true"));
|
||||
|
||||
/**
|
||||
* {@link PluginManager} to which this belongs to.
|
||||
*/
|
||||
@@ -217,10 +223,10 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
if(idx==-1)
|
||||
throw new IllegalArgumentException("Illegal dependency specifier "+s);
|
||||
this.shortName = s.substring(0,idx);
|
||||
this.version = s.substring(idx+1);
|
||||
|
||||
String version = s.substring(idx+1);
|
||||
|
||||
boolean isOptional = false;
|
||||
String[] osgiProperties = s.split(";");
|
||||
String[] osgiProperties = version.split("[;]");
|
||||
for (int i = 1; i < osgiProperties.length; i++) {
|
||||
String osgiProperty = osgiProperties[i].trim();
|
||||
if (osgiProperty.equalsIgnoreCase("resolution:=optional")) {
|
||||
@@ -228,11 +234,16 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
}
|
||||
}
|
||||
this.optional = isOptional;
|
||||
if (isOptional) {
|
||||
this.version = osgiProperties[0];
|
||||
} else {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return shortName + " (" + version + ")";
|
||||
return shortName + " (" + version + ") " + (optional ? "optional" : "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,18 +535,60 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
*/
|
||||
/*package*/ void resolvePluginDependencies() throws IOException {
|
||||
List<String> missingDependencies = new ArrayList<String>();
|
||||
List<String> obsoleteDependencies = new ArrayList<String>();
|
||||
List<String> disabledDependencies = new ArrayList<String>();
|
||||
// make sure dependencies exist
|
||||
for (Dependency d : dependencies) {
|
||||
if (parent.getPlugin(d.shortName) == null)
|
||||
PluginWrapper dependency = parent.getPlugin(d.shortName);
|
||||
if (dependency == null) {
|
||||
missingDependencies.add(d.toString());
|
||||
}
|
||||
if (!missingDependencies.isEmpty())
|
||||
throw new IOException("Dependency "+Util.join(missingDependencies, ", ")+" doesn't exist");
|
||||
} else {
|
||||
if (dependency.isActive()) {
|
||||
if (ENABLE_PLUGIN_DEPENDENCIES_VERSION_CHECK && dependency.getVersionNumber().isOlderThan(new VersionNumber(d.version))) {
|
||||
obsoleteDependencies.add(dependency.getShortName() + "(" + dependency.getVersion() + " < " + d.version + ")");
|
||||
}
|
||||
} else {
|
||||
disabledDependencies.add(d.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// add the optional dependencies that exists
|
||||
for (Dependency d : optionalDependencies) {
|
||||
if (parent.getPlugin(d.shortName) != null)
|
||||
dependencies.add(d);
|
||||
PluginWrapper dependency = parent.getPlugin(d.shortName);
|
||||
if (dependency != null && dependency.isActive()) {
|
||||
if (ENABLE_PLUGIN_DEPENDENCIES_VERSION_CHECK && dependency.getVersionNumber().isOlderThan(new VersionNumber(d.version))) {
|
||||
obsoleteDependencies.add(dependency.getShortName() + "(" + dependency.getVersion() + " < " + d.version + ")");
|
||||
} else {
|
||||
dependencies.add(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
StringBuilder messageBuilder = new StringBuilder();
|
||||
if (!missingDependencies.isEmpty()) {
|
||||
boolean plural = missingDependencies.size() > 1;
|
||||
messageBuilder.append(plural ? "Dependencies " : "Dependency ")
|
||||
.append(Util.join(missingDependencies, ", "))
|
||||
.append(" ").append(plural ? "don't" : "doesn't")
|
||||
.append(" exist. ");
|
||||
}
|
||||
if (!disabledDependencies.isEmpty()) {
|
||||
boolean plural = disabledDependencies.size() > 1;
|
||||
messageBuilder.append(plural ? "Dependencies " : "Dependency ")
|
||||
.append(Util.join(missingDependencies, ", "))
|
||||
.append(" ").append(plural ? "are" : "is")
|
||||
.append(" disabled. ");
|
||||
}
|
||||
if (!obsoleteDependencies.isEmpty()) {
|
||||
boolean plural = obsoleteDependencies.size() > 1;
|
||||
messageBuilder.append(plural ? "Dependencies " : "Dependency ")
|
||||
.append(Util.join(obsoleteDependencies, ", "))
|
||||
.append(" ").append(plural ? "are" : "is")
|
||||
.append(" older than required.");
|
||||
}
|
||||
String message = messageBuilder.toString();
|
||||
if (!message.isEmpty()) {
|
||||
throw new IOException(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user