|
52 | 52 | import com.semmle.util.exception.UserError; |
53 | 53 | import com.semmle.util.extraction.ExtractorOutputConfig; |
54 | 54 | import com.semmle.util.files.FileUtil; |
| 55 | +import com.semmle.util.files.FileUtil8; |
55 | 56 | import com.semmle.util.io.WholeIO; |
56 | 57 | import com.semmle.util.io.csv.CSVReader; |
57 | 58 | import com.semmle.util.language.LegacyLanguage; |
@@ -433,23 +434,41 @@ private boolean addPathPattern(Set<Path> patterns, Path base, String pattern) { |
433 | 434 | return true; |
434 | 435 | } |
435 | 436 |
|
| 437 | + /** |
| 438 | + * Returns whether the autobuilder has seen code. |
| 439 | + * This is overridden in tests. |
| 440 | + */ |
| 441 | + protected boolean hasSeenCode() { |
| 442 | + return seenCode; |
| 443 | + } |
| 444 | + |
436 | 445 | /** Perform extraction. */ |
437 | 446 | public int run() throws IOException { |
438 | 447 | startThreadPool(); |
439 | 448 | try { |
440 | | - extractSource(); |
441 | | - extractExterns(); |
| 449 | + CompletableFuture<?> sourceFuture = extractSource(); |
| 450 | + sourceFuture.join(); // wait for source extraction to complete |
| 451 | + if (hasSeenCode()) { // don't bother with the externs if no code was seen |
| 452 | + extractExterns(); |
| 453 | + } |
442 | 454 | extractXml(); |
443 | 455 | } finally { |
444 | 456 | shutdownThreadPool(); |
445 | 457 | } |
446 | | - if (!seenCode) { |
| 458 | + if (!hasSeenCode()) { |
447 | 459 | if (seenFiles) { |
448 | 460 | warn("Only found JavaScript or TypeScript files that were empty or contained syntax errors."); |
449 | 461 | } else { |
450 | 462 | warn("No JavaScript or TypeScript code found."); |
451 | 463 | } |
452 | | - return -1; |
| 464 | + // ensuring that the finalize steps detects that no code was seen. |
| 465 | + Path srcFolder = Paths.get(EnvironmentVariables.getWipDatabase(), "src"); |
| 466 | + // check that the srcFolder is empty |
| 467 | + if (Files.list(srcFolder).count() == 0) { |
| 468 | + // Non-recursive delete because "src/" should be empty. |
| 469 | + FileUtil8.delete(srcFolder); |
| 470 | + } |
| 471 | + return 0; |
453 | 472 | } |
454 | 473 | return 0; |
455 | 474 | } |
@@ -571,7 +590,7 @@ public FileType fileType(Path f) { |
571 | 590 | } |
572 | 591 |
|
573 | 592 | /** Extract all supported candidate files that pass the filters. */ |
574 | | - private void extractSource() throws IOException { |
| 593 | + private CompletableFuture<?> extractSource() throws IOException { |
575 | 594 | // default extractor |
576 | 595 | FileExtractor defaultExtractor = |
577 | 596 | new FileExtractor(mkExtractorConfig(), outputConfig, trapCache); |
@@ -618,7 +637,7 @@ private void extractSource() throws IOException { |
618 | 637 | boolean hasTypeScriptFiles = extractedFiles.size() > 0; |
619 | 638 |
|
620 | 639 | // extract remaining files |
621 | | - extractFiles( |
| 640 | + return extractFiles( |
622 | 641 | filesToExtract, extractedFiles, extractors, |
623 | 642 | f -> !(hasTypeScriptFiles && isFileDerivedFromTypeScriptFile(f, extractedFiles))); |
624 | 643 | } |
|
0 commit comments