Skip to content

Commit 074ad64

Browse files
author
Rob Austin
committed
added support for "ea" and windows
1 parent ea45685 commit 074ad64

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/main/java/software/chronicle/BinaryCompatibilityEnforcerPluginMogo.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
import java.util.concurrent.TimeUnit;
1616

1717
import static java.lang.Double.parseDouble;
18-
import static java.lang.Runtime.getRuntime;
18+
1919
import static java.lang.String.format;
2020

2121
@Mojo(name = "enforcer", defaultPhase = LifecyclePhase.VERIFY)
2222
public class BinaryCompatibilityEnforcerPluginMogo extends AbstractMojo {
23+
private static final String OS = System.getProperty("os.name").toLowerCase();
24+
private static final boolean IS_LINUX = OS.startsWith("linux");
25+
private static final boolean IS_MAC = OS.contains("mac");
26+
private static final boolean IS_WIN = OS.startsWith("win");
2327

2428
public static final String REPORT = "Report: ";
2529
public static final String BINARY_COMPATIBILITY = "Binary compatibility: ";
2630
public static final String BAR = "\n------------------------------" +
2731
"------------------------------------------";
2832
private static final String BIN_SH = "/bin/sh";
33+
private static final String CMD_EXE = "C:\\WINDOWS\\system32\\cmd.exe";
2934

3035
@Parameter(defaultValue = "${project}", readonly = true, required = true)
3136
private MavenProject project;
@@ -51,9 +56,12 @@ public void execute() throws MojoExecutionException {
5156

5257
getLog().info(format("%s\nBINARY COMPATIBILITY ENFORCER - %s%s", BAR, project.getArtifactId(), BAR));
5358

54-
// avoid errors on Windows
55-
if (!new File(BIN_SH).exists()) {
56-
getLog().info("Not supported on Windows yet");
59+
60+
if ((IS_LINUX | IS_MAC) && !new File(BIN_SH).exists()) {
61+
getLog().info(BIN_SH + " not found");
62+
return;
63+
} else if (IS_WIN && !new File(CMD_EXE).exists()) {
64+
getLog().info(CMD_EXE + " not found");
5765
return;
5866
}
5967

@@ -168,7 +176,8 @@ private File downloadArtifact(final String group, final String artifactId, final
168176
BufferedReader stdError = null;
169177
Process p = null;
170178
try {
171-
p = getRuntime().exec(command);
179+
180+
p = new ProcessBuilder(IS_WIN ? CMD_EXE : BIN_SH, IS_WIN ? "/C" : "-c", command).start();
172181

173182
final BufferedReader stdInput = new BufferedReader(new
174183
InputStreamReader(p.getInputStream()));
@@ -208,7 +217,7 @@ private void checkBinaryCompatibility(final String jar1, final String jar2, fina
208217
final String command = format(expression, artifactName, jar1, jar2, reportOutput);
209218

210219
getLog().info(command);
211-
p = new ProcessBuilder(BIN_SH, "-c", command).start();
220+
p = new ProcessBuilder(IS_WIN ? CMD_EXE : BIN_SH, IS_WIN ? "/C" : "-c", command).start();
212221

213222
final BufferedReader stdInput = new BufferedReader(new
214223
InputStreamReader(p.getInputStream()));
@@ -298,7 +307,8 @@ public void checkJavaAPIComplianceCheckerInstalled() throws MojoExecutionExcepti
298307
BufferedReader stdError = null;
299308
try {
300309

301-
p = new ProcessBuilder(BIN_SH, "-c", "japi-compliance-checker -l").start();
310+
p = new ProcessBuilder(IS_WIN ? CMD_EXE : BIN_SH, IS_WIN ? "/C" : "-c", "japi-compliance-checker -l").start();
311+
302312
final BufferedReader stdInput = new BufferedReader(new
303313
InputStreamReader(p.getInputStream()));
304314

src/test/java/software/chronicle/BinaryCompatibilityEnforcerPluginMogoTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public void test() throws MojoExecutionException {
1919

2020
assertEquals("1.2ea0", test("1.2ea3"));
2121
assertEquals("1.2ea0", test("1.2ea4-SNAPSHOT"));
22-
2322
}
2423

2524
private String test(String version) throws MojoExecutionException {

0 commit comments

Comments
 (0)