Skip to content

Commit

Permalink
[JENKINS-69588] Stop installed plugins page jumping on load (jenkinsc…
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored Apr 10, 2024
1 parent 92e137c commit d14b380
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
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;
Expand Down Expand Up @@ -1253,6 +1254,13 @@ public List<PluginWrapper> getPlugins() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
Expand Down
13 changes: 13 additions & 0 deletions test/src/test/java/hudson/PluginManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -81,6 +82,7 @@
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;
Expand Down Expand Up @@ -626,6 +628,17 @@ public void optionalExtensionCanBeFoundAfterDynamicLoadOfVariant() throws Except
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")
Expand Down

0 comments on commit d14b380

Please sign in to comment.