Skip to content

Commit 98edade

Browse files
committed
add progress reporting for file collection
1 parent 6ad8c08 commit 98edade

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,10 @@ boolean getIndexDownArgs(String dir, File sourceRoot, IndexDownArgs args) throws
868868
if (historyBased) {
869869
indexDownUsingHistory(env.getSourceRootFile(), args);
870870
} else {
871-
indexDown(sourceRoot, dir, args);
871+
String logSuffix = project != null ? " for project " + project : String.format(" for directory '%s'", dir);
872+
try (Progress progress = new Progress(LOGGER, String.format("file collection%s", logSuffix))) {
873+
indexDown(sourceRoot, dir, args, progress);
874+
}
872875
}
873876

874877
elapsed.report(LOGGER, String.format("Done file collection for directory '%s'", dir),
@@ -890,9 +893,13 @@ void indexDownUsingHistory(File sourceRoot, IndexDownArgs args) throws IOExcepti
890893

891894
FileCollector fileCollector = RuntimeEnvironment.getInstance().getFileCollector(project.getName());
892895

893-
for (String path : fileCollector.getFiles()) {
894-
File file = new File(sourceRoot, path);
895-
processFileIncremental(args, file, path);
896+
try (Progress progress = new Progress(LOGGER, String.format("collecting files for %s", project),
897+
fileCollector.getFiles().size())) {
898+
for (String path : fileCollector.getFiles()) {
899+
File file = new File(sourceRoot, path);
900+
processFileIncremental(args, file, path);
901+
progress.increment();
902+
}
896903
}
897904
}
898905

@@ -1561,10 +1568,11 @@ private void handleSymlink(String path, AcceptSymlinkRet ret) {
15611568
* @param dir the root indexDirectory to generate indexes for
15621569
* @param parent path to parent directory
15631570
* @param args arguments to control execution and for collecting a list of
1571+
* @param progress {@link Progress} instance
15641572
* files for indexing
15651573
*/
15661574
@VisibleForTesting
1567-
void indexDown(File dir, String parent, IndexDownArgs args) throws IOException {
1575+
void indexDown(File dir, String parent, IndexDownArgs args, Progress progress) throws IOException {
15681576

15691577
if (isInterrupted()) {
15701578
return;
@@ -1590,9 +1598,10 @@ void indexDown(File dir, String parent, IndexDownArgs args) throws IOException {
15901598
handleSymlink(path, ret);
15911599
} else {
15921600
if (file.isDirectory()) {
1593-
indexDown(file, path, args);
1601+
indexDown(file, path, args, progress);
15941602
} else {
15951603
processFile(args, file, path);
1604+
progress.increment();
15961605
}
15971606
}
15981607
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2018, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.index;
@@ -555,11 +555,11 @@ private void checkIndexDown(boolean historyBased, IndexDatabase idb) throws IOEx
555555
// hence it should be called just once.
556556
if (historyBased) {
557557
verify(idb, times(1)).indexDownUsingHistory(any(), any());
558-
verify(idb, times(0)).indexDown(any(), any(), any());
558+
verify(idb, times(0)).indexDown(any(), any(), any(), any());
559559
} else {
560560
// indexDown() is recursive, so it will be called more than once.
561561
verify(idb, times(0)).indexDownUsingHistory(any(), any());
562-
verify(idb, atLeast(1)).indexDown(any(), any(), any());
562+
verify(idb, atLeast(1)).indexDown(any(), any(), any(), any());
563563
}
564564
}
565565

0 commit comments

Comments
 (0)