Skip to content

Commit

Permalink
[FIXED JENKINS-19736] Installing a plugin with optional dependencies …
Browse files Browse the repository at this point in the history
…doesn't upgrade the optional dependencies when needed
  • Loading branch information
stephenc committed Sep 25, 2013
1 parent 0ab7988 commit 01d5fbc
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions core/src/main/java/hudson/model/UpdateSite.java
Expand Up @@ -597,6 +597,12 @@ public final class Plugin extends Entry {
@Exported
public final Map<String,String> dependencies = new HashMap<String,String>();

/**
* Optional dependencies of this plugin.
*/
@Exported
public final Map<String,String> optionalDependencies = new HashMap<String,String>();

@DataBoundConstructor
public Plugin(String sourceId, JSONObject o) {
super(sourceId, o, UpdateSite.this.url);
Expand All @@ -611,9 +617,12 @@ public Plugin(String sourceId, JSONObject o) {
// Make sure there's a name attribute, that that name isn't maven-plugin - we ignore that one -
// and that the optional value isn't true.
if (get(depObj,"name")!=null
&& !get(depObj,"name").equals("maven-plugin")
&& get(depObj,"optional").equals("false")) {
dependencies.put(get(depObj,"name"), get(depObj,"version"));
&& !get(depObj,"name").equals("maven-plugin")) {
if (get(depObj, "optional").equals("false")) {
dependencies.put(get(depObj, "name"), get(depObj, "version"));
} else {
optionalDependencies.put(get(depObj, "name"), get(depObj, "version"));
}
}

}
Expand Down Expand Up @@ -691,6 +700,22 @@ else if (current.isOlderThan(requiredVersion)) {
}
}

for(Map.Entry<String,String> e : optionalDependencies.entrySet()) {
Plugin depPlugin = Jenkins.getInstance().getUpdateCenter().getPlugin(e.getKey());
if (depPlugin == null) {
continue;
}
VersionNumber requiredVersion = new VersionNumber(e.getValue());

PluginWrapper current = depPlugin.getInstalled();

// If the optional dependency plugin is installed, is the version we depend on newer than
// what's installed? If so, upgrade.
if (current != null && current.isOlderThan(requiredVersion)) {
deps.add(depPlugin);
}
}

return deps;
}

Expand Down

0 comments on commit 01d5fbc

Please sign in to comment.