1515import java .util .concurrent .TimeUnit ;
1616
1717import static java .lang .Double .parseDouble ;
18- import static java . lang . Runtime . getRuntime ;
18+
1919import static java .lang .String .format ;
2020
2121@ Mojo (name = "enforcer" , defaultPhase = LifecyclePhase .VERIFY )
2222public 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\n BINARY 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
0 commit comments