提交 a21402b5 编写于 作者: R Romén Rodríguez-Gil 提交者: Oleg Nenashev

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

* [JENKINS-56477] New "isCompatible" method avoiding all plugins w/ warns

Previous version was only checking "isCompatibleWithInstalledVersion", but there were several other cases that had to be checked

* [JENKINS-56477] Added issue annotation to isPluginUpdateCompatible test

* [JENKINS-56477] Factored out getUpdateSite, init method used by 2 tests

Also removed the "sites" list from the init, since it seemed it was not being used, only using the specific site created from the external json

* [JENKINS-56477] Added a new option for plugin selection: "compatible"

Now users can select "All", "Compatible" or "None"

* [JENKINS-56477] checkPluginsWithoutWarnings also unchecks now

Useful if the user first clicks "Select All" and now wants to "Select Compatible" only.

* [JENKINS-56477] Added unit test for "UpdateSite.Plugin.isCompatible"

The UpdateSite class and its internal classes (e.g. Plugin) are a bit tricky to unit-test. Using some stubs to set the necessary context for the test to run

* [JENKINS-56477] "mock-maker-inline" incompatible w/ other tests

Had to remove the unit test checking "pluginUpdateNotCompatible. It needed "mock-maker-inline" config to mock/spy the Plugin class (which is final), but that mockito config caused conflicts with pre-existing tests.

* [JENKINS-56477] Simplifying condition to check the candidate checkbox

* [JENKINS-56477] Method overload with param should not be exported

* [JENKINS-56477] Javadoc for isCompatible(). Overloaded ver. restricted

Also switched the call in table.jelly to the overloaded version of isCompatible, since a "cache" var was available in the context (and was being already used by calls to the internal methods to show the warnings)

* Removed empty line.

Trivial change to force re-execution of pipeline.

* [JENKINS-56477] "isCompatible" set to @Restricted for now

This method is currently only being used by the Jenkins UI, so we are not being exposing it to plugins nor exporting it. If in the future that need emerges, this can be changed
上级 b641aa82
......@@ -1043,6 +1043,24 @@ public class UpdateSite {
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() {
return isCompatible(new PluginManager.MetadataCache());
}
@Restricted(NoExternalUse.class) // table.jelly
public boolean isCompatible(PluginManager.MetadataCache cache) {
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
......
......@@ -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';
}
}
}
......
......@@ -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>,
<a href="javascript:toggleCheckboxes(false);">${%None}</a><br/>
${%UpdatePageDescription}
<j:if test="${!empty(app.updateCenter.jobs)}">
<br/> ${%UpdatePageLegend(rootURL+'/updateCenter/')}
......
......@@ -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>
......
......@@ -45,7 +45,6 @@ import static org.junit.Assert.*;
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;
......@@ -56,7 +55,6 @@ import org.junit.Rule;
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 {
......@@ -153,16 +151,20 @@ public class UpdateSiteTest {
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);
......@@ -187,4 +189,12 @@ public class UpdateSiteTest {
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;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册