Skip to content

Commit

Permalink
feat: sort the YAML output by name and version (#576)
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Dagenais <odagenai@contractor.ciena.com>
  • Loading branch information
olivierdagenais and olivierdagenais authored Jul 10, 2023
1 parent f290198 commit fff28c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.List;
import java.util.stream.Collectors;

import static java.util.Comparator.comparing;

public class YamlPluginOutputConverter implements PluginOutputConverter {
@Override
public String convert(List<Plugin> plugins) {
Expand All @@ -28,6 +30,7 @@ public String convert(List<Plugin> plugins) {

private Plugins mapToOutputFormat(List<Plugin> plugins) {
List<PluginInfo> convertedPlugins = plugins.stream()
.sorted(comparing(Plugin::getName).thenComparing(Plugin::getVersion))
.map(this::toPluginHolder)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,30 +363,31 @@ public void listPluginsOutputYamlTest() throws Exception {
"plugin2 2.0\n\n");

assertThat(stdOutput).isEqualTo("plugins:\n" +
"- artifactId: \"installed2\"\n" +
"- artifactId: \"bundled1\"\n" +
" source:\n" +
" version: \"2.0\"\n" +
" version: \"1.0\"\n" +
"- artifactId: \"bundled2\"\n" +
" source:\n" +
" version: \"2.0\"\n" +
"- artifactId: \"plugin1\"\n" +
" source:\n" +
" version: \"1.0\"\n" +
"- artifactId: \"plugin2\"\n" +
"- artifactId: \"dependency1\"\n" +
" source:\n" +
" version: \"2.0\"\n" +
"- artifactId: \"bundled1\"\n" +
" version: \"1.0.0\"\n" +
"- artifactId: \"dependency2\"\n" +
" source:\n" +
" version: \"1.0\"\n" +
" version: \"1.0.0\"\n" +
"- artifactId: \"installed1\"\n" +
" source:\n" +
" version: \"1.0\"\n" +
"- artifactId: \"dependency2\"\n" +
"- artifactId: \"installed2\"\n" +
" source:\n" +
" version: \"1.0.0\"\n" +
"- artifactId: \"dependency1\"\n" +
" version: \"2.0\"\n" +
"- artifactId: \"plugin1\"\n" +
" source:\n" +
" version: \"1.0\"\n" +
"- artifactId: \"plugin2\"\n" +
" source:\n" +
" version: \"1.0.0\"\n\n");
" version: \"2.0\"\n" +
"\n");
}

@Test
Expand Down

0 comments on commit fff28c7

Please sign in to comment.