Search in sources :

Example 16 with Nullable

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();
}
Also used : StringWriter(java.io.StringWriter) Date(java.util.Date) Nullable(javax.annotation.Nullable) PrintWriter(java.io.PrintWriter)

Example 17 with Nullable

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;
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Nullable(javax.annotation.Nullable)

Example 18 with Nullable

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(""));
}
Also used : Path(java.nio.file.Path) Nullable(javax.annotation.Nullable)

Example 19 with Nullable

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;
    }
}
Also used : JavaCompiler(javax.tools.JavaCompiler) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable)

Example 20 with Nullable

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;
        }
    }
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) FileHashCache(com.facebook.buck.util.cache.FileHashCache) TargetNode(com.facebook.buck.rules.TargetNode) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) DistBuildService(com.facebook.buck.distributed.DistBuildService) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckVersion(com.facebook.buck.distributed.thrift.BuckVersion) TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) DefaultParserTargetNodeFactory(com.facebook.buck.parser.DefaultParserTargetNodeFactory) ParserTargetNodeFactory(com.facebook.buck.parser.ParserTargetNodeFactory) DistBuildClientExecutor(com.facebook.buck.distributed.DistBuildClientExecutor) DistBuildTargetGraphCodec(com.facebook.buck.distributed.DistBuildTargetGraphCodec) DistBuildLogStateTracker(com.facebook.buck.distributed.DistBuildLogStateTracker) DistBuildTypeCoercerFactory(com.facebook.buck.distributed.DistBuildTypeCoercerFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)3188 List (java.util.List)363 IOException (java.io.IOException)307 Map (java.util.Map)294 ArrayList (java.util.ArrayList)284 Nonnull (javax.annotation.Nonnull)264 File (java.io.File)225 Collectors (java.util.stream.Collectors)175 Arrays (java.util.Arrays)165 HashMap (java.util.HashMap)161 Test (org.junit.Test)137 Layer (com.simiacryptus.mindseye.lang.Layer)116 Tensor (com.simiacryptus.mindseye.lang.Tensor)116 ItemStack (net.minecraft.item.ItemStack)115 Logger (org.slf4j.Logger)113 LoggerFactory (org.slf4j.LoggerFactory)113 ImmutableList (com.google.common.collect.ImmutableList)111 Set (java.util.Set)107 Result (com.simiacryptus.mindseye.lang.Result)104 Function (com.google.common.base.Function)100