Example usage for java.util.jar Attributes getValue

List of usage examples for java.util.jar Attributes getValue

Introduction

In this page you can find the example usage for java.util.jar Attributes getValue.

Prototype

public String getValue(Name name) 

Source Link

Document

Returns the value of the specified Attributes.Name, or null if the attribute was not found.

Usage

From source file:org.talend.commons.utils.resource.BundleFileUtil.java

public static String getBundleVersion(Manifest manifest) {
    if (manifest == null) {
        return null;
    }/*from  w ww . j a  v a 2  s .  c o m*/
    Attributes mainAttributes = manifest.getMainAttributes();
    if (mainAttributes == null) {
        return null;
    }
    return mainAttributes.getValue("Bundle-Version"); //$NON-NLS-1$
}

From source file:org.sonar.updatecenter.deprecated.Plugin.java

public static Plugin extractMetadata(File file) throws IOException {
    JarFile jar = new JarFile(file);
    ZipEntry entry = jar.getEntry("META-INF/MANIFEST.MF");
    long timestamp = entry.getTime();
    Manifest manifest = jar.getManifest();
    jar.close();/*from  w w  w.  j  a v  a 2s.  c o  m*/

    Attributes attributes = manifest.getMainAttributes();
    String pluginKey = attributes.getValue("Plugin-Key");
    Plugin plugin = new Plugin(pluginKey);
    plugin.setName(attributes.getValue("Plugin-Name"));
    plugin.setVersion(attributes.getValue("Plugin-Version"));
    plugin.setRequiredSonarVersion(attributes.getValue("Sonar-Version"));
    plugin.setHomepage(attributes.getValue("Plugin-Homepage"));
    plugin.setDate(timestamp);
    return plugin;
}

From source file:org.talend.commons.utils.resource.BundleFileUtil.java

public static String getBundleSymbolicName(Manifest manifest) {
    if (manifest == null) {
        return null;
    }/*ww  w.j  a va 2s.  c o m*/
    Attributes mainAttributes = manifest.getMainAttributes();
    if (mainAttributes == null) {
        return null;
    }
    String name = mainAttributes.getValue("Bundle-SymbolicName"); //$NON-NLS-1$
    if (name == null) {
        return null;
    }
    final int indexOf = name.indexOf(';');
    if (indexOf > 0)
        name = name.substring(0, indexOf);
    return name;
}

From source file:info.dolezel.fatrat.plugins.helpers.JarClassLoader.java

private static void getPackageVersion(File fo, Map<String, String> rv) throws IOException {
    if (!fo.exists())
        return;/*from  w w  w  . j a  v  a 2  s.  co m*/

    JarFile file = new JarFile(fo);
    Manifest manifest = file.getManifest();
    Attributes attr = manifest.getMainAttributes();

    rv.put(fo.getName(), attr.getValue("Implementation-Version"));
}

From source file:org.nuxeo.osgi.BundleManifestReader.java

public static Dictionary<String, String> getHeaders(Manifest mf) throws BundleException {
    Attributes attrs = mf.getMainAttributes();
    String symbolicName = attrs.getValue(Constants.BUNDLE_SYMBOLICNAME);
    if (symbolicName == null) {
        throw new BundleException("Missing " + Constants.BUNDLE_SYMBOLICNAME);
    }/* ww  w . java  2  s .com*/
    Hashtable<String, String> headers = new Hashtable<String, String>();
    parseSymbolicName(headers, symbolicName);
    String val = attrs.getValue(Constants.BUNDLE_ACTIVATOR);
    if (val != null) {
        headers.put(Constants.BUNDLE_ACTIVATOR, val.trim());
    }
    val = attrs.getValue(Constants.BUNDLE_CLASSPATH);
    if (val != null) {
        headers.put(Constants.BUNDLE_CLASSPATH, val.trim());
    }
    val = attrs.getValue(Constants.BUNDLE_NAME);
    if (val != null) {
        headers.put(Constants.BUNDLE_NAME, val);
    }
    val = attrs.getValue(Constants.BUNDLE_VENDOR);
    if (val != null) {
        headers.put(Constants.BUNDLE_VENDOR, val);
    }
    val = attrs.getValue(Constants.BUNDLE_VERSION);
    if (val != null) {
        headers.put(Constants.BUNDLE_VERSION, val);
    }
    val = attrs.getValue(Constants.BUNDLE_DESCRIPTION);
    if (val != null) {
        headers.put(Constants.BUNDLE_DESCRIPTION, val);
    }
    val = attrs.getValue(Constants.BUNDLE_DOCURL);
    if (val != null) {
        headers.put(Constants.BUNDLE_DOCURL, val);
    }
    val = attrs.getValue(Constants.BUNDLE_COPYRIGHT);
    if (val != null) {
        headers.put(Constants.BUNDLE_COPYRIGHT, val);
    }
    val = attrs.getValue(Constants.BUNDLE_LOCALIZATION);
    if (val != null) {
        headers.put(Constants.BUNDLE_LOCALIZATION, val);
    }
    val = attrs.getValue(Constants.REQUIRE_BUNDLE);
    if (val != null) {
        headers.put(Constants.REQUIRE_BUNDLE, val);
    }
    val = attrs.getValue(Constants.FRAGMENT_HOST);
    if (val != null) {
        headers.put(Constants.FRAGMENT_HOST, val);
    }
    // Nuxeo headers
    for (String key : CUSTOM_HEADERS) {
        val = attrs.getValue(key);
        if (val != null) {
            headers.put(key, val);
        }
    }
    return headers;
}

From source file:org.talend.commons.utils.resource.BundleFileUtil.java

public static String[] getBundleClassPath(Manifest manifest) {
    if (manifest == null) {
        return new String[0];
    }/* ww w .  j av a 2s  . co  m*/
    Attributes mainAttributes = manifest.getMainAttributes();
    if (mainAttributes == null) {
        return new String[0];
    }

    String value = mainAttributes.getValue("Bundle-ClassPath"); //$NON-NLS-1$
    if (value == null) {
        return new String[0];
    }

    List<String> bundleCPs = new ArrayList<String>();
    final String[] entries = value.split(","); //$NON-NLS-1$
    for (String entry : entries) {
        bundleCPs.add(entry);
    }
    return bundleCPs.toArray(new String[0]);
}

From source file:com.stgmastek.core.comm.main.StartCoreCommunication.java

static void getBundleDetails() {
    strBundleDetailsArray_ = new String[] { "Unknown", "Unknown", "Unknown", Integer.MIN_VALUE + "",
            Integer.MIN_VALUE + "", Integer.MIN_VALUE + "" };
    String localFile = StartCoreCommunication.class.getProtectionDomain().getCodeSource().getLocation()
            .toString();//ww  w . j  a va  2s.  c o m
    localFile = localFile.concat("!/");
    String tmpString = "jar:";
    String localJarFileString = tmpString.concat(localFile);
    URL localJarFileURL;
    try {
        localJarFileURL = new URL(localJarFileString);
        JarURLConnection localJarFile = (JarURLConnection) localJarFileURL.openConnection();
        Manifest mf = localJarFile.getManifest();
        Attributes attributes = mf.getMainAttributes();
        strBundleDetailsArray_[0] = (String) attributes.getValue("Bundle-Name");
        strBundleDetailsArray_[1] = (String) attributes.getValue("Bundle-Version");
        strBundleDetailsArray_[2] = (String) attributes.getValue("Bundled-On");
        strBundleDetailsArray_[3] = (String) attributes.getValue("Major-Version");
        strBundleDetailsArray_[4] = (String) attributes.getValue("Minor-Version");
        strBundleDetailsArray_[5] = (String) attributes.getValue("Build-Number");
    } catch (MalformedURLException e) {
        // do nothing
    } catch (FileNotFoundException fnfe) {
        // do nothing
    } catch (IOException ioe) {
        // do nothing
    }
}

From source file:com.arcusys.liferay.vaadinplugin.util.WidgetsetUtil.java

private static void includeVaadinAddonJar(File file, List<VaadinAddonInfo> addons) {
    try {/*  w w  w.  j  a  v a  2 s.  c om*/
        URL url = new URL("file:" + file.getCanonicalPath());
        url = new URL("jar:" + url.toExternalForm() + "!/");
        JarURLConnection conn = (JarURLConnection) url.openConnection();
        JarFile jarFile = conn.getJarFile();
        if (jarFile != null) {
            Manifest manifest = jarFile.getManifest();
            if (manifest == null) {
                // No manifest so this is not a Vaadin Add-on
                return;
            }

            Attributes attrs = manifest.getMainAttributes();
            String value = attrs.getValue("Vaadin-Widgetsets");
            if (value != null) {
                String name = attrs.getValue("Implementation-Title");
                String version = attrs.getValue("Implementation-Version");
                if (name == null || version == null) {
                    // A jar file with Vaadin-Widgetsets but name or version
                    // missing. Most probably vaadin.jar itself, skipping it
                    // here
                    return;
                }

                List<String> widgetsets = new ArrayList<String>();
                String[] widgetsetNames = value.split(",");
                for (String wName : widgetsetNames) {
                    String widgetsetname = wName.trim().intern();
                    if (!widgetsetname.equals("")) {
                        widgetsets.add(widgetsetname);
                    }
                }

                if (!widgetsets.isEmpty()) {
                    addons.add(new VaadinAddonInfo(name, version, file, widgetsets));
                }
            }
        }
    } catch (Exception e) {
        log.warn("Exception trying to include Vaadin Add-ons.", e);
    }

}

From source file:com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.java

private static void assertMainClass(final String jarFile, final String mainClass) throws Exception {
    JarInputStream jarStream = null;
    try {//  w w w. j  a  v a2s  .  c  o  m
        jarStream = new JarInputStream(new FileInputStream(jarFile));
        final Manifest manifest = jarStream.getManifest();
        final Attributes attrs = manifest.getMainAttributes();
        assertEquals("Maven plugin must also provide and main class in manifest", mainClass,
                attrs.getValue("Main-Class"));
    } finally {
        IOUtils.closeQuietly(jarStream);
    }
}

From source file:net.fabricmc.installer.installer.ClientInstaller.java

public static void install(File mcDir, String version, IInstallerProgress progress, File fabricJar)
        throws IOException {
    progress.updateProgress(Translator.getString("gui.installing") + ": " + version, 0);
    JarFile jarFile = new JarFile(fabricJar);
    Attributes attributes = jarFile.getManifest().getMainAttributes();

    String id = "fabric-" + attributes.getValue("FabricVersion");

    System.out.println(Translator.getString("gui.installing") + " " + id);
    File versionsFolder = new File(mcDir, "versions");
    File fabricVersionFolder = new File(versionsFolder, id);
    File mcVersionFolder = new File(versionsFolder, version);
    File fabricJsonFile = new File(fabricVersionFolder, id + ".json");

    File tempWorkDir = new File(fabricVersionFolder, "temp");
    ZipUtil.unpack(fabricJar, tempWorkDir, name -> {
        if (name.startsWith(Reference.INSTALLER_METADATA_FILENAME)) {
            return name;
        } else {/* w  w  w  .ja  v  a2 s .c  o m*/
            return null;
        }
    });
    InstallerMetadata metadata = new InstallerMetadata(tempWorkDir);

    File mcJarFile = new File(mcVersionFolder, version + ".jar");
    if (fabricVersionFolder.exists()) {
        progress.updateProgress(Translator.getString("install.client.removeOld"), 10);
        FileUtils.deleteDirectory(fabricVersionFolder);
    }
    fabricVersionFolder.mkdirs();

    progress.updateProgress(Translator.getString("install.client.createJson"), 20);

    String mcJson = FileUtils.readFileToString(mcJarFile, Charset.defaultCharset());

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonObject versionJson = new JsonObject();
    versionJson.addProperty("id", id);
    versionJson.addProperty("type", "release");
    versionJson.addProperty("time", Utils.ISO_8601.format(fabricJar.lastModified()));
    versionJson.addProperty("releaseTime", Utils.ISO_8601.format(fabricJar.lastModified()));
    versionJson.addProperty("mainClass", metadata.getMainClass());
    versionJson.addProperty("inheritsFrom", version);

    JsonArray gameArgs = new JsonArray();
    JsonObject arguments = new JsonObject();

    List<String> metadataTweakers = metadata.getTweakers("client", "common");
    if (metadataTweakers.size() > 1) {
        throw new RuntimeException("Not supporting > 1 tweaker yet!");
    }

    metadata.getArguments("client", "common").forEach(gameArgs::add);
    gameArgs.add("--tweakClass");
    gameArgs.add(metadataTweakers.get(0));

    arguments.add("game", gameArgs);
    versionJson.add("arguments", arguments);

    JsonArray libraries = new JsonArray();

    addDep(Reference.PACKAGE_FABRIC + ":" + Reference.NAME_FABRIC_LOADER + ":"
            + attributes.getValue("FabricVersion"), "http://maven.modmuss50.me/", libraries);

    for (InstallerMetadata.LibraryEntry entry : metadata.getLibraries("client", "common")) {
        libraries.add(entry.toVanillaEntry());
    }

    versionJson.add("libraries", libraries);

    FileUtils.write(fabricJsonFile, gson.toJson(versionJson), "UTF-8");
    jarFile.close();
    progress.updateProgress(Translator.getString("install.client.cleanDir"), 90);
    FileUtils.deleteDirectory(tempWorkDir);

    progress.updateProgress(Translator.getString("install.success"), 100);
}