Skip to content

Commit

Permalink
Set MetaData root (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-leuthaeuser authored Jun 27, 2022
1 parent f37ad8b commit 956d140
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val cpgVersion = "1.3.545"
val joernVersion = "1.1.895"
val cpgVersion = "1.3.549"
val joernVersion = "1.1.911"

val gitCommitString = SettingKey[String]("gitSha")

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/shiftleft/js2cpg/core/Js2Cpg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class Js2Cpg {
.createAndApply()
new CallLinkerPass(cpg).createAndApply()

new JsMetaDataPass(cpg, metaDataKeyPool, hash).createAndApply()
new JsMetaDataPass(cpg, metaDataKeyPool, hash, config.srcDir).createAndApply()
new BuiltinTypesPass(cpg, builtinTypesKeyPool).createAndApply()
new DependenciesPass(cpg, config, dependenciesKeyPool)
.createAndApply()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package io.shiftleft.js2cpg.cpg.passes

import better.files.File
import io.shiftleft.codepropertygraph.Cpg
import io.shiftleft.codepropertygraph.generated.Languages
import io.shiftleft.codepropertygraph.generated.nodes.NewMetaData
import io.shiftleft.passes.{KeyPool, SimpleCpgPass}
import org.slf4j.LoggerFactory

class JsMetaDataPass(cpg: Cpg, keyPool: KeyPool, hash: String) extends SimpleCpgPass(cpg, keyPool = Some(keyPool)) {
class JsMetaDataPass(cpg: Cpg, keyPool: KeyPool, hash: String, root: String)
extends SimpleCpgPass(cpg, keyPool = Some(keyPool)) {

private val logger = LoggerFactory.getLogger(getClass)

override def run(diffGraph: DiffGraphBuilder): Unit = {
logger.debug("Generating meta-data.")
val metaNode = NewMetaData().language(Languages.JAVASCRIPT).hash(hash)
val absolutePathToRoot = File(root).path.toAbsolutePath.toString
val metaNode = NewMetaData().language(Languages.JAVASCRIPT).hash(hash).root(absolutePathToRoot)
diffGraph.addNode(metaNode)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class JsMetaDataPassTest extends AbstractPassTest {
val cpg = Cpg.emptyCpg
val jsMetaDataKeyPool = new IntervalKeyPool(1, 100)

new JsMetaDataPass(cpg, jsMetaDataKeyPool, "somehash").createAndApply()
new JsMetaDataPass(cpg, jsMetaDataKeyPool, "somehash", ".").createAndApply()

"create exactly 1 node" in {
cpg.graph.V.asScala.size shouldBe 1
Expand Down

0 comments on commit 956d140

Please sign in to comment.