@@ -7,7 +7,7 @@ import java.net.URL
7
7
import java.nio.file.Paths
8
8
9
9
class LibraryFactory (
10
- var defaultResolutionInfo : LibraryResolutionInfo ,
10
+ val resolutionInfoProvider : ResolutionInfoProvider ,
11
11
private val parsers : Map <String , LibraryResolutionInfoParser > = defaultParsers,
12
12
) {
13
13
fun parseReferenceWithArgs (str : String ): Pair <LibraryReference , List <Variable >> {
@@ -25,16 +25,16 @@ class LibraryFactory(
25
25
26
26
private fun parseResolutionInfo (string : String ): LibraryResolutionInfo {
27
27
// In case of empty string after `@`: %use lib@
28
- if (string.isBlank()) return defaultResolutionInfo
28
+ if (string.isBlank()) return resolutionInfoProvider.get()
29
29
30
30
val (type, vars) = parseCall(string, Brackets .SQUARE )
31
- val parser = parsers[type] ? : return LibraryResolutionInfo .getInfoByRef (type)
31
+ val parser = parsers[type] ? : return resolutionInfoProvider.get (type)
32
32
return parser.getInfo(vars)
33
33
}
34
34
35
35
private fun parseReference (string : String ): LibraryReference {
36
36
val sepIndex = string.indexOf(' @' )
37
- if (sepIndex == - 1 ) return LibraryReference (defaultResolutionInfo , string)
37
+ if (sepIndex == - 1 ) return LibraryReference (resolutionInfoProvider.get() , string)
38
38
39
39
val nameString = string.substring(0 , sepIndex)
40
40
val infoString = string.substring(sepIndex + 1 )
@@ -43,8 +43,6 @@ class LibraryFactory(
43
43
}
44
44
45
45
companion object {
46
- fun withDefaultDirectoryResolution (dir : File ) = LibraryFactory (LibraryResolutionInfo .ByDir (dir))
47
-
48
46
private val defaultParsers = listOf (
49
47
LibraryResolutionInfoParser .make(" ref" , listOf (Parameter .Required (" ref" ))) { args ->
50
48
LibraryResolutionInfo .getInfoByRef(args[" ref" ] ? : error(" Argument 'ref' should be specified" ))
@@ -59,5 +57,9 @@ class LibraryFactory(
59
57
LibraryResolutionInfo .ByURL (URL (args[" url" ] ? : error(" Argument 'url' should be specified" )))
60
58
},
61
59
).map { it.name to it }.toMap()
60
+
61
+ val EMPTY = LibraryFactory (EmptyResolutionInfoProvider )
62
+
63
+ fun withDefaultDirectoryResolution (dir : File ) = LibraryFactory (StandardResolutionInfoProvider (LibraryResolutionInfo .ByDir (dir)))
62
64
}
63
65
}
0 commit comments