Skip to content

Commit db92aa4

Browse files
authored
Replace brackets in runAfterPush (#52)
2 parents e70b716 + bbffb0c commit db92aa4

File tree

6 files changed

+32
-24
lines changed

6 files changed

+32
-24
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- The `runAfterPush` command should replace brackets as documented. ([#52](https://github.com/diffplug/spotless-changelog/pull/52))
810

911
## [3.1.0] - 2024-07-06
1012
### Added

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ subprojects {
5858
}
5959
tasks.register('configCacheTest', Test) {
6060
systemProperty 'com.diffplug.config-cache-test', 'true'
61+
testClassesDirs = testing.suites.test.sources.output.classesDirs
62+
classpath = testing.suites.test.sources.runtimeClasspath
6163
}
6264
tasks.named('check') {
6365
dependsOn 'configCacheTest'

spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2023 DiffPlug
2+
* Copyright (C) 2019-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -116,6 +116,21 @@ public void tagBranchPush() throws GitAPIException {
116116
push(cfg.branch, RemoteRefUpdate.Status.OK);
117117
}
118118

119+
public void runAfterPush() {
120+
if (cfg.runAfterPush == null) {
121+
return;
122+
}
123+
try (var runner = new ProcessRunner()) {
124+
var result = runner.shell(formatTagMessage(cfg.runAfterPush));
125+
System.out.write(result.stdOut());
126+
System.out.flush();
127+
System.err.write(result.stdErr());
128+
System.err.flush();
129+
} catch (IOException | InterruptedException e) {
130+
throw new RuntimeException("runAfterPush failed: " + formatTagMessage(cfg.runAfterPush), e);
131+
}
132+
}
133+
119134
private String formatCommitMessage(final String commitMessage) {
120135
return commitMessage.replace(GitCfg.COMMIT_MESSAGE_VERSION, model.versions().next());
121136
}

spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/ProcessRunner.java spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/ProcessRunner.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.changelog.gradle;
16+
package com.diffplug.spotless.changelog;
1717

1818
import static java.util.Objects.requireNonNull;
1919

@@ -34,8 +34,7 @@
3434
import java.util.concurrent.Future;
3535
import java.util.concurrent.TimeUnit;
3636
import java.util.function.BiConsumer;
37-
import javax.annotation.Nonnull;
38-
import javax.annotation.Nullable;
37+
import pl.tlinkowski.annotation.basic.NullOr;
3938

4039
/**
4140
* Shelling out to a process is harder than it ought to be in Java.
@@ -82,7 +81,7 @@ private static boolean machineIsWin() {
8281
}
8382

8483
/** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */
85-
public Result shellWinUnix(@Nullable File cwd, @Nullable Map<String, String> environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException {
84+
public Result shellWinUnix(@NullOr File cwd, @NullOr Map<String, String> environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException {
8685
List<String> args;
8786
if (machineIsWin()) {
8887
args = Arrays.asList("cmd", "/c", cmdWin);
@@ -98,7 +97,7 @@ public Result exec(String... args) throws IOException, InterruptedException {
9897
}
9998

10099
/** Creates a process with the given arguments, the given byte array is written to stdin immediately. */
101-
public Result exec(@Nullable byte[] stdin, String... args) throws IOException, InterruptedException {
100+
public Result exec(@NullOr byte[] stdin, String... args) throws IOException, InterruptedException {
102101
return exec(stdin, Arrays.asList(args));
103102
}
104103

@@ -108,12 +107,12 @@ public Result exec(List<String> args) throws IOException, InterruptedException {
108107
}
109108

110109
/** Creates a process with the given arguments, the given byte array is written to stdin immediately. */
111-
public Result exec(@Nullable byte[] stdin, List<String> args) throws IOException, InterruptedException {
110+
public Result exec(@NullOr byte[] stdin, List<String> args) throws IOException, InterruptedException {
112111
return exec(null, null, stdin, args);
113112
}
114113

115114
/** Creates a process with the given arguments, the given byte array is written to stdin immediately. */
116-
public Result exec(@Nullable File cwd, @Nullable Map<String, String> environment, @Nullable byte[] stdin, List<String> args) throws IOException, InterruptedException {
115+
public Result exec(@NullOr File cwd, @NullOr Map<String, String> environment, @NullOr byte[] stdin, List<String> args) throws IOException, InterruptedException {
117116
LongRunningProcess process = start(cwd, environment, stdin, args);
118117
try {
119118
// wait for the process to finish
@@ -130,7 +129,7 @@ public Result exec(@Nullable File cwd, @Nullable Map<String, String> environment
130129
* <br>
131130
* Delegates to {@link #start(File, Map, byte[], boolean, List)} with {@code false} for {@code redirectErrorStream}.
132131
*/
133-
public LongRunningProcess start(@Nullable File cwd, @Nullable Map<String, String> environment, @Nullable byte[] stdin, List<String> args) throws IOException {
132+
public LongRunningProcess start(@NullOr File cwd, @NullOr Map<String, String> environment, @NullOr byte[] stdin, List<String> args) throws IOException {
134133
return start(cwd, environment, stdin, false, args);
135134
}
136135

@@ -142,7 +141,7 @@ public LongRunningProcess start(@Nullable File cwd, @Nullable Map<String, String
142141
* To dispose this {@code ProcessRunner} instance, either call {@link #close()} or {@link LongRunningProcess#close()}. After
143142
* {@link #close()} or {@link LongRunningProcess#close()} has been called, this {@code ProcessRunner} instance must not be used anymore.
144143
*/
145-
public LongRunningProcess start(@Nullable File cwd, @Nullable Map<String, String> environment, @Nullable byte[] stdin, boolean redirectErrorStream, List<String> args) throws IOException {
144+
public LongRunningProcess start(@NullOr File cwd, @NullOr Map<String, String> environment, @NullOr byte[] stdin, boolean redirectErrorStream, List<String> args) throws IOException {
146145
checkState();
147146
ProcessBuilder builder = new ProcessBuilder(args);
148147
if (cwd != null) {
@@ -203,7 +202,7 @@ public static class Result {
203202
private final int exitCode;
204203
private final byte[] stdOut, stdErr;
205204

206-
public Result(@Nonnull List<String> args, int exitCode, @Nonnull byte[] stdOut, @Nullable byte[] stdErr) {
205+
public Result(List<String> args, int exitCode, byte[] stdOut, @NullOr byte[] stdErr) {
207206
this.args = args;
208207
this.exitCode = exitCode;
209208
this.stdOut = stdOut;
@@ -295,7 +294,7 @@ public class LongRunningProcess extends Process implements AutoCloseable {
295294
private final Future<byte[]> outputFut;
296295
private final Future<byte[]> errorFut;
297296

298-
public LongRunningProcess(@Nonnull Process delegate, @Nonnull List<String> args, @Nonnull Future<byte[]> outputFut, @Nullable Future<byte[]> errorFut) {
297+
public LongRunningProcess(Process delegate, List<String> args, Future<byte[]> outputFut, @NullOr Future<byte[]> errorFut) {
299298
this.delegate = requireNonNull(delegate);
300299
this.args = args;
301300
this.outputFut = outputFut;
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.changelog.gradle;
16+
package com.diffplug.spotless.changelog;
1717

1818
import java.io.ByteArrayOutputStream;
1919
import java.io.IOException;

spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/ChangelogPlugin.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,7 @@ public void push() throws IOException, GitAPIException {
247247
GitActions git = data.gitCfg.withChangelog(data.changelogFile, data.model());
248248
git.addAndCommit();
249249
git.tagBranchPush();
250-
if (data.gitCfg.runAfterPush != null) {
251-
try (var runner = new ProcessRunner()) {
252-
var result = runner.shell(data.gitCfg.runAfterPush);
253-
System.out.write(result.stdOut());
254-
System.out.flush();
255-
System.err.write(result.stdErr());
256-
System.err.flush();
257-
} catch (IOException | InterruptedException e) {
258-
throw new GradleException("runAfterPush failed: " + data.gitCfg.runAfterPush, e);
259-
}
260-
}
250+
git.runAfterPush();
261251
}
262252
}
263253
}

0 commit comments

Comments
 (0)