/** {@inheritDoc} */ public void contribute(Map<String, Object> config, Gadget gadget) { // Add gadgets.util support. This is calculated dynamically based on request inputs. ModulePrefs prefs = gadget.getSpec().getModulePrefs(); Collection<Feature> features = prefs.getFeatures().values(); Map<String, Map<String, Object>> featureMap = Maps.newHashMapWithExpectedSize(features.size()); Set<String> allFeatureNames = registry.getAllFeatureNames(); for (Feature feature : features) { // Skip unregistered features if (!allFeatureNames.contains(feature.getName())) { continue; } // Flatten out the multimap a bit for backwards compatibility: map keys // with just 1 value into the string, treat others as arrays Map<String, Object> paramFeaturesInConfig = Maps.newHashMap(); for (String paramName : feature.getParams().keySet()) { Collection<String> paramValues = feature.getParams().get(paramName); if (paramValues.size() == 1) { paramFeaturesInConfig.put(paramName, paramValues.iterator().next()); } else { paramFeaturesInConfig.put(paramName, paramValues); } } featureMap.put(feature.getName(), paramFeaturesInConfig); } config.put("core.util", featureMap); }
@Inject public AllJsIframeVersioner(FeatureRegistry registry) { StringBuilder jsBuf = new StringBuilder(); for (FeatureResource resource : registry.getAllFeatures()) { jsBuf.append(resource.getContent()).append(resource.getDebugContent()); } allJsChecksum = HashUtil.checksum(jsBuf.toString().getBytes()); }
/** * Helper method retrieving feature resources, including transitive dependencies. * @param ctx Context for the request. * @param needed List of all needed features. * @param unsupported If non-null, a List populated with unknown features from the needed list. * @return List of FeatureResources that may be used to render the needed features. */ public LookupResult getFeatureResources(GadgetContext ctx, Collection<String> needed, List<String> unsupported) { return getFeatureResources(ctx, needed, unsupported, true); }
/** * * @param resourceLoader * @param featuresoo * @throws GadgetException */ @Inject public FeatureRegistry(FeatureResourceLoader resourceLoader, @Named("org.apache.shindig.features") List<String> features) throws GadgetException { this.parser = new FeatureParser(); this.resourceLoader = resourceLoader; featureMap = register(features); // Connect the dependency graph made up of all features and validate there // are no circular deps. connectDependencyGraph(); // Clear caches. cache.clear(); }
Uri uriLoc = getComponentUri(location); for (String resource : getResourceContent(location).split("[\r\n]+")) { resource = resource.trim(); if (resource.length () > 0 && resource.charAt(0) != '#') { resource = getComponentUri(resource.trim()).getPath(); resources.add(resource); loadResources(resources, featureMapBuilder); } else { loadFile(new File(uriLoc.getPath()), featureMapBuilder);
@SuppressWarnings("unchecked") private void setupMockRegistry(List<String> features) { EasyMock.expect(mockRegistry.getFeatures(EasyMock.isA(Collection.class))) .andReturn(Lists.newArrayList(features)).anyTimes(); FeatureBundle featureBundle = createMockFeatureBundle(); FeatureRegistry.LookupResult lr = createMockLookupResult(ImmutableList.of(featureBundle)); EasyMock.expect( mockRegistry.getFeatureResources(isA(GadgetContext.class), eq(Lists.newArrayList(features)), EasyMock.<List<String>> isNull())) .andReturn(lr).anyTimes(); replay(); }
private void expectFeatureCalls(Gadget gadget, List<FeatureResource> gadgetResources, Set<String> externLibs, List<FeatureResource> externResources) { reset(featureRegistry); GadgetContext gadgetContext = gadget.getContext(); List<String> gadgetFeatures = Lists.newArrayList(gadget.getDirectFeatureDeps()); List<String> allFeatures = Lists.newArrayList(gadgetFeatures); List<String> allFeaturesAndLibs = Lists.newArrayList(gadgetFeatures); allFeaturesAndLibs.addAll(externLibs); List<String> emptyList = Lists.newArrayList(); expect(featureRegistry.getFeatureResources(same(gadgetContext), eq(externLibs), eq(emptyList))) .andReturn(externResources); expect(featureRegistry.getFeatureResources(same(gadgetContext), eq(gadgetFeatures), eq(emptyList))) .andReturn(gadgetResources); expect(featureRegistry.getFeatures(eq(allFeatures))) .andReturn(allFeatures); expect(featureRegistry.getFeatures(eq(allFeaturesAndLibs))) .andReturn(allFeaturesAndLibs); // Add CoreUtilConfigContributor behavior expect(featureRegistry.getAllFeatureNames()). andReturn(ImmutableSet.of("foo", "foo2", "core.util")).anyTimes(); replay(featureRegistry); }
public synchronized List<String> getAllFeatures() { if (allGadgetFeatures == null) { Preconditions.checkState(featureRegistry != null, "setGadgetFeatureRegistry must be called before Gadget.getAllFeatures()"); allGadgetFeatures = featureRegistry.getFeatures(Lists.newArrayList(directFeatureDeps)); } return allGadgetFeatures; }
GadgetContext ctx, Collection<String> needed, List<String> unsupported, boolean transitive) { boolean useCache = (transitive && !ctx.getIgnoreCache()); String cacheKey = makeCacheKey(needed, ctx, unsupported); getTransitiveDeps(needed, unsupported) : getRequestedNodes(needed, unsupported); String containerAttrib = bundle.getAttribs().get("container"); if (containerAttrib != null) { if (containerMatch(containerAttrib, ctx.getContainer())) { bundlesBuilder.add(bundle); specificContainerMatched = true;
featureNodes = getTransitiveDeps(needed, unsupported); } else { featureNodes = getRequestedNodes(needed, unsupported); String containerAttrib = bundle.getAttribs().get("container"); if (containerAttrib != null) { if (containerMatch(containerAttrib, ctx.getContainer())) { resourcesBuilder.addAll(bundle.getResources()); specificContainerMatched = true;
Uri uriLoc = getComponentUri(location); if (resource.charAt(0) != '#') { resource = getComponentUri(resource).getPath(); resources.add(resource); loadResources(resources, featureMapBuilder); } else { MessageKeys.LOAD_FILES_FROM, new Object[] {location}); loadFile(fileSystem.getFile(uriLoc.getPath()), featureMapBuilder);
/** * Calculates and returns a dependency-ordered (as in getFeatureResources) list of features * included directly or transitively from the specified list of needed features. * This API ignores any unknown features among the needed list. * @param needed List of features for which to obtain an ordered dep list. * @return Ordered list of feature names, as described. */ public List<String> getFeatures(Collection<String> needed) { List<FeatureNode> fullTree = getTransitiveDeps(needed, Lists.<String>newLinkedList()); List<String> allFeatures = Lists.newLinkedList(); for (FeatureNode node : fullTree) { allFeatures.add(node.name); } return allFeatures; }
private List<FeatureNode> getTransitiveDeps(Collection<String> needed, List<String> unsupported) { final List<FeatureNode> requested = getRequestedNodes(needed, unsupported);
getResourceAttribs(parsedBundle.getAttribs(), parsedResource.getAttribs())));
if (src != null && src.length() > 0) { if (!"false".equals(attribs.get("inline"))) { source = parent.resolve(FeatureRegistry.getComponentUri(src)); } else { source = Uri.parse(src);
@SuppressWarnings("unchecked") private void setupMockRegistry(List<String> features) { EasyMock.expect(mockRegistry.getFeatures(EasyMock.isA(List.class))) .andReturn(Lists.newArrayList(features)).anyTimes(); FeatureBundle featureBundle = createMockFeatureBundle(); FeatureRegistry.LookupResult lr = createMockLookupResult(ImmutableList.of(featureBundle)); EasyMock.expect( mockRegistry.getFeatureResources(isA(GadgetContext.class), eq(Lists.newArrayList(features)), EasyMock.<List<String>> isNull())) .andReturn(lr).anyTimes(); replay(); }
expect(gadgetLr.getResources()).andReturn(gadgetResources); replay(gadgetLr); expect(featureRegistry.getFeatureResources(same(gadgetContext), eq(externLibs), eq(emptyList))) .andReturn(externLr); expect(featureRegistry.getFeatureResources(same(gadgetContext), eq(gadgetFeatures), eq(emptyList))).andReturn(gadgetLr); expect(featureRegistry.getFeatures(eq(allFeatures))) .andReturn(allFeatures).anyTimes(); expect(featureRegistry.getFeatures(eq(Sets.newHashSet(allFeaturesAndLibs)))) .andReturn(allFeaturesAndLibs); expect(featureRegistry.getFeatures(eq(ImmutableSet.of("*")))) .andReturn(ImmutableList.<String>of()).anyTimes(); expect(featureRegistry.getFeatures(eq(ImmutableSet.of("hello")))) .andReturn(ImmutableList.<String>of("hello")).anyTimes(); if(!allRequiredFeatures.equals(allFeatures)) { expect(featureRegistry.getFeatures(eq(allRequiredFeatures))) .andReturn(allRequiredFeatuesAndLibs).anyTimes(); expect(featureRegistry.getFeatures(eq(Sets.newHashSet(allRequiredFeatuesAndLibs)))) .andReturn(allRequiredFeatuesAndLibs).anyTimes(); expect(featureRegistry.getAllFeatureNames()). andReturn(ImmutableSet.of("foo", "foo2", "core.util")).anyTimes(); replay(featureRegistry);
public synchronized List<String> getAllFeatures() { if (allGadgetFeatures == null) { Preconditions.checkState(featureRegistry != null, "setGadgetFeatureRegistry must be called before Gadget.getAllFeatures()"); allGadgetFeatures = featureRegistry.getFeatures(Lists.newArrayList(directFeatureDeps)); } return allGadgetFeatures; }
Uri uriLoc = getComponentUri(location); for (String resource : getResourceContent(location).split("[\r\n]+")) { resource = resource.trim(); if (resource.length () > 0 && resource.charAt(0) != '#') { resource = getComponentUri(resource.trim()).getPath(); resources.add(resource); loadResources(resources, featureMapBuilder); } else { loadFile(new File(uriLoc.getPath()), featureMapBuilder);
featureNodes = getTransitiveDeps(needed, unsupported); } else { featureNodes = getRequestedNodes(needed, unsupported); String containerAttrib = bundle.getAttribs().get("container"); if (containerAttrib != null) { if (containerMatch(containerAttrib, ctx.getContainer())) { resourcesBuilder.addAll(bundle.getResources()); specificContainerMatched = true;