| 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.output; |
| 24 | |
|
| 25 | |
import java.io.BufferedReader; |
| 26 | |
import java.io.File; |
| 27 | |
import java.io.FileInputStream; |
| 28 | |
import java.io.FileNotFoundException; |
| 29 | |
import java.io.FileReader; |
| 30 | |
import java.io.IOException; |
| 31 | |
import java.io.InputStream; |
| 32 | |
import java.net.MalformedURLException; |
| 33 | |
import java.net.URL; |
| 34 | |
import java.util.ArrayList; |
| 35 | |
import java.util.Collection; |
| 36 | |
import java.util.Properties; |
| 37 | |
import java.util.regex.Pattern; |
| 38 | |
import java.util.regex.PatternSyntaxException; |
| 39 | |
|
| 40 | |
import net.sf.statcvs.pages.MarkupSyntax; |
| 41 | |
import net.sf.statcvs.util.FilePatternMatcher; |
| 42 | |
import net.sf.statcvs.util.FileUtils; |
| 43 | |
import net.sf.statcvs.weblinks.bugs.BugTracker; |
| 44 | |
import net.sf.statcvs.weblinks.bugs.Bugzilla; |
| 45 | |
import net.sf.statcvs.weblinks.bugs.Mantis; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | 0 | public class ConfigurationOptions { |
| 58 | |
|
| 59 | |
private static final String LOGGING_CONFIG_DEFAULT = "logging.properties"; |
| 60 | |
private static final String LOGGING_CONFIG_VERBOSE = "logging-verbose.properties"; |
| 61 | |
private static final String LOGGING_CONFIG_DEBUG = "logging-debug.properties"; |
| 62 | |
|
| 63 | 16 | private static String logFileName = null; |
| 64 | 16 | private static String checkedOutDirectory = null; |
| 65 | 16 | private static String projectName = null; |
| 66 | 16 | private static String outputDir = ""; |
| 67 | 16 | private static String loggingProperties = LOGGING_CONFIG_DEFAULT; |
| 68 | 16 | private static String notesFile = null; |
| 69 | 16 | private static String notes = null; |
| 70 | |
|
| 71 | 16 | private static FilePatternMatcher includePattern = null; |
| 72 | 16 | private static FilePatternMatcher excludePattern = null; |
| 73 | |
|
| 74 | 16 | private static Collection nonDeveloperLogins = new ArrayList(); |
| 75 | |
|
| 76 | 16 | private static CssHandler cssHandler = new DefaultCssHandler("statcvs.css"); |
| 77 | 16 | private static WebRepositoryIntegration webRepository = null; |
| 78 | |
private static Pattern symbolicNamesPattern; |
| 79 | |
|
| 80 | 16 | private static BugTracker webBugTracker = BugTracker.NO_BUG_TRACKER; |
| 81 | 16 | private static String outputFormat = "html"; |
| 82 | 16 | private static Properties properties = new Properties(); |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public static CssHandler getCssHandler() { |
| 89 | 0 | return cssHandler; |
| 90 | |
} |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
public static String getProjectName() { |
| 97 | 0 | return projectName; |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
public static String getCheckedOutDirectory() { |
| 105 | 0 | return checkedOutDirectory; |
| 106 | |
} |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
public static String getLogFileName() { |
| 113 | 0 | return logFileName; |
| 114 | |
} |
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
public static String getOutputDir() { |
| 121 | 0 | return outputDir; |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
public static String getNotes() { |
| 130 | 0 | return notes; |
| 131 | |
} |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
public static WebRepositoryIntegration getWebRepository() { |
| 139 | 0 | return webRepository; |
| 140 | |
} |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
public static void setCheckedOutDirectory(final String checkedOutDirectory) throws ConfigurationException { |
| 148 | 0 | final File directory = new File(checkedOutDirectory); |
| 149 | 0 | if (!directory.exists() || !directory.isDirectory()) { |
| 150 | 0 | throw new ConfigurationException("directory does not exist: " + checkedOutDirectory); |
| 151 | |
} |
| 152 | 0 | ConfigurationOptions.checkedOutDirectory = checkedOutDirectory; |
| 153 | 0 | } |
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
public static void setCssFile(final String cssFile) throws ConfigurationException { |
| 167 | |
try { |
| 168 | 0 | final URL url = new URL(cssFile); |
| 169 | 0 | if (!url.getProtocol().equals("http")) { |
| 170 | 0 | throw new ConfigurationException("Only HTTP URLs or local files allowed for -css"); |
| 171 | |
} |
| 172 | 0 | cssHandler = new UrlCssHandler(url); |
| 173 | 0 | } catch (final MalformedURLException isLocalFile) { |
| 174 | 0 | cssHandler = new LocalFileCssHandler(cssFile); |
| 175 | 0 | } |
| 176 | 0 | cssHandler.checkForMissingResources(); |
| 177 | 0 | } |
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
public static void setLogFileName(final String logFileName) throws ConfigurationException { |
| 185 | 0 | final File inputFile = new File(logFileName); |
| 186 | 0 | if (!inputFile.exists()) { |
| 187 | 0 | throw new ConfigurationException("Specified logfile not found: " + logFileName); |
| 188 | |
} |
| 189 | 0 | ConfigurationOptions.logFileName = logFileName; |
| 190 | 0 | } |
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
public static void setOutputDir(String outputDir) throws ConfigurationException { |
| 198 | 0 | if (!outputDir.endsWith(FileUtils.getDirSeparator())) { |
| 199 | 0 | outputDir += FileUtils.getDefaultDirSeparator(); |
| 200 | |
} |
| 201 | 0 | final File outDir = new File(outputDir); |
| 202 | 0 | if (!outDir.exists() && !outDir.mkdirs()) { |
| 203 | 0 | throw new ConfigurationException("Can't create output directory: " + outputDir); |
| 204 | |
} |
| 205 | 0 | ConfigurationOptions.outputDir = outputDir; |
| 206 | 0 | } |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
public static void setNotesFile(final String notesFile) throws ConfigurationException { |
| 217 | 0 | final File f = new File(notesFile); |
| 218 | 0 | if (!f.exists()) { |
| 219 | 0 | throw new ConfigurationException("Notes file not found: " + notesFile); |
| 220 | |
} |
| 221 | 0 | if (!f.canRead()) { |
| 222 | 0 | throw new ConfigurationException("Can't read notes file: " + notesFile); |
| 223 | |
} |
| 224 | 0 | ConfigurationOptions.notesFile = notesFile; |
| 225 | |
try { |
| 226 | 0 | notes = readNotesFile(); |
| 227 | 0 | } catch (final IOException e) { |
| 228 | 0 | throw new ConfigurationException(e.getMessage()); |
| 229 | 0 | } |
| 230 | 0 | } |
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
public static void setViewCvsURL(final String url) { |
| 239 | 0 | ConfigurationOptions.webRepository = new ViewCvsIntegration(url); |
| 240 | 0 | } |
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
public static void setCvswebURL(final String url) { |
| 250 | 0 | ConfigurationOptions.webRepository = new CvswebIntegration(url); |
| 251 | 0 | } |
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
public static void setChoraURL(final String url) { |
| 260 | 0 | ConfigurationOptions.webRepository = new ChoraIntegration(url); |
| 261 | 0 | } |
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
public static void setJCVSWebURL(final String url) { |
| 270 | 0 | ConfigurationOptions.webRepository = new JCVSWebIntegration(url); |
| 271 | 0 | } |
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
public static void setViewVcURL(final String url) { |
| 282 | 0 | ConfigurationOptions.webRepository = new ViewVcIntegration(url); |
| 283 | 0 | } |
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | 0 | |
| 291 | 0 | |
| 292 | |
|
| 293 | |
public static void setViewTracURL(final String url) { |
| 294 | 0 | ConfigurationOptions.webRepository = new TracIntegration(url); |
| 295 | 0 | } |
| 296 | |
|
| 297 | |
|
| 298 | 0 | |
| 299 | |
|
| 300 | |
|
| 301 | |
public static void setProjectName(final String projectName) { |
| 302 | 0 | ConfigurationOptions.projectName = projectName; |
| 303 | 0 | } |
| 304 | |
|
| 305 | 0 | |
| 306 | 0 | |
| 307 | |
|
| 308 | |
|
| 309 | |
public static String getLoggingProperties() { |
| 310 | 0 | return loggingProperties; |
| 311 | |
} |
| 312 | 0 | |
| 313 | 0 | |
| 314 | |
|
| 315 | |
|
| 316 | 0 | public static void setVerboseLogging() { |
| 317 | 0 | ConfigurationOptions.loggingProperties = LOGGING_CONFIG_VERBOSE; |
| 318 | 0 | } |
| 319 | 0 | |
| 320 | 0 | |
| 321 | 0 | |
| 322 | 0 | |
| 323 | 0 | public static void setDebugLogging() { |
| 324 | 0 | ConfigurationOptions.loggingProperties = LOGGING_CONFIG_DEBUG; |
| 325 | 0 | } |
| 326 | 0 | |
| 327 | 0 | private static String readNotesFile() throws IOException { |
| 328 | 0 | BufferedReader r = null; |
| 329 | 0 | final StringBuffer result = new StringBuffer(); |
| 330 | 0 | try { |
| 331 | 0 | r = new BufferedReader(new FileReader(notesFile)); |
| 332 | 0 | String line = r.readLine(); |
| 333 | 0 | while (line != null) { |
| 334 | 0 | result.append(line); |
| 335 | 0 | line = r.readLine(); |
| 336 | |
} |
| 337 | |
} finally { |
| 338 | 0 | if (r != null) { |
| 339 | 0 | r.close(); |
| 340 | |
} |
| 341 | 0 | } |
| 342 | 0 | return result.toString(); |
| 343 | |
} |
| 344 | |
|
| 345 | 0 | |
| 346 | 0 | |
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | 0 | public static void setIncludePattern(final String patternList) { |
| 353 | 0 | includePattern = new FilePatternMatcher(patternList); |
| 354 | 0 | } |
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | 0 | |
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
public static void setExcludePattern(final String patternList) { |
| 364 | 0 | excludePattern = new FilePatternMatcher(patternList); |
| 365 | 0 | } |
| 366 | 0 | |
| 367 | 0 | |
| 368 | 0 | |
| 369 | |
|
| 370 | |
public static FilePatternMatcher getExcludePattern() { |
| 371 | 0 | return excludePattern; |
| 372 | 0 | } |
| 373 | 0 | |
| 374 | 0 | |
| 375 | 0 | |
| 376 | 0 | |
| 377 | |
public static FilePatternMatcher getIncludePattern() { |
| 378 | 0 | return includePattern; |
| 379 | 0 | } |
| 380 | 0 | |
| 381 | |
public static void setSymbolicNamesPattern(final String symbolicNamesPattern) throws ConfigurationException { |
| 382 | 0 | try { |
| 383 | 0 | ConfigurationOptions.symbolicNamesPattern = Pattern.compile(symbolicNamesPattern); |
| 384 | 0 | } catch (final PatternSyntaxException e) { |
| 385 | 0 | throw new ConfigurationException("Invalid regular expression for tags: " + e.getLocalizedMessage()); |
| 386 | 0 | } |
| 387 | 0 | } |
| 388 | 0 | |
| 389 | |
public static Pattern getSymbolicNamesPattern() { |
| 390 | 0 | return symbolicNamesPattern; |
| 391 | 0 | } |
| 392 | |
|
| 393 | |
public static void setBugzillaUrl(final String bugzillaUrl) { |
| 394 | 0 | ConfigurationOptions.webBugTracker = new Bugzilla(bugzillaUrl); |
| 395 | 0 | } |
| 396 | |
|
| 397 | 0 | public static void setMantisUrl(final String mantisUrl) { |
| 398 | 0 | ConfigurationOptions.webBugTracker = new Mantis(mantisUrl); |
| 399 | 0 | } |
| 400 | 0 | |
| 401 | 2 | public static BugTracker getWebBugtracker() { |
| 402 | 0 | return ConfigurationOptions.webBugTracker; |
| 403 | 0 | } |
| 404 | |
|
| 405 | 0 | public static void setOutputFormat(final String outputFormat) throws ConfigurationException { |
| 406 | 0 | if (!"html".equals(outputFormat) && !"xdoc".equals(outputFormat) && !"xml".equals(outputFormat)) { |
| 407 | 0 | throw new ConfigurationException("Invalid output format, use only 'html', 'xdoc' or 'xml'"); |
| 408 | 0 | } |
| 409 | 0 | ConfigurationOptions.outputFormat = outputFormat; |
| 410 | 0 | } |
| 411 | |
|
| 412 | |
public static String getOutputFormat() { |
| 413 | 6 | return outputFormat; |
| 414 | 0 | } |
| 415 | 0 | |
| 416 | 0 | public static MarkupSyntax getMarkupSyntax() { |
| 417 | 0 | if ("xdoc".equals(outputFormat)) { |
| 418 | 0 | return ReportConfig.XDOC; |
| 419 | 0 | } else if ("xml".equals(outputFormat)) { |
| 420 | 0 | return ReportConfig.XML; |
| 421 | |
} |
| 422 | 0 | return ReportConfig.HTML; |
| 423 | 0 | } |
| 424 | |
|
| 425 | 0 | public static void setWebRepositoryIntegration(final WebRepositoryIntegration webRepo) { |
| 426 | 0 | webRepository = webRepo; |
| 427 | 0 | } |
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
|
| 432 | 0 | |
| 433 | 0 | public static void setDefaultCssFile(final String cssName) { |
| 434 | 0 | cssHandler = new DefaultCssHandler(cssName); |
| 435 | 0 | } |
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | 0 | |
| 441 | 0 | |
| 442 | 0 | |
| 443 | |
public static void addNonDeveloperLogin(final String loginName) { |
| 444 | 0 | nonDeveloperLogins.add(loginName); |
| 445 | 0 | } |
| 446 | 0 | |
| 447 | 0 | |
| 448 | 0 | |
| 449 | 0 | |
| 450 | |
|
| 451 | 0 | public static Collection getNonDeveloperLogins() { |
| 452 | 0 | return nonDeveloperLogins; |
| 453 | 0 | } |
| 454 | 0 | |
| 455 | 0 | |
| 456 | 0 | |
| 457 | |
|
| 458 | 0 | |
| 459 | |
public static void setConfigFile(final String propertiesFilename) throws ConfigurationException { |
| 460 | 0 | if (propertiesFilename != null) { |
| 461 | 0 | InputStream is = null; |
| 462 | 0 | try { |
| 463 | 0 | is = new FileInputStream(propertiesFilename); |
| 464 | 0 | properties.load(is); |
| 465 | 0 | } catch (final FileNotFoundException e) { |
| 466 | 0 | throw new ConfigurationException("Unable to find the configuration file " + propertiesFilename); |
| 467 | 0 | } catch (final IOException e) { |
| 468 | 0 | throw new ConfigurationException("Problem reading the configuration file " + propertiesFilename); |
| 469 | |
} finally { |
| 470 | 0 | if (is != null) { |
| 471 | |
try { |
| 472 | 0 | is.close(); |
| 473 | 0 | } catch (final IOException e) { |
| 474 | 25 | throw new ConfigurationException("Problem closing stream to the configuration file " + propertiesFilename); |
| 475 | 0 | } |
| 476 | |
} |
| 477 | |
} |
| 478 | |
} |
| 479 | 0 | } |
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
public static Properties getConfigProperties() { |
| 486 | 75 | return properties; |
| 487 | |
} |
| 488 | |
} |