From cc3a89ebf7297fe2ef0988ecbc01266deb82e4c6 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Fri, 14 Feb 2014 00:37:14 +0400 Subject: [PATCH] Makes `started' dependency event to be emitted before any dependency checking. Suppresses repeated ClassHolder transformation --- .../java/org/teavm/javascript/JavascriptBuilder.java | 5 ++++- .../javascript/JavascriptProcessedClassSource.java | 12 ++++++++++++ .../org/teavm/maven/BuildJavascriptJUnitMojo.java | 1 + .../java/org/teavm/maven/BuildJavascriptMojo.java | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/teavm-core/src/main/java/org/teavm/javascript/JavascriptBuilder.java b/teavm-core/src/main/java/org/teavm/javascript/JavascriptBuilder.java index 2f3e4a757..5f6d08654 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/JavascriptBuilder.java +++ b/teavm-core/src/main/java/org/teavm/javascript/JavascriptBuilder.java @@ -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("", diff --git a/teavm-core/src/main/java/org/teavm/javascript/JavascriptProcessedClassSource.java b/teavm-core/src/main/java/org/teavm/javascript/JavascriptProcessedClassSource.java index a5055f618..f3729f559 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/JavascriptProcessedClassSource.java +++ b/teavm-core/src/main/java/org/teavm/javascript/JavascriptProcessedClassSource.java @@ -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 transformers = new ArrayList<>(); + private ConcurrentCachedMapper mapper = new ConcurrentCachedMapper<>( + new Mapper() { + @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); diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptJUnitMojo.java b/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptJUnitMojo.java index a164a4853..330b2b66f 100644 --- a/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptJUnitMojo.java +++ b/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptJUnitMojo.java @@ -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(), diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java b/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java index 6776746a8..bd5fe724f 100644 --- a/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java +++ b/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java @@ -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))