-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle static resources and externs (#117)
This establishes a simple set of conventions for static resources and externs. While encouraged, this new convention for externs is not enforced or warned yet. See discussion #116 Fixes #39
- Loading branch information
Showing
16 changed files
with
335 additions
and
37 deletions.
There are no files selected for viewing
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
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
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,87 @@ | ||
<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>static-resources</groupId> | ||
<artifactId>static-resources</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<elemental2.version>1.1.0</elemental2.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.elemental2</groupId> | ||
<artifactId>elemental2-core</artifactId> | ||
<version>${elemental2.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.elemental2</groupId> | ||
<artifactId>elemental2-dom</artifactId> | ||
<version>${elemental2.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.elemental2</groupId> | ||
<artifactId>elemental2-promise</artifactId> | ||
<version>${elemental2.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.vertispan.j2cl</groupId> | ||
<artifactId>junit-annotations</artifactId> | ||
<version>@j2cl.version@</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.vertispan.j2cl</groupId> | ||
<artifactId>junit-emul</artifactId> | ||
<version>@j2cl.version@</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.vertispan.j2cl</groupId> | ||
<artifactId>junit-emul</artifactId> | ||
<version>@j2cl.version@</version> | ||
<classifier>sources</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
<!-- Tests have to be run by hand for now, htmlunit doesnt support fetch --> | ||
<!--<goal>test</goal>--> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
<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> |
29 changes: 29 additions & 0 deletions
29
j2cl-maven-plugin/src/it/static-resources/src/main/java/com/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,29 @@ | ||
package com.example; | ||
|
||
import elemental2.dom.DomGlobal; | ||
import elemental2.dom.Response; | ||
import elemental2.promise.Promise; | ||
import jsinterop.base.Js; | ||
import jsinterop.annotations.JsType; | ||
|
||
@JsType | ||
public class App { | ||
public static void main() { | ||
getData("publicfile.js").then(data -> alert(data), err -> alert("fail!")); | ||
getData("metainfresourcesfile.js").then(data -> alert(data), err -> alert("fail!")); | ||
getData("ignoredfile.js").then(data -> alert("fail!"), err -> alert("success, file missing")); | ||
} | ||
private static Promise<Object> alert(Object data) { | ||
DomGlobal.alert(data); | ||
return Promise.resolve(data); | ||
} | ||
public static Promise<String> getData(String path) { | ||
return DomGlobal.fetch(path) | ||
.then(response -> { | ||
if (response.ok) { | ||
return response.text(); | ||
} | ||
return Promise.reject(response.status + ""); | ||
}); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
j2cl-maven-plugin/src/it/static-resources/src/main/java/com/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,3 @@ | ||
setTimeout(function() { | ||
App.main(); | ||
}, 0); |
9 changes: 9 additions & 0 deletions
9
j2cl-maven-plugin/src/it/static-resources/src/main/java/com/example/public/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,9 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ||
<html> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | ||
<script type="application/javascript" src="static-resources.js"></script> | ||
<title>static resources test</title> | ||
</head> | ||
<body>this is stored in the public/ directory, so it is in the same dir as the output js in the webappDirectory</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
j2cl-maven-plugin/src/it/static-resources/src/main/java/com/example/public/publicfile.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,2 @@ | ||
com/example/public | ||
" this file fails to parse, but that's okay, it will not be loaded as js |
1 change: 1 addition & 0 deletions
1
j2cl-maven-plugin/src/it/static-resources/src/main/resources/META-INF/ignoredfile.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 @@ | ||
" Deliberate parse error, if this file is seen by closure it will fail |
2 changes: 2 additions & 0 deletions
2
...gin/src/it/static-resources/src/main/resources/META-INF/resources/metainfresourcesfile.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,2 @@ | ||
META-INF/resources | ||
" this file fails to parse, but that's okay, it will not be loaded as js |
34 changes: 34 additions & 0 deletions
34
j2cl-maven-plugin/src/it/static-resources/src/test/java/com/example/AppTest.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,34 @@ | ||
package com.example; | ||
|
||
import com.google.j2cl.junit.apt.J2clTestInput; | ||
|
||
import elemental2.promise.Promise; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test has to be run by hand, htmlunit doesn't support fetch: | ||
* https://github.com/HtmlUnit/htmlunit/issues/78 | ||
*/ | ||
@J2clTestInput(AppTest.class) | ||
public class AppTest { | ||
@Test(timeout = 1000) | ||
public Promise<?> testPublicFile() { | ||
return App.getData("publicfile.js"); | ||
} | ||
@Test(timeout = 1000) | ||
public Promise<?> testMetaInfFile() { | ||
return App.getData("metainfresourcesfile.js"); | ||
} | ||
@Test(timeout = 1000) | ||
public Promise<?> testIgnoredFile() { | ||
// failure expected, we handle that in the .then() so that the test will only see success | ||
return App.getData("ignoredfile.js").then(text -> Promise.reject("failure expected"), fail -> { | ||
if ("404".equals(fail)) { | ||
return Promise.resolve("Succcess, saw 404"); | ||
} | ||
return Promise.reject("Expected 404, saw " + fail); | ||
}); | ||
} | ||
} |
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
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
Oops, something went wrong.