01: /*
02: * Author: Chris Seguin
03: *
04: * This software has been developed under the copyleft
05: * rules of the GNU General Public License. Please
06: * consult the GNU General Public License for more
07: * details about use and distribution of this software.
08: */
09: package org.acm.seguin.refactor.undo;
10:
11: import java.io.File;
12: import org.acm.seguin.io.DirectoryTreeTraversal;
13:
14: /**
15: * Clase responsible for cleaning up all the undo files that are left on the
16: * hard disk.
17: *
18: *@author Chris Seguin
19: */
20: public class UndoCleaner extends DirectoryTreeTraversal {
21: /**
22: * Constructor for the UndoCleaner object
23: *
24: *@param dir Description of Parameter
25: */
26: public UndoCleaner(String dir) {
27: super (dir);
28:
29: UndoStack.get().delete();
30: }
31:
32: /**
33: * Determines if this file should be handled by this traversal
34: *
35: *@param currentFile the current file
36: *@return true if the file should be handled
37: */
38: protected boolean isTarget(File currentFile) {
39: String filename = currentFile.getName();
40: int index = filename.indexOf(".java.");
41: if (index < 0) {
42: return false;
43: }
44:
45: try {
46: int value = Integer.parseInt(filename.substring(index + 6));
47: return true;
48: } catch (NumberFormatException nfe) {
49: return false;
50: }
51: }
52:
53: /**
54: * Visits the current file
55: *
56: *@param currentFile the current file
57: */
58: protected void visit(File currentFile) {
59: currentFile.delete();
60: }
61:
62: /**
63: * The main program for the UndoCleaner class
64: *
65: *@param args The command line arguments
66: */
67: public static void main(String[] args) {
68: if (args.length > 0) {
69: (new UndoCleaner(args[0])).run();
70: } else {
71: String dir = System.getProperty("user.dir");
72: (new UndoCleaner(dir)).run();
73: }
74: }
75: }
|