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.dtolabs.rundeck.ExpandRunServer.java

@SuppressWarnings("static-access")
public ExpandRunServer() {

    Option baseDir = OptionBuilder.withLongOpt("basedir").hasArg().withDescription("The basedir")
            .withArgName("PATH").create('b');

    Option serverDir = OptionBuilder.withLongOpt("serverdir").hasArg()
            .withDescription("The base directory for the server").withArgName("PATH").create();

    Option binDir = OptionBuilder.withLongOpt("bindir").hasArg().withArgName("PATH")
            .withDescription("The install directory for the tools used by users.").create('x');

    Option sbinDir = OptionBuilder.withLongOpt("sbindir").hasArg().withArgName("PATH")
            .withDescription("The install directory for the tools used by administrators.").create('s');

    Option configDir = OptionBuilder.withLongOpt("configdir").hasArg().withArgName("PATH")
            .withDescription("The location of the configuration.").create('c');

    Option dataDir = OptionBuilder.withLongOpt("datadir").hasArg().withArgName("PATH")
            .withDescription("The location of Rundeck's runtime data.").create();

    Option projectDir = OptionBuilder.withLongOpt("projectdir").hasArg().withArgName("PATH")
            .withDescription("The location of Rundeck's project data.").create('p');

    Option help = OptionBuilder.withLongOpt("help").withDescription("Display this message.").create('h');

    Option debugFlag = OptionBuilder.withDescription("Show debug information").create('d');

    Option skipInstall = OptionBuilder.withLongOpt(FLAG_SKIPINSTALL)
            .withDescription("Skip the extraction of the utilities from the launcher.").create();

    Option installonly = OptionBuilder.withLongOpt(FLAG_INSTALLONLY)
            .withDescription("Perform installation only and do not start the server.").create();

    options.addOption(baseDir);/*from w ww  .  j av  a2  s. c  o  m*/
    options.addOption(dataDir);
    options.addOption(serverDir);
    options.addOption(binDir);
    options.addOption(sbinDir);
    options.addOption(configDir);
    options.addOption(help);
    options.addOption(debugFlag);
    options.addOption(skipInstall);
    options.addOption(installonly);
    options.addOption(projectDir);

    debug = Boolean.getBoolean(SYS_PROP_RUNDECK_LAUNCHER_DEBUG);
    rewrite = Boolean.getBoolean(SYS_PROP_RUNDECK_LAUNCHER_REWRITE);
    useJaas = null == System.getProperty(SYS_PROP_RUNDECK_JAASLOGIN)
            || Boolean.getBoolean(SYS_PROP_RUNDECK_JAASLOGIN);
    runClassName = RUN_SERVER_CLASS;
    thisJar = thisJarFile();
    //load jar attributes
    final Attributes mainAttributes = getJarMainAttributes();
    if (null == mainAttributes) {
        throw new RuntimeException("Unable to load attributes");
    }

    versionString = mainAttributes.getValue(RUNDECK_VERSION);
    if (null != versionString) {
        DEBUG("Rundeck version: " + versionString);
    } else {
        throw new RuntimeException("Jar file attribute not found: " + RUNDECK_VERSION);
    }
    runClassName = mainAttributes.getValue(RUNDECK_START_CLASS);
    if (null == runClassName) {
        throw new RuntimeException("Jar file attribute not found: " + RUNDECK_START_CLASS);
    }
    jettyLibsString = mainAttributes.getValue(RUNDECK_JETTY_LIBS);
    if (null == jettyLibsString) {
        throw new RuntimeException("Jar file attribute not found: " + RUNDECK_JETTY_LIBS);
    }
    jettyLibPath = mainAttributes.getValue(RUNDECK_JETTY_LIB_PATH);
    if (null == jettyLibPath) {
        throw new RuntimeException("Jar file attribute not found: " + RUNDECK_JETTY_LIB_PATH);
    }
}

From source file:uk.ac.ebi.embl.api.validation.EnaValidator.java

private String getImplementationVersion(Manifest manifest) {

    Attributes attributes = manifest.getMainAttributes();
    return attributes.getValue("Implementation-Version");
}

From source file:org.rzo.yajsw.app.WrapperManagerImpl.java

/**
 * Load jar.//from w w  w.j a v  a2  s  . c o m
 * 
 * @param jarName
 *            the jar name
 * 
 * @return the method
 */
private Method loadJar(String jarName) {
    URL url = null;
    try {
        url = new File(jarName).toURI().toURL();
    } catch (MalformedURLException e2) {
        e2.printStackTrace();
        return null;
    }
    Manifest manifest;
    try {
        manifest = new JarFile(new File(jarName)).getManifest();
    } catch (IOException e1) {
        e1.printStackTrace();
        return null;
    }
    Attributes attr = manifest.getMainAttributes();

    String cl = attr.getValue("Class-Path");
    ClassLoader loader = null;
    if (cl != null) {
        ArrayList classpath = new ArrayList();
        String[] clArr = cl.split(" ");
        for (int i = 0; i < clArr.length; i++) {
            String file = clArr[i];
            File myFile;
            try {
                myFile = new File(file);
                classpath.add(myFile);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        URL[] urlsArr = new URL[classpath.size()];
        int i = 0;
        for (Iterator it = classpath.iterator(); it.hasNext(); i++)
            try {
                urlsArr[i] = ((File) it.next()).toURI().toURL();
            } catch (Exception e) {
                e.printStackTrace();
            }

        loader = new URLClassLoader(urlsArr, ClassLoader.getSystemClassLoader());
    }
    if (loader == null)
        loader = ClassLoader.getSystemClassLoader();

    String mainClassName = attr.getValue("Main-Class");
    if (mainClassName == null)
        return null;
    Method mainMethod = null;
    try {
        Class cls = loader.loadClass(mainClassName);// cl.loadClass(mainClassName);
        mainMethod = cls.getDeclaredMethod("main", new Class[] { String[].class });
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return mainMethod;
}

From source file:com.aimluck.eip.project.ProjectTaskSimpleSelectData.java

/**
 * ????// w ww  .j av a 2  s  . co  m
 * 
 * @param crt
 * @return
 */
protected SelectQuery<EipTProjectTask> buildSelectQueryForListViewSortOrder(SelectQuery<EipTProjectTask> query,
        RunData rundata, Context context) {
    buildSelectQueryForListViewSort(query, rundata, context);

    String sort = ALEipUtils.getTemp(rundata, context, LIST_SORT_STR);
    String crt_key = null;

    Attributes map = getColumnMap();
    if (sort != null && sort.length() > 0) {
        crt_key = map.getValue(sort);
    }
    if (crt_key == null) {
        if (topView) {
            query.orderAscending(EipTProjectTask.END_PLAN_DATE_PROPERTY);
            query.orderAscending(EipTProjectTask.ORDER_NO_PROPERTY);
        } else {
            query.orderAscending(EipTProjectTask.ORDER_NO_PROPERTY);
        }
    }
    return query;
}

From source file:runtime.starter.MPJRun.java

/**
 * Parses the input .../*w  w  w . j a  v  a 2  s  .  co  m*/
 */
private void processInput(String args[]) {

    if (args.length < 1) {
        printUsage();
        System.exit(0);
    }

    boolean parallelProgramNotYetEncountered = true;

    for (int i = 0; i < args.length; i++) {

        if (args[i].equals("-np")) {

            try {
                nprocs = new Integer(args[i + 1]).intValue();
                if (nprocs < 1) {
                    System.out.println("Number of Processes should be equal to or greater than 1");
                    System.out.println("exiting ...");
                    System.exit(0);
                }
            } catch (NumberFormatException e) {
                nprocs = Runtime.getRuntime().availableProcessors();
            }

            i++;
        }

        else if (args[i].equals("-h")) {
            printUsage();
            System.exit(0);
        }

        else if (args[i].equals("-dport")) {
            D_SER_PORT = new Integer(args[i + 1]).intValue();
            i++;
        }

        else if (args[i].equals("-dev")) {
            deviceName = args[i + 1];
            i++;
            if (!(deviceName.equals("niodev") || deviceName.equals("hybdev") || deviceName.equals("mxdev")
                    || deviceName.equals("multicore"))) {
                System.out.println("MPJ Express currently does not support the <" + deviceName + "> device.");
                System.out.println(
                        "Possible options are niodev, hybdev, mxdev, native, and " + "multicore devices.");
                System.out.println("exiting ...");
                System.exit(0);
            }
        }

        else if (args[i].equals("-machinesfile")) {
            machinesFile = args[i + 1];
            i++;
        }

        else if (args[i].equals("-wdir")) {
            wdir = args[i + 1];
            i++;
        }

        else if (args[i].equals("-psl")) {
            psl = new Integer(args[i + 1]).intValue();
            i++;
        }

        else if (args[i].equals("-mxboardnum")) {
            mxBoardNum = new Integer(args[i + 1]).intValue();
            i++;
        }

        else if (args[i].equals("-cp") | args[i].equals("-classpath")) {
            jvmArgs.add("-cp");
            jvmArgs.add(args[i + 1]);
            i++;
        } else if (args[i].equals("-jar")) {
            File tFile = new File(args[i + 1]);
            String absJarPath = tFile.getAbsolutePath();

            if (tFile.exists()) {
                applicationClassPathEntry = new String(absJarPath);

                try {
                    JarFile jarFile = new JarFile(absJarPath);
                    Attributes attr = jarFile.getManifest().getMainAttributes();
                    className = attr.getValue(Attributes.Name.MAIN_CLASS);
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
                parallelProgramNotYetEncountered = false;
                i++;
            } else {
                throw new MPJRuntimeException("mpjrun cannot find the jar file <" + args[i + 1]
                        + ">. Make sure this is the right path.");
            }

        } else if (args[i].equals("-src")) {
            this.zippedSource = true;
        } else if (args[i].equals("-debug")) {
            DEBUG_PORT = new Integer(args[i + 1]).intValue();
            i++;
            ADEBUG = true;
        } else if (args[i].equals("-profile")) {
            APROFILE = true;
        } else {
            // these are JVM options ..
            if (parallelProgramNotYetEncountered) {
                if (args[i].startsWith("-")) {
                    jvmArgs.add(args[i]);
                } else {
                    // This code takes care of executing class files
                    // directly ....
                    // although does not look like it ....
                    applicationClassPathEntry = System.getProperty("user.dir");
                    className = args[i];
                    parallelProgramNotYetEncountered = false;
                }
            }

            // these have to be app arguments ...
            else {
                appArgs.add(args[i]);
            }

        }

    }

    jArgs = jvmArgs.toArray(new String[0]);
    aArgs = appArgs.toArray(new String[0]);

    if (DEBUG && logger.isDebugEnabled()) {

        logger.debug("###########################");
        logger.debug("-dport: <" + D_SER_PORT + ">");
        logger.debug("-np: <" + nprocs + ">");
        logger.debug("$MPJ_HOME: <" + mpjHomeDir + ">");
        logger.debug("-dir: <" + wdir + ">");
        logger.debug("-dev: <" + deviceName + ">");
        logger.debug("-psl: <" + psl + ">");
        logger.debug("jvmArgs.length: <" + jArgs.length + ">");
        logger.debug("className : <" + className + ">");
        logger.debug("applicationClassPathEntry : <" + applicationClassPathEntry + ">");

        for (int i = 0; i < jArgs.length; i++) {
            if (DEBUG && logger.isDebugEnabled())
                logger.debug(" jvmArgs[" + i + "]: <" + jArgs[i] + ">");
        }
        if (DEBUG && logger.isDebugEnabled())
            logger.debug("appArgs.length: <" + aArgs.length + ">");

        for (int i = 0; i < aArgs.length; i++) {
            if (DEBUG && logger.isDebugEnabled())
                logger.debug(" appArgs[" + i + "]: <" + aArgs[i] + ">");
        }

        if (DEBUG && logger.isDebugEnabled())
            logger.debug("###########################");
    }
}

From source file:org.fusesource.mop.MOP.java

protected void setClassNameFromExecutableJar(List<File> dependencies) throws Exception, UsageException {
    // now lets figure out the className from the manifest
    // lets assume that the first file in the dependency list is usually the one we want to execute
    for (File file : dependencies) {
        JarFile jar = new JarFile(file);
        Manifest manifest = jar.getManifest();
        if (manifest != null) {
            Attributes attributes = manifest.getMainAttributes();
            if (attributes != null) {
                //debug("file " + file + " has main attributes: " + new HashMap(attributes));
                className = attributes.getValue(Attributes.Name.MAIN_CLASS);
                if (className != null && className.length() > 0) {
                    className = className.trim();
                    if (className.length() > 0) {
                        break;
                    }//from w w  w. ja v  a 2 s.c  o  m
                }
            } else {
                LOG.debug("file " + file + " has no manifest main attributes: " + attributes);
            }
        } else {
            LOG.debug("file " + file + " has no manifest");
        }
    }
    if (className == null) {
        throw new Exception("No Main-Class attribute could be found in the dependent jars!");
    }
}

From source file:jdbc.pool.CConnectionPoolManager.java

/**
 * Stores the version number array of the JDBCPool in the variable {@link #VERSION}.
 * //from  w  w w.  j  a va 2s.c  o m
 * String[0] element is the product name.
 * String[1] element is the version number.
 * String[2] element is the date on which the JDBCPool was released.
 * 
 */
private void getVersion() {
    String localFile = getClass().getProtectionDomain().getCodeSource().getLocation().toString();
    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();
        VERSION[0] = (String) attributes.getValue("Bundle-Name");
        VERSION[1] = (String) attributes.getValue("Bundle-Version");
        VERSION[2] = (String) attributes.getValue("Bundled-On");
    } catch (MalformedURLException e) {
        //do nothing
    } catch (IOException e) {
        //do nothing
    }

    //        URL url = getURL();
    //        if (url != null)
    //        {
    //            try {
    //                String file = url.getFile();
    //                if (file.lastIndexOf(".jar") > -1) {
    //                    url = new URL(file.substring(0, file.lastIndexOf(".jar")+4));
    //                } else {
    //                    logger_.warn("Illegal Execution. Execution is not as distributed.");
    //                    return;
    //                }
    //                JarInputStream jis = null;
    //                try {
    //                    jis = new JarInputStream(url.openStream());
    //                    Manifest manifest = jis.getManifest();
    //                    Attributes attributes = manifest.getMainAttributes();
    //                    VERSION[0] = (String) attributes.getValue("Bundle-Name");
    //                    VERSION[1] = (String) attributes.getValue("Bundle-Version");
    //                    VERSION[2] = (String) attributes.getValue("Bundled-On");
    //                } finally {
    //                    if (jis != null) {
    //                        jis.close();
    //                    }
    //                }
    //            } catch (Exception e) {
    //                //Do nothing
    //            }
    //            return;
    //        } else {
    //            logger_.debug("Unable to find the class.");
    //            logger_.warn("Illegal Execution. Execution is not as distributed.");
    //        }
    //        return;
}

From source file:org.jahia.modules.modulemanager.flow.ModuleManagementFlowHandler.java

private void installBundles(File file, MessageContext context, String originalFilename, boolean forceUpdate,
        boolean autoStart) throws IOException, BundleException {

    JarFile jarFile = new JarFile(file);
    try {/* w ww. j  ava2  s. co  m*/

        Attributes manifestAttributes = jarFile.getManifest().getMainAttributes();
        String jahiaRequiredVersion = manifestAttributes.getValue(Constants.ATTR_NAME_JAHIA_REQUIRED_VERSION);
        if (StringUtils.isEmpty(jahiaRequiredVersion)) {
            context.addMessage(new MessageBuilder().source("moduleFile")
                    .code("serverSettings.manageModules.install.required.version.missing.error").error()
                    .build());
            return;
        }
        if (new Version(jahiaRequiredVersion).compareTo(new Version(Jahia.VERSION)) > 0) {
            context.addMessage(new MessageBuilder().source("moduleFile")
                    .code("serverSettings.manageModules.install.required.version.error")
                    .args(jahiaRequiredVersion, Jahia.VERSION).error().build());
            return;
        }

        if (manifestAttributes.getValue(Constants.ATTR_NAME_JAHIA_PACKAGE_NAME) != null) {
            handlePackage(jarFile, manifestAttributes, originalFilename, forceUpdate, autoStart, context);
        } else {
            ModuleInstallationResult installationResult = installModule(file, context, null, null, forceUpdate,
                    autoStart);
            if (installationResult != null) {
                addModuleInstallationMessage(installationResult, context);
            }
        }
    } finally {
        jarFile.close();
    }
}

From source file:io.smartspaces.launcher.bootstrap.SmartSpacesFrameworkBootstrap.java

/**
 * Get the Smart Spaces version from the JAR manifest.
 *
 * @return The smart spaces version/*w  w  w . ja va  2s  . c  om*/
 */
private String getSmartSpacesVersion() {
    // This little lovely line gives us the name of the jar that gave the
    // class
    // we are looking at.
    String classContainer = getClass().getProtectionDomain().getCodeSource().getLocation().toString();

    InputStream in = null;
    try {
        URL manifestUrl = new URL("jar:" + classContainer + "!/META-INF/MANIFEST.MF");
        in = manifestUrl.openStream();
        Manifest manifest = new Manifest(in);
        Attributes attributes = manifest.getMainAttributes();

        return attributes.getValue(MANIFEST_PROPERTY_SMARTSPACES_VERSION);
    } catch (IOException ex) {
        return null;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // Don't care
            }
        }
    }
}