use of java.util.jar.Manifest 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);
}
}
use of java.util.jar.Manifest in project buck by facebook.
the class StubJarIntegrationTest method abiJarManifestShouldContainHashesOfItsFiles.
@Test
public void abiJarManifestShouldContainHashesOfItsFiles() throws IOException {
Path out = Paths.get("junit-abi.jar");
Path regularJar = testDataDir.resolve("junit.jar");
new StubJar(regularJar).writeTo(filesystem, out);
try (JarFile stubJar = new JarFile(filesystem.resolve(out).toFile())) {
Manifest manifest = stubJar.getManifest();
Enumeration<JarEntry> entries = stubJar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (JarFile.MANIFEST_NAME.equals(entry.getName())) {
continue;
}
String seenDigest = manifest.getAttributes(entry.getName()).getValue("Murmur3-128-Digest");
String expectedDigest;
try (InputStream inputStream = stubJar.getInputStream(entry)) {
ByteSource byteSource = ByteSource.wrap(ByteStreams.toByteArray(inputStream));
expectedDigest = byteSource.hash(Hashing.murmur3_128()).toString();
}
assertEquals(String.format("Digest mismatch for %s", entry.getName()), expectedDigest, seenDigest);
}
}
}
use of java.util.jar.Manifest in project buck by facebook.
the class FakeProjectFilesystem method getJarManifest.
@Override
public Manifest getJarManifest(Path path) throws IOException {
try (JarInputStream jar = new JarInputStream(newFileInputStream(path))) {
Manifest result = jar.getManifest();
if (result != null) {
return result;
}
// JarInputStream will only find the manifest if it's the first entry, but we have code that
// puts it elsewhere. We must search. Fortunately, this is test code! So we can be slow!
JarEntry entry;
while ((entry = jar.getNextJarEntry()) != null) {
if (JarFile.MANIFEST_NAME.equals(entry.getName())) {
result = new Manifest();
result.read(jar);
return result;
}
}
}
return null;
}
use of java.util.jar.Manifest in project pinpoint by naver.
the class AgentDirGenerator method createJarFile.
private void createJarFile(File parentDir, String filepath) throws IOException {
final String jarPath = parentDir.getPath() + File.separator + filepath;
logger.debug("create jar:{}", jarPath);
JarOutputStream jos = null;
try {
Manifest manifest = new Manifest();
FileOutputStream out = new FileOutputStream(jarPath);
jos = new JarOutputStream(out, manifest);
} finally {
IOUtils.closeQuietly(jos);
}
}
use of java.util.jar.Manifest in project XobotOS by xamarin.
the class URLClassLoader method createURLJarHandler.
private URLHandler createURLJarHandler(URL url) {
String prefixName;
String file = url.getFile();
if (url.getFile().endsWith("!/")) {
prefixName = "";
} else {
int sepIdx = file.lastIndexOf("!/");
if (sepIdx == -1) {
// Invalid URL, don't look here again
return null;
}
sepIdx += 2;
prefixName = file.substring(sepIdx);
}
try {
URL jarURL = ((JarURLConnection) url.openConnection()).getJarFileURL();
JarURLConnection juc = (JarURLConnection) new URL("jar", "", jarURL.toExternalForm() + "!/").openConnection();
JarFile jf = juc.getJarFile();
URLJarHandler jarH = new URLJarHandler(url, jarURL, jf, prefixName);
if (jarH.getIndex() == null) {
try {
Manifest manifest = jf.getManifest();
if (manifest != null) {
String classpath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
if (classpath != null) {
searchList.addAll(0, getInternalURLs(url, classpath));
}
}
} catch (IOException e) {
}
}
return jarH;
} catch (IOException e) {
}
return null;
}
Aggregations