| 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 | 0 | public LogXml(final ReportConfig config) { |
| 29 | 0 | this.config = config; |
| 30 | 0 | this.repository = config.getRepository(); |
| 31 | 0 | } |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public Element toFile() { |
| 39 | 0 | if (this.repository.getCommits().isEmpty()) { |
| 40 | 0 | return null; |
| 41 | |
} |
| 42 | 0 | final Date start = this.repository.getFirstDate(); |
| 43 | 0 | final Date end = this.repository.getLastDate(); |
| 44 | 0 | final Calendar calendar = new GregorianCalendar(); |
| 45 | 0 | calendar.setTime(end); |
| 46 | 0 | final Calendar startCal = new GregorianCalendar(); |
| 47 | 0 | startCal.setTime(start); |
| 48 | 0 | final Element commLog = new LogXmlMaker(this.config, this.repository.getCommits()).toFile(); |
| 49 | 0 | commLog.setAttribute("no_of_commits", Integer.toString(this.repository.getCommits().size())); |
| 50 | 0 | commLog.setAttribute("active_developers", countActiveDevelopers()); |
| 51 | 0 | return commLog; |
| 52 | 0 | } |
| 53 | 0 | |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
private String countActiveDevelopers() { |
| 61 | 0 | final Set developers = new HashSet(); |
| 62 | 0 | final Iterator it = this.repository.getCommits().iterator(); |
| 63 | 0 | while (it.hasNext()) { |
| 64 | 0 | final Commit commit = (Commit) it.next(); |
| 65 | 0 | developers.add(commit.getAuthor()); |
| 66 | 0 | } |
| 67 | 0 | return Integer.toString(developers.size()); |
| 68 | 0 | } |
| 69 | 0 | } |