Beispiel #1
0
 void ParseCommand(StringTagModel tagSource, out string cmd, out string args)
 {
     if (command.Length > 0 && command [0] == '"')
     {
         int n = command.IndexOf('"', 1);
         if (n != -1)
         {
             cmd  = command.Substring(1, n - 1);
             args = command.Substring(n + 1).Trim();
         }
         else
         {
             cmd  = command;
             args = string.Empty;
         }
     }
     else
     {
         int i = command.IndexOf(' ');
         if (i != -1)
         {
             cmd  = command.Substring(0, i);
             args = command.Substring(i + 1).Trim();
         }
         else
         {
             cmd  = command;
             args = string.Empty;
         }
     }
     cmd  = StringParserService.Parse(cmd, tagSource);
     args = StringParserService.Parse(args, tagSource);
 }
        protected virtual StringTagModel OnGetStringTagModel(ConfigurationSelector conf)
        {
            var m = new StringTagModel();

            m.Add(this);
            return(m);
        }
Beispiel #3
0
        public virtual StringTagModel GetStringTagModel()
        {
            StringTagModel source = new StringTagModel();

            source.Add(this);
            return(source);
        }
Beispiel #4
0
        public string GetCommandArgs(IWorkspaceObject entry, ConfigurationSelector configuration)
        {
            string         exe, args;
            StringTagModel tagSource = GetTagModel(entry, configuration);

            ParseCommand(tagSource, out exe, out args);
            return(args);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        protected override StringTagModel OnGetStringTagModel(ConfigurationSelector conf)
        {
            StringTagModel source = base.OnGetStringTagModel(conf);

            if (ParentSolution != null)
            {
                source.Add(ParentSolution.GetStringTagModel());
            }
            return(source);
        }
Beispiel #7
0
        public bool CanExecute(IWorkspaceObject entry, ExecutionContext context, ConfigurationSelector configuration)
        {
            string         exe, args;
            StringTagModel tagSource = GetTagModel(entry, configuration);

            ParseCommand(tagSource, out exe, out args);
            ExecutionCommand cmd = Runtime.ProcessService.CreateCommand(exe);

            return(context == null || context.ExecutionHandler.CanExecute(cmd));
        }
Beispiel #8
0
        public void TestNonStringFormatFunctions()
        {
            var model = new StringTagModel();

            model.Add(this);

            using (new TemporaryRegistration(new DateTimeStringTagProvider())) {
                Assert.AreEqual(StringParserService.Parse("${FIXEDTIME:d}", model), DateTimeStringTagProvider.Value.ToString("d"));
            }
        }
        public override StringTagModel GetStringTagModel(ConfigurationSelector conf)
        {
            StringTagModel            source = base.GetStringTagModel(conf);
            SolutionItemConfiguration config = GetConfiguration(conf);

            if (config != null)
            {
                source.Add(config);
            }
            return(source);
        }
Beispiel #10
0
        /// <summary>
        /// Gets the string tag model for this solution item
        /// </summary>
        /// <returns>
        /// The string tag model
        /// </returns>
        /// <param name='conf'>
        /// Configuration for which to get the string tag model
        /// </param>
        public virtual StringTagModel GetStringTagModel(ConfigurationSelector conf)
        {
            StringTagModel source = new StringTagModel();

            source.Add(this);
            if (ParentSolution != null)
            {
                source.Add(ParentSolution.GetStringTagModel());
            }
            return(source);
        }
Beispiel #11
0
        public FilePath GetCommandWorkingDir(IWorkspaceObject entry, ConfigurationSelector configuration)
        {
            StringTagModel tagSource = GetTagModel(entry, configuration);

            if (string.IsNullOrEmpty(workingdir))
            {
                return(entry.BaseDirectory);
            }
            FilePath dir = StringParserService.Parse(workingdir, tagSource);

            return(dir.ToAbsolute(entry.BaseDirectory));
        }
Beispiel #12
0
        public StringTagModel GetStringTagModel()
        {
            StringTagModel source = new StringTagModel();

            source.Add(this);
            if (IdeApp.ProjectOperations.CurrentSelectedSolutionItem != null)
            {
                source.Add(IdeApp.ProjectOperations.CurrentSelectedSolutionItem.GetStringTagModel(IdeApp.Workspace.ActiveConfiguration));
            }
            else if (IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem != null)
            {
                source.Add(IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.GetStringTagModel());
            }
            return(source);
        }
Beispiel #13
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);
        }
Beispiel #14
0
        public void TestFormatFunctions()
        {
            var model = new StringTagModel();

            model.Add(this);

            using (new TemporaryRegistration(new UnencodedValueStringTagProvider())) {
                // Custom tag models
                Assert.AreEqual("Mono &amp; .NET", StringParserService.Parse("${UNENCODEDVALUE:HtmlEncode}", model));
                Assert.AreEqual("mono & .net", StringParserService.Parse("${UNENCODEDVALUE:lower}", model));
                Assert.AreEqual("MONO & .NET", StringParserService.Parse("${UNENCODEDVALUE:UPPER}", model));

                // Built-in string generators
                Assert.That(StringParserService.Parse("${YEAR:F4}", model), Is.StringEnding("0000"));
            }
        }
        public Dictionary <string, string> GetParsedEnvironmentVariables()
        {
            if (ParentItem == null)
            {
                return(environmentVariables);
            }

            StringTagModel tagSource         = ParentItem.GetStringTagModel(Selector);
            Dictionary <string, string> vars = new Dictionary <string, string> ();

            foreach (var v in environmentVariables)
            {
                vars [v.Key] = StringParserService.Parse(v.Value, tagSource);
            }
            return(vars);
        }
Beispiel #16
0
        public FilePath GetCommandWorkingDir(IWorkspaceObject entry, ConfigurationSelector configuration)
        {
            StringTagModel tagSource = GetTagModel(entry, configuration);

            return(string.IsNullOrEmpty(workingdir) ? entry.BaseDirectory : (FilePath)StringParserService.Parse(workingdir, tagSource));
        }
Beispiel #17
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();
            }
        }
Beispiel #18
0
 void ParseCommand(StringTagModel tagSource, out string cmd, out string args)
 {
     ParseCommand(out cmd, out args);
     cmd  = StringParserService.Parse(cmd, tagSource);
     args = StringParserService.Parse(args, tagSource);
 }
Beispiel #19
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();
            }
        }