|
21 | 21 | import com.semmle.util.process.Env; |
22 | 22 | import com.semmle.util.projectstructure.ProjectLayout; |
23 | 23 | import com.semmle.util.trap.TrapWriter; |
| 24 | +import java.io.BufferedReader; |
24 | 25 | import java.io.File; |
25 | 26 | import java.io.IOException; |
| 27 | +import java.io.InputStreamReader; |
26 | 28 | import java.io.Reader; |
27 | 29 | import java.lang.ProcessBuilder.Redirect; |
28 | 30 | import java.net.URI; |
@@ -562,7 +564,32 @@ private void extractSource() throws IOException { |
562 | 564 | } |
563 | 565 | } |
564 | 566 |
|
| 567 | + /** Returns true if yarn is installed, otherwise prints a warning and returns false. */ |
| 568 | + private boolean verifyYarnInstallation() { |
| 569 | + ProcessBuilder pb = new ProcessBuilder(Arrays.asList("yarn", "-v")); |
| 570 | + try { |
| 571 | + Process process = pb.start(); |
| 572 | + boolean completed = process.waitFor(this.installDependenciesTimeout, TimeUnit.MILLISECONDS); |
| 573 | + if (!completed) { |
| 574 | + System.err.println("Yarn could not be launched. Timeout during 'yarn -v'."); |
| 575 | + return false; |
| 576 | + } |
| 577 | + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| 578 | + String version = reader.readLine(); |
| 579 | + System.out.println("Found yarn version: " + version); |
| 580 | + return true; |
| 581 | + } catch (IOException | InterruptedException ex) { |
| 582 | + System.err.println( |
| 583 | + "Yarn not found. Please put 'yarn' on the PATH for automatic dependency installation."); |
| 584 | + Exceptions.ignore(ex, "Continue without dependency installation"); |
| 585 | + return false; |
| 586 | + } |
| 587 | + } |
| 588 | + |
565 | 589 | protected void installDependencies(Set<Path> filesToExtract) { |
| 590 | + if (!verifyYarnInstallation()) { |
| 591 | + return; |
| 592 | + } |
566 | 593 | for (Path file : filesToExtract) { |
567 | 594 | if (file.getFileName().toString().equals("package.json")) { |
568 | 595 | System.out.println("Installing dependencies from " + file); |
|
0 commit comments