Unverified Commit c839c2be authored by Romain Reuillon's avatar Romain Reuillon
Browse files

Update to scala 2.12.

parent 88e4bab8
......@@ -14,9 +14,7 @@ object BuildSystem {
val credential = Path.userHome / ".sbt" / "openmole.credentials"
lazy val settings =
Seq(scalacOptions ++= Seq("-feature", "-language:reflectiveCalls", "-language:implicitConversions",
"-language:existentials", "-language:postfixOps", "-Yinline-warnings")) ++
(if (credential.exists()) Seq(credentials += Credentials(credential)) else Seq.empty) ++ scalariformDefaults
(if (credential.exists()) Seq(credentials += Credentials(credential)) else Seq.empty) ++ scalariformDefaults
protected lazy val scalariformDefaults =
Seq(
......
version in ThisBuild := "1.6-SNAPSHOT"
version in ThisBuild := "1.7-SNAPSHOT"
......@@ -8,7 +8,7 @@ def settings = Seq(
resolvers += Resolver.sonatypeRepo("snapshots"),
resolvers += Resolver.sonatypeRepo("releases"),
resolvers += Resolver.bintrayRepo("projectseptemberinc", "maven"), // For freek
scalaVersion in Global := "2.11.8",
scalaVersion in Global := "2.12.2",
scalacOptions ++= Seq("-deprecation"),
publishArtifact in (packageDoc in publishLocal) := false,
publishArtifact in (packageSrc in publishLocal) := false,
......@@ -34,8 +34,8 @@ lazy val json4s = OsgiProject(dir, "org.json4s",
exports = Seq("org.json4s.*"),
privatePackages = Seq("!scala.*", "!org.slf4j.*", "!com.thoughtworks.paranamer.*", "*"),
imports = Seq("scala.*", "org.slf4j.*", "com.thoughtworks.paranamer.*", "")) settings (
libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.4.0",
version := "3.4.0") settings(settings: _*)
libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.5.0",
version := "3.5.0") settings(settings: _*)
lazy val logback = OsgiProject(dir, "ch.qos.logback", exports = Seq("ch.qos.logback.*", "org.slf4j.impl"), dynamicImports = Seq("*")) settings
(libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.0.9", version := "1.0.9") settings(settings: _*)
......@@ -91,7 +91,6 @@ lazy val scalaLang = OsgiProject(
"jline" % "jline" % "2.12.1",
"org.scala-stm" %% "scala-stm" % "0.8",
"com.typesafe" % "config" % "1.2.1",
"com.github.scala-incubator.io" %% "scala-io-core" % "0.4.3",
"org.scala-lang" % "scala-compiler" % scalaVersion.value
)
}, version := scalaVersion.value) settings(settings: _*)
......@@ -135,11 +134,11 @@ lazy val netlogo6 = OsgiProject(
), version := netLogo6Version, scalaVersion := "2.12.1", crossPaths := false) settings(settings: _*)
lazy val scalaTagsVersion = "0.6.2"
lazy val scalaRxVersion = "0.3.1"
lazy val scalaRxVersion = "0.3.2"
lazy val scalaDomVersion = "0.9.1"
lazy val scalaUpickleVersion = "0.4.3"
lazy val scalaUpickleVersion = "0.4.4"
lazy val scalaAutowireVersion = "0.2.6"
lazy val scalajsVersion = "0.6.14"
lazy val scalajsVersion = "0.6.16"
lazy val rx = OsgiProject(dir, "rx", exports = Seq("rx.*")) settings(
libraryDependencies ++= Seq("com.lihaoyi" %% "scalarx" % scalaRxVersion),
......@@ -159,8 +158,8 @@ lazy val scalaTags = OsgiProject(dir, "com.scalatags", exports = Seq("scalatags.
lazy val scalatexSite =
OsgiProject(dir, "com.lihaoyi.scalatex-site", exports = Seq("scalatex.*", "ammonite.*", "fastparse.*"), privatePackages = Seq("META-INF.**", "pprint.*", "scalaj.*", "scalaparse.*"), imports = Seq("*")) settings (
libraryDependencies += "com.lihaoyi" %% "scalatex-site" % "0.3.6",
version := "0.3.6") settings(settings: _*)
libraryDependencies += "com.lihaoyi" %% "scalatex-site" % "0.3.7",
version := "0.3.7") settings(settings: _*)
lazy val upickle = OsgiProject(dir, "upickle", exports = Seq("upickle.*", "jawn.*", "derive.*", "sourcecode.*"), imports = Seq("*")) settings(
libraryDependencies ++= Seq("com.lihaoyi" %% "upickle" % scalaUpickleVersion),
......@@ -198,11 +197,11 @@ lazy val mgo = OsgiProject(dir, "mgo") settings(
version := mgoVersion
) dependsOn(monocle, freedsl, math) settings(settings: _*)
lazy val familyVersion = "1.3"
/*lazy val familyVersion = "1.3"
lazy val family = OsgiProject(dir, "fr.iscpif.family") settings(
libraryDependencies += "fr.iscpif" %% "family" % familyVersion,
version := familyVersion
) settings(settings: _*)
) settings(settings: _*)*/
lazy val opencsv = OsgiProject(dir, "au.com.bytecode.opencsv") settings(
libraryDependencies += "net.sf.opencsv" % "opencsv" % "2.3",
......@@ -210,13 +209,13 @@ lazy val opencsv = OsgiProject(dir, "au.com.bytecode.opencsv") settings(
) settings(settings: _*)
lazy val arm = OsgiProject(dir, "com.jsuereth.scala-arm") settings(
libraryDependencies += "com.jsuereth" %% "scala-arm" % "1.4",
version := "1.4",
libraryDependencies += "com.jsuereth" %% "scala-arm" % "2.0",
version := "2.0",
exportPackage := Seq("resource.*")) settings(settings: _*)
lazy val scalajHttp = OsgiProject(dir, "org.scalaj.scalaj-http") settings(
libraryDependencies += "org.scalaj" %% "scalaj-http" % "0.3.15",
version := "0.3.15",
libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.3.0",
version := "2.3.0",
exportPackage := Seq("scalaj.http.*")
) settings(settings: _*)
......@@ -225,15 +224,15 @@ lazy val scopt = OsgiProject(dir, "com.github.scopt", exports = Seq("scopt.*"))
version := "3.5.0"
) settings(settings: _*)
lazy val scalabc = OsgiProject(dir, "fr.iscpif.scalabc", privatePackages = Seq("!scala.*", "!junit.*", "*")) settings(
/*lazy val scalabc = OsgiProject(dir, "fr.iscpif.scalabc", privatePackages = Seq("!scala.*", "!junit.*", "*")) settings(
libraryDependencies += "fr.iscpif" %% "scalabc" % "0.4",
version := "0.4"
) settings(settings: _*)
) settings(settings: _*)*/
lazy val async =
OsgiProject(dir, "scala-async") settings (
libraryDependencies += "org.scala-lang.modules" %% "scala-async" % "0.9.1",
version := "0.9.1",
libraryDependencies += "org.scala-lang.modules" %% "scala-async" % "0.9.6",
version := "0.9.6",
exportPackage := Seq("scala.async.*")) settings(settings: _*)
lazy val mathVersion = "3.6.1"
......@@ -269,9 +268,9 @@ lazy val jgit = OsgiProject(dir, "org.eclipse.jgit", privatePackages = Seq("!sca
lazy val txtmark = OsgiProject(dir, "com.github.rjeschke.txtmark", privatePackages = Seq("!scala.*", "!org.slf4j.*", "*")) settings (
libraryDependencies += "com.github.rjeschke" % "txtmark" % "0.13", version := "0.13" ) settings(settings: _*)
lazy val clapperVersion = "1.0.5"
lazy val clapperVersion = "1.1.2"
lazy val clapper = OsgiProject(dir, "org.clapper", exports = Seq("!scala.*","!grizzled.*","!jline.*","!org.fusesource.*","!org.slf4j.*","*")) settings (
libraryDependencies += "org.clapper" % "classutil_2.11" % clapperVersion, version := clapperVersion) settings(settings: _*)
libraryDependencies += "org.clapper" %% "classutil" % clapperVersion, version := clapperVersion) settings(settings: _*)
val monocleVersion = "1.3.2"
......@@ -296,6 +295,6 @@ lazy val config = OsgiProject(dir, "org.apache.commons.configuration2",
version := "2.1") settings(settings: _*) dependsOn (logging)
lazy val sourceCode = OsgiProject(dir, "sourcecode") settings (
libraryDependencies += "com.lihaoyi" %% "sourcecode" % "0.1.2",
version := "0.1.2"
libraryDependencies += "com.lihaoyi" %% "sourcecode" % "0.1.3",
version := "0.1.3"
) settings(settings: _*)
......@@ -4,6 +4,6 @@ resolvers += Classpaths.sbtPluginSnapshots
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
addSbtPlugin("org.openmole" % "openmole-buildsystem-plugin" % "1.6-SNAPSHOT")
addSbtPlugin("org.openmole" % "openmole-buildsystem-plugin" % "1.7-SNAPSHOT")
addSbtPlugin("com.eed3si9n" % "sbt-dirty-money" % "0.1.0")
......@@ -24,6 +24,7 @@ import org.openmole.core.buildinfo
import org.openmole.core.console.ScalaREPL
import org.openmole.core.dsl._
import org.openmole.core.exception.UserBadDataError
import org.openmole.core.fileservice.FileService
import org.openmole.core.project._
import org.openmole.core.tools.io.Prettifier._
import org.openmole.core.workflow.execution.Environment
......@@ -91,7 +92,7 @@ class Command(val console: ScalaREPL, val variables: ConsoleVariables) { command
} println(s"${error.level.toString}: ${exceptionToString(error.exception)}")
}
def verify(mole: Mole): Unit = Validation(mole).foreach(println)
def verify(mole: Mole)(implicit newFile: NewFile, fileService: FileService): Unit = Validation(mole).foreach(println)
def encrypted(implicit cypher: Cypher): String = encrypt(Console.askPassword())
......@@ -99,7 +100,7 @@ class Command(val console: ScalaREPL, val variables: ConsoleVariables) { command
println(s"""You are running OpenMOLE ${buildinfo.version} - ${buildinfo.name}
|built on the ${buildinfo.version.generationDate}.""".stripMargin)
def loadAny(file: File, args: Seq[String] = Seq.empty)(implicit services: Services): AnyRef =
def loadAny(file: File, args: Seq[String] = Seq.empty)(implicit services: Services): Any =
try {
val project =
new Project(
......@@ -112,7 +113,7 @@ class Command(val console: ScalaREPL, val variables: ConsoleVariables) { command
project.compile(file, args) match {
case ScriptFileDoesNotExists() throw new IOException("File " + file + " doesn't exist.")
case e: CompilationError throw e.error
case Compiled(compiled) compiled.eval()
case Compiled(compiled) compiled.apply()
}
}
finally ConsoleVariables.bindVariables(console, variables)
......@@ -123,7 +124,7 @@ class Command(val console: ScalaREPL, val variables: ConsoleVariables) { command
case x throw new UserBadDataError("The result is not a puzzle")
}
def modules(urls: OptionalArgument[Seq[String]] = None)(implicit preference: Preference, randomProvider: RandomProvider, newFile: NewFile): Unit = {
def modules(urls: OptionalArgument[Seq[String]] = None)(implicit preference: Preference, randomProvider: RandomProvider, newFile: NewFile, fileService: FileService): Unit = {
val installedBundles = PluginManager.bundleHashes.map(_.toString).toSet
def installed(components: Seq[String]) = (components.toSet -- installedBundles).isEmpty
......@@ -137,8 +138,8 @@ class Command(val console: ScalaREPL, val variables: ConsoleVariables) { command
}.sorted.foreach(println)
}
def install(name: String*)(implicit preference: Preference, randomProvider: RandomProvider, newFile: NewFile, workspace: Workspace): Unit = install(name)
def install(names: Seq[String], urls: OptionalArgument[Seq[String]] = None)(implicit preference: Preference, randomProvider: RandomProvider, newFile: NewFile, workspace: Workspace): Unit = {
def install(name: String*)(implicit preference: Preference, randomProvider: RandomProvider, newFile: NewFile, workspace: Workspace, fileService: FileService): Unit = install(name)
def install(names: Seq[String], urls: OptionalArgument[Seq[String]] = None)(implicit preference: Preference, randomProvider: RandomProvider, newFile: NewFile, workspace: Workspace, fileService: FileService): Unit = {
val toInstall = urls.getOrElse(module.indexes).flatMap(url module.selectableModules(url)).filter(sm names.contains(sm.module.name))
if (toInstall.isEmpty) println("The module(s) is/are already installed.")
else
......
......@@ -19,6 +19,7 @@ package org.openmole.console
import jline.console.ConsoleReader
import org.openmole.core.console.ScalaREPL
import org.openmole.core.fileservice.FileService
import org.openmole.core.preference.Preference
import org.openmole.core.project._
import org.openmole.core.tools.io.Prettifier._
......@@ -27,6 +28,7 @@ import org.openmole.tool.file._
import org.openmole.tool.logger.Logger
import org.openmole.core.services._
import org.openmole.core.workflow.mole._
import org.openmole.core.workspace.NewFile
import scala.annotation.tailrec
import scala.util._
......@@ -113,9 +115,8 @@ class Console(script: Option[String] = None) {
loop.loopWithExitCode
}
case Some(script)
ScalaREPL.warmup
val scriptFile = new File(script)
val project = new Project(workDirectory.getOrElse(scriptFile.getParentFileSafe))
val project = Project(workDirectory.getOrElse(scriptFile.getParentFileSafe))
project.compile(scriptFile, args) match {
case ScriptFileDoesNotExists()
println("File " + scriptFile + " doesn't exist.")
......@@ -151,7 +152,7 @@ class Console(script: Option[String] = None) {
}
}
def withREPL[T](args: ConsoleVariables)(f: ScalaREPL T) = {
def withREPL[T](args: ConsoleVariables)(f: ScalaREPL T)(implicit newFile: NewFile, fileService: FileService) = {
val loop =
OpenMOLEREPL.newREPL(
args,
......
......@@ -264,7 +264,6 @@ object Application extends Logger {
val server = new GUIServer(port, config.remote, useHTTP, services, config.password)
server.start()
if (config.browse && !config.remote) browse(url)
ScalaREPL.warmup
logger.info(s"Server listening on port $port.")
server.join() match {
case GUIServer.Ok Console.ExitCodes.ok
......
......@@ -14,12 +14,11 @@ name := "openmole-root"
def macroParadise =
addCompilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full)
lazy val scalaVersionValue = "2.11.8"
lazy val scalaVersionValue = "2.12.2"
def defaultSettings = BuildSystem.settings ++
Seq(
organization := "org.openmole",
scalaOrganization := "org.typelevel",
updateOptions := updateOptions.value.withCachedResolution(true),
resolvers += Resolver.sonatypeRepo("snapshots"),
resolvers += Resolver.sonatypeRepo("staging"),
......@@ -224,7 +223,7 @@ lazy val console = OsgiProject(coreDir, "org.openmole.core.console", global = tr
libraryDependencies += Libraries.monocle,
macroParadise,
defaultActivator
) dependsOn(openmoleByteCode, openmoleOSGi) settings (coreSettings: _*)
) dependsOn(openmoleByteCode, openmoleOSGi, workspace, fileService) settings (coreSettings: _*)
lazy val project = OsgiProject(coreDir, "org.openmole.core.project", imports = Seq("*")) dependsOn(console, openmoleDSL, services) settings (OsgiKeys.importPackage := Seq("*")) settings (coreSettings: _*)
......@@ -402,14 +401,14 @@ lazy val modifierHook = OsgiProject(pluginDir, "org.openmole.plugin.hook.modifie
/* Method */
def allMethod = Seq(evolution, directSampling, abc)
def allMethod = Seq(evolution, directSampling)
lazy val evolution = OsgiProject(pluginDir, "org.openmole.plugin.method.evolution", imports = Seq("*")) dependsOn(
openmoleDSL, fileHook, toolsTask, pattern, collectionDomain % "test"
) settings(libraryDependencies += Libraries.mgo, libraryDependencies += Libraries.shapeless) settings (pluginSettings: _*)
lazy val abc = OsgiProject(pluginDir, "org.openmole.plugin.method.abc", imports = Seq("*")) dependsOn(openmoleDSL, fileHook, tools) settings
(libraryDependencies += Libraries.scalabc) settings (pluginSettings: _*)
//lazy val abc = OsgiProject(pluginDir, "org.openmole.plugin.method.abc", imports = Seq("*")) dependsOn(openmoleDSL, fileHook, tools) settings
// (libraryDependencies += Libraries.scalabc) settings (pluginSettings: _*)
lazy val directSampling = OsgiProject(pluginDir, "org.openmole.plugin.method.directsampling", imports = Seq("*")) dependsOn(openmoleDSL, distributionDomain, pattern, modifierDomain) settings (pluginSettings: _*)
......@@ -490,7 +489,7 @@ lazy val server = OsgiProject(
lazy val client = Project("org-openmole-rest-client", restDir / "client") settings(
libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.3.5",
libraryDependencies += "org.apache.httpcomponents" % "httpmime" % "4.3.5",
libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.4.0"
libraryDependencies += "org.json4s" %% "json4s-jackson" % Libraries.json4sVersion
) dependsOn(message, openmoleTar) settings (defaultSettings: _*)
......@@ -591,7 +590,7 @@ lazy val clientToolGUI = OsgiProject(guiClientDir, "org.openmole.gui.client.tool
def guiServerDir = guiDir / "server"
lazy val serverGUI = OsgiProject(guiServerDir, "org.openmole.gui.server.core") settings
(libraryDependencies ++= Seq(Libraries.autowire, Libraries.upickle, Libraries.scalaTags, Libraries.logback, Libraries.scalatra, Libraries.clapper)) dependsOn(
(libraryDependencies ++= Seq(Libraries.autowire, Libraries.upickle, Libraries.scalaTags, Libraries.logback, Libraries.scalatra, Libraries.clapper, Libraries.arm)) dependsOn(
sharedGUI,
dataGUI,
workflow,
......@@ -790,55 +789,55 @@ lazy val api = Project("api", binDir / "target" / "api") settings (defaultSettin
Tar.folder := (UnidocKeys.unidoc in Compile).map(_.head).value
)
lazy val site =
OsgiProject(
binDir,
"org.openmole.site",
singleton = true,
imports = Seq("*"),
settings = defaultSettings ++ scalatex.SbtPlugin.projectSettings ++ assemblySettings
) settings(
organization := "org.openmole.site",
OsgiKeys.exportPackage := Seq("scalatex.openmole.*") ++ OsgiKeys.exportPackage.value,
libraryDependencies += Libraries.scalaLang,
libraryDependencies += Libraries.xstream,
libraryDependencies += Libraries.scalatexSite,
libraryDependencies += Libraries.scalaTags,
libraryDependencies += Libraries.upickle,
libraryDependencies += Libraries.spray,
libraryDependencies += Libraries.lang3,
libraryDependencies += Libraries.toolxitBibtex intransitive(),
libraryDependencies += Libraries.json4s,
libraryDependencies += Libraries.logging,
setExecutable ++= Seq("site"),
assemblyDependenciesPath := assemblyPath.value / "plugins",
resourcesAssemble ++= (Osgi.bundleDependencies in Compile).value.map(b b (assemblyPath.value / "plugins" / b.getName)),
resourcesAssemble += ((resourceDirectory in Compile).value / "site") -> (assemblyPath.value / "site"),
resourcesAssemble += (resourceDirectory in Compile).value -> (assemblyPath.value / "resources"),
resourcesAssemble += ((sourceDirectory in Compile).value / "md") -> (assemblyPath.value / "resources" / "md"),
resourcesAssemble += {
val bundle = OsgiKeys.bundle.value
bundle -> (assemblyPath.value / "plugins" / bundle.getName)
},
resourcesAssemble += (assemble in launcher).value -> (assemblyPath.value / "launcher"),
resourcesAssemble += {
val tar = (Tar.tar in openmole).value
tar -> (assemblyPath.value / "resources" / tar.getName)
},
resourcesAssemble += {
val tar = (Tar.tar in daemon).value
tar -> (assemblyPath.value / "resources" / tar.getName)
},
resourcesAssemble += {
val tar = (Tar.tar in api).value
tar -> (assemblyPath.value / "resources" / tar.getName)
},
resourcesAssemble += (fullOptJS in siteJS in Compile).value.data -> (assemblyPath.value / "resources" / "sitejs.js"),
dependencyFilter := bundleFilter,
dependencyName := rename,
cleanFiles ++= (cleanFiles in openmole).value
) dependsOn (txtmark) dependsOn (toDependencies(openmoleNakedDependencies): _*) dependsOn (toDependencies(openmoleDependencies): _*)
//lazy val site =
// OsgiProject(
// binDir,
// "org.openmole.site",
// singleton = true,
// imports = Seq("*"),
// settings = defaultSettings ++ scalatex.SbtPlugin.projectSettings ++ assemblySettings
// ) settings(
// organization := "org.openmole.site",
// OsgiKeys.exportPackage := Seq("scalatex.openmole.*") ++ OsgiKeys.exportPackage.value,
// libraryDependencies += Libraries.scalaLang,
// libraryDependencies += Libraries.xstream,
// libraryDependencies += Libraries.scalatexSite,
// libraryDependencies += Libraries.scalaTags,
// libraryDependencies += Libraries.upickle,
// libraryDependencies += Libraries.spray,
// libraryDependencies += Libraries.lang3,
// libraryDependencies += Libraries.toolxitBibtex intransitive(),
// libraryDependencies += Libraries.json4s,
// libraryDependencies += Libraries.logging,
// setExecutable ++= Seq("site"),
// assemblyDependenciesPath := assemblyPath.value / "plugins",
// resourcesAssemble ++= (Osgi.bundleDependencies in Compile).value.map(b ⇒ b → (assemblyPath.value / "plugins" / b.getName)),
// resourcesAssemble += ((resourceDirectory in Compile).value / "site") -> (assemblyPath.value / "site"),
// resourcesAssemble += (resourceDirectory in Compile).value -> (assemblyPath.value / "resources"),
// resourcesAssemble += ((sourceDirectory in Compile).value / "md") -> (assemblyPath.value / "resources" / "md"),
// resourcesAssemble += {
// val bundle = OsgiKeys.bundle.value
// bundle -> (assemblyPath.value / "plugins" / bundle.getName)
// },
// resourcesAssemble += (assemble in launcher).value -> (assemblyPath.value / "launcher"),
// resourcesAssemble += {
// val tar = (Tar.tar in openmole).value
// tar -> (assemblyPath.value / "resources" / tar.getName)
// },
// resourcesAssemble += {
// val tar = (Tar.tar in daemon).value
// tar -> (assemblyPath.value / "resources" / tar.getName)
// },
// resourcesAssemble += {
// val tar = (Tar.tar in api).value
// tar -> (assemblyPath.value / "resources" / tar.getName)
// },
// resourcesAssemble += (fullOptJS in siteJS in Compile).value.data -> (assemblyPath.value / "resources" / "sitejs.js"),
// dependencyFilter := bundleFilter,
// dependencyName := rename,
// cleanFiles ++= (cleanFiles in openmole).value
// ) dependsOn (txtmark) dependsOn (toDependencies(openmoleNakedDependencies): _*) dependsOn (toDependencies(openmoleDependencies): _*)
//
lazy val siteJS = OsgiProject(binDir, "org.openmole.sitejs") settings(
......
......@@ -17,7 +17,7 @@
package org.openmole.core.console
import org.openmole.core.pluginmanager.PluginManager
import org.openmole.core.pluginmanager.{ BundleDecorator, PluginManager }
import org.osgi.framework.Bundle
import scala.reflect.io.ZipArchive
......@@ -28,38 +28,43 @@ import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.reporters.ConsoleReporter
import scala.tools.nsc.reporters.Reporter
import scala.tools.nsc.util._
import scala.util.parsing.input.OffsetPosition
import collection.mutable.ListBuffer
import java.io.{ File, PrintWriter, StringWriter }
import java.net.URL
import scala.tools.nsc.symtab.SymbolLoaders
import scala.tools.nsc.backend.JavaPlatform
import scala.tools.util.PathResolver
import scala.tools.nsc._
object OSGiScalaCompiler {
def createSettings(settings: Settings, priorityBundles: Seq[Bundle], jars: Seq[File], classDirectory: File) =
if (!Activator.osgi) {
val newSettings = settings.copy()
case class Plop()
newSettings.embeddedDefaults[Plop]
//settings.usejavacp.value = true
newSettings
}
else {
def toPath(b: Bundle) = new URL(b.getLocation).getPath
//def dependencies(b: Bundle) = PluginManager.allDependingBundles(b, _=> true).map(toPath)
class OSGiScalaCompiler(settings: Settings, reporter: Reporter, virtualDirectory: AbstractFile, priorityBundles: Seq[Bundle], jars: Seq[File]) extends Global(settings, reporter) with ReplGlobal { g
def bundles: Seq[String] = {
priorityBundles.map(toPath) ++
jars.map(_.getCanonicalPath) ++
PluginManager.bundlesForClass(OSGiScalaCompiler.getClass).map(toPath) ++ Activator.bundleContext.get.getBundles.filter(!_.isSystem).map(toPath)
}.distinct
//settings.bootclasspath.value = ClassPathBuilder.getClassPathFrom(classOf[scala.App].getClassLoader).mkString(":")
val newSettings = settings.copy()
lazy val cp = {
val original = new PathResolver(settings).result
def bundles: Iterable[AbstractFile] =
priorityBundles.flatMap(BundleClassPathBuilder.create) ++
jars.map(f ZipArchive.fromFile(f)) ++
PluginManager.bundlesForClass(classOf[OSGiScalaCompiler]).flatMap(BundleClassPathBuilder.create) ++
BundleClassPathBuilder.allBundles
classDirectory.mkdirs()
newSettings.outputDirs.setSingleOutput(AbstractFile.getDirectory(classDirectory))
newSettings.classpath.append(classDirectory.getCanonicalPath)
bundles.foreach(newSettings.classpath.append)
val result = bundles.map { original.context.newClassPath }.toList
val vdcp = original.context.newClassPath(virtualDirectory)
new MergedClassPath(vdcp :: result ::: original :: Nil, original.context) {
override def asURLs = List.empty
newSettings
}
}
override lazy val platform = new JavaPlatform {
val global: OSGiScalaCompiler.this.type = OSGiScalaCompiler.this
override def classPath = cp
}
def apply(settings: Settings, reporter: Reporter, priorityBundles: Seq[Bundle], jars: Seq[File]) =
new OSGiScalaCompiler(settings, reporter)
}
class OSGiScalaCompiler private (settings: Settings, reporter: Reporter) extends Global(settings, reporter) with ReplGlobal
\ No newline at end of file
......@@ -20,6 +20,7 @@ package org.openmole.core.console
import java.net.URLClassLoader
import java.util
import java.util.UUID
import javax.script._
import org.openmole.core.exception._
import org.openmole.core.pluginmanager._
......@@ -33,12 +34,23 @@ import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.tools.nsc.interpreter._
import monocle.macros._
import org.openmole.core.fileservice.FileService
import org.openmole.core.workspace.NewFile
import scala.tools.nsc.io.AbstractFile
import org.openmole.tool.osgi._
import scala.reflect.ClassTag
import scala.tools.nsc
object ScalaREPL {
def apply(priorityBundles: Seq[Bundle] = Nil, jars: Seq[JFile] = Seq.empty, quiet: Boolean = true)(implicit newFile: NewFile, fileService: FileService) = {
val classDirectory = newFile.newDir("classDirectory")
fileService.deleteWhenGarbageCollected(classDirectory)
new ScalaREPL(priorityBundles, jars, quiet, classDirectory)
}
private def compilationMessage(errorMessages: List[ErrorMessage], code: String) = {
def readableErrorMessages(error: ErrorMessage) =
error.position.map(p s"(line ${p.line}) ").getOrElse("") + error.decoratedMessage
......@@ -56,7 +68,6 @@ object ScalaREPL {
@Lenses case class ErrorMessage(decoratedMessage: String, rawMessage: String, position: Option[ErrorPosition])
@Lenses case class ErrorPosition(line: Int, start: Int, end: Int, point: Int)
def warmup = new ScalaREPL().eval("(i: Int) => { i * 2 }")
case class HeaderInfo(file: String)
def firstLine(file: String) = HeaderInfo(file)
......@@ -96,6 +107,65 @@ object ScalaREPL {
bundle = bundle
)
}
class OMIMain(settings: Settings, priorityBundles: Seq[Bundle], jars: Seq[JFile], quiet: Boolean) extends IMain(settings) {
var storeErrors: Boolean = true
var errorMessage: List[ErrorMessage] = Nil
lazy val firstLineTag = "/*" + UUID.randomUUID().toString + "*/"
override lazy val reporter = new ReplReporter(this) {
override def error(pos: Position, msg: String): Unit = {
if (storeErrors) {
val error =
pos match {
case NoPosition ErrorMessage(msg, msg, None)
case _
val compiled = new String(pos.source.content).split("\n")
val firstLine = compiled.zipWithIndex.find { case (l, _) l.contains(firstLineTag) }.map(_._2 + 1).getOrElse(0)
val offset = compiled.take(firstLine).map(_.length + 1).sum
def errorPos = ErrorPosition(pos.line - firstLine, pos.start - offset, pos.end - offset, pos.point - offset)
def decoratedMessage = {
val offsetOfError = pos.point - compiled.take(pos.line - 1).map(_.length + 1).sum
s"""$msg
|${compiled(pos.line - 1)}
|${(" " * offsetOfError)}^""".stripMargin
}
ErrorMessage(decoratedMessage, msg, Some(errorPos))
}
errorMessage ::= error
}
super.error(pos, msg)
}
//override def printMessage(msg: String) = println(msg)
override def printMessage(msg: String) = if (!quiet) super.printMessage(msg)
}
override protected def newCompiler(settings: Settings, reporter: Reporter) = {
//settings.Yreplclassbased.value = true
//settings.exposeEmptyPackage.value = true
//settings.outputDirs setSingleOutput replOutput.dir