RuntimeEnvironment.java revision 1327
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) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
1356N/A */
58N/Apackage org.opensolaris.opengrok.configuration;
58N/A
58N/Aimport java.beans.XMLDecoder;
234N/Aimport java.beans.XMLEncoder;
234N/Aimport java.io.BufferedInputStream;
234N/Aimport java.io.ByteArrayInputStream;
234N/Aimport java.io.ByteArrayOutputStream;
1287N/Aimport java.io.File;
639N/Aimport java.io.FileNotFoundException;
639N/Aimport java.io.IOException;
234N/Aimport java.net.InetAddress;
234N/Aimport java.net.ServerSocket;
234N/Aimport java.net.Socket;
1289N/Aimport java.net.SocketAddress;
234N/Aimport java.net.UnknownHostException;
639N/Aimport java.util.Date;
639N/Aimport java.util.List;
1463N/Aimport java.util.Set;
58N/Aimport java.util.logging.Level;
1185N/Aimport java.util.logging.Logger;
667N/A
1185N/Aimport org.opensolaris.opengrok.history.HistoryGuru;
1016N/Aimport org.opensolaris.opengrok.history.RepositoryInfo;
58N/Aimport org.opensolaris.opengrok.index.Filter;
1185N/Aimport org.opensolaris.opengrok.index.IgnoredNames;
1016N/Aimport org.opensolaris.opengrok.util.Executor;
1436N/Aimport org.opensolaris.opengrok.util.IOUtils;
1185N/A
664N/A/**
1026N/A * The RuntimeEnvironment class is used as a placeholder for the current
112N/A * configuration this execution context (classloader) is using.
1195N/A */
1419N/Apublic final class RuntimeEnvironment {
58N/A private Configuration configuration;
58N/A private final ThreadLocal<Configuration> threadConfig;
77N/A
77N/A private static final Logger log = Logger.getLogger(RuntimeEnvironment.class.getName());
77N/A
77N/A private static RuntimeEnvironment instance = new RuntimeEnvironment();
58N/A
418N/A /**
1462N/A * Get the one and only instance of the RuntimeEnvironment
1462N/A * @return the one and only instance of the RuntimeEnvironment
1327N/A */
1327N/A public static RuntimeEnvironment getInstance() {
1463N/A return instance;
1327N/A }
1327N/A
1327N/A /**
1356N/A * Creates a new instance of RuntimeEnvironment. Private to ensure a
1356N/A * singleton pattern.
1356N/A */
1463N/A private RuntimeEnvironment() {
1463N/A configuration = new Configuration();
1463N/A threadConfig = new ThreadLocal<Configuration>() {
1463N/A @Override protected Configuration initialValue() {
1463N/A return configuration;
1463N/A }
1463N/A };
1463N/A }
1463N/A
1463N/A private String getCanonicalPath(String s) {
1463N/A try {
1463N/A File file = new File(s);
1463N/A if (!file.exists()) {
1463N/A return s;
1463N/A }
1463N/A return file.getCanonicalPath();
1463N/A } catch (IOException ex) {
1463N/A log.warning("Failed to get canonical path for '" + s + "': "
58N/A + ex.getMessage());
1436N/A log.log(Level.FINE, "getCanonicalPath", ex);
1436N/A return s;
1436N/A }
58N/A }
773N/A
773N/A public int getScanningDepth() {
773N/A return threadConfig.get().getScanningDepth();
773N/A }
58N/A
1436N/A public void setScanningDepth(int scanningDepth) {
1436N/A threadConfig.get().setScanningDepth(scanningDepth);
1436N/A }
773N/A
773N/A /**
58N/A * Get the path to the where the index database is stored
58N/A * @return the path to the index database
58N/A */
664N/A public String getDataRootPath() {
58N/A return threadConfig.get().getDataRoot();
65N/A }
1436N/A
1436N/A /**
1436N/A * Get a file representing the index database
1436N/A * @return the index database
1436N/A */
77N/A public File getDataRootFile() {
99N/A File ret = null;
99N/A String file = getDataRootPath();
1115N/A if (file != null) {
1115N/A ret = new File(file);
125N/A }
112N/A
1026N/A return ret;
129N/A }
1100N/A
129N/A /**
129N/A * Set the path to where the index database is stored
318N/A * @param dataRoot the index database
318N/A */
144N/A public void setDataRoot(String dataRoot) {
173N/A threadConfig.get().setDataRoot(getCanonicalPath(dataRoot));
253N/A }
296N/A
335N/A /**
480N/A * Get the path to where the sources are located
816N/A * @return path to where the sources are located
816N/A */
833N/A public String getSourceRootPath() {
833N/A return threadConfig.get().getSourceRoot();
1416N/A }
1185N/A
1016N/A /**
1123N/A * Get a file representing the directory where the sources are located
1125N/A * @return A file representing the directory where the sources are located
1218N/A */
1185N/A public File getSourceRootFile() {
1463N/A File ret = null;
1463N/A String file = getSourceRootPath();
1463N/A if (file != null) {
1326N/A ret = new File(file);
993N/A }
1185N/A
1185N/A return ret;
1190N/A }
1436N/A
1185N/A /**
1185N/A * Specify the source root
1252N/A * @param sourceRoot the location of the sources
1185N/A */
1185N/A public void setSourceRoot(String sourceRoot) {
1185N/A threadConfig.get().setSourceRoot(getCanonicalPath(sourceRoot));
1185N/A }
1185N/A
1185N/A /**
1185N/A * Returns a path relative to source root. This would just be a simple
1185N/A * substring operation, except we need to support symlinks outside the
1436N/A * source root.
1185N/A * @param file A file to resolve
1185N/A * @param stripCount Number of characters past source root to strip
1252N/A * @throws IOException If an IO error occurs
1185N/A * @throws FileNotFoundException If the file is not relative to source root
1185N/A * @return Path relative to source root
1185N/A */
1185N/A public String getPathRelativeToSourceRoot(File file, int stripCount) throws IOException {
1185N/A String canonicalPath = file.getCanonicalPath();
1461N/A String sourceRoot = getSourceRootPath();
1461N/A if (canonicalPath.startsWith(sourceRoot)) {
1461N/A return canonicalPath.substring(sourceRoot.length() + stripCount);
1461N/A }
1461N/A for (String allowedSymlink : getAllowedSymlinks()) {
1185N/A String allowedTarget = new File(allowedSymlink).getCanonicalPath();
993N/A if (canonicalPath.startsWith(allowedTarget)) {
993N/A return canonicalPath.substring(allowedTarget.length() + stripCount);
993N/A }
1461N/A }
1461N/A throw new FileNotFoundException("Failed to resolve '" + canonicalPath
1461N/A + "' relative to source root '" + sourceRoot + "'");
1461N/A }
1461N/A
1185N/A /**
993N/A * Do we have projects?
993N/A * @return true if we have projects
937N/A */
1436N/A public boolean hasProjects() {
1436N/A List<Project> proj = getProjects();
1436N/A return (proj != null && !proj.isEmpty());
58N/A }
816N/A
58N/A /**
58N/A * Get all of the projects
773N/A * @return a list containing all of the projects (may be null)
58N/A */
664N/A public List<Project> getProjects() {
1419N/A return threadConfig.get().getProjects();
1419N/A }
1419N/A
1327N/A /**
870N/A * Set the list of the projects
870N/A * @param projects the list of projects to use
99N/A */
1115N/A public void setProjects(List<Project> projects) {
101N/A threadConfig.get().setProjects(projects);
106N/A }
112N/A
1026N/A /**
129N/A * Register this thread in the thread/configuration map (so that all
129N/A * subsequent calls to the RuntimeEnvironment from this thread will use
129N/A * the same configuration
875N/A * @return this instance
318N/A */
1356N/A public RuntimeEnvironment register() {
173N/A threadConfig.set(configuration);
253N/A return this;
296N/A }
335N/A
480N/A /**
816N/A * Get the context name of the web application
816N/A * @return the web applications context name
993N/A */
1016N/A public String getUrlPrefix() {
1315N/A return threadConfig.get().getUrlPrefix();
1185N/A }
1463N/A
1463N/A /**
1463N/A * Set the web context name
1463N/A * @param urlPrefix the web applications context name
1463N/A */
1463N/A public void setUrlPrefix(String urlPrefix) {
1463N/A threadConfig.get().setUrlPrefix(urlPrefix);
1463N/A }
1463N/A
1463N/A /**
1463N/A * Get the name of the ctags program in use
1463N/A * @return the name of the ctags program in use
1463N/A */
1463N/A public String getCtags() {
1463N/A return threadConfig.get().getCtags();
1463N/A }
1463N/A
1463N/A /**
1463N/A * Specify the CTags program to use
1463N/A * @param ctags the ctags program to use
1463N/A */
1463N/A public void setCtags(String ctags) {
1463N/A threadConfig.get().setCtags(ctags);
1463N/A }
1463N/A
1463N/A public int getCachePages() {
1463N/A return threadConfig.get().getCachePages();
1463N/A }
1463N/A
1463N/A public void setCachePages(int cachePages) {
1463N/A threadConfig.get().setCachePages(cachePages);
1463N/A }
1463N/A
1463N/A public int getHitsPerPage() {
1463N/A return threadConfig.get().getHitsPerPage();
1463N/A }
1463N/A
1463N/A public void setHitsPerPage(int hitsPerPage) {
1463N/A threadConfig.get().setHitsPerPage(hitsPerPage);
1463N/A }
1463N/A
1463N/A /**
1463N/A * Validate that I have a Exuberant ctags program I may use
1463N/A * @return true if success, false otherwise
1463N/A */
1463N/A public boolean validateExuberantCtags() {
1463N/A boolean ret = true;
1463N/A Executor executor = new Executor(new String[] {getCtags(), "--version"});
1463N/A
58N/A executor.exec(false);
937N/A String output = executor.getOutputString();
1461N/A if (output == null || output.indexOf("Exuberant Ctags") == -1) {
1461N/A log.warning("No Exuberant Ctags found in PATH!\n" +
1461N/A "(tried running '" + getCtags() + "')\n" +
1461N/A "Please use option -c to specify path to a good Exuberant Ctags program\n"+
1461N/A "Or set it in java system property "
1461N/A + Configuration.CTAGS_CMD_PROPERTY_KEY);
1185N/A ret = false;
1185N/A }
1185N/A
1190N/A return ret;
1461N/A }
1461N/A
1461N/A /**
1461N/A * Get the max time a SMC operation may use to avoid beeing cached
1461N/A * @return the max time
1461N/A */
1461N/A public int getHistoryReaderTimeLimit() {
1461N/A return threadConfig.get().getHistoryCacheTime();
1461N/A }
1185N/A
1185N/A /**
1185N/A * Specify the maximum time a SCM operation should take before it will
1185N/A * be cached (in ms)
1185N/A * @param historyReaderTimeLimit the max time in ms before it is cached
1185N/A */
1185N/A public void setHistoryReaderTimeLimit(int historyReaderTimeLimit) {
1185N/A threadConfig.get().setHistoryCacheTime(historyReaderTimeLimit);
1185N/A }
1185N/A
1461N/A /**
1461N/A * Is history cache currently enabled?
1461N/A * @return true if history cache is enabled
1461N/A */
1461N/A public boolean useHistoryCache() {
1461N/A return threadConfig.get().isHistoryCache();
1185N/A }
1185N/A
1185N/A /**
1190N/A * Specify if we should use history cache or not
1461N/A * @param useHistoryCache set false if you do not want to use history cache
1461N/A */
1461N/A public void setUseHistoryCache(boolean useHistoryCache) {
1461N/A threadConfig.get().setHistoryCache(useHistoryCache);
1461N/A }
1461N/A
1185N/A /**
1185N/A * Should the history cache be stored in a database instead of in XML
1185N/A * files?
1185N/A *
1190N/A * @return {@code true} if the cache should be stored in a database
1461N/A */
1461N/A public boolean storeHistoryCacheInDB() {
1461N/A return threadConfig.get().isHistoryCacheInDB();
1461N/A }
58N/A
58N/A /**
58N/A * Set whether the history cache should be stored in a database.
937N/A * @param store {@code true} if the cache should be stored in a database
1461N/A */
1461N/A public void setStoreHistoryCacheInDB(boolean store) {
1461N/A threadConfig.get().setHistoryCacheInDB(store);
1461N/A }
58N/A
58N/A /**
58N/A * Should we generate HTML or not during the indexing phase
937N/A * @return true if HTML should be generated during the indexing phase
1461N/A */
1461N/A public boolean isGenerateHtml() {
1461N/A return threadConfig.get().isGenerateHtml();
1461N/A }
1461N/A
1461N/A /**
816N/A * Specify if we should generate HTML or not during the indexing phase
816N/A * @param generateHtml set this to true to pregenerate HTML
816N/A */
816N/A public void setGenerateHtml(boolean generateHtml) {
1461N/A threadConfig.get().setGenerateHtml(generateHtml);
1461N/A }
1461N/A
1461N/A /**
1461N/A * Set if we should compress the xref files or not
1461N/A * @param compressXref set to true if the generated html files should be
816N/A * compressed
816N/A */
816N/A public void setCompressXref(boolean compressXref) {
816N/A threadConfig.get().setCompressXref(compressXref);
1461N/A }
1461N/A
1461N/A /**
1461N/A * Are we using compressed HTML files?
816N/A * @return {@code true} if the html-files should be compressed.
816N/A */
816N/A public boolean isCompressXref() {
816N/A return threadConfig.get().isCompressXref();
1461N/A }
1461N/A
1461N/A public boolean isQuickContextScan() {
1461N/A return threadConfig.get().isQuickContextScan();
816N/A }
816N/A
816N/A public void setQuickContextScan(boolean quickContextScan) {
773N/A threadConfig.get().setQuickContextScan(quickContextScan);
773N/A }
773N/A
1436N/A public List<RepositoryInfo> getRepositories() {
1436N/A return threadConfig.get().getRepositories();
1436N/A }
773N/A
58N/A /**
58N/A * Set the map of external SCM repositories
58N/A * @param repositories the repositories to use
773N/A */
773N/A public void setRepositories(List<RepositoryInfo> repositories) {
773N/A threadConfig.get().setRepositories(repositories);
1436N/A }
773N/A
773N/A /**
58N/A * Set the project that is specified to be the default project to use. The
58N/A * default project is the project you will search (from the web application)
58N/A * if the page request didn't contain the cookie..
773N/A * @param defaultProject The default project to use
773N/A */
1436N/A public void setDefaultProject(Project defaultProject) {
1436N/A threadConfig.get().setDefaultProject(defaultProject);
773N/A }
773N/A
773N/A /**
773N/A * Get the project that is specified to be the default project to use. The
773N/A * default project is the project you will search (from the web application)
58N/A * if the page request didn't contain the cookie..
58N/A * @return the default project (may be null if not specified)
58N/A */
773N/A public Project getDefaultProject() {
773N/A return threadConfig.get().getDefaultProject();
1436N/A }
1436N/A
773N/A /**
773N/A * Chandan wrote the following answer on the opengrok-discuss list:
773N/A * "Traditionally search engines (specially spiders) think that large files
58N/A * are junk. Large files tend to be multimedia files etc., which text
58N/A * search spiders do not want to chew. So they ignore the contents of
58N/A * the file after a cutoff length. Lucene does this by number of words,
773N/A * which is by default is 10,000."
773N/A * By default OpenGrok will increase this limit to 60000, but it may be
773N/A * overridden in the configuration file
773N/A * @return The maximum words to index
773N/A */
773N/A public int getIndexWordLimit() {
773N/A return threadConfig.get().getIndexWordLimit();
773N/A }
773N/A
773N/A /**
773N/A * Set the number of words in a file Lucene will index.
773N/A * See getIndexWordLimit for a better description.
773N/A * @param indexWordLimit the number of words to index in a single file
773N/A */
773N/A public void setIndexWordLimit(int indexWordLimit) {
773N/A threadConfig.get().setIndexWordLimit(indexWordLimit);
773N/A }
1436N/A
1436N/A /**
773N/A * Is the verbosity flag turned on?
773N/A * @return true if we can print extra information
773N/A */
773N/A public boolean isVerbose() {
937N/A return threadConfig.get().isVerbose();
1461N/A }
1461N/A
1461N/A /**
1461N/A * Set the verbosity flag (to add extra debug information in output)
58N/A * @param verbose new value
58N/A */
58N/A public void setVerbose(boolean verbose) {
937N/A threadConfig.get().setVerbose(verbose);
1461N/A }
1461N/A
1461N/A /**
1461N/A * Is the progress print flag turned on?
58N/A * @return true if we can print per project progress %
58N/A */
58N/A public boolean isPrintProgress() {
937N/A return threadConfig.get().isPrintProgress();
1461N/A }
1461N/A
1461N/A /**
1461N/A * Set the printing of progress % flag (user convenience)
58N/A * @param printP new value
58N/A */
58N/A public void setPrintProgress(boolean printP) {
937N/A threadConfig.get().setPrintProgress(printP);
1461N/A }
1461N/A
1461N/A /**
1461N/A * Specify if a search may start with a wildcard. Note that queries
58N/A * that start with a wildcard will give a significant impact on the
58N/A * search performace.
58N/A * @param allowLeadingWildcard set to true to activate (disabled by default)
937N/A */
1461N/A public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
1461N/A threadConfig.get().setAllowLeadingWildcard(allowLeadingWildcard);
1461N/A }
1461N/A
58N/A /**
58N/A * Is leading wildcards allowed?
58N/A * @return true if a search may start with a wildcard
937N/A */
1461N/A public boolean isAllowLeadingWildcard() {
1461N/A return threadConfig.get().isAllowLeadingWildcard();
1461N/A }
1461N/A
58N/A public IgnoredNames getIgnoredNames() {
58N/A return threadConfig.get().getIgnoredNames();
58N/A }
937N/A
1461N/A public void setIgnoredNames(IgnoredNames ignoredNames) {
1461N/A threadConfig.get().setIgnoredNames(ignoredNames);
1461N/A }
1461N/A
664N/A public Filter getIncludedNames() {
58N/A return threadConfig.get().getIncludedNames();
58N/A }
937N/A
1461N/A public void setIncludedNames(Filter includedNames) {
1461N/A threadConfig.get().setIncludedNames(includedNames);
1461N/A }
1461N/A
664N/A /**
58N/A * Returns the user page for the history listing
58N/A * @return the URL string fragment preceeding the username
937N/A */
1461N/A public String getUserPage() {
1469N/A return threadConfig.get().getUserPage();
1469N/A }
1469N/A
1469N/A /**
1469N/A * Get the client command to use to access the repository for the given
1469N/A * fully quallified classname.
1461N/A * @param clazzName name of the targeting class
58N/A * @return {@code null} if not yet set, the client command otherwise.
58N/A */
58N/A public String getRepoCmd(String clazzName) {
937N/A return threadConfig.get().getRepoCmd(clazzName);
1185N/A }
1252N/A
1252N/A /**
1436N/A * Set the client command to use to access the repository for the given
1436N/A * fully quallified classname.
1436N/A * @param clazzName name of the targeting class. If {@code null} this method
1469N/A * does nothing.
1185N/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) {
1461N/A return threadConfig.get().setRepoCmd(clazzName, cmd);
1461N/A }
1461N/A
1461N/A /**
1461N/A * Sets the user page for the history listing
1461N/A * @param userPage the URL fragment preceeding the username from history
1461N/A */
1461N/A public void setUserPage(String userPage) {
65N/A threadConfig.get().setUserPage(userPage);
65N/A }
65N/A
937N/A /**
1461N/A * Returns the user page suffix for the history listing
1461N/A * @return the URL string fragment following the username
1461N/A */
1461N/A public String getUserPageSuffix() {
65N/A return threadConfig.get().getUserPageSuffix();
65N/A }
65N/A
937N/A /**
1461N/A * Sets the user page suffix for the history listing
1461N/A * @param userPageSuffix the URL fragment following the username from history
1461N/A */
1461N/A public void setUserPageSuffix(String userPageSuffix) {
1461N/A threadConfig.get().setUserPageSuffix(userPageSuffix);
1461N/A }
77N/A
77N/A /**
77N/A * Returns the bug page for the history listing
937N/A * @return the URL string fragment preceeding the bug ID
1461N/A */
1461N/A public String getBugPage() {
1461N/A return threadConfig.get().getBugPage();
1461N/A }
1461N/A
1461N/A /**
77N/A * Sets the bug page for the history listing
77N/A * @param bugPage the URL fragment preceeding the bug ID
77N/A */
99N/A public void setBugPage(String bugPage) {
1461N/A threadConfig.get().setBugPage(bugPage);
1461N/A }
1461N/A
1461N/A /**
1461N/A * Returns the bug regex for the history listing
1461N/A * @return the regex that is looked for in history comments
1461N/A */
1461N/A public String getBugPattern() {
1461N/A return threadConfig.get().getBugPattern();
1461N/A }
1461N/A
99N/A /**
99N/A * Sets the bug regex for the history listing
99N/A * @param bugPattern the regex to search history comments
99N/A */
1461N/A public void setBugPattern(String bugPattern) {
1461N/A threadConfig.get().setBugPattern(bugPattern);
1461N/A }
1461N/A
1461N/A
99N/A /**
99N/A * Returns the review(ARC) page for the history listing
99N/A * @return the URL string fragment preceeding the review page ID
99N/A */
1461N/A public String getReviewPage() {
1461N/A return threadConfig.get().getReviewPage();
1461N/A }
1461N/A
99N/A /**
99N/A * Sets the review(ARC) page for the history listing
99N/A * @param reviewPage the URL fragment preceeding the review page ID
99N/A */
1461N/A public void setReviewPage(String reviewPage) {
1461N/A threadConfig.get().setReviewPage(reviewPage);
1461N/A }
1461N/A
99N/A /**
99N/A * Returns the review(ARC) regex for the history listing
99N/A * @return the regex that is looked for in history comments
937N/A */
1461N/A public String getReviewPattern() {
1461N/A return threadConfig.get().getReviewPattern();
1461N/A }
1461N/A
1115N/A /**
1115N/A * Sets the review(ARC) regex for the history listing
1115N/A * @param reviewPattern the regex to search history comments
1115N/A */
1461N/A public void setReviewPattern(String reviewPattern) {
1461N/A threadConfig.get().setReviewPattern(reviewPattern);
1461N/A }
1461N/A
1461N/A public String getWebappLAF() {
1461N/A return threadConfig.get().getWebappLAF();
1115N/A }
1115N/A
1461N/A public void setWebappLAF(String laf) {
1461N/A threadConfig.get().setWebappLAF(laf);
1461N/A }
1461N/A
1461N/A public boolean isRemoteScmSupported() {
1461N/A return threadConfig.get().isRemoteScmSupported();
125N/A }
125N/A
125N/A public void setRemoteScmSupported(boolean supported) {
937N/A threadConfig.get().setRemoteScmSupported(supported);
1461N/A }
1461N/A
1461N/A public boolean isOptimizeDatabase() {
1461N/A return threadConfig.get().isOptimizeDatabase();
125N/A }
125N/A
125N/A public void setOptimizeDatabase(boolean optimizeDatabase) {
106N/A threadConfig.get().setOptimizeDatabase(optimizeDatabase);
106N/A }
937N/A
1461N/A public boolean isUsingLuceneLocking() {
1461N/A return threadConfig.get().isUsingLuceneLocking();
1461N/A }
1461N/A
1461N/A public void setUsingLuceneLocking(boolean useLuceneLocking) {
106N/A threadConfig.get().setUsingLuceneLocking(useLuceneLocking);
106N/A }
106N/A
937N/A public boolean isIndexVersionedFilesOnly() {
1461N/A return threadConfig.get().isIndexVersionedFilesOnly();
1461N/A }
1461N/A
1461N/A public void setIndexVersionedFilesOnly(boolean indexVersionedFilesOnly) {
1461N/A threadConfig.get().setIndexVersionedFilesOnly(indexVersionedFilesOnly);
1461N/A }
1461N/A
106N/A public Date getDateForLastIndexRun() {
106N/A return threadConfig.get().getDateForLastIndexRun();
106N/A }
112N/A
1461N/A public String getDatabaseDriver() {
1461N/A return threadConfig.get().getDatabaseDriver();
1461N/A }
1461N/A
1461N/A public void setDatabaseDriver(String databaseDriver) {
1461N/A threadConfig.get().setDatabaseDriver(databaseDriver);
1461N/A }
112N/A
1461N/A public String getDatabaseUrl() {
112N/A return threadConfig.get().getDatabaseUrl();
112N/A }
1461N/A
1461N/A public void setDatabaseUrl(String databaseUrl) {
1461N/A threadConfig.get().setDatabaseUrl(databaseUrl);
1461N/A }
1461N/A
1461N/A public Set<String> getAllowedSymlinks() {
112N/A return threadConfig.get().getAllowedSymlinks();
112N/A }
112N/A
129N/A public void setAllowedSymlinks(Set<String> allowedSymlinks) {
1461N/A threadConfig.get().setAllowedSymlinks(allowedSymlinks);
1461N/A }
1461N/A
1461N/A /**
1461N/A * Return whether e-mail addresses should be obfuscated in the xref.
1461N/A */
1026N/A public boolean isObfuscatingEMailAddresses() {
1026N/A return threadConfig.get().isObfuscatingEMailAddresses();
1026N/A }
1026N/A
1461N/A /**
1461N/A * Set whether e-mail addresses should be obfuscated in the xref.
1461N/A */
1461N/A public void setObfuscatingEMailAddresses(boolean obfuscate) {
1461N/A threadConfig.get().setObfuscatingEMailAddresses(obfuscate);
1461N/A }
1026N/A
1026N/A /**
1026N/A * Should status.jsp print internal settings, like paths and database
1026N/A * URLs?
1461N/A *
1469N/A * @return {@code true} if status.jsp should show the configuration,
1469N/A * {@code false} otherwise
1469N/A */
1461N/A public boolean isChattyStatusPage() {
129N/A return threadConfig.get().isChattyStatusPage();
129N/A }
129N/A
129N/A /**
1461N/A * Set whether status.jsp should print internal settings.
1469N/A *
1469N/A * @param chatty {@code true} if internal settings should be printed,
1461N/A * {@code false} otherwise
129N/A */
129N/A public void setChattyStatusPage(boolean chatty) {
129N/A threadConfig.get().setChattyStatusPage(chatty);
129N/A }
1461N/A
1469N/A /**
1469N/A * Read an configuration file and set it as the current configuration.
1469N/A * @param file the file to read
1461N/A * @throws IOException if an error occurs
1100N/A */
1100N/A public void readConfiguration(File file) throws IOException {
1100N/A setConfiguration(Configuration.read(file));
1100N/A }
1461N/A
1469N/A /**
1469N/A * Write the current configuration to a file
1461N/A * @param file the file to write the configuration into
1100N/A * @throws IOException if an error occurs
1100N/A */
1100N/A public void writeConfiguration(File file) throws IOException {
1100N/A threadConfig.get().write(file);
1461N/A }
1469N/A
1469N/A /**
1461N/A * Write the current configuration to a socket
129N/A * @param host the host address to receive the configuration
129N/A * @param port the port to use on the host
129N/A * @throws IOException if an error occurs
129N/A */
1461N/A public void writeConfiguration(InetAddress host, int port) throws IOException {
1469N/A Socket sock = new Socket(host, port);
1469N/A XMLEncoder e = new XMLEncoder(sock.getOutputStream());
1461N/A e.writeObject(threadConfig.get());
129N/A e.close();
129N/A IOUtils.close(sock);
129N/A }
129N/A
1461N/A protected void writeConfiguration() throws IOException {
1469N/A writeConfiguration(configServerSocket.getInetAddress(), configServerSocket.getLocalPort());
1461N/A }
1461N/A
129N/A public void setConfiguration(Configuration configuration) {
129N/A this.configuration = configuration;
129N/A register();
129N/A HistoryGuru.getInstance().invalidateRepositories(configuration.getRepositories());
1461N/A }
1469N/A
1461N/A public Configuration getConfiguration() {
1461N/A return this.threadConfig.get();
129N/A }
129N/A
129N/A private ServerSocket configServerSocket;
937N/A
1461N/A /**
1469N/A * Try to stop the configuration listener thread
1469N/A */
1461N/A public void stopConfigurationListenerThread() {
318N/A IOUtils.close(configServerSocket);
318N/A }
318N/A
318N/A /**
1461N/A * Start a thread to listen on a socket to receive new configurations
1469N/A * to use.
1469N/A * @param endpoint The socket address to listen on
1461N/A * @return true if the endpoint was available (and the thread was started)
318N/A */
318N/A public boolean startConfigurationListenerThread(SocketAddress endpoint) {
318N/A boolean ret = false;
318N/A
1461N/A try {
1469N/A configServerSocket = new ServerSocket();
1461N/A configServerSocket.bind(endpoint);
1461N/A ret = true;
318N/A final ServerSocket sock = configServerSocket;
318N/A Thread t = new Thread(new Runnable() {
318N/A @Override
318N/A public void run() {
1461N/A ByteArrayOutputStream bos = new ByteArrayOutputStream(1<<13);
1469N/A while (!sock.isClosed()) {
1461N/A Socket s = null;
1461N/A BufferedInputStream in = null;
318N/A try {
318N/A s = sock.accept();
318N/A bos.reset();
144N/A log.info("Re-configure request from " +
1461N/A s.getInetAddress().getHostAddress());
1461N/A in = new BufferedInputStream(s.getInputStream());
1461N/A byte[] buf = new byte[1024];
1461N/A int len;
1461N/A while ((len = in.read(buf)) != -1) {
1461N/A bos.write(buf, 0, len);
1461N/A }
144N/A buf = bos.toByteArray();
144N/A if (log.isLoggable(Level.FINE)) {
144N/A log.fine("New config: \n" + new String(buf));
144N/A }
1461N/A XMLDecoder d = new XMLDecoder(new ByteArrayInputStream(buf));
1461N/A Object obj = d.readObject();
1461N/A d.close();
1461N/A
1461N/A if (obj instanceof Configuration) {
1461N/A setConfiguration((Configuration)obj);
1461N/A log.log(Level.INFO, "Configuration updated: {0}", configuration.getSourceRoot());
1461N/A }
144N/A } catch (IOException e) {
1461N/A log.warning("Error reading config file: " + e.getMessage());
144N/A log.log(Level.FINE, "run", e);
173N/A } catch (RuntimeException e) {
1461N/A log.warning("Error parsing config file: " + e.getMessage());
1461N/A log.log(Level.FINE, "run", e);
1461N/A } finally {
1461N/A IOUtils.close(s);
1461N/A IOUtils.close(in);
173N/A }
173N/A }
173N/A }
173N/A });
1461N/A t.start();
1461N/A } catch (UnknownHostException ex) {
1461N/A log.log(Level.FINE,"Problem resolving sender", ex);
1461N/A } catch (IOException ex) {
1461N/A log.log(Level.FINE,"I/O error when waiting for config", ex);
173N/A }
173N/A
173N/A if (!ret && configServerSocket != null) {
234N/A IOUtils.close(configServerSocket);
1461N/A }
1461N/A
1461N/A return ret;
1461N/A }
1461N/A}
253N/A