shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1146884 - in /shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/js/ExportJsProcessor.java test/java/org/apache/shindig/gadgets/js/ExportJsProcessorTest.java
Date Thu, 14 Jul 2011 20:28:30 GMT
Author: johnh
Date: Thu Jul 14 20:28:29 2011
New Revision: 1146884

URL: http://svn.apache.org/viewvc?rev=1146884&view=rev
Log:
Only emit deferred symbols for features that support it.


Modified:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ExportJsProcessor.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ExportJsProcessorTest.java

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ExportJsProcessor.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ExportJsProcessor.java?rev=1146884&r1=1146883&r2=1146884&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ExportJsProcessor.java
(original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ExportJsProcessor.java
Thu Jul 14 20:28:29 2011
@@ -64,7 +64,7 @@ public class ExportJsProcessor implement
     this.deferredMode = defer;
   }
   
-  public ExportJsProcessor getDeferredInstance() {
+  public JsProcessor getDeferredInstance() {
     return new ExportJsProcessor(featureRegistryProvider, context, true);
   }
 
@@ -140,7 +140,9 @@ public class ExportJsProcessor implement
     
     boolean neededExports = false;
     for (FeatureBundle bundle : lookup.getBundles()) {
-      neededExports |= appendExportJsStatementsForFeature(builder, jsRequest.getJsUri(),
bundle);
+      if (bundle.isSupportDefer()) {
+        neededExports |= appendExportJsStatementsForFeature(builder, jsRequest.getJsUri(),
bundle);
+      }
     }
     
     return neededExports;

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ExportJsProcessorTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ExportJsProcessorTest.java?rev=1146884&r1=1146883&r2=1146884&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ExportJsProcessorTest.java
(original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ExportJsProcessorTest.java
Thu Jul 14 20:28:29 2011
@@ -83,7 +83,8 @@ public class ExportJsProcessorTest {
 
   private final String EXPORT_STRING_3 = "";
   
-  private final List<String> LIBS = Lists.newArrayList("lib1");
+  private final List<String> LIBS_DEFER = Lists.newArrayList("lib1");
+  private final List<String> LIBS = Lists.newArrayList("lib2");
   private final List<String> LOADED = Lists.newArrayList();
 
   private JsContent textJsContent1;
@@ -124,9 +125,13 @@ public class ExportJsProcessorTest {
         isA(GadgetContext.class), isA(List.class), EasyMock.isNull(List.class))).
         andReturn(lookupMock).anyTimes();
     expect(result.getFeatureResources(
+        isA(GadgetContext.class), eq(LIBS_DEFER), EasyMock.isNull(List.class), eq(false))).
+        andReturn(mockLookupResult(mockBundle(EXPORTS_1, true))).anyTimes();
+    expect(result.getFeatureResources(
         isA(GadgetContext.class), eq(LIBS), EasyMock.isNull(List.class), eq(false))).
-        andReturn(mockLookupResult(mockBundle(EXPORTS_1))).anyTimes();
+        andReturn(mockLookupResult(mockBundle(EXPORTS_2))).anyTimes();
     expect(result.getFeatures(LIBS)).andReturn(LIBS).anyTimes();
+    expect(result.getFeatures(LIBS_DEFER)).andReturn(LIBS_DEFER).anyTimes();
     expect(result.getFeatures(LOADED)).andReturn(LOADED).anyTimes();
     replay(result);
     return result;
@@ -137,11 +142,15 @@ public class ExportJsProcessorTest {
   }
   
   private JsUri mockJsUri(JsCompileMode mode, boolean isJsload) {
+    return mockJsUri(mode, isJsload, LIBS);
+  }
+  
+  private JsUri mockJsUri(JsCompileMode mode, boolean isJsload, List<String> libs)
{
     JsUri result = createMock(JsUri.class);
     expect(result.getCompileMode()).andStubReturn(mode);
     expect(result.getRepository()).andStubReturn(null);
     expect(result.isJsload()).andReturn(isJsload).anyTimes();
-    expect(result.getLibs()).andReturn(LIBS).anyTimes();
+    expect(result.getLibs()).andReturn(libs).anyTimes();
     expect(result.getLoadedLibs()).andReturn(LOADED).anyTimes();
     replay(result);
     return result;
@@ -163,11 +172,15 @@ public class ExportJsProcessorTest {
   }
 
   private FeatureBundle mockBundle(List<String> exports) {
+    return mockBundle(exports, false);
+  }
+  
+  private FeatureBundle mockBundle(List<String> exports, boolean isDefer) {
     List<ApiDirective> apis = Lists.newArrayList();
     for (String e : exports) apis.add(mockApiDirective(true, e));
     FeatureBundle result = createMock(FeatureBundle.class);
     expect(result.getApis(ApiDirective.Type.JS, true)).andReturn(exports).anyTimes();
-    expect(result.isSupportDefer()).andReturn(false).anyTimes();
+    expect(result.isSupportDefer()).andReturn(isDefer).anyTimes();
     replay(result);
     return result;
   }
@@ -227,7 +240,7 @@ public class ExportJsProcessorTest {
   
   @Test
   public void testProcessWithOneNonEmptyFeatureDeferred() throws Exception {
-    JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL, true);
+    JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL, true, LIBS_DEFER);
     JsRequest jsRequest = new JsRequest(jsUri, null, false, featureRegistry);
     JsResponseBuilder jsBuilder = new JsResponseBuilder();
     boolean actualReturnCode = compiler.getDeferredInstance().process(jsRequest, jsBuilder);
@@ -238,6 +251,18 @@ public class ExportJsProcessorTest {
   }
   
   @Test
+  public void testProcessWithOneNonEmptyFeatureDeferredNotSupported() throws Exception {
+    JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL, true, LIBS); // !deferred
+    JsRequest jsRequest = new JsRequest(jsUri, null, false, featureRegistry);
+    JsResponseBuilder jsBuilder = new JsResponseBuilder();
+    boolean actualReturnCode = compiler.getDeferredInstance().process(jsRequest, jsBuilder);
+    assertTrue(actualReturnCode);
+    assertEquals(
+        "",
+        jsBuilder.build().toJsString());
+  }
+  
+  @Test
   public void testProcessWithOneNonEmptyFeatureNotDeferredMode() throws Exception {
     JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL, true);
     JsRequest jsRequest = new JsRequest(jsUri, null, false, featureRegistry);



Mime
View raw message