List of usage examples for com.google.common.collect ImmutableSet contains
boolean contains(Object o);
From source file:com.facebook.buck.android.NativeLibraryMergeEnhancer.java
private static Map<NativeLinkable, MergedNativeLibraryConstituents> makeConstituentMap( BuildRuleParams buildRuleParams, Map<String, List<Pattern>> mergeMap, Iterable<NativeLinkable> allLinkables, ImmutableSet<NativeLinkable> linkableAssetSet) { List<MergedNativeLibraryConstituents> allConstituents = new ArrayList<>(); for (Map.Entry<String, List<Pattern>> mergeConfigEntry : mergeMap.entrySet()) { String mergeSoname = mergeConfigEntry.getKey(); List<Pattern> patterns = mergeConfigEntry.getValue(); MergedNativeLibraryConstituents.Builder constituentsBuilder = MergedNativeLibraryConstituents.builder() .setSoname(mergeSoname); for (Pattern pattern : patterns) { for (NativeLinkable linkable : allLinkables) { // TODO(dreiss): Might be a good idea to cache .getBuildTarget().toString(). if (pattern.matcher(linkable.getBuildTarget().toString()).find()) { constituentsBuilder.addLinkables(linkable); }//from www . j a v a 2s. com } } allConstituents.add(constituentsBuilder.build()); } Map<NativeLinkable, MergedNativeLibraryConstituents> linkableMembership = new HashMap<>(); for (MergedNativeLibraryConstituents constituents : allConstituents) { boolean hasNonAssets = false; boolean hasAssets = false; for (NativeLinkable linkable : constituents.getLinkables()) { if (linkableMembership.containsKey(linkable)) { throw new RuntimeException( String.format("When processing %s, attempted to merge %s into both %s and %s", buildRuleParams.getBuildTarget(), linkable, linkableMembership.get(linkable), constituents)); } linkableMembership.put(linkable, constituents); if (linkableAssetSet.contains(linkable)) { hasAssets = true; } else { hasNonAssets = true; } } if (hasAssets && hasNonAssets) { StringBuilder sb = new StringBuilder(); sb.append(String.format( "When processing %s, merged lib '%s' contains both asset and non-asset libraries.\n", buildRuleParams.getBuildTarget(), constituents)); for (NativeLinkable linkable : constituents.getLinkables()) { sb.append(String.format(" %s -> %s\n", linkable, linkableAssetSet.contains(linkable) ? "asset" : "not asset")); } throw new RuntimeException(sb.toString()); } } for (NativeLinkable linkable : allLinkables) { if (!linkableMembership.containsKey(linkable)) { linkableMembership.put(linkable, MergedNativeLibraryConstituents.builder().addLinkables(linkable).build()); } } return linkableMembership; }
From source file:org.hawk.service.emf.EffectiveMetamodelRulesetSerializer.java
public EffectiveMetamodelRuleset load(Properties props) { final Map<Integer, String> incMetamodels = new TreeMap<>(); final Table<Integer, Integer, String> incTypeTable = TreeBasedTable.create(); final Table<Integer, Integer, ImmutableSet<String>> incSlotTable = TreeBasedTable.create(); final Map<Integer, String> excMetamodels = new TreeMap<>(); final Table<Integer, Integer, String> excTypeTable = TreeBasedTable.create(); final Table<Integer, Integer, ImmutableSet<String>> excSlotTable = TreeBasedTable.create(); for (String propName : props.stringPropertyNames()) { if (propName.startsWith(propertyPrefix)) { final String raw = propName.substring(propertyPrefix.length()); boolean isIncludes; String unprefixed;//from www.j a v a 2 s . c o m if (raw.startsWith(INCLUDES_SUFFIX)) { isIncludes = true; unprefixed = raw.substring(INCLUDES_SUFFIX.length()); } else if (raw.startsWith(EXCLUDES_SUFFIX)) { isIncludes = false; unprefixed = raw.substring(EXCLUDES_SUFFIX.length()); } else { continue; } final String[] parts = unprefixed.split("[" + SEPARATOR + "]"); final String propValue = props.getProperty(propName).trim(); int iMetamodel, iType; switch (parts.length) { case 1: // prefix0 -> URI of the first metamodel iMetamodel = Integer.valueOf(parts[0]); String mmURI = propValue; if (isIncludes) { incMetamodels.put(iMetamodel, mmURI); } else { excMetamodels.put(iMetamodel, mmURI); } break; case 2: // prefix0.0 -> name of the first type of the first metamodel iMetamodel = Integer.valueOf(parts[0]); iType = Integer.valueOf(parts[1]); String type = propValue; if (isIncludes) { incTypeTable.put(iMetamodel, iType, type); } else { excTypeTable.put(iMetamodel, iType, type); } break; case 3: // prefix0.0.slots -> comma-separated slots for the first type of first metamodel (if not all) iMetamodel = Integer.valueOf(parts[0]); iType = Integer.valueOf(parts[1]); ImmutableSet<String> slots; if (propValue.length() > 0) { slots = ImmutableSet.copyOf(propValue.split("[" + SEPARATOR + "]")); } else { slots = ImmutableSet.of(); } if (isIncludes) { incSlotTable.put(iMetamodel, iType, slots); } else { excSlotTable.put(iMetamodel, iType, slots); } break; default: throw new IllegalArgumentException(String .format("Property %s should only have 1-3 parts, but has %d", propName, parts.length)); } } } final EffectiveMetamodelRuleset ruleset = new EffectiveMetamodelRuleset(); for (final Cell<Integer, Integer, ImmutableSet<String>> mmEntry : incSlotTable.cellSet()) { final String mmURI = incMetamodels.get(mmEntry.getRowKey()); final String typeName = incTypeTable.get(mmEntry.getRowKey(), mmEntry.getColumnKey()); final ImmutableSet<String> slots = mmEntry.getValue(); if (EffectiveMetamodelRuleset.WILDCARD.equals(typeName)) { ruleset.include(mmURI); } else if (slots.contains(EffectiveMetamodelRuleset.WILDCARD)) { ruleset.include(mmURI, typeName); } else { ruleset.include(mmURI, typeName, slots); } } for (final Cell<Integer, Integer, ImmutableSet<String>> mmEntry : excSlotTable.cellSet()) { final String mmURI = excMetamodels.get(mmEntry.getRowKey()); final String typeName = excTypeTable.get(mmEntry.getRowKey(), mmEntry.getColumnKey()); final ImmutableSet<String> slots = mmEntry.getValue(); if (EffectiveMetamodelRuleset.WILDCARD.equals(typeName)) { ruleset.exclude(mmURI); } else if (slots.contains(EffectiveMetamodelRuleset.WILDCARD)) { ruleset.exclude(mmURI, typeName); } else { ruleset.exclude(mmURI, typeName, slots); } } return ruleset; }
From source file:com.facebook.buck.apple.AppleBundle.java
@Override public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder(); stepsBuilder.add(new MakeCleanDirectoryStep(getProjectFilesystem(), bundleRoot)); Path resourcesDestinationPath = bundleRoot.resolve(this.destinations.getResourcesPath()); if (assetCatalog.isPresent()) { stepsBuilder.add(new MkdirStep(getProjectFilesystem(), resourcesDestinationPath)); Path bundleDir = assetCatalog.get().getOutputDir(); stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), bundleDir, resourcesDestinationPath, CopyStep.DirectoryMode.CONTENTS_ONLY)); }//from www.j ava2 s.c o m if (coreDataModel.isPresent()) { stepsBuilder.add(new MkdirStep(getProjectFilesystem(), resourcesDestinationPath)); stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), coreDataModel.get().getOutputDir(), resourcesDestinationPath, CopyStep.DirectoryMode.CONTENTS_ONLY)); } if (sceneKitAssets.isPresent()) { stepsBuilder.add(new MkdirStep(getProjectFilesystem(), resourcesDestinationPath)); stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), sceneKitAssets.get().getPathToOutput(), resourcesDestinationPath, CopyStep.DirectoryMode.CONTENTS_ONLY)); } Path metadataPath = getMetadataPath(); Path infoPlistInputPath = context.getSourcePathResolver().getAbsolutePath(infoPlist); Path infoPlistSubstitutionTempPath = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.plist"); Path infoPlistOutputPath = metadataPath.resolve("Info.plist"); stepsBuilder.add(new MkdirStep(getProjectFilesystem(), metadataPath), // TODO(bhamiltoncx): This is only appropriate for .app bundles. new WriteFileStep(getProjectFilesystem(), "APPLWRUN", metadataPath.resolve("PkgInfo"), /* executable */ false), new MkdirStep(getProjectFilesystem(), infoPlistSubstitutionTempPath.getParent()), new FindAndReplaceStep(getProjectFilesystem(), infoPlistInputPath, infoPlistSubstitutionTempPath, InfoPlistSubstitution.createVariableExpansionFunction(withDefaults(infoPlistSubstitutions, ImmutableMap.of("EXECUTABLE_NAME", binaryName, "PRODUCT_NAME", binaryName)))), new PlistProcessStep(getProjectFilesystem(), infoPlistSubstitutionTempPath, assetCatalog.isPresent() ? Optional.of(assetCatalog.get().getOutputPlist()) : Optional.empty(), infoPlistOutputPath, getInfoPlistAdditionalKeys(), getInfoPlistOverrideKeys(), PlistProcessStep.OutputFormat.BINARY)); if (hasBinary) { appendCopyBinarySteps(stepsBuilder); appendCopyDsymStep(stepsBuilder, buildableContext); } if (!Iterables.isEmpty(Iterables.concat(resources.getResourceDirs(), resources.getDirsContainingResourceDirs(), resources.getResourceFiles()))) { stepsBuilder.add(new MkdirStep(getProjectFilesystem(), resourcesDestinationPath)); for (SourcePath dir : resources.getResourceDirs()) { stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(dir), resourcesDestinationPath, CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS)); } for (SourcePath dir : resources.getDirsContainingResourceDirs()) { stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(dir), resourcesDestinationPath, CopyStep.DirectoryMode.CONTENTS_ONLY)); } for (SourcePath file : resources.getResourceFiles()) { // TODO(shs96c): Check that this work cross-cell Path resolvedFilePath = context.getSourcePathResolver().getRelativePath(file); Path destinationPath = resourcesDestinationPath.resolve(resolvedFilePath.getFileName()); addResourceProcessingSteps(context.getSourcePathResolver(), resolvedFilePath, destinationPath, stepsBuilder); } } ImmutableList.Builder<Path> codeSignOnCopyPathsBuilder = ImmutableList.builder(); addStepsToCopyExtensionBundlesDependencies(context.getSourcePathResolver(), stepsBuilder, codeSignOnCopyPathsBuilder); for (SourcePath variantSourcePath : resources.getResourceVariantFiles()) { // TODO(shs96c): Ensure this works cross-cell, as relative path begins with "buck-out" Path variantFilePath = context.getSourcePathResolver().getRelativePath(variantSourcePath); Path variantDirectory = variantFilePath.getParent(); if (variantDirectory == null || !variantDirectory.toString().endsWith(".lproj")) { throw new HumanReadableException( "Variant files have to be in a directory with name ending in '.lproj', " + "but '%s' is not.", variantFilePath); } Path bundleVariantDestinationPath = resourcesDestinationPath.resolve(variantDirectory.getFileName()); stepsBuilder.add(new MkdirStep(getProjectFilesystem(), bundleVariantDestinationPath)); Path destinationPath = bundleVariantDestinationPath.resolve(variantFilePath.getFileName()); addResourceProcessingSteps(context.getSourcePathResolver(), variantFilePath, destinationPath, stepsBuilder); } if (!frameworks.isEmpty()) { Path frameworksDestinationPath = bundleRoot.resolve(this.destinations.getFrameworksPath()); stepsBuilder.add(new MkdirStep(getProjectFilesystem(), frameworksDestinationPath)); for (SourcePath framework : frameworks) { Path srcPath = context.getSourcePathResolver().getAbsolutePath(framework); stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), srcPath, frameworksDestinationPath, CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS)); codeSignOnCopyPathsBuilder.add(frameworksDestinationPath.resolve(srcPath.getFileName())); } } if (needCodeSign()) { Optional<Path> signingEntitlementsTempPath; Supplier<CodeSignIdentity> codeSignIdentitySupplier; if (adHocCodeSignIsSufficient()) { signingEntitlementsTempPath = Optional.empty(); codeSignIdentitySupplier = () -> CodeSignIdentity.AD_HOC; } else { // Copy the .mobileprovision file if the platform requires it, and sign the executable. Optional<Path> entitlementsPlist = Optional.empty(); final Path srcRoot = getProjectFilesystem().getRootPath().resolve(getBuildTarget().getBasePath()); Optional<String> entitlementsPlistString = InfoPlistSubstitution.getVariableExpansionForPlatform( CODE_SIGN_ENTITLEMENTS, platformName, withDefaults(infoPlistSubstitutions, ImmutableMap.of("SOURCE_ROOT", srcRoot.toString(), "SRCROOT", srcRoot.toString()))); if (entitlementsPlistString.isPresent()) { entitlementsPlist = Optional.of(srcRoot.resolve(Paths.get(entitlementsPlistString.get()))); } signingEntitlementsTempPath = Optional .of(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.xcent")); final Path dryRunResultPath = bundleRoot.resolve(PP_DRY_RUN_RESULT_FILE); final ProvisioningProfileCopyStep provisioningProfileCopyStep = new ProvisioningProfileCopyStep( getProjectFilesystem(), infoPlistOutputPath, Optional.empty(), // Provisioning profile UUID -- find automatically. entitlementsPlist, provisioningProfileStore, resourcesDestinationPath.resolve("embedded.mobileprovision"), dryRunCodeSigning ? bundleRoot.resolve(CODE_SIGN_DRY_RUN_ENTITLEMENTS_FILE) : signingEntitlementsTempPath.get(), codeSignIdentityStore, dryRunCodeSigning ? Optional.of(dryRunResultPath) : Optional.empty()); stepsBuilder.add(provisioningProfileCopyStep); codeSignIdentitySupplier = () -> { // Using getUnchecked here because the previous step should already throw if exception // occurred, and this supplier would never be evaluated. Optional<ProvisioningProfileMetadata> selectedProfile = Futures .getUnchecked(provisioningProfileCopyStep.getSelectedProvisioningProfileFuture()); if (!selectedProfile.isPresent()) { // This should only happen in dry-run codesign mode (since otherwise an exception // would have been thrown already.) Still, we need to return *something*. Preconditions.checkState(dryRunCodeSigning); return CodeSignIdentity.AD_HOC; } ImmutableSet<HashCode> fingerprints = selectedProfile.get() .getDeveloperCertificateFingerprints(); if (fingerprints.isEmpty()) { // No constraints, pick an arbitrary identity. // If no identities are available, use an ad-hoc identity. return Iterables.getFirst(codeSignIdentityStore.getIdentities(), CodeSignIdentity.AD_HOC); } for (CodeSignIdentity identity : codeSignIdentityStore.getIdentities()) { if (identity.getFingerprint().isPresent() && fingerprints.contains(identity.getFingerprint().get())) { return identity; } } throw new HumanReadableException( "No code sign identity available for provisioning profile: %s\n" + "Profile requires an identity with one of the following SHA1 fingerprints " + "available in your keychain: \n %s", selectedProfile.get().getProfilePath(), Joiner.on("\n ").join(fingerprints)); }; } addSwiftStdlibStepIfNeeded(context.getSourcePathResolver(), bundleRoot.resolve(Paths.get("Frameworks")), dryRunCodeSigning ? Optional.<Supplier<CodeSignIdentity>>empty() : Optional.of(codeSignIdentitySupplier), stepsBuilder, false /* is for packaging? */ ); for (Path codeSignOnCopyPath : codeSignOnCopyPathsBuilder.build()) { stepsBuilder.add(new CodeSignStep(getProjectFilesystem(), context.getSourcePathResolver(), codeSignOnCopyPath, Optional.empty(), codeSignIdentitySupplier, codesignAllocatePath, dryRunCodeSigning ? Optional.of(codeSignOnCopyPath.resolve(CODE_SIGN_DRY_RUN_ARGS_FILE)) : Optional.empty())); } stepsBuilder.add(new CodeSignStep(getProjectFilesystem(), context.getSourcePathResolver(), bundleRoot, signingEntitlementsTempPath, codeSignIdentitySupplier, codesignAllocatePath, dryRunCodeSigning ? Optional.of(bundleRoot.resolve(CODE_SIGN_DRY_RUN_ARGS_FILE)) : Optional.empty())); } else { addSwiftStdlibStepIfNeeded(context.getSourcePathResolver(), bundleRoot.resolve(Paths.get("Frameworks")), Optional.<Supplier<CodeSignIdentity>>empty(), stepsBuilder, false /* is for packaging? */ ); } // Ensure the bundle directory is archived so we can fetch it later. buildableContext.recordArtifact(getPathToOutput()); return stepsBuilder.build(); }
From source file:com.facebook.buck.rules.keys.DefaultDependencyFileRuleKeyFactory.java
@Override public Pair<RuleKey, ImmutableSet<SourcePath>> build(SupportsDependencyFileRuleKey rule, ImmutableList<DependencyFileEntry> depFileEntries) throws IOException { // Create a builder which records all `SourcePath`s which are possibly used by the rule. Builder builder = newInstance(rule); Optional<ImmutableSet<SourcePath>> possibleDepFileSourcePaths = rule.getPossibleInputSourcePaths(); // TODO(jkeljo): Make this use possibleDepFileSourcePaths all the time Iterable<SourcePath> inputsSoFar = builder.getIterableInputsSoFar(); // Dep file paths come as a sorted set, which does binary search instead of hashing for // lookups, so we re-create it as a hashset. ImmutableSet<SourcePath> fastPossibleSourcePaths = possibleDepFileSourcePaths.isPresent() ? ImmutableSet.copyOf(possibleDepFileSourcePaths.get()) : ImmutableSet.of();/*from w ww . j a v a 2 s. c om*/ ImmutableSet<DependencyFileEntry> depFileEntriesSet = ImmutableSet.copyOf(depFileEntries); final ImmutableSet.Builder<SourcePath> depFileSourcePathsBuilder = ImmutableSet.builder(); final ImmutableSet.Builder<DependencyFileEntry> filesAccountedFor = ImmutableSet.builder(); final ImmutableSet.Builder<String> metadataFilenamesBuilder = ImmutableSortedSet.naturalOrder(); // Each existing input path falls into one of three categories: // 1) It's not covered by dep files, so we need to consider it part of the rule key // 2) It's covered by dep files and present in the dep file, so we consider it // part of the rule key // 3) It's covered by dep files but not present in the dep file, so we don't include it in // the rule key (the benefit of dep file support is that lots of things fall in this // category, so we can avoid rebuilds that would have happened with input-based rule keys) for (SourcePath input : inputsSoFar) { if (possibleDepFileSourcePaths.isPresent() && !fastPossibleSourcePaths.contains(input)) { // If this path is not a dep file path, then add it to the builder directly. // Note that if {@code possibleDepFileSourcePaths} is not present, we treat // all the input files as covered by dep file, so we'll never end up here! builder.setSourcePathDirectly(input); } else { // If this input path is covered by the dep paths, check to see if it was declared // as a real dependency by the dep file entries DependencyFileEntry entry = DependencyFileEntry.fromSourcePath(input, pathResolver); if (depFileEntriesSet.contains(entry)) { builder.setSourcePathDirectly(input); depFileSourcePathsBuilder.add(input); filesAccountedFor.add(entry); } Optional<Path> pathWithinArchive = entry.pathWithinArchive(); if (pathWithinArchive.isPresent() && pathWithinArchive.get().startsWith(METADATA_DIR)) { metadataFilenamesBuilder.add(input.toString()); } } } Sets.SetView<DependencyFileEntry> filesUnaccountedFor = Sets.difference(depFileEntriesSet, filesAccountedFor.build()); // If we don't find actual inputs in one of the rules that corresponded to the input, this // likely means that the rule changed to no longer use the input. In this case we need to // throw a `NoSuchFileException` so that the build engine handles this as a signal that the // dep file rule key cannot be used. if (!filesUnaccountedFor.isEmpty()) { throw new NoSuchFileException( String.format("%s: could not find any inputs matching the relative paths [%s]", rule.getBuildTarget(), Joiner.on(',').join(filesUnaccountedFor))); } // Annotation processors might enumerate all files under a certain path and then generate // code based on that list (without actually reading the files), making the list of files // itself a used dependency that must be part of the dependency-based key. We don't // currently have the instrumentation to detect such enumeration perfectly, but annotation // processors are most commonly looking for files under META-INF, so as a stopgap we add // the listing of META-INF to the rule key. builder.setReflectively("buck.dep_file_metadata_list", metadataFilenamesBuilder.build()); return new Pair<>(builder.build(), depFileSourcePathsBuilder.build()); }
From source file:com.facebook.buck.config.BuckConfig.java
public ImmutableMap<String, ImmutableMap<String, String>> getRawConfigForParser() { ImmutableMap<String, ImmutableMap<String, String>> rawSections = config.getSectionToEntries(); // If the raw config doesn't have sections which have ignored fields, then just return it as-is. ImmutableSet<String> sectionsWithIgnoredFields = IGNORE_FIELDS_FOR_DAEMON_RESTART.keySet(); if (Sets.intersection(rawSections.keySet(), sectionsWithIgnoredFields).isEmpty()) { return rawSections; }/*from w ww .j a v a 2s . c om*/ // Otherwise, iterate through the config to do finer-grain filtering. ImmutableMap.Builder<String, ImmutableMap<String, String>> filtered = ImmutableMap.builder(); for (Map.Entry<String, ImmutableMap<String, String>> sectionEnt : rawSections.entrySet()) { String sectionName = sectionEnt.getKey(); // If this section doesn't have a corresponding ignored section, then just add it as-is. if (!sectionsWithIgnoredFields.contains(sectionName)) { filtered.put(sectionEnt); continue; } // If none of this section's entries are ignored, then add it as-is. ImmutableMap<String, String> fields = sectionEnt.getValue(); ImmutableSet<String> ignoredFieldNames = IGNORE_FIELDS_FOR_DAEMON_RESTART.getOrDefault(sectionName, ImmutableSet.of()); if (Sets.intersection(fields.keySet(), ignoredFieldNames).isEmpty()) { filtered.put(sectionEnt); continue; } // Otherwise, filter out the ignored fields. ImmutableMap<String, String> remainingKeys = ImmutableMap .copyOf(Maps.filterKeys(fields, Predicates.not(ignoredFieldNames::contains))); if (!remainingKeys.isEmpty()) { filtered.put(sectionName, remainingKeys); } } return filtered.build(); }
From source file:tv.dyndns.kishibe.qmaclone.server.ServiceServletStub.java
@Override public List<PacketProblem> searchProblem(final String query, final String creator, final boolean creatorPerfectMatching, final Set<ProblemGenre> genres, final Set<ProblemType> types, final Set<RandomFlag> randomFlags) throws ServiceException { return wrap("???????", new DatabaseAccessible<List<PacketProblem>>() { @Override/* w w w.j a va 2 s . c o m*/ public List<PacketProblem> access() throws DatabaseException { List<PacketProblem> problems = database.searchProblem(query, creator, creatorPerfectMatching, genres, types, randomFlags); ImmutableSet<Integer> usedProblems = ImmutableSet.copyOf(gameManager.getTestingProblemIds()); for (PacketProblem problem : problems) { problem.testing = usedProblems.contains(problem.id); } return problems; } }); }
From source file:com.facebook.buck.tools.consistency.RuleKeyFileParser.java
/** * Parse a thrift compact serialized file * * @param filename The name of the file//from ww w. ja v a 2 s .co m * @param targetNames The name of the targets that should be found * @return A {@link ParsedRuleKeyFile} object that all deserialized rules, and the rule key hash * of the specified target * @throws ParseException If an IO or serialization error occurs, or if the target could not be * found in the file */ public ParsedRuleKeyFile parseFile(Path filename, ImmutableSet<String> targetNames) throws ParseException { // If //foo/bar/... is passed in, we want to find all targets that start with // //foo/bar, and that are of the right type, and add them as root nodes ImmutableList<String> recursiveTargetPrefixes = targetNames.stream() .filter(name -> name.endsWith("/...") || name.endsWith(":")).map(name -> { int idx = name.lastIndexOf("/..."); if (idx != -1) { return name.substring(0, idx); } else { return name; } }).collect(ImmutableList.toImmutableList()); long startNanos = System.nanoTime(); int initialSize; try { initialSize = Math.toIntExact(filename.toFile().length() / THRIFT_STRUCT_SIZE); } catch (ArithmeticException e) { throw new ParseException(e, filename, "File size is too large (>2.1 billion objects would be deserialized"); } ImmutableMap.Builder<String, RuleKeyNode> rootNodesBuilder = ImmutableMap.builder(); Map<String, RuleKeyNode> rules = new HashMap<>(); try { reader.readFile(filename, ruleKey -> { RuleKeyNode newNode = new RuleKeyNode(ruleKey); if ("DEFAULT".equals(ruleKey.type)) { // If either a specific rule is present, or if the target starts with one of the // prefixes if (targetNames.contains(ruleKey.name) || recursiveTargetPrefixes.stream() .filter(prefix -> ruleKey.name.startsWith(prefix)).findFirst().isPresent()) { rootNodesBuilder.put(ruleKey.name, newNode); } } RuleKeyNode oldValue = rules.put(ruleKey.key, newNode); if (oldValue != null && !oldValue.ruleKey.equals(newNode.ruleKey)) { throw new RuntimeException(new ParseException(filename, "Found two rules with the same key, but different values. Key: %s, first value: " + "%s, second value: %s", ruleKey.key, oldValue.ruleKey, newNode.ruleKey)); } return false; }); } catch (RuntimeException e) { if (e.getCause() instanceof ParseException) { throw (ParseException) e.getCause(); } } ImmutableMap<String, RuleKeyNode> rootNodes = rootNodesBuilder.build(); for (String targetName : targetNames) { if (!targetName.endsWith("/...") && !targetName.endsWith(":") && !rootNodes.containsKey(targetName)) { throw new ParseException(filename, "Could not find %s in %s", targetName, filename); } } Duration runtime = Duration.ofNanos(System.nanoTime() - startNanos); return new ParsedRuleKeyFile(filename, rootNodes, rules, runtime); }
From source file:com.facebook.buck.android.AndroidBinaryBuildable.java
@SuppressWarnings("PMD.PrematureDeclaration") public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { SourcePathResolver pathResolver = context.getSourcePathResolver(); ImmutableList.Builder<Step> steps = ImmutableList.builder(); // The `HasInstallableApk` interface needs access to the manifest, so make sure we create our // own copy of this so that we don't have a runtime dep on the `AaptPackageResources` step. Path manifestPath = getManifestPath(); steps.add(MkdirStep.of(BuildCellRelativePath.fromCellRelativePath(context.getBuildCellRootPath(), getProjectFilesystem(), manifestPath.getParent()))); steps.add(CopyStep.forFile(getProjectFilesystem(), pathResolver.getRelativePath(androidManifestPath), manifestPath));/*from www . j a v a2 s . c om*/ buildableContext.recordArtifact(manifestPath); dexFilesInfo.proguardTextFilesPath.ifPresent(path -> { steps.add(createCopyProguardFilesStep(pathResolver, path)); }); ImmutableSet.Builder<Path> nativeLibraryDirectoriesBuilder = ImmutableSet.builder(); // Copy the transitive closure of native-libs-as-assets to a single directory, if any. ImmutableSet.Builder<Path> nativeLibraryAsAssetDirectories = ImmutableSet.builder(); ImmutableSet.Builder<Path> moduleResourcesDirectories = ImmutableSet.builder(); ImmutableSet.Builder<ModuleInfo> modulesInfo = ImmutableSet.builder(); ImmutableMap<String, SourcePath> mapOfModuleToSecondaryDexSourcePaths = dexFilesInfo .getMapOfModuleToSecondaryDexSourcePaths(); ModuleInfo.Builder baseModuleInfo = ModuleInfo.builder(); baseModuleInfo.setModuleName("base"); for (APKModule module : apkModules) { processModule(module, nativeLibraryDirectoriesBuilder, nativeLibraryAsAssetDirectories, moduleResourcesDirectories, steps, pathResolver, context, mapOfModuleToSecondaryDexSourcePaths, baseModuleInfo, modulesInfo); } // If non-english strings are to be stored as assets, pass them to ApkBuilder. ImmutableSet.Builder<Path> zipFiles = ImmutableSet.builder(); RichStream.from(resourceFilesInfo.primaryApkAssetsZips).map(pathResolver::getRelativePath) .forEach(zipFiles::add); if (ExopackageMode.enabledForNativeLibraries(exopackageModes) && !ExopackageMode.enabledForArch64(exopackageModes)) { // We need to include a few dummy native libraries with our application so that Android knows // to run it as 32-bit. Android defaults to 64-bit when no libraries are provided at all, // causing us to fail to load our 32-bit exopackage native libraries later. String fakeNativeLibraryBundle = System.getProperty("buck.native_exopackage_fake_path"); if (fakeNativeLibraryBundle == null) { throw new RuntimeException("fake native bundle not specified in properties"); } zipFiles.add(Paths.get(fakeNativeLibraryBundle)); } ImmutableSet<Path> allAssetDirectories = ImmutableSet.<Path>builder() .addAll(moduleResourcesDirectories.build()).addAll(nativeLibraryAsAssetDirectories.build()) .addAll(dexFilesInfo.getSecondaryDexDirs(getProjectFilesystem(), pathResolver)).build(); SourcePathResolver resolver = context.getSourcePathResolver(); Path signedApkPath = getSignedApkPath(); Path pathToKeystore = resolver.getAbsolutePath(keystorePath); Supplier<KeystoreProperties> keystoreProperties = getKeystorePropertiesSupplier(resolver, pathToKeystore); ImmutableSet<Path> thirdPartyJars = resourceFilesInfo.pathsToThirdPartyJars.stream() .map(resolver::getAbsolutePath).collect(ImmutableSet.toImmutableSet()); if (isApk) { steps.add(new ApkBuilderStep(getProjectFilesystem(), pathResolver.getAbsolutePath(resourceFilesInfo.resourcesApkPath), getSignedApkPath(), pathResolver.getRelativePath(dexFilesInfo.primaryDexPath), allAssetDirectories, nativeLibraryDirectoriesBuilder.build(), zipFiles.build(), thirdPartyJars, pathToKeystore, keystoreProperties, false, javaRuntimeLauncher.getCommandPrefix(pathResolver))); } else { ImmutableSet<String> moduleNames = apkModules.stream().map(APKModule::getName) .collect(ImmutableSet.toImmutableSet()); for (Path path : dexFilesInfo.getSecondaryDexDirs(getProjectFilesystem(), pathResolver)) { if (path.getFileName().toString().equals("additional_dexes")) { File[] assetFiles = path.toFile().listFiles(); if (assetFiles == null) { continue; } for (File assetFile : assetFiles) { if (!assetFile.getName().equals("assets")) { continue; } File[] modules = assetFile.listFiles(); if (modules == null) { continue; } for (File module : modules) { if (moduleNames.contains(module.getName())) { continue; } baseModuleInfo.putAssetDirectories(module.toPath(), "assets"); } } } else { baseModuleInfo.putAssetDirectories(path, ""); } } baseModuleInfo.setResourceApk(pathResolver.getAbsolutePath(resourceFilesInfo.resourcesApkPath)) .addDexFile(pathResolver.getRelativePath(dexFilesInfo.primaryDexPath)) .setJarFilesThatMayContainResources(thirdPartyJars).setZipFiles(zipFiles.build()); modulesInfo.add(baseModuleInfo.build()); steps.add(new AabBuilderStep(getProjectFilesystem(), getSignedApkPath(), buildTarget, false, modulesInfo.build(), moduleNames)); } // The `ApkBuilderStep` delegates to android tools to build a ZIP with timestamps in it, making // the output non-deterministic. So use an additional scrubbing step to zero these out. steps.add(ZipScrubberStep.of(getProjectFilesystem().resolve(signedApkPath))); Path apkToRedexAndAlign; // Optionally, compress the resources file in the .apk. if (isCompressResources) { Path compressedApkPath = getCompressedResourcesApkPath(); apkToRedexAndAlign = compressedApkPath; steps.add(createRepackZipEntriesStep(signedApkPath, compressedApkPath)); } else { apkToRedexAndAlign = signedApkPath; } boolean applyRedex = redexOptions.isPresent(); Path apkToAlign = apkToRedexAndAlign; Path v2SignedApkPath = getFinalApkPath(); if (applyRedex) { Path redexedApk = getRedexedApkPath(); apkToAlign = redexedApk; steps.addAll(createRedexSteps(context, buildableContext, resolver, keystoreProperties, apkToRedexAndAlign, redexedApk)); } if (isApk) { Path zipalignedApkPath = getZipalignedApkPath(); steps.add(new ZipalignStep(getProjectFilesystem().getRootPath(), androidPlatformTarget, apkToAlign, zipalignedApkPath)); steps.add(new ApkSignerStep(getProjectFilesystem(), zipalignedApkPath, v2SignedApkPath, keystoreProperties, applyRedex)); } else { steps.add(new ZipalignStep(getProjectFilesystem().getRootPath(), androidPlatformTarget, apkToAlign, v2SignedApkPath)); } buildableContext.recordArtifact(v2SignedApkPath); return steps.build(); }
From source file:com.facebook.buck.rules.CachingBuildRuleBuilder.java
private CacheResult tryToFetchArtifactFromBuildCacheAndOverlayOnTopOfProjectFilesystem(final RuleKey ruleKey, final ArtifactCache artifactCache, final ProjectFilesystem filesystem) throws IOException { if (!rule.isCacheable()) { return CacheResult.ignored(); }/*from ww w.j a v a2s. c om*/ // Create a temp file whose extension must be ".zip" for Filesystems.newFileSystem() to infer // that we are creating a zip-based FileSystem. final LazyPath lazyZipPath = new LazyPath() { @Override protected Path create() throws IOException { return Files.createTempFile( "buck_artifact_" + MoreFiles.sanitize(rule.getBuildTarget().getShortName()), ".zip"); } }; // TODO(mbolin): Change ArtifactCache.fetch() so that it returns a File instead of takes one. // Then we could download directly from the remote cache into the on-disk cache and unzip it // from there. CacheResult cacheResult = fetch(artifactCache, ruleKey, lazyZipPath); // Verify that the rule key we used to fetch the artifact is one of the rule keys reported in // it's metadata. if (cacheResult.getType().isSuccess()) { ImmutableSet<RuleKey> ruleKeys = RichStream.from(cacheResult.getMetadata().entrySet()) .filter(e -> BuildInfo.RULE_KEY_NAMES.contains(e.getKey())).map(Map.Entry::getValue) .map(RuleKey::new).toImmutableSet(); if (!ruleKeys.contains(ruleKey)) { LOG.warn("%s: rule keys in artifact don't match rule key used to fetch it: %s not in %s", rule.getBuildTarget(), ruleKey, ruleKeys); } } return unzipArtifactFromCacheResult(ruleKey, lazyZipPath, filesystem, cacheResult); }
From source file:com.maddyhome.idea.vim.group.ChangeGroup.java
/** * Delete the text covered by the motion command argument and enter insert mode * * @param editor The editor to change/* w ww.ja va 2s .c o m*/ * @param context The data context * @param count The number of time to repeat the change * @param rawCount The actual count entered by the user * @param argument The motion command * @return true if able to delete the text, false if not */ public boolean changeMotion(@NotNull Editor editor, @NotNull DataContext context, int count, int rawCount, @NotNull Argument argument) { // TODO: Hack - find better way to do this exceptional case - at least make constants out of these strings // Vim treats cw as ce and cW as cE if cursor is on a non-blank character String id = ActionManager.getInstance().getId(argument.getMotion().getAction()); boolean kludge = false; boolean bigWord = false; final CharSequence chars = editor.getDocument().getCharsSequence(); final int offset = editor.getCaretModel().getOffset(); final CharacterHelper.CharacterType charType = CharacterHelper.charType(chars.charAt(offset), false); if (EditorHelper.getFileSize(editor) > 0 && charType != CharacterHelper.CharacterType.WHITESPACE) { final boolean lastWordChar = offset <= EditorHelper.getFileSize(editor) ? CharacterHelper.charType(chars.charAt(offset + 1), false) != charType : true; final ImmutableSet<String> wordMotions = ImmutableSet.of("VimMotionWordRight", "VimMotionBigWordRight", "VimMotionCamelRight"); if (wordMotions.contains(id) && lastWordChar) { final boolean res = deleteCharacter(editor, 1, true); if (res) { insertBeforeCursor(editor, context); } return res; } if (id.equals("VimMotionWordRight")) { kludge = true; argument.getMotion().setAction(ActionManager.getInstance().getAction("VimMotionWordEndRight")); argument.getMotion().setFlags(Command.FLAG_MOT_INCLUSIVE); } else if (id.equals("VimMotionBigWordRight")) { kludge = true; bigWord = true; argument.getMotion().setAction(ActionManager.getInstance().getAction("VimMotionBigWordEndRight")); argument.getMotion().setFlags(Command.FLAG_MOT_INCLUSIVE); } else if (id.equals("VimMotionCamelRight")) { kludge = true; argument.getMotion().setAction(ActionManager.getInstance().getAction("VimMotionCamelEndRight")); argument.getMotion().setFlags(Command.FLAG_MOT_INCLUSIVE); } } if (kludge) { int pos = offset; int size = EditorHelper.getFileSize(editor); int cnt = count * argument.getMotion().getCount(); int pos1 = SearchHelper.findNextWordEnd(chars, pos, size, cnt, bigWord, false, false); int pos2 = SearchHelper.findNextWordEnd(chars, pos1, size, -cnt, bigWord, false, false); if (logger.isDebugEnabled()) { logger.debug("pos=" + pos); logger.debug("pos1=" + pos1); logger.debug("pos2=" + pos2); logger.debug("count=" + count); logger.debug("arg.count=" + argument.getMotion().getCount()); } if (pos2 == pos) { if (count > 1) { count--; rawCount--; } else if (argument.getMotion().getCount() > 1) { argument.getMotion().setCount(argument.getMotion().getCount() - 1); } else { argument.getMotion().setFlags(Command.FLAG_MOT_EXCLUSIVE); } } } boolean res = deleteMotion(editor, context, count, rawCount, argument, true); if (res) { insertBeforeCursor(editor, context); } return res; }