30
30
import java .nio .file .Path ;
31
31
import java .nio .file .Paths ;
32
32
import java .util .ArrayList ;
33
- import java .util .Comparator ;
34
- import java .util .HashMap ;
35
33
import java .util .List ;
36
34
import java .util .Map ;
37
35
import java .util .Set ;
38
36
import java .util .SortedSet ;
39
- import java .util .TreeMap ;
40
37
import java .util .TreeSet ;
41
38
import java .util .logging .Level ;
42
39
import java .util .logging .Logger ;
66
63
import org .opengrok .indexer .configuration .Project ;
67
64
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
68
65
import org .opengrok .indexer .configuration .SuperIndexSearcher ;
69
- import org .opengrok .indexer .index .IndexAnalysisSettings3 ;
70
- import org .opengrok .indexer .index .IndexAnalysisSettingsAccessor ;
71
66
import org .opengrok .indexer .index .IndexDatabase ;
72
67
import org .opengrok .indexer .index .IndexedSymlink ;
73
68
import org .opengrok .indexer .logger .LoggerFactory ;
74
69
import org .opengrok .indexer .search .QueryBuilder ;
70
+ import org .opengrok .indexer .search .SettingsHelper ;
75
71
import org .opengrok .indexer .search .Summarizer ;
76
72
import org .opengrok .indexer .search .context .Context ;
77
73
import org .opengrok .indexer .search .context .HistoryContext ;
83
79
* complexity from UI design.
84
80
*
85
81
* @author Jens Elkner
86
- * @version $Revision$
87
82
*/
88
83
public class SearchHelper {
89
84
@@ -219,16 +214,7 @@ public class SearchHelper {
219
214
*/
220
215
public static final String PARSE_ERROR_MSG = "Unable to parse your query: " ;
221
216
222
- /**
223
- * Key is Project name or empty string for null Project.
224
- */
225
- private Map <String , IndexAnalysisSettings3 > mappedAnalysisSettings ;
226
-
227
- /**
228
- * Key is Project name or empty string for null Project. Map is ordered by
229
- * canonical length (ASC) and then canonical value (ASC).
230
- */
231
- private Map <String , Map <String , IndexedSymlink >> mappedIndexedSymlinks ;
217
+ private SettingsHelper settingsHelper ;
232
218
233
219
/**
234
220
* User readable description for file types. Only those listed in
@@ -271,7 +257,7 @@ public SearchHelper prepareExec(SortedSet<String> projects) {
271
257
return this ;
272
258
}
273
259
274
- mappedAnalysisSettings = null ;
260
+ settingsHelper = null ;
275
261
// the Query created by the QueryBuilder
276
262
try {
277
263
indexDir = new File (dataRoot , IndexDatabase .INDEX_DIR );
@@ -624,22 +610,15 @@ public int searchSingle(File file) throws IOException,
624
610
}
625
611
626
612
/**
627
- * Gets the persisted tabSize via {@link #getSettings(java.lang.String)} if
628
- * available or returns the {@code proj} tabSize if available -- or zero .
613
+ * Gets the persisted tabSize via {@link SettingsHelper} for the active
614
+ * reader .
629
615
* @param proj a defined instance or {@code null} if no project is active
630
616
* @return tabSize
631
617
* @throws IOException if an I/O error occurs querying the active reader
632
618
*/
633
619
public int getTabSize (Project proj ) throws IOException {
634
- String projectName = proj != null ? proj .getName () : null ;
635
- IndexAnalysisSettings3 settings = getSettings (projectName );
636
- int tabSize ;
637
- if (settings != null && settings .getTabSize () != null ) {
638
- tabSize = settings .getTabSize ();
639
- } else {
640
- tabSize = proj != null ? proj .getTabSize () : 0 ;
641
- }
642
- return tabSize ;
620
+ ensureSettingsHelper ();
621
+ return settingsHelper .getTabSize (proj );
643
622
}
644
623
645
624
/**
@@ -661,12 +640,10 @@ public String getPrimeRelativePath(String project, String relativePath)
661
640
}
662
641
File absolute = new File (sourceRoot + relativePath );
663
642
664
- getSettings (project );
665
-
666
- Map <String , IndexedSymlink > indexedSymlinks ;
667
- if (mappedIndexedSymlinks != null && (indexedSymlinks =
668
- mappedIndexedSymlinks .get (project )) != null ) {
669
-
643
+ ensureSettingsHelper ();
644
+ settingsHelper .getSettings (project );
645
+ Map <String , IndexedSymlink > indexedSymlinks = settingsHelper .getSymlinks (project );
646
+ if (indexedSymlinks != null ) {
670
647
String canonical = absolute .getCanonicalFile ().getPath ();
671
648
for (IndexedSymlink entry : indexedSymlinks .values ()) {
672
649
if (canonical .equals (entry .getCanonical ())) {
@@ -686,49 +663,9 @@ public String getPrimeRelativePath(String project, String relativePath)
686
663
return relativePath ;
687
664
}
688
665
689
- /**
690
- * Gets the settings for a specified project, querying the active reader
691
- * upon the first call after {@link #prepareExec(java.util.SortedSet)}.
692
- * @param projectName a defined instance or {@code null} if no project is
693
- * active (or empty string to mean the same thing)
694
- * @return a defined instance or {@code null} if none is found
695
- * @throws IOException if an I/O error occurs querying the active reader
696
- */
697
- private IndexAnalysisSettings3 getSettings (String projectName )
698
- throws IOException {
699
- if (mappedAnalysisSettings == null ) {
700
- IndexAnalysisSettingsAccessor dao =
701
- new IndexAnalysisSettingsAccessor ();
702
- IndexAnalysisSettings3 [] setts = dao .read (reader , Short .MAX_VALUE );
703
- map (setts );
666
+ private void ensureSettingsHelper () {
667
+ if (settingsHelper == null ) {
668
+ settingsHelper = new SettingsHelper (reader );
704
669
}
705
-
706
- String k = projectName != null ? projectName : "" ;
707
- return mappedAnalysisSettings .get (k );
708
- }
709
-
710
- private void map (IndexAnalysisSettings3 [] setts ) {
711
-
712
- Map <String , IndexAnalysisSettings3 > settingsMap = new HashMap <>();
713
- Map <String , Map <String , IndexedSymlink >> symlinksMap = new HashMap <>();
714
-
715
- for (IndexAnalysisSettings3 settings : setts ) {
716
- String k = settings .getProjectName () != null ?
717
- settings .getProjectName () : "" ;
718
- settingsMap .put (k , settings );
719
- symlinksMap .put (k , mapSymlinks (settings ));
720
- }
721
- mappedAnalysisSettings = settingsMap ;
722
- mappedIndexedSymlinks = symlinksMap ;
723
- }
724
-
725
- private Map <String , IndexedSymlink > mapSymlinks (IndexAnalysisSettings3 settings ) {
726
-
727
- Map <String , IndexedSymlink > res = new TreeMap <>(
728
- Comparator .comparingInt (String ::length ).thenComparing (o -> o ));
729
- for (IndexedSymlink entry : settings .getIndexedSymlinks ().values ()) {
730
- res .put (entry .getCanonical (), entry );
731
- }
732
- return res ;
733
670
}
734
671
}
0 commit comments