Search in sources :

Example 16 with Attributes

use of java.util.jar.Attributes in project android_frameworks_base by ResurrectionRemix.

the class StrictJarManifest method write.

/**
     * Writes out the attribute information of the specified manifest to the
     * specified {@code OutputStream}
     *
     * @param manifest
     *            the manifest to write out.
     * @param out
     *            The {@code OutputStream} to write to.
     * @throws IOException
     *             If an error occurs writing the {@code StrictJarManifest}.
     */
static void write(StrictJarManifest manifest, OutputStream out) throws IOException {
    CharsetEncoder encoder = StandardCharsets.UTF_8.newEncoder();
    ByteBuffer buffer = ByteBuffer.allocate(LINE_LENGTH_LIMIT);
    Attributes.Name versionName = Attributes.Name.MANIFEST_VERSION;
    String version = manifest.mainAttributes.getValue(versionName);
    if (version == null) {
        versionName = Attributes.Name.SIGNATURE_VERSION;
        version = manifest.mainAttributes.getValue(versionName);
    }
    if (version != null) {
        writeEntry(out, versionName, version, encoder, buffer);
        Iterator<?> entries = manifest.mainAttributes.keySet().iterator();
        while (entries.hasNext()) {
            Attributes.Name name = (Attributes.Name) entries.next();
            if (!name.equals(versionName)) {
                writeEntry(out, name, manifest.mainAttributes.getValue(name), encoder, buffer);
            }
        }
    }
    out.write(LINE_SEPARATOR);
    Iterator<String> i = manifest.getEntries().keySet().iterator();
    while (i.hasNext()) {
        String key = i.next();
        writeEntry(out, Attributes.Name.NAME, key, encoder, buffer);
        Attributes attributes = manifest.entries.get(key);
        Iterator<?> entries = attributes.keySet().iterator();
        while (entries.hasNext()) {
            Attributes.Name name = (Attributes.Name) entries.next();
            writeEntry(out, name, attributes.getValue(name), encoder, buffer);
        }
        out.write(LINE_SEPARATOR);
    }
}
Also used : Attributes(java.util.jar.Attributes) CharsetEncoder(java.nio.charset.CharsetEncoder) ByteBuffer(java.nio.ByteBuffer)

Example 17 with Attributes

use of java.util.jar.Attributes in project tdi-studio-se by Talend.

the class JarBuilder method getManifest.

private Manifest getManifest() {
    Manifest manifest = new Manifest();
    Attributes a = new Attributes();
    //$NON-NLS-1$
    a.put(Attributes.Name.IMPLEMENTATION_VERSION, "1.0");
    //$NON-NLS-1$
    a.put(Attributes.Name.IMPLEMENTATION_VENDOR, "Talend Open Studio");
    manifest.getEntries().put(jarFile.getName(), a);
    return manifest;
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest)

Example 18 with Attributes

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

the class XsltDebuggerExtension method isValidXalanPresent.

@Nullable
private static Boolean isValidXalanPresent(SimpleJavaParameters parameters) {
    final List<VirtualFile> files = parameters.getClassPath().getVirtualFiles();
    for (VirtualFile file : files) {
        if (file.getName().matches(".*xalan.*\\.jar")) {
            final VirtualFile root = JarFileSystem.getInstance().getJarRootForLocalFile(file);
            final VirtualFile manifestFile = root != null ? root.findFileByRelativePath("META-INF/MANIFEST.MF") : null;
            if (manifestFile != null) {
                try {
                    Manifest manifest = manifestFile.getUserData(MANIFEST);
                    if (manifest == null) {
                        manifest = new Manifest(manifestFile.getInputStream());
                        manifestFile.putUserData(MANIFEST, manifest);
                    }
                    Attributes attributes = manifest.getAttributes("org/apache/xalan/");
                    if (attributes == null) {
                        attributes = manifest.getAttributes("org/apache/xalan");
                    }
                    if (attributes == null) {
                        LOG.info("No manifest attributes for 'org/apache/xalan/' in " + manifestFile.getPresentableUrl());
                        continue;
                    }
                    final String version = attributes.getValue("Implementation-Version");
                    if (version != null) {
                        final String[] parts = version.split("\\.");
                        if (parts.length >= 2) {
                            if (Integer.parseInt(parts[0]) >= 2 && Integer.parseInt(parts[1]) >= 6) {
                                return true;
                            }
                        }
                        LOG.info("Unsupported Xalan version: " + version);
                    } else {
                        LOG.info("No Xalan version information in " + file.getPath());
                    }
                } catch (IOException e) {
                    LOG.warn("Unable to read manifest from " + file.getName(), e);
                }
            } else {
                LOG.info("No manifest file in " + file.getPath());
            }
            return false;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with Attributes

use of java.util.jar.Attributes in project ProjectRails by Project-Rails.

the class Rails method run.

/**
     * Runs ProjectRails stuff. Called in
     * {@link org.projectrainbow._DiwUtils#Startup()}
     */
public static void run() {
    Attributes a = Rail_Updater.getManifest(Rail_Updater.class).getMainAttributes();
    String hash = a.getValue("GitCommitHash");
    if (hash.endsWith("-dirty"))
        hash = hash.replace("-dirty", "");
    _DiwUtils.version = "git-ProjectRails-" + hash;
    _DiwUtils.upstream_version = String.valueOf(upstream);
    config.saveDefaultConfig();
    ServerWrapper.getInstance().registerCommand(new CmdRails());
}
Also used : Attributes(java.util.jar.Attributes)

Example 20 with Attributes

use of java.util.jar.Attributes in project ACS by ACS-Community.

the class JarSourceExtractorRunner method needsProcessing.

/**
	 * Encapsulates evaluation of possible flags (properties) that may restrict the set of jar files to be processed
	 * for source extraction, for example based on the manifest information.
	 * <p>
	 * Currently only looks at the boolean property <code>jarExtract.onlyGeneratedJars</code>.
	 *  
	 * @param jarFile
	 * @return
	 * @throws IOException
	 */
static boolean needsProcessing(JarFile jarFile) throws IOException {
    // flag to 
    boolean onlyGeneratedJars = Boolean.getBoolean(PROPERTY_EXTRACT_ONLY_GENERATED_JARS);
    boolean needed = !onlyGeneratedJars;
    // only look inside if we are not already sure that this jar file is needed
    if (!needed) {
        Manifest mani = jarFile.getManifest();
        if (mani != null) {
            Map<String, Attributes> entries = mani.getEntries();
            //			System.out.println("\n\nManifest for file " + jarFile.getName());
            Attributes mainAttrs = mani.getMainAttributes();
            for (Iterator mainAttrIter = mainAttrs.keySet().iterator(); mainAttrIter.hasNext(); ) {
                String attr = ((Attributes.Name) mainAttrIter.next()).toString();
                String value = mainAttrs.getValue(attr);
                if (attr.equals(Manifest_Attr_ACSGeneratedFromFile)) {
                    needed = true;
                    break;
                }
            //				System.out.println(attr + "=" + value);
            }
        }
    }
    return needed;
}
Also used : Attributes(java.util.jar.Attributes) Iterator(java.util.Iterator) Manifest(java.util.jar.Manifest)

Aggregations

Attributes (java.util.jar.Attributes)631 Manifest (java.util.jar.Manifest)358 IOException (java.io.IOException)152 File (java.io.File)143 JarFile (java.util.jar.JarFile)106 URL (java.net.URL)92 Map (java.util.Map)78 InputStream (java.io.InputStream)62 HashMap (java.util.HashMap)62 Jar (aQute.bnd.osgi.Jar)49 Builder (aQute.bnd.osgi.Builder)43 ArrayList (java.util.ArrayList)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)42 Test (org.junit.Test)41 ZipEntry (java.util.zip.ZipEntry)39 FileOutputStream (java.io.FileOutputStream)37 JarOutputStream (java.util.jar.JarOutputStream)36 ByteArrayInputStream (java.io.ByteArrayInputStream)33 FileInputStream (java.io.FileInputStream)33 JarEntry (java.util.jar.JarEntry)32