internal protected override bool SupportsObject(WorkspaceObject item)
 {
     return(item is Project && base.SupportsObject(item));
 }
Exemple #2
0
        public async Task BuildSessionBeginEnd()
        {
            var en  = new CustomSolutionItemNode <TestBuildSolutionExtension> ();
            var en2 = new CustomSolutionItemNode <TestBuildSolutionItemExtension> ();

            WorkspaceObject.RegisterCustomExtension(en);
            WorkspaceObject.RegisterCustomExtension(en2);

            int beginCount = 0, endCount = 0, projectBuildCount = 0, msbuildBeginCount = 0, msbuildEndCount = 0;

            TestBuildSolutionExtension.BeginBuildCalled = delegate {
                beginCount++;
            };

            TestBuildSolutionExtension.EndBuildCalled = delegate {
                endCount++;
            };

            TestBuildSolutionItemExtension.BuildCalled = delegate {
                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(0, endCount);
                projectBuildCount++;
            };

            // This logger is used to verify that the BuildStarted event is raised only once per
            // build, which means only one build session is started.

            var customLogger = new MSBuildLogger();

            customLogger.EnabledEvents = MSBuildEvent.BuildStarted | MSBuildEvent.BuildFinished;
            customLogger.EventRaised  += (sender, e) => {
                if (e.Event == MSBuildEvent.BuildStarted)
                {
                    msbuildBeginCount++;
                }
                else if (e.Event == MSBuildEvent.BuildFinished)
                {
                    msbuildEndCount++;
                }
            };

            var oldPrefParallelBuild  = Runtime.Preferences.ParallelBuild.Value;
            var oldPrefSkipUnmodified = Runtime.Preferences.SkipBuildingUnmodifiedProjects.Value;

            try {
                Runtime.Preferences.ParallelBuild.Set(false);
                Runtime.Preferences.SkipBuildingUnmodifiedProjects.Set(false);
                FilePath solFile = Util.GetSampleProject("build-session", "build-session.sln");
                var      sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

                Assert.AreEqual(0, beginCount);
                Assert.AreEqual(0, endCount);
                Assert.AreEqual(0, projectBuildCount);
                Assert.AreEqual(0, msbuildBeginCount);
                Assert.AreEqual(0, msbuildEndCount);

                // Test building the whole solution

                var context = new TargetEvaluationContext();
                context.Loggers.Add(customLogger);
                var res = await sol.Build(Util.GetMonitor(), "Debug", context);

                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(1, endCount);
                Assert.AreEqual(3, projectBuildCount);
                Assert.AreEqual(1, msbuildBeginCount);
                Assert.AreEqual(1, msbuildEndCount);

                // Test building a solution folder

                beginCount = endCount = projectBuildCount = msbuildBeginCount = msbuildEndCount = 0;

                var folder = (SolutionFolder)sol.RootFolder.Items.FirstOrDefault(i => i.Name == "libraries");

                context = new TargetEvaluationContext();
                context.Loggers.Add(customLogger);
                res = await folder.Build(Util.GetMonitor(), sol.Configurations["Debug|x86"].Selector, operationContext : context);

                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(1, endCount);
                Assert.AreEqual(2, projectBuildCount);
                Assert.AreEqual(1, msbuildBeginCount);
                Assert.AreEqual(1, msbuildEndCount);

                // Test building a specific item and dependencies

                beginCount = endCount = projectBuildCount = msbuildBeginCount = msbuildEndCount = 0;

                var item = (SolutionItem)sol.RootFolder.Items.FirstOrDefault(i => i.Name == "build-session");

                context = new TargetEvaluationContext();
                context.Loggers.Add(customLogger);
                res = await item.Build(Util.GetMonitor(), sol.Configurations ["Debug|x86"].Selector, true, context);

                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(1, endCount);
                Assert.AreEqual(3, projectBuildCount);
                Assert.AreEqual(1, msbuildBeginCount);
                Assert.AreEqual(1, msbuildEndCount);

                // Test building a specific item but not its dependencies

                beginCount = endCount = projectBuildCount = msbuildBeginCount = msbuildEndCount = 0;

                context = new TargetEvaluationContext();
                context.Loggers.Add(customLogger);
                res = await item.Build(Util.GetMonitor(), sol.Configurations ["Debug|x86"].Selector, false, context);

                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(1, endCount);
                Assert.AreEqual(1, projectBuildCount);
                Assert.AreEqual(1, msbuildBeginCount);
                Assert.AreEqual(1, msbuildEndCount);

                sol.Dispose();
            } finally {
                TestBuildSolutionExtension.BeginBuildCalled = null;
                TestBuildSolutionExtension.EndBuildCalled   = null;
                TestBuildSolutionItemExtension.BuildCalled  = null;

                WorkspaceObject.UnregisterCustomExtension(en);
                WorkspaceObject.UnregisterCustomExtension(en2);

                Runtime.Preferences.ParallelBuild.Set(oldPrefParallelBuild);
                Runtime.Preferences.SkipBuildingUnmodifiedProjects.Set(oldPrefSkipUnmodified);
            }
        }
Exemple #3
0
 public static T As <T> (this WorkspaceObject ob) where T : class
 {
     return(ob != null?ob.GetService <T> () : null);
 }
 internal protected override bool SupportsObject(WorkspaceObject item)
 {
     return(base.SupportsObject(item) && (item is DotNetProject));
 }
        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 = context.ExternalConsoleFactory.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;
                    }
                }

                var stopper = monitor.CancellationToken.Register(oper.Cancel);

                await oper.Task;

                stopper.Dispose();

                if (oper.ExitCode != 0)
                {
                    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(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);
        }
 public Task <bool> Execute(ProgressMonitor monitor, WorkspaceObject entry, ConfigurationSelector configuration)
 {
     return(Execute(monitor, entry, null, configuration));
 }
Exemple #7
0
 public virtual bool ContainsItem(WorkspaceObject obj)
 {
     return(this == obj);
 }