Commit 4fdc17ed authored by Romain Reuillon's avatar Romain Reuillon
Browse files

[Core] fix: remove the worflow statement at the end of the imported files

parent 9f348692
......@@ -114,6 +114,7 @@ lazy val scalaLang = OsgiProject(
"jline" % "jline" % "2.12.1",
"org.scala-stm" %% "scala-stm" % "0.8",
"com.typesafe" % "config" % "1.2.1",
"org.scalameta" %% "scalameta" % "4.1.0",
"org.scala-lang" % "scala-compiler" % scalaVersion.value
)
}, version := scalaVersion.value) settings(settings: _*)
......
......@@ -265,7 +265,9 @@ lazy val console = OsgiProject(coreDir, "org.openmole.core.console", global = tr
defaultActivator
) dependsOn(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: _*)
lazy val project = OsgiProject(coreDir, "org.openmole.core.project", imports = Seq("*")) dependsOn(console, openmoleDSL, services) settings (OsgiKeys.importPackage := Seq("*")) settings (coreSettings: _*) settings (
Libraries.addScalaLang(scalaVersionValue)
)
lazy val buildinfo = OsgiProject(coreDir, "org.openmole.core.buildinfo", imports = Seq("*")) enablePlugins (BuildInfoPlugin) settings(
//sourceGenerators in Compile += buildInfo.taskValue,
......
......@@ -17,7 +17,6 @@
*/
package org.openmole.core.project
import javax.script.CompiledScript
import org.openmole.core.console._
import org.openmole.core.pluginmanager._
import org.openmole.core.project.Imports.{ SourceFile, Tree }
......@@ -26,7 +25,6 @@ import monocle.function.all._
import monocle.std.all._
import org.openmole.core.exception.{ InternalProcessingError, UserBadDataError }
import org.openmole.core.fileservice.FileService
import org.openmole.core.outputmanager.OutputManager
import org.openmole.core.services._
import org.openmole.core.workflow.composition.DSL
import org.openmole.core.workspace.NewFile
......@@ -55,7 +53,7 @@ object Project {
def makeVal(identifier: String, file: File) =
s"""lazy val ${identifier} = ${uniqueName(file)}"""
def makeScriptImports(sourceFile: SourceFile) = {
def makeScriptWithImports(sourceFile: SourceFile) = {
def imports = makeImportTree(Tree.insertAll(sourceFile.importedFiles))
val name = uniqueName(sourceFile.file)
......@@ -69,12 +67,32 @@ object Project {
"""
}
def makeScript(sourceFile: SourceFile) = {
def makeImportedScript(sourceFile: SourceFile) = {
def removeLastTerm(classContent: String) = {
import _root_.scala.meta._
val source = classContent.parse[Source].get
val cls = source.stats.last.asInstanceOf[Defn.Class]
val lastStat = cls.templ.stats.last
val newCls =
lastStat match {
case _: Term cls.copy(templ = cls.templ.copy(stats = cls.templ.stats.dropRight(1)))
case x
println(x.getClass)
cls
}
source.copy(stats = source.stats.dropRight(1) ++ Seq(newCls))
}
def imports = makeImportTree(Tree.insertAll(sourceFile.importedFiles))
val name = uniqueName(sourceFile.file)
s"""class ${name}Class {
val classContent =
s"""class ${name}Class {
|lazy val _imports = new {
|$imports
|}
......@@ -82,9 +100,12 @@ object Project {
|import _imports._
|
|private lazy val ${ConsoleVariables.workDirectory} = File(new java.net.URI("${sourceFile.file.getParentFileSafe.toURI}").getPath)
|
|${sourceFile.file.content}
|}
|
""".stripMargin
s"""${removeLastTerm(classContent)}
|lazy val ${name} = new ${name}Class
""".stripMargin
}
......@@ -92,7 +113,7 @@ object Project {
val allImports = Imports.importedFiles(script)
// The first script is the script being compiled itself, no need to include its vars and defs, it would be redundant
def importHeader = { allImports.take(1).map(makeScriptImports) ++ allImports.drop(1).map(makeScript) }.mkString("\n")
def importHeader = { allImports.take(1).map(makeScriptWithImports) ++ allImports.drop(1).map(makeImportedScript) }.mkString("\n")
s"""
|$importHeader
......
......@@ -19,24 +19,16 @@ package org.openmole.core.serializer
import java.io.File
import com.thoughtworks.xstream.converters.{ Converter, ConverterLookup }
import com.thoughtworks.xstream.converters.reflection.ReflectionConverter
import com.thoughtworks.xstream.core.{ ClassLoaderReference, DefaultConverterLookup, JVM }
import com.thoughtworks.xstream.core.util.CompositeClassLoader
import com.thoughtworks.xstream.io.xml.XppDriver
import com.thoughtworks.xstream.{ XStream, mapper }
import com.thoughtworks.xstream.mapper.{ DefaultMapper, Mapper, MapperWrapper }
import org.openmole.core.pluginmanager.PluginManager
import org.openmole.core.serializer.converter.Serialiser
import org.openmole.core.serializer.file.FileConverterNotifier
import org.openmole.core.serializer.plugin.{ PluginClassConverter, PluginConverter, Plugins }
import org.openmole.core.serializer.plugin.{ PluginClassConverter, PluginConverter }
import org.openmole.core.serializer.structure.PluginClassAndFiles
import org.openmole.tool.file._
import org.openmole.tool.stream.NullOutputStream
import org.openmole.core.console._
import scala.collection.immutable.{ HashSet, TreeSet }
import scala.reflect.internal.util.ScalaClassLoader.URLClassLoader
object PluginAndFilesListing {
def looksLikeREPLClassName(p: String) = p.startsWith("$line")
......@@ -57,6 +49,7 @@ trait PluginAndFilesListing { this: Serialiser ⇒
xStream.registerConverter(new PluginClassConverter(this))
def classUsed(c: Class[_]) = {
if (!seenClasses.contains(c)) {
if (PluginManager.isClassProvidedByAPlugin(c)) PluginManager.pluginsForClass(c).foreach(pluginUsed)
......
......@@ -49,7 +49,11 @@ object Libraries {
/** ------- Bundles -------------- */
def addScalaLang(scalaVersion: String) = libraryDependencies += "org.openmole.library" %% "org-scala-lang-scala-library" % scalaVersion
def addScalaLang(scalaVersion: String) =
libraryDependencies ++= Seq(
"org.openmole.library" %% "org-scala-lang-scala-library" % scalaVersion,
"org.scalameta" %% "scalameta" % "4.1.0"
)
lazy val scalatra = "org.openmole.library" %% "org-scalatra" % "2.6.3"
lazy val logback = "org.openmole.library" %% "ch-qos-logback" % "1.0.9"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment