[JENKINS-69588] Stop installed plugins page jumping on load (#9141)

This commit is contained in:
Tim Jacomb authored and GitHub committed 2024-04-10 20:07:40 +02:00
1 parent 92e137cbfa
commit d14b380c78
3 files changed
+22 -1

No files matched your search

@@ -91,6 +91,7 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -1253,6 +1254,13 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
return Collections.unmodifiableList(plugins);
}
@Restricted(NoExternalUse.class) // used by jelly
public List<PluginWrapper> getPluginsSortedByTitle() {
return plugins.stream()
.sorted(Comparator.comparing(PluginWrapper::getDisplayName, String.CASE_INSENSITIVE_ORDER))
.collect(Collectors.toUnmodifiableList());
}
public List<FailedPlugin> getFailedPlugins() {
return failedPlugins;
}
@@ -85,7 +85,7 @@ THE SOFTWARE.
</tr>
</thead>
<tbody>
<j:forEach var="p" items="${app.pluginManager.plugins}">
<j:forEach var="p" items="${app.pluginManager.pluginsSortedByTitle}">
<tr
class="plugin ${p.hasMandatoryDependents()?'has-dependents':''} ${(p.hasMandatoryDependents() and !p.enabled)?'has-dependents-but-disabled':''} ${p.isDeleted()?'deleted':''} ${p.hasImpliedDependents() and p.enabled ? 'possibly-has-implied-dependents' : ''}"
data-plugin-id="${p.shortName}" data-plugin-name="${p.displayName}">
@@ -29,6 +29,7 @@ import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInRelativeOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
@@ -81,6 +82,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.servlet.ServletException;
import jenkins.ClassLoaderReflectionToolkit;
import jenkins.RestartRequiredException;
@@ -626,6 +628,17 @@ public class PluginManagerTest {
assertTrue(ExtensionList.lookup(GlobalConfiguration.class).stream().anyMatch(gc -> "io.jenkins.plugins.MyGlobalConfiguration".equals(gc.getClass().getName())));
}
@Test @Issue("JENKINS-64840")
@WithPlugin({"mandatory-depender-0.0.2.hpi", "dependee-0.0.2.hpi", "depender-0.0.2.hpi"})
public void getPluginsSortedByTitle() throws Exception {
List<String> installedPlugins = r.jenkins.getPluginManager().getPluginsSortedByTitle()
.stream()
.map(PluginWrapper::getDisplayName)
.collect(Collectors.toUnmodifiableList());
assertThat(installedPlugins, containsInRelativeOrder("dependee", "depender", "mandatory-depender"));
}
@Issue("JENKINS-62622")
@Test
@WithPlugin("legacy.hpi")