8173261: JAXP: TESTBUG: javax/xml/jaxp/isolatedjdk/catalog/PropertiesTest.sh
Reviewed-by: dfuchs, fyuan
--- a/jaxp/test/ProblemList.txt Wed Jul 05 22:44:47 2017 +0200
+++ b/jaxp/test/ProblemList.txt Tue Jan 24 11:10:19 2017 +0100
@@ -1,6 +1,6 @@
###########################################################################
#
-# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2015, 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
@@ -22,5 +22,3 @@
# questions.
#
###########################################################################
-
-javax/xml/jaxp/isolatedjdk/catalog/PropertiesTest.sh 8169827 generic-all
--- a/jaxp/test/javax/xml/jaxp/isolatedjdk/IsolatedJDK.sh Wed Jul 05 22:44:47 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/isolatedjdk/IsolatedJDK.sh Tue Jan 24 11:10:19 2017 +0100
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2015, 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
@@ -21,11 +21,6 @@
# or visit www.oracle.com if you need additional information or have any
# questions.
-if [ $# = 0 ]; then
- echo "The suffix of ISOLATED_JDK is mandatory"
- exit 1
-fi
-
checkVariable() {
variable='$'$1
@@ -42,20 +37,33 @@
done
}
-# Check essential variables
-checkVariables TESTJAVA TESTSRC TESTCLASSES TESTCLASSPATH
+# Script needs parameters
+if [ $# = 0 ]; then
+ echo "Syntax: IsolatedJDK.sh <Suffix> [remove]"
+ exit 1
+fi
-echo "TESTJAVA=${TESTJAVA}"
-echo "TESTSRC=${TESTSRC}"
-echo "TESTCLASSES=${TESTCLASSES}"
-echo "TESTCLASSPATH=${TESTCLASSPATH}"
+# Is it the call to remove ?
+if [ $# = 2 ]; then
+ if [ "$2" = "remove" ]; then
+ removeIsolatedJdk=1
+ fi
+fi
+
+# Check essential variables
+checkVariables TESTJAVA
+ISOLATED_JDK="./ISOLATED_JDK_$1"
+
+# Remove isolated copy
+if [ "$removeIsolatedJdk" = "1" ]; then
+ echo "Removing ${ISOLATED_JDK}..."
+ rm -rf ${ISOLATED_JDK}
+ echo "Removed."
+ exit 0
+fi
# Make an isolated copy of the testing JDK
-ISOLATED_JDK="./ISOLATED_JDK_$1"
-echo "ISOLATED_JDK=${ISOLATED_JDK}"
-
-echo "Copy testing JDK started"
+echo "Copying test JDK: ${TESTJAVA} -> ${ISOLATED_JDK}..."
cp -H -R ${TESTJAVA} ${ISOLATED_JDK} || exit 1
chmod -R +w ${ISOLATED_JDK} || exit 1
-echo "Copy testing JDK ended"
-
+echo "Copy done."
--- a/jaxp/test/javax/xml/jaxp/isolatedjdk/catalog/PropertiesTest.java Wed Jul 05 22:44:47 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/isolatedjdk/catalog/PropertiesTest.java Tue Jan 24 11:10:19 2017 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -37,20 +37,95 @@
import static catalog.CatalogTestUtils.generateJAXPProps;
import static catalog.CatalogTestUtils.getCatalogPath;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.xml.catalog.CatalogResolver;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
/*
- * This case tests if the properties FILES, DEFER, PREFER, RESOLVE in
- * jaxp.properties and system properties could be cared.
+ * @test
+ * @library /javax/xml/jaxp/libs /javax/xml/jaxp/isolatedjdk
+ * @run shell/timeout=600 ../IsolatedJDK.sh JAXP_PROPS
+ * @run testng catalog.PropertiesTest
+ * @run shell/timeout=600 ../IsolatedJDK.sh JAXP_PROPS remove
+ * @summary This test case tests if the properties FILES, DEFER, PREFER,
+ * RESOLVE in jaxp.properties and system properties are used.
+ * It needs to run in a copied JDK as it modifies the JDK's
+ * jaxp.properties file.
+ * @bug 8077931
*/
public class PropertiesTest {
private static final String CATALOG_PROPERTIES = "properties.xml";
+ @Test
+ /*
+ * Run main in a child process as it will modify the JDK.
+ */
+ public void test() throws Exception {
+ // get required properties and do some assertions
+ String javaclasspath = System.getProperty("java.class.path");
+ Assert.assertNotNull(javaclasspath, "Test class path is null");
+ String testclasspath = System.getProperty("test.class.path");
+ Assert.assertNotNull(testclasspath, "Test class path is null");
+ String testsourcepath = System.getProperty("test.src");
+ Assert.assertNotNull(testsourcepath, "Test source path is null");
+
+ // start the child process
+ List<String> testCall = new ArrayList<>(6);
+ testCall.add(Paths.get("ISOLATED_JDK_JAXP_PROPS", "/bin", "java").toString());
+ testCall.add("-cp");
+ testCall.add(javaclasspath);
+ testCall.add("-Dtest.class.path=" + testclasspath);
+ testCall.add("-Dtest.src=" + testsourcepath);
+ testCall.add("catalog.PropertiesTest");
+ System.out.println("Starting child process: " + Arrays.toString(testCall.toArray()));
+ Process test = new ProcessBuilder(testCall).start();
+
+ // wait for it to finish
+ boolean interrupted = false;
+ do {
+ try {
+ test.waitFor();
+ interrupted = false;
+ } catch (InterruptedException ie) {
+ interrupted = true;
+ }
+ } while (interrupted);
+
+ // trace system.out of child process
+ System.out.println("Proccess Out:");
+ BufferedReader br = new BufferedReader(new InputStreamReader(test.getInputStream()));
+ String line;
+ while ((line = br.readLine()) != null) {
+ System.out.println(line);
+ }
+ br.close();
+
+ // trace system.err of child process
+ System.out.println("Proccess Err:");
+ br = new BufferedReader(new InputStreamReader(test.getErrorStream()));
+ while ((line = br.readLine()) != null) {
+ System.out.println(line);
+ }
+ br.close();
+
+ // trace exit value and assert 0
+ int exitValue = test.exitValue();
+ System.out.println("Process Exit code: " + exitValue);
+ Assert.assertEquals(exitValue, 0, "PropertiesTest returned nonzero exit code.");
+ }
+
public static void main(String[] args) throws Exception {
System.out.println("testJAXPProperties started");
testJAXPProperties();
@@ -64,7 +139,8 @@
}
/*
- * Tests how does jaxp.properties affects the resolution.
+ * Tests how jaxp.properties affects the resolution.
+ * Be careful: This test modifies jaxp.properties in the used JDK.
*/
private static void testJAXPProperties() throws IOException {
generateJAXPProps(createJAXPPropsContent());
@@ -73,7 +149,7 @@
}
/*
- * Tests how does system properties affects the resolution.
+ * Tests how system properties affects the resolution.
*/
private static void testSystemProperties() {
setSystemProperties();
@@ -104,7 +180,7 @@
// The properties in jaxp.properties don't use default values
private static String createJAXPPropsContent() {
Map<String, String> props = new HashMap<>();
- props.put(FEATURE_FILES, getCatalogPath(CATALOG_PROPERTIES));
+ props.put(FEATURE_FILES, getCatalogPath(CATALOG_PROPERTIES).toString());
props.put(FEATURE_DEFER, DEFER_FALSE);
props.put(FEATURE_PREFER, PREFER_SYSTEM);
props.put(FEATURE_RESOLVE, RESOLVE_CONTINUE);
@@ -113,7 +189,7 @@
// The system properties don't use default values
private static void setSystemProperties() {
- System.setProperty(FEATURE_FILES, getCatalogPath(CATALOG_PROPERTIES));
+ System.setProperty(FEATURE_FILES, getCatalogPath(CATALOG_PROPERTIES).toString());
System.setProperty(FEATURE_DEFER, DEFER_FALSE);
System.setProperty(FEATURE_PREFER, PREFER_SYSTEM);
System.setProperty(FEATURE_RESOLVE, RESOLVE_CONTINUE);
--- a/jaxp/test/javax/xml/jaxp/isolatedjdk/catalog/PropertiesTest.sh Wed Jul 05 22:44:47 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-#!/bin/sh
-
-# 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.
-
-# @test
-# @bug 8077931
-# @summary This case tests if the properties FILES, DEFER, PREFER, RESOLVE in
-# jaxp.properties and system properties could be used.
-# @key intermittent
-# @library ../../libs/
-# @build catalog.CatalogTestUtils
-# @build PropertiesTest
-# @run shell/timeout=600 ../IsolatedJDK.sh JAXP_PROPS
-# @run shell/timeout=600 PropertiesTest.sh
-
-echo "Copies properties.xml to class path"
-TEST_CATALOG_PATH=${TESTCLASSES}/catalog/catalogFiles
-echo "TEST_CATALOG_PATH=${TEST_CATALOG_PATH}"
-mkdir -p ${TEST_CATALOG_PATH}
-cp ${TESTSRC}/catalogFiles/properties.xml ${TEST_CATALOG_PATH}/properties.xml
-
-# Execute test
-ISOLATED_JDK=./ISOLATED_JDK_JAXP_PROPS
-echo "Executes PropertiesTest"
-${ISOLATED_JDK}/bin/java -Dtest.src="${TESTSRC}/.." ${TESTVMOPTS} -cp "${TESTCLASSPATH}" catalog.PropertiesTest
-exitCode=$?
-
-# Cleanup ISOLATED_JDK
-rm -rf ${ISOLATED_JDK}
-
-# Results
-echo ''
-if [ $exitCode -gt 0 ]; then
- echo "PropertiesTest failed";
-else
- echo "PropertiesTest passed";
-fi
-exit $exitCode
-
--- a/jaxp/test/javax/xml/jaxp/libs/catalog/CatalogTestUtils.java Wed Jul 05 22:44:47 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/libs/catalog/CatalogTestUtils.java Tue Jan 24 11:10:19 2017 +0100
@@ -69,12 +69,6 @@
private static final String JAXP_PROPS = "jaxp.properties";
private static final String JAXP_PROPS_BAK = JAXP_PROPS + ".bak";
- /*
- * Force using slash as File separator as we always use cygwin to test in
- * Windows platform.
- */
- private static final String FILE_SEP = "/";
-
private CatalogTestUtils() { }
/* ********** create resolver ********** */
@@ -133,11 +127,14 @@
/* ********** jaxp.properties ********** */
/*
- * Generates the jaxp.properties with the specified content.
+ * Generates jaxp.properties with the specified content,
+ * takes a backup if possible.
*/
static void generateJAXPProps(String content) throws IOException {
Path filePath = getJAXPPropsPath();
Path bakPath = filePath.resolveSibling(JAXP_PROPS_BAK);
+ System.out.println("Creating new file " + filePath +
+ ", saving old version to " + bakPath + ".");
if (Files.exists(filePath) && !Files.exists(bakPath)) {
Files.move(filePath, bakPath);
}
@@ -146,14 +143,16 @@
}
/*
- * Deletes the jaxp.properties.
+ * Deletes jaxp.properties, restoring backup if possible.
*/
static void deleteJAXPProps() throws IOException {
Path filePath = getJAXPPropsPath();
+ Path bakPath = filePath.resolveSibling(JAXP_PROPS_BAK);
+ System.out.println("Removing file " + filePath +
+ ", restoring old version from " + bakPath + ".");
Files.delete(filePath);
- Path bakFilePath = filePath.resolveSibling(JAXP_PROPS_BAK);
- if (Files.exists(bakFilePath)) {
- Files.move(bakFilePath, filePath);
+ if (Files.exists(bakPath)) {
+ Files.move(bakPath, filePath);
}
}
--- a/jaxp/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java Wed Jul 05 22:44:47 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java Tue Jan 24 11:10:19 2017 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -85,13 +85,13 @@
* A map storing every test's current test file pointer. File number should
* be incremental and it's a thread-safe reading on this file number.
*/
- private static final ConcurrentHashMap<Class, Integer> currentFileNumber
+ private static final ConcurrentHashMap<Class<?>, Integer> currentFileNumber
= new ConcurrentHashMap<>();
/**
* BOM table for storing BOM header.
*/
- private final static Map<String, byte[]> bom = new HashMap();
+ private final static Map<String, byte[]> bom = new HashMap<>();
/**
* Initialize all BOM headers.
@@ -313,7 +313,7 @@
* @param clazz test class.
* @return next test output file name.
*/
- public static String getNextFile(Class clazz) {
+ public static String getNextFile(Class<?> clazz) {
int nextNumber = currentFileNumber.contains(clazz)
? currentFileNumber.get(clazz) + 1 : 1;
Integer i = currentFileNumber.putIfAbsent(clazz, nextNumber);
@@ -332,7 +332,7 @@
* path.
* @return a string represents the full path of accessing path.
*/
- public static String getPathByClassName(Class clazz, String relativeDir) {
+ public static String getPathByClassName(Class<?> clazz, String relativeDir) {
String javaSourcePath = System.getProperty("test.src").replaceAll("\\" + File.separator, FILE_SEP);
String normalizedPath = Paths.get(javaSourcePath, relativeDir).normalize().
toAbsolutePath().toString();
@@ -435,7 +435,7 @@
*/
public static void runWithTmpPermission(Runnable r, Permission... ps) {
JAXPPolicyManager policyManager = JAXPPolicyManager.getJAXPPolicyManager(false);
- List<Integer> tmpPermissionIndexes = new ArrayList();
+ List<Integer> tmpPermissionIndexes = new ArrayList<>();
if (policyManager != null) {
for (Permission p : ps)
tmpPermissionIndexes.add(policyManager.addTmpPermission(p));
@@ -459,7 +459,7 @@
*/
public static <T> T runWithTmpPermission(Supplier<T> s, Permission... ps) {
JAXPPolicyManager policyManager = JAXPPolicyManager.getJAXPPolicyManager(false);
- List<Integer> tmpPermissionIndexes = new ArrayList();
+ List<Integer> tmpPermissionIndexes = new ArrayList<>();
if (policyManager != null) {
for (Permission p : ps)
tmpPermissionIndexes.add(policyManager.addTmpPermission(p));
@@ -483,7 +483,7 @@
*/
public static void tryRunWithTmpPermission(RunnableWithException r, Permission... ps) throws Exception {
JAXPPolicyManager policyManager = JAXPPolicyManager.getJAXPPolicyManager(false);
- List<Integer> tmpPermissionIndexes = new ArrayList();
+ List<Integer> tmpPermissionIndexes = new ArrayList<>();
if (policyManager != null) {
for (Permission p : ps)
tmpPermissionIndexes.add(policyManager.addTmpPermission(p));