[automation] ScriptFileWatcher Initial import now only processes dir (#2708)

Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
This commit is contained in:
Jonathan Gilbert 2022-01-29 22:53:56 +00:00 committed by GitHub
parent a4c39d5ba0
commit 290ad08107
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,6 +128,24 @@ public class ScriptFileWatcher extends AbstractWatchService implements ReadyServ
this.executorFactory = executorFactory;
}
/**
* Processes initial import of resources.
*
* @param rootDirectory the root directory to import initial resources from
*/
private void importInitialResources(File rootDirectory) {
if (rootDirectory.exists()) {
File[] files = rootDirectory.listFiles();
if (files != null) {
for (File f : files) {
if (!f.isHidden()) {
importResources(f);
}
}
}
}
}
/**
* Imports resources from the specified file or directory.
*
@ -285,7 +303,7 @@ public class ScriptFileWatcher extends AbstractWatchService implements ReadyServ
if (newLevel >= StartLevelService.STARTLEVEL_MODEL) { // start
ScheduledExecutorService localScheduler = executorFactory.get();
scheduler = localScheduler;
localScheduler.submit(() -> importResources(new File(pathToWatch)));
localScheduler.submit(() -> importInitialResources(new File(pathToWatch)));
localScheduler.scheduleWithFixedDelay(() -> checkFiles(currentStartLevel), 0, RECHECK_INTERVAL,
TimeUnit.SECONDS);
}