use of java.util.zip.ZipEntry in project buck by facebook.
the class AaptPackageResourcesIntegrationTest method testAaptPackageIsScrubbed.
@Test
public void testAaptPackageIsScrubbed() throws IOException {
AssumeAndroidPlatform.assumeSdkIsAvailable();
workspace.runBuckBuild(MAIN_BUILD_TARGET).assertSuccess();
Path aaptOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(MAIN_BUILD_TARGET).withFlavors(AndroidBinaryGraphEnhancer.AAPT_PACKAGE_FLAVOR), AaptPackageResources.RESOURCE_APK_PATH_FORMAT));
Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME));
try (ZipInputStream is = new ZipInputStream(new FileInputStream(aaptOutput.toFile()))) {
for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) {
assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch));
}
}
}
use of java.util.zip.ZipEntry in project buck by facebook.
the class GenAidlIntegrationTest method rootDirectoryDoesntChangeBuild.
@Test
public void rootDirectoryDoesntChangeBuild() throws IOException {
AssumeAndroidPlatform.assumeSdkIsAvailable();
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cached_build", tmp);
workspace.setUp();
Path outputOne = workspace.buildAndReturnOutput("//:AService");
ProjectWorkspace workspaceTwo = TestDataHelper.createProjectWorkspaceForScenario(this, "cached_build", tmp2);
workspaceTwo.setUp();
Path outputTwo = workspaceTwo.buildAndReturnOutput("//:AService");
assertEquals(workspace.getBuildLog().getRuleKey("//:AService"), workspaceTwo.getBuildLog().getRuleKey("//:AService"));
try (ZipFile zipOne = new ZipFile(outputOne.toFile());
ZipFile zipTwo = new ZipFile(outputTwo.toFile())) {
Enumeration<? extends ZipEntry> entriesOne = zipOne.entries(), entriesTwo = zipTwo.entries();
while (entriesOne.hasMoreElements()) {
assertTrue(entriesTwo.hasMoreElements());
ZipEntry entryOne = entriesOne.nextElement(), entryTwo = entriesTwo.nextElement();
// Compare data first, otherwise crc difference will cause a failure and you don't get to
// see the actual difference.
assertEquals(zipEntryData(zipOne, entryOne), zipEntryData(zipTwo, entryTwo));
assertEquals(zipEntryDebugString(entryOne), zipEntryDebugString(entryTwo));
}
assertFalse(entriesTwo.hasMoreElements());
}
assertEquals(new String(Files.readAllBytes(outputOne)), new String(Files.readAllBytes(outputTwo)));
}
use of java.util.zip.ZipEntry in project buck by facebook.
the class AccumulateClassNamesStepTest method testExecuteAccumulateClassNamesStepOnJarFile.
@Test
public void testExecuteAccumulateClassNamesStepOnJarFile() throws IOException {
// Create a JAR file.
String name = "example.jar";
File jarFile = tmp.newFile(name);
try (JarOutputStream out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jarFile)))) {
out.putNextEntry(new ZipEntry("com/example/Foo.class"));
out.closeEntry();
out.putNextEntry(new ZipEntry("com/example/Bar.class"));
out.closeEntry();
out.putNextEntry(new ZipEntry("com/example/not_a_class.png"));
out.closeEntry();
out.putNextEntry(new ZipEntry("com/example/subpackage/Baz.class"));
out.closeEntry();
}
// Create the AccumulateClassNamesStep and execute it.
ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot().toPath());
AccumulateClassNamesStep accumulateClassNamesStep = new AccumulateClassNamesStep(filesystem, Optional.of(Paths.get(name)), Paths.get("output.txt"));
ExecutionContext context = TestExecutionContext.newInstance();
accumulateClassNamesStep.execute(context);
String contents = Files.toString(new File(tmp.getRoot(), "output.txt"), Charsets.UTF_8);
String separator = AccumulateClassNamesStep.CLASS_NAME_HASH_CODE_SEPARATOR;
assertEquals("Verify that the contents are sorted alphabetically and ignore non-.class files.", Joiner.on('\n').join("com/example/Bar" + separator + SHA1_FOR_EMPTY_STRING, "com/example/Foo" + separator + SHA1_FOR_EMPTY_STRING, "com/example/subpackage/Baz" + separator + SHA1_FOR_EMPTY_STRING) + '\n', contents);
}
use of java.util.zip.ZipEntry in project buck by facebook.
the class ProjectFilesystemTest method testCreateZipIgnoresMtimes.
@Test
public void testCreateZipIgnoresMtimes() throws IOException {
// Create a empty executable file.
Path exe = tmp.newFile("foo");
// Archive it into a zipfile using `ProjectFileSystem.createZip`.
Path zipFile = tmp.getRoot().resolve("test.zip");
filesystem.createZip(ImmutableList.of(exe), zipFile);
// Iterate over each of the entries, expecting to see all zeros in the time fields.
Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME));
try (ZipInputStream is = new ZipInputStream(Files.newInputStream(zipFile))) {
for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) {
assertEquals(entry.getName(), dosEpoch, new Date(entry.getTime()));
}
}
}
use of java.util.zip.ZipEntry in project buck by facebook.
the class JarDirectoryStepTest method entriesFromTheGivenManifestShouldOverrideThoseInTheJars.
@Test
public void entriesFromTheGivenManifestShouldOverrideThoseInTheJars() throws IOException {
String expected = "1.4";
// Write the manifest, setting the implementation version
Path tmp = folder.newFolder();
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue(MANIFEST_VERSION.toString(), "1.0");
manifest.getMainAttributes().putValue(IMPLEMENTATION_VERSION.toString(), expected);
Path manifestFile = tmp.resolve("manifest");
try (OutputStream fos = Files.newOutputStream(manifestFile)) {
manifest.write(fos);
}
// Write another manifest, setting the implementation version to something else
manifest = new Manifest();
manifest.getMainAttributes().putValue(MANIFEST_VERSION.toString(), "1.0");
manifest.getMainAttributes().putValue(IMPLEMENTATION_VERSION.toString(), "1.0");
Path input = tmp.resolve("input.jar");
try (CustomZipOutputStream out = ZipOutputStreams.newOutputStream(input)) {
ZipEntry entry = new ZipEntry("META-INF/MANIFEST.MF");
out.putNextEntry(entry);
manifest.write(out);
}
Path output = tmp.resolve("output.jar");
JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(tmp), output, ImmutableSortedSet.of(Paths.get("input.jar")), /* main class */
null, tmp.resolve("manifest"), /* merge manifest */
true, /* blacklist */
ImmutableSet.of());
ExecutionContext context = TestExecutionContext.newInstance();
assertEquals(0, step.execute(context).getExitCode());
try (Zip zip = new Zip(output, false)) {
byte[] rawManifest = zip.readFully("META-INF/MANIFEST.MF");
manifest = new Manifest(new ByteArrayInputStream(rawManifest));
String version = manifest.getMainAttributes().getValue(IMPLEMENTATION_VERSION);
assertEquals(expected, version);
}
}
Aggregations