forked from Vertispan/j2clmavenplugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
748 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
j2cl-maven-plugin/src/it/lib-with-jre-supersource/about.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
## Problem Description | ||
When the user tries to supply JRE types **on Java 9+**, they can currently not be used. | ||
|
||
## Example | ||
Two projects: | ||
- app - `.war`, client code, using `super` | ||
- super - customer, user-supplied JRE emulation classes | ||
|
||
The relevant lines in the `build.log` are | ||
|
||
1) First the compile starts fine ... | ||
``` | ||
[INFO] Starting lib-with-jre-supersource:super:1.0/bytecode | ||
[INFO] lib-with-jre-supersource:super:1.0/bytecode: No JRE emulation for this step on Java >= 9: java.specification.version:17 | ||
``` | ||
2) ... then `javac` determines that `java.util.UUID` was already in another _module_, namely in `java.base`. | ||
``` | ||
[ERROR] lib-with-jre-supersource:super:1.0/bytecode: | ||
/C:/_data_/_p_/_git/GitHub/j2clmavenplugin/j2cl-maven-plugin/target | ||
/it-tests/lib-with-jre-supersource/super/src/main/java/java/util/UUID.java:16 | ||
package exists in another module: java.base | ||
``` | ||
3) After loading the emulated UUID failed, the original UUID causes problems in J2CL. | ||
``` | ||
[ERROR] lib-with-jre-supersource:super:1.0/bytecode: | ||
/C:/_data_/_p_/_git/GitHub/j2clmavenplugin/j2cl-maven-plugin/target | ||
/it-tests/lib-with-jre-supersource/super/src/main/java/java/util/UUID.java:43 | ||
no suitable constructor found for UUID(no arguments) | ||
constructor java.util.UUID.UUID(byte[]) is not applicable | ||
(actual and formal argument lists differ in length) | ||
constructor java.util.UUID.UUID(long,long) is not applicable | ||
(actual and formal argument lists differ in length) | ||
``` | ||
|
||
NOTE: The exact same error can happen not only in `bytecode` but also in `stripped_bytecode`. | ||
|
||
## Solution Ideas | ||
To actually make `javac` read the new UUID class from our supplied `super`-library, we must: | ||
|
||
- Use `--patch-module` to add `lib-with-jre-supersource-super-1.0.jar` as a JAR on the patch-module-path | ||
- Allow reads from any module to `java.base` | ||
|
||
|
||
--patch-module java.base={{bootClassPath}} | ||
--add-reads java.base=ALL-UNNAMED | ||
|
||
|
||
**And because we don't know which author of JAR dependencies intend on overwriting JRE built-in classes (this set varies between JDK versions), we must put _all_ JARs into the bootClassPath?** | ||
|
||
**But we don't even know, which Java modules is targeted, so need to repeat all JARs to all --patch-module modules?** | ||
|
||
**And we must open all modules?** | ||
Which java modules besides base exist? `java --list-modules` tells us: | ||
|
||
- java.base | ||
- java.compiler | ||
- java.datatransfer | ||
- java.desktop | ||
- java.instrument | ||
- java.logging | ||
- java.management | ||
- java.management.rmi | ||
- java.naming | ||
- java.net.http | ||
- java.prefs | ||
- java.rmi | ||
- java.scripting | ||
- java.se | ||
- java.security.jgss | ||
- java.security.sasl | ||
- java.smartcardio | ||
- java.sql | ||
- java.sql.rowset | ||
- java.transaction.xa | ||
- java.xml | ||
- java.xml.crypto | ||
|
||
## Conclusion | ||
We should add options in the maven plugin to state entries for `--patch-module` and `--add-reads`. | ||
|
||
<supersource> | ||
<module> | ||
<name>java.base</name> | ||
<groupId>com.example</groupId> | ||
<artifactId>libA</artifactId> | ||
<versions>1.0</version> | ||
<module> | ||
<module> | ||
<name>java.net.http</name> | ||
<groupId>com.example</groupId> | ||
<artifactId>libB</artifactId> | ||
<versions>1.0</version> | ||
<module> | ||
</supersource> | ||
|
||
which results in | ||
|
||
--patch-module java.base=.m2/com/example/com-example-libA-1.0.jar java.net.http=.m2/com/example/com-example-libB-1.0.jar | ||
--add-reads java.base=ALL-UNNAMED java.net.http=ALL-UNNAMED | ||
|
56 changes: 56 additions & 0 deletions
56
j2cl-maven-plugin/src/it/lib-with-jre-supersource/app/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>lib-with-jre-supersource</groupId> | ||
<artifactId>app</artifactId> | ||
<version>1.0</version> | ||
<packaging>war</packaging> | ||
|
||
<properties> | ||
<elemental2.version>1.1.0</elemental2.version> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>lib-with-jre-supersource</groupId> | ||
<artifactId>super</artifactId> | ||
<version>1.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.elemental2</groupId> | ||
<artifactId>elemental2-dom</artifactId> | ||
<version>${elemental2.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<!-- Fix https://stackoverflow.com/questions/66920567/error-injecting-org-apache-maven-plugin-war-warmojo --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>3.3.1</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<repositories> | ||
<repository> | ||
<id>google-snapshots</id> | ||
<url>https://oss.sonatype.org/content/repositories/google-snapshots/</url> | ||
</repository> | ||
</repositories> | ||
</project> |
14 changes: 14 additions & 0 deletions
14
j2cl-maven-plugin/src/it/lib-with-jre-supersource/app/src/main/java/example/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package example; | ||
|
||
import elemental2.dom.DomGlobal; | ||
import java.util.UUID; | ||
|
||
public class App { | ||
|
||
public void onModuleLoad() { | ||
DomGlobal.console.log("Client code runs"); | ||
UUID uuid = UUID.fromString("hello"); | ||
DomGlobal.console.log("Now we need emulated code. A custom UUID: "+uuid); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
j2cl-maven-plugin/src/it/lib-with-jre-supersource/app/src/main/java/example/App.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* #%L | ||
* Connected | ||
* %% | ||
* Copyright (C) 2017 Vertispan | ||
* %% | ||
* Licensed 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. | ||
* #L% | ||
*/ | ||
|
||
// Defer this command, since this will be folded into the FlowChartEntryPoint js impl, | ||
// and if it runs right away, will not have its dependencies resolved yet (at least while | ||
// running in BUNDLE). | ||
setTimeout(function(){ | ||
// Call the java "constructor" method, `new` will only work if it is a @JsType, or maybe | ||
// once optimized. Without this, in BUNDLE mode, `new` doesn't include the clinit, so | ||
// static imports haven't been resolved yet. | ||
var ep = App.$create__(); | ||
// Invoke onModuleLoad to start the app. | ||
ep.m_onModuleLoad__() | ||
}, 0); | ||
|
1 change: 1 addition & 0 deletions
1
j2cl-maven-plugin/src/it/lib-with-jre-supersource/app/src/main/webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<web-app></web-app> |
7 changes: 7 additions & 0 deletions
7
j2cl-maven-plugin/src/it/lib-with-jre-supersource/app/src/main/webapp/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ||
<html> | ||
<head> | ||
<script type="application/javascript" src="app/app.js"></script> | ||
</head> | ||
<body></body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>lib-with-jre-supersource</groupId> | ||
<artifactId>lib-with-jre-supersource</artifactId> | ||
|
||
<version>1.0</version> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>super</module> | ||
<module>app</module> | ||
</modules> | ||
|
||
</project> |
44 changes: 44 additions & 0 deletions
44
j2cl-maven-plugin/src/it/lib-with-jre-supersource/super/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>lib-with-jre-supersource</groupId> | ||
<version>1.0</version> | ||
<artifactId>super</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<elemental2.version>1.1.0</elemental2.version> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.jsinterop</groupId> | ||
<artifactId>jsinterop-annotations</artifactId> | ||
<version>2.0.0</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.6.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
<repositories> | ||
<repository> | ||
<id>google-snapshots</id> | ||
<url>https://oss.sonatype.org/content/repositories/google-snapshots/</url> | ||
</repository> | ||
</repositories> | ||
</project> |
74 changes: 74 additions & 0 deletions
74
j2cl-maven-plugin/src/it/lib-with-jre-supersource/super/src/main/java/java/util/UUID.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright © 2019 Dominokit | ||
* | ||
* Licensed 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 java.util; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Hand-written UUID class. Taken from DominoKit org\dominokit\domino-jackson-super\1.0.0-RC3\domino-jackson-super-1.0.0-RC3-sources | ||
* and simplified. | ||
* | ||
* Note the JDK version has e.g. a "public long node()" method which returns 48 bits of the UUID. | ||
* This version lacks that method. | ||
* This version lacks validation, so UUID.fromString("hello") works. | ||
* The JDK version throws IllegalArgumentException, e.g. if the dashes are missing. | ||
*/ | ||
public class UUID implements Serializable, Comparable<UUID> { | ||
|
||
private static final long serialVersionUID = 7373345728974414241L; | ||
|
||
private String value; | ||
|
||
private UUID() {} | ||
|
||
/** | ||
* Emulated version without validation | ||
* @param uuidString | ||
* @return | ||
*/ | ||
public static UUID fromString(String uuidString) { | ||
final UUID uuid = new UUID(); | ||
uuid.value = uuidString; | ||
return uuid; | ||
} | ||
|
||
@Override | ||
public int compareTo(UUID arg0) { | ||
return value.compareTo(arg0.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null) return false; | ||
if (getClass() != obj.getClass()) return false; | ||
UUID other = (UUID) obj; | ||
if (value == null) { | ||
if (other.value != null) return false; | ||
} else if (!value.equals(other.value)) return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This tests extends the basic "shared-lib-reactor" test and uses `java.io.Externalizable`. | ||
That class has different versions in standard JRE (two methods) and in emulated JRE (no methods). |
Oops, something went wrong.