List of usage examples for com.google.common.collect ImmutableSortedMap naturalOrder
public static <K extends Comparable<?>, V> Builder<K, V> naturalOrder()
From source file:com.facebook.buck.features.rust.RustCompileUtils.java
/** * Collect all the shared libraries generated by {@link RustLinkable}s found by transitively * traversing all unbroken dependency chains of {@link * com.facebook.buck.features.rust.RustLinkable} objects found via the passed in {@link BuildRule} * roots.// w ww. j a va 2s. c o m * * @return a mapping of library name to the library {@link SourcePath}. */ public static Map<String, SourcePath> getTransitiveRustSharedLibraries(RustPlatform rustPlatform, Iterable<? extends BuildRule> inputs, boolean forceRlib) { ImmutableSortedMap.Builder<String, SourcePath> libs = ImmutableSortedMap.naturalOrder(); new AbstractBreadthFirstTraversal<BuildRule>(inputs) { @Override public Iterable<BuildRule> visit(BuildRule rule) { Iterable<BuildRule> deps = ImmutableSet.of(); if (rule instanceof RustLinkable) { RustLinkable rustLinkable = (RustLinkable) rule; if (!rustLinkable.isProcMacro()) { deps = rustLinkable.getRustLinakbleDeps(rustPlatform); if (!forceRlib && rustLinkable.getPreferredLinkage() != NativeLinkable.Linkage.STATIC) { libs.putAll(rustLinkable.getRustSharedLibraries(rustPlatform)); } } } return deps; } }.start(); return libs.build(); }
From source file:com.facebook.buck.maven.Resolver.java
private ImmutableMap<String, Artifact> getRunTimeTransitiveDeps(Iterable<Dependency> mavenCoords) throws RepositoryException { CollectRequest collectRequest = new CollectRequest(); collectRequest.setRequestContext(JavaScopes.RUNTIME); collectRequest.setRepositories(repos); for (Dependency dep : mavenCoords) { collectRequest.addDependency(dep); }/* w w w . j a v a 2 s. c o m*/ DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, filter); DependencyResult dependencyResult = repoSys.resolveDependencies(session, dependencyRequest); ImmutableSortedMap.Builder<String, Artifact> knownDeps = ImmutableSortedMap.naturalOrder(); for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) { Artifact node = artifactResult.getArtifact(); knownDeps.put(buildKey(node), node); } return knownDeps.build(); }
From source file:com.facebook.buck.apple.ProjectGenerator.java
private ImmutableSortedMap<Path, SourcePath> convertMapKeysToPaths( ImmutableSortedMap<String, SourcePath> input) { ImmutableSortedMap.Builder<Path, SourcePath> output = ImmutableSortedMap.naturalOrder(); for (Map.Entry<String, SourcePath> entry : input.entrySet()) { output.put(Paths.get(entry.getKey()), entry.getValue()); }/*from w w w.j a va 2 s . c o m*/ return output.build(); }
From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java
protected ImmutableSortedMap<LockDescriptor, LockMode> getLocksForWrites() { Builder<LockDescriptor, LockMode> builder = ImmutableSortedMap.naturalOrder(); Iterable<String> allTables = IterableUtils.append(writesByTable.keySet(), TransactionConstants.TRANSACTION_TABLE); for (String tableName : allTables) { if (tableName.equals(TransactionConstants.TRANSACTION_TABLE)) { builder.put(AtlasRowLockDescriptor.of(TransactionConstants.TRANSACTION_TABLE, TransactionConstants.getValueForTimestamp(getStartTimestamp())), LockMode.WRITE); continue; }/* w w w .j a v a2 s .com*/ ConflictHandler conflictHandler = getConflictHandlerForTable(tableName); if (conflictHandler == ConflictHandler.RETRY_ON_WRITE_WRITE_CELL) { for (Cell cell : getLocalWrites(tableName).keySet()) { builder.put(AtlasCellLockDescriptor.of(tableName, cell.getRowName(), cell.getColumnName()), LockMode.WRITE); } } else if (conflictHandler != ConflictHandler.IGNORE_ALL) { Cell lastCell = null; for (Cell cell : getLocalWrites(tableName).keySet()) { if (lastCell == null || !Arrays.equals(lastCell.getRowName(), cell.getRowName())) { builder.put(AtlasRowLockDescriptor.of(tableName, cell.getRowName()), LockMode.WRITE); } lastCell = cell; } } } return builder.build(); }
From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java
/** * We will block here until the passed transactions have released their lock. This means that * the committing transaction is either complete or it has failed and we are allowed to roll * it back./*from w w w . ja va2 s . c o m*/ */ private void waitForCommitToComplete(Iterable<Long> startTimestamps) { boolean isEmpty = true; Builder<LockDescriptor, LockMode> builder = ImmutableSortedMap.naturalOrder(); for (long start : startTimestamps) { if (start < immutableTimestamp) { // We don't need to block in this case because this transaction is already complete continue; } isEmpty = false; builder.put(AtlasRowLockDescriptor.of(TransactionConstants.TRANSACTION_TABLE, TransactionConstants.getValueForTimestamp(start)), LockMode.READ); } if (isEmpty) { return; } // TODO: This can have better performance if we have a blockAndReturn method in lock server // However lock server blocking is an issue if we fill up all our requests try { lockService.lockAnonymously(LockRequest.builder(builder.build()).lockAndRelease().build()); } catch (InterruptedException e) { throw Throwables.throwUncheckedException(e); } }
From source file:com.facebook.buck.apple.ProjectGenerator.java
private void createHeaderSymlinkTree(Function<SourcePath, Path> pathResolver, Map<Path, SourcePath> contents, Path headerSymlinkTreeRoot) 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); }/* ww w . j a va 2 s .c o 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).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); 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()) { headerMapBuilder.add(entry.getKey().toString(), BuckConstant.BUCK_OUTPUT_PATH.relativize(headerSymlinkTreeRoot).resolve(entry.getKey())); } projectFilesystem.writeBytesToPath(headerMapBuilder.build().getBytes(), headerMapLocation); } headerSymlinkTrees.add(headerSymlinkTreeRoot); }
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 va 2 s . c o 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
private ImmutableSortedMap<Path, SourcePath> getPublicCxxHeaders( TargetNode<? extends CxxLibraryDescription.CommonArg> targetNode) { CxxLibraryDescription.CommonArg arg = targetNode.getConstructorArg(); if (arg instanceof AppleNativeTargetDescriptionArg) { Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix((AppleNativeTargetDescriptionArg) arg, targetNode.getBuildTarget()); ImmutableSortedMap.Builder<String, SourcePath> exportedHeadersBuilder = ImmutableSortedMap .naturalOrder();/*from ww w.j a v a2s . c om*/ exportedHeadersBuilder .putAll(AppleDescriptions.convertHeadersToPublicCxxHeaders(targetNode.getBuildTarget(), this::resolveSourcePath, headerPathPrefix, arg.getExportedHeaders())); for (Pair<Pattern, SourceSortedSet> patternMatchedHeader : arg.getExportedPlatformHeaders() .getPatternsAndValues()) { exportedHeadersBuilder .putAll(AppleDescriptions.convertHeadersToPublicCxxHeaders(targetNode.getBuildTarget(), this::resolveSourcePath, headerPathPrefix, patternMatchedHeader.getSecond())); } ImmutableSortedMap<String, SourcePath> fullExportedHeaders = exportedHeadersBuilder.build(); return convertMapKeysToPaths(fullExportedHeaders); } else { ActionGraphBuilder graphBuilder = actionGraphBuilderForNode.apply(targetNode); SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder); SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder); ImmutableSortedMap.Builder<Path, SourcePath> allHeadersBuilder = ImmutableSortedMap.naturalOrder(); String platform = defaultCxxPlatform.getFlavor().toString(); ImmutableList<SourceSortedSet> platformHeaders = arg.getExportedPlatformHeaders() .getMatchingValues(platform); return allHeadersBuilder .putAll(CxxDescriptionEnhancer.parseExportedHeaders(targetNode.getBuildTarget(), graphBuilder, ruleFinder, pathResolver, Optional.empty(), arg)) .putAll(ProjectGenerator.parseAllPlatformHeaders(targetNode.getBuildTarget(), pathResolver, platformHeaders, true, arg)) .build(); } }
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
private ImmutableSortedMap<Path, SourcePath> getPrivateCxxHeaders( TargetNode<? extends CxxLibraryDescription.CommonArg> targetNode) { CxxLibraryDescription.CommonArg arg = targetNode.getConstructorArg(); if (arg instanceof AppleNativeTargetDescriptionArg) { Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix((AppleNativeTargetDescriptionArg) arg, targetNode.getBuildTarget()); ImmutableSortedMap.Builder<String, SourcePath> fullHeadersBuilder = ImmutableSortedMap.naturalOrder(); fullHeadersBuilder/* w w w. j ava 2 s . com*/ .putAll(AppleDescriptions.convertHeadersToPrivateCxxHeaders(targetNode.getBuildTarget(), this::resolveSourcePath, headerPathPrefix, arg.getHeaders(), arg.getExportedHeaders())); for (Pair<Pattern, SourceSortedSet> patternMatchedHeader : arg.getExportedPlatformHeaders() .getPatternsAndValues()) { fullHeadersBuilder.putAll(AppleDescriptions.convertHeadersToPrivateCxxHeaders( targetNode.getBuildTarget(), this::resolveSourcePath, headerPathPrefix, SourceSortedSet.ofNamedSources(ImmutableSortedMap.of()), patternMatchedHeader.getSecond())); } for (Pair<Pattern, SourceSortedSet> patternMatchedHeader : arg.getPlatformHeaders() .getPatternsAndValues()) { fullHeadersBuilder.putAll(AppleDescriptions.convertHeadersToPrivateCxxHeaders( targetNode.getBuildTarget(), this::resolveSourcePath, headerPathPrefix, patternMatchedHeader.getSecond(), SourceSortedSet.ofNamedSources(ImmutableSortedMap.of()))); } ImmutableSortedMap<String, SourcePath> fullHeaders = fullHeadersBuilder.build(); return convertMapKeysToPaths(fullHeaders); } else { ActionGraphBuilder graphBuilder = actionGraphBuilderForNode.apply(targetNode); SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder); SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder); ImmutableSortedMap.Builder<Path, SourcePath> allHeadersBuilder = ImmutableSortedMap.naturalOrder(); String platform = defaultCxxPlatform.getFlavor().toString(); ImmutableList<SourceSortedSet> platformHeaders = arg.getPlatformHeaders().getMatchingValues(platform); return allHeadersBuilder .putAll(CxxDescriptionEnhancer.parseHeaders(targetNode.getBuildTarget(), graphBuilder, ruleFinder, pathResolver, Optional.empty(), arg)) .putAll(ProjectGenerator.parseAllPlatformHeaders(targetNode.getBuildTarget(), pathResolver, platformHeaders, false, arg)) .build(); } }
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
private Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> getXcodeBuildConfigurationsForTargetNode( TargetNode<?> targetNode) { Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> configs = Optional.empty(); Optional<TargetNode<AppleNativeTargetDescriptionArg>> appleTargetNode = TargetNodes.castArg(targetNode, AppleNativeTargetDescriptionArg.class); Optional<TargetNode<HalideLibraryDescriptionArg>> halideTargetNode = TargetNodes.castArg(targetNode, HalideLibraryDescriptionArg.class); if (appleTargetNode.isPresent()) { configs = Optional.of(appleTargetNode.get().getConstructorArg().getConfigs()); } else if (halideTargetNode.isPresent()) { configs = Optional.of(halideTargetNode.get().getConstructorArg().getConfigs()); }//from www .j av a 2 s . c o m HashMap<String, HashMap<String, String>> combinedConfig = new HashMap<String, HashMap<String, String>>(); combinedConfig.put(CxxPlatformXcodeConfigGenerator.DEBUG_BUILD_CONFIGURATION_NAME, new HashMap<String, String>(getDefaultDebugBuildConfiguration())); combinedConfig.put(CxxPlatformXcodeConfigGenerator.PROFILE_BUILD_CONFIGURATION_NAME, new HashMap<String, String>()); combinedConfig.put(CxxPlatformXcodeConfigGenerator.RELEASE_BUILD_CONFIGURATION_NAME, new HashMap<String, String>()); if (configs.isPresent() && !configs.get().isEmpty() && !(targetNode.getDescription() instanceof CxxLibraryDescription)) { for (Map.Entry<String, ImmutableMap<String, String>> targetLevelConfig : configs.get().entrySet()) { HashMap<String, String> pendingConfig = new HashMap<String, String>(targetLevelConfig.getValue()); String configTarget = targetLevelConfig.getKey(); if (combinedConfig.containsKey(configTarget)) { combinedConfig.get(configTarget).putAll(pendingConfig); } else { combinedConfig.put(configTarget, pendingConfig); } } } ImmutableSortedMap.Builder<String, ImmutableMap<String, String>> configBuilder = ImmutableSortedMap .naturalOrder(); for (Map.Entry<String, HashMap<String, String>> config : combinedConfig.entrySet()) { configBuilder.put(config.getKey(), ImmutableMap.copyOf(config.getValue())); } return Optional.of(configBuilder.build()); }