Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit b74d372

Browse files
Merge pull request #270 from Trivadis/feature/issue-269-sqlcl-23.4.0
Feature/issue 269 sqlcl 23.4.0
2 parents daae7f5 + ad6aab1 commit b74d372

13 files changed

Lines changed: 165 additions & 176 deletions

File tree

README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ This repository provides formatter settings for the [coding style rules](https:/
66

77
Settings are primarily provided for
88

9-
- [Oracle SQLcl, Version 23.3.0](https://www.oracle.com/tools/downloads/sqlcl-downloads.html)
9+
- [Oracle SQLcl, Version 23.4.0](https://www.oracle.com/tools/downloads/sqlcl-downloads.html)
1010
- [Oracle SQL Developer, Version 23.1.1](https://www.oracle.com/tools/downloads/sqldev-downloads.html) (requires `dbtools-common.jar` from SQLcl 23.3.0)
1111

1212
These settings have been defined and tested with the product versions mentioned above. They might not work in other versions.
1313

14+
Please note, that these settings cannot be used in [Oracle SQL Developer for VSCode 23.4.0](https://marketplace.visualstudio.com/items?itemName=Oracle.sql-developer). And it does not work in the embedded version of SQLcl 23.3.1.0, which cannot run JavaScript.
15+
1416
JDK 11 is required for SQLDev and SQLcl. The standalone tvdformat.jar works with JDK 11 or newer.
1517

1618
See [releases](https://github.com/Trivadis/plsql-formatter-settings/releases) for settings supporting older versions.
@@ -21,7 +23,9 @@ SQL Developer is slowly reaching the end of its life cycle. The days when SQL De
2123

2224
A new SQLcl version typically comes with enhancements and bug fixes in the area of PL/SQL and SQL grammar. And this also requires an adaptation of the formatting rule due to symbol name changes etc. And as a result, these formatting rules can actually only be used in SQLcl.
2325

24-
However, we know that the grammars and the formatter are provided in a JAR called `dbtools-common.jar`. And this JAR file also exists in the SQL Developer distribution. This means that in order to be able to use the current formatting rules in SQL Developer, we have to copy the `dbtools-common.jar` file from SQLcl to SQL Developer as follows:
26+
However, we know that the grammars and the formatter are provided in a JAR called `dbtools-common.jar`. And this JAR file also exists in the SQL Developer distribution. This means that in order to be able to use the current formatting rules in SQL Developer, we have to copy the `dbtools-common.jar` file from SQLcl to SQL Developer. Unfortunatelly the classes are not 100% compatible with the SQL Developer. As a a result, we have to keep some original classes, which complicates the patching process a bit.
27+
28+
Here's the full procedure to use `dbtools-common.jar` from SQLcl 23.4.0 in SQL Developer 23.1.1.345:
2529

2630
1. Quit SQL Developer
2731

@@ -35,11 +39,31 @@ However, we know that the grammars and the formatter are provided in a JAR calle
3539

3640
Find the `dbtools-common.jar` in your SQLcl installation. In our case it's in `/usr/local/bin/sqlcl/lib`. Copy the file to the SQL Developer’s directory (where `dbtools-common.original.jar` is located).
3741

38-
4. Start SQL Developer
42+
4. Patch SQLcl's `dbtools-common.jar`
43+
44+
Open a terminal window in the `lib` folder where `dbtools-common.original.jar` and `dbtools-commmon.jar` are located and run the following commands to copy the class `oracle.dbtools.parser.ParserNode.class` to `dbtools-common.jar`:
45+
46+
```bash
47+
jar -xvf dbtools-common.original.jar oracle/dbtools/parser/ParseNode.class
48+
jar -u0vMf dbtools-common.jar oracle/dbtools
49+
rm -rf oracle
50+
```
51+
52+
This step is necessary to ensure that the "Code Outline" continues to work in SQL Developer.
53+
54+
5. Clear SQL Developer's cache
55+
56+
Delete the following directory:
57+
58+
- On Windows: `%APPDATA%\SQL Developer\system23.1.1.345.2114\system_cache`
59+
- On other platforms: `$HOME/.sqldeveloper/system23.1.1.345.2114/system_cache`
60+
61+
This step is necessary to ensure no other version of `dbtools-common.jar` is used from the cache. You will all
62+
window settings. However, all other preferences including your connections are preserved.
3963

40-
Open an editor and test if the formatter is working.
64+
6. Start SQL Developer
4165

42-
We have successfully tested this procedure with SQL Developer 23.1.1. However, there were cases in the past where this did not work. For example, using the JAR of SQLcl 20.3.0 in SQL Developer 20.2.0. Replacing a JAR requires a certain level of compatiblity. We therefore expect that this procedure will no longer work with an upcoming version of SQLcl. We will update this section as soon as we know more.
66+
Open an editor and test if the formatter and code outline is working.
4367

4468
## Deviating Settings
4569

@@ -137,7 +161,7 @@ SQL Developer uses its own parse tree query language called Arbori for its advan
137161

138162
#### Links
139163

140-
- [SQL Developer 22.2 User Guide, Code Editor: Format](https://docs.oracle.com/en/database/oracle/sql-developer/22.2/rptug/sql-developer-concepts-usage.html#GUID-9421DA6E-A48A-427B-88C9-4414D83EC9D1__CODEEDITORFORMAT-C73DB981)
164+
- [SQL Developer 23.1 User Guide, Code Editor: Format](https://docs.oracle.com/en/database/oracle/sql-developer/23.1/rptug/sql-developer-concepts-usage.html#GUID-9421DA6E-A48A-427B-88C9-4414D83EC9D1__CODEEDITORFORMAT-C73DB981)
141165
- [Formatting Code With SQL Developer](https://www.salvis.com/blog/2020/04/13/formatting-code-with-sql-developer/)
142166
- [Formatter Callback Functions](https://www.salvis.com/blog/2020/11/12/formatter-callback-functions/)
143167
- [Arbori Starter Manual](https://vadimtropashko.files.wordpress.com/2017/02/arbori-starter-manual.pdf)

settings/sql_developer/trivadis_custom_format.arbori

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
include "std.arbori"
1818

1919
/**
20-
* Lightweight Formatter for SQL Developer and SQLcl, version 23.3.1-SNAPSHOT
20+
* Lightweight Formatter for SQL Developer and SQLcl, version 23.4.0-SNAPSHOT
2121
* The idea is to keep the code formatted "as is" and apply chosen formatting rules only.
2222
*
2323
* The Arbori program is processed from top to bottom.
@@ -157,9 +157,22 @@ d1_initialize_timer:
157157
dontFormatNode:
158158
[node) numeric_literal
159159
| [node) path -- expected in SQL*Plus, SQLcl commands only
160+
| [node) "create_java"
160161
->
161162
;
162163

164+
enableKeepQutoedIdentifiersForCall:
165+
runOnce
166+
-> {
167+
var keepQuotedIdentifiersForCall = false;
168+
}
169+
170+
enforceKeepQuotedIdentifiersForCall:
171+
[node) "create_java"
172+
-> {
173+
keepQuotedIdentifiersForCall = true;
174+
}
175+
163176
-- --------------------------------------------------------------------------------------------------------------------
164177
-- I5: Define global variables and functions.
165178
-- --------------------------------------------------------------------------------------------------------------------
@@ -638,6 +651,7 @@ i10_determine_and_normalize_line_separators:
638651
-- - The identifier is not part of a code section for which the formatter is disabled.
639652
-- - The identifier is not part of a conditional compilation block.
640653
-- - The identifier is not a reserved keyword
654+
-- - The variable keepQuotedIdentifiersForCall is true (set at the beginning, disabled for Java)
641655
--
642656
-- Quoted identifiers look like strings in Java and other languages. The parser in SQLDev 22.2.0 does not
643657
-- understand Java stored procedures. Trying to format a Java stored procedure leads to a syntax error.
@@ -759,7 +773,7 @@ i11_enforce_nonquoted_identifiers:
759773
// get custom option keepQuotedIdentifiers (might not exist)
760774
var keepQuotedIdentifiers = struct.options.get("keepQuotedIdentifiers");
761775

762-
if (keepQuotedIdentifiers == null || !keepQuotedIdentifiers) {
776+
if ((keepQuotedIdentifiers == null || !keepQuotedIdentifiers) && !keepQuotedIdentifiersForCall) {
763777
findAndConvertQuotedIdentifiers();
764778
}
765779
}

sqlcl/format.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var javaSqlEarley = Java.type("oracle.dbtools.parser.plsql.SqlEarley");
5151
var javaProgram = Java.type("oracle.dbtools.arbori.Program");
5252

5353
var getVersion = function() {
54-
return "23.3.1-SNAPSHOT";
54+
return "23.4.0-SNAPSHOT";
5555
}
5656

5757
var getFiles = function (rootPath, extensions, ignoreMatcher) {
@@ -759,8 +759,12 @@ var unregisterTvdFormat = function () {
759759
.stream().map(function(l) {return l.getClass()}).collect(javaCollectors.toSet());
760760
// re-register all commands except for class TvdFormat and remaining (not removed) listener classes
761761
for (var i in listeners) {
762-
if (listeners.get(i).toString() !== "TvdFormat" && !remainingListeners.contains(listeners.get(i).getClass())) {
763-
javaCommandRegistry.addForAllStmtsListener(listeners.get(i).getClass());
762+
try {
763+
if (listeners.get(i).toString() !== "TvdFormat" && !remainingListeners.contains(listeners.get(i).getClass())) {
764+
javaCommandRegistry.addForAllStmtsListener(listeners.get(i).getClass());
765+
}
766+
} catch (e) {
767+
// ignore, assume toString() cannot be evaluated and therefore a class that does not need to be registered.
764768
}
765769
}
766770
}

standalone/README.md

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ The parameters are the same as for the [SQLcl command `tvdformat`](../sqlcl/READ
3131

3232
A native image is a platform specific executable. It does not require a JDK at runtime. A native image uses less resources and is faster. The following images can be produced with a GraalVM JDK 17:
3333

34-
OS | amd64 (Intel)? | aarch64 (ARM)? |
35-
------- | :-------------: | :------------: |
36-
macOS | yes | yes |
37-
Linux | yes | yes |
38-
Windows | yes | - |
34+
| OS | amd64 (Intel)? | aarch64 (ARM)? |
35+
|---------|:--------------:|:--------------:|
36+
| macOS | yes | yes |
37+
| Linux | yes | yes |
38+
| Windows | yes | - |
3939

40-
Currently there is no way to produce an ARM based (aarch64) native image for Windows.
40+
Currently, there is no way to produce an ARM based (aarch64) native image for Windows.
4141

4242
Native images are not part of a release. You have to build them yourself as described [below](#how-to-build).
4343

@@ -49,67 +49,11 @@ To run a native image open a terminal window and type
4949

5050
The parameters are the same as for the [executable JAR](#executable-jar).
5151

52-
## Important: Native Images Do not Work Anymore
53-
54-
Starting with SQLcl 23.1.0 it is not possible to build native images on all platforms anymore.
55-
The reason is that the underlying parser uses AWT/Swing components (for whatever reason).
56-
AWT/Swing components are supported on AMD/Linux platforms only by GraalVM.
57-
As a result this build process will produce a non-working native image on most platforms.
58-
59-
You will see the following stacktrace similar to the following when running the resulting native image
60-
(based on SQLcl 23.3.0 on macOS 14.1.2 with an M-series chip):
61-
62-
```
63-
Exception in thread "main" javax.script.ScriptException: java.lang.Exception: java.lang.UnsatisfiedLinkError: no awt in java.library.path
64-
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryRelative(NativeLibrarySupport.java:136)
65-
at java.base@17.0.9/java.lang.ClassLoader.loadLibrary(ClassLoader.java:50)
66-
at java.base@17.0.9/java.lang.Runtime.loadLibrary0(Runtime.java:818)
67-
at java.base@17.0.9/java.lang.System.loadLibrary(System.java:1989)
68-
at java.desktop@17.0.9/java.awt.Toolkit$2.run(Toolkit.java:1388)
69-
at java.desktop@17.0.9/java.awt.Toolkit$2.run(Toolkit.java:1386)
70-
at java.base@17.0.9/java.security.AccessController.executePrivileged(AccessController.java:171)
71-
at java.base@17.0.9/java.security.AccessController.doPrivileged(AccessController.java:318)
72-
at java.desktop@17.0.9/java.awt.Toolkit.loadLibraries(Toolkit.java:1385)
73-
at java.desktop@17.0.9/java.awt.Toolkit.initStatic(Toolkit.java:1423)
74-
at java.desktop@17.0.9/java.awt.Toolkit.<clinit>(Toolkit.java:1397)
75-
at java.desktop@17.0.9/java.awt.Component.<clinit>(Component.java:624)
76-
at java.base@17.0.9/java.lang.Class.ensureInitialized(DynamicHub.java:579)
77-
at java.base@17.0.9/java.lang.Class.ensureInitialized(DynamicHub.java:579)
78-
at java.base@17.0.9/java.lang.Class.ensureInitialized(DynamicHub.java:579)
79-
at java.base@17.0.9/java.lang.Class.ensureInitialized(DynamicHub.java:579)
80-
at java.base@17.0.9/java.lang.Class.ensureInitialized(DynamicHub.java:579)
81-
at oracle.dbtools.parser.Visual.<init>(Visual.java:404)
82-
at oracle.dbtools.parser.Grammar.parseGrammarFile(Grammar.java:172)
83-
at oracle.dbtools.parser.Grammar.parseGrammarFile(Grammar.java:152)
84-
at oracle.dbtools.arbori.Program.getRules(Program.java:285)
85-
at oracle.dbtools.arbori.Program.getArboriParser(Program.java:194)
86-
at oracle.dbtools.arbori.Program.compile(Program.java:338)
87-
at oracle.dbtools.arbori.Program.compile(Program.java:327)
88-
at oracle.dbtools.arbori.SqlProgram.<init>(SqlProgram.java:32)
89-
at oracle.dbtools.app.Format$3.<init>(Format.java:343)
90-
at oracle.dbtools.app.Format.format(Format.java:343)
91-
at <js>.formatInSandbox(<eval>:168)
92-
at <js>.formatFile(<eval>:670)
93-
at <js>.formatFiles(<eval>:683)
94-
at <js>.run(<eval>:737)
95-
at <js>.:program(<eval>:803)
96-
at org.graalvm.sdk/org.graalvm.polyglot.Context.eval(Context.java:403)
97-
at org.graalvm.js.scriptengine/com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:485)
98-
at org.graalvm.js.scriptengine/com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:427)
99-
at com.trivadis.plsql.formatter.TvdFormat.run(TvdFormat.java:36)
100-
at com.trivadis.plsql.formatter.TvdFormat.main(TvdFormat.java:49)
101-
```
102-
103-
This is really sad. However, there is nothing we can do.
104-
We have to wait until the SQL Developer team decides to provide a parser that does not require AWT/Swing components (as in previous versions)
105-
or until the GraalVM team provides a native-image build process that works on all platforms with AWT/Swing.
106-
See also [macOS: no awt in java.library.path](https://github.com/oracle/graal/issues/4124).
107-
10852
## How to Build
10953

110-
1. [Download](https://www.oracle.com/tools/downloads/sqlcl-downloads.html) and install SQLcl 23.3.0
111-
2. [Download](https://github.com/graalvm/graalvm-ce-builds/releases/tag/jdk-17.0.9) and install the GraalVM JDK 17.0.9
112-
3. Go to the `bin` directory of the GraalVM JDK and run `./gu install js native-image visualvm`. For native image on Windows you need to [download](https://visualstudio.microsoft.com/downloads/) Visual Studio Community 2022 and install the C++ compiler. Use `x64 Native Tools Command Prompt for VS 2022` to get a terminal window with the correct environment.
54+
1. [Download](https://www.oracle.com/tools/downloads/sqlcl-downloads.html) and install SQLcl 23.4.0
55+
2. [Download](https://github.com/graalvm/graalvm-ce-builds/releases/tag/jdk-17.0.9) and install the GraalVM JDK 21.0.2
56+
3. For native image on Windows you need to [download](https://visualstudio.microsoft.com/downloads/) Visual Studio Community 2022 and install the C++ compiler. Use `x64 Native Tools Command Prompt for VS 2022` to get a terminal window with the correct environment.
11357
4. [Download](https://maven.apache.org/download.cgi) and install Apache Maven 3.9.6
11458
5. [Download](https://git-scm.com/downloads) and install a git command line client
11559
6. Clone the plsql-formatter-settings repository. The repository uses symbolic links. On Windows you have to use `git clone -c core.symlinks=true https://github.com/Trivadis/plsql-formatter-settings.git` as Administrator to make it work. See also [Symbolic Links in Windows](https://github.com/git-for-windows/git/wiki/Symbolic-Links) for more information.
@@ -138,14 +82,14 @@ See also [macOS: no awt in java.library.path](https://github.com/oracle/graal/is
13882
13983
You can define the following optional parameters:
14084
141-
| Parameter | Value | Meaning |
142-
| -------------------------- | ------- | ------- |
143-
| `skip.native` | `true` | Do not produce a native image (default) |
144-
| | `false` | Produce a native image |
145-
| `skipTests` | `true` | Run tests (default) |
146-
| | `false` | Do not run tests |
85+
| Parameter | Value | Meaning |
86+
| -------------------------- | ------- |---------------------------------------------------|
87+
| `skip.native` | `true` | Do not produce a native image (default) |
88+
| | `false` | Produce a native image |
89+
| `skipTests` | `true` | Do not run tests |
90+
| | `false` | Run tests (default) |
14791
| `disable.logging` | `true` | Disable logging message during test run (default) |
148-
| | `false` | Enable logging message during test run |
92+
| | `false` | Enable logging message during test run |
14993
15094
Here's a fully qualified example to produce a native image and run all integration tests:
15195

standalone/install_sqlcl_libs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if ! test -f "${SQLCL_LIBDIR}/dbtools-common.jar"; then
1515
fi
1616

1717
# define common Maven properties
18-
SQLCL_VERSION="23.3.0"
18+
SQLCL_VERSION="23.4.0"
1919

2020
# install JAR files in local Maven repository, these libs are not available in public Maven repositories
2121
mvn install:install-file -Dfile=$SQLCL_LIBDIR/dbtools-common.jar -DgeneratePom=true \

0 commit comments

Comments
 (0)