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; return classSource;
} }
public void prepare() {
dependencyChecker.startListeners();
}
public void build(Appendable writer, JavascriptBuildTarget target) throws RenderingException { public void build(Appendable writer, JavascriptBuildTarget target) throws RenderingException {
AliasProvider aliasProvider = minifying ? new MinifyingAliasProvider() : new DefaultAliasProvider(); AliasProvider aliasProvider = minifying ? new MinifyingAliasProvider() : new DefaultAliasProvider();
DefaultNamingStrategy naming = new DefaultNamingStrategy(aliasProvider, classSource); DefaultNamingStrategy naming = new DefaultNamingStrategy(aliasProvider, classSource);
@ -112,7 +116,6 @@ public class JavascriptBuilder implements JavascriptBuilderHost {
SourceWriterBuilder builder = new SourceWriterBuilder(naming); SourceWriterBuilder builder = new SourceWriterBuilder(naming);
builder.setMinified(minifying); builder.setMinified(minifying);
SourceWriter sourceWriter = builder.build(writer); SourceWriter sourceWriter = builder.build(writer);
dependencyChecker.startListeners();
dependencyChecker.attachMethodGraph(new MethodReference("java.lang.Class", new MethodDescriptor("createNew", dependencyChecker.attachMethodGraph(new MethodReference("java.lang.Class", new MethodDescriptor("createNew",
ValueType.object("java.lang.Class")))); ValueType.object("java.lang.Class"))));
dependencyChecker.attachMethodGraph(new MethodReference("java.lang.String", new MethodDescriptor("<init>", 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.ArrayList;
import java.util.List; import java.util.List;
import org.teavm.common.ConcurrentCachedMapper;
import org.teavm.common.Mapper;
import org.teavm.model.ClassHolder; import org.teavm.model.ClassHolder;
import org.teavm.model.ClassHolderSource; import org.teavm.model.ClassHolderSource;
import org.teavm.model.ClassHolderTransformer; import org.teavm.model.ClassHolderTransformer;
@ -28,6 +30,12 @@ import org.teavm.model.ClassHolderTransformer;
class JavascriptProcessedClassSource implements ClassHolderSource { class JavascriptProcessedClassSource implements ClassHolderSource {
private ClassHolderSource innerSource; private ClassHolderSource innerSource;
private List<ClassHolderTransformer> transformers = new ArrayList<>(); 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) { public JavascriptProcessedClassSource(ClassHolderSource innerSource) {
this.innerSource = innerSource; this.innerSource = innerSource;
@ -39,6 +47,10 @@ class JavascriptProcessedClassSource implements ClassHolderSource {
@Override @Override
public ClassHolder get(String name) { public ClassHolder get(String name) {
return mapper.map(name);
}
private ClassHolder getTransformed(String name) {
ClassHolder cls = innerSource.get(name); ClassHolder cls = innerSource.get(name);
if (cls != null) { if (cls != null) {
transformClass(cls); transformClass(cls);

View File

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

View File

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