本文整理了Java中java.util.jar.Manifest.getMainAttributes()
方法的一些代码示例,展示了Manifest.getMainAttributes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Manifest.getMainAttributes()
方法的具体详情如下:
包路径:java.util.jar.Manifest
类名称:Manifest
方法名:getMainAttributes
[英]Returns the main Attributes of the JarFile.
[中]返回文件的主要属性。
代码示例来源:origin: jenkinsci/jenkins
private String getVersionOf(Manifest manifest) {
String v = manifest.getMainAttributes().getValue("Plugin-Version");
if(v!=null) return v;
// plugins generated before maven-hpi-plugin 1.3 should still have this attribute
v = manifest.getMainAttributes().getValue("Implementation-Version");
if(v!=null) return v;
return "???";
}
代码示例来源:origin: jenkinsci/jenkins
protected String identifyPluginShortName(File t) {
try {
JarFile j = new JarFile(t);
try {
String name = j.getManifest().getMainAttributes().getValue("Short-Name");
if (name!=null) return name;
} finally {
j.close();
}
} catch (IOException e) {
LOGGER.log(WARNING, "Failed to identify the short name from "+t,e);
}
return FilenameUtils.getBaseName(t.getName()); // fall back to the base name of what's uploaded
}
代码示例来源:origin: gocd/gocd
private static String defaultMainClassName(JarFile jarFile) throws IOException {
return jarFile.getManifest().getMainAttributes().getValue("GoCD-Main-Class");
}
}
代码示例来源:origin: skylot/jadx
public static String getVersion() {
try {
ClassLoader classLoader = Jadx.class.getClassLoader();
if (classLoader != null) {
Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
Manifest manifest = new Manifest(resources.nextElement().openStream());
String ver = manifest.getMainAttributes().getValue("jadx-version");
if (ver != null) {
return ver;
}
}
}
} catch (Exception e) {
LOG.error("Can't get manifest file", e);
}
return "dev";
}
}
代码示例来源:origin: jenkinsci/jenkins
private static void parseClassPath(Manifest manifest, File archive, List<File> paths, String attributeName, String separator) throws IOException {
String classPath = manifest.getMainAttributes().getValue(attributeName);
if(classPath==null) return; // attribute not found
for (String s : classPath.split(separator)) {
File file = resolve(archive, s);
if(file.getName().contains("*")) {
// handle wildcard
FileSet fs = new FileSet();
File dir = file.getParentFile();
fs.setDir(dir);
fs.setIncludes(file.getName());
for( String included : fs.getDirectoryScanner(new Project()).getIncludedFiles() ) {
paths.add(new File(dir,included));
}
} else {
if(!file.exists())
throw new IOException("No such file: "+file);
paths.add(file);
}
}
}
代码示例来源:origin: stackoverflow.com
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
JarOutputStream target = new JarOutputStream(new FileOutputStream("output.jar"), manifest);
add(new File("inputDirectory"), target);
target.close();
代码示例来源:origin: apache/hive
/**
* Loads the manifest attributes from the jar.
*
* @throws java.net.MalformedURLException
* @throws IOException
*/
private static synchronized void loadManifestAttributes() throws IOException {
if (manifestAttributes != null) {
return;
}
Class<?> clazz = HiveDriver.class;
String classContainer = clazz.getProtectionDomain().getCodeSource()
.getLocation().toString();
URL manifestUrl = new URL("jar:" + classContainer
+ "!/META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(manifestUrl.openStream());
manifestAttributes = manifest.getMainAttributes();
}
代码示例来源:origin: aws/aws-sdk-java
private static String kotlinVersionByJar() {
StringBuilder kotlinVersion = new StringBuilder("");
JarInputStream kotlinJar = null;
try {
Class<?> kotlinUnit = Class.forName("kotlin.Unit");
kotlinVersion.append("kotlin");
kotlinJar = new JarInputStream(kotlinUnit.getProtectionDomain().getCodeSource().getLocation().openStream());
String version = kotlinJar.getManifest().getMainAttributes().getValue("Implementation-Version");
concat(kotlinVersion, version, "/");
} catch (ClassNotFoundException e) {
//Ignore
} catch (Exception e) {
if (log.isTraceEnabled()) {
log.trace("Exception attempting to get Kotlin version.", e);
}
} finally {
closeQuietly(kotlinJar, log);
}
return kotlinVersion.toString();
}
代码示例来源:origin: scouter-project/scouter
public static void print() throws IOException {
InputStream manifestStream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("META-INF/MANIFEST.MF");
try {
Manifest manifest = new Manifest(manifestStream);
Attributes attributes = manifest.getMainAttributes();
String impVersion = attributes.getValue("Implementation-Version");
System.out.println(attributes);
} catch (IOException ex) {
ex.printStackTrace();
}
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public File toJar(File file) throws IOException {
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION);
return toJar(file, manifest);
}
代码示例来源:origin: pxb1988/dex2jar
Manifest input = jar.getManifest();
Manifest output = new Manifest();
Attributes main = output.getMainAttributes();
if (input != null) {
main.putAll(input.getMainAttributes());
代码示例来源:origin: robovm/robovm
/**
* Gets all attributes of the manifest file referenced by this {@code
* JarURLConnection}. If this instance refers to a JAR-file rather than a
* JAR-file entry, {@code null} will be returned.
*
* @return the attributes of the manifest file or {@code null}.
* @throws IOException
* if an I/O exception occurs while retrieving the {@code
* JarFile}.
*/
public Attributes getMainAttributes() throws java.io.IOException {
Manifest m = getJarFile().getManifest();
return (m == null) ? null : m.getMainAttributes();
}
}
代码示例来源:origin: stackoverflow.com
Class clazz = MyClass.class;
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
if (!classPath.startsWith("jar")) {
// Class not from JAR
return;
}
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
"/META-INF/MANIFEST.MF";
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();
String value = attr.getValue("Manifest-Version");
代码示例来源:origin: gocd/gocd
public static String getCruiseVersion(String jar) {
String version = null;
try {
JarFile jarFile = new JarFile(jar);
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
Attributes attributes = manifest.getMainAttributes();
version = attributes.getValue("Go-Version");
}
} catch (IOException e) {
}
return version;
}
代码示例来源:origin: redisson/redisson
Attributes attributes = manifest.getMainAttributes();
if (attributes == null) {
return;
String s = attributes.getValue(Attributes.Name.CLASS_PATH);
if (s == null) {
return;
file = new File(base, t);
file = file.getCanonicalFile();
if (!file.exists()) {
file = new File(t);
file = file.getCanonicalFile();
if (!file.exists()) {
URL url = new URL(t);
file = new File(url.getFile());
file = file.getCanonicalFile();
if (!file.exists()) {
代码示例来源:origin: apache/geode
Path locationPath = new File(location).getCanonicalFile().toPath();
Files.createDirectories(locationPath);
Manifest manifest = new Manifest();
Attributes global = manifest.getMainAttributes();
global.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
global.put(new Attributes.Name("Class-Path"), String.join(" ", manifestEntries));
代码示例来源:origin: chewiebug/GCViewer
/**
* Returns Manifest-Attributes for MANIFEST.MF, if running for a .jar file
*
* @return Manifest Attributes (may be empty but never null)
* @throws IOException If something went wrong finding the MANIFEST file
* @see <a href="http://stackoverflow.com/a/1273432">stackoverflow article</a>
*/
private static Attributes getAttributes() throws IOException {
Class clazz = BuildInfoReader.class;
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
if (!classPath.startsWith("jar")) {
// Class not from JAR
return new Attributes(0);
}
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + FILE_NAME;
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
return manifest.getMainAttributes();
}
代码示例来源:origin: jenkinsci/jenkins
static String computeShortName(Manifest manifest, String fileName) {
// use the name captured in the manifest, as often plugins
// depend on the specific short name in its URLs.
String n = manifest.getMainAttributes().getValue("Short-Name");
if(n!=null) return n;
// maven seems to put this automatically, so good fallback to check.
n = manifest.getMainAttributes().getValue("Extension-Name");
if(n!=null) return n;
// otherwise infer from the file name, since older plugins don't have
// this entry.
return getBaseName(fileName);
}
代码示例来源:origin: scouter-project/scouter
public static void print() throws IOException {
InputStream manifestStream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("META-INF/MANIFEST.MF");
try {
Manifest manifest = new Manifest(manifestStream);
Attributes attributes = manifest.getMainAttributes();
String impVersion = attributes.getValue("Implementation-Version");
System.out.println(attributes);
} catch (IOException ex) {
ex.printStackTrace();
}
}
代码示例来源:origin: gocd/gocd
private static String getManifestKey(JarFile jarFile, String key) {
try {
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
Attributes attributes = manifest.getMainAttributes();
return attributes.getValue(key);
}
} catch (IOException e) {
LOG.error("Exception while trying to read key {} from manifest of {}", key, jarFile.getName(), e);
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!