Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudPG v8 Upgrade #62

Draft
wants to merge 46 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0548ba9
Merging work done in forked Repository to own CloudPG branch (#61)
CodingDepot Jul 17, 2023
fcf7496
Adding dependency to GoExtraPass
oxisto Jul 17, 2023
153ae70
Playing around with the order of the passes
oxisto Jul 17, 2023
9694639
bump CPG version to 7.1.2
CodingDepot Jul 27, 2023
b2dbe84
remove FIXME-comment
CodingDepot Jul 27, 2023
f5ac54c
fix evaluation of body for HttpRequests
CodingDepot Jul 27, 2023
8c823d4
adapt the query of the D2-Go-tests (explanation in code comment)
CodingDepot Jul 27, 2023
9f7b060
add question to code comment
CodingDepot Jul 27, 2023
34ca07d
extend comment further
CodingDepot Jul 27, 2023
ec29130
revert adaptation of D2 test query
CodingDepot Jul 27, 2023
57c1be0
Add special case for AssignExpressions; Add the label to every corres…
CodingDepot Aug 7, 2023
eb4f478
change dependencies of go passes
CodingDepot Aug 7, 2023
dd97a82
flip pass order again
CodingDepot Aug 14, 2023
440ba7a
fix extraction of the Http request function body
CodingDepot Aug 14, 2023
537ebbc
add Pass dependencies
CodingDepot Aug 14, 2023
68d5644
remove comment as this was fixed in the LabelExtractionPass
CodingDepot Aug 14, 2023
dff9530
remove/change several FIXME-comments to narrow down the problem
CodingDepot Aug 21, 2023
02459dd
remove some warnings
CodingDepot Aug 21, 2023
818e27f
provide a fix for the python requests Pass by making it depend on the…
CodingDepot Aug 24, 2023
3c36d51
change the way the key generator is resolved
CodingDepot Aug 24, 2023
daefdfb
add Pass Dependencies
CodingDepot Aug 28, 2023
b644437
use the resolved VariableDeclaration when we want to add a Label to a…
CodingDepot Aug 28, 2023
e570174
double the expected result paths as there are now two paths from the …
CodingDepot Aug 28, 2023
8f41e67
add necessary pass dependencies for flask pass
CodingDepot Aug 31, 2023
bb94f57
add necessary pass dependencies for flask pass (fixes U3Python)
CodingDepot Sep 7, 2023
296512c
increase the expected number of results to two since the PI is now li…
CodingDepot Sep 25, 2023
de62716
double the expected amount of results because of the new paths
CodingDepot Sep 25, 2023
a02d5b3
changed other test cases where number of paths doubled
CodingDepot Sep 25, 2023
d3a5eaf
upgrade to cpgv8
immqu Apr 17, 2024
a5b1191
Upgraded kotlin and gradle
oxisto Apr 19, 2024
5ec4eeb
Pass ordering, but broken until cpg 8.2.0 is released
oxisto Apr 19, 2024
f6e0ebe
First Go test works
oxisto Apr 19, 2024
7dc76c1
++
oxisto Apr 19, 2024
38ddc06
add pass dependencies, initializer check
immqu Apr 20, 2024
f775d38
update build gradle with new Python fix
immqu May 2, 2024
b02f973
update cpg release
immqu Jun 6, 2024
f314be9
DFG edges between value and root seem not to be necessary anymore in …
konradweiss Jun 6, 2024
8820ab1
Merge branch 'cpg-version-update' of github.com:clouditor/cloud-prope…
konradweiss Jun 6, 2024
c1f6797
fix: expected number of pathes
interruptedHandshake Jun 14, 2024
026229c
fix: expected number of pathes
interruptedHandshake Jun 14, 2024
61b5250
++
immqu Jul 23, 2024
e1637fe
Merge branch 'cpg-version-update' of github.com:clouditor/cloud-prope…
immqu Jul 23, 2024
79ef63e
Using ValueEvaluator instead of ValueResolver
oxisto Jul 23, 2024
ab6e104
update cpg version, fix workflowhandler
immqu Nov 7, 2024
3731bae
fix dfg edge additions
immqu Nov 7, 2024
f64e8db
cosmetic fix
immqu Nov 7, 2024
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
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
// Apply the Kotlin JVM plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.7.20-Beta" apply false
kotlin("plugin.serialization") version "1.7.20-Beta" apply false
id("org.jetbrains.kotlin.jvm") version "1.9.20" apply false
kotlin("plugin.serialization") version "1.9.20" apply false
id("com.diffplug.spotless") version "5.12.1"
}

Expand All @@ -15,7 +15,7 @@ subprojects {
mavenCentral()

ivy {
setUrl("https://download.eclipse.org/tools/cdt/releases/10.2/cdt-10.2.0/plugins")
setUrl("https://download.eclipse.org/tools/cdt/releases/11.3/cdt-11.3.1/plugins")
metadataSources {
artifact()
}
Expand Down
39 changes: 23 additions & 16 deletions cloudpg/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.com.intellij.openapi.vfs.StandardFileSystems.jar

/*
* This file was generated by the Gradle 'init' task.
*
Expand All @@ -10,7 +8,7 @@ plugins {
application
idea
`maven-publish`
id("org.jetbrains.kotlinx.benchmark") version "0.4.4"
id("org.jetbrains.kotlinx.benchmark") version "0.4.10"
// use this plugin to set all classes open which is required for kotlinx benchmark: id("org.jetbrains.kotlin.plugin.allopen") version "1.7.20-Beta"
}

Expand All @@ -31,13 +29,13 @@ java {
sourceSets["main"].java {
srcDir("${generatedDir}/main/java")
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "11"
jvmTarget = "17"
}
}

Expand All @@ -50,6 +48,7 @@ publishing {
}

repositories {
mavenLocal()
mavenCentral()

maven { setUrl("https://jitpack.io") }
Expand All @@ -59,32 +58,40 @@ repositories {
}

ivy {
setUrl("https://download.eclipse.org/tools/cdt/releases/10.3/cdt-10.3.2/plugins")
setUrl("https://download.eclipse.org/tools/cdt/releases/")
metadataSources {
artifact()
}

patternLayout {
artifact("/[organisation].[module]_[revision].[ext]")
artifact("[organisation].[module]_[revision].[ext]")
}
}
}

dependencies {
implementation("org.junit.jupiter:junit-jupiter:5.7.0")
val version = "4.6.0"
implementation("com.github.Fraunhofer-AISEC:cpg:4e7c0b862e")
//implementation("de.fraunhofer.aisec:cpg-language-cxx:8.3.0")
//val version = "8.2.0"

implementation("de.fraunhofer.aisec:cpg-language-typescript:8.3.0")

implementation("de.fraunhofer.aisec:cpg-core:$version")
/*implementation("de.fraunhofer.aisec:cpg-core:$version")
implementation("de.fraunhofer.aisec:cpg-analysis:$version")
implementation("de.fraunhofer.aisec:cpg-language-go:$version")
implementation("de.fraunhofer.aisec:cpg-language-python:$version")
implementation("de.fraunhofer.aisec:cpg-language-typescript:$version")
implementation("de.fraunhofer.aisec:cpg-language-java:$version")
implementation("de.fraunhofer.aisec:cpg-language-cxx:$version")*/

implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.+")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.2")
implementation ("org.xmlunit:xmlunit-core:2.9.0")
implementation("org.xmlunit:xmlunit-matchers:2.9.0")

api("org.neo4j", "neo4j-ogm-core", "3.2.31")
api("org.neo4j", "neo4j-ogm", "3.2.21")
api("org.neo4j", "neo4j-ogm-bolt-driver", "3.2.21")
api("org.neo4j", "neo4j-ogm-core", "4.0.10")
api("org.neo4j", "neo4j-ogm", "4.0.10")
api("org.neo4j", "neo4j-ogm-bolt-driver", "4.0.10")

implementation(platform("org.jetbrains.kotlin:kotlin-bom"))

Expand Down Expand Up @@ -118,7 +125,7 @@ dependencies {

application {
// Define the main class for the application.
mainClassName = "io.clouditor.graph.AppKt"
mainClass = "io.clouditor.graph.AppKt"
}

tasks.named("compileJava") {
Expand Down Expand Up @@ -159,7 +166,7 @@ kotlin {
sourceSets {
test {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.4")
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.10")
}
}
}
Expand Down
129 changes: 53 additions & 76 deletions cloudpg/src/main/java/io/clouditor/graph/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
package io.clouditor.graph

import de.fraunhofer.aisec.cpg.*
import de.fraunhofer.aisec.cpg.frontends.golang.GoLanguageFrontend
import de.fraunhofer.aisec.cpg.frontends.python.PythonLanguageFrontend
import de.fraunhofer.aisec.cpg.frontends.typescript.TypeScriptLanguageFrontend
import de.fraunhofer.aisec.cpg.frontends.cxx.CLanguage
import de.fraunhofer.aisec.cpg.frontends.cxx.CPPLanguage
import de.fraunhofer.aisec.cpg.frontends.golang.GoLanguage
import de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage
import de.fraunhofer.aisec.cpg.frontends.python.PythonLanguage
import de.fraunhofer.aisec.cpg.frontends.typescript.TypeScriptLanguage
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.allChildren
import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration
import de.fraunhofer.aisec.cpg.graph.graph
import de.fraunhofer.aisec.cpg.helpers.Benchmark
import io.clouditor.graph.frontends.ruby.RubyLanguageFrontend
import io.clouditor.graph.nodes.Builder
import io.clouditor.graph.passes.*
import io.clouditor.graph.passes.golang.*
import io.clouditor.graph.passes.java.JaxRsClientPass
import io.clouditor.graph.passes.java.JaxRsPass
import io.clouditor.graph.passes.java.SpringBootPass
import io.clouditor.graph.passes.js.FetchPass
import io.clouditor.graph.passes.js.JSHttpPass
import io.clouditor.graph.passes.python.*
import io.clouditor.graph.passes.ruby.WebBrickPass
import io.clouditor.graph.testing.LocalTestingPass
import java.nio.file.Path
import java.util.concurrent.Callable
Expand All @@ -35,12 +33,6 @@ import picocli.CommandLine
mixinStandardHelpOptions = true,
description = ["Builds the Cloud Property Graph and persists it into a graph database."]
)
@OptIn(
ExperimentalTypeScript::class,
ExperimentalPython::class,
ExperimentalGolang::class,
ExperimentalGraph::class
)
object App : Callable<Int> {
@CommandLine.Option(
names = ["-k8s-n", "--kubernetes-namespaces"],
Expand Down Expand Up @@ -87,18 +79,24 @@ object App : Callable<Int> {
.build()

val sessionFactory =
SessionFactory(configuration, "de.fraunhofer.aisec.cpg.graph", "io.clouditor.graph")
SessionFactory(
configuration,
"de.fraunhofer.aisec.cpg.graph",
"io.clouditor.graph",
"de.fraunhofer.aisec.cpg.frontends"
)
val session = sessionFactory.openSession()

val result = doTranslate()

val nodes = mutableListOf<Node>()
nodes.addAll(result.graph.nodes)
nodes.addAll(result.translationUnits)
val translationUnits =
result.components.stream().flatMap { it.translationUnits.stream() }.toList()
nodes.addAll(result.allChildren())
nodes.addAll(result.images)
nodes.addAll(result.builders)
nodes.addAll(result.computes)
nodes.addAll(result.translationUnits)
nodes.addAll(translationUnits)
nodes.addAll(result.additionalNodes)

session.beginTransaction().use { transaction ->
Expand All @@ -122,68 +120,53 @@ object App : Callable<Int> {
val builder =
TranslationConfiguration.builder()
.topLevel(rootPath.toFile())
.sourceLocations(paths.map { rootPath.resolve(it).toFile() })
.defaultPasses()
.defaultLanguages()
.registerLanguage(
RubyLanguageFrontend::class.java,
RubyLanguageFrontend.RUBY_EXTENSIONS
)
.registerLanguage(
TypeScriptLanguageFrontend::class.java,
TypeScriptLanguageFrontend.TYPESCRIPT_EXTENSIONS +
TypeScriptLanguageFrontend.JAVASCRIPT_EXTENSIONS
)
.registerLanguage(
PythonLanguageFrontend::class.java,
PythonLanguageFrontend.PY_EXTENSIONS
)
.registerLanguage(
GoLanguageFrontend::class.java,
GoLanguageFrontend.GOLANG_EXTENSIONS
)
.sourceLocations(paths.map { rootPath.resolve(it).toFile().normalize() })
.registerLanguage(JavaLanguage())
.registerLanguage(CPPLanguage())
.registerLanguage(CLanguage())
.registerLanguage(TypeScriptLanguage())
.registerLanguage(PythonLanguage())
.registerLanguage(GoLanguage())
.debugParser(true)
.registerPass(GitHubWorkflowPass())
.registerPass(SpringBootPass())
.registerPass(JaxRsPass())
.registerPass(GolangHttpPass())
.registerPass(GinGonicPass())
.registerPass(WebBrickPass())
.registerPass(JSHttpPass())
.registerPass(FlaskPass())
.defaultPasses()
.registerPass(GitHubWorkflowPass::class)
// .registerPass(SpringBootPass::class)
// .registerPass(JaxRsPass::class)
.registerPass(GolangHttpPass::class)
.registerPass(GinGonicPass::class)
// .registerPass(WebBrickPass::class)
// .registerPass(JSHttpPass::class)
// .registerPass(FlaskPass::class)
.apply {
if (localMode) {
// register the localTestingPass after the HTTP Passes since it needs HTTP
// request handlers
registerPass(LocalTestingPass())
registerPass(GolangHttpRequestPass())
registerPass(LocalTestingPass::class)
registerPass(GolangHttpRequestPass::class)
} else {
registerPass(AzurePass())
registerPass(AzureClientSDKPass())
registerPass(KubernetesPass())
registerPass(IngressInvocationPass())
registerPass(AzurePass::class)
registerPass(AzureClientSDKPass::class)
registerPass(KubernetesPass::class)
registerPass(IngressInvocationPass::class)
}
}
.registerPass(CryptographyPass())
.registerPass(GoCryptoPass())
.registerPass(JaxRsClientPass())
.registerPass(FetchPass())
.registerPass(RequestsPass())
.registerPass(PythonLogPass())
.registerPass(GolangLogPass())
.registerPass(GormDatabasePass())
.registerPass(PyMongoPass())
.registerPass(Psycopg2Pass())
.registerPass(CryptographyPass::class)
.registerPass(GoCryptoPass::class)
.registerPass(JaxRsClientPass::class)
.registerPass(FetchPass::class)
.registerPass(RequestsPass::class)
.registerPass(PythonLogPass::class)
.registerPass(GolangLogPass::class)
.registerPass(GormDatabasePass::class)
.registerPass(PyMongoPass::class)
.registerPass(Psycopg2Pass::class)
.processAnnotations(true)

if (labelsEnabled) {
val edgesCache: BidirectionalEdgesCachePass = BidirectionalEdgesCachePass()
val labelPass: LabelExtractionPass = LabelExtractionPass()
labelPass.edgesCachePass = edgesCache
builder
.registerPass(DFGExtensionPass())
.registerPass(edgesCache)
.registerPass(labelPass)
.registerPass(DFGExtensionPass::class)
.registerPass(BidirectionalEdgesCachePass::class)
.registerPass(LabelExtractionPass::class)
.matchCommentsToNodes(true)
}

Expand All @@ -196,7 +179,6 @@ object App : Callable<Int> {
}
}

@OptIn(ExperimentalPython::class, ExperimentalTypeScript::class, ExperimentalGolang::class)
fun main(args: Array<String>): Unit = exitProcess(CommandLine(App).execute(*args))

val TranslationResult.images: MutableList<Image>
Expand All @@ -212,13 +194,8 @@ val TranslationResult.computes: MutableList<Compute>
this.scratch.computeIfAbsent("computes") { mutableListOf<Compute>() } as
MutableList<Compute>

val TranslationResult.additionalNodes: MutableList<Node>
get() =
this.scratch.computeIfAbsent("additionalNodes") { mutableListOf<Node>() } as
MutableList<Node>

fun TranslationResult.findApplicationByTU(tu: TranslationUnitDeclaration): Application? {
return this.additionalNodes.filterIsInstance(Application::class.java).firstOrNull {
return this.additionalNodes.filterIsInstance<Application>().firstOrNull {
it.translationUnits.contains(tu)
}
}
Expand Down
17 changes: 10 additions & 7 deletions cloudpg/src/main/java/io/clouditor/graph/ValueResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import de.fraunhofer.aisec.cpg.graph.statements.expressions.*
* literal values. Furthermore, its behaviour can be adjusted by implementing the [cannotResolve]
* function, which is called when the default behaviour would not be able to resolve the value. This
* way, language specific features such as string formatting can be modelled.
*
* TODO: Replace with Evaluator from the new cpg-analysis package
*/
open class ValueResolver(
/**
Expand Down Expand Up @@ -44,7 +46,7 @@ open class ValueResolver(
when (expr) {
is KeyValueExpression -> return resolve(expr.value)
is Literal<*> -> return expr.value?.toString() ?: ""
is DeclaredReferenceExpression -> return resolveDeclaration(expr.refersTo)
// is Reference -> return resolveDeclaration(expr.refersTo)
is BinaryOperator -> {
// resolve lhs
val lhsValue = resolve(expr.lhs)
Expand Down Expand Up @@ -117,10 +119,8 @@ open class ValueResolver(
is CastExpression -> {
return this.resolve(expr.expression)
}
is ArraySubscriptionExpression -> {
val array =
(expr.arrayExpression as? DeclaredReferenceExpression)?.refersTo as?
VariableDeclaration
is SubscriptExpression -> {
val array = (expr.arrayExpression as? Reference)?.refersTo as? VariableDeclaration
val ile = array?.initializer as? InitializerListExpression

ile?.let {
Expand All @@ -144,14 +144,17 @@ open class ValueResolver(
val rhs = resolve((expr.condition as? BinaryOperator)?.rhs)

return if (lhs == rhs) {
resolve(expr.thenExpr)
resolve(expr.thenExpression)
} else {
resolve(expr.elseExpr)
resolve(expr.elseExpression)
}
}

return cannotResolve(expr, this)
}
is Reference -> {
return expr.refersTo
}
}

return cannotResolve(expr, this)
Expand Down
Loading
Loading