/**
 *  Copyright 2006 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.geronimo.testsupport;

import java.io.File;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Provides support for tests.
 *
 * @version $Rev$ $Date$
 */
public abstract class TestSupport
    extends TestCase
{
    /**
     * The base-directory which tests should be run from.
     */
    private static final File BASEDIR;
    
    static {
        //
        // TODO: Add some special magic here to figure this out when we are running from
        //       and IDE, like IDEA or Eclipse.  user.dir/target might work... but need
        //       to validate what env each IDE has this set to.
        //
        
        String tmp = System.getProperty("basedir");
        if (tmp == null) {
            throw new Error("Missing 'basedir' property; tests need this property set to run correctly");
        }
        
        BASEDIR = new File(tmp);
    }
    
    /**
     * Instance logger which tests should use to produce tracing information.
     */
    protected Log log = LogFactory.getLog(getClass());
}

@@ -1002,338 +1002,1241 @@
    *
-/
 %0A    
-private static final File BASEDIR;%0A    %0A    static %7B%0A        //%0A        // TODO: Add some special magic here to figure this out when we are running from%0A        //       and IDE, like IDEA or Eclipse.  user.
+ * @see #getBaseDir()   This field is initialized from the return of this method on instance construction.%0A     */%0A    protected final File BASEDIR = getBaseDir();%0A%0A    /**%0A     * Instance logger which tests should use to produce tracing information.%0A     *%0A     * %3Cp%3E%0A     * Unless you have a really good reason to, do not change this field from your sub-class.%0A     * And if you do, please document why you have done so.%0A     */%0A    protected Log log = LogFactory.getLog(getClass());%0A%0A    /**%0A     * Determine the value of %3Ctt%3E$%7Bbasedir%7D%3C/tt%3E, which should be the base directory of%0A     * the module which the concreate test class is defined in.%0A     *%0A     * %3Cp%3E%0A     * If The system property %3Ctt%3Ebase
 dir
+%3C
 /t
-arget might work... but need%0A        //       to validate what env each IDE has this set to.%0A        //%0A        
+t%3E is already set, then that value is used,%0A     * otherwise we determine the value from the codesource of the containing concrete class%0A     * and set the %3Ctt%3Ebasedir%3C/tt%3E system property to that value.%0A     *%0A     * @see #BASEDIR    This field is always initialized to the value which this method returns.%0A     *%0A     * @return  The base directory of the module which contains the concreate test class.%0A     */%0A    protected final File getBaseDir() %7B%0A        File dir;%0A%0A        // If $%7Bbasedir%7D is set, then honor it
 %0A   
@@ -2300,17 +2300,17 @@
 if (tmp 
-=
+!
 = null) 
@@ -2327,110 +2327,270 @@
     
-throw new Error(%22Missing 'basedir' property; tests need this property set to run correctly%22
+dir = new File(tmp);%0A        %7D%0A        else %7B%0A            // Find the directory which this class (or really the sub-class of TestSupport) is defined in.%0A            String path = getClass().getProtectionDomain().getCodeSource().getLocation().getFile(
 );%0A
+%0A
         
 %7D%0A  
@@ -2589,27 +2589,92 @@
     
-%7D%0A
     
+// We expect the file to be in target/test-classes, so go up 2 dirs%0A
     
-%0A
         
 BASE
@@ -2669,23 +2669,19 @@
         
-BASEDIR
+dir
  = new F
@@ -2688,172 +2688,270 @@
 ile(
-tmp
+path).getParentFile().getParentFile(
 );%0A
+%0A
     
-%7D%0A
     
-%0A
     /
-**%0A     * Instance logger which tests should use to produce tracing information.%0A     */%0A    protected Log log = LogFactory.getLog(getClass());
+/ Set $%7Bbasedir%7D which is needed by logging to initialize%0A            System.setProperty(%22basedir%22, dir.getPath());%0A        %7D%0A%0A        // System.err.println(%22Base Directory: %22 + dir);%0A%0A        return dir;%0A    %7D
 %0A%7D%0A

Determine ${basedir} (if not already set) by rooting to the codebase of the containing class