1 37 package net.sourceforge.cruisecontrol.sourcecontrols; 38 39 import java.io.File ; 40 import java.util.ArrayList ; 41 import java.util.Date ; 42 import java.util.Hashtable ; 43 import java.util.List ; 44 import java.util.Map ; 45 46 import net.sourceforge.cruisecontrol.CruiseControlException; 47 import net.sourceforge.cruisecontrol.Modification; 48 import net.sourceforge.cruisecontrol.util.ValidationHelper; 49 50 55 public class FileSystem extends FakeUserSourceControl { 56 57 private Hashtable properties = new Hashtable (); 58 private String property; 59 60 private List modifications; 61 private File folder; 62 64 67 public void setFolder(String s) { 68 folder = new File (s); 69 } 70 71 public void setProperty(String property) { 72 this.property = property; 73 } 74 75 public Map getProperties() { 76 return properties; 77 } 78 79 public void validate() throws CruiseControlException { 80 ValidationHelper.assertIsSet(folder, "folder", this.getClass()); 81 ValidationHelper.assertTrue(folder.exists(), 82 "folder " + folder.getAbsolutePath() + " must exist for FileSystem"); 83 } 84 85 92 public List getModifications(Date lastBuild, Date now) { 93 modifications = new ArrayList (); 94 95 visit(folder, lastBuild.getTime()); 96 97 return modifications; 98 } 99 100 106 private void addRevision(File revision) { 107 Modification mod = new Modification("filesystem"); 108 109 mod.userName = getUserName(); 110 111 Modification.ModifiedFile modfile = mod.createModifiedFile(revision.getName(), revision.getParent()); 112 modfile.action = "change"; 113 114 mod.modifiedTime = new Date (revision.lastModified()); 115 mod.comment = ""; 116 modifications.add(mod); 117 118 if (property != null) { 119 properties.put(property, "true"); 120 } 121 } 122 123 127 private void visit(File file, long lastBuild) { 128 if ((!file.isDirectory()) && (file.lastModified() > lastBuild)) { 129 addRevision(file); 130 } 131 132 if (file.isDirectory()) { 133 String [] children = file.list(); 134 for (int i = 0; i < children.length; i++) { 135 visit(new File (file, children[i]), lastBuild); 136 } 137 } 138 } 139 140 } | Popular Tags |