diff --git a/CHANGELOG.md b/CHANGELOG.md index 73093c2..a8100bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- The `runAfterPush` command should replace brackets as documented. ([#52](https://github.com/diffplug/spotless-changelog/pull/52)) ## [3.1.0] - 2024-07-06 ### Added diff --git a/build.gradle b/build.gradle index 68b9876..69ea4c1 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,8 @@ subprojects { } tasks.register('configCacheTest', Test) { systemProperty 'com.diffplug.config-cache-test', 'true' + testClassesDirs = testing.suites.test.sources.output.classesDirs + classpath = testing.suites.test.sources.runtimeClasspath } tasks.named('check') { dependsOn 'configCacheTest' diff --git a/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java b/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java index 4166b9a..ec40aad 100644 --- a/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java +++ b/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/GitActions.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 DiffPlug + * Copyright (C) 2019-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -116,6 +116,21 @@ public void tagBranchPush() throws GitAPIException { push(cfg.branch, RemoteRefUpdate.Status.OK); } + public void runAfterPush() { + if (cfg.runAfterPush == null) { + return; + } + try (var runner = new ProcessRunner()) { + var result = runner.shell(formatTagMessage(cfg.runAfterPush)); + System.out.write(result.stdOut()); + System.out.flush(); + System.err.write(result.stdErr()); + System.err.flush(); + } catch (IOException | InterruptedException e) { + throw new RuntimeException("runAfterPush failed: " + formatTagMessage(cfg.runAfterPush), e); + } + } + private String formatCommitMessage(final String commitMessage) { return commitMessage.replace(GitCfg.COMMIT_MESSAGE_VERSION, model.versions().next()); } diff --git a/spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/ProcessRunner.java b/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/ProcessRunner.java similarity index 89% rename from spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/ProcessRunner.java rename to spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/ProcessRunner.java index 3920f46..1fe755a 100644 --- a/spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/ProcessRunner.java +++ b/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/ProcessRunner.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.changelog.gradle; +package com.diffplug.spotless.changelog; import static java.util.Objects.requireNonNull; @@ -34,8 +34,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import pl.tlinkowski.annotation.basic.NullOr; /** * Shelling out to a process is harder than it ought to be in Java. @@ -82,7 +81,7 @@ private static boolean machineIsWin() { } /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ - public Result shellWinUnix(@Nullable File cwd, @Nullable Map environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException { + public Result shellWinUnix(@NullOr File cwd, @NullOr Map environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException { List args; if (machineIsWin()) { args = Arrays.asList("cmd", "/c", cmdWin); @@ -98,7 +97,7 @@ public Result exec(String... args) throws IOException, InterruptedException { } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(@Nullable byte[] stdin, String... args) throws IOException, InterruptedException { + public Result exec(@NullOr byte[] stdin, String... args) throws IOException, InterruptedException { return exec(stdin, Arrays.asList(args)); } @@ -108,12 +107,12 @@ public Result exec(List args) throws IOException, InterruptedException { } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(@Nullable byte[] stdin, List args) throws IOException, InterruptedException { + public Result exec(@NullOr byte[] stdin, List args) throws IOException, InterruptedException { return exec(null, null, stdin, args); } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, List args) throws IOException, InterruptedException { + public Result exec(@NullOr File cwd, @NullOr Map environment, @NullOr byte[] stdin, List args) throws IOException, InterruptedException { LongRunningProcess process = start(cwd, environment, stdin, args); try { // wait for the process to finish @@ -130,7 +129,7 @@ public Result exec(@Nullable File cwd, @Nullable Map environment *
* Delegates to {@link #start(File, Map, byte[], boolean, List)} with {@code false} for {@code redirectErrorStream}. */ - public LongRunningProcess start(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, List args) throws IOException { + public LongRunningProcess start(@NullOr File cwd, @NullOr Map environment, @NullOr byte[] stdin, List args) throws IOException { return start(cwd, environment, stdin, false, args); } @@ -142,7 +141,7 @@ public LongRunningProcess start(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, boolean redirectErrorStream, List args) throws IOException { + public LongRunningProcess start(@NullOr File cwd, @NullOr Map environment, @NullOr byte[] stdin, boolean redirectErrorStream, List args) throws IOException { checkState(); ProcessBuilder builder = new ProcessBuilder(args); if (cwd != null) { @@ -203,7 +202,7 @@ public static class Result { private final int exitCode; private final byte[] stdOut, stdErr; - public Result(@Nonnull List args, int exitCode, @Nonnull byte[] stdOut, @Nullable byte[] stdErr) { + public Result(List args, int exitCode, byte[] stdOut, @NullOr byte[] stdErr) { this.args = args; this.exitCode = exitCode; this.stdOut = stdOut; @@ -295,7 +294,7 @@ public class LongRunningProcess extends Process implements AutoCloseable { private final Future outputFut; private final Future errorFut; - public LongRunningProcess(@Nonnull Process delegate, @Nonnull List args, @Nonnull Future outputFut, @Nullable Future errorFut) { + public LongRunningProcess(Process delegate, List args, Future outputFut, @NullOr Future errorFut) { this.delegate = requireNonNull(delegate); this.args = args; this.outputFut = outputFut; diff --git a/spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/RingBufferByteArrayOutputStream.java b/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/RingBufferByteArrayOutputStream.java similarity index 98% rename from spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/RingBufferByteArrayOutputStream.java rename to spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/RingBufferByteArrayOutputStream.java index e2079aa..0e806b8 100644 --- a/spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/RingBufferByteArrayOutputStream.java +++ b/spotless-changelog-lib/src/main/java/com/diffplug/spotless/changelog/RingBufferByteArrayOutputStream.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.changelog.gradle; +package com.diffplug.spotless.changelog; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/ChangelogPlugin.java b/spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/ChangelogPlugin.java index 451f0f3..618cbc6 100644 --- a/spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/ChangelogPlugin.java +++ b/spotless-changelog-plugin-gradle/src/main/java/com/diffplug/spotless/changelog/gradle/ChangelogPlugin.java @@ -247,17 +247,7 @@ public void push() throws IOException, GitAPIException { GitActions git = data.gitCfg.withChangelog(data.changelogFile, data.model()); git.addAndCommit(); git.tagBranchPush(); - if (data.gitCfg.runAfterPush != null) { - try (var runner = new ProcessRunner()) { - var result = runner.shell(data.gitCfg.runAfterPush); - System.out.write(result.stdOut()); - System.out.flush(); - System.err.write(result.stdErr()); - System.err.flush(); - } catch (IOException | InterruptedException e) { - throw new GradleException("runAfterPush failed: " + data.gitCfg.runAfterPush, e); - } - } + git.runAfterPush(); } } }