Ejemplo n.º 1
0
        private int RunBuild(ICollection <string> args, TargetTree targetTree)
        {
            if (targetTree == null)
            {
                throw new ArgumentNullException("targetTree");
            }

            using (TaskSession session = new TaskSession(new SimpleTaskContextProperties(), args, targetTree))
            {
                session.IsInteractive = InteractiveSessionDetectionFunc();

                BuildTargets.FillDefaultProperties(session);
                session.Start(BuildTargets.OnBuildFinished);

                session.AddLogger(new MulticoloredConsoleLogger(Console.Out));

                ConfigureBuildProperties(session);
                bool   targetFoundInTargetTree;
                string targetToRun = ParseCmdLineArgs(args.ToList(), session, targetTree, out targetFoundInTargetTree);

                if (targetToRun == null)
                {
                    ITarget defaultTarget = targetTree.DefaultTarget;
                    if (defaultTarget == null)
                    {
                        throw new InvalidOperationException("The default build target is not defined");
                    }

                    targetTree.RunTarget(session, defaultTarget.TargetName);
                }
                else
                {
                    if (!targetFoundInTargetTree)
                    {
                        session.WriteError("ERROR: The specified target does not exist");
                        targetTree.RunTarget(session, targetToRun);
                        return(2);
                    }

                    targetTree.RunTarget(session, targetToRun);
                }

                session.Complete();

                return(0);
            }
        }
Ejemplo n.º 2
0
        public int Run(ICollection <string> args)
        {
            try
            {
                if (args == null)
                {
                    throw new ArgumentNullException("args");
                }

                TargetTree targetTree = new TargetTree();
                BuildTargets.FillBuildTargets(targetTree);

                ConfigureTargets(targetTree, args);

                return(RunBuild(args, targetTree));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(1);
            }
        }