List<FeatureBundle> noContainerBundles = Lists.newLinkedList(); for (FeatureBundle bundle : entry.getBundles()) { if (bundle.getType().equals(targetBundleType)) { String containerAttrib = bundle.getAttribs().get("container"); if (containerAttrib != null) { if (containerMatch(containerAttrib, ctx.getContainer())) { resourcesBuilder.addAll(bundle.getResources()); specificContainerMatched = true; resourcesBuilder.addAll(bundle.getResources());
public Iterable<JsContent> getJsContent(JsUri jsUri, FeatureBundle bundle) { jsUri = new JsUri(jsUri) { @Override public boolean isDebug() { // Force debug JS in the raw JS content retrieved. return true; } }; List<JsContent> builder = Lists.newLinkedList(defaultCompiler.getJsContent(jsUri, bundle)); CompilerOptions options = getCompilerOptions(jsUri); if (options.isExternExportsEnabled()) { List<String> exports = Lists.newArrayList(bundle.getApis(ApiDirective.Type.JS, true)); Collections.sort(exports); String prevExport = null; for (String export : exports) { if (!export.equals(prevExport)) { builder.add(JsContent.fromText( "goog.exportSymbol('" + StringEscapeUtils.escapeEcmaScript(export) + "', " + export + ");\n", "[export-symbol]")); prevExport = export; } } } return builder; }
private FeatureBundle mockBundle(String name, String export, String extern, List<FeatureResource> resources) { FeatureBundle result = control.createMock(FeatureBundle.class); expect(result.getName()).andReturn(name).anyTimes(); if (export != null) { expect(result.getApis(ApiDirective.Type.JS, true)).andReturn(ImmutableList.of(export)); } if (extern != null) { expect(result.getApis(ApiDirective.Type.JS, false)).andReturn(ImmutableList.of(extern)); } if (resources != null) { expect(result.getResources()).andReturn(resources); } return result; }
List<FeatureBundle> noContainerBundles = Lists.newLinkedList(); for (FeatureBundle bundle : entry.getBundles()) { if (bundle.getType().equals(targetBundleType)) { String containerAttrib = bundle.getAttribs().get("container"); if (containerAttrib != null) { if (containerMatch(containerAttrib, ctx.getContainer())) { resourcesBuilder.addAll(bundle.getResources()); specificContainerMatched = true; resourcesBuilder.addAll(bundle.getResources());
List<FeatureBundle> noContainerBundles = Lists.newLinkedList(); for (FeatureBundle bundle : entry.getBundles(ctx.getRenderingContext())) { String containerAttrib = bundle.getAttribs().get("container"); if (containerAttrib != null) { if (containerMatch(containerAttrib, ctx.getContainer())) {
String directTag = rctx.getFeatureBundleTag(); for (FeatureBundle bundle : bundles) { if (directTag != null && directTag.equalsIgnoreCase(bundle.getType())) { tagMatch = directTag;
bundles.add(new FeatureBundle(parsedBundle, resources));
loadedFeatures.add(bundle.getName()); builder.appendExterns(bundle.getApis(ApiDirective.Type.JS, true)); builder.appendExterns(bundle.getApis(ApiDirective.Type.JS, false)); if (loadedFeatures.contains(bundle.getName())) { continue; for (FeatureResource featureResource : bundle.getResources()) { isProxyCacheable = isProxyCacheable && featureResource.isProxyCacheable();
bundles.add(new FeatureBundle(parsedBundle.getType(), parsedBundle.getAttribs(), resources));
bundles.add(new FeatureBundle(parsedBundle.getType(), parsedBundle.getAttribs(), resources));
/** * Gets the set of allowed RPC service ids. * * @param gadget * the gadget to get the service ids for. * @return the set of allowed RPC service ids. */ private Set<String> getRpcServiceIds(Gadget gadget) { GadgetContext context = gadget.getContext(); Set<String> rpcEndpoints = Sets.newHashSet(gadgetAdminStore.getAdditionalRpcServiceIds(gadget)); List<Feature> modulePrefFeatures = gadget.getSpec().getModulePrefs().getAllFeatures(); List<String> featureNames = Lists.newArrayList(); for(Feature feature : modulePrefFeatures) { if(gadgetAdminStore.isAllowedFeature(feature, gadget)) { featureNames.add(feature.getName()); } } try { FeatureRegistry featureRegistry = featureRegistryProvider.get(context.getRepository()); LookupResult result = featureRegistry.getFeatureResources(context, featureRegistry.getFeatures(featureNames), null); List<FeatureBundle> bundles = result.getBundles(); for (FeatureBundle bundle : bundles) { rpcEndpoints.addAll(bundle.getApis(ApiDirective.Type.RPC, false)); } } catch (GadgetException e) { LOG.log(Level.WARNING, "Error getting features from feature registry", e); } return rpcEndpoints; }
/** * Compile content in the inbound JsResponseBuilder. * TODO: Convert JsCompiler to take JsResponseBuilder directly rather than Iterable<JsContent> * @throws JsException */ public boolean process(JsRequest request, JsResponseBuilder builder) throws JsException { Iterable<JsContent> jsContents = builder.build().getAllJsContent(); for (JsContent jsc : jsContents) { FeatureBundle bundle = jsc.getFeatureBundle(); if (bundle != null) { builder.appendExterns(bundle.getApis(ApiDirective.Type.JS, true)); } } JsResponse result = compiler.compile(request.getJsUri(), jsContents, builder.build().getExterns()); builder.clearJs().appendAllJs(result.getAllJsContent()); builder.setStatusCode(result.getStatusCode()); builder.addErrors(result.getErrors()); int refresh = result.getCacheTtlSecs(); if (refresh > 0) { // Allow ttl overwrite by compiler builder.setCacheTtlSecs(refresh); } return true; }
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; }
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 FeatureBundle mockBundle(String name, String export, String extern, List<FeatureResource> resources) { FeatureBundle result = control.createMock(FeatureBundle.class); expect(result.getName()).andReturn(name).anyTimes(); if (export != null) { expect(result.getApis(ApiDirective.Type.JS, true)).andReturn(ImmutableList.of(export)); } if (extern != null) { expect(result.getApis(ApiDirective.Type.JS, false)).andReturn(ImmutableList.of(extern)); } if (resources != null) { expect(result.getResources()).andReturn(resources); } return result; }
private FeatureBundle createMockFeatureBundle() { FeatureBundle result = createMock(FeatureBundle.class); expect(result.getApis(ApiDirective.Type.RPC, false)).andReturn( Lists.newArrayList(RPC_SERVICE_1, RPC_SERVICE_2)).anyTimes(); replay(result); return result; }
private FeatureBundle mockBundle(String... externs) { FeatureBundle result = createMock(FeatureBundle.class); expect(result.getApis(ApiDirective.Type.JS, true)).andReturn( Lists.newArrayList(externs)).anyTimes(); replay(result); return result; } }
private FeatureBundle mockBundle(String name) { FeatureBundle result = control.createMock(FeatureBundle.class); expect(result.getName()).andReturn(name).anyTimes(); return result; }
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); }
private List<FeatureBundle> getSupportDeferBundles(FeatureRegistry registry, JsRequest jsRequest) { List<FeatureBundle> result = Lists.newArrayList(); LookupResult lookup = registry.getFeatureResources(context.get(), jsRequest.getNewFeatures(), null, false); for (FeatureBundle bundle : lookup.getBundles()) { if (bundle.isSupportDefer()) { result.add(bundle); } } return result; } }