| 1 | |
package net.sf.statcvs.pages.xml; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 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 | |
|
| 36 | |
|
| 37 | 0 | public GenerateXml(final ReportConfig config) { |
| 38 | 0 | this.config = config; |
| 39 | 0 | this.repository = config.getRepository(); |
| 40 | 0 | } |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 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 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 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 | |
|
| 95 | |
|
| 96 | 0 | final AllDevelopersXml adxml = new AllDevelopersXml(config); |
| 97 | 0 | final Element child1 = adxml.toFile(); |
| 98 | 0 | root.addContent(child1); |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | 0 | final DirectoriesXml dxml = new DirectoriesXml(config); |
| 104 | 0 | final Element child2 = dxml.toFile(); |
| 105 | 0 | root.addContent(child2); |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | 0 | final LogXml log = new LogXml(config); |
| 111 | 0 | final Element child3 = log.toFile(); |
| 112 | 0 | root.addContent(child3); |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | 0 | final FilesXml fl = new FilesXml(config); |
| 118 | 0 | final Element child4 = fl.toFile(); |
| 119 | 0 | root.addContent(child4); |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 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 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
private String getReportPeriod() { |
| 147 | 0 | return XML.getDate(this.repository.getFirstDate()) + " to " + XML.getDate(this.repository.getLastDate()); |
| 148 | |
} |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 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 | |
} |