[jboss-cvs] JBossAS SVN: r80801 - in projects/jboss-aspects/trunk/remoting: src/test/java/org/jboss/aspects/remoting/test/common and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 11 11:20:26 EST 2008


Author: ALRubinger
Date: 2008-11-11 11:20:26 -0500 (Tue, 11 Nov 2008)
New Revision: 80801

Modified:
   projects/jboss-aspects/trunk/remoting/pom.xml
   projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/common/Fork.java
Log:
[JBASPECT-30] Apply a Maven workaround to invalid CP in Surefire when running from Aggregator

Modified: projects/jboss-aspects/trunk/remoting/pom.xml
===================================================================
--- projects/jboss-aspects/trunk/remoting/pom.xml	2008-11-11 16:11:30 UTC (rev 80800)
+++ projects/jboss-aspects/trunk/remoting/pom.xml	2008-11-11 16:20:26 UTC (rev 80801)
@@ -25,6 +25,23 @@
     <testSourceDirectory>src/test/java</testSourceDirectory>
 
     <plugins>
+    
+      <!-- Build a CP File for use in tests -->     
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>build-cp-file</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>build-classpath</goal>
+            </goals>
+            <configuration>
+              <outputFile>target/cp.txt</outputFile>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
 
       <!-- Surefire (Tests) Plugin -->
 

Modified: projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/common/Fork.java
===================================================================
--- projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/common/Fork.java	2008-11-11 16:11:30 UTC (rev 80800)
+++ projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/common/Fork.java	2008-11-11 16:20:26 UTC (rev 80801)
@@ -21,7 +21,9 @@
  */
 package org.jboss.aspects.remoting.test.common;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -37,6 +39,17 @@
 {
    private static final Logger log = Logger.getLogger(Fork.class);
    
+   private static final String LOCATION_BASEDIR = System.getProperty("basedir");
+   
+   private static final String LOCATION_TARGET = Fork.LOCATION_BASEDIR + File.separator + "target";
+   
+   private static final String LOCATION_TARGET_MAIN = Fork.LOCATION_TARGET + File.separator + "classes";
+   
+   private static final String LOCATION_TARGET_TESTS = Fork.LOCATION_TARGET + File.separator + "tests-classes";
+   
+   private static final String FILENAME_DEPENDENCY_CP = Fork.LOCATION_TARGET + File.separator
+   + "cp.txt";
+   
    private Process p;
    private Thread errorStreamReader;
    private Thread inputStreamReader;
@@ -49,12 +62,49 @@
    public Fork(String className) throws IOException
    {
       String java = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
-      // make sure we can run under surefire 
-      String classPath = System.getProperty("surefire.test.class.path");
-      if(classPath == null)
-         classPath = System.getProperty("java.class.path");
-      log.debug("classPath = " + classPath);
-      String cmdarray[] = { java, "-cp", classPath, className };
+      
+      String depCp = null;
+      
+      // Get the contents of the dependency classpath file
+      String dependencyClasspathFilename = Fork.FILENAME_DEPENDENCY_CP;
+      File dependencyClasspath = new File(dependencyClasspathFilename);
+      if (dependencyClasspath.exists())
+      {
+         BufferedReader reader = new BufferedReader(new FileReader(dependencyClasspath));
+         StringBuffer contents = new StringBuffer();
+         String line = null;
+         while ((line = reader.readLine()) != null)
+         {
+            contents.append(line);
+         }
+         
+         // Append "target" binaries
+         contents.append(File.pathSeparatorChar);
+         contents.append(Fork.LOCATION_TARGET_TESTS);
+         contents.append(File.pathSeparatorChar);
+         contents.append(Fork.LOCATION_TARGET_MAIN);
+         contents.append(File.separatorChar);
+         
+         depCp = contents.toString().trim();
+      }
+      // No dependency CP file found
+      else
+      {
+         log.debug("Could not find dependency CP at: " + dependencyClasspathFilename);
+      }
+
+      // If there was no dependency CP file, try to get from system properties
+      if (depCp == null)
+      {
+         depCp = System.getProperty("surefire.test.class.path");
+         if (depCp == null)
+            depCp = System.getProperty("java.class.path");
+         log.debug("classPath = " + depCp);
+      }
+      
+      String cmdarray[] =
+      {java, "-cp", depCp, className};
+      log.debug("Forking: " + cmdarray);
       p = Runtime.getRuntime().exec(cmdarray);
       
       final InputStream in = p.getInputStream();




More information about the jboss-cvs-commits mailing list