Commits

Richard Atkins committed 81545f0

SOY-29 Handle UncheckedExecutionExceptions, and prevent them from leaking again via a unit test

Comments (0)

Files changed (4)

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

 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
-import com.google.common.collect.ComputationException;
 import com.google.common.io.Closeables;
+import com.google.common.util.concurrent.UncheckedExecutionException;
 import com.google.inject.Injector;
 import com.google.template.soy.SoyFileSet;
 import com.google.template.soy.base.SoySyntaxException;
                     .setIjData(soyDataConverter.convertToSoyMapData(injectedData))
                     .render(appendable);
         }
-        catch (ComputationException e)
+        catch (UncheckedExecutionException e)
         {
             throw new SoyException("Unable to compile Soy template in plugin module: " + completeModuleKey, e.getCause());
         }

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

 public interface SoyManager
 {
     /**
-     * Make a SoyFileSet builder, loading soy functions and templates from the provided modules. Modules may be
-     * soy-resource modules (loading functions and templates directly) or web-resource modules (loading any
-     * functions or templates referenced by one of the modules dependencies)
+     * Make a SoyFileSet builder, loading soy functions and templates from the pre-configured modules. Modules may be
+     * soy-function modules (loading functions directly) or web-resource modules (loading any
+     * functions or templates referenced by one of the modules dependencies). Also supported, but deprecated, are
+     * soy-resource modules (loading functions and templates directly).
      *
      * @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
      */
     public SoyFileSet.Builder makeSoyFileSetBuilder();
 

soy-template-plugin/src/test/java/com/atlassian/soy/impl/DefaultSoyManagerTest.java

+package com.atlassian.soy.impl;
+
+import com.atlassian.plugin.PluginAccessor;
+import com.atlassian.plugin.event.PluginEventManager;
+import com.atlassian.plugin.servlet.ServletContextFactory;
+import com.atlassian.soy.impl.data.SoyDataConverter;
+import com.atlassian.soy.impl.modules.GuiceModuleSupplier;
+import com.atlassian.soy.renderer.SoyException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.io.StringWriter;
+import java.util.Collections;
+
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DefaultSoyManagerTest
+{
+    @Rule public ExpectedException expectedException = ExpectedException.none();
+    @Mock PluginAccessor pluginAccessor;
+    @Mock PluginEventManager pluginEventManager;
+    @Mock ServletContextFactory servletContextFactory;
+    @Mock GuiceModuleSupplier moduleSupplier;
+    @Mock SoyDataConverter soyDataConverter;
+
+    // SOY-16 SOY-29 Failing to handle disabled modules meant we threw whatever unchecked exception guice wanted to
+    @Test
+    public void disabledModuleKeyTriggersSoyException() throws SoyException
+    {
+        when(pluginAccessor.getEnabledPluginModule("enabledPlugin:disabledModule")).thenReturn(null);
+        SoyManager manager = new DefaultSoyManager(pluginAccessor, pluginEventManager, servletContextFactory, moduleSupplier, soyDataConverter);
+        StringWriter writer = new StringWriter();
+
+        expectedException.expect(SoyException.class);
+        manager.render(writer, "enabledPlugin:disabledModule", "myTemplate", Collections.<String, Object>emptyMap(), Collections.<String, Object>emptyMap());
+    }
+}

soy-template-renderer-api/src/main/java/com/atlassian/soy/renderer/SoyResourceModuleDescriptor.java

 import java.util.List;
 
 /**
- * @deprecated use web-resource and soy-function modules instead.
+ * @deprecated since 2.0. Use web-resource and soy-function modules instead.
  */
 @Deprecated
 public class SoyResourceModuleDescriptor extends WebResourceModuleDescriptor