db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject svn commit: r545085 - in /db/jdo/trunk: api20/project.xml api20/test/java/javax/jdo/JDOConfigTestClassLoader.java api20/test/java/javax/jdo/JDOHelperConfigTest.java project.properties
Date Thu, 07 Jun 2007 06:46:24 GMT
Author: madams
Date: Wed Jun  6 23:46:23 2007
New Revision: 545085

URL: http://svn.apache.org/viewvc?view=rev&rev=545085
Log:
JDO-494

Modified:
    db/jdo/trunk/api20/project.xml
    db/jdo/trunk/api20/test/java/javax/jdo/JDOConfigTestClassLoader.java
    db/jdo/trunk/api20/test/java/javax/jdo/JDOHelperConfigTest.java
    db/jdo/trunk/project.properties

Modified: db/jdo/trunk/api20/project.xml
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api20/project.xml?view=diff&rev=545085&r1=545084&r2=545085
==============================================================================
--- db/jdo/trunk/api20/project.xml (original)
+++ db/jdo/trunk/api20/project.xml Wed Jun  6 23:46:23 2007
@@ -41,6 +41,11 @@
             <version>1.1</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.ant</groupId>
+            <artifactId>ant</artifactId>
+            <version>1.7.0</version>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>3.8.1</version>

Modified: db/jdo/trunk/api20/test/java/javax/jdo/JDOConfigTestClassLoader.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api20/test/java/javax/jdo/JDOConfigTestClassLoader.java?view=diff&rev=545085&r1=545084&r2=545085
==============================================================================
--- db/jdo/trunk/api20/test/java/javax/jdo/JDOConfigTestClassLoader.java (original)
+++ db/jdo/trunk/api20/test/java/javax/jdo/JDOConfigTestClassLoader.java Wed Jun  6 23:46:23
2007
@@ -1,7 +1,14 @@
 package javax.jdo;
 
+import org.apache.tools.ant.AntClassLoader;
+
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.net.MalformedURLException;
+import java.util.StringTokenizer;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
 
 /**
  * A class loader used to ensure that classpath URLs added in JUnit tests
@@ -9,17 +16,45 @@
  */
 public class JDOConfigTestClassLoader extends URLClassLoader {
 
-    public JDOConfigTestClassLoader(String partialPathToIgnore, URLClassLoader unparent)
{
+    public JDOConfigTestClassLoader(
+            String partialPathToIgnore,
+            ClassLoader unparent
+    ) {
         this(new String[]{partialPathToIgnore}, unparent);
     }
 
-    public JDOConfigTestClassLoader(String[] partialPathsToIgnore, URLClassLoader unparent)
{
+    public JDOConfigTestClassLoader(
+            String[] partialPathsToIgnore,
+            ClassLoader unparent
+    ) {
         super(new URL[]{}, null);
-        addNonTestURLs(partialPathsToIgnore == null ? new String[]{} : partialPathsToIgnore,
unparent);
+        
+        if (unparent instanceof URLClassLoader) {
+            addNonTestURLs(
+                    partialPathsToIgnore == null
+                            ? new String[]{}
+                            : partialPathsToIgnore,
+                    (URLClassLoader) unparent);
+        }
+        else if (unparent instanceof AntClassLoader) {
+            addNonTestURLs(
+                    partialPathsToIgnore == null
+                            ? new String[]{}
+                            : partialPathsToIgnore,
+                    (AntClassLoader) unparent);
+        }
+        else {
+            throw new RuntimeException(
+                    "unknown ClassLoader type: "
+                            + unparent.getClass().getName());
+        }
     }
 
     // HACK:  need to identify a better way of controlling test classpath
-    protected void addNonTestURLs(String[] partialPathsToIgnore, URLClassLoader unparent)
{
+    protected void addNonTestURLs(
+            String[] partialPathsToIgnore,
+            URLClassLoader unparent
+    ) {
         URL[] urls = unparent.getURLs();
         for (int i = 0; i < urls.length; i++) {
             URL url = urls[i];
@@ -27,6 +62,33 @@
             for (int j = 0; j < partialPathsToIgnore.length; j++) {
                 if (urlString.indexOf(partialPathsToIgnore[j]) == -1) {
                     addURL(url);
+                }
+            }
+        }
+    }
+
+    protected void addNonTestURLs(
+            String[] partialPathsToIgnore,
+            AntClassLoader unparent
+    ) {
+        List elements = new ArrayList();
+        String classpath = unparent.getClasspath();
+        StringTokenizer st = new StringTokenizer(
+                classpath, System.getProperty("path.separator"));
+        while (st.hasMoreTokens()) {
+            elements.add("file://" + st.nextToken());
+        }
+        Iterator i = elements.iterator();
+        while (i.hasNext()) {
+            String element = (String) i.next();
+            for (int j = 0; j < partialPathsToIgnore.length; j++) {
+                if (element.indexOf(partialPathsToIgnore[j]) == -1) {
+                    try {
+                        addURL(new URL(element));
+                    }
+                    catch (MalformedURLException e) {
+                        throw new RuntimeException(e);
+                    }
                 }
             }
         }

Modified: db/jdo/trunk/api20/test/java/javax/jdo/JDOHelperConfigTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api20/test/java/javax/jdo/JDOHelperConfigTest.java?view=diff&rev=545085&r1=545084&r2=545085
==============================================================================
--- db/jdo/trunk/api20/test/java/javax/jdo/JDOHelperConfigTest.java (original)
+++ db/jdo/trunk/api20/test/java/javax/jdo/JDOHelperConfigTest.java Wed Jun  6 23:46:23 2007
@@ -54,18 +54,22 @@
      */
     public void testPositive00_PMF0_GetNamedPMFProperties() throws IOException {
 
-        URLClassLoader loader = new JDOConfigTestClassLoader(
-                JDOCONFIG_CLASSPATH_PREFIX,
-                (URLClassLoader) getClass().getClassLoader());
-        ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader);
+        try {
+            URLClassLoader loader = new JDOConfigTestClassLoader(
+                    JDOCONFIG_CLASSPATH_PREFIX,
+                    getClass().getClassLoader());
+            ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader);
 
-        Map expected = prepareInitialExpectedMap("positive0.pmf0", 2);
-        String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME);
+            Map expected = prepareInitialExpectedMap("positive0.pmf0", 2);
+            String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME);
 
-        Map actual = JDOHelper.getPersistenceUnitProperties(name, loader);
+            Map actual = JDOHelper.getPersistenceUnitProperties(name, loader);
 
-        assertNotNull("No properties found", actual);
-        assertEqualProperties(expected, actual);
+            assertNotNull("No properties found", actual);
+            assertEqualProperties(expected, actual);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -76,7 +80,7 @@
     public void testPositive00_PMF1_GetNamedPMFProperties() throws IOException  {
         URLClassLoader loader = new JDOConfigTestClassLoader(
                 JDOCONFIG_CLASSPATH_PREFIX,
-                (URLClassLoader) getClass().getClassLoader());
+                getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader);
 
         Map expected = prepareInitialExpectedMap("positive0.pmf1", 2);
@@ -96,7 +100,7 @@
     public void testPositive00_PMF2_GetNamedPMFProperties() throws IOException  {
         URLClassLoader loader = new JDOConfigTestClassLoader(
                 JDOCONFIG_CLASSPATH_PREFIX,
-                (URLClassLoader) getClass().getClassLoader());
+                getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader);
 
         Map expected = prepareInitialExpectedMap("positive0.pmf2", 2);
@@ -116,7 +120,7 @@
     public void testPositive00_PMF3_GetNamedPMFProperties() throws IOException  {
         URLClassLoader loader = new JDOConfigTestClassLoader(
                 JDOCONFIG_CLASSPATH_PREFIX,
-                (URLClassLoader) getClass().getClassLoader());
+                getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader);
 
         Map expected = prepareInitialExpectedMap("positive0.pmf3", 2, 2);
@@ -136,7 +140,7 @@
     public void testPositive00_PMF4_GetNamedPMFProperties() throws IOException  {
         URLClassLoader loader = new JDOConfigTestClassLoader(
                 JDOCONFIG_CLASSPATH_PREFIX,
-                (URLClassLoader) getClass().getClassLoader());
+                getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader);
 
         Map expected = prepareInitialExpectedMap("positive0.pmf4", 0, 2);
@@ -257,11 +261,11 @@
      * Positive0-jdoconfig.xml and PU name
      * "persistence-unit-name.positive0.pmf0"
      */
-    public void testPostiive01_DuplicatePUsInDifferentConfigFilesButNotRequested() throws
IOException {
+    public void testPositive01_DuplicatePUsInDifferentConfigFilesButNotRequested() throws
IOException {
 
         URLClassLoader loader = new JDOConfigTestClassLoader(
                 JDOCONFIG_CLASSPATH_PREFIX,
-                (URLClassLoader) getClass().getClassLoader());
+                getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive1/1a", loader);
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive1/1b", loader);
 
@@ -276,7 +280,7 @@
 
         URLClassLoader loader = new JDOConfigTestClassLoader(
                 JDOCONFIG_CLASSPATH_PREFIX,
-                (URLClassLoader) getClass().getClassLoader());
+                getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive3", loader);
 
         String expected = "class.positive3.pmf0";
@@ -293,7 +297,7 @@
 
         URLClassLoader loader = new JDOConfigTestClassLoader(
                 JDOCONFIG_CLASSPATH_PREFIX,
-                (URLClassLoader) getClass().getClassLoader());
+                getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive4", loader);
 
         String expected = "class.positive4.pmf0";
@@ -310,7 +314,7 @@
 
         URLClassLoader loader = new JDOConfigTestClassLoader(
                 JDOCONFIG_CLASSPATH_PREFIX,
-                (URLClassLoader) getClass().getClassLoader());
+                getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive5", loader);
 
         String expected = "class.positive5.pmf0";
@@ -341,7 +345,7 @@
         try {
             URLClassLoader loader = new JDOConfigTestClassLoader(
                     JDOCONFIG_CLASSPATH_PREFIX,
-                    (URLClassLoader) getClass().getClassLoader());
+                    getClass().getClassLoader());
             ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative0", loader);
 
             JDOHelper.getPersistenceManagerFactory(loader);
@@ -356,7 +360,7 @@
         try {
             URLClassLoader loader = new JDOConfigTestClassLoader(
                     JDOCONFIG_CLASSPATH_PREFIX,
-                    (URLClassLoader) getClass().getClassLoader());
+                    getClass().getClassLoader());
             ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative1", loader);
 
             JDOHelper.getPersistenceManagerFactory(loader);
@@ -373,7 +377,7 @@
         try {
             URLClassLoader loader = new JDOConfigTestClassLoader(
                     JDOCONFIG_CLASSPATH_PREFIX,
-                    (URLClassLoader) getClass().getClassLoader());
+                    getClass().getClassLoader());
             ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative2", loader);
 
             JDOHelper.getPersistenceManagerFactory(loader);
@@ -390,7 +394,7 @@
         try {
             URLClassLoader loader = new JDOConfigTestClassLoader(
                     JDOCONFIG_CLASSPATH_PREFIX,
-                    (URLClassLoader) getClass().getClassLoader());
+                    getClass().getClassLoader());
             ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative3", loader);
 
             JDOHelper.getPersistenceManagerFactory(
@@ -410,7 +414,7 @@
         try {
             URLClassLoader loader = new JDOConfigTestClassLoader(
                     JDOCONFIG_CLASSPATH_PREFIX,
-                    (URLClassLoader) getClass().getClassLoader());
+                    getClass().getClassLoader());
             ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative4", loader);
 
             JDOHelper.getPersistenceManagerFactory(
@@ -430,7 +434,7 @@
         try {
             URLClassLoader loader = new JDOConfigTestClassLoader(
                     JDOCONFIG_CLASSPATH_PREFIX,
-                    (URLClassLoader) getClass().getClassLoader());
+                    getClass().getClassLoader());
             ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative5", loader);
 
             JDOHelper.getPersistenceManagerFactory(loader);
@@ -448,7 +452,7 @@
         try {
             URLClassLoader loader = new JDOConfigTestClassLoader(
                     JDOCONFIG_CLASSPATH_PREFIX,
-                    (URLClassLoader) getClass().getClassLoader());
+                    getClass().getClassLoader());
             ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative6/6a", loader);
             ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative6/6b", loader);
 
@@ -466,8 +470,7 @@
     public void testNegative07_EmptyServicesFile()
         throws IOException
     {
-        URLClassLoader loader = (URLClassLoader) getClass().getClassLoader();
-        JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader(new String[] {JDOCONFIG_CLASSPATH_PREFIX},
loader);
+        JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader(new String[] {JDOCONFIG_CLASSPATH_PREFIX},
getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative7", testLoader);
         String shouldBeNull = JDOHelper.getPMFClassNameViaServiceLookup(testLoader);
         assertNull(shouldBeNull);
@@ -476,8 +479,7 @@
     public void testNegative08_ServicesFileWithOnlyComments()
         throws IOException
     {
-        URLClassLoader loader = (URLClassLoader) getClass().getClassLoader();
-        JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader(new String[] {JDOCONFIG_CLASSPATH_PREFIX},
loader);
+        JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader(new String[] {JDOCONFIG_CLASSPATH_PREFIX},
getClass().getClassLoader());
         ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative8", testLoader);
         String shouldBeNull = JDOHelper.getPMFClassNameViaServiceLookup(testLoader);
         assertNull(shouldBeNull);

Modified: db/jdo/trunk/project.properties
URL: http://svn.apache.org/viewvc/db/jdo/trunk/project.properties?view=diff&rev=545085&r1=545084&r2=545085
==============================================================================
--- db/jdo/trunk/project.properties (original)
+++ db/jdo/trunk/project.properties Wed Jun  6 23:46:23 2007
@@ -15,7 +15,10 @@
 #   limitations under the License.
 #
 
-maven.repo.remote = http://repo1.maven.org/maven,http://maven1.glassfishwiki.org
+maven.repo.remote=\
+http://repo1.maven.org/maven,\
+http://maven1.glassfishwiki.org,\
+https://maven-repository.dev.java.net/nonav/repository
 
 # Make sure the compiled class still work with J2SE 1.3
 maven.compile.source = 1.3



Mime
View raw message