CLI tool for leveraging the Code Transformation Language (CodeTL) to apply complex source code transformations to projects.
Follow these instructions if you intend to modify and build this project from source.
-
Install GraalVM 22.3.0
-
Install native-image and JavaScript components
gu install native-image js
-
Initialize Submodules
git submodule init git submodule update
-
Configure JFrog Artifactory Authentication by adding the following properties to your Gradle home gradle.properties (typically
$HOME/.gradle/gradle.properties):pixeeArtifactoryUsername=<your-username> pixeeArtifactoryPassword=<your-token>
./gradlew assembleThe built binary is at path ./cli/build/native/nativeCompile/codetl
./gradlew checkCodeTL is a language agnostic tool and code transformation domain specific language (DSL). Support
for a language is added by an extension called a "language provider". These language providers may be found in the ./languages directory.
In the working architecture, language providers are written in the language they support. For example, the JavaScript language provider is largely written in TypeScript. This proof of concept demonstrates how to integrate language providers into one process where interoperability between languages is provided by GraalVM.
The proof of concept application demonstrates reading JavaScript source files in Java then using GraalVM's polyglot SDK to transform those source files with transformations written in TypeScript. A Gradle build ties all the projects together and produces a binary using GraalVM's native-image tool.
- The JavaScript transformation logic is written in TypeScript in the
subproject
languages/javascript. The TypeScript compiler generates ES5 compatible JavaScript that uses the CommonJS module system. - The JavaScript module
module-provider.tsis the API exposed by the JavaScript language provider's TypeScript code to the Java code. As such, this module takes care not to depend on any modules that are incompatible when running in a binary produced by GraalVM'snative-imagetool. - Browserify creates a bundle from
module-provider.ts. The Gradle build inlanguages/javascriptshells out tonpmto create this bundle, and the Gradle build includes the built bundle as a artifact so that other Gradle subprojects may depend on it. - The
clisubproject's Gradle build script copies the bundle built by thelanguages/javascriptinto the GraalVM native image. - The Java code in the
clisubproject reads the JavaScript bundle from the classpath and evaluates it in using the GraalVM polyglot SDK. It then reads each JavaScript source file in the given repository and transforms it using the transformation function exposed by the bundle.