| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 12 |
Complexity Density: 0.6 |
|
| 17 |
|
public class FileFactory |
| 18 |
|
{ |
| 19 |
|
private static Map mockFiles; |
| 20 |
|
private static transient final Category log = Category.getInstance(FileFactory.class); |
| 21 |
|
|
| 22 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
| 23 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 31 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 39 |
0
|
public static void flushMockFiles()... |
| 40 |
|
{ |
| 41 |
0
|
mockFiles = null; |
| 42 |
|
} |
| 43 |
|
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
| 44 |
0
|
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 |
|
} |