use of java.util.jar.Manifest in project jdk8u_jdk by JetBrains.
the class BigJar method createLargeJar.
void createLargeJar(File jarFile, String comment) throws IOException {
final int MAX = Short.MAX_VALUE * 2 + 10;
JarEntry je = null;
File javaFile = new File("Foo.java");
File classFile = getClassFile(javaFile);
Manifest manifest = createMainClass(javaFile);
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest);
FileInputStream fis = new FileInputStream(classFile)) {
jos.setLevel(JarOutputStream.STORED);
jos.setMethod(JarOutputStream.STORED);
for (int i = 0; i < MAX; i++) {
je = new JarEntry("X" + i + ".txt");
je.setSize(0);
je.setCompressedSize(0);
je.setCrc(0);
jos.putNextEntry(je);
}
// add a class file
je = new JarEntry(classFile.getName());
je.setCompressedSize(classFile.length());
je.setSize(classFile.length());
je.setCrc(computeCRC(classFile));
jos.putNextEntry(je);
copyStream(fis, jos);
jos.closeEntry();
if (comment != null) {
jos.setComment(comment);
}
}
}
use of java.util.jar.Manifest in project GNS by MobilityFirst.
the class GNSConfig method readBuildVersion.
/**
* Attempts to look for a MANIFEST file in that contains the Build-Version
* attribute.
*
* @return a build version
*/
public static String readBuildVersion() {
String result = null;
Enumeration<URL> resources = null;
try {
resources = GNSConfig.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
} catch (IOException E) {
// handle
}
if (resources != null) {
while (resources.hasMoreElements()) {
try {
Manifest manifest = new Manifest(resources.nextElement().openStream());
// check that this is your manifest and do what you need or
// get the next one
Attributes attr = manifest.getMainAttributes();
result = attr.getValue("Build-Version");
} catch (IOException E) {
// handle
}
}
}
return result;
}
use of java.util.jar.Manifest in project intellij-community by JetBrains.
the class JarLoader method getAttributes.
@Nullable
private static Map<Resource.Attribute, String> getAttributes(ZipFile zipFile) {
ZipEntry entry = zipFile.getEntry(JarFile.MANIFEST_NAME);
if (entry == null)
return null;
Map<Resource.Attribute, String> map = null;
try {
InputStream stream = zipFile.getInputStream(entry);
try {
Attributes attributes = new Manifest(stream).getMainAttributes();
for (Pair<Resource.Attribute, Attributes.Name> p : PACKAGE_FIELDS) {
String value = attributes.getValue(p.second);
if (value != null) {
if (map == null)
map = new EnumMap<Resource.Attribute, String>(Resource.Attribute.class);
map.put(p.first, value);
}
}
} finally {
stream.close();
}
} catch (Exception ignored) {
}
return map;
}
use of java.util.jar.Manifest in project wildfly by wildfly.
the class WebApplicationBundleUtils method isWebApplicationBundle.
public static boolean isWebApplicationBundle(DeploymentUnit depUnit) {
// JAR deployments may contain OSGi metadata with a "Web-ContextPath" header
// This qualifies them as OSGi Web Application Bundle (WAB)
String deploymentName = depUnit.getName().toLowerCase(Locale.ENGLISH);
Manifest manifest = depUnit.getAttachment(Attachments.OSGI_MANIFEST);
if (manifest != null && deploymentName.endsWith(".jar")) {
if (ManifestHelper.hasMainAttributeValue(manifest, "Web-ContextPath")) {
return true;
}
}
// transformed into an OSGi Web Application Bundle (WAB)
if (deploymentName.startsWith("webbundle:")) {
return true;
}
return false;
}
use of java.util.jar.Manifest in project intellij-community by JetBrains.
the class PrepareToDeployAction method createOrFindManifest.
public static Manifest createOrFindManifest(final PluginBuildConfiguration pluginModuleBuildProperties) throws IOException {
final Manifest manifest = new Manifest();
final VirtualFile vManifest = pluginModuleBuildProperties.getManifest();
if (pluginModuleBuildProperties.isUseUserManifest() && vManifest != null) {
InputStream in = null;
try {
in = new BufferedInputStream(vManifest.getInputStream());
manifest.read(in);
} finally {
if (in != null)
in.close();
}
} else {
Attributes mainAttributes = manifest.getMainAttributes();
ManifestBuilder.setGlobalAttributes(mainAttributes);
}
return manifest;
}
Aggregations