/* * Copyright (c) 2016, 2017, 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.
*/
/* * @test * @bug 8146486 8172432 * @summary Fail to create a MR modular JAR with a versioned entry in * base-versioned empty package * @modules java.base/jdk.internal.module * jdk.compiler * jdk.jartool * @library /test/lib * @build jdk.test.lib.Platform * jdk.test.lib.util.FileUtils * @run testng Basic
*/
// updates a valid multi-release jar with a new public class in // versioned section and fails
@Test publicvoid test1() { // successful build of multi-release jar int rc = jar("-cf mmr.jar -C classes . --release 9 -C mr9 p/Hi.class"); Assert.assertEquals(rc, 0);
// failed build because of new public class
rc = jar("-uf mmr.jar --release 9 -C mr9 p/internal/Bar.class"); Assert.assertEquals(rc, 1);
String s = new String(errbytes.toByteArray()); Assert.assertTrue(Message.NOT_FOUND_IN_BASE_ENTRY.match(s, "p/internal/Bar.class"));
}
// updates a valid multi-release jar with a module-info class and new // concealed public class in versioned section and succeeds
@Test publicvoid test2() { // successful build of multi-release jar int rc = jar("-cf mmr.jar -C classes . --release 9 -C mr9 p/Hi.class"); Assert.assertEquals(rc, 0);
// successful build because of module-info and new public class
rc = jar("-uf mmr.jar module-info.class --release 9 -C mr9 p/internal/Bar.class"); Assert.assertEquals(rc, 0);
String s = new String(errbytes.toByteArray()); Assert.assertTrue(Message.NEW_CONCEALED_PACKAGE_WARNING.match(s, "p/internal/Bar.class"));
// jar tool fails building mmr.jar because of new public class
@Test publicvoid test3() { int rc = jar("-cf mmr.jar -C classes . --release 9 -C mr9 ."); Assert.assertEquals(rc, 1);
String s = new String(errbytes.toByteArray()); Assert.assertTrue(Message.NOT_FOUND_IN_BASE_ENTRY.match(s, "p/internal/Bar.class"));
}
// jar tool succeeds building mmr.jar because of concealed package
@Test publicvoid test4() { int rc = jar("-cf mmr.jar module-info.class -C classes . " + "--release 9 module-info.class -C mr9 ."); Assert.assertEquals(rc, 0);
String s = new String(errbytes.toByteArray()); Assert.assertTrue(Message.NEW_CONCEALED_PACKAGE_WARNING.match(s, "p/internal/Bar.class"));
// jar tool does two updates, no exported packages, all concealed. // Along with various --describe-module variants
@Test publicvoid test5() throws IOException { // compile the mr10 directory
Path source = testsrc.resolve("src").resolve("mr10");
Path destination = Paths.get("mr10");
javac(source, destination);
// create a directory for this tests special files
Files.createDirectory(Paths.get("test5"));
// create an empty module-info.java
String hi = "module hi {" + linesep + "}" + linesep;
Path modinfo = Paths.get("test5", "module-info.java");
Files.write(modinfo, hi.getBytes());
// and compile it
javac(modinfo, Paths.get("test5"));
for (String release : new String[] {"9" , "10", "100", "1000"}) {
jar("-d --file mr.jar --release " + release);
actual = lines(outbytes); Assert.assertEquals(actual, expected);
}
}
// root and versioned module-info entries have different main-class, version // attributes
@Test publicvoid test6() throws IOException { // create a directory for this tests special files
Files.createDirectory(Paths.get("test6"));
Files.createDirectory(Paths.get("test6-v9"));
Assert.assertTrue(Message.CONTAINS_DIFFERENT_VERSION.match( new String(errbytes.toByteArray()), "META-INF/versions/9/module-info.class"));
}
// versioned mmr without root module-info.class
@Test publicvoid test7() throws IOException { // create a directory for this tests special files
Files.createDirectory(Paths.get("test7"));
Files.createDirectory(Paths.get("test7-v9"));
Files.createDirectory(Paths.get("test7-v10"));
staticenum Message {
CONTAINS_DIFFERENT_MAINCLASS( ": module-info.class in a versioned directory contains different \"main-class\""
),
CONTAINS_DIFFERENT_VERSION( ": module-info.class in a versioned directory contains different \"version\""
),
NOT_FOUND_IN_BASE_ENTRY( ", contains a new public class not found in base entries"
),
NEW_CONCEALED_PACKAGE_WARNING( " is a public class" + " in a concealed package, placing this jar on the class path will result" + " in incompatible public interfaces"
);
final String msg;
Message(String msg) { this.msg = msg;
}
/* * Test if the given output contains this message ignoring the line break.
*/ boolean match(String output, String entry) {
System.out.println("Expected: " + entry + msg);
System.out.println("Found: " + output); return Arrays.stream(output.split("\\R"))
.collect(Collectors.joining(" "))
.contains(entry + msg);
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.