Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ maven.install(
"io.joern:flatgraph-odb-convert_3:0.1.35",
"net.sf.trove4j:core:3.1.0",
"com.google.protobuf:protobuf-java:4.34.1",
"org.json4s:json4s-native_3:4.0.3",
"com.lihaoyi:ujson_3:4.4.3",
"com.lihaoyi:os-lib_3:0.11.4",
],
excluded_artifacts = [
Expand Down
128 changes: 14 additions & 114 deletions maven_install.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"com.google.j2objc:j2objc-annotations": 2003271689,
"com.google.protobuf:protobuf-java": 1237026331,
"com.lihaoyi:os-lib_3": 899915638,
"com.lihaoyi:ujson_3": 1182647324,
"io.joern:flatgraph-core_3": 1060140408,
"io.joern:flatgraph-domain-classes-generator_3": -1894114436,
"io.joern:flatgraph-help_3": -138228966,
"io.joern:flatgraph-odb-convert_3": 1959782918,
"net.sf.trove4j:core": 1808260229,
"org.json4s:json4s-native_3": 1421532977,
"org.scala-lang:scala-library": 1230160761,
"org.scala-lang:scala3-library_3": 1771369610,
"org.slf4j:slf4j-api": -197708565,
Expand Down Expand Up @@ -45,23 +45,21 @@
"com.lihaoyi:geny_3:jar:sources": 1575781288,
"com.lihaoyi:os-lib_3": 695712032,
"com.lihaoyi:os-lib_3:jar:sources": 1732147675,
"com.lihaoyi:ujson_3": 126745168,
"com.lihaoyi:ujson_3:jar:sources": 1676340764,
"com.lihaoyi:upickle-core_3": 911572118,
"com.lihaoyi:upickle-core_3:jar:sources": 1793823939,
"com.thoughtworks.paranamer:paranamer": 216030769,
"com.thoughtworks.paranamer:paranamer:jar:sources": 1185138559,
"com.lihaoyi:ujson_3": -675221214,
"com.lihaoyi:ujson_3:jar:sources": 1401892679,
"com.lihaoyi:upickle-core_3": -1369261776,
"com.lihaoyi:upickle-core_3:jar:sources": 1761591552,
"com.typesafe:config": 1422037420,
"com.typesafe:config:jar:sources": 1794326800,
"io.get-coursier:interface": 1635041630,
"io.get-coursier:interface:jar:sources": -37171318,
"io.joern:flatgraph-core_3": 839026010,
"io.joern:flatgraph-core_3": 1182992137,
"io.joern:flatgraph-core_3:jar:sources": 575284637,
"io.joern:flatgraph-domain-classes-generator_3": 170340065,
"io.joern:flatgraph-domain-classes-generator_3:jar:sources": -123490520,
"io.joern:flatgraph-help_3": -1132428533,
"io.joern:flatgraph-help_3": 1193217379,
"io.joern:flatgraph-help_3:jar:sources": -1476209185,
"io.joern:flatgraph-odb-convert_3": -1972259056,
"io.joern:flatgraph-odb-convert_3": -1299461830,
"io.joern:flatgraph-odb-convert_3:jar:sources": 1706697962,
"io.shiftleft:overflowdb-core_3": -1655377345,
"io.shiftleft:overflowdb-core_3:jar:sources": 422126785,
Expand All @@ -77,16 +75,6 @@
"org.checkerframework:checker-qual:jar:sources": -1750922234,
"org.javassist:javassist": -448825381,
"org.javassist:javassist:jar:sources": 1531561359,
"org.json4s:json4s-ast_3": 878798110,
"org.json4s:json4s-ast_3:jar:sources": 140325100,
"org.json4s:json4s-core_3": -1327401949,
"org.json4s:json4s-core_3:jar:sources": -2043024428,
"org.json4s:json4s-native-core_3": -1463802907,
"org.json4s:json4s-native-core_3:jar:sources": -1913200314,
"org.json4s:json4s-native_3": -1745325382,
"org.json4s:json4s-native_3:jar:sources": 650512086,
"org.json4s:json4s-scalap_3": 1632132590,
"org.json4s:json4s-scalap_3:jar:sources": -763259858,
"org.msgpack:msgpack-core": -1705007667,
"org.msgpack:msgpack-core:jar:sources": -1562951139,
"org.scalameta:scalafmt-dynamic_2.13": -518206696,
Expand Down Expand Up @@ -194,24 +182,17 @@
},
"com.lihaoyi:ujson_3": {
"shasums": {
"jar": "dd4109dc66963a3552154f59f20858e2907c13bc1a9410ae46573cdfa94e7517",
"sources": "082f8d8759a6f6db5bbed0bd13e274c404000eabb4777ff5e14a7232964d78d8"
"jar": "2fd8083aabc7fb4252c299909b19b2881326a03502eba8859d39d4b2ceb7a8b2",
"sources": "e64a5a38ab13502eb021c9fc1c8740fa825dbb11c717268fc9b308ee099ce3ae"
},
"version": "4.4.1"
"version": "4.4.3"
},
"com.lihaoyi:upickle-core_3": {
"shasums": {
"jar": "4b7566695c789c9a031167a296c67f08b06107124edfbb58e6e187caaa2dc592",
"sources": "ae95168d863b4df5d6f6e2c64caf02fb1da99a50b08d6d2f51b3c4ed10080a76"
"jar": "9b9be4b677ab6fbc6b82fe5486908a39664f51e9344d1903ada1c6766d251ce2",
"sources": "04a4d1a6df374a5d03f1a0ac7048dcfd60be5c4032c42355032117c375b7f647"
},
"version": "4.4.1"
},
"com.thoughtworks.paranamer:paranamer": {
"shasums": {
"jar": "688cb118a6021d819138e855208c956031688be4b47a24bb615becc63acedf07",
"sources": "8a4bfc21755c36ccdd70f96d7ab891d842d5aebd6afa1b74e0efc6441e3df39c"
},
"version": "2.8"
"version": "4.4.3"
},
"com.typesafe:config": {
"shasums": {
Expand Down Expand Up @@ -304,41 +285,6 @@
},
"version": "3.22.0-GA"
},
"org.json4s:json4s-ast_3": {
"shasums": {
"jar": "9abf57acf0912ea87ee25950c2e717b1953c9fbd50e512005d4782ba7a014ec5",
"sources": "9a941cc22a939cadcd78fa50378bbb6f3ab09421a61af882ee8aa82257b5db4d"
},
"version": "4.0.3"
},
"org.json4s:json4s-core_3": {
"shasums": {
"jar": "02b5324658e08bc837a58800ee5863fb890df21b68db6c84391fa9b6d2558d1e",
"sources": "dd7784db655e6b5d41fffa9afe4bf8901a74a18785771fb404afa6109a8dd616"
},
"version": "4.0.3"
},
"org.json4s:json4s-native-core_3": {
"shasums": {
"jar": "e68cfc8f0c0c6a53778e6ab660d45264a8e3dc63d63c42aa9a612697583f92d9",
"sources": "80244e1308ce21e132b747be0d01ff26566a4d5082fc8ca913d86f5f3fd8d389"
},
"version": "4.0.3"
},
"org.json4s:json4s-native_3": {
"shasums": {
"jar": "678cbb3ee67453c7043c3784beb869bbfd51fcc66d425a4434ff100d52263dcb",
"sources": "7fc51eb72ce0b9af6bd07d14fffcb5f31ee1e5be2d7b6e6f18fc69515c503e6f"
},
"version": "4.0.3"
},
"org.json4s:json4s-scalap_3": {
"shasums": {
"jar": "9177935bb5f908fa5bc9a195391bffe6e822734ca711de579275bfd1922baee6",
"sources": "7abf8faab46fcaafd124dc3f4eadc4f31482dad1ff99758deb1752824ff45123"
},
"version": "4.0.3"
},
"org.msgpack:msgpack-core": {
"shasums": {
"jar": "183abb2b7c604a8b13d5f76af487ccddd003b6f0404aef52021dcb20a4358524",
Expand Down Expand Up @@ -427,18 +373,6 @@
"org.apache.commons:commons-text": [
"org.apache.commons:commons-lang3"
],
"org.json4s:json4s-core_3": [
"com.thoughtworks.paranamer:paranamer",
"org.json4s:json4s-ast_3",
"org.json4s:json4s-scalap_3"
],
"org.json4s:json4s-native-core_3": [
"org.json4s:json4s-ast_3"
],
"org.json4s:json4s-native_3": [
"org.json4s:json4s-core_3",
"org.json4s:json4s-native-core_3"
],
"org.scalameta:scalafmt-dynamic_2.13": [
"com.typesafe:config",
"io.get-coursier:interface",
Expand Down Expand Up @@ -533,9 +467,6 @@
"upickle.core",
"upickle.core.compat"
],
"com.thoughtworks.paranamer:paranamer": [
"com.thoughtworks.paranamer"
],
"com.typesafe:config": [
"com.typesafe.config",
"com.typesafe.config.impl",
Expand Down Expand Up @@ -799,25 +730,6 @@
"javassist.util",
"javassist.util.proxy"
],
"org.json4s:json4s-ast_3": [
"org.json4s",
"org.json4s.prefs"
],
"org.json4s:json4s-core_3": [
"org.json4s",
"org.json4s.prefs",
"org.json4s.reflect"
],
"org.json4s:json4s-native-core_3": [
"org.json4s.native"
],
"org.json4s:json4s-native_3": [
"org.json4s.native"
],
"org.json4s:json4s-scalap_3": [
"org.json4s.scalap",
"org.json4s.scalap.scalasig"
],
"org.msgpack:msgpack-core": [
"org.msgpack.core",
"org.msgpack.core.annotations",
Expand Down Expand Up @@ -875,8 +787,6 @@
"com.lihaoyi:ujson_3:jar:sources",
"com.lihaoyi:upickle-core_3",
"com.lihaoyi:upickle-core_3:jar:sources",
"com.thoughtworks.paranamer:paranamer",
"com.thoughtworks.paranamer:paranamer:jar:sources",
"com.typesafe:config",
"com.typesafe:config:jar:sources",
"io.get-coursier:interface",
Expand All @@ -903,16 +813,6 @@
"org.checkerframework:checker-qual:jar:sources",
"org.javassist:javassist",
"org.javassist:javassist:jar:sources",
"org.json4s:json4s-ast_3",
"org.json4s:json4s-ast_3:jar:sources",
"org.json4s:json4s-core_3",
"org.json4s:json4s-core_3:jar:sources",
"org.json4s:json4s-native-core_3",
"org.json4s:json4s-native-core_3:jar:sources",
"org.json4s:json4s-native_3",
"org.json4s:json4s-native_3:jar:sources",
"org.json4s:json4s-scalap_3",
"org.json4s:json4s-scalap_3:jar:sources",
"org.msgpack:msgpack-core",
"org.msgpack:msgpack-core:jar:sources",
"org.scalameta:scalafmt-dynamic_2.13",
Expand Down
2 changes: 1 addition & 1 deletion project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
object Versions {
val flatgraph = parseVersion("flatgraphVersion")
val scalatest = "3.2.10"
val json4s = "4.0.3"
val ujson = "4.4.3"

private def parseVersion(key: String): String = {
val versionRegexp = s""".*val $key[ ]+=[ ]?"(.*?)"""".r
Expand Down
3 changes: 1 addition & 2 deletions schema2json/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ scala_binary(
deps = [
"//schema",
"@maven//:com_lihaoyi_os_lib_3",
"@maven//:org_json4s_json4s_ast_3",
"@maven//:org_json4s_json4s_native_3",
"@maven//:com_lihaoyi_ujson_3",
],
)
2 changes: 1 addition & 1 deletion schema2json/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name := "schema2json"
dependsOn(Projects.schema)

libraryDependencies ++= Seq(
"org.json4s" %% "json4s-native" % Versions.json4s,
"com.lihaoyi" %% "ujson" % Versions.ujson,
"org.scalatest" %% "scalatest" % Versions.scalatest % Test
)

Expand Down
70 changes: 32 additions & 38 deletions schema2json/src/main/scala/Schema2Json.scala
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import io.shiftleft.codepropertygraph.schema.CpgSchema
import org.json4s.JsonDSL._
import org.json4s.native.JsonMethods._
import org.json4s.native.Serialization
import org.json4s.{Formats, NoTypeHints}
import flatgraph.schema.Property.Cardinality
import flatgraph.schema.{AbstractNodeType, NodeBaseType, NodeType, Property, SchemaInfo}

object Schema2Json {

val schema = CpgSchema.instance

implicit val formats: AnyRef & Formats =
Serialization.formats(NoTypeHints)

def main(args: Array[String]): Unit = {
val json =
("schemas" -> schemaSummary) ~ ("nodes" -> nodeTypesAsJson) ~ ("edges" -> edgeTypesAsJson) ~ ("properties" -> propertiesAsJson)
val json = ujson.Obj(
"schemas" -> schemaSummary,
"nodes" -> nodeTypesAsJson,
"edges" -> edgeTypesAsJson,
"properties" -> propertiesAsJson
)

val outFileName = "/tmp/schema.json"
os.write(os.Path(outFileName), compact(render(json)))
// Files.writeString(Paths.get(outFileName), compact(render(json)))
os.write(os.Path(outFileName), ujson.write(json))
// Files.writeString(Paths.get(outFileName), ujson.write(json))
println(s"Schema written to: $outFileName")
}

Expand Down Expand Up @@ -51,9 +48,7 @@ object Schema2Json {
val description = info.getDeclaringClass.getDeclaredMethod("description").invoke(null).asInstanceOf[String]
val providedByFrontend =
info.getDeclaringClass.getDeclaredMethod("providedByFrontend").invoke(null).asInstanceOf[Boolean]
("name" -> name) ~
("description" -> description) ~
("providedByFrontend" -> providedByFrontend)
ujson.Obj("name" -> name, "description" -> description, "providedByFrontend" -> providedByFrontend)
}
}

Expand All @@ -74,29 +69,30 @@ object Schema2Json {
}
.toMap
.toList
.map(x => (("baseType" -> x._2), ("name" -> x._1)))

val inheritedPropertyNames = inheritedProperties.map(_._2._2)
val inheritedPropertyNames = inheritedProperties.map(_._1)
val nonInheritedProperties = allPropertyNames.filterNot(x => inheritedPropertyNames.contains(x))

val containedNodes = nodeType match {
case nt: NodeType if !isSchemaHidden(nt.schemaInfo) =>
nt.containedNodes.map { n =>
Map("name" -> n.localName, "type" -> n.nodeType.name, "cardinality" -> name(n.cardinality))
ujson.Obj("name" -> n.localName, "type" -> n.nodeType.name, "cardinality" -> name(n.cardinality))
}
case _ => List()
}
val json = ("name" -> nodeType.name) ~
("comment" -> nodeType.comment) ~
("extends" -> baseTypeNames) ~
("allProperties" -> allPropertyNames) ~
("cardinalities" -> cardinalities) ~
("inheritedProperties" -> inheritedProperties.map(x => x._1 ~ x._2)) ~
("properties" -> nonInheritedProperties) ~
("schema" -> schName) ~
("schemaIndex" -> schemaIndex(nodeType)) ~
("isAbstract" -> nodeType.isInstanceOf[NodeBaseType]) ~
("containedNodes" -> containedNodes)
val json = ujson.Obj("name" -> nodeType.name)
nodeType.comment.foreach(comment => json("comment") = comment)
json("extends") = baseTypeNames
json("allProperties") = allPropertyNames
json("cardinalities") = cardinalities
json("inheritedProperties") = inheritedProperties.map { case (propertyName, baseTypeName) =>
ujson.Obj("baseType" -> baseTypeName, "name" -> propertyName)
}
json("properties") = nonInheritedProperties
json("schema") = schName
json("schemaIndex") = schemaIndex(nodeType)
json("isAbstract") = nodeType.isInstanceOf[NodeBaseType]
json("containedNodes") = containedNodes
Some(json)
}
}
Expand All @@ -107,11 +103,10 @@ object Schema2Json {
.filterNot(x => isSchemaHidden(x.schemaInfo))
.flatMap { edge =>
val schName = schemaName(edge.schemaInfo)
Some(
("name" -> edge.name) ~
("comment" -> edge.comment) ~
("schema" -> schName)
)
val json = ujson.Obj("name" -> edge.name)
edge.comment.foreach(comment => json("comment") = comment)
json("schema") = schName
Some(json)
}
}

Expand All @@ -121,11 +116,10 @@ object Schema2Json {
.filterNot(x => isSchemaHidden(x.schemaInfo))
.flatMap { prop =>
val schName = schemaName(prop.schemaInfo)
Some(
("name" -> prop.name) ~
("comment" -> prop.comment) ~
("schema" -> schName)
)
val json = ujson.Obj("name" -> prop.name)
prop.comment.foreach(comment => json("comment") = comment)
json("schema") = schName
Some(json)
}
}

Expand Down
Loading