| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
package net.sf.statcvs; |
| 24 | |
|
| 25 | |
import java.io.FileReader; |
| 26 | |
import java.io.IOException; |
| 27 | |
import java.io.Reader; |
| 28 | |
import java.util.ArrayList; |
| 29 | |
import java.util.List; |
| 30 | |
import java.util.logging.LogManager; |
| 31 | |
import java.util.logging.Logger; |
| 32 | |
|
| 33 | |
import net.sf.statcvs.input.Builder; |
| 34 | |
import net.sf.statcvs.input.CvsLogfileParser; |
| 35 | |
import net.sf.statcvs.input.LogSyntaxException; |
| 36 | |
import net.sf.statcvs.input.RepositoryFileManager; |
| 37 | |
import net.sf.statcvs.model.Repository; |
| 38 | |
import net.sf.statcvs.output.CommandLineParser; |
| 39 | |
import net.sf.statcvs.output.ConfigurationException; |
| 40 | |
import net.sf.statcvs.output.ConfigurationOptions; |
| 41 | |
import net.sf.statcvs.output.ReportConfig; |
| 42 | |
import net.sf.statcvs.pages.Page; |
| 43 | |
import net.sf.statcvs.pages.ReportSuiteMaker; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | 0 | |
| 52 | 0 | public class Main { |
| 53 | 0 | private static Logger logger = Logger.getLogger("net.sf.statcvs"); |
| 54 | 0 | private static LogManager lm = LogManager.getLogManager(); |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | 0 | public static void main(final String[] args) { |
| 61 | 0 | System.out.println(Messages.getString("PROJECT_NAME") + Messages.NL); |
| 62 | 0 | |
| 63 | 0 | if (args.length == 0) { |
| 64 | 0 | printProperUsageAndExit(); |
| 65 | 0 | } |
| 66 | 0 | if (args.length == 1) { |
| 67 | 0 | final String arg = args[0].toLowerCase(); |
| 68 | 0 | if (arg.equals("-h") || arg.equals("-help")) { |
| 69 | 0 | printProperUsageAndExit(); |
| 70 | 0 | } else if (arg.equals("-version")) { |
| 71 | 0 | printVersionAndExit(); |
| 72 | |
} |
| 73 | |
} |
| 74 | |
|
| 75 | 0 | try { |
| 76 | 0 | new CommandLineParser(args).parse(); |
| 77 | 0 | generateDefaultHTMLSuite(); |
| 78 | 0 | } catch (final ConfigurationException cex) { |
| 79 | 0 | System.err.println(cex.getMessage()); |
| 80 | 0 | System.exit(1); |
| 81 | 0 | } catch (final LogSyntaxException lex) { |
| 82 | 0 | printLogErrorMessageAndExit(lex.getMessage()); |
| 83 | 0 | } catch (final IOException ioex) { |
| 84 | 0 | printIoErrorMessageAndExit(ioex.getMessage()); |
| 85 | 0 | } catch (final OutOfMemoryError oome) { |
| 86 | 0 | printOutOfMemMessageAndExit(); |
| 87 | 0 | } |
| 88 | 0 | System.exit(0); |
| 89 | 0 | } |
| 90 | |
|
| 91 | |
private static void initLogManager(final String loggingProperties) { |
| 92 | 0 | try { |
| 93 | 0 | lm.readConfiguration(Main.class.getResourceAsStream(loggingProperties)); |
| 94 | 0 | } catch (final IOException e) { |
| 95 | 0 | System.err.println("ERROR: Logging could not be initialized!"); |
| 96 | 0 | } |
| 97 | 0 | } |
| 98 | |
|
| 99 | 0 | private static void printProperUsageAndExit() { |
| 100 | 0 | System.out.println( |
| 101 | |
|
| 102 | |
|
| 103 | |
"Usage: java -jar statcvs.jar [options] <logfile> <directory>\n" + "\n" + "Required parameters:\n" |
| 104 | |
+ " <logfile> path to the cvs logfile of the module\n" |
| 105 | |
+ " <directory> path to the directory of the checked out module\n" + "\n" + "Some options:\n" |
| 106 | |
+ " -version print version information and exit\n" + " -output-dir <dir> set directory where HTML suite will be saved\n" |
| 107 | |
+ " -include <pattern> include only files matching pattern, e.g. **/*.c;**/*.h\n" |
| 108 | |
+ " -exclude <pattern> exclude matching files, e.g. tests/**;docs/**\n" |
| 109 | |
+ " -tags <regexp> show matching tags in lines of code chart, e.g. version-.*\n" |
| 110 | |
+ " -title <title> set project title to be used in reports\n" + " -xdoc generate Maven XDoc instead of HTML\n" |
| 111 | |
+ " -trac <url> integrate with Trac at <url>\n" + " -xml generate XML instead of HTML\n" |
| 112 | |
+ " -charset <charset> specify the charset to use for html/xdoc\n" + " -verbose print extra progress information\n" |
| 113 | 0 | + " -viewcvs/viewvc/cvsweb/chora/jcvsweb/bugzilla/mantis <url>\n" + " add links to installation at <url>\n" |
| 114 | 0 | + " -disable-twitter-button\n" + "\n" + "Full options list: http://statcvs.sf.net/manual"); |
| 115 | 0 | System.exit(1); |
| 116 | 0 | } |
| 117 | 0 | |
| 118 | 0 | private static void printVersionAndExit() { |
| 119 | 0 | System.out.println("Version " + Messages.getString("PROJECT_VERSION")); |
| 120 | 0 | System.exit(1); |
| 121 | 0 | } |
| 122 | 0 | |
| 123 | 0 | private static void printOutOfMemMessageAndExit() { |
| 124 | 0 | System.err.println("OutOfMemoryError."); |
| 125 | 0 | System.err.println("Try running java with the -mx option (e.g. -mx128m for 128Mb)."); |
| 126 | 0 | System.exit(1); |
| 127 | 0 | } |
| 128 | 0 | |
| 129 | 0 | private static void printLogErrorMessageAndExit(final String message) { |
| 130 | 0 | System.err.println("Logfile parsing failed."); |
| 131 | 0 | System.err.println(message); |
| 132 | 0 | System.exit(1); |
| 133 | 0 | } |
| 134 | 0 | |
| 135 | 0 | private static void printIoErrorMessageAndExit(final String message) { |
| 136 | 0 | System.err.println(message); |
| 137 | 0 | System.exit(1); |
| 138 | 0 | } |
| 139 | 0 | |
| 140 | 0 | |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | 0 | public static void generateDefaultHTMLSuite() throws LogSyntaxException, IOException, ConfigurationException { |
| 148 | 0 | |
| 149 | 0 | if (ConfigurationOptions.getLogFileName() == null) { |
| 150 | 0 | throw new ConfigurationException("Missing logfile name"); |
| 151 | 0 | } |
| 152 | 0 | if (ConfigurationOptions.getCheckedOutDirectory() == null) { |
| 153 | 0 | throw new ConfigurationException("Missing checked out directory"); |
| 154 | 0 | } |
| 155 | 0 | |
| 156 | 0 | final long memoryUsedOnStart = Runtime.getRuntime().totalMemory(); |
| 157 | 0 | final long startTime = System.currentTimeMillis(); |
| 158 | 0 | |
| 159 | 0 | initLogManager(ConfigurationOptions.getLoggingProperties()); |
| 160 | 0 | |
| 161 | 0 | logger.info("Parsing CVS log '" + ConfigurationOptions.getLogFileName() + "'"); |
| 162 | 0 | |
| 163 | 0 | Reader logReader = null; |
| 164 | 0 | Builder builder = null; |
| 165 | 0 | try { |
| 166 | 0 | logReader = new FileReader(ConfigurationOptions.getLogFileName()); |
| 167 | 0 | final RepositoryFileManager repFileMan = new RepositoryFileManager(ConfigurationOptions.getCheckedOutDirectory()); |
| 168 | 0 | |
| 169 | 0 | builder = new Builder(repFileMan, ConfigurationOptions.getIncludePattern(), ConfigurationOptions.getExcludePattern(), ConfigurationOptions |
| 170 | 0 | .getSymbolicNamesPattern()); |
| 171 | 0 | new CvsLogfileParser(logReader, builder).parse(); |
| 172 | 0 | } finally { |
| 173 | 0 | if (logReader != null) { |
| 174 | 0 | logReader.close(); |
| 175 | 0 | } |
| 176 | 0 | } |
| 177 | 0 | if (ConfigurationOptions.getProjectName() == null) { |
| 178 | 0 | ConfigurationOptions.setProjectName(builder.getProjectName()); |
| 179 | 0 | } |
| 180 | 0 | if (ConfigurationOptions.getWebRepository() != null) { |
| 181 | 0 | ConfigurationOptions.getWebRepository().setAtticFileNames(builder.getAtticFileNames()); |
| 182 | 0 | } |
| 183 | 0 | logger.info("Generating report for " + ConfigurationOptions.getProjectName() + " into " + ConfigurationOptions.getOutputDir()); |
| 184 | 0 | logger.info("Using " + ConfigurationOptions.getCssHandler()); |
| 185 | 0 | final Repository content = builder.createCvsContent(); |
| 186 | 0 | if (content.isEmpty()) { |
| 187 | 0 | if (builder.allRejectedByExcludePattern()) { |
| 188 | 0 | logger.warning("Exclude pattern '" + ConfigurationOptions.getExcludePattern() + "' removed all files from repository"); |
| 189 | 0 | } else if (builder.allRejectedByIncludePattern()) { |
| 190 | 0 | logger.warning("Include pattern '" + ConfigurationOptions.getIncludePattern() + "' rejected all files from repository"); |
| 191 | 0 | } else { |
| 192 | 0 | logger.warning("Empty repository"); |
| 193 | 0 | } |
| 194 | 0 | } |
| 195 | 0 | if (builder.isLocalFilesNotFound()) { |
| 196 | 0 | logger.warning("The log references many files that do not exist in the local copy."); |
| 197 | 0 | logger.warning("Reports will be inaccurate or broken."); |
| 198 | 0 | logger.warning("Log not generated in '" + ConfigurationOptions.getCheckedOutDirectory() + "'?"); |
| 199 | 0 | } else if (!builder.hasLocalCVSMetadata()) { |
| 200 | 0 | logger.warning("No CVS metadata found in working copy. Reports may be inaccurate."); |
| 201 | 0 | } else if (builder.isLogAndLocalFilesOutOfSync()) { |
| 202 | 0 | logger.warning("Log and working copy are out of sync. Reports will be inaccurate."); |
| 203 | 0 | } |
| 204 | 0 | |
| 205 | 0 | builder.clean(); |
| 206 | 0 | builder = null; |
| 207 | |
|
| 208 | 0 | |
| 209 | 0 | System.setProperty("java.awt.headless", "true"); |
| 210 | 0 | |
| 211 | 0 | final ReportConfig config = new ReportConfig(content, ConfigurationOptions.getProjectName(), ConfigurationOptions.getOutputDir(), ConfigurationOptions |
| 212 | 0 | .getMarkupSyntax(), ConfigurationOptions.getCssHandler(), ConfigurationOptions.getCharSet()); |
| 213 | 0 | config.setWebRepository(ConfigurationOptions.getWebRepository()); |
| 214 | 0 | config.setWebBugtracker(ConfigurationOptions.getWebBugtracker()); |
| 215 | 0 | config.setNonDeveloperLogins(ConfigurationOptions.getNonDeveloperLogins()); |
| 216 | 0 | |
| 217 | 0 | final List extraReports = new ArrayList(); |
| 218 | 0 | |
| 219 | 0 | |
| 220 | 0 | |
| 221 | 0 | ReportSuiteMaker reportSuiteMaker = new ReportSuiteMaker(config, ConfigurationOptions.getNotes(), extraReports); |
| 222 | 0 | if ("xml".equalsIgnoreCase(ConfigurationOptions.getOutputFormat())) { |
| 223 | 0 | reportSuiteMaker.toXml(); |
| 224 | |
} else { |
| 225 | 0 | Page page = reportSuiteMaker.toFile(); |
| 226 | |
|
| 227 | 0 | |
| 228 | |
|
| 229 | 0 | |
| 230 | 0 | |
| 231 | |
|
| 232 | 0 | |
| 233 | 0 | |
| 234 | |
|
| 235 | |
|
| 236 | 0 | page.write(); |
| 237 | |
|
| 238 | 0 | |
| 239 | |
|
| 240 | 0 | |
| 241 | 0 | |
| 242 | |
|
| 243 | 0 | |
| 244 | 0 | |
| 245 | |
} |
| 246 | |
|
| 247 | 0 | final long endTime = System.currentTimeMillis(); |
| 248 | 0 | final long memoryUsedOnEnd = Runtime.getRuntime().totalMemory(); |
| 249 | |
|
| 250 | 0 | logger.info("runtime: " + (((double) endTime - startTime) / 1000) + " seconds"); |
| 251 | 0 | logger.info("memory usage: " + (((double) memoryUsedOnEnd - memoryUsedOnStart) / 1024) + " kb"); |
| 252 | 0 | } |
| 253 | |
} |