use of java.util.jar.JarOutputStream 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.jar.JarOutputStream in project buck by facebook.
the class ClassesImpl method createJar.
@Override
public void createJar(Path jarPath) throws IOException {
try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(jarPath))) {
List<Path> files = Files.walk(root.getRoot().toPath()).filter(path -> path.toFile().isFile()).collect(Collectors.toList());
for (Path file : files) {
ZipEntry entry = new ZipEntry(MorePaths.pathWithUnixSeparators(root.getRoot().toPath().relativize(file)));
jar.putNextEntry(entry);
ByteStreams.copy(Files.newInputStream(file), jar);
jar.closeEntry();
}
}
}
use of java.util.jar.JarOutputStream 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.JarOutputStream in project otertool by wuntee.
the class JarSigner15 method signJarFile.
// the actual JAR signing method -- this is the method which
// will be called by those wrapping the JARSigner class
public void signJarFile(JarFile jarFile, OutputStream outputStream) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, CertificateException, InstantiationException, ClassNotFoundException {
// calculate the necessary files for the signed jAR
// get the manifest out of the jar and verify that
// all the entries in the manifest are correct
Manifest manifest = getManifestFile(jarFile);
Map entries = createEntries(manifest, jarFile);
// create the message digest and start updating the
// the attributes in the manifest to contain the SHA1
// digests
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
updateManifestDigest(manifest, jarFile, messageDigest, entries);
// construct the signature file object and the
// signature block objects
SignatureFile signatureFile = createSignatureFile(manifest, messageDigest);
SignatureFile.Block block = signatureFile.generateBlock(privateKey, certChain, true, jarFile);
// start writing out the signed JAR file
// write out the manifest to the output jar stream
String manifestFileName = "META-INF/MANIFEST.MF";
JarOutputStream jos = new JarOutputStream(outputStream);
JarEntry manifestFile = new JarEntry(manifestFileName);
jos.putNextEntry(manifestFile);
byte[] manifestBytes = serialiseManifest(manifest);
jos.write(manifestBytes, 0, manifestBytes.length);
jos.closeEntry();
// write out the signature file -- the signatureFile
// object will name itself appropriately
String signatureFileName = signatureFile.getMetaName();
JarEntry signatureFileEntry = new JarEntry(signatureFileName);
jos.putNextEntry(signatureFileEntry);
signatureFile.write(jos);
jos.closeEntry();
// write out the signature block file -- again, the block
// will name itself appropriately
String signatureBlockName = block.getMetaName();
JarEntry signatureBlockEntry = new JarEntry(signatureBlockName);
jos.putNextEntry(signatureBlockEntry);
block.write(jos);
jos.closeEntry();
// commit the rest of the original entries in the
// META-INF directory. if any of their names conflict
// with one that we created for the signed JAR file, then
// we simply ignore it
Enumeration metaEntries = jarFile.entries();
while (metaEntries.hasMoreElements()) {
JarEntry metaEntry = (JarEntry) metaEntries.nextElement();
if (metaEntry.getName().startsWith("META-INF") && !(manifestFileName.equalsIgnoreCase(metaEntry.getName()) || signatureFileName.equalsIgnoreCase(metaEntry.getName()) || signatureBlockName.equalsIgnoreCase(metaEntry.getName())))
writeJarEntry(metaEntry, jarFile, jos);
}
// now write out the rest of the files to the stream
Enumeration allEntries = jarFile.entries();
while (allEntries.hasMoreElements()) {
JarEntry entry = (JarEntry) allEntries.nextElement();
if (!entry.getName().startsWith("META-INF"))
writeJarEntry(entry, jarFile, jos);
}
// finish the stream that we have been writing to
jos.flush();
jos.finish();
// close the JAR file that we have been using
jarFile.close();
}
use of java.util.jar.JarOutputStream in project OpenAM by OpenRock.
the class CreateSoapSTSDeployment method execute.
@SuppressWarnings("unchecked")
@Override
public String execute(Locale locale, Map mapParams) throws WorkflowException {
try {
validatePresenceOfMandatoryParams(mapParams);
final JarInputStream soapSTSServerWar = getJarInputStream();
final Path outputJarPath = getOutputJarFilePath(getStringParam(mapParams, REALM_PARAM));
final JarOutputStream modifiedSoapSTSServerWar = getJarOutputStream(outputJarPath, soapSTSServerWar.getManifest());
processFileContents(soapSTSServerWar, modifiedSoapSTSServerWar, mapParams);
return getCompletionMessage(locale, outputJarPath);
} catch (WorkflowException e) {
Debug.getInstance("workflow").error("Exception caught in CreateSoapSTSDeployment#execute: " + e.getMessage());
throw e;
}
}
Aggregations