1 package net.sf.statcvs.pages.xml;
2
3
4
5
6
7
8 import java.util.Calendar;
9 import java.util.Date;
10 import java.util.GregorianCalendar;
11 import java.util.HashSet;
12 import java.util.Iterator;
13 import java.util.Set;
14
15 import net.sf.statcvs.model.Commit;
16 import net.sf.statcvs.model.Repository;
17 import net.sf.statcvs.output.ReportConfig;
18
19 import org.jdom.Element;
20
21 public class LogXml {
22 private final ReportConfig config;
23 private final Repository repository;
24
25
26
27
28 public LogXml(final ReportConfig config) {
29 this.config = config;
30 this.repository = config.getRepository();
31 }
32
33
34
35
36
37
38 public Element toFile() {
39 if (this.repository.getCommits().isEmpty()) {
40 return null;
41 }
42 final Date start = this.repository.getFirstDate();
43 final Date end = this.repository.getLastDate();
44 final Calendar calendar = new GregorianCalendar();
45 calendar.setTime(end);
46 final Calendar startCal = new GregorianCalendar();
47 startCal.setTime(start);
48 final Element commLog = new LogXmlMaker(this.config, this.repository.getCommits()).toFile();
49 commLog.setAttribute("no_of_commits", Integer.toString(this.repository.getCommits().size()));
50 commLog.setAttribute("active_developers", countActiveDevelopers());
51 return commLog;
52 }
53
54
55
56
57
58
59
60 private String countActiveDevelopers() {
61 final Set developers = new HashSet();
62 final Iterator it = this.repository.getCommits().iterator();
63 while (it.hasNext()) {
64 final Commit commit = (Commit) it.next();
65 developers.add(commit.getAuthor());
66 }
67 return Integer.toString(developers.size());
68 }
69 }