Skip to content

Commit 91f8f84

Browse files
author
Vladimir Kotal
committed
remove deprecated IndexAnalysisSettings (version 1)
fixes #2290
1 parent 5497485 commit 91f8f84

File tree

9 files changed

+98
-511
lines changed

9 files changed

+98
-511
lines changed

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

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@
2929
import java.io.ObjectInputStream;
3030
import java.io.ObjectOutputStream;
3131
import java.io.Serializable;
32+
import java.util.Collections;
33+
import java.util.HashMap;
34+
import java.util.Map;
3235

3336
/**
3437
* Represents a serializable gathering of some top-level metadata concerning the
3538
* operation of {@link IndexDatabase} -- and persisted therein too -- which are
3639
* re-compared upon each indexing run since changes to them might require
3740
* re-indexing particular files or in certain cases all files.
3841
*/
39-
@Deprecated
4042
public final class IndexAnalysisSettings implements Serializable {
4143

42-
private static final long serialVersionUID = 1005610724146719938L;
44+
private static final long serialVersionUID = 1172403004716059609L;
4345

4446
private String projectName;
4547

@@ -57,6 +59,14 @@ public final class IndexAnalysisSettings implements Serializable {
5759
*/
5860
private Long analyzerGuruVersion;
5961

62+
/**
63+
* (nullable because otherwise custom de-serialization does not work, as a
64+
* {@code final} initialized value may not actually happen because Java
65+
* de-serialization circumvents normal construction.)
66+
* @serial
67+
*/
68+
private Map<String, Long> analyzersVersions = new HashMap<>();
69+
6070
/**
6171
* Gets the project name to be used to distinguish different instances of
6272
* {@link IndexAnalysisSettings} that might be returned by a Lucene
@@ -93,6 +103,32 @@ public void setAnalyzerGuruVersion(Long value) {
93103
this.analyzerGuruVersion = value;
94104
}
95105

106+
/**
107+
* Gets the version number for the specified file type name if it exists
108+
* @return a defined value or {@code null} if unknown
109+
*/
110+
public Long getAnalyzerVersion(String fileTypeName) {
111+
return analyzersVersions.get(fileTypeName);
112+
}
113+
114+
/**
115+
* Gets an unmodifiable view of the map of file type names to version
116+
* numbers.
117+
* @return a defined instance
118+
*/
119+
public Map<String, Long> getAnalyzersVersions() {
120+
return Collections.unmodifiableMap(analyzersVersions);
121+
}
122+
123+
/**
124+
* Replaces the contents of the instance's map with the {@code values}.
125+
* @param values a defined instance
126+
*/
127+
public void setAnalyzersVersions(Map<String, Long> values) {
128+
analyzersVersions.clear();
129+
analyzersVersions.putAll(values);
130+
}
131+
96132
/**
97133
* Creates a binary representation of this object.
98134
* @return a byte array representing this object
@@ -137,6 +173,20 @@ private void readObject(ObjectInputStream in) throws ClassNotFoundException,
137173
hasValue = in.readBoolean();
138174
long vlong = in.readLong();
139175
analyzerGuruVersion = hasValue ? vlong : null;
176+
177+
/**
178+
* De-serialization circumvents normal construction, so the following
179+
* field could be null.
180+
*/
181+
if (analyzersVersions == null) {
182+
analyzersVersions = new HashMap<>();
183+
}
184+
int analyzerCount = in.readInt();
185+
for (int i = 0; i < analyzerCount; ++i) {
186+
vstring = in.readUTF();
187+
vlong = in.readLong();
188+
analyzersVersions.put(vstring, vlong);
189+
}
140190
}
141191

142192
private void writeObject(ObjectOutputStream out) throws IOException {
@@ -148,5 +198,16 @@ private void writeObject(ObjectOutputStream out) throws IOException {
148198

149199
out.writeBoolean(analyzerGuruVersion != null); // hasValue
150200
out.writeLong(analyzerGuruVersion == null ? 0 : analyzerGuruVersion);
201+
202+
int analyzerCount = analyzersVersions.size();
203+
out.writeInt(analyzerCount);
204+
for (Map.Entry<String, Long> entry : analyzersVersions.entrySet()) {
205+
out.writeUTF(entry.getKey());
206+
out.writeLong(entry.getValue());
207+
--analyzerCount;
208+
}
209+
if (analyzerCount != 0) {
210+
throw new IllegalStateException("analyzersVersions were modified");
211+
}
151212
}
152213
}

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

Lines changed: 0 additions & 213 deletions
This file was deleted.

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class IndexAnalysisSettingsAccessor {
5050
* {@link QueryBuilder}-normalized value for UUID
5151
* 58859C75-F941-42E5-8D1A-FAF71DDEBBA7
5252
*/
53-
public static final String INDEX_ANALYSIS_SETTINGS_OBJUID =
53+
static final String INDEX_ANALYSIS_SETTINGS_OBJUID =
5454
"uthuslvotkgltggqqjmurqojpjpjjkutkujktnkk";
5555

5656
private static final int INDEX_ANALYSIS_SETTINGS_OBJVER = 2;
@@ -63,8 +63,8 @@ public class IndexAnalysisSettingsAccessor {
6363
* @return a defined instance or {@code null} if none could be found
6464
* @throws IOException if I/O error occurs while searching Lucene
6565
*/
66-
public IndexAnalysisSettings2 read(IndexReader reader) throws IOException {
67-
IndexAnalysisSettings2[] res = read(reader, 1);
66+
public IndexAnalysisSettings read(IndexReader reader) throws IOException {
67+
IndexAnalysisSettings[] res = read(reader, 1);
6868
return res.length > 0 ? res[0] : null;
6969
}
7070

@@ -77,7 +77,7 @@ public IndexAnalysisSettings2 read(IndexReader reader) throws IOException {
7777
* @return a defined instance, which is empty if none could be found
7878
* @throws IOException if I/O error occurs while searching Lucene
7979
*/
80-
public IndexAnalysisSettings2[] read(IndexReader reader, int n)
80+
public IndexAnalysisSettings[] read(IndexReader reader, int n)
8181
throws IOException {
8282
IndexSearcher searcher = new IndexSearcher(reader);
8383
Query q;
@@ -91,17 +91,18 @@ public IndexAnalysisSettings2[] read(IndexReader reader, int n)
9191
TopDocs top = searcher.search(q, n);
9292

9393
int nres = top.totalHits > n ? n : (int)top.totalHits;
94-
IndexAnalysisSettings2[] res = new IndexAnalysisSettings2[nres];
94+
IndexAnalysisSettings[] res = new IndexAnalysisSettings[nres];
9595

96-
IndexAnalysisSettingsUpgrader upgrader =
97-
new IndexAnalysisSettingsUpgrader();
9896
for (int i = 0; i < nres; ++i) {
9997
Document doc = searcher.doc(top.scoreDocs[i].doc);
10098
IndexableField objser = doc.getField(QueryBuilder.OBJSER);
10199
int objver = readObjectVersion(doc);
100+
if (objver != INDEX_ANALYSIS_SETTINGS_OBJVER) {
101+
throw new IllegalArgumentException("Unknown version " + objver);
102+
}
102103
try {
103-
res[i] = objser == null ? null : upgrader.upgrade(
104-
objser.binaryValue().bytes, objver);
104+
res[i] = objser == null ? null : IndexAnalysisSettings.deserialize(
105+
objser.binaryValue().bytes);
105106
} catch (ClassNotFoundException ex) {
106107
// This is not expected, so translate to RuntimeException.
107108
throw new RuntimeException(ex);
@@ -119,7 +120,7 @@ public IndexAnalysisSettings2[] read(IndexReader reader, int n)
119120
* @param settings a defined instance
120121
* @throws IOException if I/O error occurs while writing Lucene
121122
*/
122-
public void write(IndexWriter writer, IndexAnalysisSettings2 settings)
123+
public void write(IndexWriter writer, IndexAnalysisSettings settings)
123124
throws IOException {
124125
byte[] objser = settings.serialize();
125126

0 commit comments

Comments
 (0)