private JsContent newComment(FeatureBundle bundle, boolean start) { String tag = start ? "start" : "end"; return JsContent.fromFeature( "\n/* [" + tag + "] feature=" + bundle.getName() + " */\n", "[comment-marker-" + tag + ']', bundle, null); }
public Iterable<JsContent> getJsContent(JsUri jsUri, FeatureBundle bundle) { List<JsContent> jsContent = Lists.newLinkedList(); for (FeatureResource resource : bundle.getResources()) { String content = getFeatureContent(jsUri, resource); content = (content != null) ? content : ""; if (resource.isExternal()) { // Support external/type=url feature serving through document.write() jsContent.add(JsContent.fromFeature("document.write('<script src=\"" + content + "\"></script>')", "[external:" + content + ']', bundle, resource)); } else { jsContent.add(JsContent.fromFeature(content, resource.getName(), bundle, resource)); } jsContent.add(JsContent.fromFeature(";\n", "[separator]", bundle, resource)); } return jsContent; }
private boolean appendDeferJsStatements(ImmutableList.Builder<JsContent> builder, JsUri jsUri, FeatureBundle bundle) { List<String> exports = getExports(bundle, jsUri); if (!exports.isEmpty()) { StringBuilder sb = new StringBuilder(); for (Input input : generateInputs(exports)) { sb.append(toDeferStatement(input)); } builder.add(JsContent.fromFeature(sb.toString(), "[generated-symbol-exports]", bundle, null)); return true; } return false; }
private boolean appendExportJsStatements(ImmutableList.Builder<JsContent> builder, JsUri jsUri, FeatureBundle bundle) { List<String> exports = getExports(bundle, jsUri); if (!exports.isEmpty()) { StringBuilder sb = new StringBuilder(); for (Input input : generateInputs(exports)) { sb.append(toExportStatement(input)); } builder.add(JsContent.fromFeature(sb.toString(), "[generated-symbol-exports]", bundle, null)); return true; } return false; }
protected final List<JsContent> getSurfaceJsContents( FeatureRegistry featureRegistry, String featureName) { ImmutableList.Builder<JsContent> result = ImmutableList.builder(); LookupResult lookup = featureRegistry.getFeatureResources(context.get(), ImmutableList.of(featureName), null); for (FeatureBundle bundle : lookup.getBundles()) { for (FeatureResource resource : bundle.getResources()) { result.add(JsContent.fromFeature( resource.getDebugContent(), resource.getName(), bundle, resource)); } } return result.build(); }
private void setupForVersionAndProxy(boolean proxyCacheable, UriStatus uriStatus) { List<String> reqLibs = ImmutableList.of("feature"); List<String> loadLibs = EMPTY_STRING_LIST; FeatureResource resource1 = mockResource(proxyCacheable); FeatureResource resource2 = mockResource(proxyCacheable); FeatureBundle bundle = mockBundle("feature", null, null, Lists.newArrayList(resource1, resource2)); setupJsUriAndRegistry(uriStatus, reqLibs, Lists.newArrayList(bundle), loadLibs, EMPTY_BUNDLE_LIST); expect(compiler.getJsContent(jsUri, bundle)) .andReturn(ImmutableList.<JsContent>of( JsContent.fromFeature(JS_CODE1, "source1", bundle, resource1), JsContent.fromFeature(JS_CODE2, "source2", bundle, resource2))); }
private void setupForVersionAndProxy(boolean proxyCacheable, UriStatus uriStatus) { List<String> reqLibs = ImmutableList.of("feature"); List<String> loadLibs = EMPTY_STRING_LIST; FeatureResource resource1 = mockResource(proxyCacheable); FeatureResource resource2 = mockResource(proxyCacheable); FeatureBundle bundle = mockBundle("feature", null, null, Lists.newArrayList(resource1, resource2)); setupJsUriAndRegistry(uriStatus, reqLibs, Lists.newArrayList(bundle), loadLibs, EMPTY_BUNDLE_LIST); expect(compiler.getJsContent(jsUri, bundle)) .andReturn(ImmutableList.<JsContent>of( JsContent.fromFeature(JS_CODE1, "source1", bundle, resource1), JsContent.fromFeature(JS_CODE2, "source2", bundle, resource2))); }
@Before public void setUp() { control = createControl(); contents = Lists.newArrayList(); contents.add(JsContent.fromFeature(NORMAL_CONTENT_JS, SOURCE, null, null)); contents.add(JsContent.fromFeature(NORMAL_CONTENT_JS, SOURCE, null, mockFeatureResource(null))); contents.add(JsContent.fromFeature(NORMAL_CONTENT_JS, SOURCE, null, mockFeatureResource(ImmutableMap.of(UriCommon.Param.CAJOLE.getKey(), "blah")))); contents.add(JsContent.fromFeature(CAJA_CONTENT_JS, SOURCE, null, mockFeatureResource(ImmutableMap.of(UriCommon.Param.CAJOLE.getKey(), ATTRIB_VALUE)))); response = new JsResponse(contents, -1, -1, false, ERRORS, null); builder = new JsResponseBuilder(response); processor = new CajaJsSubtractingProcessor(); }
@Before public void setUp() { control = createControl(); contents = Lists.newArrayList(); contents.add(JsContent.fromFeature(NORMAL_CONTENT_JS, SOURCE, null, null)); contents.add(JsContent.fromFeature(NORMAL_CONTENT_JS, SOURCE, null, mockFeatureResource(null))); contents.add(JsContent.fromFeature(NORMAL_CONTENT_JS, SOURCE, null, mockFeatureResource(ImmutableMap.of(UriCommon.Param.CAJOLE.getKey(), "blah")))); contents.add(JsContent.fromFeature(CAJA_CONTENT_JS, SOURCE, null, mockFeatureResource(ImmutableMap.of(UriCommon.Param.CAJOLE.getKey(), ATTRIB_VALUE)))); response = new JsResponse(contents, -1, -1, false, ERRORS, null); builder = new JsResponseBuilder(response); processor = new CajaJsSubtractingProcessor(); }
@Test public void testPopulateWithLoadedFeatures() throws Exception { List<String> reqLibs = ImmutableList.of("feature1", "feature2"); List<String> loadLibs = ImmutableList.of("feature2"); FeatureResource resource1 = mockResource(true); FeatureBundle bundle1 = mockBundle("feature1", null, null, Lists.newArrayList(resource1)); FeatureBundle bundle2 = mockBundle("feature2", "export2", "extern2", null); setupJsUriAndRegistry(UriStatus.VALID_UNVERSIONED, reqLibs, ImmutableList.of(bundle1, bundle2), loadLibs, ImmutableList.of(bundle2)); expect(compiler.getJsContent(jsUri, bundle1)) .andReturn(ImmutableList.<JsContent>of( JsContent.fromFeature(JS_CODE1, "source1", null, null))); control.replay(); processor.process(request, response); checkResponse(true, GetJsContentProcessor.DEFAULT_UNVERSIONED_MAXAGE, JS_CODE1, "export2", "extern2"); control.verify(); }
@Test public void testPopulateWithLoadedFeatures() throws Exception { List<String> reqLibs = ImmutableList.of("feature1", "feature2"); List<String> loadLibs = ImmutableList.of("feature2"); FeatureResource resource1 = mockResource(true); FeatureBundle bundle1 = mockBundle("feature1", null, null, Lists.newArrayList(resource1)); FeatureBundle bundle2 = mockBundle("feature2", "export2", "extern2", null); setupJsUriAndRegistry(UriStatus.VALID_UNVERSIONED, reqLibs, ImmutableList.of(bundle1, bundle2), loadLibs, ImmutableList.of(bundle2)); expect(compiler.getJsContent(jsUri, bundle1)) .andReturn(ImmutableList.<JsContent>of( JsContent.fromFeature(JS_CODE1, "source1", null, null))); control.replay(); processor.process(request, response); checkResponse(true, GetJsContentProcessor.DEFAULT_UNVERSIONED_MAXAGE, JS_CODE1, "export2", "extern2"); control.verify(); }
@Before public void setUp() throws Exception { GadgetContext ctx = new GadgetContext(); Provider<GadgetContext> contextProviderMock = Providers.of(ctx); FeatureResource resource = mockResource(EXPORT_JS_DEB); FeatureRegistry.FeatureBundle bundle = mockExportJsBundle(resource); LookupResult lookupMock = mockLookupResult(bundle); final FeatureRegistry featureRegistryMock = mockRegistry(lookupMock); FeatureRegistryProvider registryProvider = new FeatureRegistryProvider() { public FeatureRegistry get(String repository) { return featureRegistryMock; } }; textJsContent1 = JsContent.fromText(TEXT_CONTENT_1, "source1"); textJsContent2 = JsContent.fromText(TEXT_CONTENT_2, "source2"); featureJsContent1 = JsContent.fromFeature(FEATURE_CONTENT_1, "source3", mockBundle(EXPORTS_1), null); featureJsContent2 = JsContent.fromFeature(FEATURE_CONTENT_2, "source4", mockBundle(EXPORTS_2), null); featureJsContent3 = JsContent.fromFeature(FEATURE_CONTENT_3, "source5", mockBundle(EXPORTS_3), null); processor = new ExportJsProcessor(registryProvider, contextProviderMock); }
@Before public void setUp() throws Exception { GadgetContext ctx = new GadgetContext(); Provider<GadgetContext> contextProviderMock = Providers.of(ctx); FeatureResource resource = mockResource(EXPORT_JS_DEB); FeatureRegistry.FeatureBundle bundle = mockExportJsBundle(resource); LookupResult lookupMock = mockLookupResult(bundle); final FeatureRegistry featureRegistryMock = mockRegistry(lookupMock); FeatureRegistryProvider registryProvider = new FeatureRegistryProvider() { public FeatureRegistry get(String repository) { return featureRegistryMock; } }; textJsContent1 = JsContent.fromText(TEXT_CONTENT_1, "source1"); textJsContent2 = JsContent.fromText(TEXT_CONTENT_2, "source2"); featureJsContent1 = JsContent.fromFeature(FEATURE_CONTENT_1, "source3", mockBundle(EXPORTS_1), null); featureJsContent2 = JsContent.fromFeature(FEATURE_CONTENT_2, "source4", mockBundle(EXPORTS_2), null); featureJsContent3 = JsContent.fromFeature(FEATURE_CONTENT_3, "source5", mockBundle(EXPORTS_3), null); processor = new ExportJsProcessor(registryProvider, contextProviderMock); }
@Test public void testNeighboringSameFeatures() throws Exception { FeatureBundle bundle = mockBundle("bundle"); JsContent js1 = JsContent.fromFeature("content1", "source1", bundle, null); JsContent js2 = JsContent.fromFeature("content2", "source2", bundle, null); JsResponseBuilder builder = newBuilder(js1, js2); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle */\n" + "content1" + "content2" + "\n/* [end] feature=bundle */\n", actualResponse.toJsString()); }
@Test public void testNeighboringSameFeatures() throws Exception { FeatureBundle bundle = mockBundle("bundle"); JsContent js1 = JsContent.fromFeature("content1", "source1", bundle, null); JsContent js2 = JsContent.fromFeature("content2", "source2", bundle, null); JsResponseBuilder builder = newBuilder(js1, js2); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle */\n" + "content1" + "content2" + "\n/* [end] feature=bundle */\n", actualResponse.toJsString()); }
@Test public void testMultipleFeaturesWithoutInBetweenTexts() throws Exception { JsContent js1 = JsContent.fromFeature("content1", "source1", mockBundle("bundle1"), null); JsContent js2 = JsContent.fromFeature("content2", "source2", mockBundle("bundle2"), null); JsResponseBuilder builder = newBuilder(js1, js2); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle1 */\n" + "content1" + "\n/* [end] feature=bundle1 */\n" + "\n/* [start] feature=bundle2 */\n" + "content2" + "\n/* [end] feature=bundle2 */\n", actualResponse.toJsString()); }
@Test public void testMultipleFeaturesWithoutInBetweenTexts() throws Exception { JsContent js1 = JsContent.fromFeature("content1", "source1", mockBundle("bundle1"), null); JsContent js2 = JsContent.fromFeature("content2", "source2", mockBundle("bundle2"), null); JsResponseBuilder builder = newBuilder(js1, js2); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle1 */\n" + "content1" + "\n/* [end] feature=bundle1 */\n" + "\n/* [start] feature=bundle2 */\n" + "content2" + "\n/* [end] feature=bundle2 */\n", actualResponse.toJsString()); }
@Test public void testMultipleFeaturesWithInBetweenTexts() throws Exception { JsContent text1 = JsContent.fromText("text1", "source1"); JsContent text2 = JsContent.fromText("text2", "source2"); JsContent text3 = JsContent.fromText("text3", "source3"); JsContent js1 = JsContent.fromFeature("content1", "source4", mockBundle("bundle1"), null); JsContent js2 = JsContent.fromFeature("content2", "source5", mockBundle("bundle2"), null); JsResponseBuilder builder = newBuilder(text1, js1, text2, js2, text3); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "text1" + "\n/* [start] feature=bundle1 */\n" + "content1" + "\n/* [end] feature=bundle1 */\n" + "text2" + "\n/* [start] feature=bundle2 */\n" + "content2" + "\n/* [end] feature=bundle2 */\n" + "text3", actualResponse.toJsString()); }
@Test public void testOneFeature() throws Exception { JsContent js = JsContent.fromFeature("content", "source", mockBundle("bundle"), null); JsResponseBuilder builder = newBuilder(js); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle */\n" + "content" + "\n/* [end] feature=bundle */\n", actualResponse.toJsString()); }
@Test public void testOneFeature() throws Exception { JsContent js = JsContent.fromFeature("content", "source", mockBundle("bundle"), null); JsResponseBuilder builder = newBuilder(js); control.replay(); boolean actualReturn = processor.process(null, builder); JsResponse actualResponse = builder.build(); control.verify(); assertTrue(actualReturn); assertEquals( "\n/* [start] feature=bundle */\n" + "content" + "\n/* [end] feature=bundle */\n", actualResponse.toJsString()); }