Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-56477] Fix to allow selecting compatible-only updates for plugins #3985

Merged
merged 12 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions core/src/main/java/hudson/model/UpdateSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,24 @@ public PluginWrapper getInstalled() {
return pm.getPlugin(name);
}

/**
* Returns true if the plugin and its dependencies are fully compatible with the current installation
* This is set to restricted for now, since it is only being used by Jenkins UI at the moment.
*
* @since TODO
*/
@Restricted(NoExternalUse.class)
public boolean isCompatible() {
romenrg marked this conversation as resolved.
Show resolved Hide resolved
return isCompatible(new PluginManager.MetadataCache());
}

@Restricted(NoExternalUse.class) // table.jelly
public boolean isCompatible(PluginManager.MetadataCache cache) {
romenrg marked this conversation as resolved.
Show resolved Hide resolved
return isCompatibleWithInstalledVersion() && !isForNewerHudson() && !isForNewerJava() &&
isNeededDependenciesCompatibleWithInstalledVersion(cache) &&
!isNeededDependenciesForNewerJenkins(cache) && !isNeededDependenciesForNewerJava();
}

/**
* If the plugin is already installed, and the new version of the plugin has a "compatibleSinceVersion"
* value (i.e., it's only directly compatible with that version or later), this will check to
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/hudson/PluginManager/_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ function checkPluginsWithoutWarnings() {
var inputs = document.getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++) {
var candidate = inputs[i];
if(candidate.type === "checkbox" && candidate.dataset.compatWarning === 'false') {
candidate.checked = true;
if(candidate.type === "checkbox") {
candidate.checked = candidate.dataset.compatWarning === 'false';
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/resources/hudson/PluginManager/index.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ THE SOFTWARE.
<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">
<local:table page="updates" list="${app.updateCenter.updates}" xmlns:local="/hudson/PluginManager">
<div style="margin-top:1em">
${%Select}: <a href="javascript:checkPluginsWithoutWarnings();">${%All}</a>, <a href="javascript:toggleCheckboxes(false);">${%None}</a><br/>
${%Select}: <a href="javascript:toggleCheckboxes(true);">${%All}</a>,
<a href="javascript:checkPluginsWithoutWarnings();">${%Compatible}</a>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather put "Compatible" before "All".

<a href="javascript:toggleCheckboxes(false);">${%None}</a><br/>
${%UpdatePageDescription}
<j:if test="${!empty(app.updateCenter.jobs)}">
<br/> ${%UpdatePageLegend(rootURL+'/updateCenter/')}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/PluginManager/table.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ THE SOFTWARE.
<input type="checkbox" name="plugin.${p.name}.${p.sourceId}"
checked="${installedOk ? 'checked' : null}"
disabled="${installedOk ? 'disabled' : null}" onClick="flip(this);"
data-compat-warning="${!p.isCompatibleWithInstalledVersion()}" />
data-compat-warning="${!p.isCompatible(cache)}" />
</td>
<td class="pane" data="${h.xmlEscape(p.displayName)}" data-id="${h.xmlEscape(p.name+':'+p.version)}">
<div>
Expand Down
30 changes: 20 additions & 10 deletions test/src/test/java/hudson/model/UpdateSiteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import jenkins.security.UpdateSiteWarningsConfiguration;
import jenkins.security.UpdateSiteWarningsMonitor;
import org.apache.commons.io.FileUtils;
import org.eclipse.jetty.server.HttpConnection;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
Expand All @@ -56,7 +55,6 @@
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

public class UpdateSiteTest {

Expand Down Expand Up @@ -153,16 +151,20 @@ public void shutdownWebserver() throws Exception {
assertNotEquals("plugin data is present", Collections.emptyMap(), site.getData().plugins);
}

@Issue("JENKINS-56477")
@Test
public void isPluginUpdateCompatible() throws Exception {
UpdateSite site = getUpdateSite("/plugins/minJavaVersion-update-center.json");
final UpdateSite.Plugin tasksPlugin = site.getPlugin("tasks");
assertNotNull(tasksPlugin);
assertFalse(tasksPlugin.isNeededDependenciesForNewerJava());
assertFalse(tasksPlugin.isForNewerJava());
assertTrue(tasksPlugin.isCompatible());
}

@Issue("JENKINS-55048")
@Test public void minimumJavaVersion() throws Exception {
// TODO: factor out the sites init
PersistedList<UpdateSite> sites = j.jenkins.getUpdateCenter().getSites();
sites.clear();
URL url = new URL(baseUrl, "/plugins/minJavaVersion-update-center.json");
UpdateSite site = new UpdateSite(UpdateCenter.ID_DEFAULT, url.toString());
sites.add(site);
assertEquals(FormValidation.ok(), site.updateDirectly(false).get());
// END TODO
UpdateSite site = getUpdateSite("/plugins/minJavaVersion-update-center.json");

final UpdateSite.Plugin tasksPlugin = site.getPlugin("tasks");
assertNotNull(tasksPlugin);
Expand All @@ -187,4 +189,12 @@ public void shutdownWebserver() throws Exception {
assertTrue("isLegacyDefault should be true when url is http://updates.hudson-labs.org/",new UpdateSite("dummy","http://updates.hudson-labs.org/").isLegacyDefault());
assertFalse("isLegacyDefault should be false with null url",new UpdateSite(null,null).isLegacyDefault());
}


private UpdateSite getUpdateSite(String path) throws Exception {
URL url = new URL(baseUrl, path);
UpdateSite site = new UpdateSite(UpdateCenter.ID_DEFAULT, url.toString());
assertEquals(FormValidation.ok(), site.updateDirectly(false).get());
return site;
}
}