use of java.util.jar.Manifest in project robovm by robovm.
the class OldURLClassLoaderTest method test_definePackage.
public void test_definePackage() throws MalformedURLException {
Manifest manifest = new Manifest();
URL[] u = new URL[0];
TestURLClassLoader tucl = new TestURLClassLoader(u);
URL[] urls = { new URL("http://foo.com/foo"), new URL("jar:file://foo.jar!/foo.c"), new URL("ftp://foo1/foo2/foo.c"), new URL("file://new/package/name/"), null };
String packageName = "new.package.name";
for (int i = 0; i < urls.length; i++) {
Package pack = tucl.definePackage(packageName + i, manifest, urls[i]);
assertEquals(packageName + i, pack.getName());
assertNull("Implementation Title is not null", pack.getImplementationTitle());
assertNull("Implementation Vendor is not null", pack.getImplementationVendor());
assertNull("Implementation Version is not null.", pack.getImplementationVersion());
}
try {
tucl.definePackage(packageName + "0", manifest, null);
fail("IllegalArgumentException was not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
}
use of java.util.jar.Manifest 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.Manifest in project gradle by gradle.
the class DefaultManifest method writeTo.
@Deprecated
@Override
public DefaultManifest writeTo(Writer writer) {
SingleMessageLogger.nagUserOfDeprecated("Manifest.writeTo(Writer)", "Please use Manifest.writeTo(Object) instead");
try {
Manifest javaManifest = generateJavaManifest(getEffectiveManifest());
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
javaManifest.write(buffer);
String manifestContent = buffer.toString(DEFAULT_CONTENT_CHARSET);
if (!DEFAULT_CONTENT_CHARSET.equals(contentCharset)) {
// Convert the UTF-8 manifest bytes to the requested content charset
manifestContent = new String(manifestContent.getBytes(contentCharset), contentCharset);
}
writer.write(manifestContent);
writer.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return this;
}
use of java.util.jar.Manifest 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;
}
use of java.util.jar.Manifest in project bazel by bazelbuild.
the class JarCreator method manifestContent.
private byte[] manifestContent() throws IOException {
Manifest manifest;
if (manifestFile != null) {
FileInputStream in = new FileInputStream(manifestFile);
manifest = new Manifest(in);
} else {
manifest = new Manifest();
}
Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
Attributes.Name createdBy = new Attributes.Name("Created-By");
if (attributes.getValue(createdBy) == null) {
attributes.put(createdBy, "blaze");
}
if (mainClass != null) {
attributes.put(Attributes.Name.MAIN_CLASS, mainClass);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
manifest.write(out);
return out.toByteArray();
}
Aggregations