use of java.util.jar.Attributes in project robovm by robovm.
the class URLClassLoader method definePackage.
/**
* Defines a new package using the information extracted from the specified
* manifest.
*
* @param packageName
* the name of the new package.
* @param manifest
* the manifest containing additional information for the new
* package.
* @param url
* the URL to the code source for the new package.
* @return the created package.
* @throws IllegalArgumentException
* if a package with the given name already exists.
*/
protected Package definePackage(String packageName, Manifest manifest, URL url) throws IllegalArgumentException {
Attributes mainAttributes = manifest.getMainAttributes();
String dirName = packageName.replace('.', '/') + "/";
Attributes packageAttributes = manifest.getAttributes(dirName);
boolean noEntry = false;
if (packageAttributes == null) {
noEntry = true;
packageAttributes = mainAttributes;
}
String specificationTitle = packageAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE);
if (specificationTitle == null && !noEntry) {
specificationTitle = mainAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE);
}
String specificationVersion = packageAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
if (specificationVersion == null && !noEntry) {
specificationVersion = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
}
String specificationVendor = packageAttributes.getValue(Attributes.Name.SPECIFICATION_VENDOR);
if (specificationVendor == null && !noEntry) {
specificationVendor = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VENDOR);
}
String implementationTitle = packageAttributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
if (implementationTitle == null && !noEntry) {
implementationTitle = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
}
String implementationVersion = packageAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (implementationVersion == null && !noEntry) {
implementationVersion = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
}
String implementationVendor = packageAttributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
if (implementationVendor == null && !noEntry) {
implementationVendor = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
}
return definePackage(packageName, specificationTitle, specificationVersion, specificationVendor, implementationTitle, implementationVersion, implementationVendor, isSealed(manifest, dirName) ? url : null);
}
use of java.util.jar.Attributes in project robovm by robovm.
the class OldJarURLConnectionTest method test_getMainAttributes.
public void test_getMainAttributes() throws Exception {
URL u = createContent("lf.jar", "swt.dll");
juc = (JarURLConnection) u.openConnection();
java.util.jar.Attributes a = juc.getMainAttributes();
assertEquals("Returned incorrect Attributes", "1.0", a.get(java.util.jar.Attributes.Name.MANIFEST_VERSION));
URL invURL = createContent("InvalidJar.jar", "Test.class");
JarURLConnection juConn = (JarURLConnection) invURL.openConnection();
try {
juConn.getMainAttributes();
fail("IOException was not thrown.");
} catch (java.io.IOException io) {
//expected
}
}
use of java.util.jar.Attributes in project bazel by bazelbuild.
the class SingleJar method createManifest.
/**
* Creates a manifest and returns an input stream for its contents.
*/
private InputStream createManifest() throws IOException {
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
attributes.put(new Attributes.Name("Created-By"), "blaze-singlejar");
if (mainClass != null) {
attributes.put(Attributes.Name.MAIN_CLASS, mainClass);
}
if (extraManifestContent != null) {
ByteArrayInputStream in = new ByteArrayInputStream(extraManifestContent.getBytes("UTF8"));
manifest.read(in);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
manifest.write(out);
return new ByteArrayInputStream(out.toByteArray());
}
use of java.util.jar.Attributes in project platform_frameworks_base by android.
the class StrictJarManifest method write.
/**
* Writes out the attribute information of the specified manifest to the
* specified {@code OutputStream}
*
* @param manifest
* the manifest to write out.
* @param out
* The {@code OutputStream} to write to.
* @throws IOException
* If an error occurs writing the {@code StrictJarManifest}.
*/
static void write(StrictJarManifest manifest, OutputStream out) throws IOException {
CharsetEncoder encoder = StandardCharsets.UTF_8.newEncoder();
ByteBuffer buffer = ByteBuffer.allocate(LINE_LENGTH_LIMIT);
Attributes.Name versionName = Attributes.Name.MANIFEST_VERSION;
String version = manifest.mainAttributes.getValue(versionName);
if (version == null) {
versionName = Attributes.Name.SIGNATURE_VERSION;
version = manifest.mainAttributes.getValue(versionName);
}
if (version != null) {
writeEntry(out, versionName, version, encoder, buffer);
Iterator<?> entries = manifest.mainAttributes.keySet().iterator();
while (entries.hasNext()) {
Attributes.Name name = (Attributes.Name) entries.next();
if (!name.equals(versionName)) {
writeEntry(out, name, manifest.mainAttributes.getValue(name), encoder, buffer);
}
}
}
out.write(LINE_SEPARATOR);
Iterator<String> i = manifest.getEntries().keySet().iterator();
while (i.hasNext()) {
String key = i.next();
writeEntry(out, Attributes.Name.NAME, key, encoder, buffer);
Attributes attributes = manifest.entries.get(key);
Iterator<?> entries = attributes.keySet().iterator();
while (entries.hasNext()) {
Attributes.Name name = (Attributes.Name) entries.next();
writeEntry(out, name, attributes.getValue(name), encoder, buffer);
}
out.write(LINE_SEPARATOR);
}
}
use of java.util.jar.Attributes in project gocd by gocd.
the class JarUtil method getManifestKey.
public static String getManifestKey(String jar, String key) {
String version = null;
try {
JarFile jarFile = new JarFile(jar);
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
Attributes attributes = manifest.getMainAttributes();
version = attributes.getValue(key);
}
} catch (IOException e) {
LOG.error("Exception while trying to read Go-Version from " + jar + ":" + e.toString());
}
return version;
}
Aggregations