1 package net.sf.statcvs.pages;
2
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.Calendar;
6 import java.util.Collections;
7 import java.util.Iterator;
8 import java.util.List;
9
10 import net.sf.statcvs.Main;
11 import net.sf.statcvs.model.Directory;
12 import net.sf.statcvs.output.ChurnPageMaker;
13 import net.sf.statcvs.output.RepoMapPageMaker;
14 import net.sf.statcvs.output.ReportConfig;
15 import net.sf.statcvs.pages.xml.GenerateXml;
16 import net.sf.statcvs.util.ModuleUtil;
17
18 /**
19 * TODO: Clean up
20 *
21 * @author Anja Jentzsch
22 * @author Benoit Xhenseval (OutputRenderer and ExtraReportRegister interfaces)
23 * @version $Id: ReportSuiteMaker.java,v 1.11 2009/08/22 10:30:42 benoitx Exp $
24 */
25 public class ReportSuiteMaker {
26
27 /**
28 * Path to web distribution files inside the distribution JAR, relative to
29 * the {@link net.sf.statcvs.Main} class
30 */
31 public static final String WEB_FILE_PATH = "web-files/";
32
33 public static final String DIRECTORY_ICON = "folder.png";
34 public static final String BUG_ICON = "bug.png";
35 public static final String TWEET_THIS_SMALL = "tt-twitter-micro3.png";
36 public static final String TWEET_THIS_ICON = "tweet-this.png";
37 public static final String DELETED_DIRECTORY_ICON = "folder-deleted.png";
38 public static final String FILE_ICON = "file.png";
39 public static final String DELETED_FILE_ICON = "file-deleted.png";
40 public static final int ICON_WIDTH = 15;
41 public static final int ICON_HEIGHT = 13;
42
43 private final ReportConfig config;
44 private final String notesHTML;
45 private List extraPages = new ArrayList();
46
47 /**
48 * @param config Configuration and data for the report suite
49 * @param notesHTML A note to be inserted on top of the page; might be <tt>null</tt>
50 */
51 public ReportSuiteMaker(final ReportConfig config, final String notesHTML) {
52 this(config, notesHTML, Collections.EMPTY_LIST);
53 }
54
55 /**
56 * @param config Configuration and data for the report suite
57 * @param notesHTML A note to be inserted on top of the page; might be <tt>null</tt>
58 * @param additionalPages A list of {@link Page}s for inclusion in the index page's main menu
59 */
60 public ReportSuiteMaker(final ReportConfig config, final String notesHTML, final List additionalPages) {
61 this.config = config;
62 this.notesHTML = notesHTML;
63 this.extraPages = additionalPages;
64 }
65
66 /**
67 * this method will move away from the ordinary routine taken by
68 * statSVn and will invoke some new classes that are written to generate the xml's
69 *
70 */
71 public void toXml() {
72 new GenerateXml(this.config).generate();
73 }
74
75 /**
76 * TODO: Don't throw exception
77 * @throws IOException on error while writing the files
78 */
79 public Page toFile() throws IOException {
80 this.config.getCssHandler().createOutputFiles();
81 if (this.config.getRepository().isEmpty()) {
82 return createEmptyRepositoryPage();
83 }
84 createIcon(TWEET_THIS_SMALL);
85 createIcon(TWEET_THIS_ICON);
86 createIcon(BUG_ICON);
87 createIcon(DIRECTORY_ICON);
88 createIcon(DELETED_DIRECTORY_ICON);
89 createIcon(FILE_ICON);
90 createIcon(DELETED_FILE_ICON);
91
92 final PageGroup mainMenu = new PageGroup("Reports", false);
93 final IndexPageMaker indexPageMaker = new IndexPageMaker(this.config, this.notesHTML, mainMenu);
94
95
96
97
98 final NavigationNode allDevPage = new AllDevelopersPageMaker(this.config).toFile();
99 mainMenu.add(allDevPage);
100 allDevPage.setParent(indexPageMaker.getPage());
101
102
103
104 allDevPage.write();
105
106
107
108 final PageGroup locPageGroup = new CommitLogPageGroupMaker(this.config).getPages();
109 if (locPageGroup != null) {
110 mainMenu.add(locPageGroup);
111 locPageGroup.setParent(indexPageMaker.getPage());
112 locPageGroup.write();
113 }
114
115 final NavigationNode locPage = new LOCPageMaker(this.config).toFile();
116 mainMenu.add(locPage);
117 locPage.setParent(indexPageMaker.getPage());
118 locPage.write();
119
120 final NavigationNode fileSizePage = new FileSizesPageMaker(this.config).toFile();
121 mainMenu.add(fileSizePage);
122 fileSizePage.setParent(indexPageMaker.getPage());
123 fileSizePage.write();
124
125 final NavigationNode dirPage = new DirectorySizesPageMaker(this.config).toFile();
126 mainMenu.add(dirPage);
127 dirPage.setParent(indexPageMaker.getPage());
128 dirPage.write();
129
130 if (ModuleUtil.modulesPresent()) {
131 final NavigationNode modulePage = new ModulesPageMaker(this.config).toFile();
132 mainMenu.add(modulePage);
133 modulePage.setParent(indexPageMaker.getPage());
134 modulePage.write();
135 }
136
137 final NavigationNode repoPage = new RepoMapPageMaker(config).toFile();
138 mainMenu.add(repoPage);
139 repoPage.setParent(indexPageMaker.getPage());
140 repoPage.write();
141
142 final NavigationNode churnPage = new ChurnPageMaker(config).toFile();
143 mainMenu.add(churnPage);
144 churnPage.setParent(indexPageMaker.getPage());
145 churnPage.write();
146
147 final NavigationNode cloudPage = new CloudCommitPageMaker(this.config).toFile();
148 mainMenu.add(cloudPage);
149 cloudPage.setParent(indexPageMaker.getPage());
150 cloudPage.write();
151
152 Iterator it = this.extraPages.iterator();
153 while (it.hasNext()) {
154 final Page extra = (Page) it.next();
155 extra.setParent(indexPageMaker.getPage());
156 mainMenu.add(extra);
157 }
158 final Page indexPage = indexPageMaker.toFile();
159
160 final PageGroup directoryPages = new PageGroup("Directories", false);
161 it = this.config.getRepository().getDirectories().iterator();
162 while (it.hasNext()) {
163 final Page dirPageGrp = new DirectoryPageMaker(this.config, (Directory) it.next()).toFile();
164 dirPageGrp.setParent(indexPageMaker.getPage());
165 directoryPages.add(dirPageGrp);
166 dirPageGrp.write();
167 }
168 indexPage.addChild(directoryPages);
169 directoryPages.write();
170 return indexPage;
171 }
172
173 private void createIcon(final String iconFilename) throws IOException {
174 this.config.copyFileIntoReport(Main.class.getResource(WEB_FILE_PATH + iconFilename), iconFilename);
175 }
176
177 private Page createEmptyRepositoryPage() {
178 String projectName = this.config.getProjectName();
179 if (projectName == null) {
180 projectName = "empty repository";
181 }
182 final String title = "Development statistics for " + projectName;
183 final Page page = this.config.createPage("index", title, title);
184 page.addAttribute("Generated", Calendar.getInstance().getTime());
185 page.addRawContent("<p>No matching files in repository.</p>");
186 return page;
187 }
188 }