@@ -11,21 +11,30 @@ public InputSourceDetector() {
11
11
}
12
12
13
13
public boolean isReadable (String programPath ) {
14
- if (programPath .startsWith (RESOURCE_PREFIX )) {
15
- String path = programPath .substring (RESOURCE_PREFIX .length ());
16
- return getClass ().getResource (basePath + path ) != null ;
14
+ if (basePath .startsWith (RESOURCE_PREFIX ) || programPath .startsWith (RESOURCE_PREFIX )) {
15
+ String base = removePrefixIfExists (basePath );
16
+ String path = removePrefixIfExists (programPath );
17
+ return getClass ().getResource (base + path ) != null ;
17
18
} else {
18
19
Path path = Path .of (basePath , programPath );
19
20
return Files .isReadable (path ) && Files .isRegularFile (path );
20
21
}
21
22
}
22
23
23
24
public InputSource toInputSource (String programPath ) {
24
- if (programPath .startsWith (RESOURCE_PREFIX )) {
25
- String path = programPath .substring (RESOURCE_PREFIX .length ());
26
- return new InputSourceResource (basePath + path );
25
+ if (basePath .startsWith (RESOURCE_PREFIX ) || programPath .startsWith (RESOURCE_PREFIX )) {
26
+ String base = removePrefixIfExists (basePath );
27
+ String path = removePrefixIfExists (programPath );
28
+ return new InputSourceResource (base + path );
27
29
} else {
28
30
return new InputSourceFile (basePath + programPath );
29
31
}
30
32
}
33
+
34
+ private String removePrefixIfExists (String path ) {
35
+ if (path .startsWith (RESOURCE_PREFIX )) {
36
+ return path .substring (RESOURCE_PREFIX .length ());
37
+ }
38
+ return path ;
39
+ }
31
40
}
0 commit comments