You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Omair-Inam Abdul-Matin <oi...@cs.uwaterloo.ca> on 2004/07/10 19:08:21 UTC

Re: Reactor: tests failing (working dir set to master proj dir not child proj dir)

I've tried the following and my unit tests still fail because the 
working directory seems to be the directory of the master project.

Does anyone have any ideas how I might go about solving this problem?  I 
want to run each subproject but have the working directory be the 
directory of the subproject *not* the directory of the master project.

Omair

     <goal name="printenv-test-all">
     	<echo>----- MASTER PROJECT ENV -----</echo>
     	<attainGoal name="printenv"/>
     	<!-- only collect the project names -->
     	<m:reactor basedir="${basedir}"
     		includes="*/project.xml"
     		goals="printenv"
     		banner="Building"
     		collectOnly="true"
     		postProcessing="true"
     		ignoreFailures="false"
     	/>

     	
     	<j:forEach var="reactorProject" items="${reactorProjects}">
		<j:set var="subProjectDir"
		       value="${basedir}/${reactorProject.artifactId}"/>
		<echo>${subProjectDir}</echo>		
       		<m:maven
       			basedir="${subProjectDir}"
       			descriptor="${subProjectDir}/project.xml"
       			goals="clean,jar:install"
       			ignoreFailures="false"
       		/>      			
     	</j:forEach>
     	
     </goal>



Omair-Inam Abdul-Matin wrote:
> Dion Gillard wrote:
> 
>> Set the user.home system property in the child subproject?
>>
>> On Fri, 09 Jul 2004 23:38:58 -0400, Omair-Inam Abdul-Matin
>> <oi...@cs.uwaterloo.ca> wrote:
>>
>>> I'm using JUnit to run some regression tests that need to read in
>>> configuration and data files.  For this it is necessary that the working
>>> directory be the same as the project directory.  Recently the project
>>> was subdivided into a master project and child subprojects.  Now when I
>>> try to run unit tests by invoking the master build target, the tests
>>> fail because apparently the working directory is the directory of the
>>> master project not the current child project.  I believe this topic has
>>> been brought up in a previous post but I was not able to find the
>>> solution to the problem.
>>>
>>> Can someone please nudge me in the correction direction?
>>>
>>> Omair
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>
>>
>>
> I don't think that'll work. I believe the solution is something along 
> the lines of the following:
> 
> <goal name="printenv-test-all">
>         <echo>----- MASTER PROJECT ENV -----</echo>
>         <attainGoal name="printenv"/>
>         <!-- only collect the project names -->
>         <m:reactor basedir="${basedir}"
>             includes="*/project.xml"
>             goals="printenv"
>             banner="Building"
>             collectOnly="false"
>             postProcessing="true"
>             ignoreFailures="false"
>         />
> 
>        
>         <j:forEach var="reactorProject" items="${reactorProjects}">
>     <!-- set the basedir value here for each project and then
>              attain the desired goal -->
>          
>     </j:forEach>
>        
>     </goal>
> 
> I was surprised why the reactor doc doesn't mention the fact that any 
> instance var of the Project class can be accessed (e.g. 
> ${reactorProject.groupId})  I had to actually go thru the source and 
> then find the instance vars.
> 
> 
> Omair


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Re: Reactor: tests failing (working dir set to master proj dir not child proj dir)

Posted by Brett Porter <br...@gmail.com>.
this isn't a generic method for getting maven properties, but basedir is special

On Sat, 10 Jul 2004 18:43:25 -0400, Omair-Inam Abdul-Matin
<oi...@cs.uwaterloo.ca> wrote:
> Jason van Zyl wrote:
> > On Sat, 2004-07-10 at 13:08, Omair-Inam Abdul-Matin wrote:
> >
> >>I've tried the following and my unit tests still fail because the
> >>working directory seems to be the directory of the master project.
> >
> >
> > There is no way to reliably set the working directory in Java. To make
> > your tests reactor-able you must reference resources using the "basedir"
> > system property that is made available in tests by the junit plugin.
> >
> > So the general pattern is:
> >
> > public class MyTest extends TestCase
> > {
> >   private String basedir;
> >
> >   protected void setUp()
> >   {
> >       basedir = System.getProperty( "basedir" );
> >   }
> >
> >   public void testThatUsesAResourceFromTheFileSystem()
> >   {
> >       File resource = new File( basedir, "src/test/resources/MyTestResource.txt" );
> >
> >       // do you stuff with the file system resource.
> >   }
> > }
> >
> >
> > 
> Thanks... that's exactly what I was looking for..  I didn't know how to
> fetch maven-defined properties in a java file.
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Reactor: tests failing (working dir set to master proj dir not child proj dir)

Posted by Omair-Inam Abdul-Matin <oi...@cs.uwaterloo.ca>.
Jason van Zyl wrote:
> On Sat, 2004-07-10 at 13:08, Omair-Inam Abdul-Matin wrote:
> 
>>I've tried the following and my unit tests still fail because the 
>>working directory seems to be the directory of the master project.
> 
> 
> There is no way to reliably set the working directory in Java. To make
> your tests reactor-able you must reference resources using the "basedir"
> system property that is made available in tests by the junit plugin.
> 
> So the general pattern is:
> 
> public class MyTest extends TestCase
> {
>   private String basedir;
> 
>   protected void setUp()
>   {
>       basedir = System.getProperty( "basedir" );
>   }
> 
>   public void testThatUsesAResourceFromTheFileSystem()
>   {
>       File resource = new File( basedir, "src/test/resources/MyTestResource.txt" );
> 
>       // do you stuff with the file system resource.
>   }
> }
> 
> 
> 
Thanks... that's exactly what I was looking for..  I didn't know how to 
fetch maven-defined properties in a java file.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Reactor: tests failing (working dir set to master proj dir not child proj dir)

Posted by Jason van Zyl <jv...@maven.org>.
On Sat, 2004-07-10 at 13:08, Omair-Inam Abdul-Matin wrote:
> I've tried the following and my unit tests still fail because the 
> working directory seems to be the directory of the master project.

There is no way to reliably set the working directory in Java. To make
your tests reactor-able you must reference resources using the "basedir"
system property that is made available in tests by the junit plugin.

So the general pattern is:

public class MyTest extends TestCase
{
  private String basedir;

  protected void setUp()
  {
      basedir = System.getProperty( "basedir" );
  }

  public void testThatUsesAResourceFromTheFileSystem()
  {
      File resource = new File( basedir, "src/test/resources/MyTestResource.txt" );

      // do you stuff with the file system resource.
  }
}



-- 
jvz.

Jason van Zyl
jason@maven.org
http://maven.apache.org

happiness is like a butterfly: the more you chase it, the more it will
elude you, but if you turn your attention to other things, it will come
and sit softly on your shoulder ...

 -- Thoreau 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org