use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.
the class GoTestMainStep method getShellCommandInternal.
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
ImmutableList.Builder<String> command = ImmutableList.<String>builder().addAll(generatorCommandPrefix).add("--output", output.toString()).add("--import-path", packageName.toString()).add("--cover-mode", coverageMode);
for (Map.Entry<Path, ImmutableMap<String, Path>> pkg : coverageVariables.entrySet()) {
if (pkg.getValue().isEmpty()) {
continue;
}
StringBuilder pkgFlag = new StringBuilder();
pkgFlag.append(pkg.getKey().toString());
pkgFlag.append(':');
boolean first = true;
for (Map.Entry<String, Path> pkgVars : pkg.getValue().entrySet()) {
if (!first) {
pkgFlag.append(',');
}
first = false;
pkgFlag.append(pkgVars.getKey());
pkgFlag.append('=');
pkgFlag.append(pkgVars.getValue().toString());
}
command.add("--cover-pkgs", pkgFlag.toString());
}
for (Path source : testFiles) {
command.add(source.toString());
}
return command.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.
the class DirectToJarOutputSettingsSerializer method serialize.
public static ImmutableMap<String, Object> serialize(DirectToJarOutputSettings settings) {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
builder.put(OUTPUT_PATH, settings.getDirectToJarOutputPath().toString());
ImmutableList.Builder<ImmutableMap<String, Object>> serializedPatterns = ImmutableList.builder();
for (Pattern pattern : settings.getClassesToRemoveFromJar()) {
serializedPatterns.add(ImmutableMap.<String, Object>of(CLASSES_TO_REMOVE_PATTERN, pattern.pattern(), CLASSES_TO_REMOVE_PATTERN_FLAGS, pattern.flags()));
}
builder.put(CLASSES_TO_REMOVE, serializedPatterns.build());
ImmutableList.Builder<String> serializedEntries = ImmutableList.builder();
for (Path entry : settings.getEntriesToJar()) {
serializedEntries.add(entry.toString());
}
builder.put(ENTRIES, serializedEntries.build());
if (settings.getMainClass().isPresent()) {
builder.put(MAIN_CLASS, settings.getMainClass().get());
}
if (settings.getManifestFile().isPresent()) {
builder.put(MANIFEST_FILE, settings.getManifestFile().get().toString());
}
return builder.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.
the class BaseCompileToJarStepFactory method addPostprocessClassesCommands.
/**
* Adds a BashStep for each postprocessClasses command that runs the command followed by the
* outputDirectory of javac outputs.
*
* The expectation is that the command will inspect and update the directory by
* modifying, adding, and deleting the .class files in the directory.
*
* The outputDirectory should be a valid java root. I.e., if outputDirectory
* is buck-out/bin/java/abc/lib__abc__classes/, then a contained class abc.AbcModule
* should be at buck-out/bin/java/abc/lib__abc__classes/abc/AbcModule.class
*
* @param filesystem the project filesystem.
* @param postprocessClassesCommands the list of commands to post-process .class files.
* @param outputDirectory the directory that will contain all the javac output.
* @param declaredClasspathEntries the list of classpath entries.
* @param bootClasspath the compilation boot classpath.
*/
@VisibleForTesting
static ImmutableList<Step> addPostprocessClassesCommands(ProjectFilesystem filesystem, List<String> postprocessClassesCommands, Path outputDirectory, ImmutableSortedSet<Path> declaredClasspathEntries, Optional<String> bootClasspath) {
if (postprocessClassesCommands.isEmpty()) {
return ImmutableList.of();
}
ImmutableList.Builder<Step> commands = new ImmutableList.Builder<Step>();
ImmutableMap.Builder<String, String> envVarBuilder = ImmutableMap.builder();
envVarBuilder.put("COMPILATION_CLASSPATH", Joiner.on(':').join(Iterables.transform(declaredClasspathEntries, filesystem::resolve)));
if (bootClasspath.isPresent()) {
envVarBuilder.put("COMPILATION_BOOTCLASSPATH", bootClasspath.get());
}
ImmutableMap<String, String> envVars = envVarBuilder.build();
for (final String postprocessClassesCommand : postprocessClassesCommands) {
BashStep bashStep = new BashStep(filesystem.getRootPath(), postprocessClassesCommand + " " + outputDirectory) {
@Override
public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
return envVars;
}
};
commands.add(bashStep);
}
return commands.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.
the class Watchman method build.
@VisibleForTesting
@SuppressWarnings("PMD.PrematureDeclaration")
static Watchman build(ListeningProcessExecutor executor, Function<Path, Optional<WatchmanClient>> watchmanConnector, ImmutableSet<Path> projectWatchList, ImmutableMap<String, String> env, ExecutableFinder exeFinder, Console console, Clock clock, Optional<Long> commandTimeoutMillis) throws InterruptedException {
LOG.info("Creating for: " + projectWatchList);
Optional<WatchmanClient> watchmanClient = Optional.empty();
try {
Path watchmanPath = exeFinder.getExecutable(WATCHMAN, env).toAbsolutePath();
Optional<? extends Map<String, ?>> result;
long timeoutMillis = commandTimeoutMillis.orElse(DEFAULT_COMMAND_TIMEOUT_MILLIS);
long endTimeNanos = clock.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeoutMillis);
result = execute(executor, console, clock, timeoutMillis, TimeUnit.MILLISECONDS.toNanos(timeoutMillis), watchmanPath, "get-sockname");
if (!result.isPresent()) {
return NULL_WATCHMAN;
}
String rawSockname = (String) result.get().get("sockname");
if (rawSockname == null) {
return NULL_WATCHMAN;
}
Path socketPath = Paths.get(rawSockname);
LOG.info("Connecting to Watchman version %s at %s", result.get().get("version"), socketPath);
watchmanClient = watchmanConnector.apply(socketPath);
if (!watchmanClient.isPresent()) {
LOG.warn("Could not connect to Watchman, disabling.");
return NULL_WATCHMAN;
}
LOG.debug("Connected to Watchman");
long versionQueryStartTimeNanos = clock.nanoTime();
result = watchmanClient.get().queryWithTimeout(endTimeNanos - versionQueryStartTimeNanos, "version", ImmutableMap.of("required", REQUIRED_CAPABILITIES, "optional", ALL_CAPABILITIES.keySet()));
LOG.info("Took %d ms to query capabilities %s", TimeUnit.NANOSECONDS.toMillis(clock.nanoTime() - versionQueryStartTimeNanos), ALL_CAPABILITIES);
if (!result.isPresent()) {
LOG.warn("Could not get version response from Watchman, disabling Watchman");
watchmanClient.get().close();
return NULL_WATCHMAN;
}
ImmutableSet.Builder<Capability> capabilitiesBuilder = ImmutableSet.builder();
if (!extractCapabilities(result.get(), capabilitiesBuilder)) {
LOG.warn("Could not extract capabilities, disabling Watchman");
watchmanClient.get().close();
return NULL_WATCHMAN;
}
ImmutableSet<Capability> capabilities = capabilitiesBuilder.build();
LOG.debug("Got Watchman capabilities: %s", capabilities);
ImmutableMap.Builder<Path, ProjectWatch> projectWatchesBuilder = ImmutableMap.builder();
ImmutableMap.Builder<Path, String> clockIdsBuilder = ImmutableMap.builder();
for (Path rootPath : projectWatchList) {
Optional<ProjectWatch> projectWatch = queryWatchProject(watchmanClient.get(), rootPath, clock, endTimeNanos - clock.nanoTime());
if (!projectWatch.isPresent()) {
watchmanClient.get().close();
return NULL_WATCHMAN;
}
projectWatchesBuilder.put(rootPath, projectWatch.get());
Optional<String> clockId = queryClock(watchmanClient.get(), projectWatch.get().getWatchRoot(), capabilities, clock, endTimeNanos - clock.nanoTime());
if (clockId.isPresent()) {
clockIdsBuilder.put(rootPath, clockId.get());
}
}
return new Watchman(projectWatchesBuilder.build(), capabilities, clockIdsBuilder.build(), Optional.of(socketPath), watchmanClient);
} catch (ClassCastException | HumanReadableException | IOException e) {
LOG.warn(e, "Unable to determine the version of watchman. Going without.");
if (watchmanClient.isPresent()) {
try {
watchmanClient.get().close();
} catch (IOException ioe) {
LOG.warn(ioe, "Could not close watchman query client");
}
}
return NULL_WATCHMAN;
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap in project buck by facebook.
the class Resolver method resolve.
public void resolve(Collection<String> artifacts) throws RepositoryException, ExecutionException, InterruptedException, IOException {
ImmutableList.Builder<RemoteRepository> repoBuilder = ImmutableList.builder();
ImmutableMap.Builder<String, Dependency> dependencyBuilder = ImmutableMap.builder();
repoBuilder.addAll(repos);
for (String artifact : artifacts) {
if (artifact.endsWith(".pom")) {
Model model = loadPomModel(Paths.get(artifact));
repoBuilder.addAll(getReposFromPom(model));
for (Dependency dep : getDependenciesFromPom(model)) {
dependencyBuilder.put(buildKey(dep.getArtifact()), dep);
}
} else {
Dependency dep = getDependencyFromString(artifact);
dependencyBuilder.put(buildKey(dep.getArtifact()), dep);
}
}
repos = repoBuilder.build();
ImmutableMap<String, Dependency> specifiedDependencies = dependencyBuilder.build();
ImmutableMap<String, Artifact> knownDeps = getRunTimeTransitiveDeps(specifiedDependencies.values());
// We now have the complete set of dependencies. Build the graph of dependencies. We'd like
// aether to do this for us, but it doesn't preserve the complete dependency information we need
// to accurately construct build files.
final MutableDirectedGraph<Artifact> graph = buildDependencyGraph(knownDeps);
// Now we have the graph, grab the sources and jars for each dependency, as well as the relevant
// checksums (which are download by default. Yay!)
ImmutableSetMultimap<Path, Prebuilt> downloadedArtifacts = downloadArtifacts(graph, specifiedDependencies);
createBuckFiles(downloadedArtifacts);
}
Aggregations