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:com.trsst.Common.java

public static String getBuildId() {
    Attributes attributes = getManifestAttributes();
    if (attributes != null) {
        return attributes.getValue("Implementation-Build");
    } else {/*ww w .j  a  v a 2  s .c  o  m*/
        log.warn("Could not find manifest attributes.");
    }
    return null;
}

From source file:com.trsst.Common.java

public static Date getBuildDate() {
    Date result = null;/*from   ww  w . j av  a 2 s.c o  m*/
    Attributes attributes = getManifestAttributes();
    if (attributes != null) {
        String dateString = attributes.getValue("Built-On");
        try {
            result = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
        } catch (Throwable t) {
            log.warn("Could not parse build timestamp: " + dateString);
        }
    } else {
        log.warn("Could not find manifest attributes.");
    }
    return result;
}

From source file:com.trsst.Common.java

public static String getBuildString() {
    String result = null;//from   w w  w.  j  a va 2s . c  o m
    String[] keys = new String[] { "Implementation-Title", "Implementation-Version", "Implementation-Build",
            "Built-On", };
    Attributes attributes = getManifestAttributes();
    if (attributes != null) {
        Object value;
        for (String key : keys) {
            value = attributes.getValue(key);
            if (value != null) {
                if (result == null) {
                    result = value.toString();
                } else {
                    result = result + ' ' + value.toString();
                }
            }
        }
    } else {
        result = "trsst client";
    }
    return result;
}

From source file:JarClassLoader.java

public String getMainClassName() throws IOException {
    URL u = new URL("jar", "", url + "!/");
    JarURLConnection uc = (JarURLConnection) u.openConnection();
    Attributes attr = uc.getMainAttributes();
    return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
}

From source file:strat.mining.stratum.proxy.configuration.ConfigurationManager.java

/**
 * Return the version of the program/*from w  w w .  java  2  s.  co m*/
 * 
 * @return
 */
public static String getVersion() {
    if (version == null) {
        version = "Dev";

        Class<Launcher> clazz = Launcher.class;
        String className = clazz.getSimpleName() + ".class";
        String classPath = clazz.getResource(className).toString();
        if (classPath.startsWith("jar")) {
            // Class not from JAR
            String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1)
                    + "/META-INF/MANIFEST.MF";

            try {
                Manifest manifest = new Manifest(new URL(manifestPath).openStream());
                Attributes attr = manifest.getMainAttributes();
                version = attr.getValue("Implementation-Version");
            } catch (IOException e) {
                // Do nothing, just return Unknown as version
                version = "Unknown";
            }
        }
    }

    return version;
}

From source file:cascading.flow.hadoop.util.HadoopUtil.java

private static PlatformInfo getPlatformInfoInternal() {
    URL url = JobConf.class.getResource(JobConf.class.getSimpleName() + ".class");

    if (url == null || !url.toString().startsWith("jar"))
        return new PlatformInfo("Hadoop", null, null);

    String path = url.toString();
    String manifestPath = path.substring(0, path.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";

    Manifest manifest;//from   w w  w  .ja va2  s.  c  o m

    try {
        manifest = new Manifest(new URL(manifestPath).openStream());
    } catch (IOException exception) {
        LOG.warn("unable to get manifest from {}", manifestPath, exception);

        return new PlatformInfo("Hadoop", null, null);
    }

    Attributes attributes = manifest.getAttributes("org/apache/hadoop");

    if (attributes == null) {
        LOG.debug("unable to get Hadoop manifest attributes");
        return new PlatformInfo("Hadoop", null, null);
    }

    String vendor = attributes.getValue("Implementation-Vendor");
    String version = attributes.getValue("Implementation-Version");

    return new PlatformInfo("Hadoop", vendor, version);
}

From source file:org.parosproxy.paros.Constant.java

private static String getVersionFromManifest() {
    Manifest manifest = getManifest();
    if (manifest != null) {
        Attributes attr = manifest.getMainAttributes();
        return attr.getValue("Implementation-Version");
    } else {/*from w ww  . j a v  a  2s . c  o  m*/
        return DEV_VERSION;
    }
}

From source file:org.parosproxy.paros.Constant.java

public static Date getReleaseCreateDate() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Manifest manifest = getManifest();
    if (manifest != null) {
        Attributes attr = manifest.getMainAttributes();
        try {//from   w w  w.  ja  v  a2  s  . c om
            return sdf.parse(attr.getValue("Create-Date"));
        } catch (ParseException e) {
            // Ignore - treat as undated
        }
    }
    return null;
}

From source file:de.u808.simpleinquest.web.tags.VersionInfoTag.java

@Override
public void doTag() throws JspException, IOException {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    try {//  w  ww  .ja v  a2  s.co m
        String appServerHome = pageContext.getServletContext().getRealPath("/");

        File manifestFile = new File(appServerHome, "META-INF/MANIFEST.MF");

        Manifest mf = new Manifest();
        mf.read(new FileInputStream(manifestFile));

        Attributes atts = mf.getMainAttributes();

        out.println("<span id=\"version\"> (Revision " + atts.getValue("Implementation-Version") + " Build "
                + atts.getValue("Implementation-Build") + " Built-By " + atts.getValue("Built-By")
                + ")</span>");
    } catch (Exception e) {
        log.error("Tag error", e);
    }
}

From source file:fm.last.citrine.web.AdminController.java

@Override
protected void initServletContext(ServletContext servletContext) {
    super.initServletContext(servletContext);
    try {//from  w w  w. ja  v a2  s. c o  m
        InputStream inputStream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF");
        Manifest manifest = new Manifest(inputStream);
        Attributes attributes = manifest.getMainAttributes();
        buildVersion = attributes.getValue("Build-Version");
        buildDateTime = attributes.getValue("Build-DateTime");
        log.info("Citrine Build-Version: " + attributes.getValue("Build-Version"));
        log.info("Citrine Build-DateTime: " + attributes.getValue("Build-DateTime"));
    } catch (Exception e) {
        log.error("Error determining build version", e);
    }
}