Search in sources :

Example 21 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class JavaBinaryIntegrationTest method fatJarWithBlacklist.

@Test
public void fatJarWithBlacklist() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "java_binary_with_blacklist", tmp);
    workspace.setUp();
    Path binaryJarWithBlacklist = workspace.buildAndReturnOutput("//:bin-blacklist");
    Path binaryJarWithoutBlacklist = workspace.buildAndReturnOutput("//:bin-no-blacklist");
    ImmutableSet<String> commonEntries = ImmutableSet.of("META-INF/", "META-INF/MANIFEST.MF", "com/", "com/example/", "com/example/B.class");
    ImmutableSet<String> blacklistedEntries = ImmutableSet.of("com/example/A.class", "com/example/A$C.class", "com/example/Alligator.class");
    assertEquals("com.example.Alligator, com.example.A and any inner classes should be removed.", commonEntries, new ZipInspector(binaryJarWithBlacklist).getZipFileEntries());
    assertEquals(ImmutableSet.builder().addAll(commonEntries).addAll(blacklistedEntries).build(), new ZipInspector(binaryJarWithoutBlacklist).getZipFileEntries());
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Example 22 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class CalculateAbiStepTest method shouldCalculateAbiFromAStubJar.

@Test
public void shouldCalculateAbiFromAStubJar() throws IOException {
    Path outDir = temp.newFolder().toAbsolutePath();
    ProjectFilesystem filesystem = new ProjectFilesystem(outDir);
    Path directory = TestDataHelper.getTestDataDirectory(this);
    Path source = directory.resolve("prebuilt/junit.jar");
    Path binJar = Paths.get("source.jar");
    Files.copy(source, outDir.resolve(binJar));
    Path abiJar = outDir.resolve("abi.jar");
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    FakeBuildableContext context = new FakeBuildableContext();
    new CalculateAbiStep(context, filesystem, binJar, abiJar).execute(executionContext);
    String seenHash = filesystem.computeSha1(Paths.get("abi.jar")).getHash();
    // Hi there! This is hardcoded here because we want to make sure buck always produces the same
    // jar files across timezones and versions. If the test is failing because of an intentional
    // modification to how we produce abi .jar files, then just update the hash, otherwise please
    // investigate why the value is different.
    // NOTE: If this starts failing on CI for no obvious reason it's possible that the offset
    // calculation in ZipConstants.getFakeTime() does not account for DST correctly.
    assertEquals("2f8dd47439697c6d633f7baef3d0f71cbac9d4a4", seenHash);
    // Assert that the abiJar contains non-class resources (like txt files).
    ZipInspector inspector = new ZipInspector(abiJar);
    inspector.assertFileExists("LICENSE.txt");
}
Also used : Path(java.nio.file.Path) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 23 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class InteractiveReportIntegrationTest method testTraceInReport.

@Test
public void testTraceInReport() throws Exception {
    DefectSubmitResult report = createDefectReport(traceWorkspace, new ByteArrayInputStream("1\nreport text\n".getBytes("UTF-8")));
    Path reportFile = traceWorkspace.asCell().getFilesystem().resolve(report.getReportSubmitLocation().get());
    ZipInspector zipInspector = new ZipInspector(reportFile);
    zipInspector.assertFileExists(tracePath1);
}
Also used : Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Example 24 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class InteractiveReportIntegrationTest method testTraceRespectReportSize.

@Test
public void testTraceRespectReportSize() throws Exception {
    DefectSubmitResult report = createDefectReport(traceWorkspace, new ByteArrayInputStream("0,1\nreport text\n".getBytes("UTF-8")));
    Path reportFile = traceWorkspace.asCell().getFilesystem().resolve(report.getReportSubmitLocation().get());
    ZipInspector zipInspector = new ZipInspector(reportFile);
    // The second command was more recent, so its file should be included.
    zipInspector.assertFileExists(tracePath2);
    zipInspector.assertFileDoesNotExist(tracePath1);
}
Also used : Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Example 25 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class ZipRuleIntegrationTest method shouldUnpackContentsOfASrcJar.

@Test
public void shouldUnpackContentsOfASrcJar() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "zip-rule", tmp);
    workspace.setUp();
    Path zip = workspace.buildAndReturnOutput("//example:unrolled");
    ZipInspector inspector = new ZipInspector(zip);
    inspector.assertFileExists("menu.txt");
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Aggregations

ZipInspector (com.facebook.buck.testutil.integration.ZipInspector)63 Test (org.junit.Test)62 Path (java.nio.file.Path)34 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)29 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)15 BuildTarget (com.facebook.buck.model.BuildTarget)10 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 TestConsole (com.facebook.buck.testutil.TestConsole)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)3 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)3 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)3 Clock (com.facebook.buck.timing.Clock)3 DefaultClock (com.facebook.buck.timing.DefaultClock)3 SymbolGetter (com.facebook.buck.android.AndroidNdkHelper.SymbolGetter)2 SymbolsAndDtNeeded (com.facebook.buck.android.AndroidNdkHelper.SymbolsAndDtNeeded)2 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)2 ExecutionContext (com.facebook.buck.step.ExecutionContext)2