3030import java .nio .file .Path ;
3131import java .nio .file .Paths ;
3232import java .util .ArrayList ;
33- import java .util .Comparator ;
34- import java .util .HashMap ;
3533import java .util .List ;
3634import java .util .Map ;
3735import java .util .Set ;
3836import java .util .SortedSet ;
39- import java .util .TreeMap ;
4037import java .util .TreeSet ;
4138import java .util .logging .Level ;
4239import java .util .logging .Logger ;
6663import org .opengrok .indexer .configuration .Project ;
6764import org .opengrok .indexer .configuration .RuntimeEnvironment ;
6865import org .opengrok .indexer .configuration .SuperIndexSearcher ;
69- import org .opengrok .indexer .index .IndexAnalysisSettings3 ;
70- import org .opengrok .indexer .index .IndexAnalysisSettingsAccessor ;
7166import org .opengrok .indexer .index .IndexDatabase ;
7267import org .opengrok .indexer .index .IndexedSymlink ;
7368import org .opengrok .indexer .logger .LoggerFactory ;
7469import org .opengrok .indexer .search .QueryBuilder ;
70+ import org .opengrok .indexer .search .SettingsHelper ;
7571import org .opengrok .indexer .search .Summarizer ;
7672import org .opengrok .indexer .search .context .Context ;
7773import org .opengrok .indexer .search .context .HistoryContext ;
8379 * complexity from UI design.
8480 *
8581 * @author Jens Elkner
86- * @version $Revision$
8782 */
8883public class SearchHelper {
8984
@@ -219,16 +214,7 @@ public class SearchHelper {
219214 */
220215 public static final String PARSE_ERROR_MSG = "Unable to parse your query: " ;
221216
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 ;
232218
233219 /**
234220 * User readable description for file types. Only those listed in
@@ -271,7 +257,7 @@ public SearchHelper prepareExec(SortedSet<String> projects) {
271257 return this ;
272258 }
273259
274- mappedAnalysisSettings = null ;
260+ settingsHelper = null ;
275261 // the Query created by the QueryBuilder
276262 try {
277263 indexDir = new File (dataRoot , IndexDatabase .INDEX_DIR );
@@ -624,22 +610,15 @@ public int searchSingle(File file) throws IOException,
624610 }
625611
626612 /**
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 .
629615 * @param proj a defined instance or {@code null} if no project is active
630616 * @return tabSize
631617 * @throws IOException if an I/O error occurs querying the active reader
632618 */
633619 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 );
643622 }
644623
645624 /**
@@ -661,12 +640,10 @@ public String getPrimeRelativePath(String project, String relativePath)
661640 }
662641 File absolute = new File (sourceRoot + relativePath );
663642
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 ) {
670647 String canonical = absolute .getCanonicalFile ().getPath ();
671648 for (IndexedSymlink entry : indexedSymlinks .values ()) {
672649 if (canonical .equals (entry .getCanonical ())) {
@@ -686,49 +663,9 @@ public String getPrimeRelativePath(String project, String relativePath)
686663 return relativePath ;
687664 }
688665
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 );
704669 }
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 ;
733670 }
734671}
0 commit comments