Skip to content

Commit 369f83f

Browse files
author
Vladimir Kotal
committed
get rid of default project argument of prepareIndexer()
1 parent 7516a8e commit 369f83f

File tree

16 files changed

+65
-61
lines changed

16 files changed

+65
-61
lines changed

dev/checkstyle/suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<suppress checks="ParameterNumber" files="CtagsReader\.java|Definitions\.java|PerlLexHelper\.java|
1515
|JFlexXrefUtils\.java|RubyLexHelper\.java|FileAnalyzerFactory\.java|SearchController\.java|
16-
|Context\.java|HistoryContext\.java|Indexer\.java|Suggester\.java" />
16+
|Context\.java|HistoryContext\.java|Suggester\.java" />
1717

1818
<suppress checks="MethodLength" files="Indexer\.java" />
1919
</suppressions>

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.opengrok.indexer.util.PathUtils;
7272
import org.opengrok.indexer.web.Prefix;
7373
import org.opengrok.indexer.web.Statistics;
74+
import org.opengrok.indexer.web.Util;
7475
import org.opengrok.indexer.web.messages.Message;
7576
import org.opengrok.indexer.web.messages.MessagesContainer;
7677
import org.opengrok.indexer.web.messages.MessagesContainer.AcceptedMessage;
@@ -777,6 +778,35 @@ public void addRepositories(List<RepositoryInfo> repositories) {
777778
}
778779
}
779780

781+
/**
782+
* Set the specified projects as default in the configuration.
783+
* This method should be called only after projects were discovered and became part of the configuration,
784+
* i.e. after {@link org.opengrok.indexer.index.Indexer#prepareIndexer} was called.
785+
*
786+
* @param defaultProjects The default project to use
787+
* @see #setDefaultProjects
788+
*/
789+
public void setDefaultProjectsFromNames(Set<String> defaultProjects) {
790+
if (defaultProjects != null && !defaultProjects.isEmpty()) {
791+
Set<Project> projects = new TreeSet<>();
792+
for (String projectPath : defaultProjects) {
793+
if (projectPath.equals("__all__")) {
794+
projects.addAll(getProjects().values());
795+
break;
796+
}
797+
for (Project p : getProjectList()) {
798+
if (p.getPath().equals(Util.fixPathIfWindows(projectPath))) {
799+
projects.add(p);
800+
break;
801+
}
802+
}
803+
}
804+
if (!projects.isEmpty()) {
805+
setDefaultProjects(projects);
806+
}
807+
}
808+
}
809+
780810
/**
781811
* Set the projects that are specified to be the default projects to use.
782812
* The default projects are the projects you will search (from the web

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

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import org.opengrok.indexer.util.Executor;
6666
import org.opengrok.indexer.util.OptionParser;
6767
import org.opengrok.indexer.util.Statistics;
68-
import org.opengrok.indexer.web.Util;
6968

7069
/**
7170
* Creates and updates an inverted source index as well as generates Xref, file
@@ -313,9 +312,11 @@ public static void main(String[] argv) {
313312

314313
// Create history cache first.
315314
getInstance().prepareIndexer(env, searchRepositories, addProjects,
316-
defaultProjects,
317315
createDict, runIndex, subFiles, new ArrayList<>(repositories));
318316

317+
// prepareIndexer() populated the list of projects so now default projects can be set.
318+
env.setDefaultProjectsFromNames(defaultProjects);
319+
319320
// And now index it all.
320321
if (runIndex || (optimizedChanged && env.isOptimizeDatabase())) {
321322
IndexChangedListener progress = new DefaultIndexChangedListener();
@@ -875,12 +876,11 @@ public static void writeConfigToFile(RuntimeEnvironment env, String filename) th
875876
public void prepareIndexer(RuntimeEnvironment env,
876877
boolean searchRepositories,
877878
boolean addProjects,
878-
Set<String> defaultProjects,
879879
boolean createDict,
880880
List<String> subFiles,
881881
List<String> repositories) throws IndexerException, IOException {
882882

883-
prepareIndexer(env, searchRepositories, addProjects, defaultProjects, createDict, true,
883+
prepareIndexer(env, searchRepositories, addProjects, createDict, true,
884884
subFiles, repositories);
885885
}
886886

@@ -897,7 +897,6 @@ public void prepareIndexer(RuntimeEnvironment env,
897897
* @param env runtime environment
898898
* @param searchRepositories if true, search for repositories
899899
* @param addProjects if true, add projects
900-
* @param defaultProjects default projects
901900
* @param createDict if true, create dictionary
902901
* @param createHistoryCache create history cache flag
903902
* @param subFiles list of directories
@@ -909,7 +908,6 @@ public void prepareIndexer(RuntimeEnvironment env,
909908
public void prepareIndexer(RuntimeEnvironment env,
910909
boolean searchRepositories,
911910
boolean addProjects,
912-
Set<String> defaultProjects,
913911
boolean createDict,
914912
boolean createHistoryCache,
915913
List<String> subFiles,
@@ -971,25 +969,6 @@ public void prepareIndexer(RuntimeEnvironment env,
971969
env.getRepositories().size()));
972970
}
973971

974-
if (defaultProjects != null && !defaultProjects.isEmpty()) {
975-
Set<Project> projects = new TreeSet<>();
976-
for (String projectPath : defaultProjects) {
977-
if (projectPath.equals("__all__")) {
978-
projects.addAll(env.getProjects().values());
979-
break;
980-
}
981-
for (Project p : env.getProjectList()) {
982-
if (p.getPath().equals(Util.fixPathIfWindows(projectPath))) {
983-
projects.add(p);
984-
break;
985-
}
986-
}
987-
}
988-
if (!projects.isEmpty()) {
989-
env.setDefaultProjects(projects);
990-
}
991-
}
992-
993972
if (createHistoryCache) {
994973
// Even if history is disabled globally, it can be enabled for some repositories.
995974
if (repositories != null && !repositories.isEmpty()) {

opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/executables/JarAnalyzerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public static void setUpClass() throws Exception {
8484
env.setHistoryEnabled(false);
8585
IndexChangedListener progress = new DefaultIndexChangedListener();
8686
Indexer.getInstance().prepareIndexer(env, true, true,
87-
new TreeSet<>(Collections.singletonList("/c")),
8887
false, null, null);
88+
env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
8989

9090
Indexer.getInstance().doIndexerExecution(true, null, progress);
9191

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexDatabaseTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ public static void setUpClass() throws Exception {
8787
// the tests are run.
8888
Indexer indexer = Indexer.getInstance();
8989
indexer.prepareIndexer(
90-
env, true, true, new TreeSet<>(Arrays.asList(new String[]{"/c"})),
90+
env, true, true,
9191
false, null, null);
92+
env.setDefaultProjectsFromNames(new TreeSet<>(Arrays.asList(new String[]{"/c"})));
9293
indexer.doIndexerExecution(true, null, null);
9394
}
9495

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexVersionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void tearDown() throws IOException {
9090
private void testIndexVersion(boolean projectsEnabled, List<String> subFiles) throws Exception {
9191
env.setHistoryEnabled(false);
9292
env.setProjectsEnabled(projectsEnabled);
93-
Indexer.getInstance().prepareIndexer(env, true, true, null,
93+
Indexer.getInstance().prepareIndexer(env, true, true,
9494
false, null, null);
9595
Indexer.getInstance().doIndexerExecution(true, null, null);
9696

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexerRepoTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ private void testPerProjectHistory(boolean globalOn) throws IndexerException, IO
138138
env,
139139
true, // search for repositories
140140
true, // scan and add projects
141-
null, // no default project
142141
false, // don't create dictionary
143142
null, // subFiles - not needed since we don't list files
144143
null); // repositories - not needed when not refreshing history
@@ -201,7 +200,6 @@ public void testSymlinks() throws IndexerException, IOException {
201200
env,
202201
true, // search for repositories
203202
true, // scan and add projects
204-
null, // no default project
205203
false, // don't create dictionary
206204
null, // subFiles - not needed since we don't list files
207205
null); // repositories - not needed when not refreshing history

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexerTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ public void testIndexGeneration() throws Exception {
120120
env.setSourceRoot(repository.getSourceRoot());
121121
env.setDataRoot(repository.getDataRoot());
122122
env.setHistoryEnabled(false);
123-
Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Collections.singletonList("/c")),
123+
Indexer.getInstance().prepareIndexer(env, true, true,
124124
false, null, null);
125+
env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
125126
Indexer.getInstance().doIndexerExecution(true, null, null);
126127
}
127128

@@ -154,7 +155,6 @@ public void testRescanProjects() throws Exception {
154155
env,
155156
false, // don't search for repositories
156157
true, // scan and add projects
157-
null, // no default project
158158
false, // don't create dictionary
159159
null, // subFiles - not needed since we don't list files
160160
null); // repositories - not needed when not refreshing history
@@ -481,10 +481,9 @@ public void testDefaultProjectsSingleProject() throws Exception {
481481
env.setSourceRoot(repository.getSourceRoot());
482482
env.setDataRoot(repository.getDataRoot());
483483
env.setHistoryEnabled(false);
484-
Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Arrays.asList(new String[]{
485-
Paths.get("/c").toString()
486-
})),
484+
Indexer.getInstance().prepareIndexer(env, true, true,
487485
false, null, null);
486+
env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
488487
assertEquals(1, env.getDefaultProjects().size());
489488
assertEquals(new TreeSet<>(Arrays.asList(new String[]{"c"})),
490489
env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));
@@ -501,16 +500,16 @@ public void testDefaultProjectsNonExistent() throws Exception {
501500
env.setSourceRoot(repository.getSourceRoot());
502501
env.setDataRoot(repository.getDataRoot());
503502
env.setHistoryEnabled(false);
504-
System.out.println(Paths.get("/lisp").toString());
503+
Set<String> projectSet = new TreeSet<>();
504+
projectSet.add("/lisp");
505+
projectSet.add("/pascal");
506+
projectSet.add("/perl");
507+
projectSet.add("/data");
508+
projectSet.add("/no-project-x32ds1");
509+
505510
Indexer.getInstance().prepareIndexer(env, true, true,
506-
new TreeSet<>(Arrays.asList(new String[]{
507-
Paths.get("/lisp").toString(),
508-
Paths.get("/pascal").toString(),
509-
Paths.get("/perl").toString(),
510-
Paths.get("/data").toString(),
511-
Paths.get("/no-project-x32ds1").toString()
512-
})),
513511
false, null, null);
512+
env.setDefaultProjectsFromNames(projectSet);
514513
assertEquals(4, env.getDefaultProjects().size());
515514
assertEquals(new TreeSet<>(Arrays.asList(new String[]{"lisp", "pascal", "perl", "data"})),
516515
env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));
@@ -527,14 +526,15 @@ public void testDefaultProjectsAll() throws Exception {
527526
env.setSourceRoot(repository.getSourceRoot());
528527
env.setDataRoot(repository.getDataRoot());
529528
env.setHistoryEnabled(false);
529+
Set<String> defaultProjects = new TreeSet<>();
530+
defaultProjects.add("/c");
531+
defaultProjects.add("/data");
532+
defaultProjects.add("__all__");
533+
defaultProjects.add("/no-project-x32ds1");
534+
530535
Indexer.getInstance().prepareIndexer(env, true, true,
531-
new TreeSet<>(Arrays.asList(new String[]{
532-
Paths.get("/c").toString(),
533-
Paths.get("/data").toString(),
534-
Paths.get("__all__").toString(),
535-
Paths.get("/no-project-x32ds1").toString()
536-
})),
537536
false, null, null);
537+
env.setDefaultProjectsFromNames(defaultProjects);
538538
Set<String> projects = new TreeSet<>(Arrays.asList(new File(repository.getSourceRoot()).list()));
539539
assertEquals(projects.size(), env.getDefaultProjects().size());
540540
assertEquals(projects, env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));

opengrok-indexer/src/test/java/org/opengrok/indexer/search/SearchEngineTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public static void setUpClass() throws Exception {
7373
env.setSourceRoot(repository.getSourceRoot());
7474
env.setDataRoot(repository.getDataRoot());
7575
env.setHistoryEnabled(false);
76+
7677
Indexer.getInstance().prepareIndexer(env, true, true,
77-
new TreeSet<>(Collections.singletonList("/c")),
7878
false, null, null);
79+
env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
7980
Indexer.getInstance().doIndexerExecution(true, null, null);
8081

81-
8282
configFile = File.createTempFile("configuration", ".xml");
8383
env.writeConfiguration(configFile);
8484
RuntimeEnvironment.getInstance().readConfiguration(new File(configFile.getAbsolutePath()));

opengrok-indexer/src/test/java/org/opengrok/indexer/search/context/SearchAndContextFormatterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public static void setUpClass() throws Exception {
8888
env.setDataRoot(repository.getDataRoot());
8989
env.setHistoryEnabled(false);
9090
Indexer.getInstance().prepareIndexer(env, true, true,
91-
new TreeSet<>(Collections.singletonList("/c")),
9291
false, null, null);
92+
env.setDefaultProjectsFromNames(new TreeSet<String>(Collections.singletonList("/c")));
9393
Indexer.getInstance().doIndexerExecution(true, null, null);
9494

9595
configFile = File.createTempFile("configuration", ".xml");

0 commit comments

Comments
 (0)