< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  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


 136     private SoftReference<Manifest> manRef;
 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.privilegedGetProperty("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                 .privilegedGetProperty("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;


 340      * @throws NullPointerException if {@code version} is {@code null}
 341      * @since 9
 342      */
 343     public JarFile(File file, boolean verify, int mode, Release version) throws IOException {
 344         super(file, mode);
 345         Objects.requireNonNull(version);
 346         this.verify = verify;
 347         // version applies to multi-release jar files, ignored for regular jar files
 348         if (MULTI_RELEASE_FORCED) {
 349             this.version = RUNTIME_VERSION;
 350             version = Release.RUNTIME;
 351         } else {
 352             this.version = version.value();
 353         }
 354         this.runtimeVersioned = version == Release.RUNTIME;
 355 
 356         assert runtimeVersionExists();
 357     }
 358 
 359     private boolean runtimeVersionExists() {
 360         int version = jdk.Version.current().major();
 361         try {
 362             Release.valueOf(version);
 363             return true;
 364         } catch (IllegalArgumentException x) {
 365             System.err.println("No JarFile.Release object for release " + version);
 366             return false;
 367         }
 368     }
 369 
 370     /**
 371      * Returns the maximum version used when searching for versioned entries.
 372      *
 373      * @return the maximum version, or {@code Release.BASE} if this jar file is
 374      *         processed as if it is an unversioned jar file or is not a
 375      *         multi-release jar file
 376      * @since 9
 377      */
 378     public final Release getVersion() {
 379         if (isMultiRelease()) {
 380             return runtimeVersioned ? Release.RUNTIME : Release.valueOf(version);


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  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


 136     private SoftReference<Manifest> manRef;
 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 = Runtime.version().major();
 157         String jarVersion =
 158                 GetPropertyAction.privilegedGetProperty("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                 .privilegedGetProperty("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;


 340      * @throws NullPointerException if {@code version} is {@code null}
 341      * @since 9
 342      */
 343     public JarFile(File file, boolean verify, int mode, Release version) throws IOException {
 344         super(file, mode);
 345         Objects.requireNonNull(version);
 346         this.verify = verify;
 347         // version applies to multi-release jar files, ignored for regular jar files
 348         if (MULTI_RELEASE_FORCED) {
 349             this.version = RUNTIME_VERSION;
 350             version = Release.RUNTIME;
 351         } else {
 352             this.version = version.value();
 353         }
 354         this.runtimeVersioned = version == Release.RUNTIME;
 355 
 356         assert runtimeVersionExists();
 357     }
 358 
 359     private boolean runtimeVersionExists() {
 360         int version = Runtime.version().major();
 361         try {
 362             Release.valueOf(version);
 363             return true;
 364         } catch (IllegalArgumentException x) {
 365             System.err.println("No JarFile.Release object for release " + version);
 366             return false;
 367         }
 368     }
 369 
 370     /**
 371      * Returns the maximum version used when searching for versioned entries.
 372      *
 373      * @return the maximum version, or {@code Release.BASE} if this jar file is
 374      *         processed as if it is an unversioned jar file or is not a
 375      *         multi-release jar file
 376      * @since 9
 377      */
 378     public final Release getVersion() {
 379         if (isMultiRelease()) {
 380             return runtimeVersioned ? Release.RUNTIME : Release.valueOf(version);


< prev index next >