Configuration.java revision 1470
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/*
1291N/A * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
58N/A * Portions Copyright 2011, 2012 Jens Elkner.
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;
1287N/Aimport java.io.BufferedOutputStream;
639N/Aimport java.io.BufferedReader;
639N/Aimport java.io.ByteArrayInputStream;
234N/Aimport java.io.ByteArrayOutputStream;
234N/Aimport java.io.File;
234N/Aimport java.io.FileInputStream;
1289N/Aimport java.io.FileNotFoundException;
234N/Aimport java.io.FileOutputStream;
639N/Aimport java.io.FileReader;
639N/Aimport java.io.IOException;
58N/Aimport java.io.InputStream;
1185N/Aimport java.io.OutputStream;
667N/Aimport java.text.SimpleDateFormat;
1185N/Aimport java.util.ArrayList;
1016N/Aimport java.util.Collections;
1291N/Aimport java.util.Date;
58N/Aimport java.util.HashMap;
1185N/Aimport java.util.HashSet;
1016N/Aimport java.util.List;
1185N/Aimport java.util.Map;
664N/Aimport java.util.Set;
1026N/Aimport java.util.logging.Level;
112N/Aimport java.util.logging.Logger;
1195N/A
58N/Aimport org.opensolaris.opengrok.history.RepositoryInfo;
58N/Aimport org.opensolaris.opengrok.index.Filter;
77N/Aimport org.opensolaris.opengrok.index.IgnoredNames;
77N/Aimport org.opensolaris.opengrok.util.IOUtils;
77N/Aimport org.opensolaris.opengrok.web.Prefix;
77N/A
58N/A/**
418N/A * Placeholder class for all configuration variables. Due to the multithreaded
1327N/A * nature of the web application, each thread will use the same instance of the
1327N/A * configuration object for each page request. Class and methods should have
1327N/A * package scope, but that didn't work with the XMLDecoder/XMLEncoder.
1327N/A */
1327N/Apublic final class Configuration {
1327N/A /** The common property key prefix used to access opengrok system properties */
58N/A public static final String PROPERTY_KEY_PREFIX = "org.opensolaris.opengrok.";
773N/A /** The property name used to obtain the ctags command to use. */
773N/A public static final String CTAGS_CMD_PROPERTY_KEY =
58N/A PROPERTY_KEY_PREFIX + "analysis.Ctags";
773N/A /** The command to use if no ctags command was given explicitly */
773N/A public static final String CTAGS_CMD_FALLBACK = "ctags";
773N/A
773N/A /** Relative path wrt. servlet context to the default CSS to use */
58N/A public static final String DEFAULT_STYLE = "static/default";
773N/A
773N/A /** The string property name used to get the date format pattern to use for
773N/A * directory listings in the web app. It needs to be a pattern acceptable
773N/A * by {@link java.text.SimpleDateFormat}.
58N/A * @see #DIRLIST_DATE_DEFAULT */
58N/A public static final String DIRLIST_DATE_PROPERTY_KEY =
58N/A PROPERTY_KEY_PREFIX + "web.dirlist.date";
664N/A /** the default/fallback value to use wrt. {@link #DIRLIST_DATE_PROPERTY_KEY} */
58N/A public static final String DIRLIST_DATE_DEFAULT = "dd-MMM-yyyy";
65N/A
894N/A /** The boolean property name used to determine, whether the web app should
77N/A * show {@code Today} instead of the last modified date, if the file has
99N/A * been changed in the last 24 hours. */
99N/A public static final String DIRLIST_TODAY_PROPERTY_KEY =
1115N/A PROPERTY_KEY_PREFIX + "web.dirlist.today";
1115N/A /** the default/fallback value to use wrt. {@link #DIRLIST_TODAY_PROPERTY_KEY} */
125N/A public static final boolean DIRLIST_TODAY_DEFAULT = false;
112N/A
1026N/A
129N/A private String ctags;
1100N/A /**
129N/A * Should the history log be cached?
129N/A */
318N/A private boolean historyCache;
318N/A /**
144N/A * The maximum time in milliseconds {@code HistoryCache.get()} can take
173N/A * before its result is cached.
253N/A */
296N/A private int historyCacheTime;
335N/A /**
480N/A * Should the history cache be stored in a database?
816N/A */
816N/A private boolean historyCacheInDB;
833N/A
833N/A private List<Project> projects;
1185N/A private String sourceRoot;
1016N/A private String dataRoot;
1123N/A private List<RepositoryInfo> repositories;
1125N/A private String urlPrefix;
1218N/A private boolean generateHtml;
1185N/A /**
1326N/A * Default project will be used, when no project is selected and no project
993N/A * is in cookie, so basically only the first time you open the first page,
1185N/A * or when you clear your web cookies
1185N/A */
1190N/A private Project defaultProject;
1185N/A private int indexWordLimit;
1185N/A private boolean verbose;
1252N/A //if below is set, then we count how many files per project we need to process and print percentage of completion per project
1185N/A private boolean printProgress;
1185N/A private boolean allowLeadingWildcard;
1185N/A private IgnoredNames ignoredNames;
1185N/A private Filter includedNames;
1185N/A private String userPage;
1185N/A private String userPageSuffix;
1185N/A private String bugPage;
1185N/A private String bugPattern;
1185N/A private String reviewPage;
1185N/A private String reviewPattern;
1252N/A private String webappLAF;
1185N/A private boolean remoteScmSupported;
1185N/A private boolean optimizeDatabase;
1185N/A private boolean useLuceneLocking;
1185N/A private boolean compressXref;
1185N/A private boolean indexVersionedFilesOnly;
1185N/A private int hitsPerPage;
993N/A private int cachePages;
993N/A private String databaseDriver;
993N/A private String databaseUrl;
1185N/A private String ctagsOptionsFile;
993N/A private int scanningDepth;
993N/A private Set<String> allowedSymlinks;
937N/A private boolean obfuscatingEMailAddresses;
58N/A private boolean chattyStatusPage;
58N/A private final Map<String,String> cmds;
816N/A private int tabSize;
58N/A private boolean dirlistUseToday;
58N/A private String dirlistDatePattern;
773N/A
58N/A private static final Logger logger = Logger.getLogger(Configuration.class.getName());
664N/A
58N/A /**
850N/A * Get the default tab size (number of space characters per tab character)
1327N/A * to use for each project. If {@code <= 0} tabs are read/write as is.
870N/A *
870N/A * @return current tab size set.
99N/A * @see Project#getTabSize()
1115N/A * @see org.opensolaris.opengrok.analysis.ExpandTabsReader
101N/A */
106N/A public int getTabSize() {
112N/A return tabSize;
1026N/A }
129N/A
129N/A /**
129N/A * Set the default tab size (number of space characters per tab character)
875N/A * to use for each project. If {@code <= 0} tabs are read/write as is.
318N/A *
144N/A * @param tabSize tabsize to set.
173N/A * @see Project#setTabSize(int)
253N/A * @see org.opensolaris.opengrok.analysis.ExpandTabsReader
296N/A */
335N/A public void setTabSize(int tabSize) {
480N/A this.tabSize = tabSize;
816N/A }
816N/A
993N/A /**
1016N/A * Get the depth of scanning for repositories in the directory tree relative
1315N/A * to source root.
1185N/A * @return the scan depth.
58N/A */
937N/A public int getScanningDepth() {
1185N/A return scanningDepth;
1185N/A }
1185N/A
1190N/A /**
1185N/A * Set the depth of scanning for repositories in the directory tree relative
1185N/A * to source root.
1185N/A * @param scanningDepth the scan depth to set.
1185N/A */
1185N/A public void setScanningDepth(int scanningDepth) {
1185N/A this.scanningDepth = scanningDepth;
1185N/A }
1185N/A
1185N/A /**
1185N/A * Creates a new instance of Configuration
1185N/A */
1185N/A public Configuration() {
1185N/A //defaults for an opengrok instance configuration
1185N/A setHistoryCache(true);
1190N/A setHistoryCacheTime(30);
1185N/A setHistoryCacheInDB(false);
1185N/A setProjects(new ArrayList<Project>());
1185N/A setRepositories(new ArrayList<RepositoryInfo>());
1185N/A setUrlPrefix("/source" + Prefix.SEARCH_R + '?');
1190N/A // TODO generate relative search paths, get rid of -w <webapp> option to indexer !
58N/A // setUrlPrefix(".." + Prefix.SEARCH_R + '?');
58N/A setCtags(System.getProperty(CTAGS_CMD_PROPERTY_KEY, CTAGS_CMD_FALLBACK));
58N/A //below can cause an outofmemory error, since it is defaulting to NO LIMIT
937N/A setIndexWordLimit(Integer.MAX_VALUE);
58N/A setVerbose(false);
58N/A setPrintProgress(false);
58N/A setGenerateHtml(true);
937N/A setQuickContextScan(true);
816N/A setIgnoredNames(new IgnoredNames());
816N/A setIncludedNames(new Filter());
816N/A setUserPage("http://www.opensolaris.org/viewProfile.jspa?username=");
816N/A setBugPage("http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=");
816N/A setBugPattern("\\b([12456789][0-9]{6})\\b");
816N/A setReviewPage("http://arc.opensolaris.org/caselog/PSARC/");
816N/A setReviewPattern("\\b(\\d{4}/\\d{3})\\b"); // in form e.g. PSARC 2008/305
816N/A setWebappLAF(DEFAULT_STYLE);
816N/A setRemoteScmSupported(false);
816N/A setOptimizeDatabase(true);
816N/A setUsingLuceneLocking(false);
816N/A setCompressXref(true);
816N/A setIndexVersionedFilesOnly(false);
816N/A setHitsPerPage(25);
816N/A setCachePages(5);
773N/A setScanningDepth(3); // default depth of scanning for repositories
773N/A setAllowedSymlinks(new HashSet<String>());
773N/A //setTabSize(4);
773N/A cmds = new HashMap<String, String>();
773N/A setDirlistUseToday(DIRLIST_TODAY_DEFAULT);
773N/A setDirlistDatePattern(DIRLIST_DATE_DEFAULT);
58N/A }
58N/A
58N/A /**
773N/A * Get the {@link SimpleDateFormat} pattern to use to show the last modified
773N/A * time in web app directory listings.
773N/A * @return an always usuable pattern for date formatting.
773N/A */
773N/A public String getDirlistDatePattern() {
58N/A return dirlistDatePattern;
58N/A }
58N/A
773N/A /**
773N/A * Set the {@link SimpleDateFormat} pattern to use to show the last modified
773N/A * time in web app directory listings.
773N/A * @param pattern the pattern to use. Ignored if {@code null} or invalid.
773N/A */
773N/A public void setDirlistDatePattern(String pattern) {
773N/A if (pattern == null) {
773N/A return;
773N/A }
58N/A try {
58N/A @SuppressWarnings("unused")
58N/A SimpleDateFormat sdf = new SimpleDateFormat(pattern);
773N/A dirlistDatePattern = pattern;
773N/A } catch (Exception e) {
773N/A logger.warning("Invalid web directory list date format pattern ("
773N/A + pattern + ") ignored: " + e.getMessage());
773N/A }
773N/A }
773N/A
58N/A /**
58N/A * Check, whether the web app should show {@code Today} instead of the last
58N/A * modified time if the target was changed within the last 24 hours.
773N/A * @return {@code true} if {@code Today} should be shown.
773N/A */
773N/A public boolean isDirlistUseToday() {
773N/A return dirlistUseToday;
773N/A }
773N/A
773N/A /**
773N/A * Set, whether the web app should show {@code Today} instead of the last
773N/A * modified time if the target was changed within the last 24 hours.
773N/A * @param enable use {@code true} if {@code Today} should be shown.
773N/A * @see #DIRLIST_TODAY_PROPERTY_KEY
773N/A */
773N/A public void setDirlistUseToday(boolean enable) {
773N/A this.dirlistUseToday = enable;
773N/A }
773N/A
773N/A /**
773N/A * Get the client command to use to access the repository for the given
773N/A * fully quallified classname.
773N/A * @param clazzName name of the targeting class
773N/A * @return {@code null} if not yet set, the client command otherwise.
773N/A */
773N/A public String getRepoCmd(String clazzName) {
937N/A return cmds.get(clazzName);
58N/A }
58N/A
58N/A /**
937N/A * Set the client command to use to access the repository for the given
58N/A * fully quallified classname.
58N/A * @param clazzName name of the targeting class. If {@code null} this method
58N/A * does nothing.
937N/A * @param cmd the client command to use. If {@code null} the corresponding
58N/A * entry for the given clazzName get removed.
58N/A * @return the client command previously set, which might be {@code null}.
58N/A */
937N/A public String setRepoCmd(String clazzName, String cmd) {
58N/A if (clazzName == null) {
58N/A return null;
58N/A }
937N/A if (cmd == null || cmd.length() == 0) {
58N/A return cmds.remove(clazzName);
58N/A }
58N/A return cmds.put(clazzName, cmd);
937N/A }
58N/A
58N/A /**
58N/A * Get a map of repository class names with the corresponding CLI command to
937N/A * access the repository it is able to handle.
664N/A * Basically exists to satisfy bean/de|encoder stuff, only.
58N/A * @return a unmodifyable map.
58N/A */
937N/A public Map<String, String> getCmds() {
664N/A return Collections.unmodifiableMap(cmds);
58N/A }
58N/A
937N/A /**
58N/A * Set the map of repository class names with the corresponding CLI command
58N/A * to access the repository it is able to handle.
58N/A * Basically exists to satisfy bean/de|encoder stuff, only.
937N/A * @param cmds the map to copy.
1185N/A */
1252N/A public void setCmds(Map<String, String> cmds) {
1252N/A this.cmds.clear();
1252N/A this.cmds.putAll(cmds);
1252N/A }
1185N/A
1185N/A /**
58N/A * Get the name of the ctags program in use
58N/A * @return the name of the ctags program in use
58N/A */
937N/A public String getCtags() {
65N/A return ctags;
65N/A }
65N/A
937N/A /**
65N/A * Specify the CTags program to use
65N/A * @param ctags the ctags program to use
65N/A */
937N/A public void setCtags(String ctags) {
77N/A this.ctags = ctags;
77N/A }
77N/A
937N/A /**
77N/A * Get the number of search result pages, which should be cached in
77N/A * a search result.
77N/A * @return the number of result pages to cache.
99N/A * @see #getHitsPerPage()
99N/A */
99N/A public int getCachePages() {
99N/A return cachePages;
99N/A }
99N/A
99N/A /**
99N/A * Set the number of search result pages, which should be cached in
99N/A * a search result.
99N/A * @param cachePages the number of result pages to cache.
99N/A * @see #getHitsPerPage()
99N/A */
99N/A public void setCachePages(int cachePages) {
99N/A this.cachePages = cachePages;
99N/A }
99N/A
937N/A /**
1115N/A * Get the number of hits to display on one search result page.
1115N/A * @return number of hits per page.
1115N/A */
1115N/A public int getHitsPerPage() {
1115N/A return hitsPerPage;
1115N/A }
1115N/A
1115N/A /**
125N/A * Set the number of hits to display on one search result page.
125N/A * @param hitsPerPage number of hits per page to set.
125N/A */
937N/A public void setHitsPerPage(int hitsPerPage) {
125N/A this.hitsPerPage = hitsPerPage;
125N/A }
125N/A
106N/A /**
106N/A * Should the history log be cached?
937N/A *
106N/A * @return {@code true} if a {@code HistoryCache} implementation should be
106N/A * used, {@code false} otherwise
106N/A */
937N/A public boolean isHistoryCache() {
106N/A return historyCache;
106N/A }
106N/A
112N/A /**
112N/A * Set whether history should be cached.
112N/A *
112N/A * @param historyCache if {@code true} enable history cache
112N/A */
112N/A public void setHistoryCache(boolean historyCache) {
112N/A this.historyCache = historyCache;
112N/A }
129N/A
1026N/A /**
1026N/A * How long can a history request take before it's cached? If the time is
1026N/A * exceeded, the result is cached. This setting only affects
1026N/A * {@code FileHistoryCache}.
1026N/A *
1026N/A * @return the maximum time in milliseconds a history request can take
1026N/A * before it's cached
1026N/A */
129N/A public int getHistoryCacheTime() {
129N/A return historyCacheTime;
129N/A }
129N/A
129N/A /**
129N/A * Set the maximum time a history request can take before it's cached. This
129N/A * setting is only respected if {@code FileHistoryCache} is used.
129N/A *
1100N/A * @param historyCacheTime maximum time in milliseconds
1100N/A */
1100N/A public void setHistoryCacheTime(int historyCacheTime) {
1100N/A this.historyCacheTime = historyCacheTime;
1100N/A }
1100N/A
1100N/A /**
1100N/A * Should the history cache be stored in a database? If yes,
129N/A * {@code JDBCHistoryCache} will be used to cache the history; otherwise,
129N/A * {@code FileHistoryCache} is used.
129N/A *
129N/A * @return whether the history cache should be stored in a database
129N/A */
129N/A public boolean isHistoryCacheInDB() {
129N/A return historyCacheInDB;
129N/A }
129N/A
129N/A /**
129N/A * Set whether the history cache should be stored in a database, and
129N/A * {@code JDBCHistoryCache} should be used instead of {@code
129N/A * FileHistoryCache}.
129N/A *
129N/A * @param historyCacheInDB whether the history cached should be stored in a
937N/A * database
318N/A */
318N/A public void setHistoryCacheInDB(boolean historyCacheInDB) {
318N/A this.historyCacheInDB = historyCacheInDB;
318N/A }
318N/A
318N/A /**
318N/A * Get all of the projects
318N/A * @return a list containing all of the projects (may be null)
318N/A */
318N/A public List<Project> getProjects() {
318N/A return projects;
318N/A }
318N/A
318N/A /**
318N/A * Set the list of the projects
144N/A * @param projects the list of projects to use
144N/A */
144N/A public void setProjects(List<Project> projects) {
144N/A this.projects = projects;
144N/A }
144N/A
144N/A /**
144N/A * Do we have projects?
173N/A * @return true if we have projects
173N/A */
173N/A public boolean hasProjects() {
173N/A return projects != null && !projects.isEmpty();
173N/A }
173N/A
173N/A private static String getCanonicalPath(String s) {
173N/A try {
234N/A File file = new File(s);
253N/A if (!file.exists()) {
253N/A return s;
253N/A }
253N/A return file.getCanonicalPath();
253N/A } catch (IOException ex) {
253N/A logger.warning("Failed to get canonical path for '" + s + "': "
253N/A + ex.getMessage());
253N/A logger.log(Level.FINE, "getCanonicalPath", ex);
296N/A return s;
296N/A }
296N/A }
296N/A
296N/A /**
296N/A * Specify the source root
296N/A * @param sourceRoot the location of the sources
335N/A */
335N/A public void setSourceRoot(String sourceRoot) {
335N/A String p = getCanonicalPath(sourceRoot);
335N/A if (p != null) {
335N/A this.sourceRoot = p;
335N/A }
335N/A }
335N/A
335N/A /**
480N/A * Get the path to where the sources are located
480N/A * @return path to where the sources are located
480N/A */
480N/A public String getSourceRoot() {
480N/A return sourceRoot;
480N/A }
480N/A
937N/A /**
1330N/A * Get a file representing the directory where the sources are located
1330N/A * @return A file representing the directory where the sources are located
1330N/A */
1330N/A public File getSourceRootFile() {
1330N/A return sourceRoot != null ? new File(sourceRoot) : null;
1330N/A }
1330N/A
1330N/A /**
1330N/A * Returns a path relative to source root. This would just be a simple
1330N/A * substring operation, except we need to support symlinks outside the
1330N/A * source root.
1330N/A * @param file A file to resolve
1330N/A * @param stripCount Number of characters past source root to strip
1330N/A * @throws IOException If an IO error occurs
1330N/A * @throws FileNotFoundException If the file is not relative to source root
1330N/A * @return Path relative to source root
1330N/A */
1330N/A public String getPathRelativeToSourceRoot(File file, int stripCount)
1330N/A throws IOException
1330N/A {
1330N/A String canonicalPath = file.getCanonicalPath();
1330N/A if (canonicalPath.startsWith(sourceRoot)) {
1330N/A return canonicalPath.substring(sourceRoot.length() + stripCount);
1330N/A }
1330N/A for (String allowedSymlink : getAllowedSymlinks()) {
1324N/A String allowedTarget = new File(allowedSymlink).getCanonicalPath();
1324N/A if (canonicalPath.startsWith(allowedTarget)) {
1324N/A return canonicalPath.substring(allowedTarget.length() + stripCount);
1324N/A }
937N/A }
1330N/A throw new FileNotFoundException("Failed to resolve '" + canonicalPath
1324N/A + "' relative to source root '" + sourceRoot + "'");
1330N/A }
1324N/A
1330N/A /**
667N/A * Set the path to where the index database is stored
833N/A * @param dataRoot the index database
1286N/A */
1324N/A public void setDataRoot(String dataRoot) {
1286N/A String p = getCanonicalPath(dataRoot);
1324N/A if (p != null) {
1324N/A this.dataRoot = p;
1324N/A }
1324N/A }
1324N/A
1324N/A /**
1289N/A * Get the path to the where the index database is stored
1324N/A * @return the path to the index database
1324N/A */
1324N/A public String getDataRoot() {
1324N/A return dataRoot;
1324N/A }
1324N/A
1324N/A /**
1286N/A * Get a file representing the index database
1324N/A * @return the index database
1324N/A */
1324N/A public File getDataRootFile() {
1324N/A return dataRoot != null ? new File(dataRoot) : null;
1327N/A }
1327N/A
1324N/A /**
1324N/A * Get the map of known repositories.
1324N/A * @return a possible empty list including {@code null}.
1324N/A */
1324N/A public List<RepositoryInfo> getRepositories() {
1324N/A return repositories;
1324N/A }
1324N/A
1286N/A /**
1324N/A * Set the map of known repositories.
1286N/A * @param repositories the repositories to set.
1286N/A */
1299N/A public void setRepositories(List<RepositoryInfo> repositories) {
1324N/A this.repositories = repositories;
1324N/A }
1324N/A
1324N/A /**
1324N/A * Get the the URL prefix to be used by the {@link
1324N/A * org.opensolaris.opengrok.analysis.executables.JavaClassAnalyzer} as well
1324N/A * as lexers (see {@link org.opensolaris.opengrok.analysis.JFlexXref}) when
1324N/A * they create output with html links.
1324N/A *
1324N/A * @return the URI encoded prefix to use.
1331N/A */
1299N/A public String getUrlPrefix() {
1299N/A return urlPrefix;
1324N/A }
1324N/A
1324N/A /**
1324N/A * Set the URL prefix to be used by the {@link
1299N/A * org.opensolaris.opengrok.analysis.executables.JavaClassAnalyzer} as well
1299N/A * as lexers (see {@link org.opensolaris.opengrok.analysis.JFlexXref}) when
1299N/A * they create output with html links.
1324N/A *
1324N/A * @param urlPrefix URI encoded prefix to set.
1324N/A */
1324N/A public void setUrlPrefix(String urlPrefix) {
1324N/A this.urlPrefix = urlPrefix;
1324N/A }
1324N/A
1324N/A /**
1324N/A * Set whether to generate hyper text cross reference (xref) files
1324N/A * offline (i.e. when indexing). If set to {@code false}, xref files are
1331N/A * created on the fly on demand and gets disposed when served to the client
1299N/A * - so saves disk space, but could be sightly slow and more resource
1299N/A * demanding for the servlet container.
1324N/A * @param generateHtml {@code true} to generate and cache xref files immediately.
1324N/A */
1324N/A public void setGenerateHtml(boolean generateHtml) {
1324N/A this.generateHtml = generateHtml;
1299N/A }
1299N/A
1326N/A /**
1331N/A * Check, whether to generate and cache xref files immediately.
1331N/A * @return {@code true} if immediate generation/caching is preferred.
1331N/A */
1331N/A public boolean isGenerateHtml() {
1331N/A return generateHtml;
1331N/A }
1331N/A
1331N/A /**
1331N/A * Set the project that is specified to be the default project to use. The
1331N/A * default project is the project you will search (from the web application)
1331N/A * if the page request didn't contain the cookie.
1331N/A * @param defaultProject The default project to use
1331N/A */
1331N/A public void setDefaultProject(Project defaultProject) {
1331N/A this.defaultProject = defaultProject;
1331N/A }
1331N/A
1331N/A /**
1331N/A * Get the project that is specified to be the default project to use. The
1331N/A * default project is the project you will search (from the web application)
1326N/A * if the page request didn't contain the cookie.
1326N/A * @return the default project (may be null if not specified)
1326N/A */
1326N/A public Project getDefaultProject() {
1326N/A return defaultProject;
1326N/A }
1326N/A
1326N/A /**
1326N/A * Chandan wrote the following answer on the opengrok-discuss list:
1326N/A * "Traditionally search engines (specially spiders) think that large files
1326N/A * are junk. Large files tend to be multimedia files etc., which text
1326N/A * search spiders do not want to chew. So they ignore the contents of
1326N/A * the file after a cutoff length. Lucene does this by number of words,
1326N/A * which is by default is 10,000."
1326N/A * By default OpenGrok will increase this limit to 60000, but it may be
1326N/A * overridden in the configuration file
1326N/A * @return The maximum words to index
1326N/A */
1326N/A public int getIndexWordLimit() {
1326N/A return indexWordLimit;
1326N/A }
1326N/A
833N/A /**
833N/A * Set the number of words in a file Lucene will index.
833N/A * See getIndexWordLimit for a better description.
833N/A * @param indexWordLimit the number of words to index in a single file
833N/A */
833N/A public void setIndexWordLimit(int indexWordLimit) {
833N/A this.indexWordLimit = indexWordLimit;
833N/A }
833N/A
833N/A /**
833N/A * Is the verbosity flag turned on?
833N/A * @return true if we can print extra information
833N/A */
833N/A public boolean isVerbose() {
833N/A return verbose;
833N/A }
1016N/A
1016N/A /**
1016N/A * Set the verbosity flag (to add extra debug information in output)
1016N/A * @param verbose new value
1016N/A */
1016N/A public void setVerbose(boolean verbose) {
1016N/A this.verbose = verbose;
1016N/A }
1123N/A
1123N/A /**
1123N/A * Is the progress print flag turned on?
1123N/A * @return {@code true} if we can print per project progress %
1123N/A */
1123N/A public boolean isPrintProgress() {
1123N/A return printProgress;
1123N/A }
1125N/A
1125N/A /**
1125N/A * Set the printing of progress % flag (user convenience).
1125N/A * @param enable {@code true} to enable progress printing.
1125N/A */
1125N/A public void setPrintProgress(boolean enable) {
1125N/A this.printProgress = enable;
1330N/A }
234N/A
234N/A /**
234N/A * Specify if a search may start with a wildcard. Note that queries
234N/A * that start with a wildcard will give a significant impact on the
234N/A * search performace (disabled by default).
234N/A * @param allowLeadingWildcard set to {@code true} to activate
509N/A */
640N/A public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
640N/A this.allowLeadingWildcard = allowLeadingWildcard;
640N/A }
1195N/A
640N/A /**
639N/A * Is leading wildcards allowed?
937N/A * @return {@code true} if a search may start with a wildcard
639N/A */
639N/A public boolean isAllowLeadingWildcard() {
639N/A return allowLeadingWildcard;
639N/A }
639N/A
937N/A private boolean quickContextScan;
639N/A
640N/A /**
640N/A * Check whether a quick context scan should be done.
640N/A * @return {@code true} if quick scan should be made.
234N/A * @see #setQuickContextScan(boolean)
234N/A */
234N/A public boolean isQuickContextScan() {
639N/A return quickContextScan;
640N/A }
640N/A
640N/A /**
1195N/A * If set to {@code true}, at most 1 MiB of a file gets read into a buffer
640N/A * at once and than tokenized. Otherwise the whole file gets processed as
639N/A * usual, i.e. the file content gets read on demand when tokenizing and the
937N/A * whole file gets processed (no matter of its size).
937N/A * @param quickContextScan if {@code true} enable quick scanning
937N/A */
639N/A public void setQuickContextScan(boolean quickContextScan) {
639N/A this.quickContextScan = quickContextScan;
639N/A }
639N/A
639N/A /**
639N/A * Set the list of names/patterns to determine file, which should be
937N/A * ignored/excluded from indexing.
639N/A * Takes precedence over {@link #getIncludedNames()}.
640N/A * @param ignoredNames stuff to ignore. If {@code null} defaults will be
640N/A * used instead.
640N/A */
509N/A public void setIgnoredNames(IgnoredNames ignoredNames) {
234N/A this.ignoredNames = ignoredNames == null ? new IgnoredNames() : ignoredNames;
234N/A }
640N/A
234N/A /**
234N/A * Get the list of names/patterns to determine file, which should be
639N/A * ignored/excluded from indexing.
58N/A * Takes precedence over {@link #getIncludedNames()}.
* @return stuff to ignore.
*/
public IgnoredNames getIgnoredNames() {
return ignoredNames;
}
/**
* Set the list of names/patterns to determine, which are allowed to
* be indexed.
* @param includedNames stuff to index. {@code null} means everything.
* @see #setIgnoredNames(IgnoredNames)
*/
public void setIncludedNames(Filter includedNames) {
this.includedNames = includedNames;
}
/**
* Get the list of names/patterns to determine, which are allowed to
* be indexed.
* @return stuff to index. {@code null} means everything.
* @see #getIgnoredNames()
*/
public Filter getIncludedNames() {
return includedNames;
}
/**
* Set the user page for the history listing
* @param userPage the URI encoded URL fragment preceeding the username from
* history
*/
public void setUserPage(String userPage) {
this.userPage = userPage;
}
/**
* Get the user page for the history listing
* @return the URI encoded URL string fragment preceeding the username
*/
public String getUserPage() {
return userPage;
}
/**
* Set the user page suffix for the history listing
* @param userPageSuffix the URI encoded URL fragment following the username
* from history
*/
public void setUserPageSuffix(String userPageSuffix) {
this.userPageSuffix = userPageSuffix;
}
/**
* Get the user page suffix for the history listing
* @return the URI encoded URL string fragment following the username
*/
public String getUserPageSuffix() {
return userPageSuffix;
}
/**
* Set the bug page for the history listing
* @param bugPage the URI encoded URL fragment preceeding the bug ID
*/
public void setBugPage(String bugPage) {
this.bugPage = bugPage;
}
/**
* Get the bug page for the history listing
* @return the URI encoded URL string fragment preceeding the bug ID
*/
public String getBugPage() {
return bugPage;
}
/**
* Set the bug regex for the history listing
* @param bugPattern the regex to search history comments
*/
public void setBugPattern(String bugPattern) {
this.bugPattern = bugPattern;
}
/**
* Get the bug regex for the history listing
* @return the regex that is looked for in history comments
*/
public String getBugPattern() {
return bugPattern;
}
/**
* Get the review (ARC) page for the history listing
* @return the URI encoded URL string fragment preceeding the review page ID
*/
public String getReviewPage() {
return reviewPage;
}
/**
* Set the review (ARC) page for the history listing
* @param reviewPage the URI encoded URL fragment preceeding the review page ID
*/
public void setReviewPage(String reviewPage) {
this.reviewPage = reviewPage;
}
/**
* Get the review (ARC) regex for the history listing
* @return the regex that is looked for in history comments
*/
public String getReviewPattern() {
return reviewPattern;
}
/**
* Set the review (ARC) regex for the history listing
* @param reviewPattern the regex to search history comments
*/
public void setReviewPattern(String reviewPattern) {
this.reviewPattern = reviewPattern;
}
/**
* Get the name of the web app Look And Feel (LAF) theme to use. It gets
* used to construct the stylesheet and image include links in web pages
* and names a directory, which contains all this stuff.
* @return the name of the web app LAF
* @see #DEFAULT_STYLE
*/
public String getWebappLAF() {
return webappLAF;
}
/**
* Set the name of the web app Look And Feel (LAF) theme to use. It gets
* used to construct the stylesheet and image include links in web pages
* and names a directory, which contains all this stuff.
* @param webappLAF the name of the web app LAF. If {@code null} the default
* will be used.
* @see #DEFAULT_STYLE
*/
public void setWebappLAF(String webappLAF) {
this.webappLAF = webappLAF == null ? DEFAULT_STYLE : webappLAF;
}
/**
* Check whether file histories should be retrieved from the related remote
* repositories when needed.
* @return {@code true} if fetch on demand is enabled.
*/
public boolean isRemoteScmSupported() {
return remoteScmSupported;
}
/**
* Set whether file histories should be retrieved from the related remote
* repositories when needed.
* @param remoteScmSupported {@code true} if fetch on demand is enabled.
*/
public void setRemoteScmSupported(boolean remoteScmSupported) {
this.remoteScmSupported = remoteScmSupported;
}
/**
* Check, whether the lucene index database should be optimized (compact
* segments etc.) after indexing has been run.
* @return {@code true} if optimization is enabled.
*/
public boolean isOptimizeDatabase() {
return optimizeDatabase;
}
/**
* Set, whether the lucene index database should be optimized (compact
* segments etc.) after indexing has been run.
* @param optimizeDatabase {@code true} if optimization should be done.
*/
public void setOptimizeDatabase(boolean optimizeDatabase) {
this.optimizeDatabase = optimizeDatabase;
}
/**
* Check, wheter lucene should lock index files when indexing to avoid
* concurrent access, reading invalid data.
* @return {@code true} if locking should be used.
*/
public boolean isUsingLuceneLocking() {
return useLuceneLocking;
}
/**
* Set wheter lucene should lock index files when indexing to avoid
* concurrent access, reading invalid data.
* @param useLuceneLocking {@code true} if locking should be used.
*/
public void setUsingLuceneLocking(boolean useLuceneLocking) {
this.useLuceneLocking = useLuceneLocking;
}
/**
* Set if we should compress the xref files or not. Applies to newly
* generated/updated files, only. Re-indexing is not needed, since the
* application automatically detects, whether an xref file is compressed
* and processes it properly.
* @param compressXref set to {@code true} if generated xref html files
* should be compressed
*/
public void setCompressXref(boolean compressXref) {
this.compressXref = compressXref;
}
/**
* Set if we should compress generated xref html files?
* @return {@code true} if the xref html files should be compressed.
*/
public boolean isCompressXref() {
return compressXref;
}
/**
* Check, whether unversioned files should not be indexed.
* If {@code true}, it takes precedence over {@link #getIncludedNames()},
* i.e. files are not indexed when unversioned, even if they match an
* include name.
* @return {@code true} if indexing of unversioned files is disabled.
*/
public boolean isIndexVersionedFilesOnly() {
return indexVersionedFilesOnly;
}
/**
* Set, whether unversioned files should not be indexed.
* If set to {@code true}, it takes precedence over {@link #getIncludedNames()},
* i.e. files are not indexed when unversioned, even if they match an
* include name.
* @param indexVersionedFilesOnly {@code true} to disable indexing of
* unversioned files
*/
public void setIndexVersionedFilesOnly(boolean indexVersionedFilesOnly) {
this.indexVersionedFilesOnly = indexVersionedFilesOnly;
}
private transient long lastModified;
/**
* Get the time, when this instance has been modified. If not explicitly set
* or set to {@code 0}, it gets initialized with the time of the first call
* to this method after instantiation/de-serialization.
*
* @return time in milliseconds since 1 Jan 1970 00:00:00 GMT
*/
public long getLastModified() {
if (lastModified == 0) {
// since we use it for If-Last-Modified-Since evals, which has no
// millis, we need to clear the milliseconds part
lastModified = System.currentTimeMillis()/1000 * 1000;
}
return lastModified;
}
/**
* Set the time, when this configuration has been modified for the last time.
* @param lastModified the time in milliseconds since 1 Jan 1970 00:00:00 GMT
*/
public void setLastModified(long lastModified) {
this.lastModified = lastModified/1000 * 1000;
}
private transient Date indexLastModified;
/**
* Get the date of the last index update.
*
* @return the time of the last index update.
*/
public Date getDateForLastIndexRun() {
if (indexLastModified == null) {
File timestamp = new File(getDataRoot(), "timestamp");
indexLastModified = new Date(timestamp.lastModified());
}
return indexLastModified;
}
/**
* Get the contents of a file or empty string if the file cannot be read.
*/
@SuppressWarnings("resource")
private static String getFileContent(File file) {
if (file == null || ! file.canRead()) {
return "";
}
FileReader fin = null;
BufferedReader input = null;
try {
fin = new FileReader(file);
input = new BufferedReader(fin);
String line = null;
StringBuilder contents = new StringBuilder();
String EOL = System.getProperty("line.separator");
while (( line = input.readLine()) != null) {
contents.append(line).append(EOL);
}
return contents.toString();
} catch (java.io.FileNotFoundException e) {
/*
* should usually not happen
*/
} catch (java.io.IOException e) {
logger.warning("failed to read include file '" + file.getName()
+ "': " + e.getMessage());
} finally {
if (input != null) {
IOUtils.close(input);
} else if (fin != null) {
IOUtils.close(fin);
}
}
return "";
}
/**
* The name of the file relative to the <var>DATA_ROOT</var>, which should
* be included into the footer of generated web pages.
*/
public static final String FOOTER_INCLUDE_FILE = "footer_include";
private transient String footer = null;
/**
* Get the contents of the footer include file.
*
* @return an empty string if it could not be read successfully, the
* contents of the file otherwise.
* @see #FOOTER_INCLUDE_FILE
*/
public String getFooterIncludeFileContent() {
if (footer == null) {
footer = getFileContent(new File(getDataRoot(), FOOTER_INCLUDE_FILE));
}
return footer;
}
/**
* The name of the file relative to the <var>DATA_ROOT</var>, which should
* be included into the footer of generated web pages.
*/
public static final String HEADER_INCLUDE_FILE = "header_include";
private transient String header = null;
/**
* Get the contents of the footer include file.
*
* @return an empty string if it could not be read successfully, the
* contents of the file otherwise.
* @see #HEADER_INCLUDE_FILE
*/
public String getHeaderIncludeFileContent() {
if (header == null) {
header = getFileContent(new File(getDataRoot(), HEADER_INCLUDE_FILE));
}
return header;
}
/**
* The name of the file relative to the <var>DATA_ROOT</var>, which should
* be included into the body of web app's "Home" page.
*/
public static final String BODY_INCLUDE_FILE = "body_include";
private transient String body = null;
/**
* Get the contents of the body include file.
* @return an empty string if it could not be read successfully, the
* contents of the file otherwise.
* @see Configuration#BODY_INCLUDE_FILE
*/
public String getBodyIncludeFileContent() {
if (body == null) {
body = getFileContent(new File(getDataRoot(), BODY_INCLUDE_FILE));
}
return body;
}
/**
* The name of the eftar file relative to the <var>DATA_ROOT</var>, which
* contains definition tags.
*/
public static final String EFTAR_DTAGS_FILE = "index/dtags.eftar";
private transient String dtagsEftar = null;
/**
* Get the eftar file, which contains definition tags.
*
* @return {@code null} if there is no such file, the file otherwise.
*/
public File getDtagsEftar() {
if (dtagsEftar == null) {
File tmp = new File(getDataRoot() + "/" + EFTAR_DTAGS_FILE);
if (tmp.canRead()) {
try {
dtagsEftar = tmp.getAbsolutePath();
} catch (SecurityException e) {
logger.warning(e.getLocalizedMessage());
dtagsEftar = "";
}
} else {
dtagsEftar = "";
}
}
return dtagsEftar.isEmpty() ? null : new File(dtagsEftar);
}
/**
* Get the fully quallified class name of the history database driver to use.
* @return the database driver class name.
*/
public String getDatabaseDriver() {
return databaseDriver;
}
/**
* Set the fully quallified class name of the history database driver to use.
* @param databaseDriver the database driver class name to set.
*/
public void setDatabaseDriver(String databaseDriver) {
this.databaseDriver = databaseDriver;
}
/**
* Get the JDBC connection URL to use to connect to the history database.
* @return the JDBC connection URL to use.
*/
public String getDatabaseUrl() {
return databaseUrl;
}
/**
* Set the JDBC connection URL to use to connect to the history database.
* @param databaseUrl the JDBC connection URL to set.
*/
public void setDatabaseUrl(String databaseUrl) {
this.databaseUrl = databaseUrl;
}
/**
* Get the optional file to be used to handover additional options to the
* ctags command.
* @return {@code null} if not set, the options filename otherwise.
*/
public String getCtagsOptionsFile() {
return ctagsOptionsFile;
}
/**
* Set the file to be used to handover additional options to the ctags
* command.
* @param filename the options filename to use. Might be {@code null}.
*/
public void setCtagsOptionsFile(String filename) {
this.ctagsOptionsFile = filename;
}
/**
* Get the pathnames of symlinks, which are allowed to be processed (e.g.
* indexed, tokenized, etc.).
* @return a possible empty set.
*/
public Set<String> getAllowedSymlinks() {
return allowedSymlinks;
}
/**
* Set the pathnames of symlinks, which are allowed to be processed (e.g.
* indexed, tokenized, etc.).
* @param allowedSymlinks symlinks to allow. {@code null} means none.
*/
public void setAllowedSymlinks(Set<String> allowedSymlinks) {
if (allowedSymlinks == null) {
this.allowedSymlinks.clear();
} else {
this.allowedSymlinks = new HashSet<String>(allowedSymlinks);
}
}
/**
* Check whether e-mail addresses should be obfuscated in the xref.
* @return {@code true} if obfuscation is needed.
*/
public boolean isObfuscatingEMailAddresses() {
return obfuscatingEMailAddresses;
}
/**
* Set whether e-mail addresses should be obfuscated in the xref.
* @param obfuscate {@code true} if obfuscation is needed.
*/
public void setObfuscatingEMailAddresses(boolean obfuscate) {
this.obfuscatingEMailAddresses = obfuscate;
}
/**
* Should status.jsp print internal settings, like paths and database
* URLs?
*
* @return {@code true} if status.jsp should show the configuration.
*/
public boolean isChattyStatusPage() {
return chattyStatusPage;
}
/**
* Set whether status.jsp should print internal settings.
*
* @param chattyStatusPage {@code true} if internal settings should be printed.
*/
public void setChattyStatusPage(boolean chattyStatusPage) {
this.chattyStatusPage = chattyStatusPage;
}
/**
* 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 {
@SuppressWarnings("resource")
final FileOutputStream out = new FileOutputStream(file);
try {
this.encodeObject(out);
} finally {
IOUtils.close(out);
}
}
/**
* Serialize this instance into an XML formatted string.
* @return this instance as xml string
*/
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();
}
/**
* Read the file containing a serialized {@link Configuration} instance and
* return the marshalled instance.
* @param file the file to read
* @return the un-serialized Configuration instance represented by the file.
* @throws IOException if the file cannot be read/decoded.
*/
@SuppressWarnings("resource")
public static Configuration read(File file) throws IOException {
final FileInputStream in = new FileInputStream(file);
try {
return decodeObject(in);
} finally {
IOUtils.close(in);
}
}
/**
* Read the given string representing a in XML serialized {@link Configuration}
* and return the marshalled instance.
* @param xmlconfig serialized config to read.
* @return the un-serialized Configuration instance represented by the string.
* @throws IOException if the string cannot be decoded.
*/
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;
}
}