List of usage examples for com.google.common.collect ImmutableSet stream
default Stream<E> stream()
From source file:com.facebook.buck.features.js.JsBundleDescription.java
@Override public BuildRule createBuildRule(BuildRuleCreationContextWithTargetGraph context, BuildTarget buildTarget, BuildRuleParams params, JsBundleDescriptionArg args) { ActionGraphBuilder graphBuilder = context.getActionGraphBuilder(); ProjectFilesystem projectFilesystem = context.getProjectFilesystem(); ImmutableSortedSet<Flavor> flavors = buildTarget.getFlavors(); SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder); // Source maps are exposed individually using a special flavor if (flavors.contains(JsFlavors.SOURCE_MAP)) { BuildTarget bundleTarget = buildTarget.withoutFlavors(JsFlavors.SOURCE_MAP); graphBuilder.requireRule(bundleTarget); JsBundleOutputs bundleOutputs = graphBuilder.getRuleWithType(bundleTarget, JsBundleOutputs.class); return new ExportFile(buildTarget, projectFilesystem, ruleFinder, bundleOutputs.getBundleName() + ".map", ExportFileDescription.Mode.REFERENCE, bundleOutputs.getSourcePathToSourceMap(), ExportFileDirectoryAction.FAIL); }/*www. j a va 2s . c o m*/ if (flavors.contains(JsFlavors.MISC)) { BuildTarget bundleTarget = buildTarget.withoutFlavors(JsFlavors.MISC); graphBuilder.requireRule(bundleTarget); JsBundleOutputs bundleOutputs = graphBuilder.getRuleWithType(bundleTarget, JsBundleOutputs.class); return new ExportFile(buildTarget, projectFilesystem, ruleFinder, bundleOutputs.getBundleName() + "-misc", ExportFileDescription.Mode.REFERENCE, bundleOutputs.getSourcePathToMisc(), // TODO(27131551): temporary allow directory export until a proper fix is implemented ExportFileDirectoryAction.ALLOW); } // For Android, we bundle JS output as assets, and images etc. as resources. // To facilitate this, we return a build rule that in turn depends on a `JsBundle` and // an `AndroidResource`. The `AndroidResource` rule also depends on the `JsBundle` // if the `FORCE_JS_BUNDLE` flavor is present, we create the `JsBundle` instance itself. if (flavors.contains(JsFlavors.ANDROID) && !flavors.contains(JsFlavors.FORCE_JS_BUNDLE) && !flavors.contains(JsFlavors.DEPENDENCY_FILE)) { return createAndroidRule(toolchainProvider, buildTarget, projectFilesystem, graphBuilder, ruleFinder, args.getAndroidPackage()); } Either<ImmutableSet<String>, String> entryPoint = args.getEntry(); TransitiveLibraryDependencies libsResolver = new TransitiveLibraryDependencies(buildTarget, context.getTargetGraph(), graphBuilder, ruleFinder); ImmutableSet<JsLibrary> flavoredLibraryDeps = libsResolver.collect(args.getDeps()); Stream<BuildRule> generatedDeps = findGeneratedSources(ruleFinder, flavoredLibraryDeps.stream()) .map(graphBuilder::requireRule); // Flavors are propagated from js_bundle targets to their js_library dependencies // for that reason, dependencies of libraries are handled manually, and as a first step, // all dependencies to libraries are replaced with dependencies to flavored library targets. BuildRuleParams paramsWithFlavoredLibraries = params.withoutDeclaredDeps() .copyAppendingExtraDeps(Stream.concat(flavoredLibraryDeps.stream(), generatedDeps)::iterator); ImmutableSortedSet<SourcePath> libraries = flavoredLibraryDeps.stream() .map(JsLibrary::getSourcePathToOutput) .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())); ImmutableSet<String> entryPoints = entryPoint.isLeft() ? entryPoint.getLeft() : ImmutableSet.of(entryPoint.getRight()); Optional<Arg> extraJson = JsUtil.getExtraJson(args, buildTarget, graphBuilder, context.getCellPathResolver()); // If {@link JsFlavors.DEPENDENCY_FILE} is specified, the worker will output a file containing // all dependencies between files that go into the final bundle if (flavors.contains(JsFlavors.DEPENDENCY_FILE)) { return new JsDependenciesFile(buildTarget, projectFilesystem, paramsWithFlavoredLibraries, libraries, entryPoints, extraJson, graphBuilder.getRuleWithType(args.getWorker(), WorkerTool.class)); } String bundleName = args.computeBundleName(buildTarget.getFlavors(), () -> args.getName() + ".js"); return new JsBundle(buildTarget, projectFilesystem, paramsWithFlavoredLibraries, libraries, entryPoints, extraJson, bundleName, graphBuilder.getRuleWithType(args.getWorker(), WorkerTool.class)); }
From source file:com.facebook.buck.features.project.intellij.TransitiveDepsClosureResolver.java
/** * @param buildTarget target to process. * @return the set of {@link BuildTarget}s that must be appended to the dependencies of a node Y * if node Y depends on X./*w w w .j a va 2s . c om*/ */ public ImmutableSet<BuildTarget> getTransitiveDepsClosure(BuildTarget buildTarget) { if (index.containsKey(buildTarget)) { return index.get(buildTarget); } ImmutableSet<BuildTarget> exportedDeps = ImmutableSet.of(); TargetNode<?> targetNode = targetGraph.get(buildTarget); if (targetNode.getConstructorArg() instanceof JavaLibraryDescription.CoreArg) { JavaLibraryDescription.CoreArg arg = (JavaLibraryDescription.CoreArg) targetNode.getConstructorArg(); exportedDeps = arg.getExportedDeps(); } ImmutableSet<BuildTarget> transitiveDepsClosure = Stream .concat(exportedDeps.stream(), targetNode.getBuildDeps().stream()).filter(target -> { CommonDescriptionArg arg = (CommonDescriptionArg) targetGraph.get(target).getConstructorArg(); return !arg.labelsContainsAnyOf(ignoredTargetLabels); }).sorted() .flatMap(target -> Stream.concat(getTransitiveDepsClosure(target).stream(), Stream.of(target))) .collect(ImmutableSet.toImmutableSet()); index.put(buildTarget, transitiveDepsClosure); return transitiveDepsClosure; }
From source file:com.facebook.buck.ide.intellij.TransitiveDepsClosureResolver.java
/** * @param buildTarget target to process. * @return the set of {@link BuildTarget}s that must be appended to the dependencies of a node Y * if node Y depends on X.//from www. j a v a2 s. c o m */ public ImmutableSet<BuildTarget> getTransitiveDepsClosure(BuildTarget buildTarget) { if (index.containsKey(buildTarget)) { return index.get(buildTarget); } ImmutableSet<BuildTarget> exportedDeps = ImmutableSet.of(); TargetNode<?, ?> targetNode = targetGraph.get(buildTarget); if (targetNode.getConstructorArg() instanceof JavaLibraryDescription.CoreArg) { JavaLibraryDescription.CoreArg arg = (JavaLibraryDescription.CoreArg) targetNode.getConstructorArg(); exportedDeps = arg.getExportedDeps(); } ImmutableSet<BuildTarget> transitiveDepsClosure = Stream .concat(exportedDeps.stream(), targetNode.getBuildDeps().stream()).filter(target -> { CommonDescriptionArg arg = (CommonDescriptionArg) targetGraph.get(target).getConstructorArg(); return !arg.labelsContainsAnyOf(ignoredTargetLabels); }).flatMap(target -> Stream.concat(Stream.of(target), getTransitiveDepsClosure(target).stream())) .collect(MoreCollectors.toImmutableSet()); index.put(buildTarget, transitiveDepsClosure); return transitiveDepsClosure; }
From source file:com.facebook.buck.features.project.intellij.IjProjectTemplateDataPreparer.java
public ImmutableSet<Path> createFilesystemTraversalBoundaryPathSet(ImmutableSet<IjModule> modules) { return Stream.concat(modules.stream().map(IjModule::getModuleBasePath), Stream.of(projectPaths.getIdeaConfigDir())).collect(ImmutableSet.toImmutableSet()); }
From source file:com.zuppelli.living.docs.DiagramMojo.java
public void generateDiagram() throws Exception { final ClassPath classPath = ClassPath.from(getClassLoader(this.getProject())); final String prefix = getPrefix(); final ImmutableSet<ClassPath.ClassInfo> allClasses = classPath.getTopLevelClassesRecursive(prefix); final DotGraph.Digraph digraph = graph.getDigraph(); digraph.setOptions("rankdir=LR"); Stream<ClassPath.ClassInfo> pkFilter = allClasses.stream().filter(new PackageInfoPedicate()); pkFilter.forEach(new Consumer<ClassPath.ClassInfo>() { public void accept(ClassPath.ClassInfo ci) { Class clazz = ci.load(); Annotation annotation = clazz.getAnnotation(DomainContext.class); if (null != annotation) { packages.put(clazz.getPackage().getName(), ((DomainContext) annotation).name()); }/* w ww .ja v a 2 s. co m*/ } }); Stream<ClassPath.ClassInfo> domain = allClasses.stream().filter(filter(prefix, "domain")); // Todo create cluster from bounded context final DotGraph.Cluster core = digraph.addCluster("hexagon"); // Todo retireve label from bounded context core.setLabel("Core Domain"); // add all domain model elements first domain.forEach(new Consumer<ClassPath.ClassInfo>() { public void accept(ClassPath.ClassInfo ci) { final Class clazz = ci.load(); core.addNode(clazz.getName()).setLabel(clazz.getSimpleName()).setComment(clazz.getSimpleName()); } }); Stream<ClassPath.ClassInfo> infra = allClasses.stream().filter(filterNot(prefix, "domain")); infra.forEach(new Consumer<ClassPath.ClassInfo>() { public void accept(ClassPath.ClassInfo ci) { final Class clazz = ci.load(); digraph.addNode(clazz.getName()).setLabel(clazz.getSimpleName()).setComment(clazz.getSimpleName()); } }); infra = allClasses.stream().filter(filterNot(prefix, "domain")); infra.forEach(new Consumer<ClassPath.ClassInfo>() { public void accept(ClassPath.ClassInfo ci) { final Class clazz = ci.load(); // API for (Field field : clazz.getDeclaredFields()) { final Class<?> type = field.getType(); if (!type.isPrimitive()) { digraph.addExistingAssociation(clazz.getName(), type.getName(), null, null, DotStyles.ASSOCIATION_EDGE_STYLE); } } // SPI for (Class intf : clazz.getInterfaces()) { digraph.addExistingAssociation(intf.getName(), clazz.getName(), null, null, DotStyles.IMPLEMENTS_EDGE_STYLE); } } }); // then wire them together domain = allClasses.stream().filter(filter(prefix, "domain")); domain.forEach(new Consumer<ClassPath.ClassInfo>() { public void accept(ClassPath.ClassInfo ci) { final Class clazz = ci.load(); for (Field field : clazz.getDeclaredFields()) { final Class<?> type = field.getType(); if (!type.isPrimitive()) { digraph.addExistingAssociation(clazz.getName(), type.getName(), null, null, DotStyles.ASSOCIATION_EDGE_STYLE); } } for (Class intf : clazz.getInterfaces()) { digraph.addExistingAssociation(intf.getName(), clazz.getName(), null, null, DotStyles.IMPLEMENTS_EDGE_STYLE); } } }); String title = "Living Diagram"; final String content = graph.render().trim(); this.content.put("content", graph.render().trim()); this.content.put("title", title); Template template = initializeFreeMarker(); Writer writer = new PrintWriter("diagrama.html"); try { template.process(this.content, writer); } finally { writer.close(); } }
From source file:io.github.katrix_.chitchat.io.ConfigSettings.java
private void updateOldData() { try {/*from w ww . ja va 2 s . co m*/ TypeToken<TextTemplate> textTemplateToken = TypeToken.of(TextTemplate.class); ImmutableSet<String> oldArgs = ImmutableSet.of(TEMPLATE_MESSAGE, TEMPLATE_MESSAGE, "playerName"); Predicate<TextTemplate> messagePredicate = t -> { Set<String> argSet = t.getArguments().keySet(); return oldArgs.stream().anyMatch(argSet::contains); }; //playerName and message updateOldObject(cfgRoot.getNode("command", "meTemplate"), textTemplateToken, messagePredicate, meTemplate); updateOldObject(cfgRoot.getNode("command", "pmReciever"), textTemplateToken, messagePredicate, pmReciever); updateOldObject(cfgRoot.getNode("command", "pmSender"), textTemplateToken, messagePredicate, pmSender); updateOldObject(cfgRoot.getNode("command", "shoutTemplate"), textTemplateToken, messagePredicate, shoutTemplate); updateOldObject(cfgRoot.getNode("command", "announceTemplate"), textTemplateToken, messagePredicate, announceTemplate); //suffix updateOldObject(cfgRoot.getNode("chat", "suffixTemplate"), textTemplateToken, t -> t.getArguments().containsKey("suffix"), suffixTemplate); //prefix updateOldObject(cfgRoot.getNode("chat", "headerTemplate"), textTemplateToken, t -> t.getArguments().containsKey("prefix"), headerTemplate); updateOldObject(cfgRoot.getNode("chat", "channelTemplate"), textTemplateToken, t -> t.getArguments().containsKey("prefix"), channelTemplate); //channel updateOldObject(cfgRoot.getNode("chat", "chattingJoinTemplate"), textTemplateToken, t -> t.getArguments().containsKey("channel"), chattingJoinTemplate); //Remove old defaultHeader, there is now defaultPrefix instead cfgRoot.getNode("chat", "defaultHeader").setValue(null); } catch (ObjectMappingException e) { e.printStackTrace(); } }
From source file:com.facebook.buck.rules.modern.builders.RemoteExecutionStrategy.java
RemoteExecutionStrategy(BuckEventBus eventBus, RemoteExecutionStrategyConfig strategyConfig, RemoteExecutionClients executionClients, SourcePathRuleFinder ruleFinder, CellPathResolver cellResolver, Cell rootCell, ThrowingFunction<Path, HashCode, IOException> fileHasher) { this.executionClients = executionClients; this.service = MoreExecutors.listeningDecorator( MostExecutors.newMultiThreadExecutor("remote-exec", strategyConfig.getThreads())); this.computeActionLimiter = new JobLimiter(strategyConfig.getMaxConcurrentActionComputations()); this.pendingUploadsLimiter = new JobLimiter(strategyConfig.getMaxConcurrentPendingUploads()); this.executionLimiter = new JobLimiter(strategyConfig.getMaxConcurrentExecutions()); this.handleResultLimiter = new JobLimiter(strategyConfig.getMaxConcurrentResultHandling()); this.maxInputSizeBytes = strategyConfig.maxInputSizeBytes(); this.eventBus = eventBus; ImmutableSet<Optional<String>> cellNames = rootCell.getCellProvider().getLoadedCells().values().stream() .map(Cell::getCanonicalName).collect(ImmutableSet.toImmutableSet()); this.cellPathPrefix = MorePaths.splitOnCommonPrefix(cellNames.stream() .map(name -> cellResolver.getCellPath(name).get()).collect(ImmutableList.toImmutableList())).get() .getFirst();//from w ww . ja v a 2s. co m this.mbrHelper = new ModernBuildRuleRemoteExecutionHelper(eventBus, this.executionClients.getProtocol(), ruleFinder, cellResolver, rootCell, cellNames, cellPathPrefix, fileHasher); }
From source file:com.zuppelli.living.docs.ContextAwareDiagramMojo.java
protected void populatePackageClusters(ImmutableSet<ClassPath.ClassInfo> allClasses, DotGraph.Digraph digraph) { List<String> orderedPackages = new ArrayList<String>(this.packages.keySet()); Collections.sort(orderedPackages, this.largerLengthComparator); final Set<Class> handled = new HashSet<Class>(); Map<String, DotGraph.Cluster> clusters = new HashMap(); for (String pkg : orderedPackages) { Stream<ClassPath.ClassInfo> layer = allClasses.stream().filter(ClassInfoFilters.filter(pkg)); String name = this.packages.get(pkg); DotGraph.Cluster found = null;/* w ww . j a v a2 s . com*/ for (String handledPkg : clusters.keySet()) { if (pkg.contains(handledPkg)) { found = clusters.get(handledPkg); break; } } final DotGraph.Cluster core = null == found ? digraph.addCluster(pkg) : found.addCluster(pkg); clusters.put(pkg, core); core.setLabel(name); layer.forEach(new Consumer<ClassPath.ClassInfo>() { public void accept(ClassPath.ClassInfo ci) { final Class clazz = ci.load(); if (!ignoreDeprecated(clazz) && !PACKAGE_INFO.equals(clazz.getSimpleName()) && !handled.contains(clazz)) { core.addNode(clazz.getName()).setLabel(clazz.getSimpleName()) .setComment(clazz.getSimpleName()); handled.add(clazz); } } }); } }
From source file:dagger.internal.codegen.ModuleValidator.java
/** * Validates modules included in a given module or installed in a given component. * * <p>Checks that the referenced modules are non-generic types annotated with {@code @Module} or * {@code @ProducerModule}.//from w w w. jav a 2s . c om * * <p>If the referenced module is in the {@linkplain #addKnownModules(Collection) known modules * set} and has errors, reports an error at that module's inclusion. * * @param annotatedType the annotated module or component * @param annotation the annotation specifying the referenced modules ({@code @Component}, * {@code @ProductionComponent}, {@code @Subcomponent}, {@code @ProductionSubcomponent}, * {@code @Module}, or {@code @ProducerModule}) * @param validModuleKinds the module kinds that the annotated type is permitted to include */ ValidationReport<TypeElement> validateReferencedModules(TypeElement annotatedType, AnnotationMirror annotation, ImmutableSet<ModuleDescriptor.Kind> validModuleKinds) { ValidationReport.Builder<TypeElement> subreport = ValidationReport.about(annotatedType); ImmutableSet<? extends Class<? extends Annotation>> validModuleAnnotations = validModuleKinds.stream() .map(ModuleDescriptor.Kind::moduleAnnotation).collect(toImmutableSet()); for (AnnotationValue includedModule : getModules(annotatedType, annotation)) { asType(includedModule).accept(new SimpleTypeVisitor8<Void, Void>() { @Override protected Void defaultAction(TypeMirror mirror, Void p) { reportError("%s is not a valid module type.", mirror); return null; } @Override public Void visitDeclared(DeclaredType t, Void p) { TypeElement module = MoreElements.asType(t.asElement()); if (!t.getTypeArguments().isEmpty()) { reportError(REFERENCED_MODULE_MUST_NOT_HAVE_TYPE_PARAMS, module.getQualifiedName()); } if (!isAnyAnnotationPresent(module, validModuleAnnotations)) { reportError(REFERENCED_MODULE_NOT_ANNOTATED, module.getQualifiedName(), (validModuleAnnotations.size() > 1 ? "one of " : "") + validModuleAnnotations .stream().map(otherClass -> "@" + otherClass.getSimpleName()) .collect(joining(", "))); } else if (knownModules.contains(module) && !validate(module).isClean()) { reportError("%s has errors", module.getQualifiedName()); } return null; } private void reportError(String format, Object... args) { subreport.addError(String.format(format, args), annotatedType, annotation, includedModule); } }, null); } return subreport.build(); }
From source file:de.metas.ui.web.handlingunits.HUEditorViewBuffer_HighVolume.java
private Stream<HUEditorRow> streamByIds(@NonNull final HUEditorRowFilter filter) { final Stream<HUEditorRowId> huEditorRowIds; final ImmutableSet<HUEditorRowId> onlyRowIds = filter.getOnlyRowIds(); if (onlyRowIds.isEmpty()) { final List<DocumentQueryOrderBy> defaultOrderBys = getDefaultSelection().getOrderBys(); huEditorRowIds = streamHUIdsByPage(0, Integer.MAX_VALUE, defaultOrderBys) .map(HUEditorRowId::ofTopLevelHU); } else {/* ww w . java 2 s. c om*/ huEditorRowIds = onlyRowIds.stream(); } return HUEditorRowsPagedLoadingIterator.builder().huEditorRepo(huEditorRepo).cache(cache_huRowsById) .rowIds(huEditorRowIds.iterator()).filter(filter).build().stream(); }