Skip to content

Commit

Permalink
Log php-parser warnings as warnings and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
johannescoetzee committed Dec 3, 2024
1 parent e79d3ef commit 61f6c84
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
13 changes: 6 additions & 7 deletions joern-cli/frontends/php2cpg/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import better.files.File

name := "php2cpg"

val phpParserVersion = "4.15.8"
val upstreamParserBinName = "php-parser.phar"
val versionedParserBinName = s"php-parser-$phpParserVersion.phar"
val versionedParserBinName = s"php-parser-${Versions.phpParser}.phar"
val phpParserDlUrl =
s"https://github.com/joernio/PHP-Parser/releases/download/v$phpParserVersion/$upstreamParserBinName"
s"https://github.com/joernio/PHP-Parser/releases/download/v${Versions.phpParser}/$upstreamParserBinName"

dependsOn(Projects.dataflowengineoss % "compile->compile;test->test", Projects.x2cpg % "compile->compile;test->test")

libraryDependencies ++= Seq(
"com.lihaoyi" %% "upickle" % Versions.upickle,
"com.lihaoyi" %% "ujson" % Versions.upickle,
"io.shiftleft" %% "codepropertygraph" % Versions.cpg,
"com.lihaoyi" %% "upickle" % Versions.upickle,
"com.lihaoyi" %% "ujson" % Versions.upickle,
"io.shiftleft" %% "codepropertygraph" % Versions.cpg,
"com.github.sh4869" %% "semver-parser-scala" % Versions.semverParser,
"org.scalatest" %% "scalatest" % Versions.scalatest % Test
"org.scalatest" %% "scalatest" % Versions.scalatest % Test
)

lazy val phpParseInstallTask = taskKey[Unit]("Install PHP-Parse using PHP Composer")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,23 @@ class PhpParser private (phpParserPath: String, phpIniPath: String, disableFileC
result
}

private def logWarning(lines: collection.Seq[String]): Unit = {
if (lines.exists(_.nonEmpty)) {
logger.warn(s"Found warning in PHP-Parser JSON output:\n${lines.mkString("\n")}")
}
}

private def linesToJsonValues(
lines: collection.Seq[String]
): collection.Seq[(String, Option[ujson.Value], String)] = {
val filePrefix = "====> File "
val filenameRegex = Pattern.compile(s"$filePrefix(.*):")
val result = mutable.ArrayBuffer.empty[(String, Option[ujson.Value], String)]

var filename = ""
val infoLines = mutable.ArrayBuffer.empty[String]
val jsonLines = mutable.ArrayBuffer.empty[String]
var filename = ""
val infoLines = mutable.ArrayBuffer.empty[String]
val jsonLines = mutable.ArrayBuffer.empty[String]
val warningLines = mutable.ArrayBuffer.empty[String]

var mode = PARSE_MODE.SKIP_TRAILER
val linesIt = lines.iterator
Expand All @@ -117,14 +124,16 @@ class PhpParser private (phpParserPath: String, phpIniPath: String, disableFileC
}
case PARSE_MODE.SKIP_WARNING =>
if (line == "[]") {
logWarning(warningLines)
jsonLines.append(line)
result.appendAll(getJsonResult(filename, jsonLines.toArray, infoLines.toArray))
mode = PARSE_MODE.SKIP_TRAILER
} else if (line.startsWith("[")) {
logWarning(warningLines)
jsonLines.append(line)
mode = PARSE_MODE.PARSE_JSON
} else {
infoLines.append(line)
warningLines.append(line)
}
case PARSE_MODE.PARSE_JSON =>
jsonLines.append(line)
Expand Down
1 change: 1 addition & 0 deletions project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object Versions {
val json4s = "4.0.7"
val lombok = "1.18.32"
val mavenArcheologist = "0.0.10"
val phpParser = "4.15.9"
val pPrint = "0.8.1"
val reflection = "0.10.2"
val requests = "0.8.0"
Expand Down

0 comments on commit 61f6c84

Please sign in to comment.