@@ -0,0 +1,2715 @@
+/*%0A * Copyright 2013 Paul Merlin.%0A *%0A * Licensed  under the  Apache License,  Version 2.0  (the %22License%22);%0A * you may not use  this file  except in  compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed  under the  License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or%0A * implied.%0A *%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.qi4j.test.util;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport org.junit.rules.TestRule;%0Aimport org.junit.runner.Description;%0Aimport org.junit.runners.model.Statement;%0A%0A/**%0A * JUnit Test Rule that delete directories after the test.%0A */%0Apublic class DelTreeAfter%0A    implements TestRule%0A%7B%0A%0A    private final boolean createDirsBefore;%0A    private final File%5B%5D directories;%0A%0A    public DelTreeAfter( File... directories )%0A    %7B%0A        this( false, directories );%0A    %7D%0A%0A    public DelTreeAfter( boolean createDirsBefore, File%5B%5D directories )%0A    %7B%0A        this.createDirsBefore = createDirsBefore;%0A        this.directories = directories;%0A    %7D%0A%0A    @Override%0A    public Statement apply( final Statement base, Description description )%0A    %7B%0A        return new Statement()%0A        %7B%0A            @Override%0A            public void evaluate()%0A                throws Throwable%0A            %7B%0A                if( createDirsBefore )%0A                %7B%0A                    for( File dir : directories )%0A                    %7B%0A                        if( !dir.mkdirs() )%0A                        %7B%0A                            throw new IOException( %22Unable to create directory: %22 + dir );%0A                        %7D%0A                    %7D%0A                %7D%0A                try%0A                %7B%0A                    base.evaluate();%0A                %7D%0A                finally%0A                %7B%0A                    if( directories != null )%0A                    %7B%0A                        for( File dir : directories )%0A                        %7B%0A                            if( dir.exists() )%0A                            %7B%0A                                delTree( dir );%0A                            %7D%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A        %7D;%0A    %7D%0A%0A    private static void delTree( File dir )%0A    %7B%0A        if( dir.isDirectory() )%0A        %7B%0A            for( File file : dir.listFiles() )%0A            %7B%0A                delTree( file );%0A            %7D%0A            dir.delete();%0A        %7D%0A        else%0A        %7B%0A            dir.delete();%0A        %7D%0A    %7D%0A%0A%7D%0A

introduce DelTreeAfter JUnit @Rule