Package java.util.jar

Examples of java.util.jar.Attributes$Name


    JarFile jarFile = null;
    try {
      jarFile = new JarFile(classPathJar);
      Manifest jarManifest = jarFile.getManifest();
      Assert.assertNotNull(jarManifest);
      Attributes mainAttributes = jarManifest.getMainAttributes();
      Assert.assertNotNull(mainAttributes);
      Assert.assertTrue(mainAttributes.containsKey(Attributes.Name.CLASS_PATH));
      String classPathAttr = mainAttributes.getValue(Attributes.Name.CLASS_PATH);
      Assert.assertNotNull(classPathAttr);
      List<String> expectedClassPaths = new ArrayList<String>();
      for (String classPath: classPaths) {
        if (classPath.length() == 0) {
          continue;
View Full Code Here


   
        // Pick some things out of the top-level JAR file.
        String jar = getMyJarPath();
        JarFile jarFile = new JarFile(jar);
        Manifest manifest = jarFile.getManifest();
        Attributes attributes = manifest.getMainAttributes();
        String bootLoaderName = attributes.getValue(ONE_JAR_CLASSLOADER);
        if (mainJar == null) {
            mainJar = attributes.getValue(ONE_JAR_DEFAULT_MAIN_JAR);
        }
       
        String mainargs = attributes.getValue(ONE_JAR_MAIN_ARGS);
        if (mainargs != null && args.length == 0) {
            // Replace the args with built-in.  Support escaped whitespace.
            args = mainargs.split("[^\\\\]\\s");
            for (int i=0; i<args.length; i++) {
                args[i] = args[i].replaceAll("\\\\(\\s)", "$1");
            }
        }
       
    // If no main-class specified, check the manifest of the main jar for
    // a Boot-Class attribute.
    if (mainClass == null) {
            mainClass = attributes.getValue(ONE_JAR_MAIN_CLASS);
            if (mainClass == null) {
                mainClass = attributes.getValue(BOOT_CLASS);
                if (mainClass != null) {
                    LOGGER.warning("The manifest attribute " + BOOT_CLASS + " is deprecated in favor of the attribute " + ONE_JAR_MAIN_CLASS);
                }
            }
    }
       
    if (mainClass == null) {
      // Still don't have one (default).  One final try: look for a jar file in a
      // main directory.  There should be only one, and it's manifest
      // Main-Class attribute is the main class.  The JarClassLoader will take
      // care of finding it.
      InputStream is = Boot.class.getResourceAsStream("/" + mainJar);
      if (is != null) {
        JarInputStream jis = new JarInputStream(is);
        Manifest mainmanifest = jis.getManifest();
                jis.close();
        mainClass = mainmanifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
      } else {
          // There is no main jar. Info unless mainJar is empty string. 
          // The load(mainClass) will scan for main jars anyway.
        if (!"".equals(mainJar)){
                    LOGGER.info("Unable to locate main jar '" + mainJar + "' in the JAR file " + getMyJarPath());
        }
      }
    }
 
    // Do we need to create a wrapping classloader?  Check for the
    // presence of a "wrap" directory at the top of the jar file.
    URL url = Boot.class.getResource(WRAP_JAR);
   
    if (url != null) {
      // Wrap class loaders.
            final JarClassLoader bootLoader = getBootLoader(bootLoaderName);
      bootLoader.load(null);
     
      // Read the "Wrap-Class-Loader" property from the wraploader jar file.
      // This is the class to use as a wrapping class-loader.
            InputStream is = Boot.class.getResourceAsStream(WRAP_JAR);
            if (is != null) {
          JarInputStream jis = new JarInputStream(is);
          final String wrapLoader = jis.getManifest().getMainAttributes().getValue(WRAP_CLASS_LOADER);
                jis.close();
          if (wrapLoader == null) {
            LOGGER.warning(url + " did not contain a " + WRAP_CLASS_LOADER + " attribute, unable to load wrapping classloader");
          } else {
            LOGGER.info("using " + wrapLoader);
                    JarClassLoader wrapped = getWrapLoader(bootLoader, wrapLoader);
                    if (wrapped == null) {
                        LOGGER.warning("Unable to instantiate " + wrapLoader + " from " + WRAP_DIR + ": using default JarClassLoader");
                        wrapped = getBootLoader(null);
                    }
                    setClassLoader(wrapped);
          }
            }
    } else {
            setClassLoader(getBootLoader(bootLoaderName, Boot.class.getClassLoader()));
            LOGGER.info("using JarClassLoader: " + getClassLoader().getClass().getName());
    }
       
    // Allow injection of the URL factory.
    String urlfactory = attributes.getValue(ONE_JAR_URL_FACTORY);
    if (urlfactory != null) {
        loader.setURLFactory(urlfactory);
    }
      
    mainClass = loader.load(mainClass);
View Full Code Here

       
    }
   
    private boolean isSealed(String name, Manifest man) {
    String path = name.concat("/");
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
      sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
      if ((attr = man.getMainAttributes()) != null) {
        sealed = attr.getValue(Name.SEALED);
      }
    }
    return "true".equalsIgnoreCase(sealed);
  }
View Full Code Here

    String specTitle = null, specVersion = null, specVendor = null;
    String implTitle = null, implVersion = null, implVendor = null;
    String sealed = null;
    URL sealBase = null;

    Attributes attr = man.getAttributes(path);
    if (attr != null) {
      specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
      specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
      specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
      implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
      implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
      implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
      sealed = attr.getValue(Name.SEALED);
    }
    attr = man.getMainAttributes();
    if (attr != null) {
      if (specTitle == null) {
        specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
      }
      if (specVersion == null) {
        specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
      }
      if (specVendor == null) {
        specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
      }
      if (implTitle == null) {
        implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
      }
      if (implVersion == null) {
        implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
      }
      if (implVendor == null) {
        implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
      }
      if (sealed == null) {
        sealed = attr.getValue(Name.SEALED);
      }
    }
        if (sealed != null) {
          boolean isSealed = Boolean.parseBoolean(sealed);
          if (isSealed) {
View Full Code Here

        // Copy the template's boot-manifest.mf file
        ZipInputStream zipIS = openOnejarTemplateArchive();
        Manifest manifest = new Manifest(getFileBytes(zipIS, "boot-manifest.mf"));
        IOUtils.closeQuietly(zipIS);

        Attributes mainAttributes = manifest.getMainAttributes();
        // first add the custom specified entries
        addExplicitManifestEntries(mainAttributes);

        // If the client has specified an implementationVersion argument, add it also
        // (It's required and defaulted, so this always executes...)
View Full Code Here

            {
                if ( name.equals( "META-INF/MANIFEST.MF" ) )
                {
                    Manifest manifest = new Manifest( handle.getEntryContent( name ) );

                    Attributes mainAttributes = manifest.getMainAttributes();

                    if ( mainAttributes != null )
                    {
                        String attValue = mainAttributes.getValue( BSN );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleSymbolicName = attValue;
                            updated = true;
                        }
                        else
                        {
                            ai.bundleSymbolicName = null;
                        }

                        attValue = mainAttributes.getValue( BV );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleVersion = attValue;
                            updated = true;
                        }
                        else
                        {
                            ai.bundleVersion = null;
                        }

                        attValue = mainAttributes.getValue( BEP );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleExportPackage = attValue;
                            updated = true;
                        }
                        else
                        {
                            ai.bundleExportPackage = null;
                        }

                        attValue = mainAttributes.getValue( BES );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleExportService = attValue;
                            updated = true;
                        }
                        else
                        {
                            ai.bundleExportService = null;
                        }

                        attValue = mainAttributes.getValue( BD );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleDescription = attValue;
                            updated = true;
                        }
                        else
                        {
                            ai.bundleDescription = null;
                        }

                        attValue = mainAttributes.getValue( BN );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleName = attValue;
                            updated = true;
                        }
                        else
                        {
                            ai.bundleName = null;
                        }

                        attValue = mainAttributes.getValue( BL );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleLicense = attValue;
                            updated = true;
                        }
                        else
                        {
                            ai.bundleLicense = null;
                        }

                        attValue = mainAttributes.getValue( BDU );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleDocUrl = attValue;
                            updated = true;
                        }
                        else
                        {
                            ai.bundleDocUrl = null;
                        }

                        attValue = mainAttributes.getValue( BIP );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleImportPackage = attValue;
                            updated = true;
                        }
                        else
                        {
                            ai.bundleImportPackage = null;
                        }

                        attValue = mainAttributes.getValue( BRB );
                        if ( StringUtils.isNotBlank( attValue ) )
                        {
                            ai.bundleRequireBundle = attValue;
                            updated = true;
                        }
View Full Code Here

     * given manifest.
     */
    protected boolean isPackageSealed(String name, Manifest man) {

        String path = name + "/";
        Attributes attr = man.getAttributes(path);
        String sealed = null;
        if (attr != null) {
            sealed = attr.getValue(Name.SEALED);
        }
        if (sealed == null) {
            if ((attr = man.getMainAttributes()) != null) {
                sealed = attr.getValue(Name.SEALED);
            }
        }
        return "true".equalsIgnoreCase(sealed);

    }
View Full Code Here

            String findContainingJar = JarManager.findContainingJar(ScriptState.class);
            try {
                JarFile jar = new JarFile(findContainingJar);
                final Manifest manifest = jar.getManifest();
                final Map <String,Attributes> attrs = manifest.getEntries();
                Attributes attr = attrs.get("org/apache/pig");
                pigVersion = attr.getValue("Implementation-Version");
            } catch (Exception e) {
                LOG.warn("unable to read pigs manifest file");
            }
        }
        return (pigVersion == null) ? "" : pigVersion;
View Full Code Here

  String findContainingJar = JarManager.findContainingJar(Main.class);
    try {
          JarFile jar = new JarFile(findContainingJar);
          final Manifest manifest = jar.getManifest();
          final Map <String,Attributes> attrs = manifest.getEntries();
          Attributes attr = attrs.get("org/apache/pig");
          String version = attr.getValue("Implementation-Version");
          String svnRevision = attr.getValue("Svn-Revision");
          String buildTime = attr.getValue("Build-TimeStamp");
          // we use a version string similar to svn
          //svn, version 1.4.4 (r25188)
          // compiled Sep 23 2007, 22:32:34
          return "Apache Pig version " + version + " (r" + svnRevision + ") \ncompiled "+buildTime;
      } catch (Exception e) {
View Full Code Here

     * given manifest.
     */
    protected boolean isPackageSealed(String name, Manifest man) {

        String path = name.replace('.', '/') + '/';
        Attributes attr = man.getAttributes(path);
        String sealed = null;
        if (attr != null) {
            sealed = attr.getValue(Name.SEALED);
        }
        if (sealed == null) {
            if ((attr = man.getMainAttributes()) != null) {
                sealed = attr.getValue(Name.SEALED);
            }
        }
        return "true".equalsIgnoreCase(sealed);

    }
View Full Code Here

TOP

Related Classes of java.util.jar.Attributes$Name

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.