Example #1
0
        public static int Execute <T>(Expression <Func <T, Target> > defaultTargetExpression)
            where T : NukeBuild
        {
            var executionList = default(IReadOnlyCollection <TargetDefinition>);
            var build         = CreateBuildInstance(defaultTargetExpression);

            try
            {
                build.OnBuildCreated();

                Logger.OutputSink = build.OutputSink;
                Logger.LogLevel   = build.LogLevel;
                NuGetPackageResolver.DefaultPackagesConfigFile = build.PackagesConfigFile;

                Logger.Log(FigletTransform.GetText("NUKE"));
                Logger.Log($"Version: {typeof(BuildExecutor).GetTypeInfo().Assembly.GetInformationalText()}");
                Logger.Log($"Host: {build.Host}");
                Logger.Log();

                ProcessManager.CheckPathEnvironmentVariable();
                InjectionService.InjectValues(build);
                HandleEarlyExits(build);

                executionList = TargetDefinitionLoader.GetExecutingTargets(build, build.InvokedTargets);
                RequirementService.ValidateRequirements(executionList, build);

                build.OnBuildInitialized();

                Execute(build, executionList);

                return(0);
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
                return(-1);
            }
            finally
            {
                if (Logger.OutputSink is SevereMessagesOutputSink outputSink)
                {
                    Logger.Log();
                    WriteWarningsAndErrors(outputSink);
                }

                if (executionList != null)
                {
                    Logger.Log();
                    WriteSummary(executionList);
                }

                build.OnBuildFinished();
            }
        }
Example #2
0
        public static int Execute <T>(Expression <Func <T, Target> > defaultTargetExpression)
            where T : NukeBuild
        {
            Logger.Log(FigletTransform.GetText("NUKE"));
            Logger.Log($"Version: {typeof(BuildExecutor).GetTypeInfo().Assembly.GetVersionText()}");
            Logger.Log($"Host: {EnvironmentInfo.HostType}");
            Logger.Log();

            var executionList = default(IReadOnlyCollection <TargetDefinition>);

            try
            {
                var build = CreateBuildInstance(defaultTargetExpression);
                InjectionService.InjectValues(build);
                HandleEarlyExits(build);

                executionList = TargetDefinitionLoader.GetExecutingTargets(build);
                RequirementService.ValidateRequirements(executionList, build);
                Execute(executionList);

                return(0);
            }
            catch (AggregateException exception)
            {
                foreach (var innerException in exception.Flatten().InnerExceptions)
                {
                    OutputSink.Error(innerException.Message, innerException.StackTrace);
                }
                return(-exception.Message.GetHashCode());
            }
            catch (TargetInvocationException exception)
            {
                var innerException = exception.InnerException.NotNull();
                OutputSink.Error(innerException.Message, innerException.StackTrace);
                return(-exception.Message.GetHashCode());
            }
            catch (Exception exception)
            {
                OutputSink.Error(exception.Message, exception.StackTrace);
                return(-exception.Message.GetHashCode());
            }
            finally
            {
                if (executionList != null)
                {
                    OutputSink.WriteSummary(executionList);
                }
            }
        }