Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-33308 - automatically install previously bundled dependencies
for plugins that depend on old Jenkins versions
  • Loading branch information
kzantow committed Mar 15, 2016
1 parent 3edb9fd commit 5e8bb98
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
13 changes: 13 additions & 0 deletions core/src/main/java/hudson/ClassicPluginStrategy.java
Expand Up @@ -259,6 +259,19 @@ private static Manifest loadLinkedManifest(File archive) throws IOException {
return new PluginWrapper(pluginManager, archive, manifest, baseResourceURL,
createClassLoader(paths, dependencyLoader, atts), disableFile, dependencies, optionalDependencies);
}

/**
* Returns all the bundled plugin dependencies for a particular Jenkins version
*/
public static List<PluginWrapper.Dependency> getPreviouslyBundledDependencies(String jenkinsVersion) {
List<PluginWrapper.Dependency> out = new ArrayList<>();
for (DetachedPlugin detached : DETACHED_LIST) {
if (jenkinsVersion == null || jenkinsVersion.equals("null") || new VersionNumber(jenkinsVersion).compareTo(detached.splitWhen) <= 0) {
out.add(new PluginWrapper.Dependency(detached.shortName + ':' + detached.requireVersion));
}
}
return out;
}

@Deprecated
protected ClassLoader createClassLoader(List<File> paths, ClassLoader parent) throws IOException {
Expand Down
18 changes: 17 additions & 1 deletion core/src/main/java/hudson/PluginManager.java
Expand Up @@ -1140,7 +1140,9 @@ private List<Future<UpdateCenter.UpdateCenterJob>> install(@Nonnull Collection<S
String pluginName = n.substring(0, index);
String siteName = n.substring(index + 1);
UpdateSite.Plugin plugin = getPlugin(pluginName, siteName);
// TODO: Someone that understands what the following logic is about, please add a comment.
// There could be cases like:
// 'plugin.ambiguous.updatesite' where both
// 'plugin' @ 'ambigiuous.updatesite' and 'plugin.ambiguous' @ 'updatesite' resolve to valid plugins
if (plugin != null) {
if (p != null) {
throw new Failure("Ambiguous plugin: " + n);
Expand All @@ -1150,9 +1152,23 @@ private List<Future<UpdateCenter.UpdateCenterJob>> install(@Nonnull Collection<S
index = n.indexOf('.', index + 1);
}
}

if (p == null) {
throw new Failure("No such plugin: " + n);
}

// JENKINS-33308 - automatically install implied/previously bundled dependencies for older plugins that may need them
for(PluginWrapper.Dependency previouslyBundledDependency : ClassicPluginStrategy.getPreviouslyBundledDependencies(p.requiredCore)) {
// if they aren't already installed, note the dependencies show 'need restart' messages if installed multiple times
// but it can't be prevented here
if(getPlugin(previouslyBundledDependency.shortName) == null) {
// as these are basically jenkins core, these should always be installed from the default update center
UpdateSite.Plugin previouslyBundledPlugin = getPlugin(previouslyBundledDependency.shortName, UpdateCenter.ID_DEFAULT);
Future<UpdateCenter.UpdateCenterJob> jobFuture = previouslyBundledPlugin.deploy(dynamicLoad, correlationId);
installJobs.add(jobFuture);
}
}

Future<UpdateCenter.UpdateCenterJob> jobFuture = p.deploy(dynamicLoad, correlationId);
installJobs.add(jobFuture);
}
Expand Down

0 comments on commit 5e8bb98

Please sign in to comment.