Skip to content

Commit 0b5216a

Browse files
Ian GravesAlexey Semenyuk
Ian Graves
authored and
Alexey Semenyuk
committedMar 19, 2021
8263545: Convert jpackage to use Stream.toList()
Reviewed-by: asemenyuk, almatvee
1 parent ed701ea commit 0b5216a

17 files changed

+44
-46
lines changed
 

‎src/jdk.jpackage/linux/classes/jdk/jpackage/internal/DesktopIntegration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -175,7 +175,7 @@ static DesktopIntegration create(PlatformPackage thePackage,
175175
List<String> requiredPackages() {
176176
return Stream.of(List.of(this), nestedIntegrations).flatMap(
177177
List::stream).map(DesktopIntegration::requiredPackagesSelf).flatMap(
178-
List::stream).distinct().collect(Collectors.toList());
178+
List::stream).distinct().toList();
179179
}
180180

181181
Map<String, String> create() throws IOException {
@@ -525,7 +525,7 @@ private static String stringifyShellCommands(String... commands) {
525525

526526
private static String stringifyShellCommands(List<String> commands) {
527527
return String.join(System.lineSeparator(), commands.stream().filter(
528-
s -> s != null && !s.isEmpty()).collect(Collectors.toList()));
528+
s -> s != null && !s.isEmpty()).toList());
529529
}
530530

531531
private static class LinuxFileAssociation {

‎src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LibProvidersLookup.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -81,7 +81,7 @@ List<String> execute(Path root) throws IOException {
8181
List<String> packageNames = Collections.emptyList();
8282
return packageNames;
8383
}
84-
}).flatMap(List::stream).sorted().distinct().collect(Collectors.toList());
84+
}).flatMap(List::stream).sorted().distinct().toList();
8585

8686
return neededPackages;
8787
}

‎src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -173,7 +173,7 @@ public void doValidate(Map<String, ? super Object> params)
173173
protected List<ToolValidator> getToolValidators(
174174
Map<String, ? super Object> params) {
175175
return Stream.of(TOOL_DPKG_DEB, TOOL_DPKG, TOOL_FAKEROOT).map(
176-
ToolValidator::new).collect(Collectors.toList());
176+
ToolValidator::new).toList();
177177
}
178178

179179
@Override

‎src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBundler.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -205,8 +205,7 @@ private List<String> getListOfNeededPackages(
205205
// Merge all package lists together.
206206
// Filter out empty names, sort and remove duplicates.
207207
List<String> result = Stream.of(xdgUtilsPackage, neededLibPackages).flatMap(
208-
List::stream).filter(Predicate.not(String::isEmpty)).sorted().distinct().collect(
209-
Collectors.toList());
208+
List::stream).filter(Predicate.not(String::isEmpty)).sorted().distinct().toList();
210209

211210
Log.verbose(String.format("Required packages: %s", result));
212211

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -80,7 +80,7 @@ List<Path> expandFileset(Path root) throws IOException {
8080
if (!Files.isSymbolicLink(root)) {
8181
if (Files.isDirectory(root)) {
8282
try (Stream<Path> stream = Files.list(root)) {
83-
List<Path> children = stream.collect(Collectors.toList());
83+
List<Path> children = stream.toList();
8484
if (children != null && children.size() > 0) {
8585
children.forEach(f -> {
8686
try {

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/DottedVersion.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -148,8 +148,7 @@ private static BigInteger[] parseVersionString(String version, boolean greedy) {
148148
if (components.isEmpty()) {
149149
components.add(BigInteger.ZERO);
150150
}
151-
return components.stream()
152-
.collect(Collectors.toList()).toArray(BigInteger[]::new);
151+
return components.toArray(BigInteger[]::new);
153152
}
154153

155154
@Override

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/Executor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -148,7 +148,7 @@ int execute() throws IOException {
148148

149149
if ((outputConsumer != null || Log.isVerbose())
150150
|| saveOutput) {
151-
savedOutput = br.lines().collect(Collectors.toList());
151+
savedOutput = br.lines().toList();
152152
} else {
153153
savedOutput = null;
154154
}

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/FileAssociation.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -95,7 +95,7 @@ static List<FileAssociation> fetchFrom(Map<String, ? super Object> params) {
9595
}
9696

9797
return assoc;
98-
}).collect(Collectors.toList());
98+
}).toList();
9999
}
100100

101101
Path launcherPath;

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/LauncherData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private void initClasspath(Map<String, ? super Object> params)
238238
.relativize(p.toAbsolutePath()))
239239
.collect(Collectors.toSet());
240240
jars.remove(mainJarName);
241-
classPath = jars.stream().sorted().collect(Collectors.toList());
241+
classPath = jars.stream().sorted().toList();
242242
}
243243
}
244244
}

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/OverridableResource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -103,7 +103,7 @@ enum Source { External, ResourceDir, DefaultResource };
103103
OverridableResource setSourceOrder(Source... v) {
104104
sources = Stream.of(v)
105105
.map(source -> Map.entry(source, getHandler(source)))
106-
.collect(Collectors.toList());
106+
.toList();
107107
return this;
108108
}
109109

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/PathGroup.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -65,7 +65,7 @@ void setPath(Object id, Path path) {
6565
* All configured entries.
6666
*/
6767
List<Path> paths() {
68-
return entries.values().stream().collect(Collectors.toList());
68+
return entries.values().stream().toList();
6969
}
7070

7171
/**
@@ -74,8 +74,7 @@ List<Path> paths() {
7474
List<Path> roots() {
7575
// Sort by the number of path components in ascending order.
7676
List<Map.Entry<Path, Path>> sorted = normalizedPaths().stream().sorted(
77-
(a, b) -> a.getKey().getNameCount() - b.getKey().getNameCount()).collect(
78-
Collectors.toList());
77+
(a, b) -> a.getKey().getNameCount() - b.getKey().getNameCount()).toList();
7978

8079
// Returns `true` if `a` is a parent of `b`
8180
BiFunction<Map.Entry<Path, Path>, Map.Entry<Path, Path>, Boolean> isParentOrSelf = (a, b) -> {
@@ -85,7 +84,7 @@ List<Path> roots() {
8584
return sorted.stream().filter(
8685
v -> v == sorted.stream().sequential().filter(
8786
v2 -> isParentOrSelf.apply(v2, v)).findFirst().get()).map(
88-
v -> v.getValue()).collect(Collectors.toList());
87+
v -> v.getValue()).toList();
8988
}
9089

9190
long sizeInBytes() throws IOException {

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -387,15 +387,16 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
387387
(s, p) -> {
388388
List<Path> modulePath = Stream.of(s.split(File.pathSeparator))
389389
.map(Path::of)
390-
.collect(Collectors.toList());
390+
.toList();
391391
Path javaBasePath = findPathOfModule(modulePath, JAVABASEJMOD);
392392

393393
// Add the default JDK module path to the module path.
394394
if (javaBasePath == null) {
395395
List<Path> jdkModulePath = getDefaultModulePath();
396396

397397
if (jdkModulePath != null) {
398-
modulePath.addAll(jdkModulePath);
398+
modulePath = Stream.concat(modulePath.stream(),
399+
jdkModulePath.stream()).toList();
399400
javaBasePath = findPathOfModule(modulePath, JAVABASEJMOD);
400401
}
401402
}

‎src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ public WinMsiBundler() {
195195
wixFragments = Stream.of(
196196
Map.entry("bundle.wxf", new WixAppImageFragmentBuilder()),
197197
Map.entry("ui.wxf", new WixUiFragmentBuilder())
198-
).map(e -> {
198+
).<WixFragmentBuilder>map(e -> {
199199
e.getValue().setOutputFileName(e.getKey());
200200
return e.getValue();
201-
}).collect(Collectors.toList());
201+
}).toList();
202202
}
203203

204204
@Override
@@ -520,7 +520,7 @@ private static List<Path> getCustomWxlFiles(Map<String, ? super Object> params)
520520
.filter(Files::isReadable)
521521
.filter(pathMatcher::matches)
522522
.sorted((a, b) -> a.getFileName().toString().compareToIgnoreCase(b.getFileName().toString()))
523-
.collect(Collectors.toList());
523+
.toList();
524524
}
525525
}
526526

‎src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixAppImageFragmentBuilder.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -112,7 +112,7 @@ void initFromParams(Map<String, ? super Object> params) {
112112
launcherPaths = AppImageFile.getLauncherNames(appImageRoot, params).stream()
113113
.map(name -> installedAppImage.launchersDirectory().resolve(name))
114114
.map(WixAppImageFragmentBuilder::addExeSuffixToPath)
115-
.collect(Collectors.toList());
115+
.toList();
116116
}
117117

118118
programMenuFolderName = MENU_GROUP.fetchFrom(params);
@@ -162,7 +162,7 @@ private void normalizeFileAssociation(FileAssociation fa) {
162162

163163
// Filter out empty extensions.
164164
fa.extensions = fa.extensions.stream().filter(Predicate.not(
165-
String::isEmpty)).collect(Collectors.toList());
165+
String::isEmpty)).toList();
166166
}
167167

168168
private static Path addExeSuffixToPath(Path path) {
@@ -179,7 +179,7 @@ private void initFileAssociations(Map<String, ? super Object> params) {
179179
.peek(this::normalizeFileAssociation)
180180
// Filter out file associations without extensions.
181181
.filter(fa -> !fa.extensions.isEmpty())
182-
.collect(Collectors.toList());
182+
.toList();
183183

184184
associations.stream().filter(fa -> fa.iconPath != null).forEach(fa -> {
185185
// Need to add fa icon in the image.
@@ -600,7 +600,7 @@ public void createDirectory(final Path dir) throws IOException {
600600
for (var dir : allDirs.stream()
601601
.filter(Predicate.not(emptyDirs::contains))
602602
.filter(Predicate.not(removeFolderItems::containsKey))
603-
.collect(Collectors.toList())) {
603+
.toList()) {
604604
componentIds.add(addRemoveDirectoryComponent(xml, dir));
605605
}
606606
}

‎src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixTool.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -159,7 +159,7 @@ private static List<Path> findWixInstallDirs() {
159159
return Stream.of(programFiles, programFilesX86).map(path -> {
160160
List<Path> result;
161161
try (var paths = Files.walk(path, 1)) {
162-
result = paths.collect(Collectors.toList());
162+
result = paths.toList();
163163
} catch (IOException ex) {
164164
Log.verbose(ex);
165165
result = Collections.emptyList();
@@ -169,6 +169,6 @@ private static List<Path> findWixInstallDirs() {
169169
.filter(path -> wixInstallDirMatcher.matches(path.getFileName()))
170170
.sorted(Comparator.comparing(Path::getFileName).reversed())
171171
.map(path -> path.resolve("bin"))
172-
.collect(Collectors.toList());
172+
.toList();
173173
}
174174
}

‎src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixUiFragmentBuilder.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void initFromParams(Map<String, ? super Object> params) {
6868
ShortcutsFolder.values()).filter(shortcutFolder -> {
6969
return shortcutFolder.requested(params)
7070
&& SHORTCUT_PROMPT.fetchFrom(params);
71-
}).collect(Collectors.toList());
71+
}).toList();
7272

7373
withShortcutPromptDlg = !shortcutFolders.isEmpty();
7474

@@ -265,10 +265,10 @@ static Map<DialogPair, List<Publish>> createPair(Dialog firstId,
265265
var pair = new DialogPair(firstId, secondId);
266266
return Map.of(pair, nextBuilders.stream().map(b -> {
267267
return buildPublish(b.create()).next().create();
268-
}).collect(Collectors.toList()), pair.flip(),
268+
}).toList(), pair.flip(),
269269
prevBuilders.stream().map(b -> {
270270
return buildPublish(b.create()).back().create();
271-
}).collect(Collectors.toList()));
271+
}).toList());
272272
}
273273

274274
static Map<DialogPair, List<Publish>> createPair(Dialog firstId,

‎test/jdk/tools/jpackage/junit/jdk/jpackage/internal/PathGroupTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -87,7 +87,7 @@ public void testDuplicatedRoots() {
8787
PATH_FOO, "root", PATH_EMPTY));
8888

8989
List<Path> paths = pg.paths();
90-
Collections.sort(paths);
90+
paths = paths.stream().sorted().toList();
9191

9292
assertEquals(3, paths.size());
9393
assertEquals(PATH_EMPTY, paths.get(0));

0 commit comments

Comments
 (0)
Please sign in to comment.