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:net.fabricmc.installer.installer.LocalVersionInstaller.java

public static void install(File mcDir, IInstallerProgress progress) throws Exception {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle(Translator.getString("install.client.selectCustomJar"));
    fc.setFileFilter(new FileNameExtensionFilter("Jar Files", "jar"));
    if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        File inputFile = fc.getSelectedFile();

        JarFile jarFile = new JarFile(inputFile);
        Attributes attributes = jarFile.getManifest().getMainAttributes();
        String mcVersion = attributes.getValue("MinecraftVersion");
        Optional<String> stringOptional = ClientInstaller.isValidInstallLocation(mcDir, mcVersion);
        jarFile.close();/*from w w  w  . j  a  v a  2 s  . co  m*/
        if (stringOptional.isPresent()) {
            throw new Exception(stringOptional.get());
        }
        ClientInstaller.install(mcDir, mcVersion, progress, inputFile);
    } else {
        throw new Exception("Failed to find jar");
    }

}

From source file:ru.codeinside.gses.webui.utils.JarParseUtils.java

public static boolean isOsgiComponent(JarInputStream jarStream) {
    Attributes mainAttributes = jarStream.getManifest().getMainAttributes();
    String serviceComponent = mainAttributes.getValue("Service-Component");
    String exportPackage = mainAttributes.getValue("Export-Package");
    String importPackage = mainAttributes.getValue("Import-Package");

    return StringUtils.isNotEmpty(serviceComponent) && StringUtils.isNotEmpty(exportPackage)
            && StringUtils.isNotEmpty(importPackage);
}

From source file:com.thoughtworks.go.agent.common.util.JarUtil.java

private static String getManifestKey(JarFile jarFile, String key) {
    try {/*www.j a v a 2  s  .c o m*/
        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;
}

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

public static void installServer(File mcDir, IInstallerProgress progress) throws Exception {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle(Translator.getString("install.client.selectCustomJar"));
    fc.setFileFilter(new FileNameExtensionFilter("Jar Files", "jar"));
    if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        File inputFile = fc.getSelectedFile();

        JarFile jarFile = new JarFile(inputFile);
        Attributes attributes = jarFile.getManifest().getMainAttributes();
        String fabricVersion = attributes.getValue("FabricVersion");
        jarFile.close();//www  . j  a  v a  2 s  . c  o m
        File fabricJar = new File(mcDir, "fabric-" + fabricVersion + ".jar");
        if (fabricJar.exists()) {
            fabricJar.delete();
        }
        FileUtils.copyFile(inputFile, fabricJar);
        ServerInstaller.install(mcDir, fabricVersion, progress, fabricJar);
    } else {
        throw new Exception("Failed to find jar");
    }

}

From source file:org.jcurl.core.helpers.Version.java

public static final Version find(final ClassLoader clz) {
    try {/*  w  w w. ja  v  a  2 s .  c  o m*/
        final Manifest mf = findManifest(clz, "jcurl-");
        final Attributes main = mf.getMainAttributes();
        return create(main.getValue("Bundle-Version"), main.getValue("Built-Time"));
    } catch (final Exception e) {
        return null;
    }
}

From source file:com.ikon.util.WarUtils.java

/**
 * /*from  w  w  w.j  a v  a  2s .  com*/
 */
public static synchronized void readAppVersion(ServletContext sc) {
    String appServerHome = sc.getRealPath("/");
    File manifestFile = new File(appServerHome, "META-INF/MANIFEST.MF");
    FileInputStream fis = null;

    try {
        fis = new FileInputStream(manifestFile);
        Manifest mf = new Manifest();
        mf.read(fis);
        Attributes atts = mf.getMainAttributes();
        String impVersion = atts.getValue("Implementation-Version");
        String impBuild = atts.getValue("Implementation-Build");
        log.info("Implementation-Version: " + impVersion);
        log.info("Implementation-Build: " + impBuild);

        if (impVersion != null) {
            String[] version = impVersion.split("\\.");

            if (version.length > 0 && version[0] != null) {
                appVersion.setMajor(version[0]);
            }

            if (version.length > 1 && version[1] != null) {
                appVersion.setMinor(version[1]);
            }

            if (version.length > 2 && version[2] != null && !version[2].equals("")) {
                appVersion.setMaintenance(version[2]);
            }
        }

        if (impBuild != null) {
            appVersion.setBuild(impBuild);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(fis);
    }
}

From source file:tk.tomby.tedit.plugins.PluginDriver.java

private static JarEntry getDescriptor(JarFile jar) throws IOException {
    JarEntry entry = null;/*from  w  ww.  java  2s .  c  o m*/

    Manifest manifest = jar.getManifest();
    Attributes attrs = manifest.getMainAttributes();
    String pluginAttr = attrs.getValue("Plugin-Descriptor");

    if (pluginAttr != null) {
        entry = jar.getJarEntry(pluginAttr);
    } else {
        entry = jar.getJarEntry("META-INF/plugin.xml");
    }

    return entry;
}

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

public static void install(File mcDir, String version, IInstallerProgress progress) throws IOException {
    String[] split = version.split("-");
    if (isValidInstallLocation(mcDir, split[0]).isPresent()) {
        throw new RuntimeException(isValidInstallLocation(mcDir, split[0]).get());
    }//  w  ww  .j a  va2s  . co  m
    File fabricData = new File(mcDir, "fabricData");
    File fabricJar = new File(fabricData, version + ".jar");
    if (!fabricJar.exists()) {
        progress.updateProgress(Translator.getString("install.client.downloadFabric"), 10);
        FileUtils.copyURLToFile(new URL(MavenHandler.getPath(Reference.MAVEN_SERVER_URL,
                Reference.PACKAGE_FABRIC, Reference.NAME_FABRIC_LOADER, version)), fabricJar);
    }
    JarFile jarFile = new JarFile(fabricJar);
    Attributes attributes = jarFile.getManifest().getMainAttributes();
    String mcVersion = attributes.getValue("MinecraftVersion");
    install(mcDir, mcVersion, progress, fabricJar);
    FileUtils.deleteDirectory(fabricData);
}

From source file:org.jahia.services.modulemanager.persistence.PersistentBundleInfoBuilder.java

/**
 * Parses the supplied resource and builds the information for the bundle.
 *
 * @param resource The bundle resource//  w w  w .  ja v a2  s . c om
 * @param calculateChecksum should we calculate the resource checksum?
 * @param checkTransformationRequired should we check if the module dependency capability headers has to be added
 * @return The information about the supplied bundle
 * @throws IOException In case of resource read errors
 */
public static PersistentBundle build(Resource resource, boolean calculateChecksum,
        boolean checkTransformationRequired) throws IOException {

    // populate data from manifest
    String groupId = null;
    String symbolicName = null;
    String version = null;
    String displayName = null;
    try (JarInputStream jarIs = new JarInputStream(resource.getInputStream())) {
        Manifest mf = jarIs.getManifest();
        if (mf != null) {
            Attributes attrs = mf.getMainAttributes();
            groupId = attrs.getValue(ATTR_NAME_GROUP_ID);
            symbolicName = attrs.getValue(ATTR_NAME_BUNDLE_SYMBOLIC_NAME);
            version = StringUtils.defaultIfBlank(attrs.getValue(ATTR_NAME_BUNDLE_VERSION),
                    attrs.getValue(ATTR_NAME_IMPL_VERSION));
            displayName = StringUtils.defaultIfBlank(attrs.getValue(ATTR_NAME_IMPL_TITLE),
                    attrs.getValue(ATTR_NAME_BUNDLE_NAME));
        }
    }

    if (StringUtils.isBlank(symbolicName) || StringUtils.isBlank(version)) {
        // not a valid JAR or bundle information is missing -> we stop here
        logger.warn("Not a valid JAR or bundle information is missing for resource " + resource);
        return null;
    }

    PersistentBundle bundleInfo = new PersistentBundle(groupId, symbolicName, version);
    bundleInfo.setDisplayName(displayName);
    if (calculateChecksum) {
        bundleInfo.setChecksum(calculateDigest(resource));
    }
    if (checkTransformationRequired) {
        bundleInfo.setTransformationRequired(isTransformationRequired(resource));
    }
    bundleInfo.setResource(resource);
    return bundleInfo;
}

From source file:com.ericsson.eiffel.remrem.generate.EiffelRemremControllerIntegrationTest.java

public static String getMessagingVersion() {
    Enumeration resEnum;//from  www.  j a va2 s.  c o  m
    try {
        resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
        while (resEnum.hasMoreElements()) {
            try {
                URL url = (URL) resEnum.nextElement();
                if (url.getPath().contains("eiffel-remrem-semantics")) {
                    InputStream is = url.openStream();
                    if (is != null) {
                        Manifest manifest = new Manifest(is);
                        Attributes mainAttribs = manifest.getMainAttributes();
                        String version = mainAttribs.getValue("semanticsVersion");
                        if (version != null) {
                            return version;
                        }
                    }
                }
            } catch (Exception e) {
                // Silently ignore wrong manifests on classpath?
            }
        }
    } catch (IOException e1) {
        // Silently ignore wrong manifests on classpath?
    }
    return null;
}