use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.
the class ProgressEstimatorTest method testUpdatesStorageWithProjectGenerationEstimationsAfterCommandInvocation.
@Test
public void testUpdatesStorageWithProjectGenerationEstimationsAfterCommandInvocation() throws IOException {
Path storagePath = getStorageForTest();
Map<String, Object> storageContents = ImmutableSortedMap.<String, Object>naturalOrder().put("project arg1 arg2", ImmutableSortedMap.<String, Number>naturalOrder().put(ProgressEstimator.EXPECTED_NUMBER_OF_GENERATED_PROJECT_FILES, 10).build()).build();
String contents = MAPPER.writeValueAsString(storageContents);
Files.write(storagePath, contents.getBytes(StandardCharsets.UTF_8));
// path is 2 levels up folder
ProgressEstimator estimator = new ProgressEstimator(storagePath, getBuckEventBus(), MAPPER);
estimator.setCurrentCommand("project", ImmutableList.of("arg1", "arg2"));
estimator.didGenerateProjectForTarget();
estimator.didGenerateProjectForTarget();
estimator.didGenerateProjectForTarget();
estimator.didFinishProjectGeneration();
Map<String, Map<String, Number>> jsonObject = MAPPER.readValue(Files.readAllBytes(storagePath), new TypeReference<HashMap<String, Map<String, Number>>>() {
});
Map<String, Number> storedValues = jsonObject.get("project arg1 arg2");
assertThat(storedValues.get(ProgressEstimator.EXPECTED_NUMBER_OF_GENERATED_PROJECT_FILES).intValue(), Matchers.equalTo(3));
}
use of com.google.common.collect.ImmutableSortedMap in project bazel by bazelbuild.
the class CcIncLibrary method create.
@Override
public ConfiguredTarget create(final RuleContext ruleContext) throws RuleErrorException, InterruptedException {
CcToolchainProvider ccToolchain = CppHelper.getToolchain(ruleContext, ":cc_toolchain");
FeatureConfiguration featureConfiguration = CcCommon.configureFeatures(ruleContext, ccToolchain);
PathFragment packageFragment = ruleContext.getPackageDirectory();
// The rule needs a unique location for the include directory, which doesn't conflict with any
// other rule. For that reason, the include directory is at:
// configuration/package_name/_/target_name
// And then the symlink is placed at:
// configuration/package_name/_/target_name/package_name
// So that these inclusions can be resolved correctly:
// #include "package_name/a.h"
//
// The target of the symlink is:
// package_name/targetPrefix/
// All declared header files must be below that directory.
String expandedIncSymlinkAttr = ruleContext.attributes().get("prefix", Type.STRING);
// We use an additional "_" directory here to avoid conflicts between this and previous Blaze
// versions. Previous Blaze versions created a directory symlink; the new version does not
// detect that the output directory isn't a directory, and tries to put the symlinks into what
// is actually a symlink into the source tree.
PathFragment includeDirectory = new PathFragment("_").getRelative(ruleContext.getTarget().getName());
Root configIncludeDirectory = ruleContext.getConfiguration().getIncludeDirectory(ruleContext.getRule().getRepository());
PathFragment includePath = configIncludeDirectory.getExecPath().getRelative(packageFragment).getRelative(includeDirectory);
Path includeRoot = configIncludeDirectory.getPath().getRelative(packageFragment).getRelative(includeDirectory);
// For every source artifact, we compute a virtual artifact that is below the include directory.
// These are used for include checking.
PathFragment prefixFragment = packageFragment.getRelative(expandedIncSymlinkAttr);
if (!prefixFragment.isNormalized()) {
ruleContext.attributeWarning("prefix", "should not contain '.' or '..' elements");
}
ImmutableSortedMap.Builder<Artifact, Artifact> virtualArtifactMapBuilder = ImmutableSortedMap.orderedBy(Artifact.EXEC_PATH_COMPARATOR);
prefixFragment = prefixFragment.normalize();
ImmutableList<Artifact> hdrs = ruleContext.getPrerequisiteArtifacts("hdrs", Mode.TARGET).list();
for (Artifact src : hdrs) {
// All declared header files must start with package/targetPrefix.
if (!src.getRootRelativePath().startsWith(prefixFragment)) {
ruleContext.attributeError("hdrs", src + " does not start with '" + prefixFragment.getPathString() + "'");
return null;
}
// Remove the targetPrefix from within the exec path of the source file, and prepend the
// unique directory prefix, e.g.:
// third_party/foo/1.2/bar/a.h -> third_party/foo/name/third_party/foo/bar/a.h
PathFragment suffix = src.getRootRelativePath().relativeTo(prefixFragment);
PathFragment virtualPath = includeDirectory.getRelative(packageFragment).getRelative(suffix);
// These virtual artifacts have the symlink action as generating action.
Artifact virtualArtifact = ruleContext.getPackageRelativeArtifact(virtualPath, configIncludeDirectory);
virtualArtifactMapBuilder.put(virtualArtifact, src);
}
ImmutableSortedMap<Artifact, Artifact> virtualArtifactMap = virtualArtifactMapBuilder.build();
ruleContext.registerAction(new CreateIncSymlinkAction(ruleContext.getActionOwner(), virtualArtifactMap, includeRoot));
FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":cc_toolchain");
CcLibraryHelper.Info info = new CcLibraryHelper(ruleContext, semantics, featureConfiguration, ccToolchain, fdoSupport).addIncludeDirs(Arrays.asList(includePath)).addPublicHeaders(virtualArtifactMap.keySet()).addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET)).build();
// cc_inc_library doesn't compile any file - no compilation outputs available.
InstrumentedFilesProvider instrumentedFilesProvider = new CcCommon(ruleContext).getInstrumentedFilesProvider(new ArrayList<Artifact>(), /*withBaselineCoverage=*/
true);
return new RuleConfiguredTargetBuilder(ruleContext).addProviders(info.getProviders()).addSkylarkTransitiveInfo(CcSkylarkApiProvider.NAME, new CcSkylarkApiProvider()).addOutputGroups(info.getOutputGroups()).add(InstrumentedFilesProvider.class, instrumentedFilesProvider).add(RunfilesProvider.class, RunfilesProvider.simple(Runfiles.EMPTY)).build();
}
use of com.google.common.collect.ImmutableSortedMap in project gradle by gradle.
the class AbstractNamedFileSnapshotTaskStateChanges method buildSnapshots.
protected static ImmutableSortedMap<String, FileCollectionSnapshot> buildSnapshots(String taskName, FileCollectionSnapshotterRegistry snapshotterRegistry, String title, SortedSet<? extends TaskFilePropertySpec> fileProperties) {
ImmutableSortedMap.Builder<String, FileCollectionSnapshot> builder = ImmutableSortedMap.naturalOrder();
for (TaskFilePropertySpec propertySpec : fileProperties) {
FileCollectionSnapshot result;
try {
FileCollectionSnapshotter snapshotter = snapshotterRegistry.getSnapshotter(propertySpec.getSnapshotter());
result = snapshotter.snapshot(propertySpec.getPropertyFiles(), propertySpec.getCompareStrategy(), propertySpec.getSnapshotNormalizationStrategy());
} catch (UncheckedIOException e) {
throw new UncheckedIOException(String.format("Failed to capture snapshot of %s files for task '%s' property '%s' during up-to-date check.", title.toLowerCase(), taskName, propertySpec.getPropertyName()), e);
}
builder.put(propertySpec.getPropertyName(), result);
}
return builder.build();
}
use of com.google.common.collect.ImmutableSortedMap in project gerrit by GerritCodeReview.
the class ChangeNotes method getPatchSets.
public ImmutableSortedMap<PatchSet.Id, PatchSet> getPatchSets() {
if (patchSets == null) {
ImmutableSortedMap.Builder<PatchSet.Id, PatchSet> b = ImmutableSortedMap.orderedBy(comparing(PatchSet.Id::get));
for (Map.Entry<PatchSet.Id, PatchSet> e : state.patchSets()) {
b.put(e.getKey(), new PatchSet(e.getValue()));
}
patchSets = b.build();
}
return patchSets;
}
use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.
the class TargetsCommand method getMatchingNodes.
/**
* @param graph Graph used to resolve dependencies between targets and find all build files.
* @param referencedFiles If present, the result will be limited to the nodes that transitively
* depend on at least one of those.
* @param matchingBuildTargets If present, the result will be limited to the specified targets.
* @param buildRuleTypes If present, the result will be limited to targets with the specified
* types.
* @param detectTestChanges If true, tests are considered to be dependencies of the targets they
* are testing.
* @return A map of target names to target nodes.
*/
@VisibleForTesting
ImmutableSortedMap<String, TargetNode<?, ?>> getMatchingNodes(TargetGraph graph, Optional<ImmutableSet<Path>> referencedFiles, final Optional<ImmutableSet<BuildTarget>> matchingBuildTargets, final Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses, boolean detectTestChanges, String buildFileName) {
ImmutableSet<TargetNode<?, ?>> directOwners;
if (referencedFiles.isPresent()) {
BuildFileTree buildFileTree = new InMemoryBuildFileTree(graph.getNodes().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()));
directOwners = FluentIterable.from(graph.getNodes()).filter(new DirectOwnerPredicate(buildFileTree, referencedFiles.get(), buildFileName)).toSet();
} else {
directOwners = graph.getNodes();
}
Iterable<TargetNode<?, ?>> selectedReferrers = FluentIterable.from(getDependentNodes(graph, directOwners, detectTestChanges)).filter(targetNode -> {
if (matchingBuildTargets.isPresent() && !matchingBuildTargets.get().contains(targetNode.getBuildTarget())) {
return false;
}
if (descriptionClasses.isPresent() && !descriptionClasses.get().contains(targetNode.getDescription().getClass())) {
return false;
}
return true;
});
ImmutableSortedMap.Builder<String, TargetNode<?, ?>> matchingNodesBuilder = ImmutableSortedMap.naturalOrder();
for (TargetNode<?, ?> targetNode : selectedReferrers) {
matchingNodesBuilder.put(targetNode.getBuildTarget().getFullyQualifiedName(), targetNode);
}
return matchingNodesBuilder.build();
}
Aggregations