Skip to content

Commit

Permalink
Extracting typescript into separate module (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto authored Jun 29, 2022
1 parent 459b357 commit 4072c7d
Show file tree
Hide file tree
Showing 28 changed files with 122 additions and 61 deletions.
25 changes: 14 additions & 11 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
* @konradweiss @oxisto
* @konradweiss @oxisto

*.go @oxisto
cpg-language-go @oxisto
*.go @oxisto
cpg-language-go @oxisto

*.py @maximiliankaul
cpg-language-python @maximiliankaul
*.ts @oxisto
cpg-language-typescript @oxisto

*.ll @KuechA
cpg-language-llvm @KuechA
cpg-analysis @KuechA
*.py @maximiliankaul
cpg-language-python @maximiliankaul

cpg-neo4j @peckto
*.ll @KuechA
cpg-language-llvm @KuechA
cpg-analysis @KuechA

build.gradle.kts @oxisto
.github @oxisto
cpg-neo4j @peckto

build.gradle.kts @oxisto
.github @oxisto
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ updates:
- dependency-name: "*"
update-types: ["version-update:semver-patch"]
- package-ecosystem: "npm"
directory: "/cpg-core/src/main/nodejs"
directory: "/cpg-language-typescript/src/main/nodejs"
schedule:
interval: "daily"
labels:
Expand Down
3 changes: 0 additions & 3 deletions cpg-console/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ dependencies {
// CPG
api(project(":cpg-core"))
api(project(":cpg-analysis"))
api(project(":cpg-language-llvm"))
api(project(":cpg-language-python"))
api(project(":cpg-language-go"))
api(project(":cpg-neo4j"))

implementation("org.apache.logging.log4j:log4j-slf4j18-impl:2.17.2")
Expand Down
42 changes: 0 additions & 42 deletions cpg-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
* \______/ \__| \______/
*
*/
import com.github.gradle.node.yarn.task.YarnTask

plugins {
`java-library`
`java-test-fixtures`
signing

id("com.github.node-gradle.node") version "3.4.0"
}

publishing {
Expand All @@ -53,48 +49,10 @@ tasks.named<Test>("test") {
if (!project.hasProperty("experimental")) {
excludeTags("experimental")
}

if (!project.hasProperty("experimentalTypeScript")) {
excludeTags("experimentalTypeScript")
}
}
maxHeapSize = "4048m"
}

node {
download.set(findProperty("nodeDownload")?.toString()?.toBoolean() ?: false)
version.set("16.4.2")
}

val yarnInstall by tasks.registering(YarnTask::class) {
inputs.file("src/main/nodejs/package.json").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.file("src/main/nodejs/yarn.lock").withPathSensitivity(PathSensitivity.RELATIVE)
outputs.dir("src/main/nodejs/node_modules")
outputs.cacheIf { true }

workingDir.set(file("src/main/nodejs"))
yarnCommand.set(listOf("install", "--ignore-optional"))
}

val yarnBuild by tasks.registering(YarnTask::class) {
inputs.file("src/main/nodejs/package.json").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.file("src/main/nodejs/yarn.lock").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.dir("src/main/nodejs/src").withPathSensitivity(PathSensitivity.RELATIVE)
outputs.dir("build/resources/main/nodejs")
outputs.cacheIf { true }

workingDir.set(file("src/main/nodejs"))
yarnCommand.set(listOf("bundle"))

dependsOn(yarnInstall)
}

if (project.hasProperty("experimentalTypeScript")) {
tasks.processResources {
dependsOn(yarnBuild)
}
}

dependencies {
api("org.apache.commons:commons-lang3:3.12.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import de.fraunhofer.aisec.cpg.frontends.LanguageFrontend;
import de.fraunhofer.aisec.cpg.frontends.cpp.CXXLanguageFrontend;
import de.fraunhofer.aisec.cpg.frontends.java.JavaLanguageFrontend;
import de.fraunhofer.aisec.cpg.frontends.typescript.TypeScriptLanguageFrontend;
import de.fraunhofer.aisec.cpg.graph.declarations.Declaration;
import de.fraunhofer.aisec.cpg.graph.declarations.RecordDeclaration;
import de.fraunhofer.aisec.cpg.graph.declarations.TemplateDeclaration;
Expand Down Expand Up @@ -57,11 +56,11 @@ public class TypeManager {
private static Class<?> llvmClass = null;
private static Class<?> pythonClass = null;
private static Class<?> goClass = null;
private static Class<?> typescriptClass = null;

static {
try {
llvmClass = Class.forName("de.fraunhofer.aisec.cpg.frontends.llvm.LLVMIRLanguageFrontend");

} catch (ClassNotFoundException | ExceptionInInitializerError ignored) {
log.info("LLVM frontend not loaded.");
}
Expand All @@ -78,6 +77,12 @@ public class TypeManager {
} catch (LinkageError ex) {
log.error("Go frontend was found, but could not be loaded", ex);
}
try {
typescriptClass =
Class.forName("de.fraunhofer.aisec.cpg.frontends.typescript.TypeScriptLanguageFrontend");
} catch (ClassNotFoundException | ExceptionInInitializerError ignored) {
log.info("TypeScript frontend not loaded.");
}
}

private static final List<String> primitiveTypeNames =
Expand Down Expand Up @@ -600,7 +605,9 @@ public Language getLanguage() {
&& pythonClass != null
&& pythonClass.isAssignableFrom(frontend.getClass())) {
return Language.PYTHON;
} else if (frontend instanceof TypeScriptLanguageFrontend) {
} else if (frontend != null
&& typescriptClass != null
&& typescriptClass.isAssignableFrom(frontend.getClass())) {
return Language.TYPESCRIPT;
} else if (frontend != null
&& llvmClass != null
Expand Down
94 changes: 94 additions & 0 deletions cpg-language-typescript/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2022, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
import com.github.gradle.node.yarn.task.YarnTask

plugins {
`java-library`

id("com.github.node-gradle.node") version "3.4.0"
}

publishing {
publications {
named<MavenPublication>("cpg-language-typescript") {
pom {
artifactId = "cpg-language-typescript"
name.set("Code Property Graph - JavaScript/TypeScript Frontend")
description.set("A JavaScript/TypeScript language frontend for the CPG")
}
}
}
}

dependencies {
api(project(":cpg-core"))

testImplementation(testFixtures(project(":cpg-core")))
}


node {
download.set(findProperty("nodeDownload")?.toString()?.toBoolean() ?: false)
version.set("16.4.2")
}

val yarnInstall by tasks.registering(YarnTask::class) {
inputs.file("src/main/nodejs/package.json").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.file("src/main/nodejs/yarn.lock").withPathSensitivity(PathSensitivity.RELATIVE)
outputs.dir("src/main/nodejs/node_modules")
outputs.cacheIf { true }

workingDir.set(file("src/main/nodejs"))
yarnCommand.set(listOf("install", "--ignore-optional"))
}

val yarnBuild by tasks.registering(YarnTask::class) {
inputs.file("src/main/nodejs/package.json").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.file("src/main/nodejs/yarn.lock").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.dir("src/main/nodejs/src").withPathSensitivity(PathSensitivity.RELATIVE)
outputs.dir("build/resources/main/nodejs")
outputs.cacheIf { true }

workingDir.set(file("src/main/nodejs"))
yarnCommand.set(listOf("bundle"))

dependsOn(yarnInstall)
}

if (project.hasProperty("experimentalTypeScript")) {
tasks.processResources {
dependsOn(yarnBuild)
}
}

tasks.named<Test>("test") {
useJUnitPlatform {
if (!project.hasProperty("experimentalTypeScript")) {
excludeTags("experimentalTypeScript")
}
}
maxHeapSize = "4048m"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import org.junit.jupiter.api.Tag

@Tag("experimentalTypeScript")
@ExperimentalTypeScript
class TypescriptLanguageFrontendTest {
class TypeScriptLanguageFrontendTest {

@Test
fun testFunction() {
Expand Down
1 change: 1 addition & 0 deletions cpg-neo4j/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ dependencies {
api(project(":cpg-language-llvm"))
api(project(":cpg-language-python"))
api(project(":cpg-language-go"))
api(project(":cpg-language-typescript"))

implementation("org.apache.logging.log4j:log4j-slf4j18-impl:2.17.2")

Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include(":cpg-neo4j")
include(":cpg-language-llvm")
include(":cpg-language-python")
include(":cpg-language-go")
include(":cpg-language-typescript")
include(":cpg-console")

gradleEnterprise {
Expand Down

0 comments on commit 4072c7d

Please sign in to comment.