You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Pierre De Rop <pi...@gmail.com> on 2010/02/24 08:54:00 UTC

pax exam and temporary files ...

Hello everyone,

I am facing a little issue with pax-exams and Junit4TestRunner test classes,
and I would like to know if someone else got caught by the same problem:
When I launch a "mvn test" command, and once the test is done,  some
temporary files are left in* /tmp/tb/ *directory ... So, the temp file
system grows ineluctably and I would like to avoid that problem.

In order to work around, I have found the two following solutions:

1) make a base class which is inherited by all unit tests: this base class
just ensures that the bundle's location file is cleaned once the jvm exits:

public class Base {
    /**
     * Always cleanup our bundle's location file
     */
    @After
    public void tearDown(BundleContext context) {
        try {
            File f = new File(new
URL(context.getBundle().getLocation()).getPath());
            f.deleteOnExit();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}


... And then, my unit tests just inherit the Base class like this:


@RunWith(JUnit4TestRunner.class)
public class MyTest extends Base
{
    @Configuration
    public static Option[] configuration()
    {
        return options(
            provision(

mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version("4.1.0"),
                // ..


2) the other consists in just setting the* java.io.tmpdir* parameter to my
target's project like this:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.4.3</version>
        <configuration>
          <systemProperties>
            <property>
              <name>java.io.tmpdir</name>
              <value>${basedir}/target/temp</value>
            </property>
          </systemProperties>
        </configuration>
      </plugin>

-> So, the tb directory is stored in my maven project's target/temp
directory, which is cleaned when I type "mvn clean"
The drawbak of this second solution is that the felix fwk, as well as
pax-exams bundles are always downloaded each time I type "mvn clean test"
...


So, I will use the solution 1) for now, but I would like to know if there is
a better/simpler way to resolve this problem ?
Is there a pax-exams configuration property which allows to ensure that the
/tmp/tb/*.bin temp files are cleaned after jvm exits ?


thanks in advance;
/pierre