Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
openmole
openmole
Commits
71af9f41
Commit
71af9f41
authored
Jul 16, 2021
by
Romain Reuillon
Browse files
[Plugin] enh: list only first level imports
parent
a49331da
Pipeline
#1206
passed with stages
in 32 minutes and 6 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
openmole/core/org.openmole.core.project/src/main/scala/org/openmole/core/project/Imports.scala
View file @
71af9f41
...
...
@@ -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
=
level1
ImportedFiles
(
parseImports
(
source
.
content
),
source
.
getParentFileSaf
e
)
val
imported
=
direct
ImportedFiles
(
sourc
e
)
val
newlyImported
=
imported
.
map
(
_
.
file
.
getCanonicalFile
).
distinct
.
filter
(
i
⇒
!
alreadyImported
.
contains
(
i
))
newlyImported
.
foreach
(
f
⇒
alreadyImported
.
add
(
f
))
...
...
openmole/core/org.openmole.core.project/src/main/scala/org/openmole/core/project/Project.scala
View file @
71af9f41
...
...
@@ -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
=
...
...
openmole/core/org.openmole.core.project/src/main/scala/org/openmole/core/project/ScriptSourceData.scala
View file @
71af9f41
...
...
@@ -6,24 +6,15 @@ 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(",")}))"""
}
def
importsContent
(
scriptData
:
ScriptSourceData
)
=
scriptData
match
{
case
NoData
⇒
Seq
()
case
s
:
ScriptData
⇒
s.imports
s
"""${classOf[ScriptSourceData.ScriptData].getCanonicalName}(File($tq$workDirectory$tq), File($tq$script$tq))"""
}
def
scriptContent
(
scriptData
:
ScriptSourceData
)
=
...
...
openmole/plugins/org.openmole.plugin.hook.omr/src/main/scala/org/openmole/plugin/hook/omr/OMROutputFormat.scala
View file @
71af9f41
...
...
@@ -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
)
{
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
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment