author | herrick |
Thu, 17 Oct 2019 07:55:35 -0400 | |
branch | JDK-8200758-branch |
changeset 58670 | 6fb9e12d5595 |
parent 58302 | 718bd56695b3 |
child 58696 | 61c44899b4eb |
permissions | -rw-r--r-- |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
1 |
/* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
4 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
10 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
15 |
* accompanied this code). |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
16 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
20 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
23 |
* questions. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
24 |
*/ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
25 |
package jdk.jpackage.internal; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
26 |
|
58302 | 27 |
import java.io.File; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
28 |
import java.io.IOException; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
29 |
import java.nio.file.Files; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
30 |
import java.nio.file.Path; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
31 |
import java.util.ArrayList; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
32 |
import java.util.Collection; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
33 |
import java.util.Collections; |
58302 | 34 |
import java.util.HashMap; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
35 |
import java.util.List; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
36 |
import java.util.Map; |
58302 | 37 |
import java.util.function.BiFunction; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
38 |
import java.util.stream.Collectors; |
58670
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
39 |
import java.util.stream.Stream; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
40 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
41 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
42 |
/** |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
43 |
* Group of paths. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
44 |
* Each path in the group is assigned a unique id. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
45 |
*/ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
46 |
final class PathGroup { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
47 |
PathGroup(Map<Object, Path> paths) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
48 |
entries = Collections.unmodifiableMap(paths); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
49 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
50 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
51 |
Path getPath(Object id) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
52 |
return entries.get(id); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
53 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
54 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
55 |
/** |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
56 |
* All configured entries. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
57 |
*/ |
58302 | 58 |
List<Path> paths() { |
59 |
return entries.values().stream().collect(Collectors.toList()); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
60 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
61 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
62 |
/** |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
63 |
* Root entries. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
64 |
*/ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
65 |
List<Path> roots() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
66 |
// Sort by the number of path components in ascending order. |
58302 | 67 |
List<Map.Entry<Path, Path>> sorted = normalizedPaths().stream().sorted( |
68 |
(a, b) -> a.getKey().getNameCount() - b.getKey().getNameCount()).collect( |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
69 |
Collectors.toList()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
70 |
|
58302 | 71 |
// Returns `true` if `a` is a parent of `b` |
72 |
BiFunction<Map.Entry<Path, Path>, Map.Entry<Path, Path>, Boolean> isParentOrSelf = (a, b) -> { |
|
73 |
return a == b || b.getKey().startsWith(a.getKey()); |
|
74 |
}; |
|
75 |
||
76 |
return sorted.stream().filter( |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
77 |
v -> v == sorted.stream().sequential().filter( |
58302 | 78 |
v2 -> isParentOrSelf.apply(v2, v)).findFirst().get()).map( |
79 |
v -> v.getValue()).collect(Collectors.toList()); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
80 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
81 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
82 |
long sizeInBytes() throws IOException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
83 |
long reply = 0; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
84 |
for (Path dir : roots().stream().filter(f -> Files.isDirectory(f)).collect( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
85 |
Collectors.toList())) { |
58670
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
86 |
try (Stream<Path> stream = Files.walk(dir)) { |
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
87 |
reply += stream.filter(p -> Files.isRegularFile(p)).mapToLong( |
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
88 |
f -> f.toFile().length()).sum(); |
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
89 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
90 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
91 |
return reply; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
92 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
93 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
94 |
PathGroup resolveAt(Path root) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
95 |
return new PathGroup(entries.entrySet().stream().collect( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
96 |
Collectors.toMap(e -> e.getKey(), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
97 |
e -> root.resolve(e.getValue())))); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
98 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
99 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
100 |
void copy(PathGroup dst) throws IOException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
101 |
copy(this, dst, false); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
102 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
103 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
104 |
void move(PathGroup dst) throws IOException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
105 |
copy(this, dst, true); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
106 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
107 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
108 |
static interface Facade<T> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
109 |
PathGroup pathGroup(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
110 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
111 |
default Collection<Path> paths() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
112 |
return pathGroup().paths(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
113 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
114 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
115 |
default List<Path> roots() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
116 |
return pathGroup().roots(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
117 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
118 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
119 |
default long sizeInBytes() throws IOException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
120 |
return pathGroup().sizeInBytes(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
121 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
122 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
123 |
T resolveAt(Path root); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
124 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
125 |
default void copy(Facade<T> dst) throws IOException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
126 |
pathGroup().copy(dst.pathGroup()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
127 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
128 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
129 |
default void move(Facade<T> dst) throws IOException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
130 |
pathGroup().move(dst.pathGroup()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
131 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
132 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
133 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
134 |
private static void copy(PathGroup src, PathGroup dst, boolean move) throws |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
135 |
IOException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
136 |
copy(move, src.entries.keySet().stream().filter( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
137 |
id -> dst.entries.containsKey(id)).map(id -> Map.entry( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
138 |
src.entries.get(id), dst.entries.get(id))).collect( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
139 |
Collectors.toCollection(ArrayList::new))); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
140 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
141 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
142 |
private static void copy(boolean move, List<Map.Entry<Path, Path>> entries) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
143 |
throws IOException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
144 |
|
58302 | 145 |
// destination -> source file mapping |
146 |
Map<Path, Path> actions = new HashMap<>(); |
|
147 |
for (var action: entries) { |
|
148 |
Path src = action.getKey(); |
|
149 |
Path dst = action.getValue(); |
|
150 |
if (src.toFile().isDirectory()) { |
|
58670
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
151 |
try (Stream<Path> stream = Files.walk(src)) { |
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
152 |
stream.forEach(path -> actions.put(dst.resolve( |
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
153 |
src.relativize(path)).toAbsolutePath().normalize(), |
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
154 |
path)); |
6fb9e12d5595
8232280: close() is not called on return value of Files.walk()
herrick
parents:
58302
diff
changeset
|
155 |
} |
58302 | 156 |
} else { |
157 |
actions.put(dst.toAbsolutePath().normalize(), src); |
|
158 |
} |
|
159 |
} |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
160 |
|
58302 | 161 |
for (var action : actions.entrySet()) { |
162 |
Path dst = action.getKey(); |
|
163 |
Path src = action.getValue(); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
164 |
|
58302 | 165 |
if (src.equals(dst) || !src.toFile().exists()) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
166 |
continue; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
167 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
168 |
|
58302 | 169 |
if (src.toFile().isDirectory()) { |
170 |
Files.createDirectories(dst); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
171 |
} else { |
58302 | 172 |
Files.createDirectories(dst.getParent()); |
173 |
if (move) { |
|
174 |
Files.move(src, dst); |
|
175 |
} else { |
|
176 |
Files.copy(src, dst); |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
180 |
||
181 |
if (move) { |
|
182 |
// Delete source dirs. |
|
183 |
for (var entry: entries) { |
|
184 |
File srcFile = entry.getKey().toFile(); |
|
185 |
if (srcFile.isDirectory()) { |
|
186 |
IOUtils.deleteRecursive(srcFile); |
|
187 |
} |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
188 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
189 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
190 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
191 |
|
58302 | 192 |
private static Map.Entry<Path, Path> normalizedPath(Path v) { |
193 |
final Path normalized; |
|
194 |
if (!v.isAbsolute()) { |
|
195 |
normalized = Path.of("./").resolve(v.normalize()); |
|
196 |
} else { |
|
197 |
normalized = v.normalize(); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
198 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
199 |
|
58302 | 200 |
return Map.entry(normalized, v); |
201 |
} |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
202 |
|
58302 | 203 |
private List<Map.Entry<Path, Path>> normalizedPaths() { |
204 |
return entries.values().stream().map(PathGroup::normalizedPath).collect( |
|
205 |
Collectors.toList()); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
206 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
207 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
208 |
private final Map<Object, Path> entries; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
209 |
} |