本文整理汇总了Java中java.util.jar.Manifest.getMainAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java Manifest.getMainAttributes方法的具体用法?Java Manifest.getMainAttributes怎么用?Java Manifest.getMainAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.Manifest
的用法示例。
在下文中一共展示了Manifest.getMainAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVersion
import java.util.jar.Manifest; //导入方法依赖的package包/类
private static String getVersion() {
try {
final Enumeration resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
while (resEnum.hasMoreElements()) {
try {
final URL url = (URL) resEnum.nextElement();
final InputStream is = url.openStream();
if (is != null) {
final Manifest manifest = new Manifest(is);
final Attributes mainAttribs = manifest.getMainAttributes();
final String version = mainAttribs.getValue("Walle-Version");
if (version != null) {
return version;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (IOException e1) {
e1.printStackTrace();
}
return null;
}
示例2: updateClasspath
import java.util.jar.Manifest; //导入方法依赖的package包/类
/** Add the jar file to the classpath in the MANIFEST.MF file */
@Override
protected void updateClasspath(Manifest manifest) throws DeployException {
Attributes mainAttributes = manifest.getMainAttributes();
String classpath = null;
if (mainAttributes != null) {
classpath = mainAttributes.getValue(Attributes.Name.CLASS_PATH);
}
String newJar = getJarFileNameWithDotSlash();
if (classpath == null) {
mainAttributes.put(Attributes.Name.CLASS_PATH, newJar);
System.out.println("Added " + newJar + " to classpath");
} else if (classpath.indexOf(newJar) < 0) {
mainAttributes.put(Attributes.Name.CLASS_PATH, classpath + " " + newJar);
System.out.println("Added " + newJar + " to classpath");
} else {
System.out.println(newJar + " already on the classpath.");
}
}
示例3: testWithAddOpensInManifest
import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
* Specify Add-Opens in JAR file manifest
*/
public void testWithAddOpensInManifest() throws Exception {
Manifest man = new Manifest();
Attributes attrs = man.getMainAttributes();
attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
attrs.put(Attributes.Name.MAIN_CLASS, "TryAccess");
attrs.put(new Attributes.Name("Add-Opens"), "java.base/java.lang");
Path jarfile = Paths.get("x.jar");
Path classes = Paths.get(TEST_CLASSES);
JarUtils.createJarFile(jarfile, man, classes, Paths.get("TryAccess.class"));
run(jarfile, "setAccessibleNonPublicMemberExportedPackage", successNoWarning());
run(jarfile, "reflectPublicMemberNonExportedPackage", successWithWarning());
// attempt two illegal accesses, one allowed by Add-Opens
run(jarfile, "reflectPublicMemberNonExportedPackage,"
+ "setAccessibleNonPublicMemberExportedPackage",
successWithWarning());
}
示例4: setUp
import java.util.jar.Manifest; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
clearWorkDir();
f = new File(getWorkDir(), "m.jar");
Manifest man = new Manifest();
Attributes attr = man.getMainAttributes();
attr.putValue("OpenIDE-Module", "m.test");
attr.putValue("OpenIDE-Module-Public-Packages", "-");
attr.putValue("Manifest-Version", "1.0");
JarOutputStream os = new JarOutputStream(new FileOutputStream(f), man);
os.putNextEntry(new JarEntry("META-INF/namedservices/ui/javax.swing.JComponent"));
os.write("javax.swing.JButton\n".getBytes("UTF-8"));
os.closeEntry();
os.close();
FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), "ui/ch/my/javax-swing-JPanel.instance");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:RecognizeInstanceObjectsOnModuleEnablementTest.java
示例5: isPackageSealed
import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
* Returns true if the specified package name is sealed according to the
* given manifest.
*/
protected boolean isPackageSealed(String name, Manifest man) {
String path = name.replace('.', '/') + '/';
Attributes attr = man.getAttributes(path);
String sealed = null;
if (attr != null) {
sealed = attr.getValue(Name.SEALED);
}
if (sealed == null) {
if ((attr = man.getMainAttributes()) != null) {
sealed = attr.getValue(Name.SEALED);
}
}
return "true".equalsIgnoreCase(sealed);
}
示例6: getAvailableExtensions
import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
* Return the set of <code>Extension</code> objects representing optional
* packages that are bundled with the application associated with the
* specified <code>Manifest</code>.
*
* @param manifest
* Manifest to be parsed
*
* @return List of available extensions, or null if the web application does
* not bundle any extensions
*/
private ArrayList<Extension> getAvailableExtensions(Manifest manifest) {
Attributes attributes = manifest.getMainAttributes();
String name = attributes.getValue("Extension-Name");
if (name == null)
return null;
ArrayList<Extension> extensionList = new ArrayList<Extension>();
Extension extension = new Extension();
extension.setExtensionName(name);
extension.setImplementationURL(attributes.getValue("Implementation-URL"));
extension.setImplementationVendor(attributes.getValue("Implementation-Vendor"));
extension.setImplementationVendorId(attributes.getValue("Implementation-Vendor-Id"));
extension.setImplementationVersion(attributes.getValue("Implementation-Version"));
extension.setSpecificationVersion(attributes.getValue("Specification-Version"));
extensionList.add(extension);
return extensionList;
}
示例7: testMainClass
import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
* Test that a JAR file with a Main-Class attribute results
* in a module with a main class.
*/
public void testMainClass() throws IOException {
String mainClass = "p.Main";
Manifest man = new Manifest();
Attributes attrs = man.getMainAttributes();
attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
attrs.put(Attributes.Name.MAIN_CLASS, mainClass);
Path dir = Files.createTempDirectory(USER_DIR, "mods");
String entry = mainClass.replace('.', '/') + ".class";
createDummyJarFile(dir.resolve("m.jar"), man, entry);
ModuleFinder finder = ModuleFinder.of(dir);
Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = resolve(parent, finder, "m");
ModuleDescriptor descriptor = findDescriptor(cf, "m");
assertTrue(descriptor.mainClass().isPresent());
assertEquals(descriptor.mainClass().get(), mainClass);
}
示例8: getMainClassFromJar
import java.util.jar.Manifest; //导入方法依赖的package包/类
static String getMainClassFromJar(String jarname) {
String mainValue = null;
try (JarFile jarFile = new JarFile(jarname)) {
Manifest manifest = jarFile.getManifest();
if (manifest == null) {
abort(null, "java.launcher.jar.error2", jarname);
}
Attributes mainAttrs = manifest.getMainAttributes();
if (mainAttrs == null) {
abort(null, "java.launcher.jar.error3", jarname);
}
mainValue = mainAttrs.getValue(MAIN_CLASS);
if (mainValue == null) {
abort(null, "java.launcher.jar.error3", jarname);
}
/*
* Hand off to FXHelper if it detects a JavaFX application
* This must be done after ensuring a Main-Class entry
* exists to enforce compliance with the jar specification
*/
if (mainAttrs.containsKey(
new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) {
return FXHelper.class.getName();
}
return mainValue.trim();
} catch (IOException ioe) {
abort(ioe, "java.launcher.jar.error1", jarname);
}
return null;
}
示例9: getRequiredExtensions
import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
* Return the set of <code>Extension</code> objects representing optional
* packages that are required by the application associated with the
* specified <code>Manifest</code>.
*
* @param manifest Manifest to be parsed
*
* @return List of required extensions, or null if the application
* does not require any extensions
*/
private ArrayList<Extension> getRequiredExtensions(Manifest manifest) {
Attributes attributes = manifest.getMainAttributes();
String names = attributes.getValue("Extension-List");
if (names == null)
return null;
ArrayList<Extension> extensionList = new ArrayList<Extension>();
names += " ";
while (true) {
int space = names.indexOf(' ');
if (space < 0)
break;
String name = names.substring(0, space).trim();
names = names.substring(space + 1);
String value =
attributes.getValue(name + "-Extension-Name");
if (value == null)
continue;
Extension extension = new Extension();
extension.setExtensionName(value);
extension.setImplementationURL
(attributes.getValue(name + "-Implementation-URL"));
extension.setImplementationVendorId
(attributes.getValue(name + "-Implementation-Vendor-Id"));
String version = attributes.getValue(name + "-Implementation-Version");
extension.setImplementationVersion(version);
extension.setSpecificationVersion
(attributes.getValue(name + "-Specification-Version"));
extensionList.add(extension);
}
return extensionList;
}
示例10: getJarPath
import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
* Generates the transitive closure of the Class-Path attribute for
* the specified jar file.
*/
List<String> getJarPath(String jar) throws IOException {
List<String> files = new ArrayList<String>();
files.add(jar);
jarPaths.add(jar);
// take out the current path
String path = jar.substring(0, Math.max(0, jar.lastIndexOf('/') + 1));
// class path attribute will give us jar file name with
// '/' as separators, so we need to change them to the
// appropriate one before we open the jar file.
JarFile rf = new JarFile(jar.replace('/', File.separatorChar));
if (rf != null) {
Manifest man = rf.getManifest();
if (man != null) {
Attributes attr = man.getMainAttributes();
if (attr != null) {
String value = attr.getValue(Attributes.Name.CLASS_PATH);
if (value != null) {
StringTokenizer st = new StringTokenizer(value);
while (st.hasMoreTokens()) {
String ajar = st.nextToken();
if (!ajar.endsWith("/")) { // it is a jar file
ajar = path.concat(ajar);
/* check on cyclic dependency */
if (! jarPaths.contains(ajar)) {
files.addAll(getJarPath(ajar));
}
}
}
}
}
}
}
rf.close();
return files;
}
示例11: testGoodESVersionInJar
import java.util.jar.Manifest; //导入方法依赖的package包/类
/** make sure if a plugin is compiled against the same ES version, it works */
public void testGoodESVersionInJar() throws Exception {
Path dir = createTempDir();
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
attributes.put(new Attributes.Name("X-Compile-Elasticsearch-Version"), Version.CURRENT.toString());
URL[] jars = {makeJar(dir, "foo.jar", manifest, "Foo.class")};
JarHell.checkJarHell(jars);
}
示例12: processManifest
import java.util.jar.Manifest; //导入方法依赖的package包/类
private static void processManifest(final List<VersionLine> components, final URL url) {
try (InputStream is = url.openStream()) {
final Manifest manifest = new Manifest(is);
final Attributes attributes = manifest.getMainAttributes();
final String artifact = attributes.getValue(ARTIFACT_ATTRIBUTE);
if (artifact != null && !artifact.isEmpty()) {
components.add(maakVersionLine(attributes));
}
} catch (final IOException e) {
LOGGER.warn("Could not read manifest: {} ", url, e);
}
}
示例13: outputToJar
import java.util.jar.Manifest; //导入方法依赖的package包/类
/**
* Generate output JAR-file and packages
*/
public void outputToJar() throws IOException {
// create the manifest
final Manifest manifest = new Manifest();
final java.util.jar.Attributes atrs = manifest.getMainAttributes();
atrs.put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.2");
final Map<String, Attributes> map = manifest.getEntries();
// create manifest
final String now = (new Date()).toString();
final java.util.jar.Attributes.Name dateAttr =
new java.util.jar.Attributes.Name("Date");
final File jarFile = new File(_destDir, _jarFileName);
final JarOutputStream jos =
new JarOutputStream(new FileOutputStream(jarFile), manifest);
for (JavaClass clazz : _bcelClasses) {
final String className = clazz.getClassName().replace('.', '/');
final java.util.jar.Attributes attr = new java.util.jar.Attributes();
attr.put(dateAttr, now);
map.put(className + ".class", attr);
jos.putNextEntry(new JarEntry(className + ".class"));
final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
clazz.dump(out); // dump() closes it's output stream
out.writeTo(jos);
}
jos.close();
}
示例14: jarFileOf
import java.util.jar.Manifest; //导入方法依赖的package包/类
@Test
public void jarFileOf() throws IOException {
JarFile jf = Classes.jarFileOf(DateTimeZone.class);
Manifest mf = jf.getManifest();
Attributes attrs = mf.getMainAttributes();
String name = attrs.getValue("Bundle-Name");
String version = attrs.getValue("Bundle-Version");
if (VERBOSE) {
System.out.println(name);
System.out.println(version);
}
assertNotNull(name);
assertNotNull(version);
}
示例15: testCreateModule
import java.util.jar.Manifest; //导入方法依赖的package包/类
public void testCreateModule() {
String codeName = "test-module";
String specificationVersion = "1.0";
URL distribution = null;
try {
new URL ("http://netbeans.de/module.nbm");
} catch (MalformedURLException ex) {
fail (ex.getMessage ());
}
String author = "Jiri Rechtacek";
String downloadSize = "12";
String homepage = "http://netbeans.de";
Manifest manifest = new Manifest ();
Attributes mfAttrs = manifest.getMainAttributes ();
mfAttrs.put (new Attributes.Name ("OpenIDE-Module"), "org.myorg.module/1");
mfAttrs.put (new Attributes.Name ("OpenIDE-Module-Implementation-Version"), "060216");
mfAttrs.put (new Attributes.Name ("OpenIDE-Module-Long-Description"), "Real module Hello installs Hello menu item into Help menu.");
mfAttrs.put (new Attributes.Name ("OpenIDE-Module-Module-Dependencies"), "org.openide.util > 6.9.0.1");
mfAttrs.put (new Attributes.Name ("OpenIDE-Module-Name"), "module");
mfAttrs.put (new Attributes.Name ("OpenIDE-Module-Requires"), "org.openide.modules.ModuleFormat1");
mfAttrs.put (new Attributes.Name ("OpenIDE-Module-Specification-Version"), "1.0");
UpdateLicense license = UpdateLicense.createUpdateLicense ("none-license", "no-license");
UpdateItem result = UpdateItem.createModule(codeName,
specificationVersion,
distribution, author, downloadSize,
homepage, null, "test-category",
manifest, false, false, true, true, "my-cluster",
license);
assertNotNull ("Module UpdateItem was created.", result);
}