Makes `started' dependency event to be emitted before any dependency

checking. Suppresses repeated ClassHolder transformation
This commit is contained in:
konsoletyper 2014-02-14 00:37:14 +04:00
parent 4dd9eaa1fd
commit cc3a89ebf7
4 changed files with 18 additions and 1 deletions

View File

@ -105,6 +105,10 @@ public class JavascriptBuilder implements JavascriptBuilderHost {
return classSource;
}
public void prepare() {
dependencyChecker.startListeners();
}
public void build(Appendable writer, JavascriptBuildTarget target) throws RenderingException {
AliasProvider aliasProvider = minifying ? new MinifyingAliasProvider() : new DefaultAliasProvider();
DefaultNamingStrategy naming = new DefaultNamingStrategy(aliasProvider, classSource);
@ -112,7 +116,6 @@ public class JavascriptBuilder implements JavascriptBuilderHost {
SourceWriterBuilder builder = new SourceWriterBuilder(naming);
builder.setMinified(minifying);
SourceWriter sourceWriter = builder.build(writer);
dependencyChecker.startListeners();
dependencyChecker.attachMethodGraph(new MethodReference("java.lang.Class", new MethodDescriptor("createNew",
ValueType.object("java.lang.Class"))));
dependencyChecker.attachMethodGraph(new MethodReference("java.lang.String", new MethodDescriptor("<init>",

View File

@ -17,6 +17,8 @@ package org.teavm.javascript;
import java.util.ArrayList;
import java.util.List;
import org.teavm.common.ConcurrentCachedMapper;
import org.teavm.common.Mapper;
import org.teavm.model.ClassHolder;
import org.teavm.model.ClassHolderSource;
import org.teavm.model.ClassHolderTransformer;
@ -28,6 +30,12 @@ import org.teavm.model.ClassHolderTransformer;
class JavascriptProcessedClassSource implements ClassHolderSource {
private ClassHolderSource innerSource;
private List<ClassHolderTransformer> transformers = new ArrayList<>();
private ConcurrentCachedMapper<String, ClassHolder> mapper = new ConcurrentCachedMapper<>(
new Mapper<String, ClassHolder>() {
@Override public ClassHolder map(String preimage) {
return getTransformed(preimage);
}
});
public JavascriptProcessedClassSource(ClassHolderSource innerSource) {
this.innerSource = innerSource;
@ -39,6 +47,10 @@ class JavascriptProcessedClassSource implements ClassHolderSource {
@Override
public ClassHolder get(String name) {
return mapper.map(name);
}
private ClassHolder getTransformed(String name) {
ClassHolder cls = innerSource.get(name);
if (cls != null) {
transformClass(cls);

View File

@ -236,6 +236,7 @@ public class BuildJavascriptJUnitMojo extends AbstractMojo {
JavascriptBuilder builder = builderFactory.create();
builder.setMinifying(minifying);
builder.installPlugins();
builder.prepare();
File file = new File(outputDir, targetName);
try (Writer innerWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
MethodReference cons = new MethodReference(methodRef.getClassName(),

View File

@ -133,6 +133,7 @@ public class BuildJavascriptMojo extends AbstractMojo {
builder.setMinifying(minifying);
builder.setBytecodeLogging(bytecodeLogging);
builder.installPlugins();
builder.prepare();
MethodDescriptor mainMethodDesc = new MethodDescriptor("main", ValueType.arrayOf(
ValueType.object("java.lang.String")), ValueType.VOID);
builder.entryPoint("main", new MethodReference(mainClass, mainMethodDesc))