-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kotlin2cpg: add nodes for gradle dependencies
- Loading branch information
Showing
3 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...2cpg/src/main/scala/io/joern/kotlin2cpg/passes/DependenciesFromMavenCoordinatesPass.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.joern.kotlin2cpg.passes | ||
|
||
import io.shiftleft.codepropertygraph.Cpg | ||
import io.shiftleft.passes.CpgPass | ||
import io.shiftleft.semanticcpg.language._ | ||
import io.shiftleft.codepropertygraph.generated.nodes.{NewDependency} | ||
import org.slf4j.{Logger, LoggerFactory} | ||
|
||
import scala.util.matching.Regex | ||
|
||
// This pass takes a list of strings representing maven coordinates in order to add DEPENDENCY nodes to the graph. | ||
/* | ||
example of a sequence of coordinates that are valid for the pass: | ||
``` | ||
org.jetbrains.kotlin:kotlin-stdlib:1.7.22 | ||
org.jetbrains.kotlin:kotlin-stdlib-common:1.7.22 | ||
org.jetbrains:annotations:13.0 | ||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22 | ||
org.apache.logging.log4j:log4j-api:2.15.0 | ||
org.springframework.boot:spring-boot-starter:3.0.5 | ||
org.springframework.boot:spring-boot:3.0.5 | ||
org.springframework:spring-core:6.0.7 | ||
org.springframework:spring-jcl:6.0.7 | ||
org.springframework:spring-context:6.0.7 | ||
``` | ||
*/ | ||
class DependenciesFromMavenCoordinatesPass(coordinates: Seq[String], cpg: Cpg) extends CpgPass(cpg) { | ||
override def run(dstGraph: DiffGraphBuilder): Unit = { | ||
|
||
coordinates.foreach { coordinate => | ||
val keyValPattern: Regex = "^([^:]+):([^:]+):([^:]+)$".r | ||
for (patternMatch <- keyValPattern.findAllMatchIn(coordinate)) { | ||
val groupId = patternMatch.group(1) | ||
val name = patternMatch.group(2) | ||
val version = patternMatch.group(3) | ||
val node = NewDependency().name(name).version(version).dependencyGroupId(groupId) | ||
dstGraph.addNode(node) | ||
} | ||
} | ||
} | ||
} |