Index: contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java =================================================================== --- contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java (revision 781346) +++ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java (working copy) @@ -128,7 +128,7 @@ FileUtils.fullyDelete(indexDir); } indexDir.mkdirs(); - directory = FSDirectory.getDirectory(indexDir); + directory = FSDirectory.open(indexDir); } else { directory = new RAMDirectory(); } Index: contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/utils/QualityQueriesFinder.java =================================================================== --- contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/utils/QualityQueriesFinder.java (revision 781346) +++ contrib/benchmark/src/java/org/apache/lucene/benchmark/quality/utils/QualityQueriesFinder.java (working copy) @@ -52,7 +52,7 @@ System.err.println("Usage: java QualityQueriesFinder "); System.exit(1); } - QualityQueriesFinder qqf = new QualityQueriesFinder(FSDirectory.getDirectory(new File(args[0]))); + QualityQueriesFinder qqf = new QualityQueriesFinder(FSDirectory.open(new File(args[0]))); String q[] = qqf.bestQueries("body",20); for (int i=0; i "); } - FSDirectory directory = FSDirectory.getDirectory(args[0], false); + FSDirectory directory = FSDirectory.open(new File(args[0])); IndexSearcher searcher = new IndexSearcher(directory); String query = args[1]; Index: contrib/wordnet/src/java/org/apache/lucene/wordnet/SynLookup.java =================================================================== --- contrib/wordnet/src/java/org/apache/lucene/wordnet/SynLookup.java (revision 781346) +++ contrib/wordnet/src/java/org/apache/lucene/wordnet/SynLookup.java (working copy) @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.StringReader; +import java.io.File; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; @@ -51,7 +52,7 @@ "java org.apache.lucene.wordnet.SynLookup "); } - FSDirectory directory = FSDirectory.getDirectory(args[0], false); + FSDirectory directory = FSDirectory.open(new File(args[0])); IndexSearcher searcher = new IndexSearcher(directory); String word = args[1]; Index: src/demo/org/apache/lucene/demo/DeleteFiles.java =================================================================== --- src/demo/org/apache/lucene/demo/DeleteFiles.java (revision 781346) +++ src/demo/org/apache/lucene/demo/DeleteFiles.java (working copy) @@ -17,6 +17,8 @@ * limitations under the License. */ +import java.io.File; + import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.index.IndexReader; @@ -37,7 +39,7 @@ System.exit(1); } try { - Directory directory = FSDirectory.getDirectory("index"); + Directory directory = FSDirectory.open(new File("index")); IndexReader reader = IndexReader.open(directory); Term term = new Term("path", args[0]); Index: src/java/org/apache/lucene/index/CheckIndex.java =================================================================== --- src/java/org/apache/lucene/index/CheckIndex.java (revision 781346) +++ src/java/org/apache/lucene/index/CheckIndex.java (working copy) @@ -26,6 +26,7 @@ import java.text.NumberFormat; import java.io.PrintStream; import java.io.IOException; +import java.io.File; import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -702,7 +703,7 @@ System.out.println("\nOpening index @ " + indexPath + "\n"); Directory dir = null; try { - dir = FSDirectory.getDirectory(indexPath); + dir = FSDirectory.open(new File(indexPath)); } catch (Throwable t) { System.out.println("ERROR: could not open directory \"" + indexPath + "\"; exiting"); t.printStackTrace(System.out); Index: src/java/org/apache/lucene/index/IndexModifier.java =================================================================== --- src/java/org/apache/lucene/index/IndexModifier.java (revision 781346) +++ src/java/org/apache/lucene/index/IndexModifier.java (working copy) @@ -97,7 +97,7 @@ protected Directory directory = null; protected Analyzer analyzer = null; - protected boolean open = false; + protected boolean open = false, closeDir = false; // Lucene defaults: protected PrintStream infoStream = null; @@ -135,9 +135,11 @@ * has this index open (write.lock could not * be obtained) * @throws IOException if there is a low-level IO error + * @deprecated */ public IndexModifier(String dirName, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException { Directory dir = FSDirectory.getDirectory(dirName); + this.closeDir = true; init(dir, analyzer, create); } @@ -153,9 +155,11 @@ * has this index open (write.lock could not * be obtained) * @throws IOException if there is a low-level IO error + * @deprecated */ public IndexModifier(File file, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException { Directory dir = FSDirectory.getDirectory(file); + this.closeDir = true; init(dir, analyzer, create); } @@ -578,6 +582,10 @@ indexReader = null; } open = false; + if (closeDir) { + directory.close(); + } + closeDir = false; } } Index: src/java/org/apache/lucene/index/IndexReader.java =================================================================== --- src/java/org/apache/lucene/index/IndexReader.java (revision 781346) +++ src/java/org/apache/lucene/index/IndexReader.java (working copy) @@ -204,7 +204,8 @@ * path. * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error - * @deprecated Use {@link #open(Directory, boolean)} instead + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #open(Directory, boolean)} instead * @param path the path to the index directory */ public static IndexReader open(String path) throws CorruptIndexException, IOException { return open(FSDirectory.getDirectory(path), true, null, null, false); @@ -220,7 +221,9 @@ * @param path the path to the index directory * @param readOnly true if this should be a readOnly * reader - * @deprecated Use {@link #open(Directory, boolean)} instead*/ + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #open(Directory, boolean)} instead + */ public static IndexReader open(String path, boolean readOnly) throws CorruptIndexException, IOException { return open(FSDirectory.getDirectory(path), true, null, null, readOnly); } @@ -230,7 +233,8 @@ * @param path the path to the index directory * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error - * @deprecated Use {@link #open(Directory, boolean)} instead + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #open(Directory, boolean)} instead */ public static IndexReader open(File path) throws CorruptIndexException, IOException { return open(FSDirectory.getDirectory(path), true, null, null, false); @@ -246,8 +250,9 @@ * @param path the path to the index directory * @param readOnly true if this should be a readOnly * reader - * @deprecated Use {@link #open(Directory, boolean)} - * instead */ + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #open(Directory, boolean)} instead + */ public static IndexReader open(File path, boolean readOnly) throws CorruptIndexException, IOException { return open(FSDirectory.getDirectory(path), true, null, null, readOnly); } @@ -500,6 +505,8 @@ * {@link #isCurrent()} instead. * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #lastModified(Directory)} instead */ public static long lastModified(String directory) throws CorruptIndexException, IOException { return lastModified(new File(directory)); @@ -511,13 +518,16 @@ * {@link #isCurrent()} instead. * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #lastModified(Directory)} instead */ public static long lastModified(File fileDirectory) throws CorruptIndexException, IOException { - return ((Long) new SegmentInfos.FindSegmentsFile(fileDirectory) { - public Object doBody(String segmentFileName) { - return new Long(FSDirectory.fileModified(fileDirectory, segmentFileName)); - } - }.run()).longValue(); + Directory dir = FSDirectory.open(fileDirectory); // use new static method here + try { + return lastModified(dir); + } finally { + dir.close(); + } } /** @@ -544,6 +554,8 @@ * @return version number. * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #getCurrentVersion(Directory)} instead */ public static long getCurrentVersion(String directory) throws CorruptIndexException, IOException { return getCurrentVersion(new File(directory)); @@ -558,7 +570,8 @@ * @return version number. * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error - * @deprecated Use {@link #getCurrentVersion(Directory)} instead + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #getCurrentVersion(Directory)} instead */ public static long getCurrentVersion(File directory) throws CorruptIndexException, IOException { Directory dir = FSDirectory.getDirectory(directory); @@ -741,6 +754,8 @@ * false is returned. * @param directory the directory to check for an index * @return true if an index exists; false otherwise + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #indexExists(Directory)} instead */ public static boolean indexExists(String directory) { return indexExists(new File(directory)); @@ -751,6 +766,8 @@ * If the directory does not exist or if there is no index in it. * @param directory the directory to check for an index * @return true if an index exists; false otherwise + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #indexExists(Directory)} instead */ public static boolean indexExists(File directory) { @@ -1171,7 +1188,8 @@ * currently locked. * @param directory the directory to check for a lock * @throws IOException if there is a low-level IO error - * @deprecated Please use {@link IndexWriter#isLocked(Directory)} instead + * @deprecated This method will be removed in the 3.0 release. + * Use {@link #isLocked(Directory)} instead */ public static boolean isLocked(String directory) throws IOException { Directory dir = FSDirectory.getDirectory(directory); @@ -1236,7 +1254,7 @@ File file = new File(filename); String dirname = file.getAbsoluteFile().getParent(); filename = file.getName(); - dir = FSDirectory.getDirectory(dirname); + dir = FSDirectory.open(new File(dirname)); cfr = new CompoundFileReader(dir, filename); String [] files = cfr.list(); Index: src/java/org/apache/lucene/index/SegmentInfos.java =================================================================== --- src/java/org/apache/lucene/index/SegmentInfos.java (revision 781346) +++ src/java/org/apache/lucene/index/SegmentInfos.java (working copy) @@ -523,13 +523,8 @@ */ public abstract static class FindSegmentsFile { - File fileDirectory; Directory directory; - public FindSegmentsFile(File directory) { - this.fileDirectory = directory; - } - public FindSegmentsFile(Directory directory) { this.directory = directory; } @@ -572,10 +567,7 @@ long genA = -1; - if (directory != null) - files = directory.listAll(); - else - files = FSDirectory.listAll(fileDirectory); + files = directory.listAll(); if (files != null) genA = getCurrentSegmentGeneration(files); @@ -722,10 +714,7 @@ gen-1); final boolean prevExists; - if (directory != null) - prevExists = directory.fileExists(prevSegmentFileName); - else - prevExists = new File(fileDirectory, prevSegmentFileName).exists(); + prevExists = directory.fileExists(prevSegmentFileName); if (prevExists) { message("fallback to prior segment file '" + prevSegmentFileName + "'"); Index: src/java/org/apache/lucene/search/IndexSearcher.java =================================================================== --- src/java/org/apache/lucene/search/IndexSearcher.java (revision 781346) +++ src/java/org/apache/lucene/search/IndexSearcher.java (working copy) @@ -46,7 +46,7 @@ /** Creates a searcher searching the index in the named directory. * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error - * @deprecated Use {@link #IndexSearcher(String, boolean)} instead + * @deprecated Use {@link #IndexSearcher(Directory, boolean)} instead */ public IndexSearcher(String path) throws CorruptIndexException, IOException { this(IndexReader.open(path), true); @@ -62,6 +62,7 @@ * will be opened readOnly * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error + * @deprecated Use {@link #IndexSearcher(Directory, boolean)} instead */ public IndexSearcher(String path, boolean readOnly) throws CorruptIndexException, IOException { this(IndexReader.open(path, readOnly), true); Index: src/java/overview.html =================================================================== --- src/java/overview.html (revision 781346) +++ src/java/overview.html (working copy) @@ -40,7 +40,7 @@     // Store the index in memory:
    Directory directory = new RAMDirectory();
    // To store an index on disk, use this instead:
-    //Directory directory = FSDirectory.getDirectory("/tmp/testindex");
+    //Directory directory = FSDirectory.open("/tmp/testindex");
    IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
                                          new IndexWriter.MaxFieldLength(25000));
    Document doc = new Document();
Index: src/test/org/apache/lucene/TestDemo.java =================================================================== --- src/test/org/apache/lucene/TestDemo.java (revision 781346) +++ src/test/org/apache/lucene/TestDemo.java (working copy) @@ -49,7 +49,7 @@ // Store the index in memory: Directory directory = new RAMDirectory(); // To store an index on disk, use this instead: - //Directory directory = FSDirectory.getDirectory("/tmp/testindex"); + //Directory directory = FSDirectory.open(new File("/tmp/testindex")); IndexWriter iwriter = new IndexWriter(directory, analyzer, true, new IndexWriter.MaxFieldLength(25000)); Document doc = new Document(); Index: src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java =================================================================== --- src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java (revision 781346) +++ src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java (working copy) @@ -54,7 +54,7 @@ try { // Sometimes past test leaves the dir _TestUtil.rmDir(dir); - Directory fsDir = FSDirectory.getDirectory(dir); + Directory fsDir = FSDirectory.open(dir); runTest(fsDir); fsDir.close(); } finally {