Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-34494 - enable required plugins during plugin installs
  • Loading branch information
kzantow committed Apr 29, 2016
1 parent caef648 commit 247abf7
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
37 changes: 36 additions & 1 deletion core/src/main/java/hudson/model/UpdateCenter.java
Expand Up @@ -1404,7 +1404,42 @@ public String[] getStatuses() {


}


/**
* Enables a required plugin, provides feedback in the update center
*/
public class EnableJob extends UpdateCenterJob {
private final Plugin plugin;

public EnableJob(UpdateSite site, @Nonnull Plugin plugin) {
super(site);
this.plugin = plugin;
}

public Plugin getPlugin() {
return plugin;
}

@Override
public void run() {
try {
plugin.getInstalled().enable();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to enable " + plugin.getDisplayName(), e);
error = e;
}
}
}

/**
* A no-op, e.g. this plugin is already installed
*/
public class NoOpJob extends EnableJob {
public NoOpJob(UpdateSite site, @Nonnull Plugin plugin) {
super(site, plugin);
}
}

/**
* Base class for a job that downloads a file from the Jenkins project.
*/
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/hudson/model/UpdateSite.java
Expand Up @@ -731,6 +731,10 @@ public List<Plugin> getNeededDependencies() {
else if (current.isOlderThan(requiredVersion)) {
deps.add(depPlugin);
}
// JENKINS-34494 - or if the plugin is disabled, this will allow us to enable it
else if (!current.isEnabled()) {
deps.add(depPlugin);
}
}

for(Map.Entry<String,String> e : optionalDependencies.entrySet()) {
Expand Down Expand Up @@ -853,6 +857,18 @@ public Future<UpdateCenterJob> deploy(boolean dynamicLoad, @CheckForNull UUID co
LOGGER.log(Level.WARNING, "Dependent install of " + dep.name + " for plugin " + name + " already added, skipping");
}
}
PluginWrapper pw = getInstalled();
if(pw != null) { // JENKINS-34494 - check for this plugin being disabled
Future<UpdateCenterJob> enableJob = null;
if(!pw.isEnabled()) {
UpdateCenter.EnableJob job = uc.new EnableJob(UpdateSite.this, this);
job.setCorrelationId(correlationId);
enableJob = uc.addJob(job);
}
if(pw.getVersionNumber().equals(new VersionNumber(version))) {
return enableJob != null ? enableJob : uc.addJob(uc.new NoOpJob(UpdateSite.this, this));
}
}
UpdateCenter.InstallationJob job = uc.new InstallationJob(this, UpdateSite.this, Jenkins.getAuthentication(), dynamicLoad);
job.setCorrelationId(correlationId);
return uc.addJob(job);
Expand Down
@@ -0,0 +1,33 @@
<!--
The MIT License
Copyright (c) 2016, CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<tr id="row${it.id}">
<td style="vertical-align: top; padding-right:1em">${it.plugin.displayName}</td>
<td style="vertical-align:middle">
<l:icon class="icon-yellow icon-md"/> ${%Enabled}
</td>
</tr>
</j:jelly>
@@ -0,0 +1,33 @@
<!--
The MIT License
Copyright (c) 2016, CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<tr id="row${it.id}">
<td style="vertical-align: top; padding-right:1em">${it.plugin.displayName}</td>
<td style="vertical-align:middle">
<l:icon class="icon-yellow icon-md"/> ${%Already Installed}
</td>
</tr>
</j:jelly>

0 comments on commit 247abf7

Please sign in to comment.