List of usage examples for com.google.common.collect ImmutableSet contains
boolean contains(Object o);
From source file:com.facebook.buck.rules.keys.DefaultDependencyFileRuleKeyBuilderFactory.java
@Override public RuleKey build(BuildRule rule, ImmutableList<Path> inputs) throws IOException { // Create a builder which records all `SourcePath`s which are possibly used by the rule. Builder builder = newInstance(rule); // Use a multi-map to gather up all the `SourcePath`s that have relative paths that are // referenced in the input list, as it's possible for multiple `SourcePath`s to have the // same relative path (but come from different cells). ImmutableSet<Path> inputSet = ImmutableSet.copyOf(inputs); ImmutableMultimap.Builder<Path, SourcePath> relativePathToSourcePathsBuilder = ImmutableMultimap.builder(); for (SourcePath input : builder.getInputsSoFar()) { Path relativePath = pathResolver.getRelativePath(input); if (inputSet.contains(relativePath)) { relativePathToSourcePathsBuilder.put(relativePath, input); }/*from ww w . j av a 2s . co m*/ } final ImmutableMultimap<Path, SourcePath> relativePathToSourcePaths = relativePathToSourcePathsBuilder .build(); // Now add the actual given inputs to the rule key using all possible `SourcePath`s they map to. // It's important that we do this by walking the `inputs` list, so that we maintain the original // ordering the duplicate handling. for (Path input : inputs) { ImmutableCollection<SourcePath> sourcePaths = relativePathToSourcePaths.get(input); // If we don't find actual inputs in the rule that correspond to this input, this likely means // that the rule changed to no longer use the input. In this case, we need to throw a // `NoSuchFileException` error so that the build engine handles this as a signal that the dep // file rule key can't be used. if (sourcePaths.isEmpty()) { throw new NoSuchFileException( String.format("%s: could not find any inputs matching the relative path `%s`", rule.getBuildTarget(), input)); } // Add each `SourcePath` using `builder.setPath()`. We can't use `builder.setSourcePath()` // here since the special `RuleKeyBuilder` sub-class that dep-file rule keys use intentionally // override `builder.setSourcePath()` to be a noop (and just record the inputs). for (SourcePath sourcePath : sourcePaths) { builder.setPath(pathResolver.getAbsolutePath(sourcePath), pathResolver.getRelativePath(sourcePath)); } } return builder.build(); }
From source file:com.jeffreybosboom.lyne.Puzzle.java
private Puzzle withEdgeSet(Pair<Node, Node> edge, ImmutableSet<Node.Kind> newEdgeSet) { assert neighbors(edge.first).anyMatch(Predicate.isEqual(edge.second)); assert edge.first.compareTo(edge.second) < 0; assert edgeSets.containsKey(edge) : "not an edge: " + edge; assert !newEdgeSet.contains(Node.Kind.OCTAGON); assert !newEdgeSet.isEmpty(); //TODO: no-change and ContradictionException checks could be moved here //from set and remove. ImmutableMap.Builder<Pair<Node, Node>, ImmutableSet<Node.Kind>> edgeSetBuilder = ImmutableMap.builder(); edgeSets.entrySet().stream().filter(e -> !e.getKey().equals(edge)).forEachOrdered(edgeSetBuilder::put); edgeSetBuilder.put(edge, newEdgeSet); return new Puzzle(this, edgeSetBuilder.build()); }
From source file:org.janusgraph.diskstorage.indexing.IndexFeatures.java
public IndexFeatures(boolean supportsDocumentTTL, Mapping defaultMap, ImmutableSet<Mapping> supportedMap, String wildcardField, ImmutableSet<Cardinality> supportedCardinaities, boolean supportsNanoseconds) { Preconditions.checkArgument(defaultMap != null || defaultMap != Mapping.DEFAULT); Preconditions.checkArgument(//from w ww. j av a 2 s .c om supportedMap != null && !supportedMap.isEmpty() && supportedMap.contains(defaultMap)); this.supportsDocumentTTL = supportsDocumentTTL; this.defaultStringMapping = defaultMap; this.supportedStringMappings = supportedMap; this.wildcardField = wildcardField; this.supportedCardinaities = supportedCardinaities; this.supportsNanoseconds = supportsNanoseconds; }
From source file:com.outerspacecat.icalendar.RecurrenceFunctions.java
/** * Returns a function for transforming instances of * {@link ChronoFixedSchedule} into zero or more instances. Used to apply * BYDAY values to a WEEKLY recurrence or a YEARLY recurrence with BYWEEKNO * values./*www . j av a 2s .c o m*/ * <p> * May not work for all chronologies. * * @param weekStart the week start. Must be non {@code null}. * @param daysOfWeek the values to alter supplied fixed schedules with. Must * be non {@code null}.. * @return a function for transforming instances of {@link FixedSchedule} into * zero or more instances. Never {@code null}. */ static Function<ChronoFixedSchedule, List<ChronoFixedSchedule>> weeklyByDayExpander(final DayOfWeek weekStart, final ImmutableSet<DayOfWeek> daysOfWeek) { Preconditions.checkNotNull(weekStart, "weekStart required"); Preconditions.checkNotNull(daysOfWeek, "daysOfWeek required"); Preconditions.checkArgument(!daysOfWeek.isEmpty(), "jodaByDay must be non empty"); return new Function<ChronoFixedSchedule, List<ChronoFixedSchedule>>() { @Override public List<ChronoFixedSchedule> apply(final ChronoFixedSchedule obj) { Preconditions.checkNotNull(obj, "obj required"); List<ChronoFixedSchedule> ret = new ArrayList<ChronoFixedSchedule>(); ChronoLocalDate startOfWeek = obj.getDateOfStart().minus( (7 + obj.getDateOfStart().get(ChronoField.DAY_OF_WEEK) - weekStart.getValue()) % 7, ChronoUnit.DAYS); for (int i = 0; i < 7; ++i) { ChronoLocalDate adjustedStart = startOfWeek.plus(i, ChronoUnit.DAYS); if (daysOfWeek.contains(DayOfWeek.of(adjustedStart.get(ChronoField.DAY_OF_WEEK)))) ret.add(obj.adjustDateOfStart(adjustedStart)); } return ret; } }; }
From source file:com.facebook.buck.cxx.CxxBinaryFactory.java
@SuppressWarnings("PMD.PrematureDeclaration") public BuildRule createBuildRule(BuildTarget target, ProjectFilesystem projectFilesystem, ActionGraphBuilder graphBuilder, CellPathResolver cellRoots, CxxBinaryDescriptionArg args, ImmutableSortedSet<BuildTarget> extraCxxDeps) { // We explicitly remove some flavors below from params to make sure rule // has the same output regardless if we will strip or not. Optional<StripStyle> flavoredStripStyle = StripStyle.FLAVOR_DOMAIN.getValue(target); Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(target); target = CxxStrip.removeStripStyleFlavorInTarget(target, flavoredStripStyle); target = LinkerMapMode.removeLinkerMapModeFlavorInTarget(target, flavoredLinkerMapMode); CxxPlatformsProvider cxxPlatformsProvider = getCxxPlatformsProvider(); // Extract the platform from the flavor, falling back to the default platform if none are // found.//from w w w . ja v a2 s .com ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(target.getFlavors()); CxxPlatform cxxPlatform = CxxPlatforms .getCxxPlatform(cxxPlatformsProvider, target, args.getDefaultPlatform()).resolve(graphBuilder); if (flavors.contains(CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR)) { return createHeaderSymlinkTreeBuildRule( target.withoutFlavors(CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR), projectFilesystem, graphBuilder, cxxPlatform, args); } if (flavors.contains(CxxCompilationDatabase.COMPILATION_DATABASE)) { CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer .createBuildRulesForCxxBinaryDescriptionArg( target.withoutFlavors(CxxCompilationDatabase.COMPILATION_DATABASE), projectFilesystem, graphBuilder, cellRoots, cxxBuckConfig, cxxPlatform, args, ImmutableSet.of(), flavoredStripStyle, flavoredLinkerMapMode); return CxxCompilationDatabase.createCompilationDatabase(target, projectFilesystem, cxxLinkAndCompileRules.compileRules); } FlavorDomain<UnresolvedCxxPlatform> cxxPlatforms = cxxPlatformsProvider.getUnresolvedCxxPlatforms(); if (flavors.contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) { return CxxDescriptionEnhancer.createUberCompilationDatabase( cxxPlatforms.getValue(flavors).isPresent() ? target : target.withAppendedFlavors( cxxPlatformsProvider.getDefaultUnresolvedCxxPlatform().getFlavor()), projectFilesystem, graphBuilder); } if (CxxInferEnhancer.INFER_FLAVOR_DOMAIN.containsAnyOf(flavors)) { return CxxInferEnhancer.requireInferRule(target, projectFilesystem, graphBuilder, cellRoots, cxxBuckConfig, cxxPlatform, args, inferBuckConfig); } CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer .createBuildRulesForCxxBinaryDescriptionArg(target, projectFilesystem, graphBuilder, cellRoots, cxxBuckConfig, cxxPlatform, args, extraCxxDeps, flavoredStripStyle, flavoredLinkerMapMode); SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder); if (target.getFlavors().contains(CxxDescriptionEnhancer.CXX_LINK_MAP_FLAVOR)) { return CxxDescriptionEnhancer.createLinkMap(target, projectFilesystem, ruleFinder, cxxLinkAndCompileRules); } // Return a CxxBinary rule as our representative in the action graph, rather than the CxxLink // rule above for a couple reasons: // 1) CxxBinary extends BinaryBuildRule whereas CxxLink does not, so the former can be used // as executables for genrules. // 2) In some cases, users add dependencies from some rules onto other binary rules, typically // if the binary is executed by some test or library code at test time. These target graph // deps should *not* become build time dependencies on the CxxLink step, otherwise we'd // have to wait for the dependency binary to link before we could link the dependent binary. // By using another BuildRule, we can keep the original target graph dependency tree while // preventing it from affecting link parallelism. target = CxxStrip.restoreStripStyleFlavorInTarget(target, flavoredStripStyle); target = LinkerMapMode.restoreLinkerMapModeFlavorInTarget(target, flavoredLinkerMapMode); return new CxxBinary(target, projectFilesystem, new BuildRuleParams(() -> cxxLinkAndCompileRules.deps, () -> ImmutableSortedSet.copyOf( BuildableSupport.getDepsCollection(cxxLinkAndCompileRules.executable, ruleFinder)), ImmutableSortedSet.of()), cxxPlatform, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, args.getFrameworks(), args.getTests(), target.withoutFlavors(cxxPlatforms.getFlavors()), cxxBuckConfig.shouldCacheBinaries()); }
From source file:com.facebook.buck.halide.HalideLibraryDescription.java
@Override public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException { SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver); SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder); BuildTarget target = params.getBuildTarget(); ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(target.getFlavors()); CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform); if (flavors.contains(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR)) { ImmutableMap.Builder<Path, SourcePath> headersBuilder = ImmutableMap.builder(); BuildTarget compileTarget = resolver .requireRule(target.withFlavors(HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor())) .getBuildTarget();//from w w w .j a v a 2 s . c om Path outputPath = HalideCompile.headerOutputPath(compileTarget, params.getProjectFilesystem(), args.functionName); headersBuilder.put(outputPath.getFileName(), new BuildTargetSourcePath(compileTarget, outputPath)); return CxxDescriptionEnhancer.createHeaderSymlinkTree(params, resolver, pathResolver, cxxPlatform, headersBuilder.build(), HeaderVisibility.PUBLIC, true); } else if (flavors.contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) { CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor()); return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, hostCxxPlatform, params); } else if (flavors.contains(HALIDE_COMPILER_FLAVOR)) { // We always want to build the halide "compiler" for the host platform, so // we use the host flavor here, regardless of the flavors on the build // target. CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor()); final ImmutableSortedSet<BuildTarget> compilerDeps = args.compilerDeps; return createHalideCompiler( params.copyWithChanges(params.getBuildTarget().withFlavors(HALIDE_COMPILER_FLAVOR), Suppliers.ofInstance(resolver.getAllRules(compilerDeps)), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, pathResolver, ruleFinder, hostCxxPlatform, args.srcs, args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, args.linkerFlags, args.platformLinkerFlags, args.includeDirs); } else if (flavors.contains(CxxDescriptionEnhancer.STATIC_FLAVOR) || flavors.contains(CxxDescriptionEnhancer.STATIC_PIC_FLAVOR)) { // Halide always output PIC, so it's output can be used for both cases. // See: https://github.com/halide/Halide/blob/e3c301f3/src/LLVM_Output.cpp#L152 return createHalideStaticLibrary(params, resolver, pathResolver, ruleFinder, cxxPlatform, args); } else if (flavors.contains(CxxDescriptionEnhancer.SHARED_FLAVOR)) { throw new HumanReadableException("halide_library '%s' does not support shared libraries as output", params.getBuildTarget()); } else if (flavors.contains(HALIDE_COMPILE_FLAVOR)) { return createHalideCompile( params.copyWithDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, pathResolver, cxxPlatform, Optional.of(args.compilerInvocationFlags), args.functionName); } return new HalideLibrary(params, resolver, pathResolver, args.supportedPlatformsRegex); }
From source file:com.facebook.buck.features.go.GoTestDescription.java
@Override public boolean hasFlavors(ImmutableSet<Flavor> flavors) { return getGoToolchain().getPlatformFlavorDomain().containsAnyOf(flavors) || flavors.contains(TEST_LIBRARY_FLAVOR); }
From source file:google.registry.flows.domain.DomainCheckFlow.java
/** * Return the domains to be checked for a particular fee check item. Some versions of the fee * extension specify the domain name in the extension item, while others use the list of domain * names from the regular check domain availability list. *//*from w w w .jav a 2 s .com*/ private Set<String> getDomainNamesToCheckForFee(FeeCheckCommandExtensionItem feeCheckItem, ImmutableSet<String> availabilityCheckDomains) throws OnlyCheckedNamesCanBeFeeCheckedException { if (feeCheckItem.isDomainNameSupported()) { String domainNameInExtension = feeCheckItem.getDomainName(); if (!availabilityCheckDomains.contains(domainNameInExtension)) { // Although the fee extension explicitly says it's ok to fee check a domain name that you // aren't also availability checking, we forbid it. This makes the experience simpler and // also means we can assume any domain names in the fee checks have been validated. throw new OnlyCheckedNamesCanBeFeeCheckedException(); } return ImmutableSet.of(domainNameInExtension); } // If this version of the fee extension is nameless, use the full list of domains. return availabilityCheckDomains; }
From source file:com.facebook.buck.apple.WorkspaceAndProjectGenerator.java
/** * Find transitive dependencies of inputs for building. * * @param projectGraph {@link TargetGraph} containing nodes * @param nodes Nodes to fetch dependencies for. * @param excludes Nodes to exclude from dependencies list. * @return targets and their dependencies that should be build. *//* w w w .j av a2 s.c o m*/ private static ImmutableSet<TargetNode<?>> getTransitiveDepsAndInputs(final TargetGraph projectGraph, Iterable<? extends TargetNode<?>> nodes, final ImmutableSet<TargetNode<?>> excludes) { return FluentIterable.from(nodes) .transformAndConcat(new Function<TargetNode<?>, Iterable<TargetNode<?>>>() { @Override public Iterable<TargetNode<?>> apply(TargetNode<?> input) { return AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(projectGraph, AppleBuildRules.RecursiveDependenciesMode.BUILDING, input, Optional.<ImmutableSet<BuildRuleType>>absent()); } }).append(nodes).filter(new Predicate<TargetNode<?>>() { @Override public boolean apply(TargetNode<?> input) { return !excludes.contains(input) && AppleBuildRules.isXcodeTargetBuildRuleType(input.getType()); } }).toSet(); }
From source file:com.facebook.buck.util.unarchive.Untar.java
/** Cleans up any files that exist on the filesystem that were not in the archive */ private void tidyDirectories(ProjectFilesystem filesystem, Set<Path> dirsToTidy, ImmutableSet<Path> createdFiles) throws IOException { for (Path directory : dirsToTidy) { for (Path foundFile : filesystem.getDirectoryContents(directory)) { if (!createdFiles.contains(foundFile) && !dirsToTidy.contains(foundFile)) { filesystem.deleteRecursivelyIfExists(foundFile); }/* w w w . ja v a 2 s . c o m*/ } } }