Search in sources :

Example 1 with Paths

use of java.nio.file.Paths in project buck by facebook.

the class PreDexMerge method addStepsForSplitDex.

private void addStepsForSplitDex(ImmutableList.Builder<Step> steps, BuildableContext buildableContext) {
    // Collect all of the DexWithClasses objects to use for merging.
    ImmutableMultimap.Builder<APKModule, DexWithClasses> dexFilesToMergeBuilder = ImmutableMultimap.builder();
    dexFilesToMergeBuilder.putAll(FluentIterable.from(preDexDeps.entries()).transform(input -> new AbstractMap.SimpleEntry<>(input.getKey(), DexWithClasses.TO_DEX_WITH_CLASSES.apply(input.getValue()))).filter(input -> input.getValue() != null).toSet());
    final SplitDexPaths paths = new SplitDexPaths();
    final ImmutableSet.Builder<Path> secondaryDexDirectories = ImmutableSet.builder();
    if (dexSplitMode.getDexStore() == DexStore.RAW) {
        // Raw classes*.dex files go in the top-level of the APK.
        secondaryDexDirectories.add(paths.jarfilesSubdir);
    } else {
        // Otherwise, we want to include the metadata and jars as assets.
        secondaryDexDirectories.add(paths.metadataDir);
        secondaryDexDirectories.add(paths.jarfilesDir);
    }
    //always add additional dex stores and metadata as assets
    secondaryDexDirectories.add(paths.additionalJarfilesDir);
    // Do not clear existing directory which might contain secondary dex files that are not
    // re-merged (since their contents did not change).
    steps.add(new MkdirStep(getProjectFilesystem(), paths.jarfilesSubdir));
    steps.add(new MkdirStep(getProjectFilesystem(), paths.additionalJarfilesSubdir));
    steps.add(new MkdirStep(getProjectFilesystem(), paths.successDir));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), paths.metadataSubdir));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), paths.scratchDir));
    buildableContext.addMetadata(SECONDARY_DEX_DIRECTORIES_KEY, secondaryDexDirectories.build().stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
    buildableContext.recordArtifact(primaryDexPath);
    buildableContext.recordArtifact(paths.jarfilesSubdir);
    buildableContext.recordArtifact(paths.metadataSubdir);
    buildableContext.recordArtifact(paths.successDir);
    buildableContext.recordArtifact(paths.additionalJarfilesSubdir);
    PreDexedFilesSorter preDexedFilesSorter = new PreDexedFilesSorter(Optional.ofNullable(DexWithClasses.TO_DEX_WITH_CLASSES.apply(dexForUberRDotJava)), dexFilesToMergeBuilder.build(), dexSplitMode.getPrimaryDexPatterns(), apkModuleGraph, paths.scratchDir, // to set the dex weight limit during pre-dex merging.
    dexSplitMode.getLinearAllocHardLimit(), dexSplitMode.getDexStore(), paths.jarfilesSubdir, paths.additionalJarfilesSubdir);
    final ImmutableMap<String, PreDexedFilesSorter.Result> sortResults = preDexedFilesSorter.sortIntoPrimaryAndSecondaryDexes(getProjectFilesystem(), steps);
    PreDexedFilesSorter.Result rootApkModuleResult = sortResults.get(APKModuleGraph.ROOT_APKMODULE_NAME);
    if (rootApkModuleResult == null) {
        throw new HumanReadableException("No classes found in primary or secondary dexes");
    }
    Multimap<Path, Path> aggregatedOutputToInputs = HashMultimap.create();
    ImmutableMap.Builder<Path, Sha1HashCode> dexInputHashesBuilder = ImmutableMap.builder();
    for (PreDexedFilesSorter.Result result : sortResults.values()) {
        if (!result.apkModule.equals(apkModuleGraph.getRootAPKModule())) {
            Path dexOutputPath = paths.additionalJarfilesSubdir.resolve(result.apkModule.getName());
            steps.add(new MkdirStep(getProjectFilesystem(), dexOutputPath));
        }
        aggregatedOutputToInputs.putAll(result.secondaryOutputToInputs);
        dexInputHashesBuilder.putAll(result.dexInputHashes);
    }
    final ImmutableMap<Path, Sha1HashCode> dexInputHashes = dexInputHashesBuilder.build();
    steps.add(new SmartDexingStep(getProjectFilesystem(), primaryDexPath, Suppliers.ofInstance(rootApkModuleResult.primaryDexInputs), Optional.of(paths.jarfilesSubdir), Optional.of(Suppliers.ofInstance(aggregatedOutputToInputs)), () -> dexInputHashes, paths.successDir, DX_MERGE_OPTIONS, dxExecutorService, xzCompressionLevel, dxMaxHeapSize));
    // Record the primary dex SHA1 so exopackage apks can use it to compute their ABI keys.
    // Single dex apks cannot be exopackages, so they will never need ABI keys.
    steps.add(new RecordFileSha1Step(getProjectFilesystem(), primaryDexPath, PRIMARY_DEX_HASH_KEY, buildableContext));
    for (PreDexedFilesSorter.Result result : sortResults.values()) {
        if (!result.apkModule.equals(apkModuleGraph.getRootAPKModule())) {
            Path dexMetadataOutputPath = paths.additionalJarfilesSubdir.resolve(result.apkModule.getName()).resolve("metadata.txt");
            addMetadataWriteStep(result, steps, dexMetadataOutputPath);
        }
    }
    addMetadataWriteStep(rootApkModuleResult, steps, paths.metadataFile);
}
Also used : Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) SourcePath(com.facebook.buck.rules.SourcePath) Multimap(com.google.common.collect.Multimap) BuildOutput(com.facebook.buck.android.PreDexMerge.BuildOutput) MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) Suppliers(com.google.common.base.Suppliers) BuildOutputInitializer(com.facebook.buck.rules.BuildOutputInitializer) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ImmutableMap(com.google.common.collect.ImmutableMap) InitializableFromDisk(com.facebook.buck.rules.InitializableFromDisk) BuildableContext(com.facebook.buck.rules.BuildableContext) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) OnDiskBuildInfo(com.facebook.buck.rules.OnDiskBuildInfo) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) Objects(java.util.Objects) AbstractMap(java.util.AbstractMap) List(java.util.List) Paths(java.nio.file.Paths) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) BuildContext(com.facebook.buck.rules.BuildContext) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) BuildTargets(com.facebook.buck.model.BuildTargets) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) Collections(java.util.Collections) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MkdirStep(com.facebook.buck.step.fs.MkdirStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableMap(com.google.common.collect.ImmutableMap) HumanReadableException(com.facebook.buck.util.HumanReadableException) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 2 with Paths

use of java.nio.file.Paths in project buck by facebook.

the class ExecutableFinder method getPaths.

private ImmutableSet<Path> getPaths(ImmutableMap<String, String> env) {
    ImmutableSet.Builder<Path> paths = ImmutableSet.builder();
    // Add the empty path so that when we iterate over it, we can check for the suffixed version of
    // a given path, be it absolute or not.
    paths.add(Paths.get(""));
    String pathEnv = env.get("PATH");
    if (pathEnv != null) {
        pathEnv = pathEnv.trim();
        paths.addAll(StreamSupport.stream(Splitter.on(pathSeparator).omitEmptyStrings().split(pathEnv).spliterator(), false).map(Paths::get).iterator());
    }
    if (platform == Platform.MACOS) {
        Path osXPaths = Paths.get("/etc/paths");
        if (Files.exists(osXPaths)) {
            try {
                paths.addAll(Files.readAllLines(osXPaths, Charset.defaultCharset()).stream().map(Paths::get).iterator());
            } catch (IOException e) {
                LOG.warn("Unable to read mac-specific paths. Skipping");
            }
        }
    }
    return paths.build();
}
Also used : Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) Paths(java.nio.file.Paths) IOException(java.io.IOException)

Example 3 with Paths

use of java.nio.file.Paths in project buck by facebook.

the class CxxBinaryIntegrationTest method testInferCxxBinaryWritesSpecsListFilesOfTransitiveDependencies.

@Test
public void testInferCxxBinaryWritesSpecsListFilesOfTransitiveDependencies() throws IOException {
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.empty());
    workspace.setupCxxSandboxing(sandboxSources);
    ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
    BuildTarget inputBuildTarget = BuildTargetFactory.newInstance("//foo:binary_with_chain_deps").withFlavors(CxxInferEnhancer.InferFlavors.INFER.get());
    //Build the given target and check that it succeeds.
    workspace.runBuckCommand("build", inputBuildTarget.getFullyQualifiedName()).assertSuccess();
    String specsPathList = BuildTargets.getGenPath(filesystem, inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get()), "infer-analysis-%s/specs_path_list.txt").toString();
    String out = workspace.getFileContents(specsPathList);
    ImmutableList<Path> paths = FluentIterable.from(out.split("\n")).transform(input -> new File(input).toPath()).toList();
    assertSame("There must be 2 paths in total", paths.size(), 2);
    for (Path path : paths) {
        assertTrue("Path must be absolute", path.isAbsolute());
        assertTrue("Path must exist", Files.exists(path));
    }
}
Also used : TestDataHelper(com.facebook.buck.testutil.integration.TestDataHelper) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AssumeAndroidPlatform(com.facebook.buck.android.AssumeAndroidPlatform) InferHelper(com.facebook.buck.testutil.integration.InferHelper) FluentIterable(com.google.common.collect.FluentIterable) PathMatcher(java.nio.file.PathMatcher) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) Path(java.nio.file.Path) Parameterized(org.junit.runners.Parameterized) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) ImmutableSet(com.google.common.collect.ImmutableSet) CxxFlavorSanitizer.sanitize(com.facebook.buck.cxx.CxxFlavorSanitizer.sanitize) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Platform(com.facebook.buck.util.environment.Platform) Set(java.util.Set) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Assume.assumeTrue(org.junit.Assume.assumeTrue) Joiner(com.google.common.base.Joiner) Assume.assumeThat(org.junit.Assume.assumeThat) RunWith(org.junit.runner.RunWith) TemporaryPaths(com.facebook.buck.testutil.integration.TemporaryPaths) Assert.assertSame(org.junit.Assert.assertSame) BuildRuleStatus(com.facebook.buck.rules.BuildRuleStatus) ImmutableList(com.google.common.collect.ImmutableList) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) File.pathSeparator(java.io.File.pathSeparator) Predicates(com.google.common.base.Predicates) Assume(org.junit.Assume) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Matchers.oneOf(org.hamcrest.Matchers.oneOf) Files(java.nio.file.Files) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) BuildRuleSuccessType(com.facebook.buck.rules.BuildRuleSuccessType) File(java.io.File) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Rule(org.junit.Rule) Paths(java.nio.file.Paths) MoreFiles(com.facebook.buck.io.MoreFiles) BuildTargets(com.facebook.buck.model.BuildTargets) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) File(java.io.File) Test(org.junit.Test)

Example 4 with Paths

use of java.nio.file.Paths in project buck by facebook.

the class DefaultJavaLibraryTest method createDefaultJavaLibraryRuleWithAbiKey.

private BuildRule createDefaultJavaLibraryRuleWithAbiKey(BuildTarget buildTarget, ImmutableSet<String> srcs, ImmutableSortedSet<BuildRule> deps, ImmutableSortedSet<BuildRule> exportedDeps, Optional<AbstractJavacOptions.SpoolMode> spoolMode, ImmutableList<String> postprocessClassesCommands) {
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    ImmutableSortedSet<? extends SourcePath> srcsAsPaths = FluentIterable.from(srcs).transform(Paths::get).transform(p -> new PathSourcePath(projectFilesystem, p)).toSortedSet(Ordering.natural());
    BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(buildTarget).setDeclaredDeps(ImmutableSortedSet.copyOf(deps)).build();
    JavacOptions javacOptions = spoolMode.isPresent() ? JavacOptions.builder(DEFAULT_JAVAC_OPTIONS).setSpoolMode(spoolMode.get()).build() : DEFAULT_JAVAC_OPTIONS;
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    DefaultJavaLibrary defaultJavaLibrary = new DefaultJavaLibrary(buildRuleParams, new SourcePathResolver(ruleFinder), ruleFinder, srcsAsPaths, /* resources */
    ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
    Optional.empty(), postprocessClassesCommands, exportedDeps, /* providedDeps */
    ImmutableSortedSet.of(), ImmutableSortedSet.of(), javacOptions.trackClassUsage(), /* additionalClasspathEntries */
    ImmutableSet.of(), new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), /* resourcesRoot */
    Optional.empty(), /* manifest file */
    Optional.empty(), /* mavenCoords */
    Optional.empty(), /* tests */
    ImmutableSortedSet.of(), /* classesToRemoveFromJar */
    ImmutableSet.of()) {
    };
    ruleResolver.addToIndex(defaultJavaLibrary);
    return defaultJavaLibrary;
}
Also used : FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) StepRunner(com.facebook.buck.step.StepRunner) ActionGraph(com.facebook.buck.rules.ActionGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RichStream(com.facebook.buck.util.RichStream) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) Ansi(com.facebook.buck.util.Ansi) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ByteArrayInputStream(java.io.ByteArrayInputStream) RuleKey(com.facebook.buck.rules.RuleKey) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Assert.fail(org.junit.Assert.fail) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) Verbosity(com.facebook.buck.util.Verbosity) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AndroidLibraryBuilder(com.facebook.buck.android.AndroidLibraryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) DEFAULT_JAVAC_OPTIONS(com.facebook.buck.jvm.java.JavaCompilationConstants.DEFAULT_JAVAC_OPTIONS) BuildTarget(com.facebook.buck.model.BuildTarget) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) EasyMock.createNiceMock(org.easymock.EasyMock.createNiceMock) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ZipOutputStream(java.util.zip.ZipOutputStream) Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) SourcePath(com.facebook.buck.rules.SourcePath) Hashing(com.google.common.hash.Hashing) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) LinkOption(java.nio.file.LinkOption) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) MoreAsserts(com.facebook.buck.testutil.MoreAsserts) ImmutableList(com.google.common.collect.ImmutableList) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) Suppliers(com.google.common.base.Suppliers) EasyMock.replay(org.easymock.EasyMock.replay) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) Before(org.junit.Before) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Charsets(com.google.common.base.Charsets) Assert.assertNotNull(org.junit.Assert.assertNotNull) TargetNode(com.facebook.buck.rules.TargetNode) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) EasyMock.expect(org.easymock.EasyMock.expect) HashingDeterministicJarWriter(com.facebook.buck.io.HashingDeterministicJarWriter) Console(com.facebook.buck.util.Console) EasyMock(org.easymock.EasyMock) HumanReadableException(com.facebook.buck.util.HumanReadableException) File(java.io.File) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Rule(org.junit.Rule) Ordering(com.google.common.collect.Ordering) Paths(java.nio.file.Paths) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) FileHashCache(com.facebook.buck.util.cache.FileHashCache) BuildContext(com.facebook.buck.rules.BuildContext) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Paths(java.nio.file.Paths)

Example 5 with Paths

use of java.nio.file.Paths in project buck by facebook.

the class JavacStepTest method successfulCompileDoesNotSendStdoutAndStderrToConsole.

@Test
public void successfulCompileDoesNotSendStdoutAndStderrToConsole() throws Exception {
    FakeJavac fakeJavac = new FakeJavac();
    BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").build();
    ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
    JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
    FakeProcess fakeJavacProcess = new FakeProcess(0, "javac stdout\n", "javac stderr\n");
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
    BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
    executionContext.getBuckEventBus().register(listener);
    StepExecutionResult result = step.execute(executionContext);
    // Note that we don't include stderr in the step result on success.
    assertThat(result, equalTo(StepExecutionResult.SUCCESS));
    assertThat(listener.getLogMessages(), empty());
}
Also used : BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) FakeProcess(com.facebook.buck.util.FakeProcess) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Paths(java.nio.file.Paths) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

Paths (java.nio.file.Paths)19 Path (java.nio.file.Path)12 IOException (java.io.IOException)10 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)7 ExecutionContext (com.facebook.buck.step.ExecutionContext)7 List (java.util.List)7 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)6 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Optional (java.util.Optional)6 BuckEventBusFactory (com.facebook.buck.event.BuckEventBusFactory)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)5 SourcePath (com.facebook.buck.rules.SourcePath)5 StepExecutionResult (com.facebook.buck.step.StepExecutionResult)5 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 BuildTarget (com.facebook.buck.model.BuildTarget)4