Skip to content
Permalink
Browse files
8263545: Convert jpackage to use Stream.toList()
Reviewed-by: asemenyuk, almatvee
  • Loading branch information
Ian Graves authored and Alexey Semenyuk committed Mar 19, 2021
1 parent ed701ea commit 0b5216a922b9d67248d1e72d3b1a70e7d23d83d5
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 46 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -175,7 +175,7 @@ static DesktopIntegration create(PlatformPackage thePackage,
List<String> requiredPackages() {
return Stream.of(List.of(this), nestedIntegrations).flatMap(
List::stream).map(DesktopIntegration::requiredPackagesSelf).flatMap(
List::stream).distinct().collect(Collectors.toList());
List::stream).distinct().toList();
}

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

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

private static class LinuxFileAssociation {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -81,7 +81,7 @@ List<String> execute(Path root) throws IOException {
List<String> packageNames = Collections.emptyList();
return packageNames;
}
}).flatMap(List::stream).sorted().distinct().collect(Collectors.toList());
}).flatMap(List::stream).sorted().distinct().toList();

return neededPackages;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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)
protected List<ToolValidator> getToolValidators(
Map<String, ? super Object> params) {
return Stream.of(TOOL_DPKG_DEB, TOOL_DPKG, TOOL_FAKEROOT).map(
ToolValidator::new).collect(Collectors.toList());
ToolValidator::new).toList();
}

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

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

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -80,7 +80,7 @@ List<Path> expandFileset(Path root) throws IOException {
if (!Files.isSymbolicLink(root)) {
if (Files.isDirectory(root)) {
try (Stream<Path> stream = Files.list(root)) {
List<Path> children = stream.collect(Collectors.toList());
List<Path> children = stream.toList();
if (children != null && children.size() > 0) {
children.forEach(f -> {
try {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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) {
if (components.isEmpty()) {
components.add(BigInteger.ZERO);
}
return components.stream()
.collect(Collectors.toList()).toArray(BigInteger[]::new);
return components.toArray(BigInteger[]::new);
}

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

if ((outputConsumer != null || Log.isVerbose())
|| saveOutput) {
savedOutput = br.lines().collect(Collectors.toList());
savedOutput = br.lines().toList();
} else {
savedOutput = null;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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) {
}

return assoc;
}).collect(Collectors.toList());
}).toList();
}

Path launcherPath;
@@ -238,7 +238,7 @@ private void initClasspath(Map<String, ? super Object> params)
.relativize(p.toAbsolutePath()))
.collect(Collectors.toSet());
jars.remove(mainJarName);
classPath = jars.stream().sorted().collect(Collectors.toList());
classPath = jars.stream().sorted().toList();
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -103,7 +103,7 @@ enum Source { External, ResourceDir, DefaultResource };
OverridableResource setSourceOrder(Source... v) {
sources = Stream.of(v)
.map(source -> Map.entry(source, getHandler(source)))
.collect(Collectors.toList());
.toList();
return this;
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -65,7 +65,7 @@ void setPath(Object id, Path path) {
* All configured entries.
*/
List<Path> paths() {
return entries.values().stream().collect(Collectors.toList());
return entries.values().stream().toList();
}

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

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

long sizeInBytes() throws IOException {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -387,15 +387,16 @@
(s, p) -> {
List<Path> modulePath = Stream.of(s.split(File.pathSeparator))
.map(Path::of)
.collect(Collectors.toList());
.toList();
Path javaBasePath = findPathOfModule(modulePath, JAVABASEJMOD);

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

if (jdkModulePath != null) {
modulePath.addAll(jdkModulePath);
modulePath = Stream.concat(modulePath.stream(),
jdkModulePath.stream()).toList();
javaBasePath = findPathOfModule(modulePath, JAVABASEJMOD);
}
}
@@ -195,10 +195,10 @@ public WinMsiBundler() {
wixFragments = Stream.of(
Map.entry("bundle.wxf", new WixAppImageFragmentBuilder()),
Map.entry("ui.wxf", new WixUiFragmentBuilder())
).map(e -> {
).<WixFragmentBuilder>map(e -> {
e.getValue().setOutputFileName(e.getKey());
return e.getValue();
}).collect(Collectors.toList());
}).toList();
}

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

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

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

// Filter out empty extensions.
fa.extensions = fa.extensions.stream().filter(Predicate.not(
String::isEmpty)).collect(Collectors.toList());
String::isEmpty)).toList();
}

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

associations.stream().filter(fa -> fa.iconPath != null).forEach(fa -> {
// Need to add fa icon in the image.
@@ -600,7 +600,7 @@ public void createDirectory(final Path dir) throws IOException {
for (var dir : allDirs.stream()
.filter(Predicate.not(emptyDirs::contains))
.filter(Predicate.not(removeFolderItems::containsKey))
.collect(Collectors.toList())) {
.toList()) {
componentIds.add(addRemoveDirectoryComponent(xml, dir));
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -159,7 +159,7 @@ private static List<Path> findWixInstallDirs() {
return Stream.of(programFiles, programFilesX86).map(path -> {
List<Path> result;
try (var paths = Files.walk(path, 1)) {
result = paths.collect(Collectors.toList());
result = paths.toList();
} catch (IOException ex) {
Log.verbose(ex);
result = Collections.emptyList();
@@ -169,6 +169,6 @@ private static List<Path> findWixInstallDirs() {
.filter(path -> wixInstallDirMatcher.matches(path.getFileName()))
.sorted(Comparator.comparing(Path::getFileName).reversed())
.map(path -> path.resolve("bin"))
.collect(Collectors.toList());
.toList();
}
}
@@ -68,7 +68,7 @@ void initFromParams(Map<String, ? super Object> params) {
ShortcutsFolder.values()).filter(shortcutFolder -> {
return shortcutFolder.requested(params)
&& SHORTCUT_PROMPT.fetchFrom(params);
}).collect(Collectors.toList());
}).toList();

withShortcutPromptDlg = !shortcutFolders.isEmpty();

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

static Map<DialogPair, List<Publish>> createPair(Dialog firstId,
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -87,7 +87,7 @@ public void testDuplicatedRoots() {
PATH_FOO, "root", PATH_EMPTY));

List<Path> paths = pg.paths();
Collections.sort(paths);
paths = paths.stream().sorted().toList();

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

0 comments on commit 0b5216a

Please sign in to comment.