1
1
package dotty .tools .scripting
2
2
3
3
import java .io .File
4
- import java .nio .file .{Files , Paths , Path }
5
- import dotty .tools .dotc .util .SourceFile
6
- import java .net .{ URL , URLClassLoader }
4
+ import java .nio .file .Path
5
+ import java .net .URLClassLoader
7
6
import java .lang .reflect .{ Modifier , Method }
8
7
9
-
10
8
/** Main entry point to the Scripting execution engine */
11
9
object Main :
12
10
/** All arguments before -script <target_script> are compiler arguments.
13
11
All arguments afterwards are script arguments.*/
14
12
private def distinguishArgs (args : Array [String ]): (Array [String ], File , Array [String ], Boolean ) =
15
- // NOTE: if -script is required but not present, quit with error.
13
+ // NOTE: if -script <scriptName> not present, quit with error.
16
14
val (leftArgs, rest) = args.splitAt(args.indexOf(" -script" ))
17
15
if ( rest.size < 2 ) then
18
16
sys.error(s " missing: -script <scriptName> " )
@@ -38,7 +36,7 @@ object Main:
38
36
case list => list
39
37
}
40
38
41
- val (mainClassName, mainMethod) = detectMainMethod (outDir, classpath, scriptFile)
39
+ val (mainClassName, mainMethod) = detectMainClassAndMethod (outDir, classpath, scriptFile)
42
40
43
41
if saveJar then
44
42
// write a standalone jar to the script parent directory
@@ -58,13 +56,12 @@ object Main:
58
56
59
57
private def writeJarfile (outDir : Path , scriptFile : File , scriptArgs: Array [String ],
60
58
classpath: String , mainClassName : String ): Unit =
61
- import java .net .{URI , URL }
62
59
val jarTargetDir : Path = Option (scriptFile.toPath.getParent) match {
63
60
case None => sys.error(s " no parent directory for script file [ $scriptFile] " )
64
61
case Some (parent) => parent
65
62
}
66
63
67
- val scriptBasename = scriptFile.getName.takeWhile(_!= '.' )
64
+ def scriptBasename = scriptFile.getName.takeWhile(_!= '.' )
68
65
val jarPath = s " $jarTargetDir/ $scriptBasename.jar "
69
66
70
67
val cpPaths = classpath.split(pathsep).map {
@@ -87,7 +84,7 @@ object Main:
87
84
writer.writeAllFrom(Directory (outDir))
88
85
end writeJarfile
89
86
90
- private def detectMainMethod (outDir : Path , classpath : String ,
87
+ private def detectMainClassAndMethod (outDir : Path , classpath : String ,
91
88
scriptFile : File ): (String , Method ) =
92
89
val outDirURL = outDir.toUri.toURL
93
90
val classpathUrls = classpath.split(pathsep).map(File (_).toURI.toURL)
@@ -127,7 +124,7 @@ object Main:
127
124
s " Detected the following main methods: \n ${candidates.mkString(" \n " )}" )
128
125
case m :: Nil => m
129
126
end match
130
- end detectMainMethod
127
+ end detectMainClassAndMethod
131
128
132
129
def pathsep = sys.props(" path.separator" )
133
130
0 commit comments