use of javax.annotation.Nullable in project buck by facebook.
the class LogFormatter method format.
@Override
public String format(LogRecord record) {
String timestamp = simpleDateFormat.get().format(new Date(record.getMillis()));
// We explicitly don't use String.format here because this code is very
// performance-critical: http://stackoverflow.com/a/1281651
long tid = record.getThreadID();
@Nullable String command = mapper.threadIdToCommandId(tid);
StringBuilder sb = new StringBuilder(255).append(timestamp).append(formatRecordLevel(record.getLevel())).append("[command:").append(command).append("][tid:");
// Zero-pad on the left. We're currently assuming we have less than 100 threads.
if (tid < 10) {
sb.append("0").append(tid);
} else {
sb.append(tid);
}
sb.append("][").append(record.getLoggerName()).append("] ");
if (record instanceof AppendableLogRecord) {
// Avoid allocating then throwing away the formatted message and
// params; just format directly to the StringBuilder.
((AppendableLogRecord) record).appendFormattedMessage(sb);
} else {
sb.append(formatMessage(record));
}
sb.append("\n");
Throwable t = record.getThrown();
if (t != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
sb.append(sw).append("\n");
}
return sb.toString();
}
use of javax.annotation.Nullable in project buck by facebook.
the class Project method resolveAndroidManifestRelativePath.
@Nullable
private Path resolveAndroidManifestRelativePath(Path basePath) {
Path fallbackManifestPath = resolveAndroidManifestFileRelativePath(basePath);
Path manifestPath = intellijConfig.getAndroidManifest().orElse(null);
if (manifestPath != null) {
Path path = basePath.resolve(manifestPath);
return projectFilesystem.exists(path) ? manifestPath : fallbackManifestPath;
}
return fallbackManifestPath;
}
use of javax.annotation.Nullable in project buck by facebook.
the class InMemoryBuildFileTree method findParent.
/**
* Finds the parent Node of the specified child Node.
* @param child whose parent is sought in {@code basePathToNodeIndex}.
* @param basePathToNodeIndex Map that must contain a Node with a basePath that is a prefix of
* {@code child}'s basePath.
* @return the Node in {@code basePathToNodeIndex} with the longest basePath that is a prefix of
* {@code child}'s basePath.
*/
@Nullable
private static Node findParent(Node child, Map<Path, Node> basePathToNodeIndex) {
Path current = child.basePath;
while (current != null) {
Node candidate = basePathToNodeIndex.get(current);
if (candidate != null) {
return candidate;
}
current = current.getParent();
}
return basePathToNodeIndex.get(Paths.get(""));
}
use of javax.annotation.Nullable in project buck by facebook.
the class TranslatingJavacPhaseTracer method setupTracing.
/**
* @param next a TaskListener that should be notified of events outside of the trace windows. It
* is passed as Object because TaskListener is not available in Buck's ClassLoader
*/
@Nullable
public static TranslatingJavacPhaseTracer setupTracing(BuildTarget invokingTarget, ClassLoaderCache classLoaderCache, JavacEventSink eventSink, JavaCompiler.CompilationTask task, @Nullable Object next) {
try {
final ClassLoader tracingTaskListenerClassLoader = PluginLoader.getPluginClassLoader(classLoaderCache, task);
final Class<?> tracingTaskListenerClass = Class.forName("com.facebook.buck.jvm.java.tracing.TracingTaskListener", false, tracingTaskListenerClassLoader);
final Method setupTracingMethod = tracingTaskListenerClass.getMethod("setupTracing", JavaCompiler.CompilationTask.class, JavacPhaseTracer.class, Object.class);
final TranslatingJavacPhaseTracer tracer = new TranslatingJavacPhaseTracer(new JavacPhaseEventLogger(invokingTarget, eventSink));
setupTracingMethod.invoke(null, task, tracer, next);
return tracer;
} catch (ReflectiveOperationException e) {
LOG.warn("Failed loading TracingTaskListener (%s: %s). " + "Perhaps using a compiler that doesn't support com.sun.source.util.JavaTask?", e.getClass().getSimpleName(), e.getMessage());
return null;
}
}
use of javax.annotation.Nullable in project buck by facebook.
the class BuildCommand method executeDistributedBuild.
private int executeDistributedBuild(final CommandRunnerParams params, ActionAndTargetGraphs graphs, final WeightedListeningExecutorService executorService) throws IOException, InterruptedException {
// Distributed builds serialize and send the unversioned target graph,
// and then deserialize and version remotely.
TargetGraphAndBuildTargets targetGraphAndBuildTargets = graphs.unversionedTargetGraph;
ProjectFilesystem filesystem = params.getCell().getFilesystem();
FileHashCache fileHashCache = params.getFileHashCache();
DistBuildTypeCoercerFactory typeCoercerFactory = new DistBuildTypeCoercerFactory(params.getObjectMapper());
ParserTargetNodeFactory<TargetNode<?, ?>> parserTargetNodeFactory = DefaultParserTargetNodeFactory.createForDistributedBuild(new ConstructorArgMarshaller(typeCoercerFactory), new TargetNodeFactory(typeCoercerFactory));
DistBuildTargetGraphCodec targetGraphCodec = new DistBuildTargetGraphCodec(params.getObjectMapper(), parserTargetNodeFactory, new Function<TargetNode<?, ?>, Map<String, Object>>() {
@Nullable
@Override
public Map<String, Object> apply(TargetNode<?, ?> input) {
try {
return params.getParser().getRawTargetNode(params.getBuckEventBus(), params.getCell().getCell(input.getBuildTarget()), false, /* enableProfiling */
executorService, input);
} catch (BuildFileParseException e) {
throw new RuntimeException(e);
}
}
}, targetGraphAndBuildTargets.getBuildTargets().stream().map(t -> t.getFullyQualifiedName()).collect(Collectors.toSet()));
BuildJobState jobState = computeDistributedBuildJobState(targetGraphCodec, params, targetGraphAndBuildTargets, graphs.actionGraph, executorService);
if (distributedBuildStateFile != null) {
Path stateDumpPath = Paths.get(distributedBuildStateFile);
BuildJobStateSerializer.serialize(jobState, filesystem.newFileOutputStream(stateDumpPath));
return 0;
} else {
BuckVersion buckVersion = getBuckVersion();
Preconditions.checkArgument(params.getInvocationInfo().isPresent());
try (DistBuildService service = DistBuildFactory.newDistBuildService(params);
DistBuildLogStateTracker distBuildLogStateTracker = DistBuildFactory.newDistBuildLogStateTracker(params.getInvocationInfo().get().getLogDirectoryPath(), filesystem)) {
DistBuildClientExecutor build = new DistBuildClientExecutor(jobState, service, distBuildLogStateTracker, 1000, /* millisBetweenStatusPoll */
buckVersion);
int exitCode = build.executeAndPrintFailuresToEventBus(executorService, filesystem, fileHashCache, params.getBuckEventBus());
// TODO(shivanker): Add a flag to disable building, and only fetch from the cache.
if (exitCode == 0) {
exitCode = executeLocalBuild(params, graphs.actionGraph, executorService);
}
return exitCode;
}
}
}
Aggregations