8173905: Test tools/jar/multiRelease/RuntimeTest.java fails under JDK 10

Reviewed-by: psandoz, redestad
This commit is contained in:
Amy Lu 2017-05-26 17:36:22 +08:00
parent 77dd83824d
commit 2fc00fbdb1
12 changed files with 72 additions and 226 deletions

View File

@ -258,8 +258,6 @@ tools/jimage/JImageExtractTest.java 8170120 generic-
tools/jimage/JImageListTest.java 8170120 generic-all
tools/jimage/JImageVerifyTest.java 8170120 generic-all
tools/jar/multiRelease/RuntimeTest.java 8173905 generic-all
tools/schemagen/MultiReleaseJarTest.java 8174692 generic-all
tools/wsgen/MultiReleaseJarTest.java 8174692 generic-all

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* 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
@ -25,12 +25,7 @@
* @test
* @summary Test Multi-Release jar usage in runtime
* @library /test/lib
* @library /lib/testlibrary
* @modules jdk.compiler
* @build jdk.test.lib.JDKToolFinder jdk.test.lib.JDKToolLauncher
* jdk.test.lib.process.OutputAnalyzer
* jdk.test.lib.process.ProcessTools
* CompilerUtils RuntimeTest
* @run testng RuntimeTest
*/
@ -41,6 +36,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
@ -51,7 +47,10 @@ import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.testng.annotations.BeforeClass;
@ -60,37 +59,53 @@ import org.testng.annotations.Test;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.compiler.CompilerUtils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
public class RuntimeTest {
public static final int SUCCESS = 0;
private final String src = System.getProperty("test.src", ".");
private final String usr = System.getProperty("user.dir", ".");
private static final String src = System.getProperty("test.src", ".");
private static final String usr = System.getProperty("user.dir", ".");
private static final Path srcFileRoot = Paths.get(src, "data", "runtimetest");
private static final Path genFileRoot = Paths.get(usr, "data", "runtimetest");
private static final int OLD_RELEASE = 8;
private static final int CURRENT_RELEASE = Runtime.version().major();
private static final int FUTURE_RELEASE = CURRENT_RELEASE + 1;
private static final String MRJAR_BOTH_RELEASES = "MV_BOTH.jar";
private static final String MRJAR_CURRENT_RELEASE = "MV_ONLY_" + CURRENT_RELEASE + ".jar";
private static final String NON_MRJAR_OLD_RELEASE = "NON_MV.jar";
private static final int[] versions = { OLD_RELEASE, CURRENT_RELEASE, FUTURE_RELEASE };
@DataProvider(name = "jarFiles")
Object[][] jarFiles() {
return new Object[][] { { "MV_BOTH.jar", 9, 9, 9 },
{ "MV_ONLY_9.jar", 9, 9, 9 },
{ "NON_MV.jar", 8, 8, 8 } };
return new Object[][]{
{ MRJAR_BOTH_RELEASES, CURRENT_RELEASE, CURRENT_RELEASE, CURRENT_RELEASE },
{ MRJAR_CURRENT_RELEASE, CURRENT_RELEASE, CURRENT_RELEASE, CURRENT_RELEASE },
{ NON_MRJAR_OLD_RELEASE, OLD_RELEASE, OLD_RELEASE, OLD_RELEASE }
};
}
@BeforeClass
protected void setUpTest() throws Throwable {
createJarSourceFiles();
compile();
Path classes = Paths.get("classes");
jar("cfm", "MV_BOTH.jar", "manifest.txt",
"-C", classes.resolve("base").toString(), ".",
"--release", "9", "-C", classes.resolve("v9").toString(), ".",
"--release", "10", "-C", classes.resolve("v10").toString(), ".")
jar("cfm", MRJAR_BOTH_RELEASES, "manifest.txt",
"-C", classes.resolve("v" + OLD_RELEASE).toString(), ".",
"--release", "" + CURRENT_RELEASE, "-C", classes.resolve("v" + CURRENT_RELEASE).toString(), ".",
"--release", "" + FUTURE_RELEASE, "-C", classes.resolve("v" + FUTURE_RELEASE).toString(), ".")
.shouldHaveExitValue(0);
jar("cfm", "MV_ONLY_9.jar", "manifest.txt",
"-C", classes.resolve("base").toString(), ".",
"--release", "9", "-C", classes.resolve("v9").toString(), ".")
jar("cfm", MRJAR_CURRENT_RELEASE, "manifest.txt",
"-C", classes.resolve("v" + OLD_RELEASE).toString(), ".",
"--release", "" + CURRENT_RELEASE, "-C", classes.resolve("v" + CURRENT_RELEASE).toString(), ".")
.shouldHaveExitValue(0);
jar("cfm", "NON_MV.jar", "manifest.txt",
"-C", classes.resolve("base").toString(), ".")
jar("cfm", NON_MRJAR_OLD_RELEASE, "manifest.txt",
"-C", classes.resolve("v" + OLD_RELEASE).toString(), ".")
.shouldHaveExitValue(0);
}
@ -203,12 +218,37 @@ public class RuntimeTest {
return ProcessTools.executeCommand(launcher.getCommand());
}
private static String platformPath(String p) {
return p.replace("/", File.separator);
}
private static void createJarSourceFiles() throws IOException {
for (int ver : versions) {
Files.find(srcFileRoot, 3, (file, attrs) -> (file.toString().endsWith(".template")))
.map(srcFileRoot::relativize)
.map(Path::toString)
.map(p -> p.replace(".template", ""))
.forEach(f -> {
try {
Path template = srcFileRoot.resolve(f + ".template");
Path out = genFileRoot.resolve(platformPath("v" + ver + "/" + f));
Files.createDirectories(out.getParent());
List<String> lines = Files.lines(template)
.map(s -> s.replaceAll("\\$version", String.valueOf(ver)))
.collect(Collectors.toList());
Files.write(out, lines);
} catch (IOException x) {
throw new UncheckedIOException(x);
}
});
}
}
private void compile() throws Throwable {
String[] vers = { "base", "v9", "v10" };
for (String ver : vers) {
Path classes = Paths.get(usr, "classes", ver);
for (int ver : versions) {
Path classes = Paths.get(usr, "classes", "v" + ver);
Files.createDirectories(classes);
Path source = Paths.get(src, "data", "runtimetest", ver);
Path source = genFileRoot.resolve("v" + ver);
assertTrue(CompilerUtils.compile(source, classes));
Files.copy(source.resolve("versionResource"),
classes.resolve("versionResource"),
@ -217,10 +257,10 @@ public class RuntimeTest {
Path classes = Paths.get(usr, "classes", "test");
Files.createDirectory(classes);
Path source = Paths.get(src, "data", "runtimetest", "test");
Path source = srcFileRoot.resolve("test");
assertTrue(
CompilerUtils.compile(source, classes, "-cp", "classes/base/"));
Files.copy(Paths.get(src, "data", "runtimetest", "manifest.txt"),
CompilerUtils.compile(source, classes, "-cp", "classes/v" + OLD_RELEASE));
Files.copy(srcFileRoot.resolve("manifest.txt"),
Paths.get(usr, "manifest.txt"),
StandardCopyOption.REPLACE_EXISTING);
}

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2016, 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.
*/
package testpackage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Main {
private static final int MAIN_VERSION = 8;
public static void main(String[] args) {
System.out.println("Main version: " + getMainVersion());
System.out.println("Helpers version: " + getHelperVersion());
System.out.println("Resource version: " + getResourceVersion());
}
public static int getMainVersion() {
return MAIN_VERSION;
}
public static int getHelperVersion() {
return testpackage.Helper.getHelperVersion();
}
public static int getResourceVersion() {
ClassLoader cl = Main.class.getClassLoader();
InputStream ris = cl.getResourceAsStream("versionResource");
if (ris == null) {
throw new Error("Test issue: resource versionResource"
+ " cannot be loaded!");
}
try (BufferedReader br = new BufferedReader(new InputStreamReader(ris))) {
return Integer.parseInt(br.readLine());
} catch (IOException ioe) {
throw new Error("Unexpected issue", ioe);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* 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
@ -25,7 +25,7 @@ package testpackage;
public class Helper {
private static final int HELPER_VERSION = 8;
private static final int HELPER_VERSION = $version;
public static int getHelperVersion() {
return HELPER_VERSION;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* 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
@ -30,7 +30,7 @@ import java.io.InputStreamReader;
public class Main {
private static final int MAIN_VERSION = 9;
private static final int MAIN_VERSION = $version;
public static void main(String[] args) {
System.out.println("Main version: " + getMainVersion());

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2016, 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.
*/
package testpackage;
public class Helper {
private static final int HELPER_VERSION = 10;
public static int getHelperVersion() {
return HELPER_VERSION;
}
}

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2016, 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.
*/
package testpackage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Main {
private static final int MAIN_VERSION = 10;
public static void main(String[] args) {
System.out.println("Main version: " + getMainVersion());
System.out.println("Helpers version: " + getHelperVersion());
System.out.println("Resource version: " + getResourceVersion());
}
public static int getMainVersion() {
return MAIN_VERSION;
}
public static int getHelperVersion() {
return testpackage.Helper.getHelperVersion();
}
public static int getResourceVersion() {
ClassLoader cl = Main.class.getClassLoader();
InputStream ris = cl.getResourceAsStream("versionResource");
if (ris == null) {
throw new Error("Test issue: resource versionResource"
+ " cannot be loaded!");
}
try (BufferedReader br = new BufferedReader(new InputStreamReader(ris))) {
return Integer.parseInt(br.readLine());
} catch (IOException ioe) {
throw new Error("Unexpected issue", ioe);
}
}
}

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2016, 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.
*/
package testpackage;
public class Helper {
private static final int HELPER_VERSION = 9;
public static int getHelperVersion() {
return HELPER_VERSION;
}
}

View File

@ -0,0 +1 @@
$version