@@ -569,7 +569,7 @@ public int compare(File f1, File f2) {
569
569
}
570
570
};
571
571
572
- class FileExtractors {
572
+ public class FileExtractors {
573
573
FileExtractor defaultExtractor ;
574
574
Map <String , FileExtractor > customExtractors = new LinkedHashMap <>();
575
575
@@ -580,6 +580,10 @@ class FileExtractors {
580
580
public FileExtractor forFile (Path f ) {
581
581
return customExtractors .getOrDefault (FileUtil .extension (f ), defaultExtractor );
582
582
}
583
+
584
+ public FileType fileType (Path f ) {
585
+ return forFile (f ).getFileType (f .toFile ());
586
+ }
583
587
}
584
588
585
589
/** Extract all supported candidate files that pass the filters. */
@@ -614,11 +618,11 @@ private void extractSource() throws IOException {
614
618
if (!tsconfigFiles .isEmpty ()) {
615
619
dependencyInstallationResult = this .preparePackagesAndDependencies (filesToExtract );
616
620
}
621
+ Set <Path > extractedFiles = new LinkedHashSet <>();
617
622
618
623
// extract TypeScript projects and files
619
- Set <Path > extractedFiles =
620
- extractTypeScript (
621
- defaultExtractor , filesToExtract , tsconfigFiles , dependencyInstallationResult );
624
+ extractTypeScript (filesToExtract , extractedFiles ,
625
+ extractors , tsconfigFiles , dependencyInstallationResult );
622
626
623
627
boolean hasTypeScriptFiles = extractedFiles .size () > 0 ;
624
628
@@ -959,12 +963,11 @@ private ExtractorConfig mkExtractorConfig() {
959
963
}
960
964
961
965
private Set <Path > extractTypeScript (
962
- FileExtractor extractor ,
963
966
Set <Path > files ,
967
+ Set <Path > extractedFiles ,
968
+ FileExtractors extractors ,
964
969
List <Path > tsconfig ,
965
970
DependencyInstallationResult deps ) {
966
- Set <Path > extractedFiles = new LinkedHashSet <>();
967
-
968
971
if (hasTypeScriptFiles (files ) || !tsconfig .isEmpty ()) {
969
972
ExtractorState extractorState = new ExtractorState ();
970
973
TypeScriptParser tsParser = extractorState .getTypeScriptParser ();
@@ -993,7 +996,7 @@ private Set<Path> extractTypeScript(
993
996
Path sourcePath = sourceFile .toPath ();
994
997
if (!files .contains (normalizePath (sourcePath ))) continue ;
995
998
if (!project .getOwnFiles ().contains (sourceFile ) && explicitlyIncludedFiles .contains (sourceFile )) continue ;
996
- if (! FileType . TYPESCRIPT . getExtensions (). contains ( FileUtil . extension ( sourcePath )) ) {
999
+ if (extractors . fileType ( sourcePath ) != FileType . TYPESCRIPT ) {
997
1000
// For the time being, skip non-TypeScript files, even if the TypeScript
998
1001
// compiler can parse them for us.
999
1002
continue ;
@@ -1003,7 +1006,7 @@ private Set<Path> extractTypeScript(
1003
1006
}
1004
1007
}
1005
1008
typeScriptFiles .sort (PATH_ORDERING );
1006
- extractTypeScriptFiles (typeScriptFiles , extractedFiles , extractor , extractorState );
1009
+ extractTypeScriptFiles (typeScriptFiles , extractedFiles , extractors , extractorState );
1007
1010
tsParser .closeProject (projectFile );
1008
1011
}
1009
1012
@@ -1017,12 +1020,12 @@ private Set<Path> extractTypeScript(
1017
1020
List <Path > remainingTypeScriptFiles = new ArrayList <>();
1018
1021
for (Path f : files ) {
1019
1022
if (!extractedFiles .contains (f )
1020
- && FileType . forFileExtension ( f . toFile () ) == FileType .TYPESCRIPT ) {
1023
+ && extractors . fileType ( f ) == FileType .TYPESCRIPT ) {
1021
1024
remainingTypeScriptFiles .add (f );
1022
1025
}
1023
1026
}
1024
1027
if (!remainingTypeScriptFiles .isEmpty ()) {
1025
- extractTypeScriptFiles (remainingTypeScriptFiles , extractedFiles , extractor , extractorState );
1028
+ extractTypeScriptFiles (remainingTypeScriptFiles , extractedFiles , extractors , extractorState );
1026
1029
}
1027
1030
1028
1031
// The TypeScript compiler instance is no longer needed.
@@ -1108,7 +1111,7 @@ public void verifyTypeScriptInstallation(ExtractorState extractorState) {
1108
1111
public void extractTypeScriptFiles (
1109
1112
List <Path > files ,
1110
1113
Set <Path > extractedFiles ,
1111
- FileExtractor extractor ,
1114
+ FileExtractors extractors ,
1112
1115
ExtractorState extractorState ) {
1113
1116
List <File > list = files
1114
1117
.stream ()
@@ -1117,7 +1120,7 @@ public void extractTypeScriptFiles(
1117
1120
extractorState .getTypeScriptParser ().prepareFiles (list );
1118
1121
for (Path path : files ) {
1119
1122
extractedFiles .add (path );
1120
- extract (extractor , path , extractorState );
1123
+ extract (extractors . forFile ( path ) , path , extractorState );
1121
1124
}
1122
1125
}
1123
1126
0 commit comments