Skip to content

Commit 6861932

Browse files
authored
Merge pull request #1284 from OpenAF/t8
Add Launcher class and update build scripts for Java 21 compatibility
2 parents cac0ff7 + 5c5edb5 commit 6861932

File tree

7 files changed

+110
-5
lines changed

7 files changed

+110
-5
lines changed

build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- Build OpenAFOS
1919
exec : |
2020
log("Repacking...");
21-
$sh(ow.format.getJavaHome() + "/bin/java -jar " + global.path + "/openaf.jar --repack").exec()
21+
$sh().envs({ __OAF_MAINCLASS: "openaf.Launcher" }, true).sh([ow.format.getJavaHome() + "/bin/java", "-jar", global.path + "/openaf.jar", "--repack"]).exec()
2222
2323
var isOk = false, init = now()
2424
do {

buildos.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ log(af.sh(cmd, "", undefined, true));
156156
if (__exitcode != 0) {
157157
logErr("Error compiling: " + __stderr);
158158
}
159+
$sh(JAVAC + " -source 8 -target 8 -d " + OPENAF_BIN + " " + OPENAF_SRC + "/openaf/Launcher.java").exec();
159160

160161
var tempJar = new ZIP(io.readFileBytes(OPENAF_BUILD_HOME + "/jar-in-jar-loader.zip"));
161162
var binFiles = listFiles(OPENAF_BIN, new RegExp("\.class$"));
@@ -360,7 +361,8 @@ log("Adding manifest");
360361
var manifest = "Manifest-Version: 1.0\n";
361362
manifest += "Rsrc-Class-Path: ./" + smallClassPath + "\n";
362363
manifest += "Class-Path: .\n";
363-
manifest += "Rsrc-Main-Class: openaf._AFCmdOS\n";
364+
//manifest += "Rsrc-Main-Class: openaf._AFCmdOS\n";
365+
manifest += "Rsrc-Main-Class: openaf.Launcher\n";
364366
manifest += "Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader\n";
365367
tempJar.putFile("META-INF/MANIFEST.MF", af.fromString2Bytes(manifest));
366368
tempJar.putFile("META-INF/services/javax.script.ScriptEngineFactory", af.fromString2Bytes("openaf.OAFEngineFactory"));

js/repack.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ __logFormat.async = false
99

1010
var createTmp = false;
1111

12-
//Check if a Jar was repacked
12+
//Check if a Jar was repacked and if main class is no longer openaf.Launcher
1313
function isRepackJar(aJarFilePath) {
1414
var res = true;
1515

@@ -87,6 +87,17 @@ var includeMore = {};
8787
var mainClass = undefined;
8888

8989
var irj = isRepackJar(classPath);
90+
log("Checking OpenAF launcher...")
91+
if (irj && isUnDef(getEnv("__OAF_MAINCLASS"))) {
92+
var _zip = new ZIP()
93+
var str = af.fromBytes2String(_zip.streamGetFile(classPath, "META-INF/MANIFEST.MF"))
94+
if (str.match(/Main-Class: openaf.Launcher/)) {
95+
var _newClass = (isDef(mainClass)) ? mainClass : "openaf.AFCmdOS"
96+
log("Replacing main class with " + _newClass + "...")
97+
str = str.replace(/Main-Class: openaf.Launcher/g, "Main-Class: " + _newClass)
98+
_zip.streamPutFile(classPath, "META-INF/MANIFEST.MF", af.fromString2Bytes(str))
99+
}
100+
}
90101

91102
try {
92103
// Set .package.json

src/openaf/Launcher.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package openaf;
2+
3+
/**
4+
*
5+
 * Copyright 2025 Nuno Aguiar
6+
*
7+
*/
8+
9+
public class Launcher {
10+
public static void main(String[] args) {
11+
// Java version check
12+
String version = System.getProperty("java.version");
13+
14+
// If lower than 21 print warning and end
15+
if (isJavaVersionBelow21(version)) {
16+
System.err.println("Warning: You are using java " + version + ". Please use or upgrade to Java >= 21.");
17+
System.exit(1);
18+
}
19+
20+
// Proceed with the normal execution
21+
try {
22+
Class<?> cls = Class.forName("openaf._AFCmdOS");
23+
cls.getMethod("main", String[].class).invoke(null, (Object) args);
24+
} catch (Exception e) {
25+
e.printStackTrace();
26+
}
27+
}
28+
29+
public static boolean isJavaVersionBelow21(String version) {
30+
String[] parts = version.split("\\.");
31+
int major = Integer.parseInt(parts[0]);
32+
return major < 21;
33+
}
34+
}

src/openaf/OAFRepack.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ public static void repack(String aOrigFile, String aDestFile, String mainClass)
9898

9999
ZipInputStream zis = null;
100100
FileInputStream fis = null;
101+
102+
// If environment variable __OAF_MAINCLASS exists then replace mainClass with it
103+
// NOTE: this should only be used for original packing proposes with openaf.Launcer
104+
String envMainClass = System.getenv("__OAF_MAINCLASS");
105+
if (envMainClass != null) {
106+
System.out.println("Previous main class: " + mainClass);
107+
System.out.println("New main class: " + envMainClass);
108+
mainClass = envMainClass;
109+
}
110+
101111
try {
102112
fis = new FileInputStream(aOrigFile);
103113
if (fis == null) throw new Exception("Couldn't read input file " + aOrigFile);

tests/oJobTypesTest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Via inline job
4343
args: |
4444
({ verb: ow.oJob.init.hello })
45-
exec: &EXE |
45+
exec: &EXE | # javascript
4646
//yprint(args);
4747
if (isDef(args.verb) && args.verb == 'world') print("arg : yes"); else print("arg : NO!!!");
4848
if (isDef(args.init)) print("init: yes"); else print("init: NO!!!");

tests/testOJobShort.yaml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ jobs:
44
from:
55
# Running function getVersion
66
- (fn): getVersion
7-
exec: |
7+
# Using YAML Embedded Language in VSCode
8+
exec: | # javascript
89
// Setting comparing values
910
args.a = $get("res")
1011
args.b = getVersion()
@@ -55,6 +56,51 @@ jobs:
5556
# Cleanup
5657
- (unset ): res
5758

59+
# --------------------
60+
- name: Test SQL query
61+
from:
62+
- (pass ):
63+
data:
64+
- id : 1
65+
name: Id 1
66+
- id : 2
67+
name: Id 2
68+
- (set ): data
69+
((path )): data
70+
- (query ): | #sql
71+
select count(1) as "count"
72+
((key )): data
73+
((type )): sql
74+
((toKey)): res
75+
to :
76+
- (pass ):
77+
a: "{{$path ($get 'res') '[0].count'}}"
78+
b: "2"
79+
- (testAssert): Problem with query
80+
81+
# ---------------
82+
- name: Test oAFp
83+
from:
84+
- (pass ):
85+
data:
86+
- id : 1
87+
name: Id 1
88+
- id : 2
89+
name: Id 2
90+
- (set ): data
91+
((path )): data
92+
- (oafp ):
93+
in : key
94+
data : data
95+
path : "[0]"
96+
out : key
97+
__key : res
98+
to :
99+
- (pass ):
100+
a: "{{$path ($get 'res') 'id'}}"
101+
b: "1"
102+
- (testAssert): Problem with oAFp
103+
58104
# ----------------------
59105
- name: Test todo simple
60106
from:
@@ -89,4 +135,6 @@ todo:
89135
- Test fn bi-directional
90136
- Test ch simple
91137
- Test todo simple
138+
- Test SQL query
139+
- Test oAFp
92140
- oJob Jobs Final Report

0 commit comments

Comments
 (0)