db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abr...@apache.org
Subject svn commit: r482433 - in /db/derby/code/trunk/java/testing: ./ org/apache/derbyTesting/functionTests/tests/lang/ org/apache/derbyTesting/functionTests/util/ org/apache/derbyTesting/junit/
Date Tue, 05 Dec 2006 00:47:04 GMT
Author: abrown
Date: Mon Dec  4 16:47:02 2006
New Revision: 482433

URL: http://svn.apache.org/viewvc?view=rev&rev=482433
Log:
DERBY-1758 (partial): Enable the lang/XMLBindingTest to run under a security
manager. Changes include all of the following:

 - Updates lang/XMLBindingTest.java so that it will run under the default
testing security manager (i.e. removed the "noSecurityManager()" wrapper).

 - Adds a new property, derbyTesting.jaxpjar, to the default testing policy
file. This property holds the location of the JAXP jar picked up from the
classpath _if_ that jar is external to the JVM. If the jar is either embedded
within, or "endorsed" by, the JVM then this property is unused.

    The JAXP jar is then given permission to read the "extin" testing
directory, which is the directory into which the DTD required by XMLBindingTest
is copied (and thus JAXP has permission to read the DTD file).

 - Adds a new static utility method, "getJAXPParserLocation()", to the
junit/XML.java file. This method instantiates a JAXP object and then uses
the implementation-specific class name to try to find out where the JAXP
jar is located.

- Modifies derbyTesing/junit/build.xml so that junit/XML.java will only
build with 1.4 JVMs and higher. This is required because junit/XML.java
now references a JAXP class that is not defined in 1.3.

 - Updates the "getURL()" method of junit/SecurityManagerSetup.java to account
for situations where a class "code source" is null. Also updates the
"determineClasspath()" method of that class to set the derbyTesting.jaxpjar
property as appropriate.

 - And finally, moves the build order of the derbyTesting/junit directory
so that it is built *before* the derbyTesting/harness directory.

Modified:
    db/derby/code/trunk/java/testing/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLBindingTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/build.xml

Modified: db/derby/code/trunk/java/testing/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/build.xml?view=diff&rev=482433&r1=482432&r2=482433
==============================================================================
--- db/derby/code/trunk/java/testing/build.xml (original)
+++ db/derby/code/trunk/java/testing/build.xml Mon Dec  4 16:47:02 2006
@@ -56,11 +56,11 @@
   <target name="testing" 
           description="Build Derby testing files">
 
+    <ant dir="${derby.testing.src.dir}/${derby.testing.junit.dir}"/> 
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/harness"/> 
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/testData"/> 
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/util"/> 
     <ant dir="${derby.testing.src.dir}/${derby.testing.unittest.dir}"/> 
-    <ant dir="${derby.testing.src.dir}/${derby.testing.junit.dir}"/> 
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/junitTests/compatibility"/>

     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/junitTests/derbyNet"/>
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/jdbcapi"/>


Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLBindingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLBindingTest.java?view=diff&rev=482433&r1=482432&r2=482433
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLBindingTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLBindingTest.java
Mon Dec  4 16:47:02 2006
@@ -30,15 +30,12 @@
 import java.sql.Types;
 
 import junit.framework.Test;
-import junit.extensions.TestSetup;
 import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.XML;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.BaseJDBCTestSetup;
-import org.apache.derbyTesting.junit.BaseTestCase;
-import org.apache.derbyTesting.junit.SecurityManagerSetup;
 import org.apache.derbyTesting.junit.SupportFilesSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
@@ -84,25 +81,15 @@
             suite.addTest(
                 TestConfiguration.defaultSuite(XMLBindingTest.class, false));
 
-            TestSetup wrapper = new XBindTestSetup(suite);
+            XBindTestSetup wrapper = new XBindTestSetup(suite);
 
             /* XML parser needs to read "personal.dtd" for schema-based
              * insertion, so copy it to user directory.
              */
-            wrapper = new SupportFilesSetup(wrapper,
+            return new SupportFilesSetup(wrapper,
                 new String [] {
                     "functionTests/tests/lang/xmlTestFiles/personal.dtd"
                 });
-
-            /* RESOLVE: In order to run XMLBindingTest as part of a
-             * suite we currently have to disable the security manager
-             * to allow the JAXP parser to read DTD files.  Once we
-             * figure out how to give JAXP the correct permissions
-             * in the derby_tests policy file, we can then remove the
-             * "noSecurityManager()" decoration. See comments in
-             * DERBY-1758 for details.
-             */
-            return SecurityManagerSetup.noSecurityManager(wrapper);
         }
 
         return suite;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy?view=diff&rev=482433&r1=482432&r2=482433
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
Mon Dec  4 16:47:02 2006
@@ -2,7 +2,7 @@
 // Policy file with minimal set of permissions to run derby's
 // functional tests.
 //
-// The test harness sets up three variables used by this policy file
+// The test harness sets up four variables used by this policy file
 //
 // derbyTesting.codejar - URL to the jar files when they are in the classpath
 // derbyTesting.codeclasses - URL to the classes directory when it is in the classpath
@@ -13,7 +13,9 @@
 // derbyTesting.codedir - File location of either derbyTesting.codejar or derbyTesting.codeclasses.
 // Only required due to a BUG (see below for more info).
 //
-// 
+// derbyTesting.jaxpjar - URL to the jar file containing the JAXP implementation
+//     for XML-based tests (ex. lang/XMLBindingTest.java).
+//
 // derbyTesting.serverhost - Host name or ip where network server is started 
 // derbyTesting.clienthost - specifies the clients ip address/hostName. 
 //     when testing with networkserver on a remote host, this needs to be passed in 
@@ -187,4 +189,12 @@
 // through this mechanism.
 grant {
     permission java.util.PropertyPermission "derbyRoutineSecurityTest.yes", "read";
+};
+
+// When inserting XML values that use external DTD's, the JAXP parser
+// needs permission to read the DTD files.  We assume that all DTD
+// files will be copied to extin/ by whichever tests need them.  So
+// grant the JAXP parser permissions to read that directory.
+grant codeBase "${derbyTesting.jaxpjar}" {
+  permission java.io.FilePermission "${user.dir}${/}extin${/}-", "read";
 };

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java?view=diff&rev=482433&r1=482432&r2=482433
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
Mon Dec  4 16:47:02 2006
@@ -252,6 +252,16 @@
             antjunit = null;
         }
 		
+        /* When inserting XML values that use external DTD's, the JAXP
+         * parser needs permission to read the DTD files.  So here we set
+         * a property to hold the location of the JAXP implementation
+         * jar file.  We can then grant the JAXP impl the permissions
+         * needed for reading the DTD files.
+         */
+        String jaxp = XML.getJAXPParserLocation();
+        if (jaxp != null)
+            classPathSet.setProperty("derbyTesting.jaxpjar", jaxp);
+
 		URL testing = getURL(SecurityManagerSetup.class);
 		
 		boolean isClasspath = testing.toExternalForm().endsWith("/");
@@ -317,12 +327,21 @@
 	/**
 	 * Get the URL of the code base from a class.
 	 */
-	private static URL getURL(final Class cl)
+	protected static URL getURL(final Class cl)
 	{
 		return (URL)
 		   AccessController.doPrivileged(new java.security.PrivilegedAction() {
 
 			public Object run() {
+
+                /* It's possible that the class does not have a "codeSource"
+                 * associated with it (ex. if it is embedded within the JVM,
+                 * as can happen with Xalan and/or a JAXP parser), so in that
+                 * case we just return null.
+                 */
+                if (cl.getProtectionDomain().getCodeSource() == null)
+                    return null;
+
 				return cl.getProtectionDomain().getCodeSource().getLocation();
 			}
 		});

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java?view=diff&rev=482433&r1=482432&r2=482433
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java Mon Dec  4 16:47:02
2006
@@ -26,6 +26,7 @@
 import java.io.InputStreamReader;
 
 import java.lang.reflect.Method;
+import java.net.URL;
 import java.security.PrivilegedActionException;
 
 import java.sql.Connection;
@@ -35,6 +36,14 @@
 import java.util.StringTokenizer;
 import java.util.Properties;
 
+/* The following import is for a JDBC 3.0 JAXP class, which means that
+ * this file can only be built with 1.4 or later (see build.xml in
+ * this directory).  This means that 1.3 JVMs will not be able to
+ * instantiate this class--but since 1.3 is deprecated as of 10.3,
+ * we do not worry about that here.
+ */
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import junit.framework.Assert;
 
 /**
@@ -90,6 +99,14 @@
         "org/apache/derbyTesting/functionTests/tests/lang/xmlTestFiles/";
 
     /**
+     * String form of the URL for the jar file in the user's classpath
+     * that holds the JAXP implementation in use.  If the implementation
+     * is embedded within, or endorsed by, the JVM, then we will set this
+     * field to be an empty string.
+     */
+    private static String jaxpURLString = null;
+
+    /**
      * Return true if the classpath contains JAXP and
      * Xalan classes (this method doesn't care about
      * the particular version of Xalan).
@@ -363,5 +380,71 @@
         }
 
         return haveMinXalanVersion;
+    }
+
+    /**
+     * Return the string form of the URL for the jar file that contains
+     * whichever JAXP parser implementation is picked up from the user's
+     * classpath.  If the JAXP parser is not in the user's classpath,
+     * then it must be embedded within the JVM (either implicitly or else
+     * through use of "endorsed standards" jars), in which case we return
+     * null.
+     *
+     * NOTE: Assumption is that we only get here if we know there is in
+     * fact a JAXP parser available to the JVM.  I.e. if a call to
+     * the "classpathMeetsXMLReqs()" method of this class will return 
+     * true.
+     */
+    protected static String getJAXPParserLocation()
+    {
+        // Only get the URL if we have not already done it.
+        if (jaxpURLString == null)
+        {
+            try {
+
+                /* Figure out which JAXP implementation we have by
+                 * instantiating a DocumentBuilderFactory and then getting
+                 * the implementation-specific class name for that object.
+                 * Note that we cannot just use:
+                 *
+                 *  Class.forName("javax.xml.parsers.DocumentBuilderFactory")
+                 *
+                 * because the constructor for DocumentBuilderFactory (and
+                 * for all JAXP abstract classes) is protected, which means
+                 * Class.forName() cannot instantiate the object.  So we
+                 * explicitly create the object using the JAXP method for
+                 * doing so, and then we pass the object's implementation-
+                 * specific class name to Class.forName() to get the
+                 * appropriate Class.  The Class can then be used for
+                 * retrieval of the URL.
+                 */
+                URL jaxpURL = SecurityManagerSetup.getURL(Class.forName(
+                    DocumentBuilderFactory.newInstance().getClass().getName()));
+
+                /* If we found a URL then the JAXP parser is in the classpath
+                 * in some jar external to the JVM; in that case we have the
+                 * the jar's location so we use/return that.  Otherwise we
+                 * assume that the JAXP parser is either embedded within the
+                 * JVM or else "endorsed" by it. In those cases we set our
+                 * URL string to be the empty string, which is non-null and
+                 * thus we will only execute this try-catch once.
+                 */
+                jaxpURLString =
+                    (jaxpURL == null) ? "" : jaxpURL.toExternalForm();
+
+            } catch (Exception e) {
+
+                /* Probably a ClassNotFoundException.  We assume this
+                 * means that there is no JAXP parser implementation
+                 * in the classpath--but in that case we do not expect
+                 * to get here.
+                 */
+                 Assert.fail("Failed to located JAXP parser.");
+
+            }
+        }
+
+        // If we didn't find the JAXP parser URL, then return null.
+        return ((jaxpURLString.length() == 0) ? null : jaxpURLString);
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/build.xml?view=diff&rev=482433&r1=482432&r2=482433
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/build.xml (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/build.xml Mon Dec  4 16:47:02
2006
@@ -55,6 +55,29 @@
  
   <target name="junitcomponents" 
           description="Build Derby JUnit test components">
+    <!-- We only compile junit/XML.java against JDK 1.4 because  -->
+    <!-- it relies on a JAXP class that is part of 1.4 but is    -->
+    <!-- not part of 1.3.                                        -->
+    <javac
+      source="1.4"
+      target="1.4"
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="${debug}"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.testing.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${java14compile.classpath}"/>
+        <pathelement path="${junit}"/>
+        <pathelement path="${xml-apis}"/>
+      </classpath>
+	  <include name="${derby.testing.junit.dir}/XML.java"/>
+    </javac>
     <javac
       source="1.3"
       target="1.3"
@@ -73,6 +96,7 @@
         <pathelement path="${junit}"/>
       </classpath>
       <include name="${derby.testing.junit.dir}/**/*.java"/>
+      <exclude name="${derby.testing.junit.dir}/XML.java"/>
     </javac>
   </target>
 



Mime
View raw message