Commits

Richard Atkins committed 8e011d8 Merge

Merge branch 'issue/SOY-16' into soy-1.1.x

Comments (0)

Files changed (3)

soy-template-plugin/src/main/java/com/atlassian/soy/impl/DefaultSoyManager.java

                 }
                 catch (SoyException e)
                 {
+                    // Guava ComputingHashMap detects that we're throwing this, and avoids rewrapping it again.
+                    // We just have to unwrap it again when we catch it.
                     throw new ComputationException(e);
                 }
             }
                 // this module.
                 throw new SoyException("Unable to compile Soy template in plugin module: " + completeModuleKey);
             }
-            try {
+            try
+            {
                 // TODO: modify SoyTofu to use a streaming approach to rendering
                 appendable.append(tofu.newRenderer(templateName)
                         .setData(soyDataConverter.convertToSoyMapData(data))
                         .setIjData(soyDataConverter.convertToSoyMapData(injectedData))
                         .render());
-            } catch (IOException e) {
+            }
+            catch (IOException e)
+            {
                 throw new SoyException(e);
             }
         }
         long lastModified = 0;
         try
         {
-            for(URL url : moduleDataFactory.get(Arrays.asList(completeModuleKey)).getFileSet())
+            for (URL url : moduleDataFactory.get(Arrays.asList(completeModuleKey)).getFileSet())
             {
                 lastModified = Math.max(lastModified, getLastModified(url));
             }
         return makeBuilder(completeModuleKey).build().compileToJavaObj();
     }
 
-    public SoyFileSet.Builder makeBuilder(String... functionModuleKeys)
+    public SoyFileSet.Builder makeBuilder(String... functionModuleKeys) throws SoyException
     {
-        try
-        {
-            List<String> keyList = ImmutableList.copyOf(functionModuleKeys);
-            ModuleData data = moduleDataFactory.get(keyList);
-            Injector injector = soyDependencyInjectorFactory.get(data);
-            SoyFileSet.Builder builder = injector.getInstance(SoyFileSet.Builder.class);
-            for (URL file : data.getFileSet())
-            {
-                builder.add(file);
-            }
-
-            return builder;
-        }
-        catch (SoyException e)
+        List<String> keyList = ImmutableList.copyOf(functionModuleKeys);
+        ModuleData data = moduleDataFactory.get(keyList);
+        Injector injector = soyDependencyInjectorFactory.get(data);
+        SoyFileSet.Builder builder = injector.getInstance(SoyFileSet.Builder.class);
+        for (URL file : data.getFileSet())
         {
-            // Can't throw this on 1.1.x branch. RuntimeExceptions to the rescue!
-            throw new ComputationException(e);
+            builder.add(file);
         }
+
+        return builder;
     }
 
     private boolean isDevMode()

soy-template-plugin/src/main/java/com/atlassian/soy/impl/SoyManager.java

 package com.atlassian.soy.impl;
 
 import com.atlassian.soy.renderer.SoyException;
-import com.google.inject.Module;
 import com.google.template.soy.SoyFileSet;
 
 import java.util.Map;
      *
      * @param functionModuleKeys the plugin keys of any module that can provide soy functions or templates
      * @return a new Soy builder instance for that module
-     * @throws com.google.common.collect.ComputationException if an error occurs in loading functions from the given modules
+     * @throws SoyException if an error occurs in loading functions from the given modules
      */
-    public SoyFileSet.Builder makeBuilder(String... functionModuleKeys);
+    public SoyFileSet.Builder makeBuilder(String... functionModuleKeys) throws SoyException;
 
     /**
      * Render a template from a module key into an appendable.

soy-template-plugin/src/main/java/com/atlassian/soy/impl/SoyTransformer.java

 import com.atlassian.plugin.servlet.DownloadableResource;
 import com.atlassian.plugin.webresource.transformer.CharSequenceDownloadableResource;
 import com.atlassian.plugin.webresource.transformer.WebResourceTransformer;
+import com.atlassian.soy.renderer.SoyException;
 import com.google.template.soy.SoyFileSet;
 import com.google.template.soy.jssrc.SoyJsSrcOptions;
 import org.dom4j.Element;
         @Override
         protected CharSequence transform(CharSequence originalContent)
         {
-            SoyFileSet.Builder sfsBuilder = soyManager.makeBuilder(pluginKeys);
-            sfsBuilder.add(originalContent, location);
+            try
+            {
+                SoyFileSet.Builder sfsBuilder = soyManager.makeBuilder(pluginKeys);
+                sfsBuilder.add(originalContent, location);
 
-            SoyFileSet sfs = sfsBuilder.build();
+                SoyFileSet sfs = sfsBuilder.build();
 
-            final List<String> output = sfs.compileToJsSrc(jsSrcOptions, null);
-            if (output.size() != 1)
+                final List<String> output = sfs.compileToJsSrc(jsSrcOptions, null);
+                if (output.size() != 1)
+                {
+                    throw new IllegalStateException("Did not manage to compile soy template at:" + location + ", size=" + output.size());
+                }
+                return output.get(0);
+            }
+            catch (SoyException e)
             {
-                throw new IllegalStateException("Did not manage to compile soy template at:" + location + ", size=" + output.size());
+                throw new IllegalStateException("Failed to make builder for soy compiler", e);
             }
-            return output.get(0);
         }
     }
 }