Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0548ba9
Merging work done in forked Repository to own CloudPG branch (#61)
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
Jul 27, 2023
b2dbe84
remove FIXME-comment
Jul 27, 2023
f5ac54c
fix evaluation of body for HttpRequests
Jul 27, 2023
8c823d4
adapt the query of the D2-Go-tests (explanation in code comment)
Jul 27, 2023
9f7b060
add question to code comment
Jul 27, 2023
34ca07d
extend comment further
Jul 27, 2023
ec29130
revert adaptation of D2 test query
Jul 27, 2023
57c1be0
Add special case for AssignExpressions; Add the label to every corres…
Aug 7, 2023
eb4f478
change dependencies of go passes
Aug 7, 2023
dd97a82
flip pass order again
Aug 14, 2023
440ba7a
fix extraction of the Http request function body
Aug 14, 2023
537ebbc
add Pass dependencies
Aug 14, 2023
68d5644
remove comment as this was fixed in the LabelExtractionPass
Aug 14, 2023
dff9530
remove/change several FIXME-comments to narrow down the problem
Aug 21, 2023
02459dd
remove some warnings
Aug 21, 2023
818e27f
provide a fix for the python requests Pass by making it depend on the…
Aug 24, 2023
3c36d51
change the way the key generator is resolved
Aug 24, 2023
daefdfb
add Pass Dependencies
Aug 28, 2023
b644437
use the resolved VariableDeclaration when we want to add a Label to a…
Aug 28, 2023
e570174
double the expected result paths as there are now two paths from the …
Aug 28, 2023
8f41e67
add necessary pass dependencies for flask pass
Aug 31, 2023
bb94f57
add necessary pass dependencies for flask pass (fixes U3Python)
Sep 7, 2023
296512c
increase the expected number of results to two since the PI is now li…
Sep 25, 2023
de62716
double the expected amount of results because of the new paths
Sep 25, 2023
a02d5b3
changed other test cases where number of paths doubled
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
23ee859
fix python resolution
immqu Dec 19, 2024
e75c7b0
fix installation instructions for python frontend
interruptedHandshake Jan 20, 2025
89afc14
fix: build gradle for version upgrade to cpg 9.0.2
interruptedHandshake Jan 22, 2025
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
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@ Note that this project primarily serves as a research prototype, so please do no
## Setup and Build

### Python Setup
Please follow the instruction at https://github.com/ninia/jep/wiki/Getting-Started#installing-jep to install jep. Also, make sure you are using Python 3.10.

You need to install [jep](https://github.com/ninia/jep/). This can either be system-wide or in a virtual environment. Your jep version has to match the version used by the CPG (see [version catalog](./gradle/libs.versions.toml)).

Currently, only Python 3.{9,10,11,12,13} is supported.

##### System Wide

Follow the instructions at https://github.com/ninia/jep/wiki/Getting-Started#installing-jep.

##### Virtual Env

- `python3 -m venv ~/.virtualenvs/cpg`
- `source ~/.virtualenvs/cpg/bin/activate`
- `pip3 install jep`

Through the `JepSingleton`, the CPG library will look for well known paths on Linux and OS X. `JepSingleton` will prefer a virtualenv with the name `cpg`, this can be adjusted with the environment variable `CPG_PYTHON_VIRTUALENV`.

### Build
Note that we recommend using Java 17. First, the graph classes need to be built from the Ontology definitions by calling `./build-ontology.sh`. We aim to automate this process using a Gradle plugin in the future. Then, build using `./gradlew installDist`.
Expand Down
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 = "9.0.2"

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

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 ("org.xmlunit:xmlunit-core:2.9.0")
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
136 changes: 60 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,23 @@
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.Component
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 +34,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 +80,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 +121,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 +180,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 +195,14 @@ 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)
}
}

fun TranslationResult.findComponentByTU(tu: TranslationUnitDeclaration): Component? {
return this.additionalNodes.filterIsInstance<Component>().firstOrNull() {
it.translationUnits.contains(tu)
}
}
Expand Down
Loading
Loading