diff --git a/.github/workflows/mac.yml b/.github/workflows/mac.yml index 4d78c4359..a70fd01c6 100644 --- a/.github/workflows/mac.yml +++ b/.github/workflows/mac.yml @@ -32,7 +32,7 @@ jobs: strategy: matrix: java: [ '8', '11', '17', '21' ] - os: [ macos-10.15 ] + os: [ macos-13 ] steps: - uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index 897174462..57bb5cea0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /target/ *.orig */nb-configuration.xml +*/dependency-reduced-pom.xml */nbactions.xml /html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle*/build/* /html4j-maven-plugin/src/test/resources/org/netbeans/html/mojo/gradle*/.gradle/* diff --git a/boot-agent-test/pom.xml b/boot-agent-test/pom.xml index 54c4e4a4a..188742a37 100644 --- a/boot-agent-test/pom.xml +++ b/boot-agent-test/pom.xml @@ -28,7 +28,7 @@ boot-agent-test jar - Dynamic Boot Test + Agent Boot Test ${skipJavaFXTests} @@ -48,6 +48,23 @@ true + + maven-dependency-plugin + + + + properties + + + + + + maven-surefire-plugin + 3.2.5 + + -javaagent:${org.netbeans.html:net.java.html.boot:jar} + + @@ -70,27 +87,19 @@ test jar - - org.netbeans.api - org-openide-util-lookup - test - jar - ${project.groupId} - net.java.html.boot.fx + net.java.html.boot.script ${project.version} test - org.openjfx - javafx-web - test + org.graalvm.js + js - org.ow2.asm - asm - test + org.graalvm.js + js-scriptengine \ No newline at end of file diff --git a/boot-agent-test/src/test/java/org/netbeans/html/bootagent/AgentBootstrapTest.java b/boot-agent-test/src/test/java/org/netbeans/html/bootagent/AgentBootstrapTest.java new file mode 100644 index 000000000..7854566d5 --- /dev/null +++ b/boot-agent-test/src/test/java/org/netbeans/html/bootagent/AgentBootstrapTest.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.html.bootagent; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import net.java.html.boot.script.Scripts; +import static org.testng.AssertJUnit.assertNotNull; +import org.testng.annotations.Factory; + +/** + * + * @author Jaroslav Tulach + */ +public class AgentBootstrapTest { + public AgentBootstrapTest() { + } + + @Factory + public static Object[] compatibilityTests() throws Exception { + var presenter = Scripts.newPresenter().build(); + assertNotNull("Presenter has been initialized", presenter); + + var res = new ArrayList(); + + Class[] arr = new Class[] { JavaScriptBodyTst.class }; + for (Class c : arr) { + for (Method m : c.getDeclaredMethods()) { + if ((m.getModifiers() & Modifier.PUBLIC) != 0) { + res.add(new KOFx(presenter, m)); + } + } + } + return res.toArray(); + } +} diff --git a/boot-agent-test/src/test/java/org/netbeans/html/bootagent/JavaScriptBodyTst.java b/boot-agent-test/src/test/java/org/netbeans/html/bootagent/JavaScriptBodyTst.java index 0c4c8df31..1d5ebbe94 100644 --- a/boot-agent-test/src/test/java/org/netbeans/html/bootagent/JavaScriptBodyTst.java +++ b/boot-agent-test/src/test/java/org/netbeans/html/bootagent/JavaScriptBodyTst.java @@ -18,12 +18,15 @@ */ package org.netbeans.html.bootagent; +import java.util.Arrays; import net.java.html.js.JavaScriptBody; +import net.java.html.js.JavaScriptResource; /** * * @author Jaroslav Tulach */ +@JavaScriptResource("empty.js") public class JavaScriptBodyTst { public JavaScriptBodyTst() { @@ -33,7 +36,56 @@ public void assert42() { int v = mul(7, 6); assert v == 42 : "Really 42: " + v; } + + public void assertEmptySymbolDefined() { + assert Boolean.TRUE.equals(eval("empty")) : "empty.js should defined empty global symbol"; + } + public void assertEmpty2SymbolDefined() { + MultiResource.loadIt(); + assert Boolean.TRUE.equals(eval("empty2")) : "empty.js should defined empty global symbol"; + } + public void assertEmpty3SymbolDefined() { + MultiResource.loadIt(); + assert Boolean.TRUE.equals(eval("empty3")) : "empty.js should defined empty global symbol"; + } + + public void assertJavaScriptBodyAnnotationPresentInRuntime() throws Exception { + var mul = JavaScriptBodyTst.class.getDeclaredMethod("mul", int.class, int.class); + var ann = mul.getAnnotation(JavaScriptBody.class); + assert ann != null : "JavaScriptBody annotation must be found in runtime"; + assert ann.args().length == 2 : "Two arguments"; + assert "x".equals(ann.args()[0]) : "First argument: " + Arrays.toString(ann.args()); + assert "y".equals(ann.args()[1]) : "Second argument: " + Arrays.toString(ann.args()); + assert "return x * y;".equals(ann.body()) : "Body argument: " + ann.body(); + } + + private static void assertResource(JavaScriptResource ann, String file) { + assert ann != null : "JavaScriptResource annotation must be found in runtime"; + assert file.equals(ann.value()) : "Expecting " + file + " but got " + ann.value(); + } + public void assertJavaScriptResourceAnnotationPresentInRuntime() throws Exception { + var ann = JavaScriptBodyTst.class.getAnnotation(JavaScriptResource.class); + assertResource(ann, "empty.js"); + } + + public void assertJavaScriptResourceGroupAnnotationPresentInRuntime() throws Exception { + var ann = MultiResource.class.getAnnotation(JavaScriptResource.Group.class); + assert ann != null : "JavaScriptResource.Group annotation must be found in runtime"; + assert ann.value().length == 2 : "Two empty*.js resources, was: " + Arrays.toString(ann.value()); + } + @JavaScriptBody(args = { "x", "y" }, body = "return x * y;") private static native int mul(int x, int y); + + @JavaScriptBody(args = { "code" }, body = "return eval(code);") + private static native Object eval(String code); + + @JavaScriptResource("empty_2.js") + @JavaScriptResource("empty_3.js") + static final class MultiResource { + @JavaScriptBody(args = {}, body = "") + static void loadIt() { + } + } } diff --git a/boot-agent-test/src/test/java/org/netbeans/html/bootagent/KOFx.java b/boot-agent-test/src/test/java/org/netbeans/html/bootagent/KOFx.java index e65b880fe..60bc3f556 100644 --- a/boot-agent-test/src/test/java/org/netbeans/html/bootagent/KOFx.java +++ b/boot-agent-test/src/test/java/org/netbeans/html/bootagent/KOFx.java @@ -20,7 +20,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import javafx.application.Platform; import org.netbeans.html.boot.spi.Fn; import org.testng.IHookCallBack; import org.testng.IHookable; @@ -51,8 +50,7 @@ public String getTestName() { @Test public synchronized void executeTest() throws Exception { if (result == null) { - Platform.runLater(this); - wait(); + run(); } if (result instanceof Exception) { throw (Exception)result; @@ -77,7 +75,7 @@ public synchronized void run() { Throwable r = ex.getTargetException(); if (r instanceof InterruptedException) { notify = false; - Platform.runLater(this); + run(); return; } result = r; diff --git a/boot-agent-test/src/test/resources/org/netbeans/html/bootagent/empty.js b/boot-agent-test/src/test/resources/org/netbeans/html/bootagent/empty.js new file mode 100644 index 000000000..b4525b4f4 --- /dev/null +++ b/boot-agent-test/src/test/resources/org/netbeans/html/bootagent/empty.js @@ -0,0 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +*/ +this.empty = true; diff --git a/boot-agent-test/src/test/resources/org/netbeans/html/bootagent/empty_2.js b/boot-agent-test/src/test/resources/org/netbeans/html/bootagent/empty_2.js new file mode 100644 index 000000000..ceb668f10 --- /dev/null +++ b/boot-agent-test/src/test/resources/org/netbeans/html/bootagent/empty_2.js @@ -0,0 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +*/ +this.empty2 = true; diff --git a/boot-agent-test/src/test/resources/org/netbeans/html/bootagent/empty_3.js b/boot-agent-test/src/test/resources/org/netbeans/html/bootagent/empty_3.js new file mode 100644 index 000000000..ddecd53bf --- /dev/null +++ b/boot-agent-test/src/test/resources/org/netbeans/html/bootagent/empty_3.js @@ -0,0 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +*/ +this.empty3 = true; diff --git a/boot-fx/pom.xml b/boot-fx/pom.xml index 25e510f74..2a5379d52 100644 --- a/boot-fx/pom.xml +++ b/boot-fx/pom.xml @@ -66,6 +66,12 @@ net.java.html.boot ${project.version} jar + + + org.ow2.asm + asm + + org.testng diff --git a/boot-script/pom.xml b/boot-script/pom.xml index 692225b20..a630aa73c 100644 --- a/boot-script/pom.xml +++ b/boot-script/pom.xml @@ -72,6 +72,12 @@ net.java.html.boot ${project.version} jar + + + org.ow2.asm + asm + + org.testng diff --git a/boot/pom.xml b/boot/pom.xml index 19968a5b1..6ef377570 100644 --- a/boot/pom.xml +++ b/boot/pom.xml @@ -50,6 +50,34 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + + true + + + + org.apache.maven.plugins + maven-shade-plugin + 3.6.0 + + + package + + shade + + + + + org.objectweb.asm + org.netbeans.html.boot.asm5 + + + + + + @@ -57,8 +85,6 @@ org.ow2.asm asm jar - provided - true org.testng diff --git a/boot/src/main/java/net/java/html/boot/BrowserBuilder.java b/boot/src/main/java/net/java/html/boot/BrowserBuilder.java index c732dc22e..9636398da 100644 --- a/boot/src/main/java/net/java/html/boot/BrowserBuilder.java +++ b/boot/src/main/java/net/java/html/boot/BrowserBuilder.java @@ -103,9 +103,9 @@ private BrowserBuilder(Object[] context) { * {@link Contexts#newBuilder(java.lang.Object...) created} * and can influence the selection * of available technologies - * (like {@link org.netbeans.html.json.spi.Technology}, - * {@link org.netbeans.html.json.spi.Transfer} or - * {@link org.netbeans.html.json.spi.WSTransfer}) by name. + * (like {@code org.netbeans.html.json.spi.Technology}, + * {@code org.netbeans.html.json.spi.Transfer} or + * {@code org.netbeans.html.json.spi.WSTransfer}) by name. * * @param context any instances that should be available to the builder - * implementation dependant diff --git a/boot/src/main/java/net/java/html/js/package.html b/boot/src/main/java/net/java/html/js/package.html index 4523d234a..848059384 100644 --- a/boot/src/main/java/net/java/html/js/package.html +++ b/boot/src/main/java/net/java/html/js/package.html @@ -25,10 +25,10 @@ Mix your Java and JavaScript code seamlessly - perform calls from Java to JavaScript and back with as much freedom as JavaScript gives you and as much type safety you can get from Java. Execute your code - in a headless testing environment or in a - JavaFX WebView. + in a headless testing environment or in a + JavaFX WebView. When done, deploy to real browsers. - +

Simple Meaning of World

The whole support is build around @JavaScriptBody annotation. Use it to create parametrised JavaScript snippet easily @@ -42,7 +42,7 @@

Simple Meaning of World

The meaning method now becomes a properly typed Java surface to your JavaScript code which can be directly called from the rest of your Java code: -
        
+
 public static void main(String... args) {
   assert 42 == meaning(40, 2) : "Meaning of World should be 42!";
 }
@@ -53,24 +53,24 @@ 

Simple Meaning of World

Bodies.

Editing hint: one can see the list of arguments of the - meaning is now duplicated - it is once specified in Java, - and once inside of the {@link net.java.html.js.JavaScriptBody} - array of args. This is necessary to keep the names of + meaning is now duplicated - it is once specified in Java, + and once inside of the {@link net.java.html.js.JavaScriptBody} + array of args. This is necessary to keep the names of arguments accessible during runtime. However don't despair - there is a code completion for the value of args attribute! Just type the Java signature first and then press Ctrl+Space and the right parameter names will be inserted for you. - +

Including JavaScript Libraries

Large amount of JavaScript code is easier to be delivered in whole files rather than {@link net.java.html.js.JavaScriptBody small code snippets} - that is also possible thanks to {@link net.java.html.js.JavaScriptResource} annotation. Imagine file mul.js with following content: -
 
+
 function mul(x, y) { return x * y; }
 
- Place the file next to your class and reference it with + Place the file next to your class and reference it with {@link net.java.html.js.JavaScriptResource the annotation}:
 {@code @}{@link net.java.html.js.JavaScriptResource}("mul.js") class Mul {
@@ -90,38 +90,38 @@ 

Simple Meaning of World

Real code tip: this - is the way + is the way the knockout.js library is included in its ko4j library. - +

Callback to Java

- + Often JavaScript code needs to call back into the Java classes. For example when a button in a browser is pressed and your code would like to invoke a runnable to handle such situation: -
 
-{@code @}{@link net.java.html.js.JavaScriptBody}(args = {"id", "r"}, {@link net.java.html.js.JavaScriptBody#javacall() javacall} = true, body = "\n" + 
-"       document.getElementById(id).onclick = function() {\n" + 
-"        r.{@code @}java.lang.Runnable::run()();\n" + 
-"       };\n" + 
+
+{@code @}{@link net.java.html.js.JavaScriptBody}(args = {"id", "r"}, {@link net.java.html.js.JavaScriptBody#javacall() javacall} = true, body = "\n" +
+"       document.getElementById(id).onclick = function() {\n" +
+"        r.{@code @}java.lang.Runnable::run()();\n" +
+"       };\n" +
 "    ")
 public static native void onClick(String id, Runnable r);
 
- As can be seen, there is a special syntax (starting with @) to + As can be seen, there is a special syntax (starting with @) to properly identify the right Java method to call on a Java object passed into the JavaScript interpreter. The syntax starts with a fully - qualified name of the class, followed by :: and name of the + qualified name of the class, followed by :: and name of the method including signature of its parameters. In case of runnable, this is just () as the method has no parameters, but the signature can be more complicated. For example in case of following method
static int compare(int i1, String s1, int i2, String s2)
-
+
it would be (ILjava/lang/String;ILjava/lang/String;) (btw. the - return type is not included in the signature). The actual parameters + return type is not included in the signature). The actual parameters then follows. The JavaScript call to such compare method would then look like:
{@code @}the.pkg.Clazz::compare(ILjava/lang/String;ILjava/lang/String;)(1, 'One', 2, 'Two');
-
+
This syntax gives enough flexibility, helps to properly select one of overloaded methods and follows the tradition of previous attempts to provide JavaScript to Java calling conventions. @@ -133,15 +133,15 @@

Callback to Java

[instance.]@classname::methodname(signature)(arguments)
    -
  • instance - must be present when calling an - instance method and must be absent when calling a +
  • instance - must be present when calling an + instance method and must be absent when calling a static method
  • -
  • classname - fully qualified name of the class in - which the method is declared +
  • classname - fully qualified name of the class in + which the method is declared
  • -
  • signature - internal JVM method signature - (as specified at - JNI type Signatures) +
  • signature - internal JVM method signature + (as specified at + JNI type Signatures) without the trailing signature of the method return type
  • arguments - the actual values to pass to the called Java method
  • @@ -149,9 +149,9 @@

    Callback to Java

    Here is the JNI type signatures table one can use to convert - Java parameters to JVM's internal letter based + Java parameters to JVM's internal letter based representation:

    - + @@ -201,19 +201,19 @@

    Callback to Java

    Type Signature

    Editing hint: The callback syntax may seem complicated at - first, however there is an associated annotation processor + first, however there is an associated annotation processor that checks the syntax and verifies the referenced class and method with the requested signature exist. If it does not, the - compilation fails offering correct alternatives. + compilation fails offering correct alternatives. Thus don't despair seeing the syntax, make sure you get the - fully qualified name of the callback class right. - You'll get warning and help + fully qualified name of the callback class right. + You'll get warning and help if there is a typo in the specified signature then - during compilation of your code. - +

    Overloaded Methods

    - - Specifying the actual callback signature is important in case of + + Specifying the actual callback signature is important in case of overloaded methods. Imagine a class:
     package x.y.z;
    @@ -227,8 +227,8 @@ 

    Overloaded Methods

    int pulse(long evenMore) { return (int) (5 + evenMore); } -}
    - you then need to choose in {@link net.java.html.js.JavaScriptBody} +}
+ you then need to choose in {@link net.java.html.js.JavaScriptBody} the appropriate method to call:
 {@code @}{@link net.java.html.js.JavaScriptBody}(args = { "h" }, javacall = true, // you want to process the @ syntax
@@ -242,17 +242,17 @@ 

Overloaded Methods

}

- To avoid ambiguity, the specification of the correct signature is + To avoid ambiguity, the specification of the correct signature is required on every call. However, to simplify the development, there is an annotation processor to verify the signature really refers to an existing method.

- +

Arrays by Copy

- + It is possible to exchange arrays between Java and JavaScript. Some implementations can pass arrays by reference, however in some systems - this is hard to achieve. To choose the least common denominator, + this is hard to achieve. To choose the least common denominator, the TCK for behavior of {@link net.java.html.js.JavaScriptBody} requires the arrays to be always transfered by a copy. As such following code:
@@ -262,33 +262,33 @@ 

Arrays by Copy

String[] hello = { "Hello", "World!" }; uselessModify(arr); System.out.println(arr[0] + " " + arr[1]); -} +}
will still print Hello World! in spite the JavaScript code sets the 0-th array element to null. Because the array is passed as a copy, such assignment has no effect on the Java array.

- In case one needs to modify an array in a JavaScript and use its + In case one needs to modify an array in a JavaScript and use its values in Java, one has to return the array back as a return value: -
        
+        
 {@code @}{@link net.java.html.js.JavaScriptBody}(args = {"arr"}, body = "arr[0] = 'Ahoy'; return arr;")
 private static native Object[] usefulModify(String[] arr);
 public static void main(String... args) {
   String[] hello = { "Hello", "World!" };
   Object[] ret = usefulModify(arr);
   System.out.println(ret[0] + " " + ret[1]);
-}            
+}
 
now the program prints Ahoy World! as the modified array is returned back and converted (by a copy) into a Java Object[] (but of course the ret != hello). Usually the copy based - passing of arrays works OK. It is however good to keep it in mind to + passing of arrays works OK. It is however good to keep it in mind to avoid unwanted surprises. - +

Instance Reference to JavaScript Object

- + When writing wrappers around existing JavaScript libraries, it may be - useful to hold a reference to some JavaScript object from a Java + useful to hold a reference to some JavaScript object from a Java instance and use it later.
 class WrapperAroundJsObj {
@@ -309,12 +309,12 @@ 

Instance Reference to JavaScript Object

args = { "js", "v" }, body = "js.value = v;", wait4js = false ) private static native void setValue(Object js, int v); -} -
- The type of the Java reference is {@link java.lang.Object}. +} +
+ The type of the Java reference is {@link java.lang.Object}. From a Java perspective it has no additional methods or fields, however its properties can be manipulated from JavaScript. Send the object back - to JavaScript by passing it as a parameter of some method + to JavaScript by passing it as a parameter of some method (like the setValue one) and perform necessary JavaScript calls or changes on it. @@ -340,22 +340,26 @@

undefined === null

}
This is the behavior since version 1.4. - +

Post Process Classes

Classes with {@link net.java.html.js.JavaScriptBody} annotated methods need to be post processed before they can be used - e.g. their native - body needs to be generated to call into JavaScript (btw. the code is performed + body needs to be generated to call into JavaScript (btw. the call is performed via {@link org.netbeans.html.boot.spi.Fn}). There are three ways - such post processing can happen. + such a post processing can be achieved.

- Compile time processing - this is the preferred method that - most of the Html Java APIs are using. + +

Compile time

+ + + The Compile time is the preferred method of post-processing that + most of the Html Java APIs are using. Just include following plugin configuration into your pom.xml and your classes will be ready for execution as soon as process-classes Maven phase is over: -
 
+
 <plugin>
     <groupId>org.netbeans.html</groupId>
     <artifactId>html4j-maven-plugin</artifactId>
@@ -370,33 +374,49 @@ 

Post Process Classes

</executions> </plugin>
- This plugin works in orchestration with + This plugin works in orchestration with annotation processor associated with {@link net.java.html.js.JavaScriptBody} and {@link net.java.html.js.JavaScriptResource} - the processor creates - list of files that need post-processing. The + list of files that need post-processing. The Maven - plugin reads these files, processes classes mentioned in them and + plugin reads these files, processes classes mentioned in them and modifies (and deletes at the end) the files to not include classes already processed.

- Instrumentation Agent - one can do processing in runtime + +

Instrumentation Agent

+ + + Instrumentation Agent can perform the post processing in runtime using JDK's {@link java.lang.instrument.ClassFileTransformer instrumentation} - abilities. The JAR artifact of org.netbeans.html:net.java.html.boot - contains an Agent-Class and Premain-Class - definitions in its manifest. As such one can launch the Java virtual + abilities. The JAR artifact of + org.netbeans.html:net.java.html.boot + contains an Agent-Class and Premain-Class + attributes in its manifest. As such one can launch the Java virtual machine with
 $ java -javaagent:jarpath=net.java.html.boot-x.y.jar
-
- and the runtime will take care of processing bytecode of classes - not yet processed in compile time before they are loaded into the - virtual machine. +
+ and the runtime will take care of processing bytecode of classes + before they are loaded into the + virtual machine. Since version 1.8.2 this agent also changes retention + of {@link net.java.html.js.JavaScriptBody} + and {@link net.java.html.js.JavaScriptResource} annotations + to {@link java.lang.annotation.RetentionPolicy#RUNTIME}. + As such technologies that need + access to these annotations during runtime can do so by using the + -javaagent JVM switch.

- Special classloading - when booting your application with + +

Special classloading

+ + + There is a special implementation of dynamic classloader. + When booting your application with {@link net.java.html.boot.BrowserBuilder} there is a 3rd option of processing the classes. If there are some classes not yet processed - (remember the files listing them generated by the + (remember the files listing them generated by the annotation processor), the {@link net.java.html.boot.BrowserBuilder#showAndWait() launching method} will create a special classloader to that does the processing before @@ -406,16 +426,16 @@

Post Process Classes

processing needs to also include asm-5.0.jar on application classpath), it is recommended to perform the compile time processing. - +

Getting Started

- - There are many ways to start developing - Html for Java application. + + There are many ways to start developing + Html for Java application. However to be sure one chooses the most recent setup, it is recommended - to switch to good old command line and use a + to switch to good old command line and use a Maven archetype associated with every version of this project. Just type: -
      
+
 $ mvn archetype:generate \
  -DarchetypeGroupId=org.apidesign.html \
  -DarchetypeArtifactId=knockout4j-archetype \
@@ -426,10 +446,10 @@ 

Getting Started

$ cd myfirstbrwsrpage $ mvn process-classes exec:java
- In a few seconds (or minutes if + In a few seconds (or minutes if Maven - decides to download the whole Internet of dependencies) you should - see a sample Hello World application. It is basically composed from one + decides to download the whole Internet of dependencies) you should + see a sample Hello World application. It is basically composed from one Java and one HTML file:
 $ ls src/main/java/**/DataModel.java
@@ -437,22 +457,22 @@ 

Getting Started

Play with them, modify them and enjoy Html for Java! - +

Mixed Java/JavaScript Debugging

- +

- The following video shows how easy it is to use - NetBeans 8.0, JDK8 to debug an application that intermixes Java - and JavaScript calls. One can put breakpoints into Java part, - as well as JavaScript source code, inspect Java as well - as JavaScript variables and switch between these two + The following video shows how easy it is to use + NetBeans 8.0, JDK8 to debug an application that intermixes Java + and JavaScript calls. One can put breakpoints into Java part, + as well as JavaScript source code, inspect Java as well + as JavaScript variables and switch between these two languages without any restrictions.

- - diff --git a/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java b/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java index 0071cdd90..2b39d661b 100644 --- a/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java +++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java @@ -21,6 +21,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.Reader; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.net.URL; import java.util.ArrayList; import java.util.Collections; @@ -62,6 +64,21 @@ private FnUtils() { * @since 0.7 */ public static byte[] transform(byte[] bytecode, ClassLoader loader) { + return transform(bytecode, loader, false); + } + /** Seeks for {@link JavaScriptBody} and {@link JavaScriptResource} annotations + * in the bytecode and converts them into real code. Used by Maven plugin + * postprocessing classes. + * + * @param bytecode the original bytecode with javascript specific annotations + * @param loader the loader to load resources (scripts and classes) when needed + * @param makeVisible {@code true} if the {@link Retention} of the + * {@link JavaScriptBody} and {@link JavaScriptResource} annotations + * should be changed to {@link RetentionPolicy#RUNTIME} + * @return the transformed bytecode + * @since 1.8.2 + */ + public static byte[] transform(byte[] bytecode, ClassLoader loader, boolean makeVisible) { ClassReader cr = new ClassReader(bytecode) { // to allow us to compile with -profile compact1 on // JDK8 while processing the class as JDK7, the highest @@ -75,11 +92,11 @@ public short readShort(int index) { return s; } }; - FindInClass tst = new FindInClass(loader, null); + FindInClass tst = new FindInClass(loader, null, makeVisible); cr.accept(tst, 0); if (tst.found > 0) { ClassWriter w = new ClassWriterEx(loader, cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); - FindInClass fic = new FindInClass(loader, w); + FindInClass fic = new FindInClass(loader, w, makeVisible); cr.accept(fic, 0); bytecode = w.toByteArray(); } @@ -119,9 +136,11 @@ private static final class FindInClass extends ClassVisitor { private int found; private int resourcesCnt = 0; private final String[] resources = new String[256]; + private final boolean makeVisible; - public FindInClass(ClassLoader l, ClassVisitor cv) { + FindInClass(ClassLoader l, ClassVisitor cv, boolean makeVisible) { super(Opcodes.ASM5, cv); + this.makeVisible = makeVisible; } @Override @@ -133,11 +152,16 @@ public void visit(int version, int access, String name, String signature, String @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { final AnnotationVisitor del = super.visitAnnotation(desc, visible); + if ("Ljava/lang/annotation/Retention;".equals(desc)) { + return makeVisible ? new RetentionChange(del) : del; + } if ("Lnet/java/html/js/JavaScriptResource;".equals(desc)) { - return new LoadResource(del); + var visibleDel = makeVisible ? super.visitAnnotation(desc, true) : null; + return new LoadResource(DoubleVisitor.combine(del, visibleDel)); } if ("Lnet/java/html/js/JavaScriptResource$Group;".equals(desc)) { - return new LoadResource(del); + var visibleDel = makeVisible ? super.visitAnnotation(desc, true) : null; + return new LoadResource(DoubleVisitor.combine(del, visibleDel)); } return del; } @@ -179,8 +203,9 @@ public FindInMethod(int access, String name, String desc, MethodVisitor mv) { @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if ("Lnet/java/html/js/JavaScriptBody;".equals(desc)) { // NOI18N + var visibleDel = makeVisible ? super.visitAnnotation(desc, true) : null; found++; - return new FindInAnno(); + return DoubleVisitor.combine(new FindInAnno(), visibleDel); } return super.visitAnnotation(desc, visible); } @@ -504,7 +529,7 @@ private final class FindInAnno extends AnnotationVisitor { Boolean wait4java; Boolean keepAlive; - public FindInAnno() { + FindInAnno() { super(Opcodes.ASM5); } @@ -564,8 +589,60 @@ boolean keepAlive() { } } + private static final class DoubleVisitor extends AnnotationVisitor { + private final AnnotationVisitor a2; + + private DoubleVisitor(AnnotationVisitor a1, AnnotationVisitor a2) { + super(Opcodes.ASM5, a1); + assert a2 != null; + this.a2 = a2; + } + + static AnnotationVisitor combine(AnnotationVisitor a1, AnnotationVisitor a2) { + if (a1 == null) { + return a2; + } else if (a2 == null) { + return a1; + } else { + return new DoubleVisitor(a1, a2); + } + } + + @Override + public void visitEnd() { + super.visitEnd(); + a2.visitEnd(); + } + + @Override + public AnnotationVisitor visitArray(String name) { + var v1 = super.visitArray(name); + var v2 = a2.visitArray(name); + return DoubleVisitor.combine(v1, v2); + } + + @Override + public AnnotationVisitor visitAnnotation(String name, String desc) { + var v1 = super.visitAnnotation(name, desc); + var v2 = a2.visitAnnotation(name, desc); + return DoubleVisitor.combine(v1, v2); + } + + @Override + public void visitEnum(String name, String desc, String value) { + super.visitEnum(name, desc, value); + a2.visitEnum(name, desc, value); + } + + @Override + public void visit(String name, Object value) { + super.visit(name, value); + a2.visit(name, value); + } + } + private final class LoadResource extends AnnotationVisitor { - public LoadResource(AnnotationVisitor av) { + LoadResource(AnnotationVisitor av) { super(Opcodes.ASM5, av); } @@ -592,6 +669,42 @@ public AnnotationVisitor visitAnnotation(String name, String desc) { return new LoadResource(super.visitAnnotation(name, desc)); } } + + private final class RetentionChange extends AnnotationVisitor { + RetentionChange(AnnotationVisitor av) { + super(Opcodes.ASM5, av); + } + + @Override + public void visit(String attrName, Object value) { + super.visit(attrName, value); + } + + @Override + public AnnotationVisitor visitArray(String name) { + return super.visitArray(name); + } + + @Override + public AnnotationVisitor visitAnnotation(String name, String desc) { + return super.visitAnnotation(desc, desc); + } + + @Override + public void visitEnum(String value, String retentionPolicy, String type) { + if ("Ljava/lang/annotation/RetentionPolicy;".equals(retentionPolicy)) { + found++; + super.visitEnum(value, retentionPolicy, "RUNTIME"); + } else { + super.visitEnum(value, retentionPolicy, type); + } + } + + @Override + public void visitEnd() { + super.visitEnd(); + } + } } private static class ClassWriterEx extends ClassWriter { diff --git a/boot/src/main/java/org/netbeans/html/boot/impl/JsAgent.java b/boot/src/main/java/org/netbeans/html/boot/impl/JsAgent.java index a2df117a1..8f16b444a 100644 --- a/boot/src/main/java/org/netbeans/html/boot/impl/JsAgent.java +++ b/boot/src/main/java/org/netbeans/html/boot/impl/JsAgent.java @@ -21,6 +21,7 @@ import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.IllegalClassFormatException; import java.lang.instrument.Instrumentation; +import java.nio.charset.StandardCharsets; import java.security.ProtectionDomain; /** @@ -39,13 +40,28 @@ public static void agentmain(String args, Instrumentation instr) { @Override public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { try { - if (JsPkgCache.process(loader, className)) { - return FnUtils.transform(classfileBuffer, loader); + if (containsJavaBodies(classfileBuffer)) { + return FnUtils.transform(classfileBuffer, loader, true); } else { return classfileBuffer; } - } catch (Exception ex) { + } catch (Error | Exception ex) { + System.err.println("Error transforming " + className); + ex.printStackTrace(); return classfileBuffer; } } + + private static final byte[] PATTERN = new String("net/java/html/js/").getBytes(StandardCharsets.UTF_8); + private static boolean containsJavaBodies(byte[] arr) { + NOT_FOUND: for (var i = 0; i < arr.length - PATTERN.length; i++) { + for (var j = 0; j < PATTERN.length; j++) { + if (arr[i + j] != PATTERN[j]) { + continue NOT_FOUND; + } + } + return true; + } + return false; + } } diff --git a/boot/src/main/java/org/netbeans/html/boot/impl/JsPkgCache.java b/boot/src/main/java/org/netbeans/html/boot/impl/JsPkgCache.java index 6d68d7dc4..49c5f1166 100644 --- a/boot/src/main/java/org/netbeans/html/boot/impl/JsPkgCache.java +++ b/boot/src/main/java/org/netbeans/html/boot/impl/JsPkgCache.java @@ -28,22 +28,32 @@ import java.util.Set; import java.util.TreeSet; import java.util.WeakHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; /** * * @author Jaroslav Tulach */ final class JsPkgCache { - private final Map> props = new WeakHashMap>(); - private static final Map CACHE = new WeakHashMap(); + private final Map> props = new WeakHashMap<>(); + private static final Map CACHE = new WeakHashMap<>(); private static final Set NONE = Collections.emptySet(); - public static boolean process(ClassLoader l, String className) { - if (className.equals("org.netbeans.html.boot.impl.Test")) { // NOI18N - return true; + public static boolean process(ClassLoader loader, String dotOrSlashClassName) { + if (loader == null) { + return false; } + var slashClassName = dotOrSlashClassName.replace('.', '/'); + var className = dotOrSlashClassName.replace('/', '.'); + return switch (className) { + case "net.java.html.js.JavaScriptBody" -> true; // NOI18N + case "net.java.html.js.JavaScriptResource" -> true; // NOI18N + case "net.java.html.js.JavaScriptResource$Group" -> true; // NOI18N; + case "org.netbeans.html.boot.impl.Test" -> true; // NOI18N + default -> packageCheck(loader, slashClassName, className); + }; + } + + private static boolean packageCheck(ClassLoader l, String slashClassName, String dotClassName) { Set p; JsPkgCache c; String pkgName; @@ -53,17 +63,17 @@ public static boolean process(ClassLoader l, String className) { c = new JsPkgCache(); CACHE.put(l, c); } - int lastDot = className.lastIndexOf('.'); - pkgName = className.substring(0, lastDot + 1).replace('.', '/'); + int lastDot = slashClassName.lastIndexOf('/'); + pkgName = slashClassName.substring(0, lastDot + 1); p = c.props.get(pkgName); if (p == NONE) { return false; } else if (p != null) { - return p.contains(className); + return p.contains(dotClassName); } } final String res = pkgName + "net.java.html.js.classes"; - + Enumeration en; try { en = l.getResources(res); @@ -76,7 +86,7 @@ public static boolean process(ClassLoader l, String className) { } try { - Set arr = new TreeSet(); + Set arr = new TreeSet<>(); while (en.hasMoreElements()) { URL u = en.nextElement(); BufferedReader r = new BufferedReader( @@ -93,15 +103,14 @@ public static boolean process(ClassLoader l, String className) { } p = arr; } catch (IOException ex) { - LOG.log(Level.WARNING, "Can't read " + res, ex); + System.err.println("Cannot read: " + res); + ex.printStackTrace(); p = NONE; } - + synchronized (CACHE) { c.props.put(pkgName, p); - return p.contains(className); + return p.contains(dotClassName); } - } - private static final Logger LOG = Logger.getLogger(JsPkgCache.class.getName()); } diff --git a/dynamic-loader-test/pom.xml b/dynamic-loader-test/pom.xml new file mode 100644 index 000000000..0b873797f --- /dev/null +++ b/dynamic-loader-test/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + org.netbeans.html + pom + 2.0-SNAPSHOT + + dynamic-loader-test + jar + Dynamic ClassLoader Test + + ${skipJavaFXTests} + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + org.apache.maven.plugins + maven-enforcer-plugin + + true + + + + + + + org.testng + testng + test + + + org.netbeans.html + net.java.html + ${project.version} + test + jar + + + org.netbeans.html + net.java.html.boot + ${project.version} + test + jar + + + ${project.groupId} + net.java.html.boot.fx + ${project.version} + test + + + org.openjfx + javafx-web + test + + + \ No newline at end of file diff --git a/boot-agent-test/src/test/java/org/netbeans/html/bootagent/DynamicClassLoaderTest.java b/dynamic-loader-test/src/test/java/org/netbeans/html/dynamicloader/DynamicClassLoaderTest.java similarity index 98% rename from boot-agent-test/src/test/java/org/netbeans/html/bootagent/DynamicClassLoaderTest.java rename to dynamic-loader-test/src/test/java/org/netbeans/html/dynamicloader/DynamicClassLoaderTest.java index b9fbc809b..95dd4f6b6 100644 --- a/boot-agent-test/src/test/java/org/netbeans/html/bootagent/DynamicClassLoaderTest.java +++ b/dynamic-loader-test/src/test/java/org/netbeans/html/dynamicloader/DynamicClassLoaderTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.netbeans.html.bootagent; +package org.netbeans.html.dynamicloader; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -39,7 +39,7 @@ public class DynamicClassLoaderTest { private static Class browserClass; private static Fn.Presenter browserPresenter; - + public DynamicClassLoaderTest() { } @@ -74,7 +74,7 @@ static synchronized Class loadClass() throws InterruptedException { } return browserClass; } - + public static void ready(Class browserCls) throws Exception { Class origClazz = ClassLoader.getSystemClassLoader().loadClass(DynamicClassLoaderTest.class.getName()); final Field f1 = origClazz.getDeclaredField("browserClass"); @@ -87,7 +87,7 @@ public static void ready(Class browserCls) throws Exception { origClazz.notifyAll(); } } - + public static void initialized() throws Exception { BrwsrCtx b1 = BrwsrCtx.findDefault(DynamicClassLoaderTest.class); assertNotSame(b1, BrwsrCtx.EMPTY, "Browser context is not empty"); diff --git a/dynamic-loader-test/src/test/java/org/netbeans/html/dynamicloader/JavaScriptBodyTst.java b/dynamic-loader-test/src/test/java/org/netbeans/html/dynamicloader/JavaScriptBodyTst.java new file mode 100644 index 000000000..b94236792 --- /dev/null +++ b/dynamic-loader-test/src/test/java/org/netbeans/html/dynamicloader/JavaScriptBodyTst.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.html.dynamicloader; + +import net.java.html.js.JavaScriptBody; +import net.java.html.js.JavaScriptResource; + +/** + * + * @author Jaroslav Tulach + */ +@JavaScriptResource("empty.js") +public class JavaScriptBodyTst { + + public JavaScriptBodyTst() { + } + + public void assert42() { + int v = mul(7, 6); + assert v == 42 : "Really 42: " + v; + } + + public void assertEmptySymbolDefined() { + assert Boolean.TRUE.equals(eval("empty")) : "empty.js should defined empty global symbol"; + } + public void assertEmpty2SymbolDefined() { + MultiResource.loadIt(); + assert Boolean.TRUE.equals(eval("empty2")) : "empty.js should defined empty global symbol"; + } + public void assertEmpty3SymbolDefined() { + MultiResource.loadIt(); + assert Boolean.TRUE.equals(eval("empty3")) : "empty.js should defined empty global symbol"; + } + + public void assertJavaScriptBodyAnnotationPresentInRuntime() throws Exception { + var mul = JavaScriptBodyTst.class.getDeclaredMethod("mul", int.class, int.class); + var ann = mul.getAnnotation(JavaScriptBody.class); + assert ann == null : "DynamicClassLoader doesn't modify retention unlike -javaagent usage"; + } + + public void assertJavaScriptResourceAnnotationPresentInRuntime() throws Exception { + var ann = JavaScriptBodyTst.class.getAnnotation(JavaScriptResource.class); + assert ann == null : "DynamicClassLoader doesn't modify retention unlike -javaagent usage"; + } + + public void assertJavaScriptResourceGroupAnnotationPresentInRuntime() throws Exception { + var ann = MultiResource.class.getAnnotation(JavaScriptResource.Group.class); + assert ann == null : "DynamicClassLoader doesn't modify retention unlike -javaagent usage"; + } + + @JavaScriptBody(args = { "x", "y" }, body = "return x * y;") + private static native int mul(int x, int y); + + @JavaScriptBody(args = { "code" }, body = "return eval(code);") + private static native Object eval(String code); + + @JavaScriptResource("empty_2.js") + @JavaScriptResource("empty_3.js") + static final class MultiResource { + @JavaScriptBody(args = {}, body = "") + static void loadIt() { + } + } +} diff --git a/dynamic-loader-test/src/test/java/org/netbeans/html/dynamicloader/KOFx.java b/dynamic-loader-test/src/test/java/org/netbeans/html/dynamicloader/KOFx.java new file mode 100644 index 000000000..0d8196c01 --- /dev/null +++ b/dynamic-loader-test/src/test/java/org/netbeans/html/dynamicloader/KOFx.java @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.html.dynamicloader; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import javafx.application.Platform; +import org.netbeans.html.boot.spi.Fn; +import org.testng.IHookCallBack; +import org.testng.IHookable; +import org.testng.ITest; +import org.testng.ITestResult; +import org.testng.annotations.Test; + +/** + * + * @author Jaroslav Tulach + */ +public final class KOFx implements ITest, IHookable, Runnable { + private final Fn.Presenter p; + private final Method m; + private Object result; + private Object inst; + + KOFx(Fn.Presenter p, Method m) { + this.p = p; + this.m = m; + } + + @Override + public String getTestName() { + return m.getName(); + } + + @Test + public synchronized void executeTest() throws Exception { + if (result == null) { + Platform.runLater(this); + wait(); + } + if (result instanceof Exception) { + throw (Exception)result; + } + if (result instanceof Error) { + throw (Error)result; + } + } + + @Override + public synchronized void run() { + boolean notify = true; + try (var ctx = Fn.activate(p)) { + if (inst == null) { + inst = m.getDeclaringClass().newInstance(); + } + result = m.invoke(inst); + if (result == null) { + result = this; + } + } catch (InvocationTargetException ex) { + Throwable r = ex.getTargetException(); + if (r instanceof InterruptedException) { + notify = false; + Platform.runLater(this); + return; + } + result = r; + } catch (Exception ex) { + result = ex; + } finally { + if (notify) { + notifyAll(); + } + } + } + + @Override + public void run(IHookCallBack ihcb, ITestResult itr) { + ihcb.runTestMethod(itr); + } + +} diff --git a/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty.html b/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty.html new file mode 100644 index 000000000..31e63db56 --- /dev/null +++ b/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty.html @@ -0,0 +1,31 @@ + + + + + Bootstrap Dynamically + + + + +
Bootstrap Dynamically
+ + diff --git a/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty.js b/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty.js new file mode 100644 index 000000000..b4525b4f4 --- /dev/null +++ b/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty.js @@ -0,0 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +*/ +this.empty = true; diff --git a/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty_2.js b/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty_2.js new file mode 100644 index 000000000..ceb668f10 --- /dev/null +++ b/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty_2.js @@ -0,0 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +*/ +this.empty2 = true; diff --git a/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty_3.js b/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty_3.js new file mode 100644 index 000000000..ddecd53bf --- /dev/null +++ b/dynamic-loader-test/src/test/resources/org/netbeans/html/dynamicloader/empty_3.js @@ -0,0 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +*/ +this.empty3 = true; diff --git a/generic/pom.xml b/generic/pom.xml index 670365ffa..e481335b3 100644 --- a/generic/pom.xml +++ b/generic/pom.xml @@ -46,6 +46,12 @@ net.java.html.boot jar ${project.version} + + + org.ow2.asm + asm + + org.testng diff --git a/geo/pom.xml b/geo/pom.xml index 928ece310..2acd1cc4b 100644 --- a/geo/pom.xml +++ b/geo/pom.xml @@ -64,6 +64,12 @@ net.java.html.boot ${project.version} jar + + + org.ow2.asm + asm + + Find out where your Java program running in an HTML page is! diff --git a/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotations.java b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotations.java index 43f4eba09..d9db453e2 100644 --- a/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotations.java +++ b/html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotations.java @@ -38,8 +38,6 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; -import java.util.logging.Level; -import java.util.logging.Logger; import org.objectweb.asm.ClassReader; abstract class ProcessJsAnnotations { diff --git a/json-tck/src/test/java/net/java/html/js/tests/ResourceOrderTest.java b/json-tck/src/test/java/net/java/html/js/tests/ResourceOrderTest.java index 59fbec85e..f9728d209 100644 --- a/json-tck/src/test/java/net/java/html/js/tests/ResourceOrderTest.java +++ b/json-tck/src/test/java/net/java/html/js/tests/ResourceOrderTest.java @@ -27,6 +27,7 @@ import org.objectweb.asm.Opcodes; import org.testng.Assert; import static org.testng.Assert.assertEquals; +import static org.testng.AssertJUnit.assertTrue; import org.testng.annotations.Test; public class ResourceOrderTest { @@ -39,7 +40,8 @@ public void testLoadData() throws Exception { InputStream is = ResourceOrder.class.getResourceAsStream("ResourceOrder.class"); int[] valueCount = { 0 }; - List values = new ArrayList<>(); + List visibleValues = new ArrayList<>(); + List hiddenValues = new ArrayList<>(); ClassReader r = new ClassReader(is); r.accept(new ClassVisitor(Opcodes.ASM5) { @@ -101,6 +103,7 @@ public void visitEnum(String name, String desc, String value) { public void visit(String name, Object value) { Assert.assertEquals(name, "value"); Assert.assertTrue(value instanceof String, "It is a string: " + value); + var values = visible ? visibleValues : hiddenValues; values.add((String) value); } }; @@ -124,10 +127,14 @@ public void visitEnd() { }; } }, 0); + assertValues("Hidden values found", hiddenValues); + assertTrue("No visible visible values after processing with Maven plugin: " + visibleValues, visibleValues.isEmpty()); + } - assertEquals(values.size(), 3, "There are there elements: " + values); - assertEquals(values.get(0), "initArray.js"); - assertEquals(values.get(1), "addHello.js"); - assertEquals(values.get(2), "addWorld.js"); + private void assertValues(String prefix, List values) { + assertEquals(values.size(), 3, prefix + ": There are there elements: " + values); + assertEquals(values.get(0), "initArray.js", prefix + " 0"); + assertEquals(values.get(1), "addHello.js", prefix + " 1"); + assertEquals(values.get(2), "addWorld.js", prefix + " 2"); } } diff --git a/ko4j/pom.xml b/ko4j/pom.xml index e1b995071..a2eca98ae 100644 --- a/ko4j/pom.xml +++ b/ko4j/pom.xml @@ -96,6 +96,12 @@ net.java.html.boot ${project.version} jar + + + org.ow2.asm + asm + + ${project.groupId} diff --git a/pom.xml b/pom.xml index de3c2ecd6..519dfd6d1 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,7 @@ + dynamic-loader-test boot-agent-test xhr4j @@ -225,6 +226,7 @@ org.netbeans.html.boot.impl:org.netbeans.html.boot.fx:org.netbeans.html.context. **/.maven/** **/*.sigtest **/nb-configuration.xml + **/dependency-reduced-pom.xml **/nbactions.xml README.md DEPENDENCIES @@ -263,6 +265,7 @@ org.netbeans.html.boot.impl:org.netbeans.html.boot.fx:org.netbeans.html.context. true + false diff --git a/renderer/pom.xml b/renderer/pom.xml index 3438c8ec3..619afad6d 100644 --- a/renderer/pom.xml +++ b/renderer/pom.xml @@ -64,6 +64,12 @@ org.netbeans.html net.java.html.boot ${project.version} + + + org.ow2.asm + asm + + \ No newline at end of file diff --git a/sound/pom.xml b/sound/pom.xml index 705ed2118..777e8e5a4 100644 --- a/sound/pom.xml +++ b/sound/pom.xml @@ -95,6 +95,12 @@ net.java.html.boot ${project.version} jar + + + org.ow2.asm + asm + + org.netbeans.api diff --git a/src/main/javadoc/overview.html b/src/main/javadoc/overview.html index 90d1b2098..182e2fc70 100644 --- a/src/main/javadoc/overview.html +++ b/src/main/javadoc/overview.html @@ -163,6 +163,17 @@

Try it

vm.loadClass('org.apidesign.demo.minesweeper.MainBrwsr'); +

New in version 1.8.2

+

+ When post-processing classes with -javaagent instrumenting agent + - read the + details here + - the RetentionType of + {@link net.java.html.js.JavaScriptBody} and related annotations + is changed to RUNTIME. Implemented by + PR #54. +

+

New in version 1.8.1

This is a bugfix release focused on improving diff --git a/webkit/pom.xml b/webkit/pom.xml index 92ffd2d9a..154946e97 100644 --- a/webkit/pom.xml +++ b/webkit/pom.xml @@ -100,6 +100,12 @@ net.java.html.boot ${project.version} jar + + + org.ow2.asm + asm + + org.netbeans.api