# HG changeset patch # Parent c1d2ccc4a630df5fccc87ded1e16a548c78f9a1f diff --git a/src/java.base/share/classes/com/sun/java/util/jar/pack/PackerImpl.java b/src/java.base/share/classes/com/sun/java/util/jar/pack/PackerImpl.java --- a/src/java.base/share/classes/com/sun/java/util/jar/pack/PackerImpl.java +++ b/src/java.base/share/classes/com/sun/java/util/jar/pack/PackerImpl.java @@ -272,22 +272,6 @@ // (Done collecting options from props.) - boolean isClassFile(String name) { - if (!name.endsWith(".class")) return false; - for (String prefix = name; ; ) { - if (passFiles.contains(prefix)) return false; - int chop = prefix.lastIndexOf('/'); - if (chop < 0) break; - prefix = prefix.substring(0, chop); - } - return true; - } - - boolean isMetaInfFile(String name) { - return name.startsWith("/" + Utils.METAINF) || - name.startsWith(Utils.METAINF); - } - // Get a new package, based on the old one. private void makeNextPackage() { pkg.reset(); @@ -332,6 +316,29 @@ InFile(JarEntry je) { this(null, je); } + boolean isClassFile() { + if (!name.endsWith(".class")) { + return false; + } + for (String prefix = name;;) { + if (passFiles.contains(prefix)) { + return false; + } + int chop = prefix.lastIndexOf('/'); + if (chop < 0) { + break; + } + prefix = prefix.substring(0, chop); + } + return true; + } + boolean isMetaInfFile() { + return name.startsWith("/" + Utils.METAINF) + || name.startsWith(Utils.METAINF); + } + boolean mustProcess() { + return !isMetaInfFile() && isClassFile(); + } long getInputLength() { long len = (je != null)? je.getSize(): f.length(); assert(len >= 0) : this+".len="+len; @@ -391,7 +398,7 @@ Package.File file = null; // (5078608) : discount the resource files in META-INF // from segment computation. - long inflen = (isMetaInfFile(name)) + long inflen = (inFile.isMetaInfFile()) ? 0L : inFile.getInputLength(); @@ -406,7 +413,7 @@ assert(je.isDirectory() == name.endsWith("/")); - if (isClassFile(name)) { + if (inFile.mustProcess()) { file = readClass(name, bits.getInputStream()); } if (file == null) { @@ -429,7 +436,7 @@ for (InFile inFile : inFiles) { String name = inFile.name; // (5078608) : discount the resource files completely from segmenting - long inflen = (isMetaInfFile(name)) + long inflen = (inFile.isMetaInfFile()) ? 0L : inFile.getInputLength() ; if ((segmentSize += inflen) > segmentLimit) { @@ -447,7 +454,7 @@ if (verbose > 1) Utils.log.fine("Reading " + name); Package.File file = null; - if (isClassFile(name)) { + if (inFile.mustProcess()) { file = readClass(name, strm); if (file == null) { strm.close(); diff --git a/test/tools/pack200/MultiVersion.java b/test/tools/pack200/MultiVersion.java new file mode 100644 --- /dev/null +++ b/test/tools/pack200/MultiVersion.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import java.io.File; +import java.util.ArrayList; +import java.util.List; +/* + * @test + * @bug 8066272 + * @summary tests a simple multi-versioned jar file + * @compile -XDignore.symbol.file Utils.java MultiVersion.java + * @run main MultiVersion + * @author ksrini + */ +public class MultiVersion { + + public static void main(String... args) throws Exception { + new MultiVersion().run(); + //Utils.cleanup(); + } + + final File cwd = new File("."); + final File metaInfDir = new File(cwd, "META-INF"); + final File versionsDir = new File(metaInfDir, "versions"); + + void run() throws Exception { + emitClassFiles(""); + emitClassFiles("6"); + emitClassFiles("7"); + emitClassFiles("8"); + // jar the file up + File testFile = new File(cwd, "test" + Utils.JAR_FILE_EXT); + Utils.jar("cvf", testFile.getAbsolutePath(), "META-INF", "src", "pkg"); + + File outFile = new File(cwd, "test" + Utils.JAR_FILE_EXT); + List cmdsList = new ArrayList<>(); + + cmdsList.add(Utils.getPack200Cmd()); + cmdsList.add("-J-ea"); + cmdsList.add("-J-esa"); + cmdsList.add("-v"); + cmdsList.add("--repack"); + cmdsList.add(outFile.getName()); + cmdsList.add(testFile.getName()); + List output = Utils.runExec(cmdsList); + Utils.doCompareVerify(testFile, outFile); + } + void emitClassFiles(String version) throws Exception { + + final File outDir = version.isEmpty() + ? cwd + : new File(versionsDir, version); + outDir.mkdirs(); + + final File srcDir = version.isEmpty() + ? new File(cwd, "src") + : new File(new File(versionsDir, version), "src"); + srcDir.mkdirs(); + final String fname = "Foo"; + final File srcFile = new File(srcDir, fname + Utils.JAVA_FILE_EXT); + + List scratch = new ArrayList<>(); + + scratch.add("package pkg;"); + switch (version) { + case "6.0": + scratch.add("public class Foo {"); + scratch.add("public static final class Bar {}"); + break; + case "7.0": + scratch.add("public abstract class Foo {"); + scratch.add("public final class Bar {}"); + break; + case "8.0": + scratch.add("public interface Foo {"); + scratch.add("public final class Bar {}"); + break; + default: + scratch.add("public class Foo {"); + scratch.add("public final class Bar {}"); + break; + } + scratch.add("}"); + + Utils.createFile(srcFile, scratch); + Utils.compiler("-d", + outDir.getAbsolutePath(), + srcFile.getAbsolutePath()); + } +}