Skip to content

Commit 3967480

Browse files
authored
#54: Agent to change retention of @JavaScriptBody and @JavaScriptResource
2 parents cbb68d5 + 8a0b704 commit 3967480

35 files changed

Lines changed: 942 additions & 158 deletions

File tree

.github/workflows/mac.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
strategy:
3333
matrix:
3434
java: [ '8', '11', '17', '21' ]
35-
os: [ macos-10.15 ]
35+
os: [ macos-13 ]
3636

3737
steps:
3838
- uses: actions/checkout@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/target/
33
*.orig
44
*/nb-configuration.xml
5+
*/dependency-reduced-pom.xml
56
*/nbactions.xml
67
/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle*/build/*
78
/html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle*/.gradle/*

boot-agent-test/pom.xml

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</parent>
2929
<artifactId>boot-agent-test</artifactId>
3030
<packaging>jar</packaging>
31-
<name>Dynamic Boot Test</name>
31+
<name>Agent Boot Test</name>
3232
<properties>
3333
<skipTests>${skipJavaFXTests}</skipTests>
3434
</properties>
@@ -48,6 +48,23 @@
4848
<skip>true</skip>
4949
</configuration>
5050
</plugin>
51+
<plugin>
52+
<artifactId>maven-dependency-plugin</artifactId>
53+
<executions>
54+
<execution>
55+
<goals>
56+
<goal>properties</goal>
57+
</goals>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
<plugin>
62+
<artifactId>maven-surefire-plugin</artifactId>
63+
<version>3.2.5</version>
64+
<configuration>
65+
<argLine>-javaagent:${org.netbeans.html:net.java.html.boot:jar}</argLine>
66+
</configuration>
67+
</plugin>
5168
</plugins>
5269
</build>
5370
<dependencies>
@@ -70,27 +87,19 @@
7087
<scope>test</scope>
7188
<type>jar</type>
7289
</dependency>
73-
<dependency>
74-
<groupId>org.netbeans.api</groupId>
75-
<artifactId>org-openide-util-lookup</artifactId>
76-
<scope>test</scope>
77-
<type>jar</type>
78-
</dependency>
7990
<dependency>
8091
<groupId>${project.groupId}</groupId>
81-
<artifactId>net.java.html.boot.fx</artifactId>
92+
<artifactId>net.java.html.boot.script</artifactId>
8293
<version>${project.version}</version>
8394
<scope>test</scope>
8495
</dependency>
8596
<dependency>
86-
<groupId>org.openjfx</groupId>
87-
<artifactId>javafx-web</artifactId>
88-
<scope>test</scope>
97+
<groupId>org.graalvm.js</groupId>
98+
<artifactId>js</artifactId>
8999
</dependency>
90100
<dependency>
91-
<groupId>org.ow2.asm</groupId>
92-
<artifactId>asm</artifactId>
93-
<scope>test</scope>
101+
<groupId>org.graalvm.js</groupId>
102+
<artifactId>js-scriptengine</artifactId>
94103
</dependency>
95104
</dependencies>
96105
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.html.bootagent;
20+
21+
import java.lang.reflect.Method;
22+
import java.lang.reflect.Modifier;
23+
import java.util.ArrayList;
24+
import net.java.html.boot.script.Scripts;
25+
import static org.testng.AssertJUnit.assertNotNull;
26+
import org.testng.annotations.Factory;
27+
28+
/**
29+
*
30+
* @author Jaroslav Tulach
31+
*/
32+
public class AgentBootstrapTest {
33+
public AgentBootstrapTest() {
34+
}
35+
36+
@Factory
37+
public static Object[] compatibilityTests() throws Exception {
38+
var presenter = Scripts.newPresenter().build();
39+
assertNotNull("Presenter has been initialized", presenter);
40+
41+
var res = new ArrayList<Object>();
42+
43+
Class[] arr = new Class[] { JavaScriptBodyTst.class };
44+
for (Class c : arr) {
45+
for (Method m : c.getDeclaredMethods()) {
46+
if ((m.getModifiers() & Modifier.PUBLIC) != 0) {
47+
res.add(new KOFx(presenter, m));
48+
}
49+
}
50+
}
51+
return res.toArray();
52+
}
53+
}

boot-agent-test/src/test/java/org/netbeans/html/bootagent/JavaScriptBodyTst.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
*/
1919
package org.netbeans.html.bootagent;
2020

21+
import java.util.Arrays;
2122
import net.java.html.js.JavaScriptBody;
23+
import net.java.html.js.JavaScriptResource;
2224

2325
/**
2426
*
2527
* @author Jaroslav Tulach
2628
*/
29+
@JavaScriptResource("empty.js")
2730
public class JavaScriptBodyTst {
2831

2932
public JavaScriptBodyTst() {
@@ -33,7 +36,56 @@ public void assert42() {
3336
int v = mul(7, 6);
3437
assert v == 42 : "Really 42: " + v;
3538
}
39+
40+
public void assertEmptySymbolDefined() {
41+
assert Boolean.TRUE.equals(eval("empty")) : "empty.js should defined empty global symbol";
42+
}
43+
public void assertEmpty2SymbolDefined() {
44+
MultiResource.loadIt();
45+
assert Boolean.TRUE.equals(eval("empty2")) : "empty.js should defined empty global symbol";
46+
}
47+
public void assertEmpty3SymbolDefined() {
48+
MultiResource.loadIt();
49+
assert Boolean.TRUE.equals(eval("empty3")) : "empty.js should defined empty global symbol";
50+
}
51+
52+
public void assertJavaScriptBodyAnnotationPresentInRuntime() throws Exception {
53+
var mul = JavaScriptBodyTst.class.getDeclaredMethod("mul", int.class, int.class);
54+
var ann = mul.getAnnotation(JavaScriptBody.class);
55+
assert ann != null : "JavaScriptBody annotation must be found in runtime";
56+
assert ann.args().length == 2 : "Two arguments";
57+
assert "x".equals(ann.args()[0]) : "First argument: " + Arrays.toString(ann.args());
58+
assert "y".equals(ann.args()[1]) : "Second argument: " + Arrays.toString(ann.args());
59+
assert "return x * y;".equals(ann.body()) : "Body argument: " + ann.body();
60+
}
61+
62+
private static void assertResource(JavaScriptResource ann, String file) {
63+
assert ann != null : "JavaScriptResource annotation must be found in runtime";
64+
assert file.equals(ann.value()) : "Expecting " + file + " but got " + ann.value();
65+
}
3666

67+
public void assertJavaScriptResourceAnnotationPresentInRuntime() throws Exception {
68+
var ann = JavaScriptBodyTst.class.getAnnotation(JavaScriptResource.class);
69+
assertResource(ann, "empty.js");
70+
}
71+
72+
public void assertJavaScriptResourceGroupAnnotationPresentInRuntime() throws Exception {
73+
var ann = MultiResource.class.getAnnotation(JavaScriptResource.Group.class);
74+
assert ann != null : "JavaScriptResource.Group annotation must be found in runtime";
75+
assert ann.value().length == 2 : "Two empty*.js resources, was: " + Arrays.toString(ann.value());
76+
}
77+
3778
@JavaScriptBody(args = { "x", "y" }, body = "return x * y;")
3879
private static native int mul(int x, int y);
80+
81+
@JavaScriptBody(args = { "code" }, body = "return eval(code);")
82+
private static native Object eval(String code);
83+
84+
@JavaScriptResource("empty_2.js")
85+
@JavaScriptResource("empty_3.js")
86+
static final class MultiResource {
87+
@JavaScriptBody(args = {}, body = "")
88+
static void loadIt() {
89+
}
90+
}
3991
}

boot-agent-test/src/test/java/org/netbeans/html/bootagent/KOFx.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.lang.reflect.InvocationTargetException;
2222
import java.lang.reflect.Method;
23-
import javafx.application.Platform;
2423
import org.netbeans.html.boot.spi.Fn;
2524
import org.testng.IHookCallBack;
2625
import org.testng.IHookable;
@@ -51,8 +50,7 @@ public String getTestName() {
5150
@Test
5251
public synchronized void executeTest() throws Exception {
5352
if (result == null) {
54-
Platform.runLater(this);
55-
wait();
53+
run();
5654
}
5755
if (result instanceof Exception) {
5856
throw (Exception)result;
@@ -77,7 +75,7 @@ public synchronized void run() {
7775
Throwable r = ex.getTargetException();
7876
if (r instanceof InterruptedException) {
7977
notify = false;
80-
Platform.runLater(this);
78+
run();
8179
return;
8280
}
8381
result = r;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
20+
*/
21+
this.empty = true;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
20+
*/
21+
this.empty2 = true;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
20+
*/
21+
this.empty3 = true;

boot-fx/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
<artifactId>net.java.html.boot</artifactId>
6767
<version>${project.version}</version>
6868
<type>jar</type>
69+
<exclusions>
70+
<exclusion>
71+
<groupId>org.ow2.asm</groupId>
72+
<artifactId>asm</artifactId>
73+
</exclusion>
74+
</exclusions>
6975
</dependency>
7076
<dependency>
7177
<groupId>org.testng</groupId>

0 commit comments

Comments
 (0)