Fix failing test

This commit is contained in:
Alexey Andreev 2017-05-30 00:27:14 +03:00
parent 3791b806b9
commit eba3fa3ac4
4 changed files with 43 additions and 70 deletions

View File

@ -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<String> 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();
}
}
}

View File

@ -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 {

View File

@ -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" };
}
}

View File

@ -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