Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
20   76   12   5
14   57   0.6   4
4     3  
1    
 
 
  FileFactory       Line # 17 20 12 0% 0.0
 
No Tests
 
1    /**
2    * Created by IntelliJ IDEA.
3    * User: Edwin
4    * Date: Nov 29, 2002
5    * Time: 1:25:34 PM
6    * To change this template use Options | File Templates.
7    */
8    package com.atlassian.core.util;
9   
10    import alt.java.io.File;
11    import alt.java.io.FileImpl;
12    import org.apache.log4j.Category;
13   
14    import java.util.HashMap;
15    import java.util.Map;
16   
 
17    public class FileFactory
18    {
19    private static Map mockFiles;
20    private static transient final Category log = Category.getInstance(FileFactory.class);
21   
22   
 
23  0 toggle public static File getFile(String absoluteFilename)
24    {
25  0 if (mockFiles == null || mockFiles.get(absoluteFilename) == null)
26  0 return new FileImpl(absoluteFilename);
27    else
28  0 return (File) mockFiles.get(absoluteFilename);
29    }
30   
 
31  0 toggle public static void addMockFile(String filename, File file)
32    {
33  0 if (mockFiles == null)
34  0 mockFiles = new HashMap();
35   
36  0 mockFiles.put(filename, file);
37    }
38   
 
39  0 toggle public static void flushMockFiles()
40    {
41  0 mockFiles = null;
42    }
43   
 
44  0 toggle public static void removeDirectory(File directory)
45    {
46  0 String[] list = directory.list();
47   
48  0 if (list == null)
49    {
50  0 list = new String[0];
51    }
52   
53  0 for (int i = 0; i < list.length; i++)
54    {
55  0 String filename = list[i];
56  0 File f = FileFactory.getFile(directory.getAbsolutePath() + System.getProperty("file.separator") + filename);
57  0 if (f.isDirectory())
58    {
59  0 removeDirectory(f);
60    }
61    else
62    {
63  0 log.debug("Deleting " + f.getAbsolutePath());
64  0 if (!f.delete())
65    {
66  0 log.warn("Unable to delete file " + f.getAbsolutePath());
67    }
68    }
69    }
70   
71  0 if (!directory.delete())
72    {
73  0 log.error("Unable to delete directory " + directory.getAbsolutePath());
74    }
75    }
76    }