Search in sources :

Example 66 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext in project buck by facebook.

the class BaseCompileToJarStepFactoryTest method testAddPostprocessClassesCommands.

@Test
public void testAddPostprocessClassesCommands() {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    String androidBootClassPath = filesystem.resolve("android.jar").toString();
    ImmutableList<String> postprocessClassesCommands = ImmutableList.of("tool arg1", "tool2");
    Path outputDirectory = filesystem.getBuckPaths().getScratchDir().resolve("android/java/lib__java__classes");
    ImmutableSortedSet<Path> classpathEntries = ImmutableSortedSet.<Path>naturalOrder().add(filesystem.resolve("rt.jar")).add(filesystem.resolve("dep.jar")).build();
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    commands.addAll(BaseCompileToJarStepFactory.addPostprocessClassesCommands(new FakeProjectFilesystem(), postprocessClassesCommands, outputDirectory, classpathEntries, Optional.of(androidBootClassPath)));
    ImmutableList<Step> steps = commands.build();
    assertEquals(2, steps.size());
    assertTrue(steps.get(0) instanceof ShellStep);
    ShellStep step0 = (ShellStep) steps.get(0);
    assertEquals(ImmutableList.of("bash", "-c", "tool arg1 " + outputDirectory), step0.getShellCommand(executionContext));
    assertEquals(ImmutableMap.of("COMPILATION_BOOTCLASSPATH", androidBootClassPath, "COMPILATION_CLASSPATH", Joiner.on(':').join(Iterables.transform(classpathEntries, filesystem::resolve))), step0.getEnvironmentVariables(executionContext));
    assertTrue(steps.get(1) instanceof ShellStep);
    ShellStep step1 = (ShellStep) steps.get(1);
    assertEquals(ImmutableList.of("bash", "-c", "tool2 " + outputDirectory), step1.getShellCommand(executionContext));
    assertEquals(ImmutableMap.of("COMPILATION_BOOTCLASSPATH", androidBootClassPath, "COMPILATION_CLASSPATH", Joiner.on(':').join(Iterables.transform(classpathEntries, filesystem::resolve))), step1.getEnvironmentVariables(executionContext));
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ImmutableList(com.google.common.collect.ImmutableList) ShellStep(com.facebook.buck.shell.ShellStep) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep) Test(org.junit.Test)

Example 67 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext in project buck by facebook.

the class GenerateCodeCoverageReportStepTest method testJarFileIsExtracted.

@Test
public void testJarFileIsExtracted() throws Throwable {
    final File[] extractedDir = new File[2];
    step = new GenerateCodeCoverageReportStep(new ExternalJavaRuntimeLauncher("/baz/qux/java"), filesystem, SOURCE_DIRECTORIES, jarFiles, Paths.get(OUTPUT_DIRECTORY), CoverageReportFormat.HTML, "TitleFoo", Optional.empty(), Optional.empty()) {

        @Override
        StepExecutionResult executeInternal(ExecutionContext context, Set<Path> jarFiles) {
            for (int i = 0; i < 2; i++) {
                extractedDir[i] = new ArrayList<>(jarFiles).get(i).toFile();
                assertTrue(extractedDir[i].isDirectory());
                assertTrue(new File(extractedDir[i], "com/facebook/testing/coverage/Foo.class").exists());
            }
            return null;
        }
    };
    step.execute(TestExecutionContext.newInstance());
    assertFalse(extractedDir[0].exists());
    assertFalse(extractedDir[1].exists());
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 68 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext in project buck by facebook.

the class GenerateCodeCoverageReportStepTest method testClassesDirIsUntouched.

@Test
public void testClassesDirIsUntouched() throws Throwable {
    final File classesDir = tmp.newFolder("classesDir");
    jarFiles.clear();
    jarFiles.add(classesDir.toPath());
    step = new GenerateCodeCoverageReportStep(new ExternalJavaRuntimeLauncher("/baz/qux/java"), filesystem, SOURCE_DIRECTORIES, jarFiles, Paths.get(OUTPUT_DIRECTORY), CoverageReportFormat.HTML, "TitleFoo", Optional.empty(), Optional.empty()) {

        @Override
        StepExecutionResult executeInternal(ExecutionContext context, Set<Path> jarFiles) {
            assertEquals(1, jarFiles.size());
            assertEquals(classesDir.toPath(), jarFiles.iterator().next());
            return null;
        }
    };
    step.execute(TestExecutionContext.newInstance());
    assertTrue(classesDir.exists());
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) File(java.io.File) Test(org.junit.Test)

Example 69 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext in project buck by facebook.

the class JUnitStepTest method testGetShellCommand.

@Test
public void testGetShellCommand() throws IOException {
    String testClass1 = "com.facebook.buck.shell.JUnitCommandTest";
    String testClass2 = "com.facebook.buck.shell.InstrumentCommandTest";
    Set<String> testClassNames = ImmutableSet.of(testClass1, testClass2);
    String vmArg1 = "-Dname1=value1";
    String vmArg2 = "-Dname1=value2";
    ImmutableList<String> vmArgs = ImmutableList.of(vmArg1, vmArg2);
    BuildId pretendBuildId = new BuildId("pretend-build-id");
    String buildIdArg = String.format("-Dcom.facebook.buck.buildId=%s", pretendBuildId);
    Path modulePath = Paths.get("module/submodule");
    String modulePathArg = String.format("-Dcom.facebook.buck.moduleBasePath=%s", modulePath);
    Path directoryForTestResults = Paths.get("buck-out/gen/theresults/");
    Path testRunnerClasspath = Paths.get("build/classes/junit");
    ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    Path classpathFile = filesystem.resolve("foo");
    JUnitJvmArgs args = JUnitJvmArgs.builder().setBuildId(pretendBuildId).setBuckModuleBaseSourceCodePath(modulePath).setClasspathFile(classpathFile).setTestRunnerClasspath(testRunnerClasspath).setExtraJvmArgs(vmArgs).setTestType(TestType.JUNIT).setDirectoryForTestResults(directoryForTestResults).addAllTestClasses(testClassNames).build();
    JUnitStep junit = new JUnitStep(filesystem, /* nativeLibsEnvironment */
    ImmutableMap.of(), /* testRuleTimeoutMs */
    Optional.empty(), /* testCaseTimeoutMs */
    Optional.empty(), ImmutableMap.of(), new ExternalJavaRuntimeLauncher("/foo/bar/custom/java"), args);
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setConsole(new TestConsole(Verbosity.ALL)).setDefaultTestTimeoutMillis(5000L).build();
    assertEquals(executionContext.getVerbosity(), Verbosity.ALL);
    assertEquals(executionContext.getDefaultTestTimeoutMillis(), 5000L);
    List<String> observedArgs = junit.getShellCommand(executionContext);
    MoreAsserts.assertListEquals(ImmutableList.of("/foo/bar/custom/java", "-Dbuck.testrunner_classes=" + testRunnerClasspath, buildIdArg, modulePathArg, "-Dapple.awt.UIElement=true", vmArg1, vmArg2, "-verbose", "-classpath", "@" + classpathFile + File.pathSeparator + MorePaths.pathWithPlatformSeparators("build/classes/junit"), FileClassPathRunner.class.getName(), "com.facebook.buck.testrunner.JUnitMain", "--output", directoryForTestResults.toString(), "--default-test-timeout", "5000", testClass1, testClass2), observedArgs);
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildId(com.facebook.buck.model.BuildId) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 70 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext in project buck by facebook.

the class JarDirectoryStepTest method shouldFailIfMainClassMissing.

@Test
public void shouldFailIfMainClassMissing() throws IOException {
    Path zipup = folder.newFolder("zipup");
    Path zip = createZip(zipup.resolve("a.zip"), "com/example/Main.class");
    JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(zipup), Paths.get("output.jar"), ImmutableSortedSet.of(zip.getFileName()), "com.example.MissingMain", /* manifest file */
    null);
    TestConsole console = new TestConsole();
    ExecutionContext context = TestExecutionContext.newBuilder().setConsole(console).build();
    int returnCode = step.execute(context).getExitCode();
    assertEquals(1, returnCode);
    assertEquals("ERROR: Main class com.example.MissingMain does not exist.\n", console.getTextWrittenToStdErr());
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

ExecutionContext (com.facebook.buck.step.ExecutionContext)176 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)140 Test (org.junit.Test)128 Path (java.nio.file.Path)79 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)67 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)66 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)55 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)50 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)45 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)44 Step (com.facebook.buck.step.Step)34 ImmutableList (com.google.common.collect.ImmutableList)32 BuildTarget (com.facebook.buck.model.BuildTarget)31 SourcePath (com.facebook.buck.rules.SourcePath)26 TestConsole (com.facebook.buck.testutil.TestConsole)25 FakeProcess (com.facebook.buck.util.FakeProcess)21 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)20 ImmutableMap (com.google.common.collect.ImmutableMap)20 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)19 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)19