KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > scm > SubversionChangeLogSet


1 package hudson.scm;
2
3 import hudson.model.AbstractBuild;
4 import hudson.model.User;
5 import hudson.scm.SubversionChangeLogSet.LogEntry;
6
7 import java.io.IOException JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import java.util.Collections JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.List JavaDoc;
12 import java.util.Map JavaDoc;
13 import java.util.Collection JavaDoc;
14 import java.util.AbstractList JavaDoc;
15
16 /**
17  * {@link ChangeLogSet} for Subversion.
18  *
19  * @author Kohsuke Kawaguchi
20  */

21 public final class SubversionChangeLogSet extends ChangeLogSet<LogEntry> {
22     private final List JavaDoc<LogEntry> logs;
23
24     /**
25      * @GuardedBy this
26      */

27     private Map JavaDoc<String JavaDoc,Long JavaDoc> revisionMap;
28
29     /*package*/ SubversionChangeLogSet(AbstractBuild build, List JavaDoc<LogEntry> logs) {
30         super(build);
31         this.logs = Collections.unmodifiableList(logs);
32         for (LogEntry log : logs)
33             log.setParent(this);
34     }
35
36     public boolean isEmptySet() {
37         return logs.isEmpty();
38     }
39
40     public List JavaDoc<LogEntry> getLogs() {
41         return logs;
42     }
43
44
45     public Iterator JavaDoc<LogEntry> iterator() {
46         return logs.iterator();
47     }
48
49     public synchronized Map JavaDoc<String JavaDoc,Long JavaDoc> getRevisionMap() throws IOException JavaDoc {
50         if(revisionMap==null)
51             revisionMap = SubversionSCM.parseRevisionFile(build);
52         return revisionMap;
53     }
54
55     /**
56      * One commit.
57      */

58     public static class LogEntry extends ChangeLogSet.Entry {
59         private int revision;
60         private User author;
61         private String JavaDoc date;
62         private String JavaDoc msg;
63         private List JavaDoc<Path> paths = new ArrayList JavaDoc<Path>();
64
65         public int getRevision() {
66             return revision;
67         }
68
69         public void setRevision(int revision) {
70             this.revision = revision;
71         }
72
73         public User getAuthor() {
74             return author;
75         }
76
77         public Collection JavaDoc<String JavaDoc> getAffectedPaths() {
78             return new AbstractList JavaDoc<String JavaDoc>() {
79                 public String JavaDoc get(int index) {
80                     return paths.get(index).value;
81                 }
82                 public int size() {
83                     return paths.size();
84                 }
85             };
86         }
87
88         public void setUser(String JavaDoc author) {
89             this.author = User.get(author);
90         }
91
92         public String JavaDoc getUser() {// digester wants read/write property, even though it never reads. Duh.
93
return author.getDisplayName();
94         }
95
96         public String JavaDoc getDate() {
97             return date;
98         }
99
100         public void setDate(String JavaDoc date) {
101             this.date = date;
102         }
103
104         public String JavaDoc getMsg() {
105             return msg;
106         }
107
108         public void setMsg(String JavaDoc msg) {
109             this.msg = msg;
110         }
111
112         public void addPath( Path p ) {
113             paths.add(p);
114         }
115
116         public List JavaDoc<Path> getPaths() {
117             return paths;
118         }
119     }
120
121     public static class Path {
122         private char action;
123         private String JavaDoc value;
124
125         public void setAction(String JavaDoc action) {
126             this.action = action.charAt(0);
127         }
128
129         public String JavaDoc getValue() {
130             return value;
131         }
132
133         public void setValue(String JavaDoc value) {
134             this.value = value;
135         }
136
137         public EditType getEditType() {
138             if( action=='A' )
139                 return EditType.ADD;
140             if( action=='D' )
141                 return EditType.DELETE;
142             return EditType.EDIT;
143         }
144     }
145 }
146
Popular Tags