forked from oracle/opengrok
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeEnvironment.java
More file actions
1989 lines (1738 loc) · 64.7 KB
/
RuntimeEnvironment.java
File metadata and controls
1989 lines (1738 loc) · 64.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.configuration;
import static org.opengrok.indexer.configuration.Configuration.makeXMLStringAsConfiguration;
import static org.opengrok.indexer.util.ClassUtil.getFieldValue;
import static org.opengrok.indexer.util.ClassUtil.setFieldValue;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.search.SearcherManager;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.NamedThreadFactory;
import org.opengrok.indexer.authorization.AuthorizationFramework;
import org.opengrok.indexer.authorization.AuthorizationStack;
import org.opengrok.indexer.history.HistoryGuru;
import org.opengrok.indexer.history.RepositoryInfo;
import org.opengrok.indexer.index.Filter;
import org.opengrok.indexer.index.IgnoredNames;
import org.opengrok.indexer.index.IndexDatabase;
import org.opengrok.indexer.index.IndexerParallelizer;
import org.opengrok.indexer.logger.LoggerFactory;
import org.opengrok.indexer.util.CtagsUtil;
import org.opengrok.indexer.util.ForbiddenSymlinkException;
import org.opengrok.indexer.util.LazilyInstantiate;
import org.opengrok.indexer.util.PathUtils;
import org.opengrok.indexer.web.Prefix;
import org.opengrok.indexer.web.Statistics;
import org.opengrok.indexer.web.Util;
import org.opengrok.indexer.web.messages.Message;
import org.opengrok.indexer.web.messages.MessagesContainer;
import org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage;
/**
* The RuntimeEnvironment class is used as a placeholder for the current
* configuration this execution context (classloader) is using.
*/
public final class RuntimeEnvironment {
private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeEnvironment.class);
private static final String URL_PREFIX = "/source" + Prefix.SEARCH_R + "?";
private Configuration configuration;
private final ReentrantReadWriteLock configLock;
private final LazilyInstantiate<IndexerParallelizer> lzIndexerParallelizer;
private final LazilyInstantiate<ExecutorService> lzSearchExecutor;
private final LazilyInstantiate<ExecutorService> lzRevisionExecutor;
private static final RuntimeEnvironment instance = new RuntimeEnvironment();
private final Map<Project, List<RepositoryInfo>> repository_map = new ConcurrentHashMap<>();
private final Map<String, SearcherManager> searcherManagerMap = new ConcurrentHashMap<>();
private String configURI;
private Statistics statistics = new Statistics();
public IncludeFiles includeFiles = new IncludeFiles();
private final MessagesContainer messagesContainer = new MessagesContainer();
private static final IndexTimestamp indexTime = new IndexTimestamp();
/**
* Stores a transient value when
* {@link #setCtags(java.lang.String)} is called -- i.e. the
* value is not mediated to {@link Configuration}.
*/
private String ctags;
/**
* Stores a transient value when
* {@link #setMandoc(java.lang.String)} is called -- i.e. the
* value is not mediated to {@link Configuration}.
*/
private String mandoc;
private transient File dtagsEftar = null;
private transient volatile Boolean ctagsFound;
private final transient Set<String> ctagsLanguages = new HashSet<>();
public WatchDogService watchDog;
/**
* Creates a new instance of RuntimeEnvironment. Private to ensure a
* singleton anti-pattern.
*/
private RuntimeEnvironment() {
configuration = new Configuration();
configLock = new ReentrantReadWriteLock();
watchDog = new WatchDogService();
lzIndexerParallelizer = LazilyInstantiate.using(() ->
new IndexerParallelizer(this));
lzSearchExecutor = LazilyInstantiate.using(() -> newSearchExecutor());
lzRevisionExecutor = LazilyInstantiate.using(() -> newRevisionExecutor());
}
// Instance of authorization framework and its lock.
private AuthorizationFramework authFramework;
private final Object authFrameworkLock = new Object();
/** Gets the thread pool used for multi-project searches. */
public ExecutorService getSearchExecutor() {
return lzSearchExecutor.get();
}
private ExecutorService newSearchExecutor() {
return Executors.newFixedThreadPool(
this.getMaxSearchThreadCount(),
new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
thread.setName("search-" + thread.getId());
return thread;
}
});
}
public ExecutorService getRevisionExecutor() {
return lzRevisionExecutor.get();
}
private ExecutorService newRevisionExecutor() {
return Executors.newFixedThreadPool(this.getMaxRevisionThreadCount(),
new NamedThreadFactory("get-revision"));
}
public void shutdownRevisionExecutor() throws InterruptedException {
getRevisionExecutor().shutdownNow();
getRevisionExecutor().awaitTermination(getCommandTimeout(), TimeUnit.SECONDS);
}
/**
* Get the one and only instance of the RuntimeEnvironment.
*
* @return the one and only instance of the RuntimeEnvironment
*/
public static RuntimeEnvironment getInstance() {
return instance;
}
public IndexerParallelizer getIndexerParallelizer() {
return lzIndexerParallelizer.get();
}
private String getCanonicalPath(String s) {
if (s == null) {
return null;
}
try {
File file = new File(s);
if (!file.exists()) {
return s;
}
return file.getCanonicalPath();
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Failed to get canonical path", ex);
return s;
}
}
/**
* Get value of configuration field.
* @param fieldName name of the field
* @return object value
*/
public Object getConfigurationValue(String fieldName) {
try {
configLock.readLock().lock();
return getFieldValue(configuration, fieldName);
} catch (IOException e) {
return null;
} finally {
configLock.readLock().unlock();
}
}
/**
* Get value of configuration field.
* @param fieldName name of the field
* @return object value
* @throws IOException I/O
*/
public Object getConfigurationValueException(String fieldName) throws IOException {
try {
configLock.readLock().lock();
return getFieldValue(configuration, fieldName);
} catch (IOException e) {
throw new IOException("getter", e);
} finally {
configLock.readLock().unlock();
}
}
/**
* Set configuration value.
* @param fieldName name of the field
* @param value string value
*/
public void setConfigurationValue(String fieldName, String value) {
try {
configLock.writeLock().lock();
setFieldValue(configuration, fieldName, value);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "failed to set value of field {}: {}", new Object[]{fieldName, e});
} finally {
configLock.writeLock().unlock();
}
}
/**
* Set configuration value.
* @param fieldName name of the field
* @param value value
*/
public void setConfigurationValue(String fieldName, Object value) {
try {
configLock.writeLock().lock();
setFieldValue(configuration, fieldName, value);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "failed to set value of field {}: {}", new Object[]{fieldName, e});
} finally {
configLock.writeLock().unlock();
}
}
/**
* Set configuration value.
* @param fieldName name of the field
* @param value value
* @throws IOException I/O exception
*/
public void setConfigurationValueException(String fieldName, Object value) throws IOException {
try {
configLock.writeLock().lock();
setFieldValue(configuration, fieldName, value);
} finally {
configLock.writeLock().unlock();
}
}
/**
* Set configuration value.
* @param fieldName name of the field
* @param value string value
* @throws IOException I/O exception
*/
public void setConfigurationValueException(String fieldName, String value) throws IOException {
try {
configLock.writeLock().lock();
setFieldValue(configuration, fieldName, value);
} finally {
configLock.writeLock().unlock();
}
}
public int getScanningDepth() {
return (int) getConfigurationValue("scanningDepth");
}
public void setScanningDepth(int scanningDepth) {
setConfigurationValue("scanningDepth", scanningDepth);
}
public int getCommandTimeout() {
return (int) getConfigurationValue("commandTimeout");
}
public void setCommandTimeout(int timeout) {
setConfigurationValue("commandTimeout", timeout);
}
public int getInteractiveCommandTimeout() {
return (int) getConfigurationValue("interactiveCommandTimeout");
}
public void setInteractiveCommandTimeout(int timeout) {
setConfigurationValue("interactiveCommandTimeout", timeout);
}
public long getCtagsTimeout() {
return (long) getConfigurationValue("ctagsTimeout");
}
public void setCtagsTimeout(long timeout) {
setConfigurationValue("ctagsTimeout", timeout);
}
public Statistics getStatistics() {
return statistics;
}
public void setStatistics(Statistics statistics) {
this.statistics = statistics;
}
public void setLastEditedDisplayMode(boolean lastEditedDisplayMode) {
setConfigurationValue("lastEditedDisplayMode", lastEditedDisplayMode);
}
public boolean isLastEditedDisplayMode() {
return (boolean) getConfigurationValue("lastEditedDisplayMode");
}
/**
* Get the path to the where the web application includes are stored.
*
* @return the path to the web application include files
*/
public String getIncludeRootPath() {
return (String) getConfigurationValue("includeRoot");
}
/**
* Set include root path.
* @param includeRoot path
*/
public void setIncludeRoot(String includeRoot) {
setConfigurationValue("includeRoot", getCanonicalPath(includeRoot));
}
/**
* Get the path to the where the index database is stored.
*
* @return the path to the index database
*/
public String getDataRootPath() {
return (String) getConfigurationValue("dataRoot");
}
/**
* Get a file representing the index database.
*
* @return the index database
*/
public File getDataRootFile() {
File ret = null;
String file = getDataRootPath();
if (file != null) {
ret = new File(file);
}
return ret;
}
/**
* Set the path to where the index database is stored.
*
* @param dataRoot the index database
*/
public void setDataRoot(String dataRoot) {
setConfigurationValue("dataRoot", getCanonicalPath(dataRoot));
}
/**
* Get the path to where the sources are located.
*
* @return path to where the sources are located
*/
public String getSourceRootPath() {
return (String) getConfigurationValue("sourceRoot");
}
/**
* Get a file representing the directory where the sources are located.
*
* @return A file representing the directory where the sources are located
*/
public File getSourceRootFile() {
File ret = null;
String file = getSourceRootPath();
if (file != null) {
ret = new File(file);
}
return ret;
}
/**
* Specify the source root.
*
* @param sourceRoot the location of the sources
*/
public void setSourceRoot(String sourceRoot) {
setConfigurationValue("sourceRoot", getCanonicalPath(sourceRoot));
}
/**
* Returns a path relative to source root. This would just be a simple
* substring operation, except we need to support symlinks outside the
* source root.
*
* @param file A file to resolve
* @return Path relative to source root
* @throws IOException If an IO error occurs
* @throws FileNotFoundException if the file is not relative to source root
* or if {@code sourceRoot} is not defined
* @throws ForbiddenSymlinkException if symbolic-link checking encounters
* an ineligible link
*/
public String getPathRelativeToSourceRoot(File file)
throws IOException, ForbiddenSymlinkException {
String sourceRoot = getSourceRootPath();
if (sourceRoot == null) {
throw new FileNotFoundException("sourceRoot is not defined");
}
String maybeRelPath = PathUtils.getRelativeToCanonical(file.getPath(),
sourceRoot, getAllowedSymlinks(), getCanonicalRoots());
File maybeRelFile = new File(maybeRelPath);
if (!maybeRelFile.isAbsolute()) {
/*
* N.b. OpenGrok has a weird convention that source-root "relative"
* paths must start with a '/' as they are elsewhere directly
* appended to getSourceRootPath() and also stored as such.
*/
maybeRelPath = File.separator + maybeRelPath;
return maybeRelPath;
}
throw new FileNotFoundException("Failed to resolve [" + file.getPath()
+ "] relative to source root [" + sourceRoot + "]");
}
/**
* Do we have any projects ?
*
* @return true if we have projects
*/
public boolean hasProjects() {
return (this.isProjectsEnabled() && getProjects().size() > 0);
}
/**
* Get list of projects.
*
* @return a list containing all of the projects
*/
public List<Project> getProjectList() {
return new ArrayList<>(getProjects().values());
}
/**
* Get project map.
*
* @return a Map with all of the projects
*/
@SuppressWarnings("unchecked")
public Map<String, Project> getProjects() {
return (Map<String, Project>) getConfigurationValue("projects");
}
/**
* Get names of all projects.
*
* @return a list containing names of all projects.
*/
public List<String> getProjectNames() {
return getProjectList().stream().map(Project::getName).collect(Collectors.toList());
}
/**
* Set the list of the projects.
*
* @param projects the map of projects to use
*/
public void setProjects(Map<String, Project> projects) {
try {
configLock.writeLock().lock();
if (projects != null) {
populateGroups(getGroups(), new TreeSet<>(projects.values()));
}
setConfigurationValue("projects", projects);
} finally {
configLock.writeLock().unlock();
}
}
/**
* Do we have groups?
*
* @return true if we have groups
*/
public boolean hasGroups() {
return (getGroups() != null && !getGroups().isEmpty());
}
/**
* Get all of the groups.
*
* @return a set containing all of the groups (may be null)
*/
@SuppressWarnings("unchecked")
public Set<Group> getGroups() {
return (Set<Group>) getConfigurationValue("groups");
}
/**
* Set the list of the groups.
*
* @param groups the set of groups to use
*/
public void setGroups(Set<Group> groups) {
populateGroups(groups, new TreeSet<>(getProjects().values()));
setConfigurationValue("groups", groups);
}
/**
* Returns constructed project - repositories map.
*
* @return the map
* @see #generateProjectRepositoriesMap
*/
public Map<Project, List<RepositoryInfo>> getProjectRepositoriesMap() {
return repository_map;
}
/**
* Gets a static placeholder for the web application context name that is
* translated to the true servlet {@code contextPath} on demand.
* @return {@code "/source"} + {@link Prefix#SEARCH_R} + {@code "?"}
*/
public String getUrlPrefix() {
return URL_PREFIX;
}
/**
* Gets the name of the ctags program to use: either the last value passed
* successfully to {@link #setCtags(java.lang.String)}, or
* {@link Configuration#getCtags()}, or the system property for
* {@code "org.opengrok.indexer.analysis.Ctags"}, or "ctags" as a
* default.
* @return a defined value
*/
public String getCtags() {
String value;
return ctags != null ? ctags :
(value = (String) getConfigurationValue("ctags")) != null ? value :
System.getProperty(CtagsUtil.SYSTEM_CTAGS_PROPERTY, "ctags");
}
/**
* Sets the name of the ctags program to use, or resets to use the fallbacks
* documented for {@link #getCtags()}.
* <p>
* N.b. the value is not mediated to {@link Configuration}.
*
* @param ctags a defined value or {@code null} to reset to use the
* {@link Configuration#getCtags()} fallbacks
* @see #getCtags()
*/
public void setCtags(String ctags) {
this.ctags = ctags;
}
/**
* Gets the name of the mandoc program to use: either the last value passed
* successfully to {@link #setMandoc(java.lang.String)}, or
* {@link Configuration#getMandoc()}, or the system property for
* {@code "org.opengrok.indexer.analysis.Mandoc"}, or {@code null} as a
* default.
* @return a defined instance or {@code null}
*/
public String getMandoc() {
String value;
return mandoc != null ? mandoc : (value =
(String) getConfigurationValue("mandoc")) != null ? value :
System.getProperty("org.opengrok.indexer.analysis.Mandoc");
}
/**
* Sets the name of the mandoc program to use, or resets to use the
* fallbacks documented for {@link #getMandoc()}.
* <p>
* N.b. the value is not mediated to {@link Configuration}.
*
* @param value a defined value or {@code null} to reset to use the
* {@link Configuration#getMandoc()} fallbacks
* @see #getMandoc()
*/
public void setMandoc(String value) {
this.mandoc = value;
}
public int getCachePages() {
return (int) getConfigurationValue("cachePages");
}
public void setCachePages(int cachePages) {
setConfigurationValue("cachePages", cachePages);
}
public int getHitsPerPage() {
return (int) getConfigurationValue("hitsPerPage");
}
public void setHitsPerPage(int hitsPerPage) {
setConfigurationValue("hitsPerPage", hitsPerPage);
}
/**
* Validate that there is a Universal ctags program.
*
* @return true if success, false otherwise
*/
public boolean validateUniversalCtags() {
if (ctagsFound == null) {
String ctagsBinary = getCtags();
configLock.writeLock().lock();
try {
if (ctagsFound == null) {
ctagsFound = CtagsUtil.validate(ctagsBinary);
if (ctagsFound) {
List<String> languages = CtagsUtil.getLanguages(ctagsBinary);
if (languages != null) {
ctagsLanguages.addAll(languages);
}
}
}
} finally {
configLock.writeLock().unlock();
}
}
return ctagsFound;
}
/**
* Gets the base set of supported Ctags languages.
* @return a defined set which may be empty if
* {@link #validateUniversalCtags()} has not yet been called or if the call
* fails
*/
public Set<String> getCtagsLanguages() {
return Collections.unmodifiableSet(ctagsLanguages);
}
/**
* Get the max time a SCM operation may use to avoid being cached.
*
* @return the max time
*/
public int getHistoryReaderTimeLimit() {
return (int) getConfigurationValue("historyCacheTime");
}
/**
* Specify the maximum time a SCM operation should take before it will be
* cached (in ms).
*
* @param historyReaderTimeLimit the max time in ms before it is cached
*/
public void setHistoryReaderTimeLimit(int historyReaderTimeLimit) {
setConfigurationValue("historyCacheTime", historyReaderTimeLimit);
}
/**
* Is history cache currently enabled?
*
* @return true if history cache is enabled
*/
public boolean useHistoryCache() {
return (boolean) getConfigurationValue("historyCache");
}
/**
* Specify if we should use history cache or not.
*
* @param useHistoryCache set false if you do not want to use history cache
*/
public void setUseHistoryCache(boolean useHistoryCache) {
setConfigurationValue("historyCache", useHistoryCache);
}
/**
* Should we generate HTML or not during the indexing phase.
*
* @return true if HTML should be generated during the indexing phase
*/
public boolean isGenerateHtml() {
return (boolean) getConfigurationValue("generateHtml");
}
/**
* Specify if we should generate HTML or not during the indexing phase.
*
* @param generateHtml set this to true to pregenerate HTML
*/
public void setGenerateHtml(boolean generateHtml) {
setConfigurationValue("generateHtml", generateHtml);
}
/**
* Set if we should compress the xref files or not.
*
* @param compressXref set to true if the generated html files should be
* compressed
*/
public void setCompressXref(boolean compressXref) {
setConfigurationValue("compressXref", compressXref);
}
/**
* Are we using compressed HTML files?
*
* @return {@code true} if the html-files should be compressed.
*/
public boolean isCompressXref() {
return (boolean) getConfigurationValue("compressXref");
}
public boolean isQuickContextScan() {
return (boolean) getConfigurationValue("quickContextScan");
}
public void setQuickContextScan(boolean quickContextScan) {
setConfigurationValue("quickContextScan", quickContextScan);
}
@SuppressWarnings("unchecked")
public List<RepositoryInfo> getRepositories() {
return (List<RepositoryInfo>) getConfigurationValue("repositories");
}
/**
* Set the list of repositories.
*
* @param repositories the repositories to use
*/
public void setRepositories(List<RepositoryInfo> repositories) {
setConfigurationValue("repositories", repositories);
}
public void removeRepositories() {
try {
configLock.writeLock().lock();
configuration.setRepositories(null);
} finally {
configLock.writeLock().unlock();
}
}
/**
* Search through the directory for repositories and use the result to replace
* the lists of repositories in both RuntimeEnvironment/Configuration and HistoryGuru.
*
* @param dir the root directory to start the search in
*/
public void setRepositories(String dir) {
List<RepositoryInfo> repos = new ArrayList<>(HistoryGuru.getInstance().
addRepositories(new File[]{new File(dir)},
RuntimeEnvironment.getInstance().getIgnoredNames()));
RuntimeEnvironment.getInstance().setRepositories(repos);
}
/**
* Add repositories to the list.
* @param repositories list of repositories
*/
public void addRepositories(List<RepositoryInfo> repositories) {
Lock writeLock = configLock.writeLock();
try {
writeLock.lock();
configuration.addRepositories(repositories);
} finally {
writeLock.unlock();
}
}
/**
* Set the specified projects as default in the configuration.
* This method should be called only after projects were discovered and became part of the configuration,
* i.e. after {@link org.opengrok.indexer.index.Indexer#prepareIndexer} was called.
*
* @param defaultProjects The default project to use
* @see #setDefaultProjects
*/
public void setDefaultProjectsFromNames(Set<String> defaultProjects) {
if (defaultProjects != null && !defaultProjects.isEmpty()) {
Set<Project> projects = new TreeSet<>();
for (String projectPath : defaultProjects) {
if (projectPath.equals("__all__")) {
projects.addAll(getProjects().values());
break;
}
for (Project p : getProjectList()) {
if (p.getPath().equals(Util.fixPathIfWindows(projectPath))) {
projects.add(p);
break;
}
}
}
if (!projects.isEmpty()) {
setDefaultProjects(projects);
}
}
}
/**
* Set the projects that are specified to be the default projects to use.
* The default projects are the projects you will search (from the web
* application) if the page request didn't contain the cookie..
*
* @param defaultProjects The default project to use
*/
public void setDefaultProjects(Set<Project> defaultProjects) {
setConfigurationValue("defaultProjects", defaultProjects);
}
/**
* Get the projects that are specified to be the default projects to use.
* The default projects are the projects you will search (from the web
* application) if the page request didn't contain the cookie..
*
* @return the default projects (may be null if not specified)
*/
@SuppressWarnings("unchecked")
public Set<Project> getDefaultProjects() {
Set<Project> projects = (Set<Project>) getConfigurationValue("defaultProjects");
if (projects == null) {
return null;
}
return Collections.unmodifiableSet(projects);
}
/**
*
* @return at what size (in MB) we should flush the buffer
*/
public double getRamBufferSize() {
return (double) getConfigurationValue("ramBufferSize");
}
/**
* Set the size of buffer which will determine when the docs are flushed to
* disk. Specify size in MB please. 16MB is default note that this is per
* thread (lucene uses 8 threads by default in 4.x)
*
* @param ramBufferSize the size(in MB) when we should flush the docs
*/
public void setRamBufferSize(double ramBufferSize) {
setConfigurationValue("ramBufferSize", ramBufferSize);
}
public void setPluginDirectory(String pluginDirectory) {
setConfigurationValue("pluginDirectory", pluginDirectory);
}
public String getPluginDirectory() {
return (String) getConfigurationValue("pluginDirectory");
}
public boolean isAuthorizationWatchdog() {
return (boolean) getConfigurationValue("authorizationWatchdogEnabled");
}
public void setAuthorizationWatchdog(boolean authorizationWatchdogEnabled) {
setConfigurationValue("authorizationWatchdogEnabled", authorizationWatchdogEnabled);
}
public AuthorizationStack getPluginStack() {
return (AuthorizationStack) getConfigurationValue("pluginStack");
}
public void setPluginStack(AuthorizationStack pluginStack) {
setConfigurationValue("pluginStack", pluginStack);
}
/**
* Is the progress print flag turned on?
*
* @return true if we can print per project progress %
*/
public boolean isPrintProgress() {
return (boolean) getConfigurationValue("printProgress");
}
/**
* Set the printing of progress % flag (user convenience).
*
* @param printProgress new value
*/
public void setPrintProgress(boolean printProgress) {
setConfigurationValue("printProgress", printProgress);
}
/**
* Specify if a search may start with a wildcard. Note that queries that
* start with a wildcard will give a significant impact on the search
* performance.
*
* @param allowLeadingWildcard set to true to activate (disabled by default)
*/
public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
setConfigurationValue("allowLeadingWildcard", allowLeadingWildcard);
}
/**
* Is leading wildcards allowed?
*
* @return true if a search may start with a wildcard
*/
public boolean isAllowLeadingWildcard() {
return (boolean) getConfigurationValue("allowLeadingWildcard");
}
public IgnoredNames getIgnoredNames() {
return (IgnoredNames) getConfigurationValue("ignoredNames");
}
public void setIgnoredNames(IgnoredNames ignoredNames) {
setConfigurationValue("ignoredNames", ignoredNames);
}
public Filter getIncludedNames() {
return (Filter) getConfigurationValue("includedNames");
}
public void setIncludedNames(Filter includedNames) {
setConfigurationValue("includedNames", includedNames);
}
/**
* Returns the user page for the history listing.
*
* @return the URL string fragment preceeding the username
*/
public String getUserPage() {
return (String) getConfigurationValue("userPage");
}
/**
* Get the client command to use to access the repository for the given
* fully qualified classname.
*
* @param clazzName name of the targeting class
* @return {@code null} if not yet set, the client command otherwise.
*/
public String getRepoCmd(String clazzName) {
Lock readLock = configLock.readLock();
String cmd = null;
try {
readLock.lock();
cmd = configuration.getRepoCmd(clazzName);
} finally {
readLock.unlock();
}
return cmd;
}
/**
* Set the client command to use to access the repository for the given
* fully qualified classname.