< prev index next >

src/java.base/share/classes/java/util/jar/JarFile.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.jar;
  27 
  28 import java.io.*;
  29 import java.lang.ref.SoftReference;
  30 import java.net.URL;
  31 import java.util.*;
  32 import java.util.stream.Stream;
  33 import java.util.stream.StreamSupport;
  34 import java.util.zip.*;
  35 import java.security.CodeSigner;
  36 import java.security.cert.Certificate;
  37 import java.security.AccessController;
  38 import java.security.CodeSource;
  39 import jdk.internal.misc.SharedSecrets;
  40 import sun.security.action.GetPropertyAction;
  41 import sun.security.util.ManifestEntryVerifier;
  42 import sun.security.util.SignatureFileVerifier;
  43 
  44 /**
  45  * The {@code JarFile} class is used to read the contents of a jar file
  46  * from any file that can be opened with {@code java.io.RandomAccessFile}.
  47  * It extends the class {@code java.util.zip.ZipFile} with support
  48  * for reading an optional {@code Manifest} entry, and support for
  49  * processing multi-release jar files.  The {@code Manifest} can be used
  50  * to specify meta-information about the jar file and its entries.
  51  *
  52  * <p>A multi-release jar file is a jar file that contains
  53  * a manifest with a main attribute named "Multi-Release",
  54  * a set of "base" entries, some of which are public classes with public
  55  * or protected methods that comprise the public interface of the jar file,
  56  * and a set of "versioned" entries contained in subdirectories of the
  57  * "META-INF/versions" directory.  The versioned entries are partitioned by the


 138     private JarEntry manEntry;
 139     private JarVerifier jv;
 140     private boolean jvInitialized;
 141     private boolean verify;
 142     private final int version;
 143     private boolean notVersioned;
 144     private final boolean runtimeVersioned;
 145     private boolean isMultiRelease;    // is jar multi-release?
 146 
 147     // indicates if Class-Path attribute present
 148     private boolean hasClassPathAttribute;
 149     // true if manifest checked for special attributes
 150     private volatile boolean hasCheckedSpecialAttributes;
 151 
 152     static {
 153         // Set up JavaUtilJarAccess in SharedSecrets
 154         SharedSecrets.setJavaUtilJarAccess(new JavaUtilJarAccessImpl());
 155 
 156         BASE_VERSION = 8;  // one less than lowest version for versioned entries
 157         int runtimeVersion = jdk.Version.current().major();
 158         String jarVersion = AccessController.doPrivileged(
 159                 new GetPropertyAction("jdk.util.jar.version"));
 160         if (jarVersion != null) {
 161             int jarVer = Integer.parseInt(jarVersion);
 162             runtimeVersion = (jarVer > runtimeVersion)
 163                     ? runtimeVersion : Math.max(jarVer, 0);
 164         }
 165         RUNTIME_VERSION = runtimeVersion;
 166         String enableMultiRelease = AccessController.doPrivileged(
 167                 new GetPropertyAction("jdk.util.jar.enableMultiRelease", "true"));
 168         switch (enableMultiRelease) {
 169             case "true":
 170             default:
 171                 MULTI_RELEASE_ENABLED = true;
 172                 MULTI_RELEASE_FORCED = false;
 173                 break;
 174             case "false":
 175                 MULTI_RELEASE_ENABLED = false;
 176                 MULTI_RELEASE_FORCED = false;
 177                 break;
 178             case "force":
 179                 MULTI_RELEASE_ENABLED = true;
 180                 MULTI_RELEASE_FORCED = true;
 181                 break;
 182         }
 183     }
 184 
 185     /**
 186      * A set of constants that represent the entries in either the base directory
 187      * or one of the versioned directories in a multi-release jar file.  It's




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.jar;
  27 
  28 import java.io.*;
  29 import java.lang.ref.SoftReference;
  30 import java.net.URL;
  31 import java.util.*;
  32 import java.util.stream.Stream;
  33 import java.util.stream.StreamSupport;
  34 import java.util.zip.*;
  35 import java.security.CodeSigner;
  36 import java.security.cert.Certificate;

  37 import java.security.CodeSource;
  38 import jdk.internal.misc.SharedSecrets;
  39 import sun.security.action.GetPropertyAction;
  40 import sun.security.util.ManifestEntryVerifier;
  41 import sun.security.util.SignatureFileVerifier;
  42 
  43 /**
  44  * The {@code JarFile} class is used to read the contents of a jar file
  45  * from any file that can be opened with {@code java.io.RandomAccessFile}.
  46  * It extends the class {@code java.util.zip.ZipFile} with support
  47  * for reading an optional {@code Manifest} entry, and support for
  48  * processing multi-release jar files.  The {@code Manifest} can be used
  49  * to specify meta-information about the jar file and its entries.
  50  *
  51  * <p>A multi-release jar file is a jar file that contains
  52  * a manifest with a main attribute named "Multi-Release",
  53  * a set of "base" entries, some of which are public classes with public
  54  * or protected methods that comprise the public interface of the jar file,
  55  * and a set of "versioned" entries contained in subdirectories of the
  56  * "META-INF/versions" directory.  The versioned entries are partitioned by the


 137     private JarEntry manEntry;
 138     private JarVerifier jv;
 139     private boolean jvInitialized;
 140     private boolean verify;
 141     private final int version;
 142     private boolean notVersioned;
 143     private final boolean runtimeVersioned;
 144     private boolean isMultiRelease;    // is jar multi-release?
 145 
 146     // indicates if Class-Path attribute present
 147     private boolean hasClassPathAttribute;
 148     // true if manifest checked for special attributes
 149     private volatile boolean hasCheckedSpecialAttributes;
 150 
 151     static {
 152         // Set up JavaUtilJarAccess in SharedSecrets
 153         SharedSecrets.setJavaUtilJarAccess(new JavaUtilJarAccessImpl());
 154 
 155         BASE_VERSION = 8;  // one less than lowest version for versioned entries
 156         int runtimeVersion = jdk.Version.current().major();
 157         String jarVersion =
 158                 GetPropertyAction.getProperty("jdk.util.jar.version");
 159         if (jarVersion != null) {
 160             int jarVer = Integer.parseInt(jarVersion);
 161             runtimeVersion = (jarVer > runtimeVersion)
 162                     ? runtimeVersion : Math.max(jarVer, 0);
 163         }
 164         RUNTIME_VERSION = runtimeVersion;
 165         String enableMultiRelease = GetPropertyAction
 166                 .getProperty("jdk.util.jar.enableMultiRelease", "true");
 167         switch (enableMultiRelease) {
 168             case "true":
 169             default:
 170                 MULTI_RELEASE_ENABLED = true;
 171                 MULTI_RELEASE_FORCED = false;
 172                 break;
 173             case "false":
 174                 MULTI_RELEASE_ENABLED = false;
 175                 MULTI_RELEASE_FORCED = false;
 176                 break;
 177             case "force":
 178                 MULTI_RELEASE_ENABLED = true;
 179                 MULTI_RELEASE_FORCED = true;
 180                 break;
 181         }
 182     }
 183 
 184     /**
 185      * A set of constants that represent the entries in either the base directory
 186      * or one of the versioned directories in a multi-release jar file.  It's


< prev index next >