author | herrick |
Mon, 30 Sep 2019 19:33:13 -0400 | |
branch | JDK-8200758-branch |
changeset 58417 | 67ffaf3a2b75 |
parent 58301 | e0efb29609bd |
child 58696 | 61c44899b4eb |
permissions | -rw-r--r-- |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57077
diff
changeset
|
2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
4 |
* |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
10 |
* |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
15 |
* accompanied this code). |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
16 |
* |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
20 |
* |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
23 |
* questions. |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
24 |
*/ |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
25 |
|
57039 | 26 |
package jdk.jpackage.internal; |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
27 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
28 |
import java.io.*; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
29 |
import java.nio.channels.FileChannel; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
30 |
import java.nio.file.FileVisitResult; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
31 |
import java.nio.file.Files; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
32 |
import java.nio.file.Path; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
33 |
import java.nio.file.SimpleFileVisitor; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
34 |
import java.nio.file.attribute.BasicFileAttributes; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
36 |
import java.util.List; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
37 |
|
56994
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
38 |
/** |
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
39 |
* IOUtils |
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
40 |
* |
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
41 |
* A collection of static utility methods. |
b4aca2dbe2b5
8212537: Create method and class description comments for main functionality
herrick
parents:
56989
diff
changeset
|
42 |
*/ |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
43 |
public class IOUtils { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
44 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
45 |
public static void deleteRecursive(File path) throws IOException { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
46 |
if (!path.exists()) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
47 |
return; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
48 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
49 |
Path directory = path.toPath(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
50 |
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
51 |
@Override |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
52 |
public FileVisitResult visitFile(Path file, |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
53 |
BasicFileAttributes attr) throws IOException { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
54 |
if (Platform.getPlatform() == Platform.WINDOWS) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
55 |
Files.setAttribute(file, "dos:readonly", false); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
56 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
57 |
Files.delete(file); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
58 |
return FileVisitResult.CONTINUE; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
59 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
60 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
61 |
@Override |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
62 |
public FileVisitResult preVisitDirectory(Path dir, |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
63 |
BasicFileAttributes attr) throws IOException { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
64 |
if (Platform.getPlatform() == Platform.WINDOWS) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
65 |
Files.setAttribute(dir, "dos:readonly", false); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
66 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
67 |
return FileVisitResult.CONTINUE; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
68 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
69 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
70 |
@Override |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
71 |
public FileVisitResult postVisitDirectory(Path dir, IOException e) |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
72 |
throws IOException { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
73 |
Files.delete(dir); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
74 |
return FileVisitResult.CONTINUE; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
75 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
76 |
}); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
77 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
78 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
79 |
public static void copyRecursive(Path src, Path dest) throws IOException { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
57446
diff
changeset
|
80 |
copyRecursive(src, dest, List.of()); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
81 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
82 |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
83 |
public static void copyRecursive(Path src, Path dest, |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
84 |
final List<String> excludes) throws IOException { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
85 |
Files.walkFileTree(src, new SimpleFileVisitor<Path>() { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
86 |
@Override |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
87 |
public FileVisitResult preVisitDirectory(final Path dir, |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
88 |
final BasicFileAttributes attrs) throws IOException { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
89 |
if (excludes.contains(dir.toFile().getName())) { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
90 |
return FileVisitResult.SKIP_SUBTREE; |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
91 |
} else { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
92 |
Files.createDirectories(dest.resolve(src.relativize(dir))); |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
93 |
return FileVisitResult.CONTINUE; |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
94 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
95 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
96 |
|
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
97 |
@Override |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
98 |
public FileVisitResult visitFile(final Path file, |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
99 |
final BasicFileAttributes attrs) throws IOException { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
100 |
if (!excludes.contains(file.toFile().getName())) { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
101 |
Files.copy(file, dest.resolve(src.relativize(file))); |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
102 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
103 |
return FileVisitResult.CONTINUE; |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
104 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
105 |
}); |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
106 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57039
diff
changeset
|
107 |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
108 |
public static void copyFile(File sourceFile, File destFile) |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
109 |
throws IOException { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
110 |
destFile.getParentFile().mkdirs(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
111 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
112 |
//recreate the file as existing copy may have weird permissions |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
113 |
destFile.delete(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
114 |
destFile.createNewFile(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
115 |
|
57390 | 116 |
try (FileChannel source = new FileInputStream(sourceFile).getChannel(); |
117 |
FileChannel destination = |
|
118 |
new FileOutputStream(destFile).getChannel()) { |
|
119 |
||
120 |
if (destination != null && source != null) { |
|
121 |
destination.transferFrom(source, 0, source.size()); |
|
122 |
} |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
123 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
124 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
125 |
//preserve executable bit! |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
126 |
if (sourceFile.canExecute()) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
127 |
destFile.setExecutable(true, false); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
128 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
129 |
if (!sourceFile.canWrite()) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
130 |
destFile.setReadOnly(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
131 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
132 |
destFile.setReadable(true, false); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
133 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
134 |
|
56982
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56869
diff
changeset
|
135 |
// run "launcher paramfile" in the directory where paramfile is kept |
57391 | 136 |
public static void run(String launcher, File paramFile) |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
137 |
throws IOException { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
138 |
if (paramFile != null && paramFile.exists()) { |
56869
41e17fe9fbeb
8208522: removed unreferenced class and minor formatting of java source
herrick
parents:
56821
diff
changeset
|
139 |
ProcessBuilder pb = |
41e17fe9fbeb
8208522: removed unreferenced class and minor formatting of java source
herrick
parents:
56821
diff
changeset
|
140 |
new ProcessBuilder(launcher, paramFile.getName()); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
141 |
pb = pb.directory(paramFile.getParentFile()); |
57391 | 142 |
exec(pb); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
143 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
144 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
145 |
|
57391 | 146 |
public static void exec(ProcessBuilder pb) |
56869
41e17fe9fbeb
8208522: removed unreferenced class and minor formatting of java source
herrick
parents:
56821
diff
changeset
|
147 |
throws IOException { |
57391 | 148 |
exec(pb, false, null); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
149 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
150 |
|
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
151 |
static void exec(ProcessBuilder pb, boolean testForPresenseOnly, |
57391 | 152 |
PrintStream consumer) throws IOException { |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
153 |
List<String> output = new ArrayList<>(); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
154 |
Executor exec = Executor.of(pb).setOutputConsumer(lines -> { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
155 |
lines.forEach(output::add); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
156 |
if (consumer != null) { |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
157 |
output.forEach(consumer::println); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
158 |
} |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
159 |
}); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
160 |
|
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
161 |
if (testForPresenseOnly) { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
162 |
exec.execute(); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
163 |
} else { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
164 |
exec.executeExpectSuccess(); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
165 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
166 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
167 |
|
57391 | 168 |
public static int getProcessOutput(List<String> result, String... args) |
169 |
throws IOException, InterruptedException { |
|
170 |
||
171 |
ProcessBuilder pb = new ProcessBuilder(args); |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
172 |
|
57391 | 173 |
final Process p = pb.start(); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
174 |
|
57391 | 175 |
List<String> list = new ArrayList<>(); |
176 |
||
177 |
final BufferedReader in = |
|
178 |
new BufferedReader(new InputStreamReader(p.getInputStream())); |
|
56869
41e17fe9fbeb
8208522: removed unreferenced class and minor formatting of java source
herrick
parents:
56821
diff
changeset
|
179 |
final BufferedReader err = |
41e17fe9fbeb
8208522: removed unreferenced class and minor formatting of java source
herrick
parents:
56821
diff
changeset
|
180 |
new BufferedReader(new InputStreamReader(p.getErrorStream())); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
181 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
182 |
Thread t = new Thread(() -> { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
183 |
try { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
184 |
String line; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
185 |
while ((line = in.readLine()) != null) { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
186 |
list.add(line); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
187 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
188 |
} catch (IOException ioe) { |
57391 | 189 |
Log.verbose(ioe); |
190 |
} |
|
191 |
||
192 |
try { |
|
193 |
String line; |
|
194 |
while ((line = err.readLine()) != null) { |
|
195 |
Log.error(line); |
|
196 |
} |
|
197 |
} catch (IOException ioe) { |
|
198 |
Log.verbose(ioe); |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
199 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
200 |
}); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
201 |
t.setDaemon(true); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
202 |
t.start(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
203 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
204 |
int ret = p.waitFor(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
205 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
206 |
result.clear(); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
207 |
result.addAll(list); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
208 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
209 |
return ret; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
210 |
} |
57407 | 211 |
|
212 |
static void writableOutputDir(Path outdir) throws PackagerException { |
|
213 |
File file = outdir.toFile(); |
|
214 |
||
215 |
if (!file.isDirectory() && !file.mkdirs()) { |
|
216 |
throw new PackagerException("error.cannot-create-output-dir", |
|
217 |
file.getAbsolutePath()); |
|
218 |
} |
|
219 |
if (!file.canWrite()) { |
|
220 |
throw new PackagerException("error.cannot-write-to-output-dir", |
|
221 |
file.getAbsolutePath()); |
|
222 |
} |
|
223 |
} |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
224 |
} |