Commit 71af9f41 authored by Romain Reuillon's avatar Romain Reuillon
Browse files

[Plugin] enh: list only first level imports

parent a49331da
Pipeline #1206 passed with stages
in 32 minutes and 6 seconds
......@@ -126,11 +126,13 @@ object Imports {
}
}
def directImportedFiles(source: File): Seq[ImportedFile] = level1ImportedFiles(parseImports(source.content), source.getParentFileSafe)
def importedFiles(script: File): Seq[SourceFile] = {
val alreadyImported = collection.mutable.Set[File](script.getCanonicalFile)
def importedFiles0(source: File): List[SourceFile] = {
val imported = level1ImportedFiles(parseImports(source.content), source.getParentFileSafe)
val imported = directImportedFiles(source)
val newlyImported = imported.map(_.file.getCanonicalFile).distinct.filter(i !alreadyImported.contains(i))
newlyImported.foreach(f alreadyImported.add(f))
......
......@@ -145,7 +145,7 @@ object Project {
|new $traitName {
|
|$functionPrototype = {
|implicit def _scriptSourceData = ${ScriptSourceData.applySource(workDirectory, script, Imports.importedFiles(script).flatMap(_.importedFiles))}
|implicit def _scriptSourceData = ${ScriptSourceData.applySource(workDirectory, script)}
|import ${Project.uniqueName(script)}._imports._""".stripMargin
def scriptFooter =
......
......@@ -6,26 +6,17 @@ import org.openmole.tool.file._
object ScriptSourceData {
implicit def defaultData = NoData
case class ImportData(`import`: String, script: File)
case class ScriptData(workDirectory: File, script: File, imports: Seq[ImportData]) extends ScriptSourceData {
case class ScriptData(workDirectory: File, script: File) extends ScriptSourceData {
val content = if (script.exists()) script.content else ""
}
case object NoData extends ScriptSourceData
def applySource(workDirectory: File, script: File, imports: Seq[ImportedFile]) = {
def applySource(workDirectory: File, script: File) = {
def tq = "\"\"\""
def importData(i: ImportedFile) = s"""${classOf[ScriptSourceData.ImportData].getCanonicalName}($tq${ImportedFile.identifier(i)}$tq, File($tq${i.file}$tq))"""
s"""${classOf[ScriptSourceData.ScriptData].getCanonicalName}(File($tq$workDirectory$tq), File($tq$script$tq), Seq(${imports.map(importData).mkString(",")}))"""
s"""${classOf[ScriptSourceData.ScriptData].getCanonicalName}(File($tq$workDirectory$tq), File($tq$script$tq))"""
}
def importsContent(scriptData: ScriptSourceData) =
scriptData match {
case NoData Seq()
case s: ScriptData s.imports
}
def scriptContent(scriptData: ScriptSourceData) =
scriptData match {
case NoData ""
......
......@@ -8,7 +8,10 @@ import org.openmole.plugin.tool.json._
import io.circe._
import org.openmole.core.exception.InternalProcessingError
import org.openmole.core.workflow.format.OutputFormat.{ PlainContent, SectionContent }
import io.circe.generic.auto._, io.circe.parser._, io.circe.syntax._
import io.circe.generic.auto._
import io.circe.parser._
import io.circe.syntax._
import org.openmole.core.project.Imports.ImportedFile
object OMROutputFormat {
......@@ -43,14 +46,17 @@ object OMROutputFormat {
.add(omrVersionField, Json.fromString(omrVersion))
.add(openMOLEVersionField, Json.fromString(org.openmole.core.buildinfo.version.value))
if (format.script) {
case class OMRImport(`import`: String, content: String)
scriptData match {
case data: ScriptSourceData.ScriptData if format.script
case class OMRImport(`import`: String, content: String)
o2.add(scriptField, Json.fromString(ScriptSourceData.scriptContent(scriptData)))
.add(importsField, Json.fromValues(ScriptSourceData.importsContent(scriptData).map(i OMRImport(i.`import`, i.script.content).asJson)))
}
else o2
val scriptContent = ScriptSourceData.scriptContent(scriptData)
val imports = Imports.directImportedFiles(data.script)
o2.add(scriptField, Json.fromString(scriptContent))
.add(importsField, Json.fromValues(imports.map(i OMRImport(ImportedFile.identifier(i), i.file.content).asJson)))
case _ o2
}
}
}
......
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