Skip to content

Commit 0938760

Browse files
authored
Run the schema extender only if necessary (#1076)
* Run the schema extender only if necessary * call `run.ossdataflow` in scanner CPG creation
1 parent 1d6495c commit 0938760

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

console/src/main/scala/io/shiftleft/console/BridgeBase.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ trait BridgeBase {
146146
if (config.server) {
147147
startHttpServer(config)
148148
} else if (config.pluginToRun.isDefined) {
149-
runBundle(config)
149+
runPlugin(config)
150150
} else {
151151
startInteractiveShell(config, slProduct)
152152
}
@@ -180,7 +180,7 @@ trait BridgeBase {
180180
}
181181
}
182182

183-
private def runBundle(config: Config): Unit = {
183+
private def runPlugin(config: Config): Unit = {
184184
if (config.src.isEmpty) {
185185
println("You must supply a source directory with the --src flag")
186186
return
@@ -196,6 +196,7 @@ trait BridgeBase {
196196
| .filter(_.inputPath == "$src")
197197
| .map(_.name).foreach(n => workspace.removeProject(n))
198198
| importCode.$language("$src")
199+
| run.ossdataflow
199200
| save
200201
| } else {
201202
| println("Using existing CPG - Use `--overwrite` if this is not what you want")

console/src/main/scala/io/shiftleft/console/PluginManager.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,26 @@ class PluginManager(val installDir: File) {
6060
}
6161

6262
private def installSchemaExtensions(file: File, pluginName: String): Unit = {
63-
schemaDir.foreach { sDir =>
64-
file.listRecursively
63+
val copyOps = schemaDir.toList.flatMap { sDir =>
64+
file.listRecursively.toList
6565
.filter(_.path.toString.contains("schema"))
6666
.filter(_.name.endsWith(".json"))
67-
.foreach { json =>
67+
.map { json =>
6868
val name = json.name
6969
val dstFileName = s"joernext-$pluginName-$name"
7070
cp(json, sDir / dstFileName)
71+
json
7172
}
7273
}
73-
try {
74-
Process("./schema-extender.sh", installDir.toJava).!!
75-
} catch {
76-
case e: Exception =>
77-
System.err.println(s"Error running schema-extender: ${e.getMessage}")
74+
75+
if (copyOps.nonEmpty) {
76+
println("Plugin modifies the schema. Running schema extender.")
77+
try {
78+
Process("./schema-extender.sh", installDir.toJava).!!
79+
} catch {
80+
case e: Exception =>
81+
System.err.println(s"Error running schema-extender: ${e.getMessage}")
82+
}
7883
}
7984
}
8085

0 commit comments

Comments
 (0)