2626import java .util .List ;
2727import java .util .Map ;
2828import java .util .Set ;
29+ import java .util .concurrent .CompletableFuture ;
2930import java .util .concurrent .ExecutorService ;
3031import java .util .concurrent .Executors ;
3132import java .util .concurrent .TimeUnit ;
@@ -621,6 +622,13 @@ private void extractSource() throws IOException {
621622 dependencyInstallationResult = this .preparePackagesAndDependencies (filesToExtract );
622623 }
623624 Set <Path > extractedFiles = new LinkedHashSet <>();
625+
626+ // Extract HTML files as they may contain TypeScript
627+ CompletableFuture <?> htmlFuture = extractFiles (
628+ filesToExtract , extractedFiles , extractors ,
629+ f -> extractors .fileType (f ) == FileType .HTML );
630+
631+ htmlFuture .join (); // Wait for HTML extraction to be finished.
624632
625633 // extract TypeScript projects and files
626634 extractTypeScript (filesToExtract , extractedFiles ,
@@ -634,21 +642,23 @@ private void extractSource() throws IOException {
634642 f -> !(hasTypeScriptFiles && isFileDerivedFromTypeScriptFile (f , extractedFiles )));
635643 }
636644
637- private void extractFiles (
645+ private CompletableFuture <?> extractFiles (
638646 Set <Path > filesToExtract ,
639647 Set <Path > extractedFiles ,
640648 FileExtractors extractors ,
641649 Predicate <Path > shouldExtract ) {
642650
651+ List <CompletableFuture <?>> futures = new ArrayList <>();
643652 for (Path f : filesToExtract ) {
644653 if (extractedFiles .contains (f ))
645654 continue ;
646655 if (!shouldExtract .test (f )) {
647656 continue ;
648657 }
649658 extractedFiles .add (f );
650- extract (extractors .forFile (f ), f , null );
659+ futures . add ( extract (extractors .forFile (f ), f , null ) );
651660 }
661+ return CompletableFuture .allOf (futures .toArray (new CompletableFuture [0 ]));
652662 }
653663
654664 /**
@@ -1164,10 +1174,13 @@ private SourceType getSourceType() {
11641174 * <p>If the state is {@code null}, the extraction job will be submitted to the {@link
11651175 * #threadPool}, otherwise extraction will happen on the main thread.
11661176 */
1167- protected void extract (FileExtractor extractor , Path file , ExtractorState state ) {
1168- if (state == null && threadPool != null )
1169- threadPool .submit (() -> doExtract (extractor , file , state ));
1170- else doExtract (extractor , file , state );
1177+ protected CompletableFuture <?> extract (FileExtractor extractor , Path file , ExtractorState state ) {
1178+ if (state == null && threadPool != null ) {
1179+ return CompletableFuture .runAsync (() -> doExtract (extractor , file , state ), threadPool );
1180+ } else {
1181+ doExtract (extractor , file , state );
1182+ return CompletableFuture .completedFuture (null );
1183+ }
11711184 }
11721185
11731186 private void doExtract (FileExtractor extractor , Path file , ExtractorState state ) {
0 commit comments