Recent updates to the Linker API broke the SingleScriptLinker. This patch allows it to compile again by overriding link().
StandardLinkerContext now traps all Exceptions emitted by a Linker's link() function to provide context for error messages.
Patch by: bobv
Review by: bruce (TBR)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2265 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
index 5733f47..2cf9cd1 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
@@ -351,7 +351,12 @@
"Invoking Linker " + linker.getDescription(), null);
workingArtifacts.freeze();
- workingArtifacts = linker.link(linkerLogger, this, workingArtifacts);
+ try {
+ workingArtifacts = linker.link(linkerLogger, this, workingArtifacts);
+ } catch (Exception e) {
+ linkerLogger.log(TreeLogger.ERROR, "Failed to link", e);
+ throw new UnableToCompleteException();
+ }
}
// Pop the primary linker off of the stack
@@ -365,10 +370,16 @@
// See if the Linker should be run in the current phase
Order order = linkerType.getAnnotation(LinkerOrder.class).value();
if (phasePost.contains(order)) {
+ TreeLogger linkerLogger = logger.branch(TreeLogger.TRACE,
+ "Invoking Linker " + linker.getDescription(), null);
+
workingArtifacts.freeze();
- workingArtifacts = linker.link(logger.branch(TreeLogger.TRACE,
- "Invoking Linker " + linker.getDescription(), null), this,
- workingArtifacts);
+ try {
+ workingArtifacts = linker.link(linkerLogger, this, workingArtifacts);
+ } catch (Exception e) {
+ linkerLogger.log(TreeLogger.ERROR, "Failed to link", e);
+ throw new UnableToCompleteException();
+ }
}
}
diff --git a/dev/core/src/com/google/gwt/core/linker/SingleScriptLinker.java b/dev/core/src/com/google/gwt/core/linker/SingleScriptLinker.java
index e14aff1..7e80bd1 100644
--- a/dev/core/src/com/google/gwt/core/linker/SingleScriptLinker.java
+++ b/dev/core/src/com/google/gwt/core/linker/SingleScriptLinker.java
@@ -28,6 +28,8 @@
import com.google.gwt.dev.util.DefaultTextOutput;
import com.google.gwt.dev.util.Util;
+import java.util.Set;
+
/**
* A Linker for producing a single JavaScript file from a GWT module. The use of
* this Linker requires that the module has exactly one distinct compilation
@@ -40,6 +42,16 @@
}
@Override
+ public ArtifactSet link(TreeLogger logger, LinkerContext context,
+ ArtifactSet artifacts) throws UnableToCompleteException {
+ ArtifactSet toReturn = new ArtifactSet(artifacts);
+
+ toReturn.add(emitSelectionScript(logger, context, artifacts));
+
+ return toReturn;
+ }
+
+ @Override
protected EmittedArtifact emitSelectionScript(TreeLogger logger,
LinkerContext context, ArtifactSet artifacts)
throws UnableToCompleteException {
@@ -66,19 +78,19 @@
out.newlineOpt();
out.print("var $moduleName, $moduleBase;");
out.newlineOpt();
+ out.print("var $stats = $wnd.__gwtstatsEvent ? function(a,b,c,d) {$wnd.__gwtstatsEvent(a,b,c,d)} : null;");
+ out.newlineOpt();
- CompilationResult result = null;
- for (CompilationResult artifact : artifacts.find(CompilationResult.class)) {
- if (result == null) {
- result = artifact;
- } else {
- logger = logger.branch(TreeLogger.ERROR,
- "The module must have exactly one distinct"
- + " permutation when using the " + getDescription()
- + " Linker.", null);
- throw new UnableToCompleteException();
- }
+ // Find the single CompilationResult
+ Set<CompilationResult> results = artifacts.find(CompilationResult.class);
+ if (results.size() != 1) {
+ logger = logger.branch(TreeLogger.ERROR,
+ "The module must have exactly one distinct"
+ + " permutation when using the " + getDescription() + " Linker.",
+ null);
+ throw new UnableToCompleteException();
}
+ CompilationResult result = results.iterator().next();
out.print(result.getJavaScript());