1 package net.sf.statcvs.pages.xml;
2
3 /**
4 * @author Nilendra Weerasinghe (nilendraw@gmail.com)
5 * @version $Id: LogXml.java,v 1.3 2008/04/02 11:52:02 benoitx Exp $
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 * @param config Configuration and data for the report suite
27 */
28 public LogXml(final ReportConfig config) {
29 this.config = config;
30 this.repository = config.getRepository();
31 }
32
33 /**
34 * returns jdom element which contains data extracted from the commit list of the repository
35 *
36 * @returns Element
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 * returns the number of active developers as a string
56 *
57 * @returns String
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 }