Skip to content

Commit 43be5a3

Browse files
author
Andy Herrick
committed
8230652: Improve verbose output
Reviewed-by: almatvee, asemenyuk, kizune
1 parent 5a7390b commit 43be5a3

File tree

9 files changed

+53
-36
lines changed

9 files changed

+53
-36
lines changed

src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacBaseInstallerBundler.java

-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ public static String findKey(String keyPrefix, String teamName, String keychainN
187187
Log.error(MessageFormat.format(I18N.getString(
188188
"error.multiple.certs.found"), key, keychainName));
189189
}
190-
Log.verbose("Using key '" + matchedKey + "'");
191190
return matchedKey;
192191
} catch (IOException ioe) {
193192
Log.verbose(ioe);

src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java

-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ public Path bundle(Map<String, ? super Object> params,
8282
if (appLocation != null && prepareConfigFiles(params)) {
8383
Path configScript = getConfig_Script(params);
8484
if (IOUtils.exists(configScript)) {
85-
Log.verbose(MessageFormat.format(
86-
I18N.getString("message.running-script"),
87-
configScript.toAbsolutePath().toString()));
8885
IOUtils.run("bash", configScript);
8986
}
9087

src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacPkgBundler.java

-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ public Path bundle(Map<String, ? super Object> params,
142142

143143
Path configScript = getConfig_Script(params);
144144
if (IOUtils.exists(configScript)) {
145-
Log.verbose(MessageFormat.format(I18N.getString(
146-
"message.running-script"),
147-
configScript.toAbsolutePath().toString()));
148145
IOUtils.run("bash", configScript);
149146
}
150147

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

+19-22
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ Executor setCommandLine(String... cmdline) {
7575
return setProcessBuilder(new ProcessBuilder(cmdline));
7676
}
7777

78+
Executor setQuiet(boolean v) {
79+
quietCommand = v;
80+
return this;
81+
}
82+
7883
List<String> getOutput() {
7984
return output;
8085
}
@@ -84,7 +89,7 @@ Executor executeExpectSuccess() throws IOException {
8489
if (0 != ret) {
8590
throw new IOException(
8691
String.format("Command %s exited with %d code",
87-
createLogMessage(pb), ret));
92+
createLogMessage(pb, false), ret));
8893
}
8994
return this;
9095
}
@@ -108,7 +113,7 @@ int execute() throws IOException {
108113
pb.redirectOutput(ProcessBuilder.Redirect.DISCARD);
109114
}
110115

111-
Log.verbose(String.format("Running %s", createLogMessage(pb)));
116+
Log.verbose(String.format("Running %s", createLogMessage(pb, true)));
112117
Process p = pb.start();
113118

114119
int code = 0;
@@ -126,47 +131,35 @@ int execute() throws IOException {
126131
Supplier<Stream<String>> outputStream;
127132

128133
if (writeOutputToFile) {
129-
savedOutput = Files.readAllLines(outputFile);
134+
output = savedOutput = Files.readAllLines(outputFile);
130135
Files.delete(outputFile);
131136
outputStream = () -> {
132137
if (savedOutput != null) {
133138
return savedOutput.stream();
134139
}
135140
return null;
136141
};
137-
138-
if (Log.isVerbose()) {
139-
outputStream.get().forEach(Log::verbose);
140-
}
141-
142142
if (outputConsumer != null) {
143143
outputConsumer.accept(outputStream.get());
144144
}
145145
} else {
146146
try (var br = new BufferedReader(new InputStreamReader(
147147
p.getInputStream()))) {
148-
// Need to save output if explicitely requested (saveOutput=true) or
149-
// if will be used used by multiple consumers
150-
if ((outputConsumer != null && Log.isVerbose()) || saveOutput) {
148+
149+
if ((outputConsumer != null || Log.isVerbose())
150+
|| saveOutput) {
151151
savedOutput = br.lines().collect(Collectors.toList());
152-
if (saveOutput) {
153-
output = savedOutput;
154-
}
155152
} else {
156153
savedOutput = null;
157154
}
155+
output = savedOutput;
158156

159157
outputStream = () -> {
160158
if (savedOutput != null) {
161159
return savedOutput.stream();
162160
}
163161
return br.lines();
164162
};
165-
166-
if (Log.isVerbose()) {
167-
outputStream.get().forEach(Log::verbose);
168-
}
169-
170163
if (outputConsumer != null) {
171164
outputConsumer.accept(outputStream.get());
172165
}
@@ -188,6 +181,9 @@ int execute() throws IOException {
188181
if (!writeOutputToFile) {
189182
code = p.waitFor();
190183
}
184+
if (!quietCommand) {
185+
Log.verbose(pb.command(), getOutput(), code);
186+
}
191187
return code;
192188
} catch (InterruptedException ex) {
193189
Log.verbose(ex);
@@ -203,7 +199,7 @@ private int waitForProcess(Process p) throws InterruptedException {
203199
return p.exitValue();
204200
} else {
205201
Log.verbose(String.format("Command %s timeout after %d seconds",
206-
createLogMessage(pb), timeout));
202+
createLogMessage(pb, false), timeout));
207203
p.destroy();
208204
return -1;
209205
}
@@ -218,9 +214,9 @@ static Executor of(ProcessBuilder pb) {
218214
return new Executor().setProcessBuilder(pb);
219215
}
220216

221-
private static String createLogMessage(ProcessBuilder pb) {
217+
private static String createLogMessage(ProcessBuilder pb, boolean quiet) {
222218
StringBuilder sb = new StringBuilder();
223-
sb.append(String.format("%s", pb.command()));
219+
sb.append((quiet) ? pb.command().get(0) : pb.command());
224220
if (pb.directory() != null) {
225221
sb.append(String.format("in %s", pb.directory().getAbsolutePath()));
226222
}
@@ -232,6 +228,7 @@ private static String createLogMessage(ProcessBuilder pb) {
232228
private ProcessBuilder pb;
233229
private boolean saveOutput;
234230
private boolean writeOutputToFile;
231+
private boolean quietCommand;
235232
private long timeout = INFINITE_TIMEOUT;
236233
private List<String> output;
237234
private Consumer<Stream<String>> outputConsumer;

src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/IOUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ public static int getProcessOutput(List<String> result, String... args)
228228
t.start();
229229

230230
int ret = p.waitFor();
231+
Log.verbose(pb.command(), list, ret);
231232

232233
result.clear();
233234
result.addAll(list);

src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/JLinkBundlerHelper.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,16 @@ private static void runJLink(Path output, List<Path> modulePath,
188188
StringWriter writer = new StringWriter();
189189
PrintWriter pw = new PrintWriter(writer);
190190

191-
Log.verbose("jlink arguments: " + args);
192191
int retVal = LazyLoad.JLINK_TOOL.run(pw, pw, args.toArray(new String[0]));
193192
String jlinkOut = writer.toString();
194193

194+
args.add(0, "jlink");
195+
Log.verbose(args, List.of(jlinkOut), retVal);
196+
197+
195198
if (retVal != 0) {
196199
throw new PackagerException("error.jlink.failed" , jlinkOut);
197200
}
198-
199-
Log.verbose("jlink output: " + jlinkOut);
200201
}
201202

202203
private static String getPathList(List<Path> pathList) {

src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/Log.java

+27
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.PrintWriter;
2929
import java.text.SimpleDateFormat;
3030
import java.util.Date;
31+
import java.util.List;
3132

3233
/**
3334
* Log
@@ -115,6 +116,25 @@ public void verbose(String msg) {
115116
}
116117
}
117118

119+
public void verbose(List<String> strings,
120+
List<String> output, int returnCode) {
121+
if (verbose) {
122+
StringBuffer sb = new StringBuffer("Command:\n ");
123+
for (String s : strings) {
124+
sb.append(" " + s);
125+
}
126+
verbose(new String(sb));
127+
if (output != null && !output.isEmpty()) {
128+
sb = new StringBuffer("Output:");
129+
for (String s : output) {
130+
sb.append("\n " + s);
131+
}
132+
verbose(new String(sb));
133+
}
134+
verbose("Returned: " + returnCode + "\n");
135+
}
136+
}
137+
118138
private String addTimestamp(String msg) {
119139
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
120140
Date time = new Date(System.currentTimeMillis());
@@ -173,4 +193,11 @@ public static void verbose(Throwable t) {
173193
delegate.verbose(t);
174194
}
175195
}
196+
197+
public static void verbose(List<String> strings, List<String> out, int ret) {
198+
if (delegate != null) {
199+
delegate.verbose(strings, out, ret);
200+
}
201+
}
202+
176203
}

src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/ToolValidator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ConfigException validate() {
9494
}
9595

9696
String[] version = new String[1];
97-
Executor.of(pb).setOutputConsumer(lines -> {
97+
Executor.of(pb).setQuiet(true).setOutputConsumer(lines -> {
9898
if (versionParser != null && minimalVersion != null) {
9999
version[0] = versionParser.apply(lines);
100100
if (minimalVersion.compareTo(version[0]) < 0) {

test/jdk/tools/jpackage/windows/WinL10nTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public static List<Object[]> data() {
9595
private final static Stream<String> getLightCommandLine(
9696
Executor.Result result) {
9797
return result.getOutput().stream()
98-
.filter(s -> s.contains("Running"))
99-
.filter(s -> s.contains("light.exe"))
100-
.filter(s -> !s.contains("/?"));
98+
.filter(s -> s.trim().startsWith("light.exe"));
10199
}
102100

103101
@Test

0 commit comments

Comments
 (0)