Coverage Report - net.sf.statcvs.pages.xml.GenerateXml
 
Classes in this File Line Coverage Branch Coverage Complexity
GenerateXml
0%
0/66
0%
0/10
2.5
 
 1  
 package net.sf.statcvs.pages.xml;
 2  
 
 3  
 /**
 4  
  * @author Nilendra Weerasinghe (nilendraw@gmail.com)
 5  
  * @version $Id: GenerateXml.java,v 1.2 2008/04/02 11:22:16 benoitx Exp $
 6  
  *
 7  
  * This is the central class which creates all of the xml reports
 8  
  */
 9  
 
 10  
 import java.io.FileOutputStream;
 11  
 import java.io.IOException;
 12  
 import java.util.Calendar;
 13  
 import java.util.Iterator;
 14  
 
 15  
 import net.sf.statcvs.Messages;
 16  
 import net.sf.statcvs.model.Repository;
 17  
 import net.sf.statcvs.model.VersionedFile;
 18  
 import net.sf.statcvs.output.ConfigurationOptions;
 19  
 import net.sf.statcvs.output.ReportConfig;
 20  
 import net.sf.statcvs.output.WebRepositoryIntegration;
 21  
 import net.sf.statcvs.reports.TopDevelopersTableReport;
 22  
 import net.sf.statcvs.weblinks.bugs.BugTracker;
 23  
 
 24  
 import org.jdom.Comment;
 25  
 import org.jdom.Document;
 26  
 import org.jdom.Element;
 27  
 import org.jdom.output.XMLOutputter;
 28  
 
 29  
 public class GenerateXml {
 30  
     private static final String TAG_REPO_STATISTICS = "RepoStatistics";
 31  
     private final ReportConfig config;
 32  
     private final Repository repository;
 33  
 
 34  
     /**
 35  
      * @param config Configuration and data for the report suite
 36  
      */
 37  0
     public GenerateXml(final ReportConfig config) {
 38  0
         this.config = config;
 39  0
         this.repository = config.getRepository();
 40  0
     }
 41  
 
 42  
     /**
 43  
      * This method will invoke the classes which capture the data required to generate the xmls
 44  
      */
 45  
     public void generate() {
 46  0
         final TopDevelopersTableReport topDevelopers = new TopDevelopersTableReport(this.config);
 47  0
         final String gen_time = Calendar.getInstance().getTime().toString();
 48  0
         final String period = getReportPeriod();
 49  0
         final String title = Messages.getString("INDEX_TITLE") + " " + this.config.getProjectName();
 50  0
         final Element root = new Element(TAG_REPO_STATISTICS);
 51  0
         root.setAttribute("date", gen_time.toLowerCase());
 52  0
         root.setAttribute("period", period.toLowerCase());
 53  0
         root.setAttribute("numberfiles", Integer.toString(getCurrentFileCount()));
 54  0
         root.setAttribute("totalloc", Integer.toString(this.repository.getCurrentLOC()));
 55  0
         root.setAttribute("numberdevelopers", Integer.toString(topDevelopers.getDeveloperCount()));
 56  
 
 57  0
         final Document myXML = new Document(root);
 58  0
         myXML.addContent(new Comment(title));
 59  
 
 60  0
         final Element el2 = new Element(XmlTags.TAG_CHECKED_OUT_DIR);
 61  0
         el2.setAttribute("path", ConfigurationOptions.getCheckedOutDirectory());
 62  0
         root.addContent(el2);
 63  
 
 64  0
         if (ConfigurationOptions.getProjectName() != null) {
 65  0
             final Element el3 = new Element(XmlTags.TAG_PROJECT);
 66  0
             el3.setAttribute("path", ConfigurationOptions.getCheckedOutDirectory());
 67  0
             root.addContent(el3);
 68  
         }
 69  
         /*
 70  
         if (repository.getRoot() != null) {
 71  
             Element el3 = new Element(XmlTags.TAG_ROOT);
 72  
             el3.setAttribute("path", repository.getRoot().getPath());
 73  
             root.addContent(el3);
 74  
         }
 75  
         */
 76  
 
 77  0
         final BugTracker bt = ConfigurationOptions.getWebBugtracker();
 78  0
         if (bt != null) {
 79  0
             final Element el = new Element(XmlTags.TAG_BUG_TRACKER);
 80  0
             el.setAttribute("baseurl", bt.baseURL());
 81  0
             el.setAttribute("name", bt.getName());
 82  0
             root.addContent(el);
 83  
         }
 84  
 
 85  0
         final WebRepositoryIntegration wi = ConfigurationOptions.getWebRepository();
 86  0
         if (wi != null) {
 87  0
             final Element el = new Element(XmlTags.TAG_WEB_REPOSITORY);
 88  0
             el.setAttribute("baseurl", wi.getBaseUrl());
 89  0
             el.setAttribute("name", wi.getName());
 90  0
             root.addContent(el);
 91  
         }
 92  
 
 93  
         /*
 94  
          * add developer statistics section to xml report
 95  
          */
 96  0
         final AllDevelopersXml adxml = new AllDevelopersXml(config);
 97  0
         final Element child1 = adxml.toFile();
 98  0
         root.addContent(child1);
 99  
 
 100  
         /*
 101  
          * add directories statistics section to xml report
 102  
          */
 103  0
         final DirectoriesXml dxml = new DirectoriesXml(config);
 104  0
         final Element child2 = dxml.toFile();
 105  0
         root.addContent(child2);
 106  
 
 107  
         /*
 108  
          * add commit log section to xml report
 109  
          */
 110  0
         final LogXml log = new LogXml(config);
 111  0
         final Element child3 = log.toFile();
 112  0
         root.addContent(child3);
 113  
 
 114  
         /*
 115  
          * add commit log section to xml
 116  
          */
 117  0
         final FilesXml fl = new FilesXml(config);
 118  0
         final Element child4 = fl.toFile();
 119  0
         root.addContent(child4);
 120  
 
 121  
         /*
 122  
          * add revised file list section to xml report
 123  
         RevisedFilesXml rxml = new RevisedFilesXml(config);
 124  
         Element child5 = rxml.toFile();
 125  
         root.addContent(child5);
 126  
          */
 127  
 
 128  
         // serialize it into a file
 129  
         try {
 130  0
             final String file = ConfigurationOptions.getOutputDir() + "repo-statistics.xml";
 131  0
             final FileOutputStream out = new FileOutputStream(file);
 132  0
             final XMLOutputter serializer = new XMLOutputter();
 133  0
             serializer.output(myXML, out);
 134  0
             out.flush();
 135  0
             out.close();
 136  0
         } catch (final IOException e) {
 137  0
             System.err.println(e);
 138  0
         }
 139  0
     }
 140  
 
 141  
     /**
 142  
      * Returns the period for which the report is being generated
 143  
      *
 144  
      * @returns String
 145  
      */
 146  
     private String getReportPeriod() {
 147  0
         return XML.getDate(this.repository.getFirstDate()) + " to " + XML.getDate(this.repository.getLastDate());
 148  
     }
 149  
 
 150  
     /**
 151  
      * Returns the no. of files in the repository
 152  
      *
 153  
      * @returns int
 154  
      */
 155  
     private int getCurrentFileCount() {
 156  0
         int result = 0;
 157  0
         final Iterator it = this.repository.getFiles().iterator();
 158  0
         while (it.hasNext()) {
 159  0
             final VersionedFile file = (VersionedFile) it.next();
 160  0
             if (!file.isDead()) {
 161  0
                 result++;
 162  
             }
 163  0
         }
 164  0
         return result;
 165  
     }
 166  
 }