/// <summary> /// Asynchronously execute a command line tool in this window, showing progress /// and finally calling the specified delegate on completion from the main / UI thread. /// </summary> /// <param name="toolPath">Tool to execute.</param> /// <param name="arguments">String to pass to the tools' command line.</param> /// <param name="completionDelegate">Called when the tool completes.</param> /// <param name="workingDirectory">Directory to execute the tool from.</param> /// <param name="ioHandler">Allows a caller to provide interactive input and also handle /// both output and error streams from a single delegate.</param> /// <param name="maxProgressLines">Specifies the number of lines output by the /// command line that results in a 100% value on a progress bar.</param> /// <returns>Reference to the new window.</returns> public void RunAsync( string toolPath, string arguments, CommandLine.CompletionHandler completionDelegate, string workingDirectory = null, Dictionary <string, string> envVars = null, CommandLine.IOHandler ioHandler = null, int maxProgressLines = 0) { CommandLineDialog.ProgressReporter reporter = new CommandLineDialog.ProgressReporter(logger); reporter.maxProgressLines = maxProgressLines; // Call the reporter from the UI thread from this window. UpdateEvent += reporter.Update; // Connect the user's delegate to the reporter's completion method. reporter.Complete += completionDelegate; // Connect the caller's IoHandler delegate to the reporter. reporter.DataHandler += ioHandler; // Disconnect the reporter when the command completes. CommandLine.CompletionHandler reporterUpdateDisable = (CommandLine.Result unusedResult) => { this.UpdateEvent -= reporter.Update; }; reporter.Complete += reporterUpdateDisable; logger.Log(String.Format( "Executing command: {0} {1}", toolPath, arguments), level: LogLevel.Verbose); CommandLine.RunAsync(toolPath, arguments, reporter.CommandLineToolCompletion, workingDirectory: workingDirectory, envVars: envVars, ioHandler: reporter.AggregateLine); }
// Handles the platform specific differences of executing the generate gradle script, and // creating the dialog responsible for showing the progress of the execution. // Any errors are reported to the console as well. /// <param name="args">Arguments to be passed to the generate gradle script tool.</param> private static void RunGenGradleScript(string args, CommandLine.CompletionHandler completedHandler) { ExtractPrebuildScripts(); // b/35663224 Combine execute-python-exe which handles the windows logic. bool onWindows = UnityEngine.Application.platform == UnityEngine.RuntimePlatform.WindowsEditor; string command = "\"" + Path.Combine(GRADLE_SCRIPT_LOCATION, onWindows ? GENERATE_GRADLE_EXE_WINDOWS : GENERATE_GRADLE_EXE_GENERIC) + "\""; if (!onWindows) { args = command + args; command = CommandLine.FindExecutable("python"); } CommandLineDialog window = CommandLineDialog.CreateCommandLineDialog( "Resolving Jars."); window.modal = false; window.summaryText = "Generating and running Gradle prebuild."; window.progressTitle = window.summaryText; window.autoScrollToBottom = true; window.RunAsync(command, args, (result) => { if (result.exitCode != 0) { Debug.LogError("Error somewhere in the process of creating the gradle build, " + "executing it, and copying the outputs.\n" + "This will break dependency resolution and your build will not run.\n" + "See the output below for possible gradle build errors. The most likely " + "cases are: an invalid bundleID (which you can correct in the Android " + "Player Settings), or a failure to determine the Android SDK platform " + "and build tools verison (you can verify that you have a valid android " + "SDK path in the Unity preferences.\n" + "If you're not able to diagnose the error, please report a bug at: " + "https://github.com/googlesamples/unity-jar-resolver/issues" + "A possible work-around is to turn off the " + "\"Gradle Prebuild\" from the Jar Resolver Settings.\n\n" + "Error (" + result.exitCode + "):\n" + result.stdout + result.stderr); window.bodyText += "\n\nResolution Failed."; } else { window.bodyText += "\n\nResolution Complete."; } window.noText = "Close"; // After adding the button we need to scroll down a little more. window.scrollPosition.y = Mathf.Infinity; window.Repaint(); completedHandler(result); if (result.exitCode == 0) { window.Close(); } }, maxProgressLines: 50); window.Show(); }
public void RunAsync(string toolPath, string arguments, CommandLine.CompletionHandler completionDelegate, string workingDirectory = null, Dictionary <string, string> envVars = null, CommandLine.IOHandler ioHandler = null, int maxProgressLines = 0) { CommandLineDialog.ProgressReporter reporter = new CommandLineDialog.ProgressReporter(this.logger); reporter.maxProgressLines = maxProgressLines; this.UpdateEvent += new CommandLineDialog.UpdateDelegate(reporter.Update); reporter.Complete += completionDelegate; reporter.DataHandler += ioHandler; CommandLine.CompletionHandler value = delegate(CommandLine.Result unusedResult) { this.UpdateEvent -= new CommandLineDialog.UpdateDelegate(reporter.Update); }; reporter.Complete += value; this.logger.Log(string.Format("Executing command: {0} {1}", toolPath, arguments), LogLevel.Verbose); CommandLine.RunAsync(toolPath, arguments, new CommandLine.CompletionHandler(reporter.CommandLineToolCompletion), workingDirectory, envVars, new CommandLine.IOHandler(reporter.AggregateLine)); }
public static void RunAsync(string toolPath, string arguments, CommandLine.CompletionHandler completionDelegate, string workingDirectory = null, Dictionary <string, string> envVars = null, CommandLine.IOHandler ioHandler = null) { Action action = delegate { CommandLine.Result result = CommandLine.Run(toolPath, arguments, workingDirectory, envVars, ioHandler); completionDelegate(result); }; if (ExecutionEnvironment.InBatchMode) { action(); } else { Thread thread = new Thread(new ThreadStart(action.Invoke)); thread.Start(); } }