You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2008/03/13 20:42:41 UTC

svn commit: r636851 - /maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java

Author: brianf
Date: Thu Mar 13 12:42:40 2008
New Revision: 636851

URL: http://svn.apache.org/viewvc?rev=636851&view=rev
Log:
MNG-3460: fixed unit test to not assume default local repo

Modified:
    maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java

Modified: maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java?rev=636851&r1=636850&r2=636851&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java (original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java Thu Mar 13 12:42:40 2008
@@ -19,6 +19,12 @@
  * under the License.
  */
 
+import java.io.File;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
 import org.apache.maven.model.Activation;
 import org.apache.maven.model.ActivationOS;
 import org.apache.maven.model.ActivationProperty;
@@ -26,8 +32,7 @@
 import org.apache.maven.profiles.activation.ProfileActivationException;
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.PlexusTestCase;
-
-import java.util.List;
+import org.codehaus.plexus.util.StringUtils;
 
 public class DefaultProfileManagerTest
     extends PlexusTestCase
@@ -246,8 +251,20 @@
 
         org.apache.maven.model.ActivationFile activationFile = new org.apache.maven.model.ActivationFile();
 
-        // Assume that junit exists
-        activationFile.setExists( "${user.home}/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar" );
+        // convert the class into the path form of the classpath
+        String classPathForm = "/" + TestCase.class.getName().replace( '.', '/' ) + ".class";
+        // get the location to the class and convert to a string
+        URL url = this.getClass().getResource( classPathForm );
+        
+        //take only the left part
+        String[] parts = url.getPath().split( "!" );
+        
+        //remove file from the beginning.
+        String path = StringUtils.stripStart( parts[0],"file://" );
+        
+        path = new File(path).getAbsolutePath();
+        // Assume that junit exists in the local repo
+        activationFile.setExists( path );
 
         fileActivation.setFile( activationFile );