/// <summary>
 /// Called when the currently executing command completes.
 /// </summary>
 public void CommandLineToolCompletion(CommandLine.Result result)
 {
     PlayServicesResolver.Log(
         string.Format("Command completed with exit code {0}: {1}", result.exitCode, result.message),
         result.exitCode == 0 ? LogLevel.Info: LogLevel.Error);
     this.result = result;
 }
Esempio n. 2
0
 /// <summary>
 /// Log Jdk version parsing failed warning.
 /// </summary>
 /// <param name="javaPath">Path to the java tool.</param>
 /// <param name="commandLineSummary">Summary of the executed command line.</param>
 private static void LogJdkVersionFailedWarning(string javaPath, string commandLineSummary)
 {
     PlayServicesResolver.Log(
         String.Format(
             "Failed to get Java version when running {0}\n" +
             "It is not be possible to verify your Java installation is new enough to " +
             "compile with the latest Android SDK\n\n" +
             "{1}", javaPath, commandLineSummary),
         level: LogLevel.Warning);
 }
Esempio n. 3
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);
            }
        }
 /// <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();
     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;
     PlayServicesResolver.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);
 }