mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-28 12:05:19 +00:00
Revert "[FIXED JENKINS-21486] Merged #2172: enforce plugin dependencies."
This reverts commitfa39668b81, reversing changes made tobe9bc0dba5.
This commit is contained in:
1 parent
4d0143b8d2
commit
70ee2012e9
9 files changed
+12
-201
No files matched your search
@@ -87,12 +87,6 @@ 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)
|
||||
*/
|
||||
private 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.
|
||||
*/
|
||||
@@ -214,10 +208,10 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
if(idx==-1)
|
||||
throw new IllegalArgumentException("Illegal dependency specifier "+s);
|
||||
this.shortName = s.substring(0,idx);
|
||||
String version = s.substring(idx+1);
|
||||
|
||||
this.version = s.substring(idx+1);
|
||||
|
||||
boolean isOptional = false;
|
||||
String[] osgiProperties = version.split("[;]");
|
||||
String[] osgiProperties = s.split(";");
|
||||
for (int i = 1; i < osgiProperties.length; i++) {
|
||||
String osgiProperty = osgiProperties[i].trim();
|
||||
if (osgiProperty.equalsIgnoreCase("resolution:=optional")) {
|
||||
@@ -225,16 +219,11 @@ 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 + ") " + (optional ? "optional" : "");
|
||||
return shortName + " (" + version + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,21 +387,6 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
return "???";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the required Jenkins core version of this plugin.
|
||||
* @return the required Jenkins core version of this plugin.
|
||||
* @since 1.657
|
||||
*/
|
||||
@Exported
|
||||
public @CheckForNull String getRequiredCoreVersion() {
|
||||
String v = manifest.getMainAttributes().getValue("Jenkins-Version");
|
||||
if (v!= null) return v;
|
||||
|
||||
v = manifest.getMainAttributes().getValue("Hudson-Version");
|
||||
if (v!= null) return v;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version number of this plugin
|
||||
*/
|
||||
@@ -539,71 +513,19 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
* thrown if one or several mandatory dependencies doesn't exists.
|
||||
*/
|
||||
/*package*/ void resolvePluginDependencies() throws IOException {
|
||||
if (ENABLE_PLUGIN_DEPENDENCIES_VERSION_CHECK) {
|
||||
String requiredCoreVersion = getRequiredCoreVersion();
|
||||
if (requiredCoreVersion == null) {
|
||||
LOGGER.warning(shortName + " doesn't declare required core version.");
|
||||
} else {
|
||||
if (Jenkins.getVersion().isOlderThan(new VersionNumber(requiredCoreVersion))) {
|
||||
throw new IOException(shortName + " requires a more recent core version (" + requiredCoreVersion + ") than the current (" + Jenkins.getVersion() + ").");
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
PluginWrapper dependency = parent.getPlugin(d.shortName);
|
||||
if (dependency == null) {
|
||||
if (parent.getPlugin(d.shortName) == null)
|
||||
missingDependencies.add(d.toString());
|
||||
} 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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (!missingDependencies.isEmpty())
|
||||
throw new IOException("Dependency "+Util.join(missingDependencies, ", ")+" doesn't exist");
|
||||
|
||||
// add the optional dependencies that exists
|
||||
for (Dependency d : optionalDependencies) {
|
||||
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);
|
||||
if (parent.getPlugin(d.shortName) != null)
|
||||
dependencies.add(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user