Configuration.java revision 667
58N/A/*
58N/A * CDDL HEADER START
58N/A *
58N/A * The contents of this file are subject to the terms of the
58N/A * Common Development and Distribution License (the "License").
58N/A * You may not use this file except in compliance with the License.
58N/A *
58N/A * See LICENSE.txt included in this distribution for the specific
58N/A * language governing permissions and limitations under the License.
58N/A *
58N/A * When distributing Covered Code, include this CDDL HEADER in each
58N/A * file and include the License file at LICENSE.txt.
58N/A * If applicable, add the following below this CDDL HEADER, with the
58N/A * fields enclosed by brackets "[]" replaced with your own identifying
58N/A * information: Portions Copyright [yyyy] [name of copyright owner]
58N/A *
58N/A * CDDL HEADER END
58N/A */
58N/A
58N/A/*
1123N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
58N/A * Use is subject to license terms.
58N/A */
58N/Apackage org.opensolaris.opengrok.configuration;
234N/A
234N/Aimport java.beans.XMLDecoder;
234N/Aimport java.beans.XMLEncoder;
234N/Aimport java.io.BufferedInputStream;
639N/Aimport java.io.BufferedOutputStream;
639N/Aimport java.io.ByteArrayInputStream;
234N/Aimport java.io.ByteArrayOutputStream;
234N/Aimport java.io.File;
234N/Aimport java.io.FileInputStream;
234N/Aimport java.io.FileOutputStream;
639N/Aimport java.io.IOException;
639N/Aimport java.io.InputStream;
58N/Aimport java.io.OutputStream;
1185N/Aimport java.util.ArrayList;
667N/Aimport java.util.Date;
1185N/Aimport java.util.HashMap;
1016N/Aimport java.util.List;
58N/Aimport org.opensolaris.opengrok.history.RepositoryInfo;
1185N/Aimport org.opensolaris.opengrok.index.IgnoredNames;
1016N/A
1185N/A/**
1185N/A * Placeholder class for all configuration variables. Due to the multithreaded
1185N/A * nature of the web application, each thread will use the same instance of the
1185N/A * configuration object for each page request. Class and methods should have
664N/A * package scope, but that didn't work with the XMLDecoder/XMLEncoder.
1026N/A */
112N/Apublic final class Configuration {
58N/A private String ctags;
58N/A private boolean historyCache;
77N/A private int historyCacheTime;
77N/A private List<Project> projects;
77N/A private String sourceRoot;
77N/A private String dataRoot;
58N/A private List<RepositoryInfo> repositories;
418N/A private String urlPrefix;
58N/A private boolean generateHtml;
773N/A private Project defaultProject;
773N/A private int indexWordLimit;
58N/A private boolean verbose;
773N/A private boolean allowLeadingWildcard;
773N/A private IgnoredNames ignoredNames;
773N/A private String userPage;
773N/A private String bugPage;
58N/A private String bugPattern;
773N/A private String reviewPage;
773N/A private String reviewPattern;
773N/A private String webappLAF;
773N/A private boolean remoteScmSupported;
58N/A private boolean optimizeDatabase;
58N/A private boolean useLuceneLocking;
58N/A private boolean compressXref;
664N/A private boolean indexVersionedFilesOnly;
58N/A
65N/A /** Creates a new instance of Configuration */
894N/A public Configuration() {
77N/A setHistoryCache(true);
99N/A setHistoryCacheTime(30);
99N/A setProjects(new ArrayList<Project>());
1115N/A setRepositories(new ArrayList<RepositoryInfo>());
1115N/A setUrlPrefix("/source/s?");
125N/A setCtags("ctags");
112N/A setIndexWordLimit(60000);
1026N/A setVerbose(false);
129N/A setGenerateHtml(true);
1100N/A setQuickContextScan(true);
129N/A setIgnoredNames(new IgnoredNames());
129N/A setUserPage("http://www.opensolaris.org/viewProfile.jspa?username=");
318N/A setBugPage("http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=");
318N/A setBugPattern("\\b([12456789][0-9]{6})\\b");
144N/A setReviewPage("http://www.opensolaris.org/os/community/arc/caselog/");
173N/A setReviewPattern("\\b(\\d{4}/\\d{3})\\b"); // in form e.g. PSARC 2008/305
253N/A setWebappLAF("default");
296N/A setRemoteScmSupported(false);
335N/A setOptimizeDatabase(true);
480N/A setUsingLuceneLocking(false);
816N/A setCompressXref(true);
816N/A setIndexVersionedFilesOnly(false);
833N/A }
833N/A
1185N/A public String getCtags() {
1016N/A return ctags;
1123N/A }
1125N/A
1185N/A public void setCtags(String ctags) {
1185N/A this.ctags = ctags;
993N/A }
1185N/A
1185N/A public boolean isHistoryCache() {
1185N/A return historyCache;
1185N/A }
1185N/A
1185N/A public void setHistoryCache(boolean historyCache) {
1185N/A this.historyCache = historyCache;
1185N/A }
1185N/A
1185N/A public int getHistoryCacheTime() {
1185N/A return historyCacheTime;
1185N/A }
1185N/A
1185N/A public void setHistoryCacheTime(int historyCacheTime) {
1185N/A this.historyCacheTime = historyCacheTime;
1185N/A }
1185N/A
1185N/A public List<Project> getProjects() {
1185N/A return projects;
1185N/A }
1185N/A
1185N/A public void setProjects(List<Project> projects) {
1185N/A this.projects = projects;
993N/A }
993N/A
993N/A public String getSourceRoot() {
1185N/A return sourceRoot;
993N/A }
993N/A
937N/A public void setSourceRoot(String sourceRoot) {
58N/A this.sourceRoot = sourceRoot;
58N/A }
816N/A
58N/A public String getDataRoot() {
58N/A return dataRoot;
773N/A }
58N/A
664N/A public void setDataRoot(String dataRoot) {
58N/A this.dataRoot = dataRoot;
850N/A }
1118N/A
870N/A public List<RepositoryInfo> getRepositories() {
870N/A return repositories;
99N/A }
1115N/A
101N/A public void setRepositories(List<RepositoryInfo> repositories) {
106N/A this.repositories = repositories;
112N/A }
1026N/A
129N/A public String getUrlPrefix() {
129N/A return urlPrefix;
129N/A }
875N/A
318N/A public void setUrlPrefix(String urlPrefix) {
144N/A this.urlPrefix = urlPrefix;
173N/A }
253N/A
296N/A public void setGenerateHtml(boolean generateHtml) {
335N/A this.generateHtml = generateHtml;
480N/A }
816N/A
816N/A public boolean isGenerateHtml() {
993N/A return generateHtml;
1016N/A }
1185N/A
1185N/A public void setDefaultProject(Project defaultProject) {
58N/A this.defaultProject = defaultProject;
937N/A }
1185N/A
1185N/A public Project getDefaultProject() {
1185N/A return defaultProject;
1185N/A }
1185N/A
1185N/A public int getIndexWordLimit() {
1185N/A return indexWordLimit;
1185N/A }
1185N/A
1185N/A public void setIndexWordLimit(int indexWordLimit) {
1185N/A this.indexWordLimit = indexWordLimit;
1185N/A }
1185N/A
1185N/A public boolean isVerbose() {
1185N/A return verbose;
1185N/A }
1185N/A
1185N/A public void setVerbose(boolean verbose) {
1185N/A this.verbose = verbose;
1185N/A }
1185N/A
1185N/A public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
1185N/A this.allowLeadingWildcard = allowLeadingWildcard;
1185N/A }
58N/A
58N/A public boolean isAllowLeadingWildcard() {
58N/A return allowLeadingWildcard;
937N/A }
58N/A
58N/A private boolean quickContextScan;
58N/A
937N/A public boolean isQuickContextScan() {
816N/A return quickContextScan;
816N/A }
816N/A
816N/A public void setQuickContextScan(boolean quickContextScan) {
816N/A this.quickContextScan = quickContextScan;
816N/A }
816N/A
816N/A public void setIgnoredNames(IgnoredNames ignoredNames) {
816N/A this.ignoredNames = ignoredNames;
816N/A }
816N/A
816N/A public IgnoredNames getIgnoredNames() {
816N/A return ignoredNames;
816N/A }
816N/A
773N/A public void setUserPage(String userPage) {
773N/A this.userPage = userPage;
773N/A }
773N/A
773N/A public String getUserPage() {
773N/A return userPage;
58N/A }
58N/A
58N/A public void setBugPage(String bugPage) {
773N/A this.bugPage = bugPage;
773N/A }
773N/A
773N/A public String getBugPage() {
773N/A return bugPage;
58N/A }
58N/A
58N/A public void setBugPattern(String bugPattern) {
773N/A this.bugPattern = bugPattern;
773N/A }
773N/A
773N/A public String getBugPattern() {
773N/A return bugPattern;
773N/A }
773N/A
773N/A public String getReviewPage() {
773N/A return reviewPage;
58N/A }
58N/A
58N/A public void setReviewPage(String reviewPage) {
773N/A this.reviewPage = reviewPage;
773N/A }
773N/A
773N/A public String getReviewPattern() {
773N/A return reviewPattern;
773N/A }
773N/A
58N/A public void setReviewPattern(String reviewPattern) {
58N/A this.reviewPattern = reviewPattern;
58N/A }
773N/A
773N/A public String getWebappLAF() {
773N/A return webappLAF;
773N/A }
773N/A
773N/A public void setWebappLAF(String webappLAF) {
773N/A this.webappLAF = webappLAF;
773N/A }
773N/A
773N/A public boolean isRemoteScmSupported() {
773N/A return remoteScmSupported;
773N/A }
773N/A
773N/A public void setRemoteScmSupported(boolean remoteScmSupported) {
773N/A this.remoteScmSupported = remoteScmSupported;
773N/A }
773N/A
773N/A public boolean isOptimizeDatabase() {
773N/A return optimizeDatabase;
773N/A }
773N/A
773N/A public void setOptimizeDatabase(boolean optimizeDatabase) {
773N/A this.optimizeDatabase = optimizeDatabase;
937N/A }
58N/A
58N/A public boolean isUsingLuceneLocking() {
58N/A return useLuceneLocking;
937N/A }
58N/A
58N/A public void setUsingLuceneLocking(boolean useLuceneLocking) {
58N/A this.useLuceneLocking = useLuceneLocking;
937N/A }
58N/A
58N/A public void setCompressXref(boolean compressXref) {
58N/A this.compressXref = compressXref;
937N/A }
58N/A
58N/A public boolean isCompressXref() {
58N/A return compressXref;
937N/A }
58N/A
58N/A public boolean isIndexVersionedFilesOnly() {
58N/A return indexVersionedFilesOnly;
937N/A }
58N/A
58N/A public void setIndexVersionedFilesOnly(boolean indexVersionedFilesOnly) {
58N/A this.indexVersionedFilesOnly = indexVersionedFilesOnly;
937N/A }
664N/A
58N/A public Date getDateForLastIndexRun() {
58N/A File timestamp = new File(getDataRoot(), "timestamp");
937N/A return new Date(timestamp.lastModified());
664N/A }
58N/A
58N/A /**
937N/A * Write the current configuration to a file
58N/A * @param file the file to write the configuration into
58N/A * @throws IOException if an error occurs
58N/A */
937N/A public void write(File file) throws IOException {
1185N/A final FileOutputStream out = new FileOutputStream(file);
1185N/A try {
1185N/A this.encodeObject(out);
1185N/A } finally {
1185N/A out.close();
58N/A }
58N/A }
58N/A
937N/A public String getXMLRepresentationAsString() {
65N/A ByteArrayOutputStream bos = new ByteArrayOutputStream();
65N/A this.encodeObject(bos);
65N/A return bos.toString();
937N/A }
65N/A
65N/A private void encodeObject(OutputStream out) {
65N/A XMLEncoder e = new XMLEncoder(new BufferedOutputStream(out));
937N/A e.writeObject(this);
77N/A e.close();
77N/A }
77N/A
937N/A public static Configuration read(File file) throws IOException {
77N/A final FileInputStream in = new FileInputStream(file);
77N/A try {
77N/A return decodeObject(in);
99N/A } finally {
99N/A in.close();
99N/A }
99N/A }
99N/A
99N/A
99N/A
99N/A public static Configuration makeXMLStringAsConfiguration(String xmlconfig) throws IOException {
99N/A final Configuration ret;
99N/A final ByteArrayInputStream in = new ByteArrayInputStream(xmlconfig.getBytes());
99N/A ret = decodeObject(in);
99N/A return ret;
99N/A }
99N/A
99N/A private static Configuration decodeObject(InputStream in) throws IOException {
99N/A XMLDecoder d = new XMLDecoder(new BufferedInputStream(in));
937N/A final Object ret = d.readObject();
1115N/A d.close();
1115N/A
1115N/A if (!(ret instanceof Configuration)) {
1115N/A throw new IOException("Not a valid config file");
1115N/A }
1115N/A return (Configuration)ret;
1115N/A }
1115N/A
125N/A}
125N/A