1 package hudson.scm; 2 3 import hudson.model.AbstractBuild; 4 import hudson.model.User; 5 import hudson.scm.CVSChangeLogSet.CVSChangeLog; 6 import hudson.util.IOException2; 7 import org.apache.commons.digester.Digester; 8 import org.xml.sax.SAXException ; 9 10 import java.io.IOException ; 11 import java.util.ArrayList ; 12 import java.util.Collections ; 13 import java.util.Iterator ; 14 import java.util.List ; 15 import java.util.Collection ; 16 import java.util.AbstractList ; 17 18 22 public final class CVSChangeLogSet extends ChangeLogSet<CVSChangeLog> { 23 private List <CVSChangeLog> logs; 24 25 public CVSChangeLogSet(AbstractBuild<?,?> build, List <CVSChangeLog> logs) { 26 super(build); 27 this.logs = Collections.unmodifiableList(logs); 28 for (CVSChangeLog log : logs) 29 log.setParent(this); 30 } 31 32 35 public List <CVSChangeLog> getLogs() { 36 return logs; 37 } 38 39 @Override 40 public boolean isEmptySet() { 41 return logs.isEmpty(); 42 } 43 44 45 public Iterator <CVSChangeLog> iterator() { 46 return logs.iterator(); 47 } 48 49 public static CVSChangeLogSet parse( AbstractBuild build, java.io.File f ) throws IOException , SAXException { 50 Digester digester = new Digester(); 51 ArrayList <CVSChangeLog> r = new ArrayList <CVSChangeLog>(); 52 digester.push(r); 53 54 digester.addObjectCreate("*/entry",CVSChangeLog.class); 55 digester.addBeanPropertySetter("*/entry/date"); 56 digester.addBeanPropertySetter("*/entry/time"); 57 digester.addBeanPropertySetter("*/entry/author","user"); 58 digester.addBeanPropertySetter("*/entry/msg"); 59 digester.addSetNext("*/entry","add"); 60 61 digester.addObjectCreate("*/entry/file",File.class); 62 digester.addBeanPropertySetter("*/entry/file/name"); 63 digester.addBeanPropertySetter("*/entry/file/revision"); 64 digester.addBeanPropertySetter("*/entry/file/prevrevision"); 65 digester.addCallMethod("*/entry/file/dead","setDead"); 66 digester.addSetNext("*/entry/file","addFile"); 67 68 try { 69 digester.parse(f); 70 } catch (IOException e) { 71 throw new IOException2("Failed to parse "+f,e); 72 } catch (SAXException e) { 73 throw new IOException2("Failed to parse "+f,e); 74 } 75 76 for(int i=r.size()-1; i>=0; i--) { 78 CVSChangeLog log = r.get(i); 79 boolean merged = false; 80 for(int j=0;j<i;j++) { 81 CVSChangeLog c = r.get(j); 82 if(c.canBeMergedWith(log)) { 83 c.merge(log); 84 merged = true; 85 break; 86 } 87 } 88 if(merged) 89 r.remove(log); 90 } 91 92 return new CVSChangeLogSet(build,r); 93 } 94 95 98 public static class CVSChangeLog extends ChangeLogSet.Entry { 99 private String date; 100 private String time; 101 private User author; 102 private String msg; 103 private final List <File> files = new ArrayList <File>(); 104 105 109 public boolean canBeMergedWith(CVSChangeLog that) { 110 if(!this.date.equals(that.date)) 111 return false; 112 if(!this.time.equals(that.time)) return false; 114 if(this.author==null || that.author==null || !this.author.equals(that.author)) 115 return false; 116 if(!this.msg.equals(that.msg)) 117 return false; 118 return true; 119 } 120 121 public void merge(CVSChangeLog that) { 122 this.files.addAll(that.files); 123 } 124 125 public String getDate() { 126 return date; 127 } 128 129 public void setDate(String date) { 130 this.date = date; 131 } 132 133 public String getTime() { 134 return time; 135 } 136 137 public void setTime(String time) { 138 this.time = time; 139 } 140 141 public User getAuthor() { 142 return author; 143 } 144 145 public Collection <String > getAffectedPaths() { 146 return new AbstractList <String >() { 147 public String get(int index) { 148 return files.get(index).getName(); 149 } 150 151 public int size() { 152 return files.size(); 153 } 154 }; 155 } 156 157 public void setUser(String author) { 158 this.author = User.get(author); 159 } 160 161 public String getUser() { return author.getDisplayName(); 163 } 164 165 public String getMsg() { 166 return msg; 167 } 168 169 public void setMsg(String msg) { 170 this.msg = msg; 171 } 172 173 public void addFile( File f ) { 174 files.add(f); 175 } 176 177 public List <File> getFiles() { 178 return files; 179 } 180 } 181 182 public static class File { 183 private String name; 184 private String revision; 185 private String prevrevision; 186 private boolean dead; 187 188 public String getName() { 189 return name; 190 } 191 192 public void setName(String name) { 193 this.name = name; 194 } 195 196 public String getRevision() { 197 return revision; 198 } 199 200 public void setRevision(String revision) { 201 this.revision = revision; 202 } 203 204 public String getPrevrevision() { 205 return prevrevision; 206 } 207 208 public void setPrevrevision(String prevrevision) { 209 this.prevrevision = prevrevision; 210 } 211 212 public boolean isDead() { 213 return dead; 214 } 215 216 public void setDead() { 217 this.dead = true; 218 } 219 220 public EditType getEditType() { 221 if(dead) 223 return EditType.DELETE; 224 if(revision.equals("1.1")) 225 return EditType.ADD; 226 return EditType.EDIT; 227 } 228 } 229 230 } 231 | Popular Tags |