Ejemplo n.º 1
0
        public ProcessExecutionCommand CreateExecutionCommand(IWorkspaceObject entry, ConfigurationSelector configuration)
        {
            string         exe, args;
            StringTagModel tagSource = GetTagModel(entry, configuration);

            ParseCommand(tagSource, out exe, out args);

            ProjectConfiguration config = null;

            if (entry is IConfigurationTarget)
            {
                config = configuration.GetConfiguration((IConfigurationTarget)entry) as ProjectConfiguration;
            }

            //if the executable name matches an executable in the project directory, use that, for back-compat
            //else fall back and let the execution handler handle it via PATH, working directory, etc.
            if (!Path.IsPathRooted(exe))
            {
                string localPath = ((FilePath)exe).ToAbsolute(entry.BaseDirectory).FullPath;
                if (File.Exists(localPath))
                {
                    exe = localPath;
                }
            }

            ProcessExecutionCommand cmd = Runtime.ProcessService.CreateCommand(exe);

            cmd.Arguments = args;

            FilePath workingDir = this.workingdir;

            if (!workingDir.IsNullOrEmpty)
            {
                workingDir = StringParserService.Parse(workingDir, tagSource);
            }
            cmd.WorkingDirectory = workingDir.IsNullOrEmpty
                                ? entry.BaseDirectory
                                : workingDir.ToAbsolute(entry.BaseDirectory);

            if (environmentVariables != null)
            {
                var vars = new Dictionary <string, string> ();
                foreach (var v in environmentVariables)
                {
                    vars [v.Key] = StringParserService.Parse(v.Value, tagSource);
                }
                if (config != null)
                {
                    foreach (var v in config.EnvironmentVariables)
                    {
                        vars [v.Key] = StringParserService.Parse(v.Value, tagSource);
                    }
                }
                cmd.EnvironmentVariables = vars;
            }

            return(cmd);
        }
 public ExternalProcessDesktopApplication(
     ProcessExecutionCommand command,
     string displayName,
     bool isDefault)
     : base(command.Command, displayName, isDefault)
 {
     this.command = command;
     Arguments    = command.Arguments ?? string.Empty;
 }
Ejemplo n.º 3
0
        public ProcessExecutionCommand CreateExecutionCommand(IWorkspaceObject entry, ConfigurationSelector configuration)
        {
            if (string.IsNullOrEmpty(command))
            {
                throw new UserException(GettextCatalog.GetString("Invalid custom command for '{0}' step: the path to the command to execute has not been provided.", TypeLabel));
            }
            string         exe, args;
            StringTagModel tagSource = GetTagModel(entry, configuration);

            ParseCommand(tagSource, out exe, out args);

            //if the executable name matches an executable in the project directory, use that, for back-compat
            //else fall back and let the execution handler handle it via PATH, working directory, etc.
            if (!Path.IsPathRooted(exe))
            {
                string localPath = ((FilePath)exe).ToAbsolute(entry.BaseDirectory).FullPath;
                if (File.Exists(localPath))
                {
                    exe = localPath;
                }
            }

            ProcessExecutionCommand cmd = Runtime.ProcessService.CreateCommand(exe);

            cmd.Arguments = args;

            FilePath workingDir = this.workingdir;

            if (!workingDir.IsNullOrEmpty)
            {
                workingDir = StringParserService.Parse(workingDir, tagSource);
            }
            cmd.WorkingDirectory = workingDir.IsNullOrEmpty
                                ? entry.BaseDirectory
                                : workingDir.ToAbsolute(entry.BaseDirectory);

            if (environmentVariables != null)
            {
                var vars = new Dictionary <string, string> ();
                foreach (var v in environmentVariables)
                {
                    vars [v.Key] = StringParserService.Parse(v.Value, tagSource);
                }
                cmd.EnvironmentVariables = vars;
            }

            return(cmd);
        }
Ejemplo n.º 4
0
        public void Customize(ExecutionCommand command, object configurationData)
        {
            CustomArgsExecutionModeData data = (CustomArgsExecutionModeData)configurationData;

            // Customize the command

            ProcessExecutionCommand cmd = (ProcessExecutionCommand)command;

            if (!string.IsNullOrEmpty(data.Arguments))
            {
                cmd.Arguments = data.Arguments;
            }
            if (!string.IsNullOrEmpty(data.WorkingDirectory))
            {
                cmd.WorkingDirectory = data.WorkingDirectory;
            }
            foreach (KeyValuePair <string, string> var in data.EnvironmentVariables)
            {
                cmd.EnvironmentVariables [var.Key] = var.Value;
            }
        }
Ejemplo n.º 5
0
        ExecutionCommand CreateCommand(SolutionEntityItem item)
        {
            DotNetProject project = item as DotNetProject;

            if (project == null || project.CompileTarget != CompileTarget.Library || project.ParentSolution == null)
            {
                return(null);
            }

            SolutionAddinData sdata = project.ParentSolution.GetAddinData();

            if (sdata == null || project.GetAddinData() == null || project.GetAddinData().IsRoot)
            {
                return(null);
            }

            RegistryInfo ri = sdata.ExternalRegistryInfo;

            if (ri == null || string.IsNullOrEmpty(ri.TestCommand))
            {
                return(null);
            }

            FilePath cmd;
            string   args;

            if (ri.TestCommand [0] == '"')
            {
                // If the file name is quoted, unquote it
                int i = ri.TestCommand.IndexOf('"', 1);
                if (i == -1)
                {
                    throw new UserException("Invalid add-in test command: " + ri.TestCommand);
                }
                cmd  = ri.TestCommand.Substring(1, i - 1);
                args = ri.TestCommand.Substring(i + 1).Trim();
            }
            else
            {
                int i = ri.TestCommand.IndexOf(' ');
                if (i == -1)
                {
                    cmd  = ri.TestCommand;
                    args = string.Empty;
                }
                else
                {
                    cmd  = ri.TestCommand.Substring(0, i);
                    args = ri.TestCommand.Substring(i + 1).Trim();
                }
            }

            // If the command is an absolute file, take it
            // It not, consider it is a file relative to the startup path
            // If a relative file can't be found, use it as is

            if (!cmd.IsAbsolute)
            {
                FilePath absCmd = cmd.ToAbsolute(ri.ApplicationPath);
                if (System.IO.File.Exists(absCmd))
                {
                    cmd = absCmd;
                }
            }

            ProcessExecutionCommand pcmd = Runtime.ProcessService.CreateCommand(cmd) as ProcessExecutionCommand;

            if (pcmd == null)
            {
                return(null);
            }
            pcmd.Arguments = args;
            pcmd.EnvironmentVariables ["MONO_ADDINS_REGISTRY"] = sdata.TestRegistryPath;
            return(pcmd);
        }
Ejemplo n.º 6
0
        public void Execute(IProgressMonitor monitor, IWorkspaceObject entry, ExecutionContext context,
                            ConfigurationSelector configuration)
        {
            ProcessExecutionCommand cmd = CreateExecutionCommand(entry, configuration);

            monitor.Log.WriteLine(GettextCatalog.GetString("Executing: {0} {1}", cmd.Command, cmd.Arguments));

            if (!Directory.Exists(cmd.WorkingDirectory))
            {
                monitor.ReportError(GettextCatalog.GetString("Custom command working directory does not exist"), null);
                return;
            }

            AggregatedOperationMonitor aggMon = null;
            IProcessAsyncOperation     oper   = null;
            IConsole console = null;

            try {
                if (context != null)
                {
                    if (externalConsole)
                    {
                        console = context.ExternalConsoleFactory.CreateConsole(!pauseExternalConsole);
                    }
                    else
                    {
                        console = context.ConsoleFactory.CreateConsole(!pauseExternalConsole);
                    }
                    oper = context.ExecutionHandler.Execute(cmd, console);
                }
                else
                {
                    if (externalConsole)
                    {
                        console = ExternalConsoleFactory.Instance.CreateConsole(!pauseExternalConsole);
                        oper    = Runtime.ProcessService.StartConsoleProcess(cmd.Command, cmd.Arguments,
                                                                             cmd.WorkingDirectory, console, null);
                    }
                    else
                    {
                        oper = Runtime.ProcessService.StartProcess(cmd.Command, cmd.Arguments,
                                                                   cmd.WorkingDirectory, monitor.Log, monitor.Log, null, false);
                    }
                }
                aggMon = new AggregatedOperationMonitor(monitor, oper);
                oper.WaitForCompleted();
                if (!oper.Success)
                {
                    monitor.ReportError("Custom command failed (exit code: " + oper.ExitCode + ")", null);
                }
            } catch (Win32Exception w32ex) {
                monitor.ReportError(GettextCatalog.GetString("Failed to execute custom command '{0}': {1}",
                                                             cmd.Command, w32ex.Message), null);
                return;
            } catch (Exception ex) {
                LoggingService.LogError("Command execution failed", ex);
                throw new UserException(GettextCatalog.GetString("Command execution failed: {0}", ex.Message));
            } finally {
                if (oper == null || !oper.Success)
                {
                    monitor.AsyncOperation.Cancel();
                }
                if (oper != null)
                {
                    oper.Dispose();
                }
                if (console != null)
                {
                    console.Dispose();
                }
                if (aggMon != null)
                {
                    aggMon.Dispose();
                }
            }
        }
Ejemplo n.º 7
0
        public async Task <bool> Execute(ProgressMonitor monitor, WorkspaceObject entry, ExecutionContext context,
                                         ConfigurationSelector configuration)
        {
            ProcessExecutionCommand cmd = CreateExecutionCommand(entry, configuration);

            monitor.Log.WriteLine(GettextCatalog.GetString("Executing: {0} {1}", cmd.Command, cmd.Arguments));

            if (!Directory.Exists(cmd.WorkingDirectory))
            {
                monitor.ReportError(GettextCatalog.GetString("Custom command working directory does not exist"), null);
                return(false);
            }

            ProcessAsyncOperation oper    = null;
            OperationConsole      console = null;
            var result = true;

            try {
                if (context != null)
                {
                    if (externalConsole)
                    {
                        console = context.ExternalConsoleFactory.CreateConsole(!pauseExternalConsole, monitor.CancellationToken);
                    }
                    else
                    {
                        console = context.ConsoleFactory.CreateConsole(monitor.CancellationToken);
                    }
                    oper = context.ExecutionHandler.Execute(cmd, console);
                }
                else
                {
                    if (externalConsole)
                    {
                        console = ExternalConsoleFactory.Instance.CreateConsole(!pauseExternalConsole, monitor.CancellationToken);
                        oper    = Runtime.ProcessService.StartConsoleProcess(cmd.Command, cmd.Arguments,
                                                                             cmd.WorkingDirectory, console, null);
                    }
                    else
                    {
                        oper = Runtime.ProcessService.StartProcess(cmd.Command, cmd.Arguments,
                                                                   cmd.WorkingDirectory, monitor.Log, monitor.Log, null, false).ProcessAsyncOperation;
                    }
                }

                using (var stopper = monitor.CancellationToken.Register(oper.Cancel)) {
                    await oper.Task;
                }

                if (oper.ExitCode != 0)
                {
                    monitor.ReportError(GettextCatalog.GetString("Custom command failed (exit code: {0})", oper.ExitCode), null);
                }
            } catch (Win32Exception w32ex) {
                monitor.ReportError(GettextCatalog.GetString("Failed to execute custom command '{0}': {1}",
                                                             cmd.Command, w32ex.Message), null);
                return(false);
            } catch (Exception ex) {
                LoggingService.LogError("Command execution failed", ex);
                throw new UserException(GettextCatalog.GetString("Command execution failed: {0}", ex.Message));
            } finally {
                result = oper != null && oper.ExitCode == 0;
                if (console != null)
                {
                    console.Dispose();
                }
            }
            return(result);
        }
Ejemplo n.º 8
0
        UnitTestResult RunWithConsoleRunner(ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var          outFile = Path.GetTempFileName();
            LocalConsole cons    = new LocalConsole();

            try {
                MonoDevelop.NUnit.External.TcpTestListener tcpListener = null;
                LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

                if (!string.IsNullOrEmpty(cmd.Arguments))
                {
                    cmd.Arguments += " ";
                }
                cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath;

                bool automaticUpdates = cmd.Command.Contains("GuiUnit") || (cmd.Command.Contains("mdtool.exe") && cmd.Arguments.Contains("run-md-tests"));
                if (!string.IsNullOrEmpty(pathName))
                {
                    cmd.Arguments += " -run=" + pathName;
                }
                if (automaticUpdates)
                {
                    tcpListener    = new MonoDevelop.NUnit.External.TcpTestListener(localMonitor, suiteName);
                    cmd.Arguments += " -port=" + tcpListener.Port;
                }

                // Note that we always dispose the tcp listener as we don't want it listening
                // forever if the test runner does not try to connect to it
                using (tcpListener) {
                    var p = testContext.ExecutionContext.Execute(cmd, cons);

                    testContext.Monitor.CancelRequested += p.Cancel;
                    if (testContext.Monitor.IsCancelRequested)
                    {
                        p.Cancel();
                    }
                    p.WaitForCompleted();

                    if (new FileInfo(outFile).Length == 0)
                    {
                        throw new Exception("Command failed");
                    }
                }

                // mdtool.exe does not necessarily guarantee we get automatic updates. It just guarantees
                // that if guiunit is being used then it will give us updates. If you have a regular test
                // assembly compiled against nunit.framework.dll
                if (automaticUpdates && tcpListener.HasReceivedConnection)
                {
                    if (testName != null)
                    {
                        return(localMonitor.SingleTestResult);
                    }
                    return(test.GetLastResult());
                }

                XDocument doc = XDocument.Load(outFile);

                if (doc.Root != null)
                {
                    var root = doc.Root.Elements("test-suite").FirstOrDefault();
                    if (root != null)
                    {
                        cons.SetDone();
                        var ot = cons.Out.ReadToEnd();
                        var et = cons.Error.ReadToEnd();
                        testContext.Monitor.WriteGlobalLog(ot);
                        if (!string.IsNullOrEmpty(et))
                        {
                            testContext.Monitor.WriteGlobalLog("ERROR:\n");
                            testContext.Monitor.WriteGlobalLog(et);
                        }

                        bool macunitStyle = doc.Root.Element("environment") != null && doc.Root.Element("environment").Attribute("macunit-version") != null;
                        var  result       = ReportXmlResult(localMonitor, root, "", macunitStyle);
                        if (testName != null)
                        {
                            result = localMonitor.SingleTestResult;
                        }
                        return(result);
                    }
                }
                throw new Exception("Test results could not be parsed.");
            } catch (Exception ex) {
                cons.SetDone();
                var ot = cons.Out.ReadToEnd();
                var et = cons.Error.ReadToEnd();
                testContext.Monitor.WriteGlobalLog(ot);
                if (!string.IsNullOrEmpty(et))
                {
                    testContext.Monitor.WriteGlobalLog("ERROR:\n");
                    testContext.Monitor.WriteGlobalLog(et);
                }
                testContext.Monitor.ReportRuntimeError("Test execution failed.\n" + ot + "\n" + et, ex);
                return(UnitTestResult.CreateIgnored("Test execution failed"));
            } finally {
                File.Delete(outFile);
            }
        }
Ejemplo n.º 9
0
        UnitTestResult RunWithConsoleRunner(ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var          outFile = Path.GetTempFileName();
            LocalConsole cons    = new LocalConsole();

            try {
                if (!string.IsNullOrEmpty(cmd.Arguments))
                {
                    cmd.Arguments += " ";
                }
                cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath;
                if (!string.IsNullOrEmpty(testName))
                {
                    cmd.Arguments += " -run=" + suiteName + "." + testName;
                }
                else if (!string.IsNullOrEmpty(suiteName))
                {
                    cmd.Arguments += " -run=" + suiteName;
                }
                var p = testContext.ExecutionContext.Execute(cmd, cons);

                testContext.Monitor.CancelRequested += p.Cancel;
                if (testContext.Monitor.IsCancelRequested)
                {
                    p.Cancel();
                }
                p.WaitForCompleted();

                if (new FileInfo(outFile).Length == 0)
                {
                    throw new Exception("Command failed");
                }

                LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);
                XDocument        doc          = XDocument.Load(outFile);
                if (doc.Root != null)
                {
                    var root = doc.Root.Elements("test-suite").FirstOrDefault();
                    if (root != null)
                    {
                        cons.SetDone();
                        var ot = cons.Out.ReadToEnd();
                        var et = cons.Error.ReadToEnd();
                        testContext.Monitor.WriteGlobalLog(ot);
                        if (!string.IsNullOrEmpty(et))
                        {
                            testContext.Monitor.WriteGlobalLog("ERROR:\n");
                            testContext.Monitor.WriteGlobalLog(et);
                        }
                        return(ReportXmlResult(localMonitor, root, ""));
                    }
                }
                throw new Exception("Test results could not be parsed.");
            } catch (Exception ex) {
                cons.SetDone();
                var ot = cons.Out.ReadToEnd();
                var et = cons.Error.ReadToEnd();
                testContext.Monitor.WriteGlobalLog(ot);
                if (!string.IsNullOrEmpty(et))
                {
                    testContext.Monitor.WriteGlobalLog("ERROR:\n");
                    testContext.Monitor.WriteGlobalLog(et);
                }
                testContext.Monitor.ReportRuntimeError("Test execution failed.\n" + ot + "\n" + et, ex);
                return(UnitTestResult.CreateIgnored("Test execution failed"));
            } finally {
                File.Delete(outFile);
            }
        }
Ejemplo n.º 10
0
        UnitTestResult RunWithConsoleRunner(ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var          outFile = Path.GetTempFileName();
            LocalConsole cons    = new LocalConsole();

            try {
                LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

                if (!string.IsNullOrEmpty(cmd.Arguments))
                {
                    cmd.Arguments += " ";
                }
                cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath;

                bool automaticUpdates = cmd.Command.Contains("GuiUnit") || (cmd.Command.Contains("mdtool.exe") && cmd.Arguments.Contains("run-md-tests"));
                if (!string.IsNullOrEmpty(testName))
                {
                    cmd.Arguments += " -run=" + suiteName + "." + testName;
                }
                else if (!string.IsNullOrEmpty(suiteName))
                {
                    cmd.Arguments += " -run=" + suiteName;
                }
                if (automaticUpdates)
                {
                    var tcpListener = new MonoDevelop.NUnit.External.TcpTestListener(localMonitor, suiteName);
                    cmd.Arguments += " -port=" + tcpListener.Port;
                }
                var p = testContext.ExecutionContext.Execute(cmd, cons);

                testContext.Monitor.CancelRequested += p.Cancel;
                if (testContext.Monitor.IsCancelRequested)
                {
                    p.Cancel();
                }
                p.WaitForCompleted();

                if (new FileInfo(outFile).Length == 0)
                {
                    throw new Exception("Command failed");
                }

                if (automaticUpdates)
                {
                    if (testName != null)
                    {
                        return(localMonitor.SingleTestResult);
                    }
                    return(test.GetLastResult());
                }

                XDocument doc = XDocument.Load(outFile);

                if (doc.Root != null)
                {
                    var root = doc.Root.Elements("test-suite").FirstOrDefault();
                    if (root != null)
                    {
                        cons.SetDone();
                        var ot = cons.Out.ReadToEnd();
                        var et = cons.Error.ReadToEnd();
                        testContext.Monitor.WriteGlobalLog(ot);
                        if (!string.IsNullOrEmpty(et))
                        {
                            testContext.Monitor.WriteGlobalLog("ERROR:\n");
                            testContext.Monitor.WriteGlobalLog(et);
                        }

                        bool macunitStyle = doc.Root.Element("environment") != null && doc.Root.Element("environment").Attribute("macunit-version") != null;
                        var  result       = ReportXmlResult(localMonitor, root, "", macunitStyle);
                        if (testName != null)
                        {
                            result = localMonitor.SingleTestResult;
                        }
                        return(result);
                    }
                }
                throw new Exception("Test results could not be parsed.");
            } catch (Exception ex) {
                cons.SetDone();
                var ot = cons.Out.ReadToEnd();
                var et = cons.Error.ReadToEnd();
                testContext.Monitor.WriteGlobalLog(ot);
                if (!string.IsNullOrEmpty(et))
                {
                    testContext.Monitor.WriteGlobalLog("ERROR:\n");
                    testContext.Monitor.WriteGlobalLog(et);
                }
                testContext.Monitor.ReportRuntimeError("Test execution failed.\n" + ot + "\n" + et, ex);
                return(UnitTestResult.CreateIgnored("Test execution failed"));
            } finally {
                File.Delete(outFile);
            }
        }
        UnitTestResult RunWithConsoleRunner(ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var outFile               = Path.GetTempFileName();
            var xmlOutputConsole      = new LocalConsole();
            var appDebugOutputConsole = testContext.ExecutionContext.ConsoleFactory.CreateConsole(
                OperationConsoleFactory.CreateConsoleOptions.Default.WithTitle(GettextCatalog.GetString("Unit Tests")));
            OperationConsole cons;

            if (appDebugOutputConsole != null)
            {
                cons = new MultipleOperationConsoles(appDebugOutputConsole, xmlOutputConsole);
            }
            else
            {
                cons = xmlOutputConsole;
            }
            try {
                MonoDevelop.UnitTesting.NUnit.External.TcpTestListener tcpListener = null;
                LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

                if (!string.IsNullOrEmpty(cmd.Arguments))
                {
                    cmd.Arguments += " ";
                }
                cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath;

                bool automaticUpdates = cmd.Command != null && (cmd.Command.Contains("GuiUnit") || (cmd.Command.Contains("mdtool.exe") && cmd.Arguments.Contains("run-md-tests")));
                if (!string.IsNullOrEmpty(pathName))
                {
                    cmd.Arguments += " -run=\"" + test.TestId.Replace("\"", "\\\"") + "\"";
                }
                if (automaticUpdates)
                {
                    tcpListener    = new MonoDevelop.UnitTesting.NUnit.External.TcpTestListener(localMonitor, suiteName);
                    cmd.Arguments += " -port=" + tcpListener.Port;
                }
                cmd.WorkingDirectory = Path.GetDirectoryName(AssemblyPath);

                // Note that we always dispose the tcp listener as we don't want it listening
                // forever if the test runner does not try to connect to it
                using (tcpListener) {
                    var handler = testContext.ExecutionContext.ExecutionHandler;

                    if (handler == null)
                    {
                        handler = Runtime.ProcessService.DefaultExecutionHandler;
                    }

                    var p = handler.Execute(cmd, cons);
                    using (testContext.Monitor.CancellationToken.Register(p.Cancel))
                        p.Task.Wait();

                    if (new FileInfo(outFile).Length == 0)
                    {
                        throw new Exception("Command failed");
                    }
                }

                // mdtool.exe does not necessarily guarantee we get automatic updates. It just guarantees
                // that if guiunit is being used then it will give us updates. If you have a regular test
                // assembly compiled against nunit.framework.dll
                if (automaticUpdates && tcpListener.HasReceivedConnection)
                {
                    if (testName != null)
                    {
                        return(localMonitor.SingleTestResult);
                    }
                    return(test.GetLastResult());
                }

                XDocument doc = XDocument.Load(outFile);

                if (doc.Root != null)
                {
                    var root = doc.Root.Elements("test-suite").FirstOrDefault();
                    if (root != null)
                    {
                        xmlOutputConsole.SetDone();
                        var ot = xmlOutputConsole.OutReader.ReadToEnd();
                        var et = xmlOutputConsole.ErrorReader.ReadToEnd();
                        testContext.Monitor.WriteGlobalLog(ot);
                        if (!string.IsNullOrEmpty(et))
                        {
                            testContext.Monitor.WriteGlobalLog("ERROR:\n");
                            testContext.Monitor.WriteGlobalLog(et);
                        }

                        bool macunitStyle = doc.Root.Element("environment") != null && doc.Root.Element("environment").Attribute("macunit-version") != null;
                        var  result       = ReportXmlResult(localMonitor, root, "", macunitStyle);
                        if (testName != null)
                        {
                            result = localMonitor.SingleTestResult;
                        }
                        return(result);
                    }
                }
                throw new Exception("Test results could not be parsed.");
            } catch (Exception ex) {
                xmlOutputConsole.SetDone();
                var ot = xmlOutputConsole.OutReader.ReadToEnd();
                var et = xmlOutputConsole.ErrorReader.ReadToEnd();
                testContext.Monitor.WriteGlobalLog(ot);
                if (!string.IsNullOrEmpty(et))
                {
                    testContext.Monitor.WriteGlobalLog("ERROR:\n");
                    testContext.Monitor.WriteGlobalLog(et);
                }
                testContext.Monitor.ReportRuntimeError("Test execution failed.\n" + ot + "\n" + et, ex);
                return(UnitTestResult.CreateIgnored("Test execution failed"));
            } finally {
                File.Delete(outFile);
                cons.Dispose();
            }
        }
Ejemplo n.º 12
0
        private static ExecutionCommand CreateExecutionCommand(HaxeProject project, HaxeProjectConfiguration configuration)
        {
            string hxmlPath = Path.GetFullPath(project.TargetHXMLFile);

            if (!File.Exists(hxmlPath))
            {
                hxmlPath = Path.Combine(project.BaseDirectory, project.TargetHXMLFile);
            }

            string hxml = File.ReadAllText(hxmlPath);

            hxml = hxml.Replace(Environment.NewLine, " ");
            string[] hxmlArgs = hxml.Split(' ');

            List <string> platforms       = new List <string> ();
            List <string> platformOutputs = new List <string> ();

            bool   addNext    = false;
            bool   nextIsMain = false;
            string main       = "";

            foreach (string hxmlArg in hxmlArgs)
            {
                if (addNext)
                {
                    if (!hxmlArg.StartsWith("-"))
                    {
                        if (nextIsMain)
                        {
                            main       = hxmlArg;
                            nextIsMain = false;
                        }
                        else
                        {
                            platformOutputs.Add(hxmlArg);
                        }
                    }
                    else
                    {
                        if (!nextIsMain)
                        {
                            platforms.RemoveAt(platforms.Count - 1);
                        }
                    }
                }

                addNext = true;

                switch (hxmlArg)
                {
                case "-cpp":
                    platforms.Add("cpp");
                    break;

                case "-swf":
                case "-swf9":
                    platforms.Add("flash");
                    break;

                case "-js":
                    platforms.Add("js");
                    break;

                case "-neko":
                    platforms.Add("neko");
                    break;

                case "-php":
                    platforms.Add("php");
                    break;

                case "-main":
                    nextIsMain = true;
                    break;

                default:
                    addNext = false;
                    break;
                }
            }


            int i = 0;

            //for (int i = 0; i < platforms.Count; i++)
            //{
            string platform = platforms[i];
            string output   = platformOutputs[i];

            if (platform == "cpp" || platform == "neko")
            {
                if (platform == "cpp")
                {
                    output = Path.Combine(output, main);
                    if (configuration.DebugMode)
                    {
                        output += "-debug";
                    }
                }

                if (!File.Exists(Path.GetFullPath(output)))
                {
                    output = Path.Combine(project.BaseDirectory, output);
                }

                string exe  = "";
                string args = "";

                if (platform == "cpp")
                {
                    exe = output;
                }
                else
                {
                    exe  = "neko";
                    args = "\"" + output + "\"";
                }

                //NativeExecutionCommand cmd = new NativeExecutionCommand (exe);
                HaxeExecutionCommand cmd = new HaxeExecutionCommand(exe);
                cmd.Arguments        = args;
                cmd.WorkingDirectory = Path.GetDirectoryName(output);

                if (configuration.DebugMode)
                {
                    //	cmd.EnvironmentVariables.Add ("HXCPP_DEBUG_HOST", "gdb");
                    cmd.EnvironmentVariables.Add("HXCPP_DEBUG", "1");
                }
                //cmd.WorkingDirectory = project.BaseDirectory.FullPath;

                //MonoDevelop.Ide.MessageService.ShowMessage (cmd.Command);
                //MonoDevelop.Ide.MessageService.ShowMessage (cmd.Arguments);
                //MonoDevelop.Ide.MessageService.ShowMessage (cmd.WorkingDirectory);

                return(cmd);
            }
            else if (platform == "flash" || platform == "js")
            {
                if (!File.Exists(Path.GetFullPath(output)))
                {
                    output = Path.Combine(project.BaseDirectory, output);
                }

                if (platform == "js")
                {
                    output = Path.Combine(Path.GetDirectoryName(output), "index.html");
                }

                //string target = output;

                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.MacOSX:
                    //target = "open \"" + output + "\"";
                    break;

                case PlatformID.Unix:
                    //target = "xdg-open \"" + output + "\"";
                    break;
                }

                ProcessExecutionCommand cmd = new ProcessExecutionCommand();
                cmd.Command = output;
                return(cmd);
            }
            //}

            return(null);
        }
Ejemplo n.º 13
0
        public void Execute(IProgressMonitor monitor, IWorkspaceObject entry, ExecutionContext context, ConfigurationSelector configuration)
        {
            if (string.IsNullOrEmpty(command))
            {
                return;
            }

            StringTagModel tagSource = GetTagModel(entry, configuration);

            string exe, args;

            ParseCommand(tagSource, out exe, out args);

            monitor.Log.WriteLine(GettextCatalog.GetString("Executing: {0} {1}", exe, args));

            FilePath dir = GetCommandWorkingDir(entry, configuration);

            FilePath localPath = entry.BaseDirectory.Combine(exe);

            if (File.Exists(localPath))
            {
                exe = localPath;
            }

            IProcessAsyncOperation oper;

            try {
                if (context != null)
                {
                    IConsole console;
                    if (externalConsole)
                    {
                        console = context.ExternalConsoleFactory.CreateConsole(!pauseExternalConsole);
                    }
                    else
                    {
                        console = context.ConsoleFactory.CreateConsole(!pauseExternalConsole);
                    }

                    ExecutionCommand        cmd  = Runtime.ProcessService.CreateCommand(exe);
                    ProcessExecutionCommand pcmd = cmd as ProcessExecutionCommand;
                    if (pcmd != null)
                    {
                        pcmd.Arguments        = args;
                        pcmd.WorkingDirectory = dir;
                    }
                    oper = context.ExecutionHandler.Execute(cmd, console);
                }
                else
                {
                    if (externalConsole)
                    {
                        IConsole console = ExternalConsoleFactory.Instance.CreateConsole(!pauseExternalConsole);
                        oper = Runtime.ProcessService.StartConsoleProcess(exe, args, dir, console, null);
                    }
                    else
                    {
                        oper = Runtime.ProcessService.StartProcess(exe, args, dir, monitor.Log, monitor.Log, null, false);
                    }
                }
            } catch (Exception ex) {
                throw new UserException(GettextCatalog.GetString("Command execution failed: {0}", ex.Message));
            }

            monitor.CancelRequested += delegate {
                if (!oper.IsCompleted)
                {
                    oper.Cancel();
                }
            };

            oper.WaitForCompleted();
            if (!oper.Success)
            {
                monitor.ReportError("Custom command failed (exit code: " + oper.ExitCode + ")", null);
                monitor.AsyncOperation.Cancel();
            }
        }
Ejemplo n.º 14
0
        public void Execute(IProgressMonitor monitor, IWorkspaceObject entry, ExecutionContext context, ConfigurationSelector configuration)
        {
            StringTagModel tagSource;

            if (entry is SolutionItem)
            {
                tagSource = ((SolutionItem)entry).GetStringTagModel(configuration);
            }
            else if (entry is WorkspaceItem)
            {
                tagSource = ((WorkspaceItem)entry).GetStringTagModel();
            }
            else
            {
                tagSource = new StringTagModel();
            }

            if (string.IsNullOrEmpty(command))
            {
                return;
            }

            int    i = command.IndexOf(' ');
            string exe;
            string args = string.Empty;

            if (i == -1)
            {
                exe  = command;
                args = string.Empty;
            }
            else
            {
                exe  = command.Substring(0, i);
                args = StringParserService.Parse(command.Substring(i + 1), tagSource);
            }

            monitor.Log.WriteLine(GettextCatalog.GetString("Executing: {0} {1}", exe, args));

            FilePath dir = (string.IsNullOrEmpty(workingdir) ? entry.BaseDirectory : (FilePath)StringParserService.Parse(workingdir, tagSource));

            FilePath localPath = entry.BaseDirectory.Combine(exe);

            if (File.Exists(localPath))
            {
                exe = localPath;
            }

            IProcessAsyncOperation oper;

            if (context != null)
            {
                IConsole console;
                if (externalConsole)
                {
                    console = context.ExternalConsoleFactory.CreateConsole(!pauseExternalConsole);
                }
                else
                {
                    console = context.ConsoleFactory.CreateConsole(!pauseExternalConsole);
                }

                ExecutionCommand        cmd  = Runtime.ProcessService.CreateCommand(exe);
                ProcessExecutionCommand pcmd = cmd as ProcessExecutionCommand;
                if (pcmd != null)
                {
                    pcmd.Arguments        = args;
                    pcmd.WorkingDirectory = dir;
                }
                oper = context.ExecutionHandler.Execute(cmd, console);
            }
            else
            {
                if (externalConsole)
                {
                    IConsole console = ExternalConsoleFactory.Instance.CreateConsole(!pauseExternalConsole);
                    oper = Runtime.ProcessService.StartConsoleProcess(exe, args, dir, console, null);
                }
                else
                {
                    oper = Runtime.ProcessService.StartProcess(exe, args, dir, monitor.Log, monitor.Log, null, false);
                }
            }

            monitor.CancelRequested += delegate {
                if (!oper.IsCompleted)
                {
                    oper.Cancel();
                }
            };

            oper.WaitForCompleted();
            if (!oper.Success)
            {
                monitor.ReportError("Custom command failed (exit code: " + oper.ExitCode + ")", null);
                monitor.AsyncOperation.Cancel();
            }
        }