예제 #1
0
        private static IReadOnlyCollection <TargetDefinition> Setup <T> (Expression <Func <T, Target> > defaultTargetExpression)
            where T : NukeBuild
        {
            var build = (T)FormatterServices.GetUninitializedObject(typeof(T));

            NukeBuild.Instance = build;

            var constructors = typeof(T).GetConstructors();

            ControlFlow.Assert(constructors.Length == 1 && constructors.Single().GetParameters().Length == 0,
                               $"Type '{typeof(T).Name}' must declare a single parameterless constructor.");
            constructors.Single().Invoke(build, new object[0]);

            PrintLogo();

            InjectionService.InjectValues(build);
            OutputSink.Instance = OutputSink.GetOutputSink(build.Host);

            Logger.Log();
            //{
            //    Console.WriteLine($"Target: {build.Target.Join(", ")}");
            //    Console.WriteLine($"Verbosity: {build.Verbosity}");
            //    Console.WriteLine($"LogLevel: {build.LogLevel}");
            //    Console.WriteLine($"NoDependencies: {build.NoDependencies}");
            //    Console.WriteLine($"Configuration: {build.Configuration}");
            //}

            var defaultTargetFactory = defaultTargetExpression.Compile().Invoke(build);

            if (build.Help != null)
            {
                if (build.Help.Length == 0 || build.Help.Any(x => "targets".StartsWithOrdinalIgnoreCase(x)))
                {
                    Logger.Log(GetTargetsText(build, defaultTargetFactory));
                }
                if (build.Help.Length == 0 || build.Help.Any(x => "parameters".StartsWithOrdinalIgnoreCase(x)))
                {
                    Logger.Log(GetParametersText(build, defaultTargetFactory));
                }
            }

            if (build.Graph)
            {
                ShowGraph(build, defaultTargetFactory);
            }

            if (build.Help != null || build.Graph)
            {
                Environment.Exit(exitCode: 0);
            }

            var executionList = TargetDefinitionLoader.GetExecutionList(build, defaultTargetFactory);

            RequirementService.ValidateRequirements(executionList, build);
            return(executionList);
        }
예제 #2
0
        private static T CreateBuildInstance <T>(Expression <Func <T, Target> > defaultTargetExpression)
            where T : NukeBuild
        {
            var constructors = typeof(T).GetConstructors();

            ControlFlow.Assert(constructors.Length == 1 && constructors.Single().GetParameters().Length == 0,
                               $"Type '{typeof(T).Name}' must declare a single parameterless constructor.");

            var build = Activator.CreateInstance <T>();

            build.TargetDefinitions = build.GetTargetDefinitions(defaultTargetExpression);
            NukeBuild.Instance      = build;

            InjectionService.InjectValues(build);

            return(build);
        }
예제 #3
0
        private static IReadOnlyCollection <TargetDefinition> Setup <T> (Expression <Func <T, Target> > defaultTargetExpression)
            where T : NukeBuild
        {
            var build = Activator.CreateInstance <T>();
            var defaultTargetFactory = defaultTargetExpression.Compile().Invoke(build);

            InjectionService.InjectValues(build);

            //{
            //    Console.WriteLine($"Target: {build.Target.Join(", ")}");
            //    Console.WriteLine($"Verbosity: {build.Verbosity}");
            //    Console.WriteLine($"LogLevel: {build.LogLevel}");
            //    Console.WriteLine($"NoDependencies: {build.NoDependencies}");
            //    Console.WriteLine($"Configuration: {build.Configuration}");
            //}

            PrintLogo();

            if (build.Help != null)
            {
                if (build.Help.Length == 0 || build.Help.Any(x => "targets".StartsWithOrdinalIgnoreCase(x)))
                {
                    Logger.Log(GetTargetsText(build, defaultTargetFactory));
                }
                if (build.Help.Length == 0 || build.Help.Any(x => "parameters".StartsWithOrdinalIgnoreCase(x)))
                {
                    Logger.Log(GetParametersText(build));
                }
                Environment.Exit(exitCode: 0);
            }

            var executionList = TargetDefinitionLoader.GetExecutionList(build, defaultTargetFactory);

            RequirementService.ValidateRequirements(executionList, build);
            return(executionList);
        }