@Test public void runWithCorrectMavenProjectPath() throws InterruptedException, TimeoutException, IOException { String projectPath = testResourceDirectory + File.separator + "projects" + File.separator + "demo-with-correct-pom" + File.separator; ClassMaker.compile(projectPath); Assert.assertTrue(new File(projectPath + "target").exists()); }
public static void compile(String projectPath) throws IOException, TimeoutException, InterruptedException { Runtime runtime = Runtime.getRuntime(); boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0; String mvnCommand = (isWindows ? "mvn.cmd" : "mvn") + " clean package -f " + projectPath; Process exec = runtime.exec(mvnCommand); Worker worker = new Worker(exec); worker.start(); ProcessStatus ps = worker.getProcessStatus(); try { worker.join(30000); if (ps.exitCode == ProcessStatus.CODE_FAIL) { throw new RuntimeException("Command exec fail,command is: " + mvnCommand); } if (ps.exitCode == ProcessStatus.CODE_STARTED) { worker.interrupt(); throw new TimeoutException(); } } catch (InterruptedException e) { worker.interrupt(); throw e; } }
ClassMaker { public static void compile(String projectPath) throws IOException, TimeoutException, InterruptedException { Runtime runtime = Runtime.getRuntime(); boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0; String mvnCommand = (isWindows ? "mvn.cmd" : "mvn") + " clean package -f " + projectPath; Process exec = runtime.exec(mvnCommand); Worker worker = new Worker(exec); worker.start(); ProcessStatus ps = worker.getProcessStatus(); try { worker.join(30000); if (ps.exitCode == ProcessStatus.CODE_FAIL) { throw new RuntimeException("Command exec fail,command is: " + mvnCommand); } if (ps.exitCode == ProcessStatus.CODE_STARTED) { worker.interrupt(); throw new TimeoutException(); } } catch (InterruptedException e) { worker.interrupt(); throw e; } } }
ClassMaker { public static void compile(String projectPath) throws IOException, TimeoutException, InterruptedException { Runtime runtime = Runtime.getRuntime(); boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0; String mvnCommand = (isWindows ? "mvn.cmd" : "mvn") + " clean package -f " + projectPath; Process exec = runtime.exec(mvnCommand); Worker worker = new Worker(exec); worker.start(); ProcessStatus ps = worker.getProcessStatus(); try { worker.join(30000); if (ps.exitCode == ProcessStatus.CODE_FAIL) { throw new RuntimeException("Command exec fail,command is: " + mvnCommand); } if (ps.exitCode == ProcessStatus.CODE_STARTED) { worker.interrupt(); throw new TimeoutException(); } } catch (InterruptedException e) { worker.interrupt(); throw e; } }  }
ClassMaker { public static void compile(String projectPath) throws IOException, TimeoutException, InterruptedException { Runtime runtime = Runtime.getRuntime(); boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0; String mvnCommand = (isWindows ? "mvn.cmd" : "mvn") + " clean package -f " + projectPath; Process exec = runtime.exec(mvnCommand); Worker worker = new Worker(exec); worker.start(); ProcessStatus ps = worker.getProcessStatus(); try { worker.join(30000); if (ps.exitCode == ProcessStatus.CODE_FAIL) { throw new RuntimeException("Command exec fail,command is: " + mvnCommand); } if (ps.exitCode == ProcessStatus.CODE_STARTED) { worker.interrupt(); throw new TimeoutException(); } } catch (InterruptedException e) { worker.interrupt(); throw e; } }  static void compile(String projectPath); }
ClassMaker { public static void compile(String projectPath) throws IOException, TimeoutException, InterruptedException { Runtime runtime = Runtime.getRuntime(); boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0; String mvnCommand = (isWindows ? "mvn.cmd" : "mvn") + " clean package -f " + projectPath; Process exec = runtime.exec(mvnCommand); Worker worker = new Worker(exec); worker.start(); ProcessStatus ps = worker.getProcessStatus(); try { worker.join(30000); if (ps.exitCode == ProcessStatus.CODE_FAIL) { throw new RuntimeException("Command exec fail,command is: " + mvnCommand); } if (ps.exitCode == ProcessStatus.CODE_STARTED) { worker.interrupt(); throw new TimeoutException(); } } catch (InterruptedException e) { worker.interrupt(); throw e; } }  static void compile(String projectPath);  }