[jboss-cvs] JBossAS SVN: r62669 - in projects/microcontainer/trunk/classloader: src/main/org/jboss/classloader/spi and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 30 17:32:57 EDT 2007


Author: adrian at jboss.org
Date: 2007-04-30 17:32:57 -0400 (Mon, 30 Apr 2007)
New Revision: 62669

Removed:
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/TestThread.java
Modified:
   projects/microcontainer/trunk/classloader/.classpath
   projects/microcontainer/trunk/classloader/pom.xml
   projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/ClassLoaderPolicy.java
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/AbstractClassLoaderTest.java
   projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/delegate/test/DelegateUnitTestCase.java
Log:
Update classloader tests to use the latest jboss-test which fixes the
running the tests under a security manager.

Modified: projects/microcontainer/trunk/classloader/.classpath
===================================================================
--- projects/microcontainer/trunk/classloader/.classpath	2007-04-30 21:19:21 UTC (rev 62668)
+++ projects/microcontainer/trunk/classloader/.classpath	2007-04-30 21:32:57 UTC (rev 62669)
@@ -6,7 +6,7 @@
 	<classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA-sources.jar"/>
 	<classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA-sources.jar"/>
 	<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/jboss-test/1.0.3.GA/jboss-test-1.0.3.GA.jar" sourcepath="M2_REPO/jboss/jboss-test/1.0.3.GA/jboss-test-1.0.3.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-test/1.0.4-SNAPSHOT/jboss-test-1.0.4-SNAPSHOT.jar" sourcepath="M2_REPO/jboss/jboss-test/1.0.4-SNAPSHOT/jboss-test-1.0.4-SNAPSHOT-sources.jar"/>
 	<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
 	<classpathentry kind="var" path="M2_REPO/jboss/profiler/jvmti/jboss-profiler-jvmti/1.0.0.CR5/jboss-profiler-jvmti-1.0.0.CR5.jar"/>
 	<classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA-sources.jar"/>

Modified: projects/microcontainer/trunk/classloader/pom.xml
===================================================================
--- projects/microcontainer/trunk/classloader/pom.xml	2007-04-30 21:19:21 UTC (rev 62668)
+++ projects/microcontainer/trunk/classloader/pom.xml	2007-04-30 21:32:57 UTC (rev 62669)
@@ -22,7 +22,7 @@
     <dependency>
       <groupId>jboss</groupId>
       <artifactId>jboss-test</artifactId>
-      <version>1.0.3.GA</version>
+      <version>1.0.4-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
     <dependency>

Modified: projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/ClassLoaderPolicy.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/ClassLoaderPolicy.java	2007-04-30 21:19:21 UTC (rev 62668)
+++ projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/ClassLoaderPolicy.java	2007-04-30 21:32:57 UTC (rev 62669)
@@ -24,6 +24,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.ProtectionDomain;
 import java.util.Arrays;
 import java.util.Collections;
@@ -192,7 +194,7 @@
    {
       JDKChecker checker = JDKCheckerFactory.getChecker();
       if (checker.isJDKRequest(name))
-         return ClassLoader.getSystemClassLoader();
+         return getSystemClassLoader();
       return null;
    }
 
@@ -207,4 +209,32 @@
       if (importAll)
          builder.append(" <IMPORT-ALL>");
    }
+
+   /**
+    * Get the system classloader
+    * 
+    * @return the classloader
+    */
+   private ClassLoader getSystemClassLoader()
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if (sm == null)
+         return ClassLoader.getSystemClassLoader();
+      
+      return AccessController.doPrivileged(GetSystemClassLoader.INSTANCE);
+   }
+   
+   /**
+    * GetSystemClassLoader.
+    */
+   private static class GetSystemClassLoader implements PrivilegedAction<ClassLoader>
+   {
+      private static GetSystemClassLoader INSTANCE = new GetSystemClassLoader();
+      
+      public ClassLoader run()
+      {
+         return ClassLoader.getSystemClassLoader();
+      }
+   }
+   
 }

Modified: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/AbstractClassLoaderTest.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/AbstractClassLoaderTest.java	2007-04-30 21:19:21 UTC (rev 62668)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/AbstractClassLoaderTest.java	2007-04-30 21:32:57 UTC (rev 62669)
@@ -23,8 +23,6 @@
 
 import java.security.ProtectionDomain;
 
-import junit.framework.AssertionFailedError;
-
 import org.jboss.classloader.plugins.ClassLoaderUtils;
 import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
 import org.jboss.classloader.spi.ClassLoaderDomain;
@@ -43,23 +41,6 @@
  */
 public abstract class AbstractClassLoaderTest extends AbstractTestCaseWithSetup
 {
-   /**
-    * Raise an assertion failed error for an error
-    * 
-    * TODO move to AbstractTestCase
-    * @param reason the reason
-    * @param cause the cause
-    */
-   protected void failure(String reason, Throwable cause)
-   {
-      getLog().error(reason, cause);
-      if (cause instanceof AssertionFailedError)
-         throw (AssertionFailedError) cause;
-      Error error = new AssertionFailedError(reason);
-      error.initCause(cause);
-      throw error;
-   }
-
    public static AbstractTestDelegate getDelegate(Class<?> clazz)
    {
       AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
@@ -79,6 +60,11 @@
       super(name);
    }
    
+   // TODO the suspension of the security manager
+   // does not play well with multi-threaded tests.
+   // We really need to give this class access to getClassLoader()
+   // and getProtectionDomain() which means figuring how Scott's
+   // properties file works in the Security policy plugin
    public ProtectionDomain getProtectionDomain(String name)
    {
       SecurityManager sm = suspendSecurity();

Deleted: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/TestThread.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/TestThread.java	2007-04-30 21:19:21 UTC (rev 62668)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/TestThread.java	2007-04-30 21:32:57 UTC (rev 62669)
@@ -1,73 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.classloader;
-
-import java.lang.Thread.UncaughtExceptionHandler;
-
-import junit.framework.AssertionFailedError;
-
-import org.jboss.logging.Logger;
-
-/**
- * TestThread.
- * 
- * TODO move to the test project
- * 
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class TestThread extends Thread implements UncaughtExceptionHandler
-{
-   private Logger log = Logger.getLogger(TestThread.class);
-   
-   private Throwable t;
-
-   public TestThread()
-   {
-      setUncaughtExceptionHandler(this);
-   }
-
-   public TestThread(String name)
-   {
-      super(name);
-      setUncaughtExceptionHandler(this);
-   }
-
-   public void uncaughtException(Thread t, Throwable e)
-   {
-      log.error("Error in thread " + t, e);
-      this.t = e;
-   }
-   
-   public void doJoin() throws InterruptedException
-   {
-      super.join();
-      if (t != null)
-      {
-         if (t instanceof AssertionFailedError)
-            throw (AssertionFailedError) t;
-         AssertionFailedError e = new AssertionFailedError("Error in thread" + t);
-         e.initCause(t);
-         throw e;
-      }
-   }
-}

Modified: projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/delegate/test/DelegateUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/delegate/test/DelegateUnitTestCase.java	2007-04-30 21:19:21 UTC (rev 62668)
+++ projects/microcontainer/trunk/classloader/src/tests/org/jboss/test/classloader/delegate/test/DelegateUnitTestCase.java	2007-04-30 21:32:57 UTC (rev 62669)
@@ -35,7 +35,6 @@
 import org.jboss.classloader.spi.DelegateLoader;
 import org.jboss.classloader.spi.filter.FilteredDelegateLoader;
 import org.jboss.test.classloader.AbstractClassLoaderTest;
-import org.jboss.test.classloader.TestThread;
 import org.jboss.test.classloader.delegate.support.a.TestA1;
 import org.jboss.test.classloader.delegate.support.a.TestADelegateClassLoaderDomain;
 import org.jboss.test.classloader.delegate.support.a.TestAbstractFactory;
@@ -43,6 +42,7 @@
 import org.jboss.test.classloader.delegate.support.b.TestB1;
 import org.jboss.test.classloader.delegate.support.b.TestFactoryImplementation;
 import org.jboss.test.classloader.support.MockClassLoaderPolicy;
+import org.jboss.test.thread.TestThread;
 
 /**
  * DelegateUnitTestCase




More information about the jboss-cvs-commits mailing list