use of com.facebook.buck.jvm.core.JavaPackageFinder in project buck by facebook.
the class DefaultJavaLibraryTest method stubOutBuildContext.
@Before
public void stubOutBuildContext() {
ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot().toPath());
StepRunner stepRunner = createNiceMock(StepRunner.class);
JavaPackageFinder packageFinder = createNiceMock(JavaPackageFinder.class);
replay(packageFinder, stepRunner);
annotationScenarioGenPath = filesystem.resolve(filesystem.getBuckPaths().getAnnotationDir()).resolve("android/java/src/com/facebook/__fb_gen__").toAbsolutePath().toString();
}
use of com.facebook.buck.jvm.core.JavaPackageFinder in project buck by facebook.
the class Build method executeBuild.
/**
* If {@code isKeepGoing} is false, then this returns a future that succeeds only if all of
* {@code rulesToBuild} build successfully. Otherwise, this returns a future that should always
* succeed, even if individual rules fail to build. In that case, a failed build rule is indicated
* by a {@code null} value in the corresponding position in the iteration order of
* {@code rulesToBuild}.
* @param targetish The targets to build. All targets in this iterable must be unique.
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
public BuildExecutionResult executeBuild(Iterable<? extends BuildTarget> targetish, boolean isKeepGoing) throws IOException, ExecutionException, InterruptedException {
BuildId buildId = executionContext.getBuildId();
BuildEngineBuildContext buildContext = BuildEngineBuildContext.builder().setBuildContext(BuildContext.builder().setActionGraph(actionGraph).setSourcePathResolver(new SourcePathResolver(new SourcePathRuleFinder(ruleResolver))).setJavaPackageFinder(javaPackageFinder).setEventBus(executionContext.getBuckEventBus()).setAndroidPlatformTargetSupplier(executionContext.getAndroidPlatformTargetSupplier()).build()).setClock(clock).setArtifactCache(artifactCache).setBuildId(buildId).setObjectMapper(objectMapper).putAllEnvironment(executionContext.getEnvironment()).setKeepGoing(isKeepGoing).build();
// It is important to use this logic to determine the set of rules to build rather than
// build.getActionGraph().getNodesWithNoIncomingEdges() because, due to graph enhancement,
// there could be disconnected subgraphs in the DependencyGraph that we do not want to build.
ImmutableSet<BuildTarget> targetsToBuild = StreamSupport.stream(targetish.spliterator(), false).collect(MoreCollectors.toImmutableSet());
// It is important to use this logic to determine the set of rules to build rather than
// build.getActionGraph().getNodesWithNoIncomingEdges() because, due to graph enhancement,
// there could be disconnected subgraphs in the DependencyGraph that we do not want to build.
ImmutableList<BuildRule> rulesToBuild = ImmutableList.copyOf(targetsToBuild.stream().map(buildTarget -> {
try {
return getRuleResolver().requireRule(buildTarget);
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException("No build rule found for target %s", buildTarget);
}
}).collect(MoreCollectors.toImmutableSet()));
// Calculate and post the number of rules that need to built.
int numRules = buildEngine.getNumRulesToBuild(rulesToBuild);
getExecutionContext().getBuckEventBus().post(BuildEvent.ruleCountCalculated(targetsToBuild, numRules));
// Setup symlinks required when configuring the output path.
createConfiguredBuckOutSymlinks();
List<ListenableFuture<BuildResult>> futures = rulesToBuild.stream().map(rule -> buildEngine.build(buildContext, executionContext, rule)).collect(MoreCollectors.toImmutableList());
// Get the Future representing the build and then block until everything is built.
ListenableFuture<List<BuildResult>> buildFuture = Futures.allAsList(futures);
List<BuildResult> results;
try {
results = buildFuture.get();
if (!isKeepGoing) {
for (BuildResult result : results) {
Throwable thrown = result.getFailure();
if (thrown != null) {
throw new ExecutionException(thrown);
}
}
}
} catch (ExecutionException | InterruptedException | RuntimeException e) {
Throwable t = Throwables.getRootCause(e);
if (e instanceof InterruptedException || t instanceof InterruptedException || t instanceof ClosedByInterruptException) {
try {
buildFuture.cancel(true);
} catch (CancellationException ignored) {
// Rethrow original InterruptedException instead.
}
Thread.currentThread().interrupt();
}
throw e;
}
// Insertion order matters
LinkedHashMap<BuildRule, Optional<BuildResult>> resultBuilder = new LinkedHashMap<>();
Preconditions.checkState(rulesToBuild.size() == results.size());
for (int i = 0, len = rulesToBuild.size(); i < len; i++) {
BuildRule rule = rulesToBuild.get(i);
resultBuilder.put(rule, Optional.ofNullable(results.get(i)));
}
return BuildExecutionResult.builder().setFailures(FluentIterable.from(results).filter(input -> input.getSuccess() == null)).setResults(resultBuilder).build();
}
use of com.facebook.buck.jvm.core.JavaPackageFinder in project buck by facebook.
the class JavacExecutionContextSerializer method deserialize.
@SuppressWarnings("unchecked")
public static JavacExecutionContext deserialize(Map<String, Object> data, JavacEventSink eventSink, PrintStream stdErr, ClassLoaderCache classLoaderCache, ObjectMapper objectMapper, Console console) {
Verbosity verbosity = Verbosity.valueOf((String) Preconditions.checkNotNull(data.get(VERBOSITY)));
CellPathResolver cellPathResolver = CellPathResolverSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CELL_PATH_RESOLVER)));
JavaPackageFinder javaPackageFinder = JavaPackageFinderSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(JAVA_PACKAGE_FINDER)));
ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get((String) Preconditions.checkNotNull(data.get(PROJECT_FILE_SYSTEM_ROOT))));
ClassUsageFileWriter classUsageFileWriter = ClassUsageFileWriterSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CLASS_USAGE_FILE_WRITER)));
ProcessExecutor processExecutor = ProcessExecutorSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(PROCESS_EXECUTOR)), console);
ImmutableList<Path> absolutePathsForInputs = ImmutableList.copyOf(((List<String>) Preconditions.checkNotNull(data.get(ABSOLUTE_PATHS_FOR_INPUTS))).stream().map(s -> Paths.get(s)).iterator());
Optional<DirectToJarOutputSettings> directToJarOutputSettings = Optional.empty();
if (data.containsKey(DIRECT_TO_JAR_SETTINGS)) {
directToJarOutputSettings = Optional.of(DirectToJarOutputSettingsSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(DIRECT_TO_JAR_SETTINGS))));
}
return JavacExecutionContext.of(eventSink, stdErr, classLoaderCache, objectMapper, verbosity, cellPathResolver, javaPackageFinder, projectFilesystem, classUsageFileWriter, (Map<String, String>) Preconditions.checkNotNull(data.get(ENVIRONMENT), "Missing environment when deserializing JavacExectionContext"), processExecutor, absolutePathsForInputs, directToJarOutputSettings);
}
use of com.facebook.buck.jvm.core.JavaPackageFinder in project buck by facebook.
the class JavaSourceJar method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
JavaPackageFinder packageFinder = context.getJavaPackageFinder();
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
steps.add(new RmStep(getProjectFilesystem(), output));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
Set<Path> seenPackages = Sets.newHashSet();
for (Path source : context.getSourcePathResolver().filterInputsToCompareToOutput(sources)) {
Path packageFolder = packageFinder.findJavaPackageFolder(source);
Path packageDir = temp.resolve(packageFolder);
if (seenPackages.add(packageDir)) {
steps.add(new MkdirStep(getProjectFilesystem(), packageDir));
}
steps.add(CopyStep.forFile(getProjectFilesystem(), source, packageDir.resolve(source.getFileName())));
}
steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.of(), /* junk paths */
false, DEFAULT_COMPRESSION_LEVEL, temp));
buildableContext.recordArtifact(output);
return steps.build();
}
use of com.facebook.buck.jvm.core.JavaPackageFinder in project buck by facebook.
the class CopyResourcesStepTest method testAddResourceCommandsWithBuildFileParentOfJavaPackage.
@Test
public void testAddResourceCommandsWithBuildFileParentOfJavaPackage() {
// Files:
// android/java/src/BUCK
// android/java/src/com/facebook/base/data.json
// android/java/src/com/facebook/common/util/data.json
BuildTarget buildTarget = BuildTargetFactory.newInstance("//android/java/src:resources");
JavaPackageFinder javaPackageFinder = createJavaPackageFinder();
ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
CopyResourcesStep step = new CopyResourcesStep(filesystem, new SourcePathResolver(ruleFinder), ruleFinder, buildTarget, ImmutableSet.<SourcePath>of(new FakeSourcePath(filesystem, "android/java/src/com/facebook/base/data.json"), new FakeSourcePath(filesystem, "android/java/src/com/facebook/common/util/data.json")), filesystem.getBuckPaths().getScratchDir().resolve("android/java/src/lib__resources__classes"), javaPackageFinder);
List<? extends Step> expected = ImmutableList.of(new MkdirAndSymlinkFileStep(filesystem, filesystem.resolve("android/java/src/com/facebook/base/data.json"), filesystem.getBuckPaths().getScratchDir().resolve("android/java/src/lib__resources__classes/com/facebook/base/data.json")), new MkdirAndSymlinkFileStep(filesystem, filesystem.resolve("android/java/src/com/facebook/common/util/data.json"), filesystem.getBuckPaths().getScratchDir().resolve("android/java/src/lib__resources__classes/com/facebook/common/util/data.json")));
assertEquals(expected, step.buildSteps());
}
Aggregations