@@ -81,6 +81,9 @@ case class Settings(
8181 def withSave : Settings =
8282 this .copy(save = true )
8383
84+ def noSave : Settings =
85+ this .copy(save = false )
86+
8487 def withModeShouldBePossibleRun : Settings =
8588 this .copy(modeShouldBePossibleRun = true )
8689
@@ -135,6 +138,8 @@ object MainGenericRunner {
135138 )
136139 case " -save" :: tail =>
137140 process(tail, settings.withSave)
141+ case " -nosave" :: tail =>
142+ process(tail, settings.noSave)
138143 case " -with-compiler" :: tail =>
139144 process(tail, settings.withCompiler)
140145 case (o @ javaOption(striped)) :: tail =>
@@ -207,18 +212,20 @@ object MainGenericRunner {
207212 case ExecuteMode .Script =>
208213 val targetScript = Paths .get(settings.targetScript).toFile
209214 val targetJar = settings.targetScript.replaceAll(" [.][^\\ /]*$" , " " )+ " .jar"
210- val precompiledJar = Paths .get (targetJar).toFile
215+ val precompiledJar = File (targetJar)
211216 val mainClass = if ! precompiledJar.isFile then " " else Jar (targetJar).mainClass.getOrElse(" " )
212- val jarIsValid = mainClass.nonEmpty && precompiledJar.lastModified >= targetScript.lastModified
217+ val jarIsValid = mainClass.nonEmpty && precompiledJar.lastModified >= targetScript.lastModified && settings.save
213218 if jarIsValid then
214219 // precompiledJar exists, is newer than targetScript, and manifest defines a mainClass
215220 sys.props(" script.path" ) = targetScript.toPath.toAbsolutePath.normalize.toString
216221 val scalaClasspath = ClasspathFromClassloader (Thread .currentThread().getContextClassLoader).split(classpathSeparator)
217222 val newClasspath = (settings.classPath.flatMap(_.split(classpathSeparator).filter(_.nonEmpty)) ++ removeCompiler(scalaClasspath) :+ " ." ).map(File (_).toURI.toURL)
218- if mainClass.nonEmpty then
223+ val res = if mainClass.nonEmpty then
219224 ObjectRunner .runAndCatch(newClasspath :+ File (targetJar).toURI.toURL, mainClass, settings.scriptArgs)
220225 else
221226 Some (IllegalArgumentException (s " No main class defined in manifest in jar: $precompiledJar" ))
227+ errorFn(" " , res)
228+
222229 else
223230 val properArgs =
224231 List (" -classpath" , settings.classPath.mkString(classpathSeparator)).filter(Function .const(settings.classPath.nonEmpty))
0 commit comments