Skip to content

Commit

Permalink
Bring in scalafmt and format code. (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabsx00 authored May 10, 2019
1 parent 152ea35 commit 4108723
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
maxColumn = 120
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.5")
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")
2 changes: 1 addition & 1 deletion src/main/scala/io/shiftleft/joern/CpgLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object CpgLoader {
* @param filename name of the file that stores the cpg
* @param config loader configuration. If not specified, use default + default semantics
* */
def load(filename : String, config : CpgLoaderConfig = CpgLoaderConfig.default) : Cpg = {
def load(filename: String, config: CpgLoaderConfig = CpgLoaderConfig.default): Cpg = {
val config = CpgLoaderConfig.default
if (config.semanticsFilename.isEmpty) {
config.semanticsFilename = Some("src/main/resources/default.semantics")
Expand Down
30 changes: 16 additions & 14 deletions src/main/scala/io/shiftleft/joern/JoernQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import javax.script.ScriptEngineManager

object JoernQuery extends App {

parseConfig.foreach {config =>
parseConfig.foreach { config =>
val e = new ScriptEngineManager().getEngineByName("scala");

val cpgLoadingCode =
s"""
s"""
| import io.shiftleft.joern.CpgLoader
| import io.shiftleft.queryprimitives.steps.starters.Cpg
| val cpg : Cpg = CpgLoader.load("${config.cpgFilename}")
Expand All @@ -20,7 +20,7 @@ object JoernQuery extends App {

if (config.isFile) {
val reader = File(config.query).fileReader
reader.foreach{ r =>
reader.foreach { r =>
println(e.eval(r, context))
}
} else {
Expand All @@ -29,16 +29,18 @@ object JoernQuery extends App {
}
}

case class Config(cpgFilename : String, query : String, isFile : Boolean = false)
def parseConfig : Option[Config] = new scopt.OptionParser[Config]("joern-query") {
opt[String]('c', "cpg")
.text("the code property graph to run queries on (default: cpg.bin.zip)")
.action((x, c) => c.copy(cpgFilename = x))
arg[String]("<query|filename>")
.text("query to execute, or script file to execute if -f is set")
.action((x, c) => c.copy(query = x))
opt[Unit]('f', "isFile").text("if specified, the second parameter is assumed to be a script file")
.action((_,c) => c.copy(isFile = true))
}.parse(args, Config("cpg.bin.zip", ""))
case class Config(cpgFilename: String, query: String, isFile: Boolean = false)
def parseConfig: Option[Config] =
new scopt.OptionParser[Config]("joern-query") {
opt[String]('c', "cpg")
.text("the code property graph to run queries on (default: cpg.bin.zip)")
.action((x, c) => c.copy(cpgFilename = x))
arg[String]("<query|filename>")
.text("query to execute, or script file to execute if -f is set")
.action((x, c) => c.copy(query = x))
opt[Unit]('f', "isFile")
.text("if specified, the second parameter is assumed to be a script file")
.action((_, c) => c.copy(isFile = true))
}.parse(args, Config("cpg.bin.zip", ""))

}

0 comments on commit 4108723

Please sign in to comment.