Coverage Report - net.sf.statcvs.pages.ReportSuiteMaker
 
Classes in this File Line Coverage Branch Coverage Complexity
ReportSuiteMaker
0%
0/124
0%
0/46
2.167
 
 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  0
 
 43  
     private final ReportConfig config;
 44  0
     private final String notesHTML;
 45  0
     private List extraPages = new ArrayList();
 46  
 
 47  
     /**
 48  
      * @param config Configuration and data for the report suite
 49  0
      * @param notesHTML A note to be inserted on top of the page; might be <tt>null</tt>
 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  
      * @param config Configuration and data for the report suite
 57  0
      * @param notesHTML A note to be inserted on top of the page; might be <tt>null</tt>
 58  0
      * @param additionalPages A list of {@link Page}s for inclusion in the index page's main menu
 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  
     * 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  0
     * 
 70  0
     */
 71  0
     public void toXml() {
 72  0
         new GenerateXml(this.config).generate();
 73  0
     }
 74  
 
 75  
     /**
 76  
      * TODO: Don't throw exception
 77  0
      * @throws IOException on error while writing the files
 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
         //        Runtime.getRuntime().gc();
 96  0
         //        final long memoryUsedOnStart = Runtime.getRuntime().freeMemory();
 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
         //        Runtime.getRuntime().gc();
 102  0
         //        long memoryUsedOnStop = Runtime.getRuntime().freeMemory();
 103  0
         //        System.out.println("Mem with HTML " + (memoryUsedOnStop-memoryUsedOnStart));
 104  0
         allDevPage.write();
 105  0
         //        Runtime.getRuntime().gc();
 106  0
         //        memoryUsedOnStop = Runtime.getRuntime().freeMemory();
 107  0
         //        System.out.println("Mem AFTER WRITING " + (memoryUsedOnStop-memoryUsedOnStart));
 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  
 }