Skip to content

Commit 9caeb01

Browse files
Logs less for gradle commands
1 parent 010cbca commit 9caeb01

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/main/java/io/micrometer/release/common/ProcessRunner.java

+22-4
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,38 @@ public List<String> run(List<String> command) {
5252
return run(command.toArray(new String[0]));
5353
}
5454

55+
public List<String> runSilently(List<String> command) {
56+
return run(false, command.toArray(new String[0]));
57+
}
58+
59+
public List<String> runSilently(String... command) {
60+
return run(false, command);
61+
}
62+
5563
public List<String> run(String... command) {
64+
return run(true, command);
65+
}
66+
67+
private List<String> run(boolean shouldLog, String... command) {
5668
List<String> lines = new ArrayList<>();
5769
String[] processedCommand = processCommand(command);
5870
try {
71+
log.info("About to start command {}", (Object) processedCommand);
5972
Process process = startProcess(processedCommand);
6073

61-
log.info("Printing out process logs:\n\n");
74+
if (shouldLog) {
75+
log.info("Printing out process logs:\n\n");
76+
}
6277

6378
List<String> errorLines = new ArrayList<>();
6479

6580
Thread outputThread = new Thread(() -> {
6681
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
6782
String line;
6883
while ((line = reader.readLine()) != null) {
69-
log.info(line);
84+
if (shouldLog) {
85+
log.info(line);
86+
}
7087
lines.add(line);
7188
}
7289
}
@@ -99,12 +116,13 @@ public List<String> run(String... command) {
99116
if (exitCode != 0) {
100117
String errorMessage = String.format("Failed to run the command %s. Exit code: %d.%nError output:%n%s",
101118
Arrays.toString(processedCommand), exitCode, String.join("\n", errorLines));
102-
throw new RuntimeException(errorMessage);
119+
throw new IllegalStateException(errorMessage);
103120
}
104121
}
105122
catch (IOException | InterruptedException e) {
106-
throw new RuntimeException("A failure around the process execution happened", e);
123+
throw new IllegalStateException("A failure around the process execution happened", e);
107124
}
125+
log.info("Command executed successfully");
108126
return lines;
109127
}
110128

src/main/java/io/micrometer/release/single/ChangelogProcessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ else if (line.isEmpty() || line.isBlank()) {
138138
}
139139

140140
List<String> dependenciesLines(List<String> gradleCommand) {
141-
return processRunner.run(gradleCommand);
141+
return processRunner.runSilently(gradleCommand);
142142
}
143143

144144
List<String> projectLines() {
145-
return processRunner.run("./gradlew", "projects");
145+
return processRunner.runSilently("./gradlew", "projects");
146146
}
147147

148148
private Collection<String> processDependencyUpgrades(Iterable<String> dependencyLines,

0 commit comments

Comments
 (0)