1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 22 * Use is subject to license terms. 23 */ 24 package org.opensolaris.opengrok.configuration; 25 26 import java.beans.XMLDecoder; 27 import java.beans.XMLEncoder; 28 import java.io.BufferedInputStream; 29 import java.io.BufferedOutputStream; 30 import java.io.File; 31 import java.io.FileInputStream; 32 import java.io.FileOutputStream; 33 import java.io.IOException; 34 import java.util.ArrayList; 35 import java.util.HashMap; 36 import java.util.List; 37 import java.util.Map; 38 import org.opensolaris.opengrok.history.Repository; 39 import org.opensolaris.opengrok.index.IgnoredNames; 40 41 /** 42 * Placeholder class for all configuration variables. Due to the multithreaded 43 * nature of the web application, each thread will use the same instance of the 44 * configuration object for each page request. Class and methods should have 45 * package scope, but that didn't work with the XMLDecoder/XMLEncoder. 46 */ 47 public final class Configuration { 48 private String ctags; 49 private boolean historyCache; 50 private int historyCacheTime; 51 private List<Project> projects; 52 private String sourceRoot; 53 private String dataRoot; 54 private Map<String, Repository> repositories; 55 private String urlPrefix; 56 private boolean generateHtml; 57 private Project defaultProject; 58 private int indexWordLimit; 59 private boolean verbose; 60 private boolean allowLeadingWildcard; 61 private IgnoredNames ignoredNames; 62 private String userPage; 63 private String bugPage; 64 private String bugPattern; 65 private String reviewPage; 66 private String reviewPattern; 67 private String webappLAF; 68 private boolean remoteScmSupported; 69 private boolean optimizeDatabase; 70 private boolean useLuceneLocking; 71 private boolean compressXref; 72 private boolean indexVersionedFilesOnly; 73 74 /** Creates a new instance of Configuration */ 75 public Configuration() { 76 setHistoryCache(true); 77 setHistoryCacheTime(30); 78 setProjects(new ArrayList<Project>()); 79 setRepositories(new HashMap<String, Repository>()); 80 setUrlPrefix("/source/s?"); 81 setCtags("ctags"); 82 setIndexWordLimit(60000); 83 setVerbose(false); 84 setGenerateHtml(true); 85 setQuickContextScan(true); 86 setIgnoredNames(new IgnoredNames()); 87 setUserPage("http://www.opensolaris.org/viewProfile.jspa?username="); 88 setBugPage("http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id="); 89 setBugPattern("\\b([12456789][0-9]{6})\\b"); 90 setReviewPage("http://www.opensolaris.org/os/community/arc/caselog/"); 91 setReviewPattern("\\b(\\d{4}/\\d{3})\\b"); // in form e.g. PSARC 2008/305 92 setWebappLAF("default"); 93 setRemoteScmSupported(false); 94 setOptimizeDatabase(true); 95 setUsingLuceneLocking(false); 96 setCompressXref(true); 97 setIndexVersionedFilesOnly(false); 98 } 99 100 public String getCtags() { 101 return ctags; 102 } 103 104 public void setCtags(String ctags) { 105 this.ctags = ctags; 106 } 107 108 public boolean isHistoryCache() { 109 return historyCache; 110 } 111 112 public void setHistoryCache(boolean historyCache) { 113 this.historyCache = historyCache; 114 } 115 116 public int getHistoryCacheTime() { 117 return historyCacheTime; 118 } 119 120 public void setHistoryCacheTime(int historyCacheTime) { 121 this.historyCacheTime = historyCacheTime; 122 } 123 124 public List<Project> getProjects() { 125 return projects; 126 } 127 128 public void setProjects(List<Project> projects) { 129 this.projects = projects; 130 } 131 132 public String getSourceRoot() { 133 return sourceRoot; 134 } 135 136 public void setSourceRoot(String sourceRoot) { 137 this.sourceRoot = sourceRoot; 138 } 139 140 public String getDataRoot() { 141 return dataRoot; 142 } 143 144 public void setDataRoot(String dataRoot) { 145 this.dataRoot = dataRoot; 146 } 147 148 public Map<String, Repository> getRepositories() { 149 return repositories; 150 } 151 152 public void setRepositories(Map<String, Repository> repositories) { 153 this.repositories = repositories; 154 } 155 156 public String getUrlPrefix() { 157 return urlPrefix; 158 } 159 160 public void setUrlPrefix(String urlPrefix) { 161 this.urlPrefix = urlPrefix; 162 } 163 164 public void setGenerateHtml(boolean generateHtml) { 165 this.generateHtml = generateHtml; 166 } 167 168 public boolean isGenerateHtml() { 169 return generateHtml; 170 } 171 172 public void setDefaultProject(Project defaultProject) { 173 this.defaultProject = defaultProject; 174 } 175 176 public Project getDefaultProject() { 177 return defaultProject; 178 } 179 180 public int getIndexWordLimit() { 181 return indexWordLimit; 182 } 183 184 public void setIndexWordLimit(int indexWordLimit) { 185 this.indexWordLimit = indexWordLimit; 186 } 187 188 public boolean isVerbose() { 189 return verbose; 190 } 191 192 public void setVerbose(boolean verbose) { 193 this.verbose = verbose; 194 } 195 196 public void setAllowLeadingWildcard(boolean allowLeadingWildcard) { 197 this.allowLeadingWildcard = allowLeadingWildcard; 198 } 199 200 public boolean isAllowLeadingWildcard() { 201 return allowLeadingWildcard; 202 } 203 204 private boolean quickContextScan; 205 206 public boolean isQuickContextScan() { 207 return quickContextScan; 208 } 209 210 public void setQuickContextScan(boolean quickContextScan) { 211 this.quickContextScan = quickContextScan; 212 } 213 214 public void setIgnoredNames(IgnoredNames ignoredNames) { 215 this.ignoredNames = ignoredNames; 216 } 217 218 public IgnoredNames getIgnoredNames() { 219 return ignoredNames; 220 } 221 222 public void setUserPage(String userPage) { 223 this.userPage = userPage; 224 } 225 226 public String getUserPage() { 227 return userPage; 228 } 229 230 public void setBugPage(String bugPage) { 231 this.bugPage = bugPage; 232 } 233 234 public String getBugPage() { 235 return bugPage; 236 } 237 238 public void setBugPattern(String bugPattern) { 239 this.bugPattern = bugPattern; 240 } 241 242 public String getBugPattern() { 243 return bugPattern; 244 } 245 246 public String getReviewPage() { 247 return reviewPage; 248 } 249 250 public void setReviewPage(String reviewPage) { 251 this.reviewPage = reviewPage; 252 } 253 254 public String getReviewPattern() { 255 return reviewPattern; 256 } 257 258 public void setReviewPattern(String reviewPattern) { 259 this.reviewPattern = reviewPattern; 260 } 261 262 public String getWebappLAF() { 263 return webappLAF; 264 } 265 266 public void setWebappLAF(String webappLAF) { 267 this.webappLAF = webappLAF; 268 } 269 270 public boolean isRemoteScmSupported() { 271 return remoteScmSupported; 272 } 273 274 public void setRemoteScmSupported(boolean remoteScmSupported) { 275 this.remoteScmSupported = remoteScmSupported; 276 } 277 278 public boolean isOptimizeDatabase() { 279 return optimizeDatabase; 280 } 281 282 public void setOptimizeDatabase(boolean optimizeDatabase) { 283 this.optimizeDatabase = optimizeDatabase; 284 } 285 286 public boolean isUsingLuceneLocking() { 287 return useLuceneLocking; 288 } 289 290 public void setUsingLuceneLocking(boolean useLuceneLocking) { 291 this.useLuceneLocking = useLuceneLocking; 292 } 293 294 public void setCompressXref(boolean compressXref) { 295 this.compressXref = compressXref; 296 } 297 298 public boolean isCompressXref() { 299 return compressXref; 300 } 301 302 public boolean isIndexVersionedFilesOnly() { 303 return indexVersionedFilesOnly; 304 } 305 306 public void setIndexVersionedFilesOnly(boolean indexVersionedFilesOnly) { 307 this.indexVersionedFilesOnly = indexVersionedFilesOnly; 308 } 309 /** 310 * Write the current configuration to a file 311 * @param file the file to write the configuration into 312 * @throws IOException if an error occurs 313 */ 314 public void write(File file) throws IOException { 315 final FileOutputStream out = new FileOutputStream(file); 316 try { 317 XMLEncoder e = new XMLEncoder(new BufferedOutputStream(out)); 318 e.writeObject(this); 319 e.close(); 320 } finally { 321 out.close(); 322 } 323 } 324 325 public static Configuration read(File file) throws IOException { 326 327 final Object ret; 328 329 final FileInputStream in = new FileInputStream(file); 330 try { 331 XMLDecoder d = new XMLDecoder(new BufferedInputStream(in)); 332 ret = d.readObject(); 333 d.close(); 334 } finally { 335 in.close(); 336 } 337 338 if (!(ret instanceof Configuration)) { 339 throw new IOException("Not a valid config file"); 340 } 341 return (Configuration)ret; 342 } 343 } 344