当前位置: 首页>>代码示例>>Java>>正文


Java Manifest类代码示例

本文整理汇总了Java中java.util.jar.Manifest的典型用法代码示例。如果您正苦于以下问题:Java Manifest类的具体用法?Java Manifest怎么用?Java Manifest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Manifest类属于java.util.jar包,在下文中一共展示了Manifest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findVersionInfo

import java.util.jar.Manifest; //导入依赖的package包/类
private static String findVersionInfo(String applicationName) throws IOException {
    Enumeration<URL> resources = Thread.currentThread().getContextClassLoader()
            .getResources("META-INF/MANIFEST.MF");
    while (resources.hasMoreElements()) {
        URL manifestUrl = resources.nextElement();
        Manifest manifest = new Manifest(manifestUrl.openStream());
        Attributes mainAttributes = manifest.getMainAttributes();
        String implementationTitle = mainAttributes.getValue("Implementation-Title");
        if (implementationTitle != null && implementationTitle.equals(applicationName)) {
            String implementationVersion = mainAttributes.getValue("Implementation-Version");
            String buildTime = mainAttributes.getValue("Build-Time");
            return implementationVersion + " (" + buildTime + ")";
        }
    }
    return "Current Version";
}
 
开发者ID:schwabdidier,项目名称:GazePlay,代码行数:17,代码来源:GazePlayLauncher.java

示例2: writeTo

import java.util.jar.Manifest; //导入依赖的package包/类
static void writeTo(org.gradle.api.java.archives.Manifest manifest, OutputStream outputStream, String contentCharset) {
    try {
        Manifest javaManifest = generateJavaManifest(manifest.getEffectiveManifest());
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        javaManifest.write(buffer);
        byte[] manifestBytes;
        if (DEFAULT_CONTENT_CHARSET.equals(contentCharset)) {
            manifestBytes = buffer.toByteArray();
        } else {
            // Convert the UTF-8 manifest bytes to the requested content charset
            manifestBytes = buffer.toString(DEFAULT_CONTENT_CHARSET).getBytes(contentCharset);
        }
        outputStream.write(manifestBytes);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:DefaultManifest.java

示例3: read

import java.util.jar.Manifest; //导入依赖的package包/类
private void read(Object manifestPath) {
    File manifestFile = fileResolver.resolve(manifestPath);
    try {
        byte[] manifestBytes = FileUtils.readFileToByteArray(manifestFile);
        manifestBytes = prepareManifestBytesForInteroperability(manifestBytes);
        // Eventually convert manifest content to UTF-8 before handing it to java.util.jar.Manifest
        if (!DEFAULT_CONTENT_CHARSET.equals(contentCharset)) {
            manifestBytes = new String(manifestBytes, contentCharset).getBytes(DEFAULT_CONTENT_CHARSET);
        }
        // Effectively read the manifest
        Manifest javaManifest = new Manifest(new ByteArrayInputStream(manifestBytes));
        addJavaManifestToAttributes(javaManifest);
        addJavaManifestToSections(javaManifest);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:DefaultManifest.java

示例4: execute

import java.util.jar.Manifest; //导入依赖的package包/类
@Override
public void execute() throws BuildException {
    if (manifest == null) {
        throw new BuildException("Must specify parameter 'manifest'.");
    }
    if (property == null) {
        throw new BuildException("Must specify parameter 'property'.");
    }
    if (attribute == null) {
        throw new BuildException("Must specify parameter 'attribute'.");
    }
    try {
        try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(manifest))) {
            Manifest mf = new Manifest(is);
            String attr = mf.getMainAttributes().getValue(attribute);
            if (attr == null)
                return;
            getProject().setProperty(property, attr);
        }
    } catch (Exception x) {
        throw new BuildException("Reading manifest " + manifest + ": " + x, x, getLocation());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ParseManifest.java

示例5: addDependencies

import java.util.jar.Manifest; //导入依赖的package包/类
private static void addDependencies (TreeSet<Dependency> addTo, java.util.jar.Manifest man, Dependency.Type dependencyType, String attrName) throws BuildException {
    String value = man.getMainAttributes ().getValue (attrName);
    if (value == null) {
        return;
    }
    
    StringTokenizer tok = new StringTokenizer (value, ",");
    while (tok.hasMoreElements ()) {
        String nextDep = tok.nextToken ();
        StringTokenizer dep = new StringTokenizer (nextDep, "=>", true);
        if (dep.countTokens () == 1) {
            addTo.add (new Dependency (dep.nextToken ().trim (), dependencyType, false, null));
            continue;
        }

        if (dep.countTokens () == 3) {
            String name = dep.nextToken ().trim ();
            String equal = dep.nextToken ().trim ();
            String comp = dep.nextToken ().trim ();
            addTo.add (new Dependency (name, dependencyType, equal.equals ("="), comp));
            continue;
        }
        
        throw new BuildException ("Cannot parse dependency: " + value);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ModuleDependencies.java

示例6: readFromManifest

import java.util.jar.Manifest; //导入依赖的package包/类
private Bundle readFromManifest ( final String location, final Manifest m ) throws IOException
{
    final Object sn = m.getMainAttributes ().getValue ( Constants.BUNDLE_SYMBOLICNAME );
    if ( ! ( sn instanceof String ) )
    {
        return null;
    }

    final Object version = m.getMainAttributes ().getValue ( Constants.BUNDLE_VERSION );
    if ( ! ( version instanceof String ) )
    {
        return null;
    }

    String symName = (String)sn;
    symName = symName.split ( ";", 2 )[0];

    return new Bundle ( symName, new Version ( (String)version ), location );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:20,代码来源:Starter.java

示例7: 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);

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:21,代码来源:WebappClassLoaderBase.java

示例8: findImpl

import java.util.jar.Manifest; //导入依赖的package包/类
final String[] findImpl(URL src, Manifest man, String path) {
    String key = src.toExternalForm();
    if (key.startsWith("jar:file:")) { // NOI18N
        key = key.substring(9);
    }
    if (!key.endsWith("!/")) { // NOI18N
        key += "!/"; // NOI18N
    }
    key += path;
    String[] arr;
    if (cache instanceof ConcurrentHashMap) {
        arr = extractFromManifest(man, path);
        if (isEmpty(arr)) {
            arr = EMPTY;
        } else {
            cache.put(key, arr);
        }
    } else {
        arr = cache.get(key);
        if (arr == null) {
            arr = EMPTY;
        }
    }
    return arr;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:PackageAttrsCache.java

示例9: updateManifest

import java.util.jar.Manifest; //导入依赖的package包/类
private boolean updateManifest(Manifest m, ZipOutputStream zos)
    throws IOException
{
    addVersion(m);
    addCreatedBy(m);
    if (ename != null) {
        addMainClass(m, ename);
    }
    ZipEntry e = new ZipEntry(MANIFEST_NAME);
    e.setTime(System.currentTimeMillis());
    if (flag0) {
        crc32Manifest(e, m);
    }
    zos.putNextEntry(e);
    m.write(zos);
    if (vflag) {
        output(getMsg("out.update.manifest"));
    }
    return true;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:Main.java

示例10: createModuleJar

import java.util.jar.Manifest; //导入依赖的package包/类
private File createModuleJar(String manifest) throws IOException {
    // XXX use TestFileUtils.writeZipFile
    File jarFile = new File( getWorkDir(), "mymodule.jar" );
    
    JarOutputStream os = new JarOutputStream(new FileOutputStream(jarFile), new Manifest(
        new ByteArrayInputStream(manifest.getBytes())
    ));
    JarEntry entry = new JarEntry("foo/mf-layer.xml");
    os.putNextEntry( entry );
    
    File l3 = new File(new File(new File(getDataDir(), "layers"), "data"), "layer3.xml");
    InputStream is = new FileInputStream(l3);
    FileUtil.copy( is, os );
    is.close();
    os.close();
    
    return jarFile;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:RemoveWritablesTest.java

示例11: getMeta

import java.util.jar.Manifest; //导入依赖的package包/类
@Override
protected Manifest getMeta() {
    Manifest manifest = new Manifest();
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (ApkPatch)");
    main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
    main.putValue("Patch-Name", name);
    main.putValue(name + "-Patch-Classes", Formater.dotStringList(classes));
    main.putValue(name + "-Prepare-Classes", Formater.dotStringList(prepareClasses));
    main.putValue(name + "-Used-Methods", Formater.dotStringList(usedMethods));
    main.putValue(name + "-Modified-Classes", Formater.dotStringList(modifiedClasses));
    main.putValue(name + "-Used-Classes", Formater.dotStringList(usedClasses));
    main.putValue(name + "-add-classes", Formater.dotStringList(addClasses));
    return manifest;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:17,代码来源:FastBuild.java

示例12: copyFiles

import java.util.jar.Manifest; //导入依赖的package包/类
/**
 * Copy all the files in a manifest from input to output.  We set
 * the modification times in the output to a fixed time, so as to
 * reduce variation in the output file and make incremental OTAs
 * more efficient.
 */
private void copyFiles(Manifest manifest, Map<String,ZioEntry> input, ZipOutput output, long timestamp)
    throws IOException 
{
    Map<String, Attributes> entries = manifest.getEntries();
    List<String> names = new ArrayList<String>(entries.keySet());
    Collections.sort(names);
    int i = 1;
    for (String name : names) {
        if (canceled) break;
        progressHelper.progress(ProgressEvent.PRORITY_NORMAL, resourceAdapter.getString(ResourceAdapter.Item.COPYING_ZIP_ENTRY, i, names.size()));
        i += 1;
        ZioEntry inEntry = input.get(name);
        inEntry.setTime(timestamp);
        output.write(inEntry);

    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:24,代码来源:ZipSigner.java

示例13: testMissingMainClassPackage

import java.util.jar.Manifest; //导入依赖的package包/类
/**
 * Test that a JAR file with a Main-Class attribute that is not in the module
 */
public void testMissingMainClassPackage() throws IOException {
    Manifest man = new Manifest();
    Attributes attrs = man.getMainAttributes();
    attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
    attrs.put(Attributes.Name.MAIN_CLASS, "p.Main");

    Path dir = Files.createTempDirectory(USER_DIR, "mods");
    createDummyJarFile(dir.resolve("m.jar"), man);

    // Main-Class should be ignored because package p is not in module
    Optional<ModuleReference> omref = ModuleFinder.of(dir).find("m");
    assertTrue(omref.isPresent());
    ModuleDescriptor descriptor = omref.get().descriptor();
    assertFalse(descriptor.mainClass().isPresent());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:AutomaticModulesTest.java

示例14: main

import java.util.jar.Manifest; //导入依赖的package包/类
public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException,
                                      InvocationTargetException, IllegalAccessException {
    URL url = FatJarClassLoaderUtils.getLocatoin(Main.class);
    File fatJarFile = new File(url.getFile());
    JarFile jar = new JarFile(fatJarFile);
    Manifest manifest = jar.getManifest();
    Attributes attributes = manifest.getMainAttributes();
    String startClass = attributes.getValue(START_CLASS_KEY);
    if (startClass == null || startClass.length() == 0) {
        throw new IllegalArgumentException(START_CLASS_KEY + " is missing");
    }
    ClassLoader classLoader = Main.class.getClassLoader();
    FatJarClassLoader fatJarClassLoader = new FatJarClassLoader(jar, url, classLoader.getParent(), classLoader,
                                                                false, true);
    ClassLoader classLoader1 = FatJarClassLoaderUtils.injectFatJarClassLoader(classLoader, fatJarClassLoader);
    Class<?> mainClazz = Class.forName(startClass, true, classLoader1);
    Method invokeMethod = mainClazz.getMethod("main", String[].class);
    invokeMethod.invoke(null, (Object) args);
}
 
开发者ID:hellojavaer,项目名称:fatjar,代码行数:20,代码来源:Main.java

示例15: create

import java.util.jar.Manifest; //导入依赖的package包/类
@Override
public Module create(
    File jar, Object history,
    boolean reloadable, boolean autoload, boolean eager,
    ModuleManager mgr, Events ev
) throws IOException {
    try {
        Module m = super.create(jar, history, reloadable, autoload, eager, mgr, ev);
        registerBundle(m);
        return m;
    } catch (InvalidException ex) {
        Manifest mani = ex.getManifest();
        if (mani != null) {
            String name = mani.getMainAttributes().getValue("AlienName"); // NOI18N
            if (name == null) {
                throw ex;
            }
            return new AlienModule(mani, jar, mgr, ev, history, reloadable, autoload, eager);
        }
        throw ex;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ModuleFactoryAlienTest.java


注:本文中的java.util.jar.Manifest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。