diff --git a/html4j/src/main/java/org/teavm/html4j/ResourcesInterceptor.java b/html4j/src/main/java/org/teavm/html4j/ResourcesInterceptor.java deleted file mode 100644 index 2e2f63b8b..000000000 --- a/html4j/src/main/java/org/teavm/html4j/ResourcesInterceptor.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2014 Alexey Andreev. - * - * 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 org.teavm.html4j; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Base64; -import java.util.HashSet; -import java.util.Set; -import org.apache.commons.io.IOUtils; -import org.teavm.backend.javascript.codegen.SourceWriter; -import org.teavm.backend.javascript.rendering.RenderingManager; -import org.teavm.vm.BuildTarget; -import org.teavm.vm.spi.AbstractRendererListener; - -/** - * - * @author Jaroslav Tulach - */ -public class ResourcesInterceptor extends AbstractRendererListener { - private final Set processed = new HashSet<>(); - @Override - public void begin(RenderingManager manager, BuildTarget buildTarget) throws IOException { - boolean hasOneResource = false; - for (String className : manager.getClassSource().getClassNames()) { - final int lastDot = className.lastIndexOf('.'); - if (lastDot == -1) { - continue; - } - String packageName = className.substring(0, lastDot); - String resourceName = packageName.replace('.', '/') + "/" + "jvm.txt"; - try (InputStream input = manager.getClassLoader().getResourceAsStream(resourceName)) { - if (input == null || !processed.add(resourceName)) { - continue; - } - ByteArrayOutputStream arr = new ByteArrayOutputStream(); - IOUtils.copy(input, arr); - String base64 = Base64.getEncoder().encodeToString(arr.toByteArray()); - input.close(); - final SourceWriter w = manager.getWriter(); - w.append("// Resource " + resourceName + " included by " + className).newLine(); - w.append("if (!window.teaVMResources) window.teaVMResources = {};").newLine(); - w.append("window.teaVMResources['" + resourceName + "'] = '"); - w.append(base64).append("';").newLine().newLine(); - } - hasOneResource = true; - } - if (hasOneResource) { - manager.getWriter().append("// TeaVM generated classes").newLine(); - } - } -} diff --git a/html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java b/html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java index 989e7775c..39b7ea1fd 100644 --- a/html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java +++ b/html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTest.java @@ -28,10 +28,6 @@ import org.junit.runner.RunWith; import org.teavm.junit.SkipJVM; import org.teavm.junit.TeaVMTestRunner; -/** - * - * @author Alexey Andreev - */ @RunWith(TeaVMTestRunner.class) @SkipJVM public class JavaScriptBodyTest { diff --git a/html4j/src/test/java/org/teavm/html4j/testing/HTML4JResourceSupplier.java b/html4j/src/test/java/org/teavm/html4j/testing/HTML4JResourceSupplier.java new file mode 100644 index 000000000..1de640094 --- /dev/null +++ b/html4j/src/test/java/org/teavm/html4j/testing/HTML4JResourceSupplier.java @@ -0,0 +1,26 @@ +/* + * Copyright 2017 Alexey Andreev. + * + * 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 org.teavm.html4j.testing; + +import org.teavm.classlib.ResourceSupplier; +import org.teavm.classlib.ResourceSupplierContext; + +public class HTML4JResourceSupplier implements ResourceSupplier { + @Override + public String[] supplyResources(ResourceSupplierContext context) { + return new String[] { "org/teavm/html4j/test/jvm.txt" }; + } +} diff --git a/html4j/src/test/resources/META-INF/services/org.teavm.classlib.ResourceSupplier b/html4j/src/test/resources/META-INF/services/org.teavm.classlib.ResourceSupplier new file mode 100644 index 000000000..283592f02 --- /dev/null +++ b/html4j/src/test/resources/META-INF/services/org.teavm.classlib.ResourceSupplier @@ -0,0 +1,17 @@ +# +# Copyright 2017 Alexey Andreev. +# +# 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. +# + +org.teavm.html4j.testing.HTML4JResourceSupplier \ No newline at end of file