Skip to content

Commit 7516a8e

Browse files
author
Vladimir Kotal
committed
replace list files in Indexer with RESTful API endpoint
1 parent 18d0c95 commit 7516a8e

File tree

17 files changed

+71
-36
lines changed

17 files changed

+71
-36
lines changed

apiary.apib

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ This entry point is used by the Indexer once it finishes indexing given project.
172172

173173
+ Response 204
174174

175+
## Project index files [/projects/{project}/files]
176+
177+
### Get a list of files tracked by the index database for given project [GET]
178+
179+
+ Response 200 (application/json)
180+
+ Body
181+
182+
["/project/foo.txt","/project/bar.txt"]
183+
175184
## Project metadata [/projects/{project}/property/{field}]
176185

177186
### sets property field for the project [PUT]

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,10 +1312,9 @@ public static Set<String> getAllFiles() throws IOException {
13121312
}
13131313

13141314
/**
1315-
* List all files in some of the index databases.
1315+
* Get all files in some of the index databases.
13161316
*
1317-
* @param subFiles Subdirectories for the various projects to list the files
1318-
* for (or null or an empty list to dump all projects)
1317+
* @param subFiles Subdirectories of various projects or null or an empty list to get everything
13191318
* @throws IOException if an error occurs
13201319
* @return set of files in the index databases specified by the subFiles parameter
13211320
*/
@@ -1369,7 +1368,13 @@ public Set<String> getFiles() throws IOException {
13691368
iter = terms.iterator(); // init uid iterator
13701369
}
13711370
while (iter != null && iter.term() != null) {
1372-
files.add(Util.uid2url(iter.term().utf8ToString()));
1371+
String value = iter.term().utf8ToString();
1372+
if (value.isEmpty()) {
1373+
iter.next();
1374+
continue;
1375+
}
1376+
1377+
files.add(Util.uid2url(value));
13731378
BytesRef next = iter.next();
13741379
if (next == null) {
13751380
iter = null;

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ public static void main(String[] argv) {
136136
ArrayList<String> subFiles = new ArrayList<>();
137137
ArrayList<String> subFilesList = new ArrayList<>();
138138

139-
boolean listFiles = false;
140139
boolean createDict = false;
141140

142141
try {
@@ -315,7 +314,7 @@ public static void main(String[] argv) {
315314
// Create history cache first.
316315
getInstance().prepareIndexer(env, searchRepositories, addProjects,
317316
defaultProjects,
318-
listFiles, createDict, runIndex, subFiles, new ArrayList<>(repositories));
317+
createDict, runIndex, subFiles, new ArrayList<>(repositories));
319318

320319
// And now index it all.
321320
if (runIndex || (optimizedChanged && env.isOptimizeDatabase())) {
@@ -877,11 +876,11 @@ public void prepareIndexer(RuntimeEnvironment env,
877876
boolean searchRepositories,
878877
boolean addProjects,
879878
Set<String> defaultProjects,
880-
boolean listFiles,
881879
boolean createDict,
882880
List<String> subFiles,
883881
List<String> repositories) throws IndexerException, IOException {
884-
prepareIndexer(env, searchRepositories, addProjects, defaultProjects, listFiles, createDict, true,
882+
883+
prepareIndexer(env, searchRepositories, addProjects, defaultProjects, createDict, true,
885884
subFiles, repositories);
886885
}
887886

@@ -899,7 +898,6 @@ public void prepareIndexer(RuntimeEnvironment env,
899898
* @param searchRepositories if true, search for repositories
900899
* @param addProjects if true, add projects
901900
* @param defaultProjects default projects
902-
* @param listFiles list files and return
903901
* @param createDict if true, create dictionary
904902
* @param createHistoryCache create history cache flag
905903
* @param subFiles list of directories
@@ -912,7 +910,6 @@ public void prepareIndexer(RuntimeEnvironment env,
912910
boolean searchRepositories,
913911
boolean addProjects,
914912
Set<String> defaultProjects,
915-
boolean listFiles,
916913
boolean createDict,
917914
boolean createHistoryCache,
918915
List<String> subFiles,
@@ -974,14 +971,6 @@ public void prepareIndexer(RuntimeEnvironment env,
974971
env.getRepositories().size()));
975972
}
976973

977-
if (listFiles) {
978-
for (String file : IndexDatabase.getAllFiles(subFiles)) {
979-
LOGGER.fine(file);
980-
}
981-
982-
return;
983-
}
984-
985974
if (defaultProjects != null && !defaultProjects.isEmpty()) {
986975
Set<Project> projects = new TreeSet<>();
987976
for (String projectPath : defaultProjects) {

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
@@ -85,7 +85,7 @@ public static void setUpClass() throws Exception {
8585
IndexChangedListener progress = new DefaultIndexChangedListener();
8686
Indexer.getInstance().prepareIndexer(env, true, true,
8787
new TreeSet<>(Collections.singletonList("/c")),
88-
false, false, null, null);
88+
false, null, null);
8989

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static void setUpClass() throws Exception {
8888
Indexer indexer = Indexer.getInstance();
8989
indexer.prepareIndexer(
9090
env, true, true, new TreeSet<>(Arrays.asList(new String[]{"/c"})),
91-
false, false, null, null);
91+
false, null, null);
9292
indexer.doIndexerExecution(true, null, null);
9393
}
9494

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
@@ -91,7 +91,7 @@ private void testIndexVersion(boolean projectsEnabled, List<String> subFiles) th
9191
env.setHistoryEnabled(false);
9292
env.setProjectsEnabled(projectsEnabled);
9393
Indexer.getInstance().prepareIndexer(env, true, true, null,
94-
false, false, null, null);
94+
false, null, null);
9595
Indexer.getInstance().doIndexerExecution(true, null, null);
9696

9797
IndexVersion.check(subFiles);

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
@@ -139,7 +139,6 @@ private void testPerProjectHistory(boolean globalOn) throws IndexerException, IO
139139
true, // search for repositories
140140
true, // scan and add projects
141141
null, // no default project
142-
false, // don't list files
143142
false, // don't create dictionary
144143
null, // subFiles - not needed since we don't list files
145144
null); // repositories - not needed when not refreshing history
@@ -203,7 +202,6 @@ public void testSymlinks() throws IndexerException, IOException {
203202
true, // search for repositories
204203
true, // scan and add projects
205204
null, // no default project
206-
false, // don't list files
207205
false, // don't create dictionary
208206
null, // subFiles - not needed since we don't list files
209207
null); // repositories - not needed when not refreshing history

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void testIndexGeneration() throws Exception {
121121
env.setDataRoot(repository.getDataRoot());
122122
env.setHistoryEnabled(false);
123123
Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Collections.singletonList("/c")),
124-
false, false, null, null);
124+
false, null, null);
125125
Indexer.getInstance().doIndexerExecution(true, null, null);
126126
}
127127

@@ -155,7 +155,6 @@ public void testRescanProjects() throws Exception {
155155
false, // don't search for repositories
156156
true, // scan and add projects
157157
null, // no default project
158-
false, // don't list files
159158
false, // don't create dictionary
160159
null, // subFiles - not needed since we don't list files
161160
null); // repositories - not needed when not refreshing history
@@ -485,7 +484,7 @@ public void testDefaultProjectsSingleProject() throws Exception {
485484
Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Arrays.asList(new String[]{
486485
Paths.get("/c").toString()
487486
})),
488-
false, false, null, null);
487+
false, null, null);
489488
assertEquals(1, env.getDefaultProjects().size());
490489
assertEquals(new TreeSet<>(Arrays.asList(new String[]{"c"})),
491490
env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));
@@ -511,7 +510,7 @@ public void testDefaultProjectsNonExistent() throws Exception {
511510
Paths.get("/data").toString(),
512511
Paths.get("/no-project-x32ds1").toString()
513512
})),
514-
false, false, null, null);
513+
false, null, null);
515514
assertEquals(4, env.getDefaultProjects().size());
516515
assertEquals(new TreeSet<>(Arrays.asList(new String[]{"lisp", "pascal", "perl", "data"})),
517516
env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));
@@ -535,7 +534,7 @@ public void testDefaultProjectsAll() throws Exception {
535534
Paths.get("__all__").toString(),
536535
Paths.get("/no-project-x32ds1").toString()
537536
})),
538-
false, false, null, null);
537+
false, null, null);
539538
Set<String> projects = new TreeSet<>(Arrays.asList(new File(repository.getSourceRoot()).list()));
540539
assertEquals(projects.size(), env.getDefaultProjects().size());
541540
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static void setUpClass() throws Exception {
7575
env.setHistoryEnabled(false);
7676
Indexer.getInstance().prepareIndexer(env, true, true,
7777
new TreeSet<>(Collections.singletonList("/c")),
78-
false, false, null, null);
78+
false, null, null);
7979
Indexer.getInstance().doIndexerExecution(true, null, null);
8080

8181

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
@@ -89,7 +89,7 @@ public static void setUpClass() throws Exception {
8989
env.setHistoryEnabled(false);
9090
Indexer.getInstance().prepareIndexer(env, true, true,
9191
new TreeSet<>(Collections.singletonList("/c")),
92-
false, false, null, null);
92+
false, null, null);
9393
Indexer.getInstance().doIndexerExecution(true, null, null);
9494

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

0 commit comments

Comments
 (0)