Search in sources :

Example 41 with Manifest

use of java.util.jar.Manifest in project jdk8u_jdk by JetBrains.

the class BigJar method createLargeJar.

void createLargeJar(File jarFile, String comment) throws IOException {
    final int MAX = Short.MAX_VALUE * 2 + 10;
    JarEntry je = null;
    File javaFile = new File("Foo.java");
    File classFile = getClassFile(javaFile);
    Manifest manifest = createMainClass(javaFile);
    try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest);
        FileInputStream fis = new FileInputStream(classFile)) {
        jos.setLevel(JarOutputStream.STORED);
        jos.setMethod(JarOutputStream.STORED);
        for (int i = 0; i < MAX; i++) {
            je = new JarEntry("X" + i + ".txt");
            je.setSize(0);
            je.setCompressedSize(0);
            je.setCrc(0);
            jos.putNextEntry(je);
        }
        // add a class file
        je = new JarEntry(classFile.getName());
        je.setCompressedSize(classFile.length());
        je.setSize(classFile.length());
        je.setCrc(computeCRC(classFile));
        jos.putNextEntry(je);
        copyStream(fis, jos);
        jos.closeEntry();
        if (comment != null) {
            jos.setComment(comment);
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) Manifest(java.util.jar.Manifest) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 42 with Manifest

use of java.util.jar.Manifest in project GNS by MobilityFirst.

the class GNSConfig method readBuildVersion.

/**
   * Attempts to look for a MANIFEST file in that contains the Build-Version
   * attribute.
   *
   * @return a build version
   */
public static String readBuildVersion() {
    String result = null;
    Enumeration<URL> resources = null;
    try {
        resources = GNSConfig.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
    } catch (IOException E) {
    // handle
    }
    if (resources != null) {
        while (resources.hasMoreElements()) {
            try {
                Manifest manifest = new Manifest(resources.nextElement().openStream());
                // check that this is your manifest and do what you need or
                // get the next one
                Attributes attr = manifest.getMainAttributes();
                result = attr.getValue("Build-Version");
            } catch (IOException E) {
            // handle
            }
        }
    }
    return result;
}
Also used : Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) URL(java.net.URL)

Example 43 with Manifest

use of java.util.jar.Manifest in project intellij-community by JetBrains.

the class JarLoader method getAttributes.

@Nullable
private static Map<Resource.Attribute, String> getAttributes(ZipFile zipFile) {
    ZipEntry entry = zipFile.getEntry(JarFile.MANIFEST_NAME);
    if (entry == null)
        return null;
    Map<Resource.Attribute, String> map = null;
    try {
        InputStream stream = zipFile.getInputStream(entry);
        try {
            Attributes attributes = new Manifest(stream).getMainAttributes();
            for (Pair<Resource.Attribute, Attributes.Name> p : PACKAGE_FIELDS) {
                String value = attributes.getValue(p.second);
                if (value != null) {
                    if (map == null)
                        map = new EnumMap<Resource.Attribute, String>(Resource.Attribute.class);
                    map.put(p.first, value);
                }
            }
        } finally {
            stream.close();
        }
    } catch (Exception ignored) {
    }
    return map;
}
Also used : InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with Manifest

use of java.util.jar.Manifest in project wildfly by wildfly.

the class WebApplicationBundleUtils method isWebApplicationBundle.

public static boolean isWebApplicationBundle(DeploymentUnit depUnit) {
    // JAR deployments may contain OSGi metadata with a "Web-ContextPath" header
    // This qualifies them as OSGi Web Application Bundle (WAB)
    String deploymentName = depUnit.getName().toLowerCase(Locale.ENGLISH);
    Manifest manifest = depUnit.getAttachment(Attachments.OSGI_MANIFEST);
    if (manifest != null && deploymentName.endsWith(".jar")) {
        if (ManifestHelper.hasMainAttributeValue(manifest, "Web-ContextPath")) {
            return true;
        }
    }
    // transformed into an OSGi Web Application Bundle (WAB)
    if (deploymentName.startsWith("webbundle:")) {
        return true;
    }
    return false;
}
Also used : Manifest(java.util.jar.Manifest)

Example 45 with Manifest

use of java.util.jar.Manifest in project intellij-community by JetBrains.

the class PrepareToDeployAction method createOrFindManifest.

public static Manifest createOrFindManifest(final PluginBuildConfiguration pluginModuleBuildProperties) throws IOException {
    final Manifest manifest = new Manifest();
    final VirtualFile vManifest = pluginModuleBuildProperties.getManifest();
    if (pluginModuleBuildProperties.isUseUserManifest() && vManifest != null) {
        InputStream in = null;
        try {
            in = new BufferedInputStream(vManifest.getInputStream());
            manifest.read(in);
        } finally {
            if (in != null)
                in.close();
        }
    } else {
        Attributes mainAttributes = manifest.getMainAttributes();
        ManifestBuilder.setGlobalAttributes(mainAttributes);
    }
    return manifest;
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest)

Aggregations

Manifest (java.util.jar.Manifest)1226 Attributes (java.util.jar.Attributes)392 File (java.io.File)391 IOException (java.io.IOException)336 JarFile (java.util.jar.JarFile)231 InputStream (java.io.InputStream)184 URL (java.net.URL)177 JarOutputStream (java.util.jar.JarOutputStream)145 FileOutputStream (java.io.FileOutputStream)131 Test (org.junit.Test)129 FileInputStream (java.io.FileInputStream)119 Jar (aQute.bnd.osgi.Jar)105 JarInputStream (java.util.jar.JarInputStream)104 Builder (aQute.bnd.osgi.Builder)99 ZipEntry (java.util.zip.ZipEntry)99 ByteArrayOutputStream (java.io.ByteArrayOutputStream)96 JarEntry (java.util.jar.JarEntry)96 ByteArrayInputStream (java.io.ByteArrayInputStream)93 ArrayList (java.util.ArrayList)83 Map (java.util.Map)83