|
8 | 8 |
|
9 | 9 | import java.io.File; |
10 | 10 |
|
11 | | -public class ReporterThatCreatesAnApprovalScript implements ApprovalFailureReporter { |
12 | | - private static String fileName = "approval_script"; |
13 | | - private static File scriptFile = null; |
14 | | - static { |
15 | | - initializeFile(); |
16 | | - |
17 | | - } |
18 | | - |
19 | | - private static void initializeFile() { |
20 | | - if (scriptFile != null) {return;} |
21 | | - if (SystemUtils.isWindowsEnvironment()) { |
22 | | - initializeWindows(); |
23 | | - } else { |
24 | | - initializeLinux(); |
25 | | - } |
26 | | - SimpleLogger.event("Created approval script:\n" + scriptFile.getAbsolutePath()); |
27 | | - } |
28 | | - |
29 | | - private static void initializeLinux() { |
30 | | - scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "/" + fileName + ".sh"); |
31 | | - FileUtils.createIfNeeded(scriptFile.getAbsolutePath()); |
32 | | - FileUtils.writeFile(scriptFile, "#!/bin/bash\n"); |
33 | | - scriptFile.setExecutable(true); |
34 | | - } |
35 | | - |
36 | | - private static void initializeWindows() { |
37 | | - scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "\\" + fileName + ".bat"); |
38 | | - FileUtils.createIfNeeded(scriptFile.getAbsolutePath()); |
39 | | - FileUtils.writeFile(scriptFile, ""); |
| 11 | +public class ReporterThatCreatesAnApprovalScript implements ApprovalFailureReporter |
| 12 | +{ |
| 13 | + private static String fileName = "approval_script"; |
| 14 | + private static File scriptFile = null; |
| 15 | + static |
| 16 | + { |
| 17 | + initializeFile(); |
| 18 | + } |
| 19 | + private static void initializeFile() |
| 20 | + { |
| 21 | + if (scriptFile != null) |
| 22 | + { return; } |
| 23 | + if (SystemUtils.isWindowsEnvironment()) |
| 24 | + { |
| 25 | + initializeWindows(); |
40 | 26 | } |
41 | | - |
42 | | - @Override |
43 | | - public boolean report(String received, String approved) { |
44 | | - String commandLine = ClipboardReporter.getCommandLine(received, approved); |
45 | | - FileUtils.appendToFile(scriptFile, commandLine + "\n"); |
46 | | - return true; |
| 27 | + else |
| 28 | + { |
| 29 | + initializeLinux(); |
47 | 30 | } |
| 31 | + SimpleLogger.event("Created approval script:\n" + scriptFile.getAbsolutePath()); |
| 32 | + } |
| 33 | + private static void initializeLinux() |
| 34 | + { |
| 35 | + scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "/" + fileName + ".sh"); |
| 36 | + FileUtils.createIfNeeded(scriptFile.getAbsolutePath()); |
| 37 | + FileUtils.writeFile(scriptFile, "#!/bin/bash\n"); |
| 38 | + scriptFile.setExecutable(true); |
| 39 | + } |
| 40 | + private static void initializeWindows() |
| 41 | + { |
| 42 | + scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "\\" + fileName + ".bat"); |
| 43 | + FileUtils.createIfNeeded(scriptFile.getAbsolutePath()); |
| 44 | + FileUtils.writeFile(scriptFile, ""); |
| 45 | + } |
| 46 | + @Override |
| 47 | + public boolean report(String received, String approved) |
| 48 | + { |
| 49 | + String commandLine = ClipboardReporter.getCommandLine(received, approved); |
| 50 | + FileUtils.appendToFile(scriptFile, commandLine + "\n"); |
| 51 | + return true; |
| 52 | + } |
48 | 53 | } |
0 commit comments