1 package net.sf.statcvs.pages;
2
3 import java.util.Calendar;
4 import java.util.Iterator;
5
6 import net.sf.statcvs.Messages;
7 import net.sf.statcvs.charts.ChartImage;
8 import net.sf.statcvs.charts.LOCChartMaker.MainLOCChartMaker;
9 import net.sf.statcvs.model.Repository;
10 import net.sf.statcvs.model.Revision;
11 import net.sf.statcvs.model.VersionedFile;
12 import net.sf.statcvs.output.ReportConfig;
13 import net.sf.statcvs.reports.CloudCommitTableReport;
14 import net.sf.statcvs.reports.TagReport;
15 import net.sf.statcvs.reports.TopDevelopersTableReport;
16
17 /**
18 * @author anja
19 * @author Richard Cyganiak (richard@cyganiak.de)
20 * @version $Id: IndexPageMaker.java,v 1.9 2009/04/21 23:17:29 benoitx Exp $
21 */
22 public class IndexPageMaker {
23 private final ReportConfig config;
24 private final Repository repository;
25 private final String notesHTML;
26 private final PageGroup reports;
27
28 /**
29 * Creates a new report index page.
30 * @param config Report configuration to use
31 * @param notesHTML A note to be inserted on top of the page; might be <tt>null</tt>
32 * @param reports A list of {@link NavigationNode}s that constitute the page's main menu
33 */
34 public IndexPageMaker(final ReportConfig config, final String notesHTML, final PageGroup reports) {
35 this.config = config;
36 this.repository = config.getRepository();
37 this.notesHTML = notesHTML;
38 this.reports = reports;
39 }
40
41 public Page toFile() {
42 final ChartImage chart = new MainLOCChartMaker("loc_small", this.config, "loc_small.png", this.config.getSmallChartSize()).toFile();
43
44 final TopDevelopersTableReport topDevelopers = new TopDevelopersTableReport(this.config);
45 final CloudCommitTableReport cloud = new CloudCommitTableReport(this.config);
46
47 final String title = Messages.getString("INDEX_TITLE") + " " + this.config.getProjectName();
48 final Page page = this.config.createPage("index", title, title);
49 page.addAttribute("Generated", Calendar.getInstance().getTime());
50 final String headRevisionNumber = getHeadRevisionNumber();
51
52
53 if (headRevisionNumber != null && headRevisionNumber.indexOf('.') < 0) {
54 page.addAttribute("Head revision", headRevisionNumber);
55 }
56 page.addRawAttribute("Report Period", getReportPeriod());
57 page.addAttribute("Total Files", getCurrentFileCount());
58 page.addAttribute("Total Lines of Code", this.repository.getCurrentLOC());
59 page.addAttribute("Developers", topDevelopers.getDeveloperCount());
60 if (this.notesHTML != null) {
61 page.addRawContent(this.notesHTML);
62 }
63 page.add(this.reports);
64 if (chart != null) {
65 page.addSection(Messages.getString("LOC_TITLE"));
66 page.add(chart, "loc.html");
67 }
68 if (topDevelopers.getDeveloperCount() > 1) {
69 if (topDevelopers.getDeveloperCount() > 10) {
70 page.addSection(Messages.getString("SECTION_TOP_AUTHORS"));
71 } else {
72 page.addSection("Developers");
73 }
74 page.add(topDevelopers);
75 page.addRawContent(HTML.getLink("developers.html", Messages.getString("NAVIGATION_MORE")));
76 }
77
78 page.addSection(Messages.getString("CLOUD_SECTION_TITLE"));
79 cloud.calculate();
80 page.addRawContent(cloud.getRawContent());
81 page.addRawContent(HTML.getLink("cloud.html", Messages.getString("NAVIGATION_MORE")));
82
83 if (!this.repository.getSymbolicNames().isEmpty()) {
84 page.addSection("Repository Tags");
85 page.add(new TagReport(this.config));
86 }
87 page.addSection("Directories");
88 page.add(this.repository.getRoot(), false);
89 return page;
90 }
91
92 private String getReportPeriod() {
93 return HTML.getDate(this.repository.getFirstDate()) + " to " + HTML.getDate(this.repository.getLastDate());
94 }
95
96 private int getCurrentFileCount() {
97 int result = 0;
98 final Iterator it = this.repository.getFiles().iterator();
99 while (it.hasNext()) {
100 final VersionedFile file = (VersionedFile) it.next();
101 if (!file.isDead()) {
102 result++;
103 }
104 }
105 return result;
106 }
107
108 private String getHeadRevisionNumber() {
109 final Revision headRevision = (Revision) (this.repository.getRevisions().last());
110
111 if (headRevision != null) {
112 return headRevision.getRevisionNumber();
113 } else {
114 return null;
115 }
116 }
117 }