From 37a114ef7620f862eabf5ca9663d9d8dd7b5c809 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 31 Aug 2014 19:22:31 +0000 Subject: [PATCH] * improve executeScript usage --- source/net/filebot/cli/ScriptShellBaseClass.java | 13 +++++++------ source/net/filebot/cli/ScriptShellMethods.java | 12 ++++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index fb5a295b..4c0071ca 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -1,5 +1,6 @@ package net.filebot.cli; +import static java.util.Arrays.*; import static java.util.Collections.*; import static net.filebot.cli.CLILogging.*; import static net.filebot.util.StringUtilities.*; @@ -76,7 +77,7 @@ public abstract class ScriptShellBaseClass extends Script { public void include(String input) throws Throwable { try { - executeScript(input, new String[0], null, null); + executeScript(input, null, null, null); } catch (Exception e) { printException(e, true); } @@ -85,7 +86,7 @@ public abstract class ScriptShellBaseClass extends Script { public Object runScript(String input, String... argv) throws Throwable { try { ArgumentBean args = argv == null || argv.length == 0 ? getArgumentBean() : ArgumentBean.parse(argv); - return executeScript(input, args.getArray(), args.defines, args.getFiles(false)); + return executeScript(input, asList(getArgumentBean().getArray()), args.defines, args.getFiles(false)); } catch (Exception e) { printException(e, true); } @@ -93,10 +94,10 @@ public abstract class ScriptShellBaseClass extends Script { } public Object executeScript(String input, Map bindings, Object... args) throws Throwable { - return executeScript(input, getArgumentBean().getArray(), bindings, FileUtilities.asFileList(args)); + return executeScript(input, asList(getArgumentBean().getArray()), bindings, FileUtilities.asFileList(args)); } - public Object executeScript(String input, String[] argv, Map bindings, List args) throws Throwable { + public Object executeScript(String input, List argv, Map bindings, List args) throws Throwable { // apply parent script defines Bindings parameters = new SimpleBindings(); @@ -105,8 +106,8 @@ public abstract class ScriptShellBaseClass extends Script { parameters.putAll(bindings); } - parameters.put(ScriptShell.SHELL_ARGV_BINDING_NAME, argv); - parameters.put(ScriptShell.ARGV_BINDING_NAME, args); + parameters.put(ScriptShell.SHELL_ARGV_BINDING_NAME, argv != null ? argv.toArray(new String[0]) : new String[0]); + parameters.put(ScriptShell.ARGV_BINDING_NAME, args != null ? new ArrayList(args) : new ArrayList()); // run given script ScriptShell shell = (ScriptShell) getBinding().getVariable(ScriptShell.SHELL_BINDING_NAME); diff --git a/source/net/filebot/cli/ScriptShellMethods.java b/source/net/filebot/cli/ScriptShellMethods.java index df0e3089..4e798910 100644 --- a/source/net/filebot/cli/ScriptShellMethods.java +++ b/source/net/filebot/cli/ScriptShellMethods.java @@ -330,8 +330,12 @@ public class ScriptShellMethods { return MediaDetection.getStructurePathTail(self); } - public static FolderWatchService watch(File self, final Closure callback) throws IOException { - FolderWatchService watchService = new FolderWatchService(true) { + public static FolderWatchService watchFolder(File self, Closure callback) throws IOException { + return watch(self, false, false, 1000, callback); + } + + public static FolderWatchService watch(File self, boolean watchTree, boolean commitPerFolder, long commitDelay, final Closure callback) throws IOException { + FolderWatchService watchService = new FolderWatchService(watchTree) { @Override public void processCommitSet(File[] files, File dir) { @@ -340,8 +344,8 @@ public class ScriptShellMethods { }; // collect updates for 500 ms and then batch process - watchService.setCommitDelay(500); - watchService.setCommitPerFolder(true); + watchService.setCommitDelay(commitDelay); + watchService.setCommitPerFolder(commitPerFolder); // start watching the given folder watchService.watchFolder(self);