Skip to content

Commit b5b252e

Browse files
committed
AnalyzerGuru is actually (unfortunately) a singleton at the moment
1 parent 5cdfd57 commit b5b252e

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public static Map<String, String> getfileTypeDescriptions() {
389389
return Collections.unmodifiableMap(fileTypeDescriptions);
390390
}
391391

392-
public List<AnalyzerFactory> getAnalyzerFactories() {
392+
public static List<AnalyzerFactory> getAnalyzerFactories() {
393393
return Collections.unmodifiableList(factories);
394394
}
395395

@@ -575,9 +575,8 @@ public static void returnAnalyzers() {
575575
* @throws IOException If an exception occurs while collecting the data
576576
* @throws InterruptedException if a timeout occurs
577577
*/
578-
public void populateDocument(Document doc, File file, String path,
579-
AbstractAnalyzer fa, Writer xrefOut) throws IOException,
580-
InterruptedException {
578+
public static void populateDocument(Document doc, File file, String path,
579+
AbstractAnalyzer fa, Writer xrefOut) throws IOException, InterruptedException {
581580

582581
String date = DateTools.timeToString(file.lastModified(),
583582
DateTools.Resolution.MILLISECOND);
@@ -1190,4 +1189,8 @@ private static boolean factoriesDifferent(AnalyzerFactory a,
11901189
}
11911190
return a_name == null || !a_name.equals(b_name);
11921191
}
1192+
1193+
/* private to enforce static */
1194+
private AnalyzerGuru() {
1195+
}
11931196
}

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public class IndexDatabase {
129129
private final Map<String, IndexedSymlink> indexedSymlinks = new TreeMap<>(
130130
Comparator.comparingInt(String::length).thenComparing(o -> o));
131131

132-
private Project project;
132+
private final Project project;
133133
private FSDirectory indexDirectory;
134134
private IndexReader reader;
135135
private IndexWriter writer;
@@ -138,7 +138,6 @@ public class IndexDatabase {
138138
private TermsEnum uidIter;
139139
private PostingsEnum postsIter;
140140
private PathAccepter pathAccepter;
141-
private AnalyzerGuru analyzerGuru;
142141
private File xrefDir;
143142
private boolean interrupted;
144143
private CopyOnWriteArrayList<IndexChangedListener> listeners;
@@ -307,7 +306,6 @@ private void initialize() throws IOException {
307306
lockfact = pickLockFactory(env);
308307
indexDirectory = FSDirectory.open(indexDir.toPath(), lockfact);
309308
pathAccepter = env.getPathAccepter();
310-
analyzerGuru = new AnalyzerGuru();
311309
xrefDir = new File(env.getDataRootFile(), XREF_DIR);
312310
listeners = new CopyOnWriteArrayList<>();
313311
dirtyFile = new File(indexDir, "dirty");
@@ -726,7 +724,7 @@ private void addFile(File file, String path, Ctags ctags)
726724

727725
Document doc = new Document();
728726
try (Writer xrefOut = newXrefWriter(fa, path)) {
729-
analyzerGuru.populateDocument(doc, file, path, fa, xrefOut);
727+
AnalyzerGuru.populateDocument(doc, file, path, fa, xrefOut);
730728
} catch (InterruptedException e) {
731729
LOGGER.log(Level.WARNING, "File ''{0}'' interrupted--{1}",
732730
new Object[]{path, e.getMessage()});

opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/LuceneCompatibilityTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public static Test suite() {
7272
}
7373
}
7474
Analyzer testA;
75-
AnalyzerGuru guru;
7675
Method testM;
7776
Object testC = null;
7877

@@ -81,15 +80,14 @@ public static Test suite() {
8180
*/
8281
@Override
8382
protected void setUp() throws Exception {
84-
guru = new AnalyzerGuru();
8583
Class<?> c = Class.forName(LUCENE_TEST_CLASS);
8684
//testC = c.newInstance(); //this is static call
8785
Class<?>[] argTypes = {TokenStream.class, String[].class, int[].class, int[].class, String[].class, int[].class, int[].class, Integer.class, boolean.class};
8886
testM = c.getDeclaredMethod(LUCENE_TEST_METHOD, argTypes);
8987
}
9088

9189
public void testCompatibility() throws Exception {
92-
for (AnalyzerFactory fa : guru.getAnalyzerFactories()) {
90+
for (AnalyzerFactory fa : AnalyzerGuru.getAnalyzerFactories()) {
9391
String input = "Hello world";
9492
String[] output = new String[]{"Hello", "world"};
9593
testA = fa.getAnalyzer();

0 commit comments

Comments
 (0)