Skip to content

Commit 653075d

Browse files
committed
Draft and test
1 parent 7809eb4 commit 653075d

File tree

8 files changed

+192
-5
lines changed

8 files changed

+192
-5
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>java11-project-and-emul</groupId>
7+
<artifactId>java11-project-and-emul</artifactId>
8+
<version>1.0</version>
9+
</parent>
10+
<artifactId>app</artifactId>
11+
<packaging>war</packaging>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>java11-project-and-emul</groupId>
16+
<artifactId>emul</artifactId>
17+
<version>1.0</version>
18+
</dependency>
19+
</dependencies>
20+
<build>
21+
<plugins>
22+
<plugin>
23+
<groupId>@project.groupId@</groupId>
24+
<artifactId>@project.artifactId@</artifactId>
25+
<version>@project.version@</version>
26+
<executions>
27+
<execution>
28+
<goals>
29+
<goal>build</goal>
30+
</goals>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
<pluginManagement>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-war-plugin</artifactId>
40+
<version>3.3.2</version>
41+
</plugin>
42+
</plugins>
43+
</pluginManagement>
44+
</build>
45+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright © 2018 j2cl-maven-plugin authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package example;
17+
18+
import java.io.EOFException;
19+
import java.io.IOException;
20+
import jsinterop.annotations.JsType;
21+
22+
@JsType
23+
public class App {
24+
public void go() throws IOException {
25+
var ex = new EOFException();
26+
27+
throw ex;
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<web-app></web-app>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script type="application/javascript" src="app/app.js"></script>
5+
</head>
6+
<body></body>
7+
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>java11-project-and-emul</groupId>
7+
<artifactId>java11-project-and-emul</artifactId>
8+
<version>1.0</version>
9+
</parent>
10+
<artifactId>emul</artifactId>
11+
<packaging>jar</packaging>
12+
<properties>
13+
<maven.compiler.source>11</maven.compiler.source>
14+
<maven.compiler.target>11</maven.compiler.target>
15+
</properties>
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.google.jsinterop</groupId>
19+
<artifactId>jsinterop-annotations</artifactId>
20+
<version>2.0.0</version>
21+
</dependency>
22+
</dependencies>
23+
<build>
24+
<pluginManagement>
25+
<plugins>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-compiler-plugin</artifactId>
29+
<version>3.6.1</version>
30+
<configuration>
31+
<source>1.8</source>
32+
<target>1.8</target>
33+
</configuration>
34+
</plugin>
35+
</plugins>
36+
</pluginManagement>
37+
</build>
38+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright © 2018 j2cl-maven-plugin authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package java.io;
17+
18+
import jsinterop.annotations.*;
19+
20+
/**
21+
* This is deliberately a little bit silly, mostly to make sure transitive dependencies on
22+
* external packages work, not as a serious suggestion of how this class might be emulated.
23+
*/
24+
@JsType
25+
public class EOFException extends IOException {
26+
@JsIgnore
27+
public EOFException() {
28+
this("EOF");
29+
}
30+
31+
public EOFException(String s) {
32+
super(s);
33+
String string = s + "hello";
34+
}
35+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>java11-project-and-emul</groupId>
6+
<artifactId>java11-project-and-emul</artifactId>
7+
<version>1.0</version>
8+
<packaging>pom</packaging>
9+
10+
<properties>
11+
<maven.compiler.source>11</maven.compiler.source>
12+
<maven.compiler.target>11</maven.compiler.target>
13+
</properties>
14+
15+
<modules>
16+
<module>emul</module>
17+
<module>app</module>
18+
</modules>
19+
</project>

j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/Javac.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,27 @@ public Javac(BuildLog log, File generatedClassesPath, List<File> sourcePaths, Li
5454
// for (File file : classpath) {
5555
// System.out.println(file.getAbsolutePath() + " " + file.exists() + " " + file.isDirectory());
5656
// }
57-
javacOptions = new ArrayList<>(Arrays.asList("-encoding", "utf8", "-implicit:none", "-bootclasspath", bootstrap.toString()));
57+
javacOptions = new ArrayList<>(Arrays.asList("-encoding", "utf8", "-implicit:none"));
5858
if (generatedClassesPath == null) {
5959
javacOptions.add("-proc:none");
6060
}
61-
if (SourceVersion.latestSupported().compareTo(SourceVersion.RELEASE_8) > 0) {
62-
//java 9+
63-
javacOptions.add("--release=8");
64-
}
61+
javacOptions.addAll(List.of(
62+
// Presently j2cl only accepts up to java 11 sources. In the future this could be configurable, but
63+
// might need to have limits (for example, can't support 8 with the other args below).
64+
"-source", "11",
65+
"-target", "11",
66+
67+
// Allow any user code to overwrite packages in java.base
68+
// TODO this set of modules should be configurable
69+
"--patch-module", "java.base=.",
70+
// Allow any user code (which by virtue of the above is in java.base) to read other packages. I don't
71+
// think this needs to be configurable, but probably it should be the same as above.
72+
"--add-reads", "java.base=ALL-UNNAMED",
73+
74+
// Disable specific bytecode generation features that would require new APIs which j2cl doesn't support
75+
"-XDstringConcat=inline",
76+
"-XDinjectLogSites=false"
77+
));
6578
if (!processors.isEmpty()) {
6679
javacOptions.add("-processor");
6780
javacOptions.add(String.join(",", processors));

0 commit comments

Comments
 (0)