| 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 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
public class ReportSuiteMaker { |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 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 | 0 | |
| 43 | |
private final ReportConfig config; |
| 44 | 0 | private final String notesHTML; |
| 45 | 0 | private List extraPages = new ArrayList(); |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 0 | |
| 50 | 0 | |
| 51 | 0 | public ReportSuiteMaker(final ReportConfig config, final String notesHTML) { |
| 52 | 0 | this(config, notesHTML, Collections.EMPTY_LIST); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | 0 | |
| 58 | 0 | |
| 59 | 0 | |
| 60 | 0 | public ReportSuiteMaker(final ReportConfig config, final String notesHTML, final List additionalPages) { |
| 61 | 0 | this.config = config; |
| 62 | 0 | this.notesHTML = notesHTML; |
| 63 | 0 | this.extraPages = additionalPages; |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | 0 | |
| 70 | 0 | |
| 71 | 0 | public void toXml() { |
| 72 | 0 | new GenerateXml(this.config).generate(); |
| 73 | 0 | } |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | 0 | |
| 78 | 0 | |
| 79 | 0 | public Page toFile() throws IOException { |
| 80 | 0 | this.config.getCssHandler().createOutputFiles(); |
| 81 | 0 | if (this.config.getRepository().isEmpty()) { |
| 82 | 0 | return createEmptyRepositoryPage(); |
| 83 | 0 | } |
| 84 | 0 | createIcon(TWEET_THIS_SMALL); |
| 85 | 0 | createIcon(TWEET_THIS_ICON); |
| 86 | 0 | createIcon(BUG_ICON); |
| 87 | 0 | createIcon(DIRECTORY_ICON); |
| 88 | 0 | createIcon(DELETED_DIRECTORY_ICON); |
| 89 | 0 | createIcon(FILE_ICON); |
| 90 | 0 | createIcon(DELETED_FILE_ICON); |
| 91 | 0 | |
| 92 | 0 | final PageGroup mainMenu = new PageGroup("Reports", false); |
| 93 | 0 | final IndexPageMaker indexPageMaker = new IndexPageMaker(this.config, this.notesHTML, mainMenu); |
| 94 | 0 | |
| 95 | 0 | |
| 96 | 0 | |
| 97 | 0 | |
| 98 | 0 | final NavigationNode allDevPage = new AllDevelopersPageMaker(this.config).toFile(); |
| 99 | 0 | mainMenu.add(allDevPage); |
| 100 | 0 | allDevPage.setParent(indexPageMaker.getPage()); |
| 101 | 0 | |
| 102 | 0 | |
| 103 | 0 | |
| 104 | 0 | allDevPage.write(); |
| 105 | 0 | |
| 106 | 0 | |
| 107 | 0 | |
| 108 | 0 | final PageGroup locPageGroup = new CommitLogPageGroupMaker(this.config).getPages(); |
| 109 | 0 | if (locPageGroup != null) { |
| 110 | 0 | mainMenu.add(locPageGroup); |
| 111 | 0 | locPageGroup.setParent(indexPageMaker.getPage()); |
| 112 | 0 | locPageGroup.write(); |
| 113 | 0 | } |
| 114 | 0 | |
| 115 | 0 | final NavigationNode locPage = new LOCPageMaker(this.config).toFile(); |
| 116 | 0 | mainMenu.add(locPage); |
| 117 | 0 | locPage.setParent(indexPageMaker.getPage()); |
| 118 | 0 | locPage.write(); |
| 119 | 0 | |
| 120 | 0 | final NavigationNode fileSizePage = new FileSizesPageMaker(this.config).toFile(); |
| 121 | 0 | mainMenu.add(fileSizePage); |
| 122 | 0 | fileSizePage.setParent(indexPageMaker.getPage()); |
| 123 | 0 | fileSizePage.write(); |
| 124 | 0 | |
| 125 | 0 | final NavigationNode dirPage = new DirectorySizesPageMaker(this.config).toFile(); |
| 126 | 0 | mainMenu.add(dirPage); |
| 127 | 0 | dirPage.setParent(indexPageMaker.getPage()); |
| 128 | 0 | dirPage.write(); |
| 129 | 0 | |
| 130 | 0 | if (ModuleUtil.modulesPresent()) { |
| 131 | 0 | final NavigationNode modulePage = new ModulesPageMaker(this.config).toFile(); |
| 132 | 0 | mainMenu.add(modulePage); |
| 133 | 0 | modulePage.setParent(indexPageMaker.getPage()); |
| 134 | 0 | modulePage.write(); |
| 135 | 0 | } |
| 136 | 0 | |
| 137 | 0 | final NavigationNode repoPage = new RepoMapPageMaker(config).toFile(); |
| 138 | 0 | mainMenu.add(repoPage); |
| 139 | 0 | repoPage.setParent(indexPageMaker.getPage()); |
| 140 | 0 | repoPage.write(); |
| 141 | 0 | |
| 142 | 0 | final NavigationNode churnPage = new ChurnPageMaker(config).toFile(); |
| 143 | 0 | mainMenu.add(churnPage); |
| 144 | 0 | churnPage.setParent(indexPageMaker.getPage()); |
| 145 | 0 | churnPage.write(); |
| 146 | 0 | |
| 147 | 0 | final NavigationNode cloudPage = new CloudCommitPageMaker(this.config).toFile(); |
| 148 | 0 | mainMenu.add(cloudPage); |
| 149 | 0 | cloudPage.setParent(indexPageMaker.getPage()); |
| 150 | 0 | cloudPage.write(); |
| 151 | 0 | |
| 152 | 0 | Iterator it = this.extraPages.iterator(); |
| 153 | 0 | while (it.hasNext()) { |
| 154 | 0 | final Page extra = (Page) it.next(); |
| 155 | 0 | extra.setParent(indexPageMaker.getPage()); |
| 156 | 0 | mainMenu.add(extra); |
| 157 | 0 | } |
| 158 | 0 | final Page indexPage = indexPageMaker.toFile(); |
| 159 | |
|
| 160 | 0 | final PageGroup directoryPages = new PageGroup("Directories", false); |
| 161 | 0 | it = this.config.getRepository().getDirectories().iterator(); |
| 162 | 0 | while (it.hasNext()) { |
| 163 | 0 | final Page dirPageGrp = new DirectoryPageMaker(this.config, (Directory) it.next()).toFile(); |
| 164 | 0 | dirPageGrp.setParent(indexPageMaker.getPage()); |
| 165 | 0 | directoryPages.add(dirPageGrp); |
| 166 | 0 | dirPageGrp.write(); |
| 167 | 0 | } |
| 168 | 0 | indexPage.addChild(directoryPages); |
| 169 | 0 | directoryPages.write(); |
| 170 | 0 | return indexPage; |
| 171 | |
} |
| 172 | |
|
| 173 | |
private void createIcon(final String iconFilename) throws IOException { |
| 174 | 0 | this.config.copyFileIntoReport(Main.class.getResource(WEB_FILE_PATH + iconFilename), iconFilename); |
| 175 | 0 | } |
| 176 | |
|
| 177 | |
private Page createEmptyRepositoryPage() { |
| 178 | 0 | String projectName = this.config.getProjectName(); |
| 179 | 0 | if (projectName == null) { |
| 180 | 0 | projectName = "empty repository"; |
| 181 | |
} |
| 182 | 0 | final String title = "Development statistics for " + projectName; |
| 183 | 0 | final Page page = this.config.createPage("index", title, title); |
| 184 | 0 | page.addAttribute("Generated", Calendar.getInstance().getTime()); |
| 185 | 0 | page.addRawContent("<p>No matching files in repository.</p>"); |
| 186 | 0 | return page; |
| 187 | |
} |
| 188 | |
} |