List of usage examples for com.google.common.collect ImmutableSortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:com.facebook.buck.apple.project_generator.ProjectGenerator.java
private void createHeaderSymlinkTree(Function<SourcePath, Path> pathResolver, Map<Path, SourcePath> contents, Path headerSymlinkTreeRoot, boolean shouldCreateHeadersSymlinks) throws IOException { LOG.verbose("Building header symlink tree at %s with contents %s", headerSymlinkTreeRoot, contents); ImmutableSortedMap.Builder<Path, Path> resolvedContentsBuilder = ImmutableSortedMap.naturalOrder(); for (Map.Entry<Path, SourcePath> entry : contents.entrySet()) { Path link = headerSymlinkTreeRoot.resolve(entry.getKey()); Path existing = projectFilesystem.resolve(pathResolver.apply(entry.getValue())); resolvedContentsBuilder.put(link, existing); }/*from w w w .j a va2 s. co m*/ ImmutableSortedMap<Path, Path> resolvedContents = resolvedContentsBuilder.build(); Path headerMapLocation = getHeaderMapLocationFromSymlinkTreeRoot(headerSymlinkTreeRoot); Path hashCodeFilePath = headerSymlinkTreeRoot.resolve(".contents-hash"); Optional<String> currentHashCode = projectFilesystem.readFileIfItExists(hashCodeFilePath); String newHashCode = getHeaderSymlinkTreeHashCode(resolvedContents, shouldCreateHeadersSymlinks).toString(); if (Optional.of(newHashCode).equals(currentHashCode)) { LOG.debug("Symlink tree at %s is up to date, not regenerating (key %s).", headerSymlinkTreeRoot, newHashCode); } else { LOG.debug("Updating symlink tree at %s (old key %s, new key %s).", headerSymlinkTreeRoot, currentHashCode, newHashCode); projectFilesystem.deleteRecursivelyIfExists(headerSymlinkTreeRoot); projectFilesystem.mkdirs(headerSymlinkTreeRoot); if (shouldCreateHeadersSymlinks) { for (Map.Entry<Path, Path> entry : resolvedContents.entrySet()) { Path link = entry.getKey(); Path existing = entry.getValue(); projectFilesystem.createParentDirs(link); projectFilesystem.createSymLink(link, existing, /* force */ false); } } projectFilesystem.writeContentsToPath(newHashCode, hashCodeFilePath); HeaderMap.Builder headerMapBuilder = new HeaderMap.Builder(); for (Map.Entry<Path, SourcePath> entry : contents.entrySet()) { if (shouldCreateHeadersSymlinks) { headerMapBuilder.add(entry.getKey().toString(), Paths.get("../../").resolve(projectCell.getRoot().getFileName()) .resolve(headerSymlinkTreeRoot).resolve(entry.getKey())); } else { headerMapBuilder.add(entry.getKey().toString(), projectFilesystem.resolve(pathResolver.apply(entry.getValue()))); } } projectFilesystem.writeBytesToPath(headerMapBuilder.build().getBytes(), headerMapLocation); } headerSymlinkTrees.add(headerSymlinkTreeRoot); }
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
/** * Create target level configuration entries. * * @param target Xcode target for which the configurations will be set. * @param targetGroup Xcode group in which the configuration file references will be placed. * @param configurations Configurations as extracted from the BUCK file. * @param overrideBuildSettings Build settings that will override ones defined elsewhere. * @param defaultBuildSettings Target-inline level build settings that will be set if not already * defined./*from w ww . ja v a 2 s .c o m*/ * @param appendBuildSettings Target-inline level build settings that will incorporate the * existing value or values at a higher level. */ private void setTargetBuildConfigurations(BuildTarget buildTarget, PBXTarget target, PBXGroup targetGroup, ImmutableMap<String, ImmutableMap<String, String>> configurations, ImmutableMap<String, String> cxxPlatformXcodeBuildSettings, ImmutableMap<String, String> overrideBuildSettings, ImmutableMap<String, String> defaultBuildSettings, ImmutableMap<String, String> appendBuildSettings) throws IOException { if (options.shouldGenerateHeaderSymlinkTreesOnly()) { return; } for (Map.Entry<String, ImmutableMap<String, String>> configurationEntry : configurations.entrySet()) { targetConfigNamesBuilder.add(configurationEntry.getKey()); ImmutableMap<String, String> targetLevelInlineSettings = configurationEntry.getValue(); XCBuildConfiguration outputConfiguration = target.getBuildConfigurationList() .getBuildConfigurationsByName().getUnchecked(configurationEntry.getKey()); HashMap<String, String> combinedOverrideConfigs = new HashMap<>(overrideBuildSettings); for (Map.Entry<String, String> entry : cxxPlatformXcodeBuildSettings.entrySet()) { String existingSetting = targetLevelInlineSettings.get(entry.getKey()); if (existingSetting == null) { combinedOverrideConfigs.put(entry.getKey(), entry.getValue()); } } for (Map.Entry<String, String> entry : defaultBuildSettings.entrySet()) { String existingSetting = targetLevelInlineSettings.get(entry.getKey()); if (existingSetting == null) { combinedOverrideConfigs.put(entry.getKey(), entry.getValue()); } } for (Map.Entry<String, String> entry : appendBuildSettings.entrySet()) { String existingSetting = targetLevelInlineSettings.get(entry.getKey()); String settingPrefix = existingSetting != null ? existingSetting : "$(inherited)"; combinedOverrideConfigs.put(entry.getKey(), settingPrefix + " " + entry.getValue()); } ImmutableSortedMap<String, String> mergedSettings = MoreMaps.mergeSorted(targetLevelInlineSettings, combinedOverrideConfigs); Path xcconfigPath = getConfigurationXcconfigPath(buildTarget, configurationEntry.getKey()); projectFilesystem.mkdirs(Objects.requireNonNull(xcconfigPath).getParent()); StringBuilder stringBuilder = new StringBuilder(); for (Map.Entry<String, String> entry : mergedSettings.entrySet()) { stringBuilder.append(entry.getKey()); stringBuilder.append(" = "); stringBuilder.append(entry.getValue()); stringBuilder.append('\n'); } String xcconfigContents = stringBuilder.toString(); if (MoreProjectFilesystems.fileContentsDiffer( new ByteArrayInputStream(xcconfigContents.getBytes(Charsets.UTF_8)), xcconfigPath, projectFilesystem)) { if (options.shouldGenerateReadOnlyFiles()) { projectFilesystem.writeContentsToPath(xcconfigContents, xcconfigPath, READ_ONLY_FILE_ATTRIBUTE); } else { projectFilesystem.writeContentsToPath(xcconfigContents, xcconfigPath); } } PBXFileReference fileReference = getConfigurationFileReference(targetGroup, xcconfigPath); outputConfiguration.setBaseConfigurationReference(fileReference); xcconfigPathsBuilder.add(projectFilesystem.getPathForRelativePath(xcconfigPath).toAbsolutePath()); } }
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
private HashCode getHeaderSymlinkTreeHashCode(ImmutableSortedMap<Path, Path> contents, Optional<String> moduleName, boolean shouldCreateHeadersSymlinks, boolean shouldCreateHeaderMap) { Hasher hasher = Hashing.sha1().newHasher(); hasher.putBytes(ruleKeyConfiguration.getCoreKey().getBytes(Charsets.UTF_8)); String symlinkState = shouldCreateHeadersSymlinks ? "symlinks-enabled" : "symlinks-disabled"; byte[] symlinkStateValue = symlinkState.getBytes(Charsets.UTF_8); hasher.putInt(symlinkStateValue.length); hasher.putBytes(symlinkStateValue);//from w ww .ja va 2s.c om String hmapState = shouldCreateHeaderMap ? "hmap-enabled" : "hmap-disabled"; byte[] hmapStateValue = hmapState.getBytes(Charsets.UTF_8); hasher.putInt(hmapStateValue.length); hasher.putBytes(hmapStateValue); if (moduleName.isPresent()) { byte[] moduleNameValue = moduleName.get().getBytes(Charsets.UTF_8); hasher.putInt(moduleNameValue.length); hasher.putBytes(moduleNameValue); } hasher.putInt(0); for (Map.Entry<Path, Path> entry : contents.entrySet()) { byte[] key = entry.getKey().toString().getBytes(Charsets.UTF_8); byte[] value = entry.getValue().toString().getBytes(Charsets.UTF_8); hasher.putInt(key.length); hasher.putBytes(key); hasher.putInt(value.length); hasher.putBytes(value); } return hasher.hash(); }
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
private void createHeaderSymlinkTree(Map<Path, SourcePath> contents, ImmutableMap<Path, Path> nonSourcePaths, Optional<String> moduleName, Path headerSymlinkTreeRoot, boolean shouldCreateHeadersSymlinks, boolean shouldCreateHeaderMap, boolean shouldGenerateUmbrellaHeaderIfMissing) throws IOException { if (!shouldCreateHeaderMap && !shouldCreateHeadersSymlinks) { return;/* ww w . j ava2 s . c o m*/ } LOG.verbose("Building header symlink tree at %s with contents %s", headerSymlinkTreeRoot, contents); ImmutableSortedMap.Builder<Path, Path> resolvedContentsBuilder = ImmutableSortedMap.naturalOrder(); for (Map.Entry<Path, SourcePath> entry : contents.entrySet()) { Path link = headerSymlinkTreeRoot.resolve(entry.getKey()); Path existing = projectFilesystem.resolve(resolveSourcePath(entry.getValue())); resolvedContentsBuilder.put(link, existing); } for (Map.Entry<Path, Path> entry : nonSourcePaths.entrySet()) { Path link = headerSymlinkTreeRoot.resolve(entry.getKey()); resolvedContentsBuilder.put(link, entry.getValue()); } ImmutableSortedMap<Path, Path> resolvedContents = resolvedContentsBuilder.build(); Path headerMapLocation = getHeaderMapLocationFromSymlinkTreeRoot(headerSymlinkTreeRoot); Path hashCodeFilePath = headerSymlinkTreeRoot.resolve(".contents-hash"); Optional<String> currentHashCode = projectFilesystem.readFileIfItExists(hashCodeFilePath); String newHashCode = getHeaderSymlinkTreeHashCode(resolvedContents, moduleName, shouldCreateHeadersSymlinks, shouldCreateHeaderMap).toString(); if (Optional.of(newHashCode).equals(currentHashCode)) { LOG.debug("Symlink tree at %s is up to date, not regenerating (key %s).", headerSymlinkTreeRoot, newHashCode); } else { LOG.debug("Updating symlink tree at %s (old key %s, new key %s).", headerSymlinkTreeRoot, currentHashCode, newHashCode); projectFilesystem.deleteRecursivelyIfExists(headerSymlinkTreeRoot); projectFilesystem.mkdirs(headerSymlinkTreeRoot); if (shouldCreateHeadersSymlinks) { for (Map.Entry<Path, Path> entry : resolvedContents.entrySet()) { Path link = entry.getKey(); Path existing = entry.getValue(); projectFilesystem.createParentDirs(link); projectFilesystem.createSymLink(link, existing, /* force */ false); } } projectFilesystem.writeContentsToPath(newHashCode, hashCodeFilePath); if (shouldCreateHeaderMap) { HeaderMap.Builder headerMapBuilder = new HeaderMap.Builder(); for (Map.Entry<Path, SourcePath> entry : contents.entrySet()) { if (shouldCreateHeadersSymlinks) { headerMapBuilder.add(entry.getKey().toString(), getHeaderMapRelativeSymlinkPathForEntry(entry, headerSymlinkTreeRoot)); } else { headerMapBuilder.add(entry.getKey().toString(), projectFilesystem.resolve(resolveSourcePath(entry.getValue()))); } } for (Map.Entry<Path, Path> entry : nonSourcePaths.entrySet()) { if (shouldCreateHeadersSymlinks) { headerMapBuilder.add(entry.getKey().toString(), getHeaderMapRelativeSymlinkPathForEntry(entry, headerSymlinkTreeRoot)); } else { headerMapBuilder.add(entry.getKey().toString(), entry.getValue()); } } projectFilesystem.writeBytesToPath(headerMapBuilder.build().getBytes(), headerMapLocation); } if (moduleName.isPresent() && resolvedContents.size() > 0) { if (shouldGenerateUmbrellaHeaderIfMissing) { writeUmbrellaHeaderIfNeeded(moduleName.get(), resolvedContents.keySet(), headerSymlinkTreeRoot); } boolean containsSwift = !nonSourcePaths.isEmpty(); if (containsSwift) { projectFilesystem.writeContentsToPath( new ModuleMap(moduleName.get(), ModuleMap.SwiftMode.INCLUDE_SWIFT_HEADER).render(), headerSymlinkTreeRoot.resolve(moduleName.get()).resolve("module.modulemap")); projectFilesystem.writeContentsToPath( new ModuleMap(moduleName.get(), ModuleMap.SwiftMode.EXCLUDE_SWIFT_HEADER).render(), headerSymlinkTreeRoot.resolve(moduleName.get()).resolve("objc.modulemap")); Path absoluteModuleRoot = projectFilesystem.getRootPath() .resolve(headerSymlinkTreeRoot.resolve(moduleName.get())); VFSOverlay vfsOverlay = new VFSOverlay( ImmutableSortedMap.of(absoluteModuleRoot.resolve("module.modulemap"), absoluteModuleRoot.resolve("objc.modulemap"))); projectFilesystem.writeContentsToPath(vfsOverlay.render(), getObjcModulemapVFSOverlayLocationFromSymlinkTreeRoot(headerSymlinkTreeRoot)); } else { projectFilesystem.writeContentsToPath( new ModuleMap(moduleName.get(), ModuleMap.SwiftMode.NO_SWIFT).render(), headerSymlinkTreeRoot.resolve(moduleName.get()).resolve("module.modulemap")); } Path absoluteModuleRoot = projectFilesystem.getRootPath() .resolve(headerSymlinkTreeRoot.resolve(moduleName.get())); VFSOverlay vfsOverlay = new VFSOverlay( ImmutableSortedMap.of(absoluteModuleRoot.resolve("module.modulemap"), absoluteModuleRoot.resolve("testing.modulemap"))); projectFilesystem.writeContentsToPath(vfsOverlay.render(), getTestingModulemapVFSOverlayLocationFromSymlinkTreeRoot(headerSymlinkTreeRoot)); projectFilesystem.writeContentsToPath("", // empty modulemap to allow non-modular imports for testing headerSymlinkTreeRoot.resolve(moduleName.get()).resolve("testing.modulemap")); } } headerSymlinkTrees.add(headerSymlinkTreeRoot); }