Configuration.java revision 773
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
1102N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
919N/A * See LICENSE.txt included in this distribution for the specific
919N/A * language governing permissions and limitations under the License.
919N/A *
919N/A * When distributing Covered Code, include this CDDL HEADER in each
919N/A * file and include the License file at LICENSE.txt.
919N/A * If applicable, add the following below this CDDL HEADER, with the
919N/A * fields enclosed by brackets "[]" replaced with your own identifying
919N/A * information: Portions Copyright [yyyy] [name of copyright owner]
919N/A *
919N/A * CDDL HEADER END
919N/A */
919N/A
919N/A/*
919N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
919N/A * Use is subject to license terms.
919N/A */
919N/Apackage org.opensolaris.opengrok.configuration;
0N/A
0N/Aimport java.beans.XMLDecoder;
0N/Aimport java.beans.XMLEncoder;
156N/Aimport java.io.BufferedInputStream;
493N/Aimport java.io.BufferedOutputStream;
0N/Aimport java.io.ByteArrayInputStream;
970N/Aimport java.io.ByteArrayOutputStream;
970N/Aimport java.io.File;
970N/Aimport java.io.FileInputStream;
970N/Aimport java.io.FileOutputStream;
970N/Aimport java.io.IOException;
970N/Aimport java.io.InputStream;
970N/Aimport java.io.OutputStream;
970N/Aimport java.util.ArrayList;
970N/Aimport java.util.Date;
970N/Aimport java.util.List;
970N/Aimport org.opensolaris.opengrok.history.RepositoryInfo;
970N/Aimport org.opensolaris.opengrok.index.IgnoredNames;
970N/A
970N/A/**
970N/A * Placeholder class for all configuration variables. Due to the multithreaded
970N/A * nature of the web application, each thread will use the same instance of the
970N/A * configuration object for each page request. Class and methods should have
970N/A * package scope, but that didn't work with the XMLDecoder/XMLEncoder.
970N/A */
970N/Apublic final class Configuration {
970N/A private String ctags;
970N/A
970N/A /** Should the history log be cached? */
970N/A private boolean historyCache;
970N/A /**
0N/A * The maximum time in milliseconds {@code HistoryCache.get()} can take
950N/A * before its result is cached.
0N/A */
911N/A private int historyCacheTime;
950N/A
950N/A /** Should the history cache be stored in a database? */
911N/A private boolean historyCacheInDB;
0N/A
493N/A private List<Project> projects;
493N/A private String sourceRoot;
0N/A private String dataRoot;
0N/A private List<RepositoryInfo> repositories;
156N/A private String urlPrefix;
156N/A private boolean generateHtml;
0N/A private Project defaultProject;
0N/A private int indexWordLimit;
950N/A private boolean verbose;
950N/A private boolean allowLeadingWildcard;
950N/A private IgnoredNames ignoredNames;
950N/A private String userPage;
950N/A private String bugPage;
950N/A private String bugPattern;
1102N/A private String reviewPage;
1160N/A private String reviewPattern;
1160N/A private String webappLAF;
364N/A private boolean remoteScmSupported;
156N/A private boolean optimizeDatabase;
156N/A private boolean useLuceneLocking;
0N/A private boolean compressXref;
591N/A private boolean indexVersionedFilesOnly;
947N/A
947N/A /** Creates a new instance of Configuration */
591N/A public Configuration() {
591N/A setHistoryCache(true);
591N/A setHistoryCacheTime(30);
947N/A setHistoryCacheInDB(false);
947N/A setProjects(new ArrayList<Project>());
947N/A setRepositories(new ArrayList<RepositoryInfo>());
947N/A setUrlPrefix("/source/s?");
947N/A setCtags("ctags");
947N/A setIndexWordLimit(60000);
947N/A setVerbose(false);
947N/A setGenerateHtml(true);
947N/A setQuickContextScan(true);
947N/A setIgnoredNames(new IgnoredNames());
947N/A setUserPage("http://www.opensolaris.org/viewProfile.jspa?username=");
947N/A setBugPage("http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=");
947N/A setBugPattern("\\b([12456789][0-9]{6})\\b");
947N/A setReviewPage("http://www.opensolaris.org/os/community/arc/caselog/");
947N/A setReviewPattern("\\b(\\d{4}/\\d{3})\\b"); // in form e.g. PSARC 2008/305
947N/A setWebappLAF("default");
0N/A setRemoteScmSupported(false);
156N/A setOptimizeDatabase(true);
493N/A setUsingLuceneLocking(false);
493N/A setCompressXref(true);
156N/A setIndexVersionedFilesOnly(false);
493N/A }
493N/A
837N/A public String getCtags() {
837N/A return ctags;
846N/A }
493N/A
156N/A public void setCtags(String ctags) {
493N/A this.ctags = ctags;
493N/A }
493N/A
364N/A /**
0N/A * Should the history log be cached?
493N/A * @return {@code true} if a {@code HistoryCache} implementation should
493N/A * be used, {@code false} otherwise
156N/A */
493N/A public boolean isHistoryCache() {
493N/A return historyCache;
0N/A }
1196N/A
1196N/A /**
1196N/A * Set whether history should be cached.
1196N/A * @param historyCache if {@code true} enable history cache
1196N/A */
967N/A public void setHistoryCache(boolean historyCache) {
967N/A this.historyCache = historyCache;
967N/A }
970N/A
980N/A /**
0N/A * How long can a history request take before it's cached? If the time
980N/A * is exceeded, the result is cached. This setting only affects
339N/A * {@code FileHistoryCache}.
970N/A *
970N/A * @return the maximum time in milliseconds a history request can take
970N/A * before it's cached
970N/A */
0N/A public int getHistoryCacheTime() {
837N/A return historyCacheTime;
837N/A }
838N/A
837N/A /**
837N/A * Set the maximum time a history request can take before it's cached.
967N/A * This setting is only respected if {@code FileHistoryCache} is used.
967N/A *
967N/A * @param historyCacheTime maximum time in milliseconds
779N/A */
970N/A public void setHistoryCacheTime(int historyCacheTime) {
838N/A this.historyCacheTime = historyCacheTime;
591N/A }
967N/A
0N/A /**
0N/A * Should the history cache be stored in a database? If yes,
0N/A * {@code JDBCHistoryCache} will be used to cache the history; otherwise,
0N/A * {@code FileHistoryCache} is used.
591N/A *
0N/A * @return whether the history cache should be stored in a database
339N/A */
339N/A public boolean isHistoryCacheInDB() {
591N/A return historyCacheInDB;
493N/A }
970N/A
970N/A /**
970N/A * Set whether the history cache should be stored in a database, and
970N/A * {@code JDBCHistoryCache} should be used instead of {@code
970N/A * FileHistoryCache}.
970N/A *
970N/A * @param historyCacheInDB whether the history cached should be stored in
970N/A * a database
837N/A */
837N/A public void setHistoryCacheInDB(boolean historyCacheInDB) {
967N/A this.historyCacheInDB = historyCacheInDB;
967N/A }
967N/A
779N/A public List<Project> getProjects() {
156N/A return projects;
156N/A }
967N/A
591N/A public void setProjects(List<Project> projects) {
1183N/A this.projects = projects;
591N/A }
591N/A
591N/A public String getSourceRoot() {
935N/A return sourceRoot;
967N/A }
967N/A
967N/A public void setSourceRoot(String sourceRoot) {
0N/A this.sourceRoot = sourceRoot;
}
public String getDataRoot() {
return dataRoot;
}
public void setDataRoot(String dataRoot) {
this.dataRoot = dataRoot;
}
public List<RepositoryInfo> getRepositories() {
return repositories;
}
public void setRepositories(List<RepositoryInfo> repositories) {
this.repositories = repositories;
}
public String getUrlPrefix() {
return urlPrefix;
}
public void setUrlPrefix(String urlPrefix) {
this.urlPrefix = urlPrefix;
}
public void setGenerateHtml(boolean generateHtml) {
this.generateHtml = generateHtml;
}
public boolean isGenerateHtml() {
return generateHtml;
}
public void setDefaultProject(Project defaultProject) {
this.defaultProject = defaultProject;
}
public Project getDefaultProject() {
return defaultProject;
}
public int getIndexWordLimit() {
return indexWordLimit;
}
public void setIndexWordLimit(int indexWordLimit) {
this.indexWordLimit = indexWordLimit;
}
public boolean isVerbose() {
return verbose;
}
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
this.allowLeadingWildcard = allowLeadingWildcard;
}
public boolean isAllowLeadingWildcard() {
return allowLeadingWildcard;
}
private boolean quickContextScan;
public boolean isQuickContextScan() {
return quickContextScan;
}
public void setQuickContextScan(boolean quickContextScan) {
this.quickContextScan = quickContextScan;
}
public void setIgnoredNames(IgnoredNames ignoredNames) {
this.ignoredNames = ignoredNames;
}
public IgnoredNames getIgnoredNames() {
return ignoredNames;
}
public void setUserPage(String userPage) {
this.userPage = userPage;
}
public String getUserPage() {
return userPage;
}
public void setBugPage(String bugPage) {
this.bugPage = bugPage;
}
public String getBugPage() {
return bugPage;
}
public void setBugPattern(String bugPattern) {
this.bugPattern = bugPattern;
}
public String getBugPattern() {
return bugPattern;
}
public String getReviewPage() {
return reviewPage;
}
public void setReviewPage(String reviewPage) {
this.reviewPage = reviewPage;
}
public String getReviewPattern() {
return reviewPattern;
}
public void setReviewPattern(String reviewPattern) {
this.reviewPattern = reviewPattern;
}
public String getWebappLAF() {
return webappLAF;
}
public void setWebappLAF(String webappLAF) {
this.webappLAF = webappLAF;
}
public boolean isRemoteScmSupported() {
return remoteScmSupported;
}
public void setRemoteScmSupported(boolean remoteScmSupported) {
this.remoteScmSupported = remoteScmSupported;
}
public boolean isOptimizeDatabase() {
return optimizeDatabase;
}
public void setOptimizeDatabase(boolean optimizeDatabase) {
this.optimizeDatabase = optimizeDatabase;
}
public boolean isUsingLuceneLocking() {
return useLuceneLocking;
}
public void setUsingLuceneLocking(boolean useLuceneLocking) {
this.useLuceneLocking = useLuceneLocking;
}
public void setCompressXref(boolean compressXref) {
this.compressXref = compressXref;
}
public boolean isCompressXref() {
return compressXref;
}
public boolean isIndexVersionedFilesOnly() {
return indexVersionedFilesOnly;
}
public void setIndexVersionedFilesOnly(boolean indexVersionedFilesOnly) {
this.indexVersionedFilesOnly = indexVersionedFilesOnly;
}
public Date getDateForLastIndexRun() {
File timestamp = new File(getDataRoot(), "timestamp");
return new Date(timestamp.lastModified());
}
/**
* Write the current configuration to a file
* @param file the file to write the configuration into
* @throws IOException if an error occurs
*/
public void write(File file) throws IOException {
final FileOutputStream out = new FileOutputStream(file);
try {
this.encodeObject(out);
} finally {
out.close();
}
}
public String getXMLRepresentationAsString() {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
this.encodeObject(bos);
return bos.toString();
}
private void encodeObject(OutputStream out) {
XMLEncoder e = new XMLEncoder(new BufferedOutputStream(out));
e.writeObject(this);
e.close();
}
public static Configuration read(File file) throws IOException {
final FileInputStream in = new FileInputStream(file);
try {
return decodeObject(in);
} finally {
in.close();
}
}
public static Configuration makeXMLStringAsConfiguration(String xmlconfig) throws IOException {
final Configuration ret;
final ByteArrayInputStream in = new ByteArrayInputStream(xmlconfig.getBytes());
ret = decodeObject(in);
return ret;
}
private static Configuration decodeObject(InputStream in) throws IOException {
XMLDecoder d = new XMLDecoder(new BufferedInputStream(in));
final Object ret = d.readObject();
d.close();
if (!(ret instanceof Configuration)) {
throw new IOException("Not a valid config file");
}
return (Configuration)ret;
}
}