private int runCommand(Command command, String commandName, String[] commandArgs) {
File portFile = null;
if (config != null) {
portFile = config.getPortFile();
}
File daemonPidFile = new File(UserConfig.getUserConfigDir(), DaemonOperation.PID_FILE);
boolean localDirHandledInDaemonScope = portFile != null && portFile.exists();
boolean daemonRunning = PidFileUtil.isProcessRunning(daemonPidFile);
boolean needsToRunInInitializedScope = command.getRequiredCommandScope() == CommandScope.INITIALIZED_LOCALDIR;
boolean sendToRest = daemonRunning & localDirHandledInDaemonScope && needsToRunInInitializedScope;
command.setOut(out);
if (sendToRest) {
if (command.canExecuteInDaemonScope()) {
return sendToRest(command, commandName, commandArgs, portFile);
}
else {
logger.log(Level.SEVERE, "Command not allowed when folder is daemon-managed: " + command.toString());
return showErrorAndExit("Command not allowed when folder is daemon-managed");
}
}
else {
return runLocally(command, commandArgs);
}
}