diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java index eee9091c81a..f8f5a4cfd11 100644 --- a/src/java/org/apache/solr/core/SolrCore.java +++ b/src/java/org/apache/solr/core/SolrCore.java @@ -29,6 +29,7 @@ import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.DOMUtil; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.SimpleOrderedMap; +import org.apache.solr.handler.admin.ShowFileRequestHandler; import org.apache.solr.handler.component.*; import org.apache.solr.highlight.DefaultSolrHighlighter; import org.apache.solr.highlight.SolrHighlighter; @@ -430,6 +431,9 @@ public final class SolrCore { solrConfig.get("highlighting/@class", DefaultSolrHighlighter.class.getName()) ); highlighter.initalize( solrConfig ); + + // Handle things that should eventually go away + initDeprecatedSupport(); final CountDownLatch latch = new CountDownLatch(1); @@ -1319,7 +1323,47 @@ public final class SolrCore { public ValueSourceParser getValueSourceParser(String parserName) { return valueSourceParsers.get(parserName); } + + /** + * Manage anything that should be taken care of in case configs change + */ + private void initDeprecatedSupport() + { + // TODO -- this should be removed in deprecation release... + String gettable = solrConfig.get("admin/gettableFiles", null ); + if( gettable != null ) { + log.warning( + "solrconfig.xml uses deprecated , Please "+ + "update your config to use the ShowFileRequestHandler." ); + if( getRequestHandler( "admin/file" ) == null ) { + NamedList invariants = new NamedList(); + + // Hide everything... + Set hide = new HashSet(); + File configdir = new File( solrConfig.getResourceLoader().getConfigDir() ); + for( String file : configdir.list() ) { + hide.add( file.toUpperCase() ); + } + + // except the "gettable" list + StringTokenizer st = new StringTokenizer( gettable ); + while( st.hasMoreTokens() ) { + hide.remove( st.nextToken().toUpperCase() ); + } + for( String s : hide ) { + invariants.add( ShowFileRequestHandler.HIDDEN, s ); + } + + NamedList args = new NamedList(); + args.add( "invariants", invariants ); + ShowFileRequestHandler handler = new ShowFileRequestHandler(); + handler.init( args ); + reqHandlers.register("admin/file", handler); + log.warning( "adding ShowFileRequestHandler with hidden files: "+hide ); + } + } + } public CoreDescriptor getCoreDescriptor() { return coreDescriptor; diff --git a/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java b/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java index 3fd2fb8ed0f..dd17929eb5a 100644 --- a/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java +++ b/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java @@ -111,6 +111,11 @@ public class ShowFileRequestHandler extends RequestHandlerBase } } + public Set getHiddenFiles() + { + return hiddenFiles; + } + @Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { diff --git a/src/test/org/apache/solr/core/TestConfig.java b/src/test/org/apache/solr/core/TestConfig.java index 8b2410d29ad..a8e7b462766 100644 --- a/src/test/org/apache/solr/core/TestConfig.java +++ b/src/test/org/apache/solr/core/TestConfig.java @@ -17,6 +17,7 @@ package org.apache.solr.core; +import org.apache.solr.handler.admin.ShowFileRequestHandler; import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.update.SolrIndexConfig; import org.w3c.dom.Node; @@ -62,4 +63,17 @@ public class TestConfig extends AbstractSolrTestCase { boolean luceneAutoCommit = solrConfig.getBool("indexDefaults/luceneAutoCommit"); assertTrue(luceneAutoCommit + " does not equal: " + false, luceneAutoCommit == false); } + + // sometime if the config referes to old things, it must be replaced with new stuff + public void testAutomaticDeprecationSupport() + { + // make sure the "admin/file" handler is registered + ShowFileRequestHandler handler = (ShowFileRequestHandler) h.getCore().getRequestHandler( "admin/file" ); + assertTrue( "file handler should have been automatically registered", handler!=null ); + + //System.out.println( handler.getHiddenFiles() ); + // should not contain: solrconfig.xml scheam.xml admin-extra.html + assertFalse( handler.getHiddenFiles().contains( "scheam.xml".toUpperCase() ) ); + assertTrue( handler.getHiddenFiles().contains( "PROTWORDS.TXT" ) ); + } } \ No newline at end of file