// store the AndroidManifest.xml in a temporary directory before processing it. /// <summary> /// Extract an AAR to the specified directory. /// </summary> /// <param name="aarFile">Name of the AAR file to extract.</param> /// <param name="extract_filenames">List of files to extract from the AAR. If this array /// is empty or null all files are extracted.</param> /// <param name="outputDirectory">Directory to extract the AAR file to.</param> /// <returns>true if successful, false otherwise.</returns> internal virtual bool ExtractAar(string aarFile, string[] extractFilenames, string outputDirectory) { try { string aarPath = Path.GetFullPath(aarFile); string extractFilesArg = extractFilenames != null && extractFilenames.Length > 0 ? " \"" + String.Join("\" \"", extractFilenames) + "\"" : ""; CommandLine.Result result = CommandLine.Run(FindJavaTool("jar"), "xvf " + "\"" + aarPath + "\"" + extractFilesArg, workingDirectory: outputDirectory); if (result.exitCode != 0) { Debug.LogError("Error expanding " + aarPath + " err: " + result.exitCode + ": " + result.stderr); return(false); } } catch (Exception e) { Debug.Log(e); throw e; } return(true); }
/// <summary> /// Create an AAR from the specified directory. /// </summary> /// <param name="aarFile">AAR file to create.</param> /// <param name="inputDirectory">Directory which contains the set of files to store /// in the AAR.</param> /// <returns>true if successful, false otherwise.</returns> internal virtual bool ArchiveAar(string aarFile, string inputDirectory) { try { string aarPath = Path.GetFullPath(aarFile); CommandLine.Result result = CommandLine.Run( JavaUtilities.JarBinaryPath, String.Format("cvf{0} \"{1}\" -C \"{2}\" .", aarFile.ToLower().EndsWith(".jar") ? "" : "M", aarPath, inputDirectory)); if (result.exitCode != 0) { Debug.LogError(String.Format("Error archiving {0}\n" + "Exit code: {1}\n" + "{2}\n" + "{3}\n", aarPath, result.exitCode, result.stdout, result.stderr)); return(false); } } catch (Exception e) { Debug.LogError(e); throw e; } return(true); }
/// <summary> /// Log a message that describes the installation / license fetching operation. /// </summary> /// <param name="toolPath">Tool that was executed.</param> /// <param name="toolArguments">Arguments to passed to the tool.</param> /// <param name="retrievingLicenses">Whether the command is retrieving licenses.</param> /// <param name="packages">List of package versions to install / upgrade..</param> /// <param name="toolResult">Result of the tool's execution.</param> private static void LogInstallLicenseResult( string toolPath, string toolArguments, bool retrievingLicenses, IEnumerable <AndroidSdkPackageNameVersion> packages, CommandLine.Result toolResult) { bool succeeded = toolResult.exitCode == 0; if (!retrievingLicenses || !succeeded) { var failedMessage = retrievingLicenses ? "Failed to retrieve Android SDK package licenses.\n\n" + "Aborted installation of the following packages:\n" : "Android package installation failed.\n\n" + "Failed when installing the following packages:\n"; PlayServicesResolver.Log( String.Format( "{0}\n" + "{1}\n\n" + "{2}\n", succeeded ? "Successfully installed Android packages.\n\n" : failedMessage, AndroidSdkPackageNameVersion.ListToString(packages), toolResult.message), level: succeeded ? LogLevel.Info : LogLevel.Warning); } }
/// <summary> /// Called when the currently executing command completes. /// </summary> public void CommandLineToolCompletion(CommandLine.Result result) { PlayServicesResolver.Log( String.Format("Command completed: {0}", result.message), level: LogLevel.Verbose); this.result = result; }
public static string FindExecutable(string executable) { string text = (Application.platform != RuntimePlatform.WindowsEditor) ? "which" : "where"; try { CommandLine.Result result = CommandLine.Run(text, executable, Environment.CurrentDirectory, null, null); if (result.exitCode == 0) { return(CommandLine.SplitLines(result.stdout)[0]); } } catch (Exception ex) { UnityEngine.Debug.Log(string.Concat(new string[] { "'", text, "' command is not on path. Unable to find executable '", executable, "' (", ex.ToString(), ")" })); } return(null); }
/// <summary> /// Called when the currently executing command completes. /// </summary> public void CommandLineToolCompletion(CommandLine.Result result) { logger.Log( String.Format("Command completed: {0}", result.message), level: LogLevel.Verbose); this.result = result; SignalComplete(); }
/// <summary> /// Called when the currently executing command completes. /// </summary> public void CommandLineToolCompletion(CommandLine.Result result) { logger.Log( String.Format("Command completed: {0}", result.message), level: LogLevel.Verbose); this.result = result; if (ExecutionEnvironment.InBatchMode) { RunOnMainThread.Run(() => { SignalComplete(); }); } }
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(); } }
/// <summary> /// Create an AAR from the specified directory. /// </summary> /// <param name="aarFile">AAR file to create.</param> /// <param name="inputDirectory">Directory which contains the set of files to store /// in the AAR.</param> /// <returns>true if successful, false otherwise.</returns> internal virtual bool ArchiveAar(string aarFile, string inputDirectory) { try { string aarPath = Path.GetFullPath(aarFile); CommandLine.Result result = CommandLine.Run( FindJavaTool("jar"), String.Format("cvf \"{0}\" -C \"{1}\" .", aarPath, inputDirectory)); if (result.exitCode != 0) { Debug.LogError(String.Format("Error archiving {0}\n" + "Exit code: {1}\n" + "{2}\n" + "{3}\n", aarPath, result.exitCode, result.stdout, result.stderr)); return(false); } } catch (Exception e) { Debug.LogError(e); throw e; } return(true); }
/// <summary> /// Called when the currently executing command completes. /// </summary> public void CommandLineToolCompletion(CommandLine.Result result) { this.result = result; }
public static CommandLine.Result RunViaShell(string toolPath, string arguments, string workingDirectory = null, Dictionary <string, string> envVars = null, CommandLine.IOHandler ioHandler = null, bool useShellExecution = false, bool stdoutRedirectionInShellMode = true) { Encoding inputEncoding = Console.InputEncoding; Encoding outputEncoding = Console.OutputEncoding; Console.InputEncoding = Encoding.UTF8; Console.OutputEncoding = Encoding.UTF8; // if (Application.platform == RuntimePlatform.WindowsEditor && toolPath.Contains("'")) // { // useShellExecution = true; // stdoutRedirectionInShellMode = true; // } string text = null; string text2 = null; if (useShellExecution && stdoutRedirectionInShellMode) { text = Path.GetTempFileName(); text2 = Path.GetTempFileName(); string text3 = toolPath; string text4; string text5; string text6; // if (Application.platform == RuntimePlatform.WindowsEditor) // { // text4 = "cmd.exe"; // text5 = "/c \""; // text6 = "\""; // } // else { text4 = "bash"; text5 = "-l -c '"; text6 = "'"; text3 = toolPath.Replace("'", "'\\''"); } arguments = string.Format("{0}\"{1}\" {2} 1> {3} 2> {4}{5}", new object[] { text5, text3, arguments, text, text2, text6 }); toolPath = text4; } Process process = new Process(); process.StartInfo.UseShellExecute = useShellExecution; process.StartInfo.Arguments = arguments; if (useShellExecution) { process.StartInfo.CreateNoWindow = false; process.StartInfo.RedirectStandardOutput = false; process.StartInfo.RedirectStandardError = false; } else { process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; if (envVars != null) { foreach (KeyValuePair <string, string> current in envVars) { process.StartInfo.EnvironmentVariables[current.Key] = current.Value; } } } process.StartInfo.RedirectStandardInput = (!useShellExecution && ioHandler != null); process.StartInfo.FileName = toolPath; process.StartInfo.WorkingDirectory = (workingDirectory ?? Environment.CurrentDirectory); process.Start(); if (ioHandler != null) { ioHandler(process, process.StandardInput, CommandLine.StreamData.Empty); } List <string>[] stdouterr = new List <string>[] { new List <string>(), new List <string>() }; if (useShellExecution) { process.WaitForExit(); if (stdoutRedirectionInShellMode) { stdouterr[0].Add(File.ReadAllText(text)); stdouterr[1].Add(File.ReadAllText(text2)); File.Delete(text); File.Delete(text2); } } else { AutoResetEvent complete = new AutoResetEvent(false); CommandLine.AsyncStreamReader[] array = CommandLine.AsyncStreamReader.CreateFromStreams(new Stream[] { process.StandardOutput.BaseStream, process.StandardError.BaseStream }, 1); new CommandLine.AsyncStreamReaderMultiplexer(array, delegate(CommandLine.StreamData data) { stdouterr[data.handle].Add(data.text); if (ioHandler != null) { ioHandler(process, process.StandardInput, data); } }, delegate { complete.Set(); }); CommandLine.AsyncStreamReader[] array2 = array; for (int i = 0; i < array2.Length; i++) { CommandLine.AsyncStreamReader asyncStreamReader = array2[i]; asyncStreamReader.Start(); } process.WaitForExit(); complete.WaitOne(); } CommandLine.Result result = new CommandLine.Result(); result.stdout = string.Join(string.Empty, stdouterr[0].ToArray()); result.stderr = string.Join(string.Empty, stdouterr[1].ToArray()); result.exitCode = process.ExitCode; result.message = CommandLine.FormatResultMessage(toolPath, arguments, result.stdout, result.stderr, result.exitCode); Console.InputEncoding = inputEncoding; Console.OutputEncoding = outputEncoding; return(result); }
/// <summary> /// Called when the currently executing command completes. /// </summary> public void CommandLineToolCompletion(CommandLine.Result result) { Google.JarResolver.PlayServicesSupport.Log( String.Format("Command completed: {0}", result.message), verbose: true); this.result = result; }