Run() public static method

Execute a command line tool.
public static Run ( string toolPath, string arguments, string workingDirectory = null, string>.Dictionary envVars = null, IOHandler ioHandler = null ) : System.Result
toolPath string Tool to execute.
arguments string String to pass to the tools' command line.
workingDirectory string Directory to execute the tool from.
envVars string>.Dictionary Additional environment variables to set for the command.
ioHandler IOHandler Allows a caller to provide interactive input and also handle /// both output and error streams from a single delegate.
return System.Result
 /// <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>
        /// Determine whether the user's JDK is sufficient for the Android SDK and recently
        /// released libraries.
        /// </summary>
        internal static void CheckJdkForApiLevel()
        {
            // Get JAVA_HOME path from the editor settings.
            string javaPath = null;

            try {
                javaPath = JavaBinaryPath;
            } catch (ToolNotFoundException) {
                return;
            }
            var result = CommandLine.Run(javaPath, "-version", Directory.GetCurrentDirectory(),
                                         envVars: new Dictionary <string, string> {
                { JAVA_HOME, JavaHome }
            });

            if (result.exitCode != 0)
            {
                LogJdkVersionFailedWarning(javaPath, result.message);
                return;
            }
            float majorMinorVersion = 0;

            // The version string is can be reported via stderr or stdout so scrape the
            // concatenated message string.
            foreach (var line in CommandLine.SplitLines(result.message))
            {
                if (line.StartsWith("java version "))
                {
                    var tokens        = line.Split();
                    var versionString = tokens[tokens.Length - 1].Trim(new [] { '"' });
                    var components    = versionString.Split(new [] { '.' });
                    if (components.Length < 2)
                    {
                        continue;
                    }
                    if (!float.TryParse(components[0] + "." + components[1], NumberStyles.Any,
                                        CultureInfo.InvariantCulture, out majorMinorVersion))
                    {
                        continue;
                    }
                }
            }
            if (majorMinorVersion == 0)
            {
                LogJdkVersionFailedWarning(javaPath, result.message);
                return;
            }
            // If the user's installed JDK is too old, report an error.
            if (majorMinorVersion < MINIMUM_JDK_VERSION_MAJOR_MINOR)
            {
                PlayServicesResolver.Log(
                    String.Format("The configured JDK {0} is too old to build Android " +
                                  "applications with recent libraries.\n" +
                                  "Please install JDK version {1} or newer and configure Unity " +
                                  "to use the new JDK installation in the " +
                                  "'Unity Preferences > External Tools' menu.\n",
                                  majorMinorVersion, MINIMUM_JDK_VERSION_MAJOR_MINOR),
                    level: LogLevel.Error);
            }
        }
 // 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);
 }
示例#4
0
        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);
        }
示例#5
0
        /// <summary>
        /// Determine whether the user's JDK is sufficient for the Android SDK and recently
        /// released libraries.
        /// </summary>
        internal static void CheckJdkForApiLevel()
        {
            // Get JAVA_HOME path from the editor settings.
            string javaPath = null;

            try {
                javaPath = JavaBinaryPath;
            } catch (ToolNotFoundException) {
                return;
            }
            var result = CommandLine.Run(javaPath, "-version", Directory.GetCurrentDirectory(),
                                         envVars: new Dictionary <string, string> {
                { JAVA_HOME, JavaHome }
            });

            if (result.exitCode != 0)
            {
                LogJdkVersionFailedWarning(javaPath, result.message);
                return;
            }
            Version foundVersion = null;
            // The version string is can be reported via stderr or stdout so scrape the
            // concatenated message string.
            string pattern = "^(?<model>java||openjdk) version \"(?<version>[^\"]*)\".*$";

            Match match = Regex.Match(result.message, pattern, RegexOptions.Multiline);

            if (match.Success)
            {
                String versionString = match.Groups["version"].Value;
                // Version requires a Max and Min version, so if there is only one version,
                // add a 0 minor version.
                if (!versionString.Contains("."))
                {
                    versionString += ".0";
                }
                foundVersion = new Version(Regex.Replace(versionString, "[^0-9\\.]", ""));
            }
            if (foundVersion == null)
            {
                LogJdkVersionFailedWarning(javaPath, result.message);
                return;
            }
            // If the user's installed JDK is too old, report an error.
            if (foundVersion < MinimumJdkVersion)
            {
                PlayServicesResolver.analytics.Report("jdk/outofdate", "JDK out of date");
                PlayServicesResolver.Log(
                    String.Format("The configured JDK {0} is too old to build Android " +
                                  "applications with recent libraries.\n" +
                                  "Please install JDK version {1} or newer and configure Unity " +
                                  "to use the new JDK installation in the " +
                                  "'Unity Preferences > External Tools' menu.\n",
                                  foundVersion, MinimumJdkVersion),
                    level: LogLevel.Error);
            }
        }
示例#6
0
        /// <summary>
        /// Determine whether the user's JDK is sufficient for the Android SDK and recently
        /// released libraries.
        /// </summary>
        internal static void CheckJdkForApiLevel()
        {
            // Get JAVA_HOME path from the editor settings.
            string javaPath = null;

            try {
                javaPath = JavaBinaryPath;
            } catch (ToolNotFoundException) {
                return;
            }
            var result = CommandLine.Run(javaPath, "-version", Directory.GetCurrentDirectory(),
                                         envVars: new Dictionary <string, string> {
                { JAVA_HOME, JavaHome }
            });

            if (result.exitCode != 0)
            {
                LogJdkVersionFailedWarning(javaPath, result.message);
                return;
            }
            float majorMinorVersion = 0;
            // The version string is can be reported via stderr or stdout so scrape the
            // concatenated message string.
            string pattern = "^(?<model>java||openjdk) version \"(?<major>\\d).(?<minor>\\d).(?<patch>\\d).*$";

            Match match = Regex.Match(result.message, pattern, RegexOptions.Multiline);

            if (match.Success)
            {
                float.TryParse(match.Groups["major"].Value + "." + match.Groups["minor"].Value, NumberStyles.Any,
                               CultureInfo.InvariantCulture, out majorMinorVersion);
            }
            if (majorMinorVersion == 0)
            {
                LogJdkVersionFailedWarning(javaPath, result.message);
                return;
            }
            // If the user's installed JDK is too old, report an error.
            if (majorMinorVersion < MINIMUM_JDK_VERSION_MAJOR_MINOR)
            {
                PlayServicesResolver.Log(
                    String.Format("The configured JDK {0} is too old to build Android " +
                                  "applications with recent libraries.\n" +
                                  "Please install JDK version {1} or newer and configure Unity " +
                                  "to use the new JDK installation in the " +
                                  "'Unity Preferences > External Tools' menu.\n",
                                  majorMinorVersion, MINIMUM_JDK_VERSION_MAJOR_MINOR),
                    level: LogLevel.Error);
            }
        }
示例#7
0
        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);
 }