This is cool that this also works in IDEA.

Regarding this proble, this is the script that I use to fix the .classpath (from the geronimo dir): ls */*/.classpath | while read file; do cat $file | grep -v classes/ META-INF > ${file}_new; mv ${file}_new $file; done

BTW, in Eclipse System.getProperty("basedir", System.getProperty ("user.dir")) was working as by default Eclipse starts JUnit tests in the project working directory, i.e. the module root.

Thanks,
Gianny


On 21/08/2006, at 2:25 PM, Jason Dillon wrote:

This was more what I was thinking:

<snip>
protected final File getBaseDir() {
    File dir;

    // If ${basedir} is set, then honor it
    String tmp = System.getProperty("basedir");
    if (tmp != null) {
        dir = new File(tmp);
    }
    else {
// Find the directory which this class (or really the sub- class of TestSupport) is defined in. String path = getClass().getProtectionDomain().getCodeSource ().getLocation().getFile();

// We expect the file to be in target/test-classes, so go up 2 dirs
        dir = new File(path).getParentFile().getParentFile();

        // Set ${basedir} which is needed by logging to initialize
        System.setProperty("basedir", dir.getPath());
    }

    return dir;
}
</snip>

Appears to work well too, in IDEA at least, probably works fine in Eclipse too... but I've got a ton of "Cannot nest output folder..." errors that prevent me from actually checking.

--jason


On Aug 19, 2006, at 8:11 AM, Dain Sundstrom wrote:

I don't think that trick will work for an IDE, as it will only tell you which directory the IDE started in. In intellij you can use something like this:

    public static String baseDir() {
        Class myClass = null; // TestClass.class

URL classUrl = myClass.getClassLoader().getResource (myClass.getName().replace('.', '/') + ".class");
        if (classUrl == null) {
            throw new RuntimeException("Could not find TestClass");
        }

        File targetDir = null;
        try {
            URLConnection urlConnection = classUrl.openConnection();

            if (urlConnection instanceof JarURLConnection) {
JarURLConnection jarConnection = (JarURLConnection) urlConnection;
                classUrl = jarConnection.getJarFileURL();

targetDir = new File(new URI(classUrl.toString ())).getParentFile();
            } else {
File classesDir = new File(new URI (classUrl.toString())).getParentFile();
                for (char c : myClass.getName().toCharArray()) {
                    if (c == '.') {
                        classesDir = classesDir.getParentFile();
                    }
                }
            }
        } catch (Exception e) {
log.debug("Could not determine classes installation directory", e);
        }

        if (targetDir != null) {
            File moduleDir = targetDir.getParentFile();
            return moduleDir.getAbsolutePath();
        } else {
return System.getProperty("basedir", System.getProperty ("user.dir"));
        }

    }

Make sure to test this code, because I didn't :)

-dain


On Aug 18, 2006, at 4:47 PM, Jason Dillon wrote:

Ya, I will add that as soon as I can verify that it works in IDEA an Eclipse... probably sometime next week.

--jason


On Aug 18, 2006, at 4:31 PM, Gianny Damour wrote:

On 19/08/2006, at 9:15 AM, [EMAIL PROTECTED] wrote:

Author: jdillon
Date: Fri Aug 18 16:15:53 2006
New Revision: 432773

URL: http://svn.apache.org/viewvc?rev=432773&view=rev
Log:
Comments about BASEDIR and IDE magic

Modified:
geronimo/trunk/modules/geronimo-testsupport/src/main/java/ org/apache/geronimo/testsupport/TestSupport.java

Modified: geronimo/trunk/modules/geronimo-testsupport/src/main/ java/org/apache/geronimo/testsupport/TestSupport.java URL: http://svn.apache.org/viewvc/geronimo/trunk/modules/ geronimo-testsupport/src/main/java/org/apache/geronimo/ testsupport/TestSupport.java? rev=432773&r1=432772&r2=432773&view=diff ================================================================== ============ --- geronimo/trunk/modules/geronimo-testsupport/src/main/java/ org/apache/geronimo/testsupport/TestSupport.java (original) +++ geronimo/trunk/modules/geronimo-testsupport/src/main/java/ org/apache/geronimo/testsupport/TestSupport.java Fri Aug 18 16:15:53 2006
@@ -37,6 +37,12 @@
     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");

Hi Jason,

This is the trick that Dain has suggested:

private static final tmp = System.getProperty("basedir", System.getProperty("user.dir"));


Thanks,
Gianny



         if (tmp == null) {
throw new Error("Missing 'basedir' property; tests need this property set to run correctly");






Reply via email to