Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
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
6 changes: 3 additions & 3 deletions sqlcl/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ var javaFiles = Java.type("java.nio.file.Files");
var javaCollectors = Java.type("java.util.stream.Collectors");
var javaPersist2XML = Java.type("oracle.dbtools.app.Persist2XML");
var javaPattern = Java.type("java.util.regex.Pattern");
var javaSQLCommand = Java.type("oracle.dbtools.raptor.newscriptrunner.SQLCommand");
var javaFormat = Java.type("oracle.dbtools.app.Format");
var javaLexer = Java.type("oracle.dbtools.parser.Lexer");
var javaParsed = Java.type("oracle.dbtools.parser.Parsed");
var javaSqlEarley = Java.type("oracle.dbtools.parser.plsql.SqlEarley");
var javaSystem = Java.type("java.lang.System");
var javaCommandRegistry = Java.type("oracle.dbtools.raptor.newscriptrunner.CommandRegistry");
var javaCommandListener = Java.type("oracle.dbtools.raptor.newscriptrunner.CommandListener");

var getFiles = function (rootPath, extensions) {
var files;
Expand Down Expand Up @@ -515,6 +512,9 @@ var registerTvdFormat = function () {

// main
if (args.length >= 2 && (args[1].equalsIgnoreCase("-r") || args[1].equalsIgnoreCase("--register"))) {
var javaSQLCommand = Java.type("oracle.dbtools.raptor.newscriptrunner.SQLCommand");
var javaCommandRegistry = Java.type("oracle.dbtools.raptor.newscriptrunner.CommandRegistry");
var javaCommandListener = Java.type("oracle.dbtools.raptor.newscriptrunner.CommandListener");
registerTvdFormat();
} else {
run(args);
Expand Down
131 changes: 77 additions & 54 deletions standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.googlecode.addjars-maven-plugin</groupId>
<artifactId>addjars-maven-plugin</artifactId>
<version>1.0.5</version>
<executions>
<execution>
<goals>
<goal>add-jars</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${sqlcl.libdir}</directory>
<includes>
<include>**/dbtools-common.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>3.8.1</version>
Expand All @@ -70,56 +92,59 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<finalName>${project.artifactId}</finalName>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.trivadis.plsql.formatter.TvdFormat</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Class-Path>lib/dbtools-common-21.2.0.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
<goal>shade</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeTransitive>false</excludeTransitive>
<includeScope>compile</includeScope>
<stripVersion>false</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
<finalName>${artifactId}</finalName>
<shadedArtifactAttached>false</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.trivadis.plsql.formatter.TvdFormat</Main-Class>
<Class-Path>.</Class-Path>
</manifestEntries>
</transformer>
</transformers>
<filters>
<filter>
<!-- remove conflicting resources (not required) -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>module-info.class</exclude>
<exclude>META-INF/versions/**</exclude>
</excludes>
</filter>
<filter>
<!-- include required packages for formatter -->
<artifact>*:*dbtools-common*</artifact>
<includes>
<include>oracle/dbtools/app/**</include>
<include>oracle/dbtools/arbori/**</include>
<include>oracle/dbtools/parser/**</include>
<include>oracle/dbtools/raptor/*</include>
<include>oracle/dbtools/raptor/utils/**</include>
<include>oracle/dbtools/util/**</include>
</includes>
</filter>
<filter>
<!-- include all classes and resources from this project -->
<artifact>*:tvdformat</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters>
</configuration>
</plugin>
<plugin>
Expand All @@ -136,18 +161,16 @@
</executions>
<configuration>
<skip>${skip.native}</skip>
<imageName>tvdformat</imageName>
<!-- "-language:js -no-fallback" leads to a runtime error:
Exception in thread "main" javax.script.ScriptException: org.graalvm.polyglot.PolyglotException: TypeError: Access to host class java.lang.String is not allowed or does not exist.
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.toScriptException(GraalJSScriptEngine.java:483)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:460)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:400)
at com.trivadis.plsql.formatter.TvdFormat.run(TvdFormat.java:40)
at com.trivadis.plsql.formatter.TvdFormat.main(TvdFormat.java:46)
Caused by: org.graalvm.polyglot.PolyglotException: TypeError: Access to host class java.lang.String is not allowed or does not exist.
at <js>.:program(<eval>:19)
at org.graalvm.polyglot.Context.eval(Context.java:375)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458)
<imageName>${project.artifactId}</imageName>
<mainClass>com.trivadis.plsql.formatter.TvdFormat</mainClass>
<!-- Creating a native image with "-language:js -no-fallback -H:ReflectionConfigurationFiles=..."
was e dead end. There were various issues, such as
- different behavior between JS/Java Strings and their methods
- laborious identification of classes used via reflection
- long build times (~280 seconds)
- very large image size (437MB)
Therefore, creating a native image which requires a JDK was much simpler.
The drawback is a slower startup time. However, loading 437MB is not fast ether, at least the first time.
-->
<buildArgs>
-H:IncludeResources=.* --force-fallback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@ public class TvdFormat {
TvdFormat() {
scriptEngine = GraalJSScriptEngine.create(null,
Context.newBuilder("js")
.option("js.nashorn-compat", "true")
.allowHostAccess(true)
.allowNativeAccess(true)
.allowCreateThread(true)
.allowIO(true)
.allowHostClassLoading(true)
.allowHostClassLookup((Predicate<String>) s -> true)
.allowAllAccess(true));
.option("js.nashorn-compat", "true")
.allowAllAccess(true));
ctx = new ScriptRunnerContext();
ctx.setOutputStream(System.out);
scriptEngine.getContext().setAttribute("ctx", ctx, ScriptContext.ENGINE_SCOPE);
}

public void run(String[] arguments) throws IOException, ScriptException {
LogManager.getLogManager().reset();
URL script = Thread.currentThread().getContextClassLoader().getResource("format.js");
String[] args = new String[arguments.length + 1];
args[0] = "format.js";
Expand All @@ -42,6 +35,7 @@ public void run(String[] arguments) throws IOException, ScriptException {
}

public static void main(String[] args) throws IOException, ScriptException {
LogManager.getLogManager().reset();
System.setProperty("tvdformat.standalone", "true");
System.setProperty("polyglot.engine.WarnInterpreterOnly", "false");
TvdFormat formatter = new TvdFormat();
Expand Down