示例#1
0
        public static void Main(string[] args)
        {
            // Ensure we always use the invariant culture in Protobuild.
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var kernel = new LightweightKernel();
            kernel.BindCore();
            kernel.BindBuildResources();
            kernel.BindGeneration();
            kernel.BindJSIL();
            kernel.BindTargets();
            kernel.BindFileFilter();
            kernel.BindPackages();

            var commandMappings = new Dictionary<string, ICommand>
            {
                { "sync", kernel.Get<SyncCommand>() },
                { "resync", kernel.Get<ResyncCommand>() },
                { "generate", kernel.Get<GenerateCommand>() },
                { "clean", kernel.Get<CleanCommand>() },
                { "extract-xslt", kernel.Get<ExtractXSLTCommand>() },
                { "enable", kernel.Get<EnableServiceCommand>() },
                { "disable", kernel.Get<DisableServiceCommand>() },
                { "spec", kernel.Get<ServiceSpecificationCommand>() },
                { "add", kernel.Get<AddPackageCommand>() },
                { "pack", kernel.Get<PackPackageCommand>() },
                { "format", kernel.Get<FormatPackageCommand>() },
                { "push", kernel.Get<PushPackageCommand>() },
                { "resolve", kernel.Get<ResolveCommand>() },
                { "swap-to-source", kernel.Get<SwapToSourceCommand>() },
                { "swap-to-binary", kernel.Get<SwapToBinaryCommand>() },
                { "start", kernel.Get<StartCommand>() },
            };

            var execution = new Execution();
            execution.CommandToExecute = kernel.Get<DefaultCommand>();

            var options = new Options();
            foreach (var kv in commandMappings)
            {
                var key = kv.Key;
                var value = kv.Value;

                if (value.GetArgCount() == 0)
                {
                    options[key] = x => { value.Encounter(execution, x); };
                }
                else
                {
                    options[key + "@" + value.GetArgCount()] = x => { value.Encounter(execution, x); };
                }
            }

            Action<string[]> helpAction = x =>
            {
                PrintHelp(commandMappings);
                Environment.Exit(0);
            };
            options["help"] = helpAction;
            options["?"] = helpAction;

            try
            {
                options.Parse(args);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
                PrintHelp(commandMappings);
                Environment.Exit(1);
            }

            try
            {
                var exitCode = execution.CommandToExecute.Execute(execution);
                Environment.Exit(exitCode);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Environment.Exit(1);
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            // Ensure we always use the invariant culture in Protobuild.
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // Set our SSL trust policy.  Because Mono doesn't ship with root certificates
            // on most Linux distributions, we have to be a little more insecure here than
            // I'd like.  For protobuild.org we always verify that the root of the certificate
            // chain matches what we expect (so people can't forge a certificate from a
            // *different CA*), but for other domains we just have to implicitly trust them
            // on Linux since we have no root store.
            if (Path.DirectorySeparatorChar == '/' && !Directory.Exists("/Library"))
            {
                ServicePointManager.ServerCertificateValidationCallback = SSLValidationForLinux;
            }

            var kernel = new LightweightKernel();
            kernel.BindCore();
            kernel.BindBuildResources();
            kernel.BindGeneration();
            kernel.BindJSIL();
            kernel.BindTargets();
            kernel.BindFileFilter();
            kernel.BindPackages();
            kernel.BindAutomatedBuild();

            var featureManager = kernel.Get<IFeatureManager>();
            featureManager.LoadFeaturesForCurrentDirectory();

            var commandMappings = new Dictionary<string, ICommand>
            {
                { "sync", kernel.Get<SyncCommand>() },
                { "resync", kernel.Get<ResyncCommand>() },
                { "generate", kernel.Get<GenerateCommand>() },
                { "build", kernel.Get<BuildCommand>() },
                { "build-target", kernel.Get<BuildTargetCommand>() },
                { "build-property", kernel.Get<BuildPropertyCommand>() },
                { "build-process-arch", kernel.Get<BuildProcessArchCommand>() },
                { "clean", kernel.Get<CleanCommand>() },
                { "automated-build", kernel.Get<AutomatedBuildCommand>() },
                { "extract-xslt", kernel.Get<ExtractXSLTCommand>() },
                { "enable", kernel.Get<EnableServiceCommand>() },
                { "disable", kernel.Get<DisableServiceCommand>() },
                { "debug-service-resolution", kernel.Get<DebugServiceResolutionCommand>() },
                { "simulate-host-platform", kernel.Get<SimulateHostPlatformCommand>() },
                { "spec", kernel.Get<ServiceSpecificationCommand>() },
                { "query-features", kernel.Get<QueryFeaturesCommand>() },
                { "features", kernel.Get<FeaturesCommand>() },
                { "add", kernel.Get<AddPackageCommand>() },
                { "list", kernel.Get<ListPackagesCommand>() },
                { "install", kernel.Get<InstallPackageCommand>() },
                { "upgrade", kernel.Get<UpgradePackageCommand>() },
                { "upgrade-all", kernel.Get<UpgradeAllPackagesCommand>() },
                { "pack", kernel.Get<PackPackageCommand>() },
                { "format", kernel.Get<FormatPackageCommand>() },
                { "push", kernel.Get<PushPackageCommand>() },
                { "ignore-on-existing", kernel.Get<IgnoreOnExistingPackageCommand>() },
                { "repush", kernel.Get<RepushPackageCommand>() },
                { "resolve", kernel.Get<ResolveCommand>() },
                { "no-resolve", kernel.Get<NoResolveCommand>() },
                { "redirect", kernel.Get<RedirectPackageCommand>() },
                { "swap-to-source", kernel.Get<SwapToSourceCommand>() },
                { "swap-to-binary", kernel.Get<SwapToBinaryCommand>() },
                { "start", kernel.Get<StartCommand>() },
                { "no-generate", kernel.Get<NoGenerateCommand>() },
                { "no-host-generate", kernel.Get<NoHostGenerateCommand>() },
                { "execute", kernel.Get<ExecuteCommand>() },
                { "execute-configuration", kernel.Get<ExecuteConfigurationCommand>() },
            };

            var execution = new Execution();
            execution.CommandToExecute = kernel.Get<DefaultCommand>();

            var options = new Options();
            foreach (var kv in commandMappings)
            {
                var key = kv.Key;
                var value = kv.Value;

                Action<string[]> handle = x =>
                {
                    if (value.IsRecognised())
                    {
                        value.Encounter(execution, x);
                    }
                    else if (value.IsIgnored())
                    {
                    }
                    else
                    {
                        throw new InvalidOperationException("Unknown argument '" + key + "'");
                    }
                };

                if (value.GetArgCount() == 0)
                {
                    options[key] = handle;
                }
                else
                {
                    options[key + "@" + value.GetArgCount()] = handle;
                }
            }

            Action<string[]> helpAction = x =>
            {
                PrintHelp(commandMappings);
                ExecEnvironment.Exit(0);
            };
            options["help"] = helpAction;
            options["?"] = helpAction;

            if (ExecEnvironment.DoNotWrapExecutionInTry)
            {
                options.Parse(args);
            }
            else
            {
                try
                {
                    options.Parse(args);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                    PrintHelp(commandMappings);
                    ExecEnvironment.Exit(1);
                }
            }

            featureManager.ValidateEnabledFeatures();

            if (ExecEnvironment.DoNotWrapExecutionInTry)
            {
                var exitCode = execution.CommandToExecute.Execute(execution);
                ExecEnvironment.Exit(exitCode);
            }
            else
            {
                try
                {
                    var exitCode = execution.CommandToExecute.Execute(execution);
                    ExecEnvironment.Exit(exitCode);
                }
                catch (ExecEnvironment.SelfInvokeExitException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    ExecEnvironment.Exit(1);
                }
            }
        }
示例#3
0
        public static void Main(string[] args)
        {
            var needToExit = false;
            var runModuleManager = false;
            int exitCode = 0;
            var options = new Options();
            options["extract-xslt"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    using (var writer = new StreamWriter(Path.Combine("Build", "GenerateProject.xslt")))
                    {
                        ResourceExtractor.GetTransparentDecompressionStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(
                            "Protobuild.BuildResources.GenerateProject.xslt.gz")).CopyTo(writer.BaseStream);
                        writer.Flush();
                    }
                    using (var writer = new StreamWriter(Path.Combine("Build", "GenerateSolution.xslt")))
                    {
                        ResourceExtractor.GetTransparentDecompressionStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(
                            "Protobuild.BuildResources.GenerateSolution.xslt.gz")).CopyTo(writer.BaseStream);
                        writer.Flush();
                    }
                    needToExit = true;
                }
            };
            options["sync@1"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
                    exitCode = Actions.SyncProjects(module, x.Length > 0 ? x[0] : null) ? 0 : 1;
                    needToExit = true;
                }
            };
            options["resync@1"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
                    exitCode = Actions.ResyncProjects(module, x.Length > 0 ? x[0] : null) ? 0 : 1;
                    needToExit = true;
                }
            };
            options["generate@1"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
                    exitCode = Actions.GenerateProjects(module, x.Length > 0 ? x[0] : null) ? 0 : 1;
                    needToExit = true;
                }
            };
            options["clean@1"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
                    exitCode = Actions.CleanProjects(module, x.Length > 0 ? x[0] : null) ? 0 : 1;
                    needToExit = true;
                }
            };
            options["compress@1"] = x =>
            {
                var file = x.Length > 0 ? x[0] : null;
                if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
                {
                    Console.Error.WriteLine("File not found for compression.");
                    exitCode = 1;
                    needToExit = true;
                    return;
                }

                using (var reader = new FileStream(file, FileMode.Open, FileAccess.Read))
                {
                    using (var writer = new FileStream(file + ".gz", FileMode.Create, FileAccess.Write))
                    {
                        using (var gzip = new GZipStream(writer, CompressionMode.Compress, true))
                        {
                            reader.CopyTo(gzip);
                        }
                    }
                }

                Console.WriteLine(file + " compressed as " + file + ".gz");
                exitCode = 0;
                needToExit = true;
            };
            options["manager-gui"] = x =>
            {
                runModuleManager = true;
            };
            Action<string[]> helpAction = x =>
            {
                Console.WriteLine("Protobuild.exe [-extract-xslt] [-extract-proj] [-sync] [-resync] [-generate]");
                Console.WriteLine();
                Console.WriteLine("By default Protobuild does resynchronises or generates projects for");
                Console.WriteLine("the current platform.  To start a graphical interface for managing project");
                Console.WriteLine("definitions, use the -manager-gui option.");
                Console.WriteLine();
                Console.WriteLine("  -manager-gui");
                Console.WriteLine();
                Console.WriteLine("  Starts the module manager GUI.  You will need to have a graphical");
                Console.WriteLine("  system present in order to use this option; otherwise Protobuild will");
                Console.WriteLine("  operate as a console application (safe for headless operation).");
                Console.WriteLine();
                Console.WriteLine("  -extract-xslt");
                Console.WriteLine();
                Console.WriteLine("  Extracts the XSLT templates to the Build\\ folder.  When present, these");
                Console.WriteLine("  are used over the built-in versions.  This allows you to customize");
                Console.WriteLine("  and extend the project / solution generation to support additional");
                Console.WriteLine("  features.");
                Console.WriteLine();
                Console.WriteLine("  -extract-util");
                Console.WriteLine();
                Console.WriteLine("  Extracts utilities again to the Build\\ folder.  This is");
                Console.WriteLine("  useful if you the utilities have been deleted from the Build\\");
                Console.WriteLine("  folder and you need to get them back.");
                Console.WriteLine();
                Console.WriteLine("  -sync <platform>");
                Console.WriteLine();
                Console.WriteLine("  Synchronises the changes in the C# project files back to the");
                Console.WriteLine("  definitions, but does not regenerate the projects.  If no");
                Console.WriteLine("  platform is specified, synchronises for the current platform.");
                Console.WriteLine();
                Console.WriteLine("  -resync <platform>");
                Console.WriteLine();
                Console.WriteLine("  Synchronises the changes in the C# project files back to the");
                Console.WriteLine("  definitions and then regenerates the projects again.  If no");
                Console.WriteLine("  platform is specified, resynchronises for the current platform.");
                Console.WriteLine();
                Console.WriteLine("  -generate <platform>");
                Console.WriteLine();
                Console.WriteLine("  Generates the C# project files from the definitions.  If no");
                Console.WriteLine("  platform is specified, generates for the current platform.");
                Console.WriteLine();
                Console.WriteLine("  -clean <platform>");
                Console.WriteLine();
                Console.WriteLine("  Removes all generated C# project and solution files.  If no");
                Console.WriteLine("  platform is specified, cleans for the current platform.");
                Console.WriteLine();
                needToExit = true;
            };
            options["help"] = helpAction;
            options["?"] = helpAction;

            try
            {
                options.Parse(args);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
                helpAction(new string[0]);
                needToExit = true;
                exitCode = 1;
            }

            if (needToExit)
            {
                Environment.Exit(exitCode);
                return;
            }

            if (!File.Exists(Path.Combine("Build", "Module.xml")))
            {
                try
                {
                    // We use Windows Forms here to prompt the user on what to do.
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    var form = new KickstartForm();
                    var result = form.ShowDialog();
                    switch (result)
                    {
                        case DialogResult.Yes:
                            RunModuleManager();
                            return;
                        case DialogResult.No:
                            Directory.CreateDirectory("Build");
                            ResourceExtractor.ExtractAll(Path.Combine(Environment.CurrentDirectory, "Build"), "MyProject");
                            MessageBox.Show("Build" + Path.DirectorySeparatorChar + "Module.xml has been created.");
                            Environment.Exit(0);
                            break;
                        default:
                            Environment.Exit(1);
                            break;
                    }
                }
                catch (Exception)
                {
                    // We might be on a platform that isn't running a graphical interface
                    // or we can't otherwise show a dialog to the user.  Output to the
                    // console to let them know what's going on.
                    Console.WriteLine("The current directory does not appear to be a Protobuild module.  Please either create ");
                    Console.WriteLine("the Module.xml file manually, or run 'Protobuild.exe --manager-gui' to be guided through ");
                    Console.WriteLine("the process of creating a new module.");
                    Environment.Exit(1);
                }
            }

            if (runModuleManager)
                RunModuleManager();
            else
                Actions.DefaultAction(ModuleInfo.Load(Path.Combine("Build", "Module.xml")));
        }
示例#4
0
        public static void Main(string[] args)
        {
            var needToExit = false;
            var runModuleManager = false;
            int exitCode = 0;
            var options = new Options();
            options["extract-xslt"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    using (var writer = new StreamWriter(Path.Combine("Build", "GenerateProject.xslt")))
                    {
                        Assembly.GetExecutingAssembly().GetManifestResourceStream(
                            "Protobuild.BuildResources.GenerateProject.xslt").CopyTo(writer.BaseStream);
                        writer.Flush();
                    }
                    using (var writer = new StreamWriter(Path.Combine("Build", "GenerateSolution.xslt")))
                    {
                        Assembly.GetExecutingAssembly().GetManifestResourceStream(
                            "Protobuild.BuildResources.GenerateSolution.xslt").CopyTo(writer.BaseStream);
                        writer.Flush();
                    }
                    needToExit = true;
                }
            };
            options["extract-util"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    ResourceExtractor.ExtractUtilities(Path.Combine(Environment.CurrentDirectory, "Build"));
                    needToExit = true;
                }
            };
            options["sync@1"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
                    exitCode = Actions.SyncProjects(module, x.Length > 0 ? x[0] : null) ? 0 : 1;
                    needToExit = true;
                }
            };
            options["resync@1"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
                    exitCode = Actions.ResyncProjects(module, x.Length > 0 ? x[0] : null) ? 0 : 1;
                    needToExit = true;
                }
            };
            options["generate@1"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
                    exitCode = Actions.GenerateProjects(module, x.Length > 0 ? x[0] : null) ? 0 : 1;
                    needToExit = true;
                }
            };
            options["clean@1"] = x =>
            {
                if (Directory.Exists("Build"))
                {
                    var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
                    exitCode = Actions.CleanProjects(module, x.Length > 0 ? x[0] : null) ? 0 : 1;
                    needToExit = true;
                }
            };
            options["manager-gui"] = x =>
            {
                runModuleManager = true;
            };
            options["help"] = x =>
            {
                Console.WriteLine("Protobuild.exe [-extract-xslt] [-extract-proj] [-sync] [-resync] [-generate]");
                Console.WriteLine();
                Console.WriteLine("By default Protobuild does resynchronises or generates projects for");
                Console.WriteLine("the current platform.  To start a graphical interface for managing project");
                Console.WriteLine("definitions, use the -manager-gui option.");
                Console.WriteLine();
                Console.WriteLine("  -manager-gui");
                Console.WriteLine();
                Console.WriteLine("  Starts the module manager GUI.  You will need to have a graphical");
                Console.WriteLine("  system present in order to use this option; otherwise Protobuild will");
                Console.WriteLine("  operate as a console application (safe for headless operation).");
                Console.WriteLine();
                Console.WriteLine("  -extract-xslt");
                Console.WriteLine();
                Console.WriteLine("  Extracts the XSLT templates to the Build\\ folder.  When present, these");
                Console.WriteLine("  are used over the built-in versions.  This allows you to customize");
                Console.WriteLine("  and extend the project / solution generation to support additional");
                Console.WriteLine("  features.");
                Console.WriteLine();
                Console.WriteLine("  -extract-util");
                Console.WriteLine();
                Console.WriteLine("  Extracts utilities again to the Build\\ folder.  This is");
                Console.WriteLine("  useful if you the utilities have been deleted from the Build\\");
                Console.WriteLine("  folder and you need to get them back.");
                Console.WriteLine();
                Console.WriteLine("  -sync <platform>");
                Console.WriteLine();
                Console.WriteLine("  Synchronises the changes in the C# project files back to the");
                Console.WriteLine("  definitions, but does not regenerate the projects.  If no");
                Console.WriteLine("  platform is specified, synchronises for the current platform.");
                Console.WriteLine();
                Console.WriteLine("  -resync <platform>");
                Console.WriteLine();
                Console.WriteLine("  Synchronises the changes in the C# project files back to the");
                Console.WriteLine("  definitions and then regenerates the projects again.  If no");
                Console.WriteLine("  platform is specified, resynchronises for the current platform.");
                Console.WriteLine();
                Console.WriteLine("  -generate <platform>");
                Console.WriteLine();
                Console.WriteLine("  Generates the C# project files from the definitions.  If no");
                Console.WriteLine("  platform is specified, generates for the current platform.");
                Console.WriteLine();
                Console.WriteLine("  -clean <platform>");
                Console.WriteLine();
                Console.WriteLine("  Removes all generated C# project and solution files.  If no");
                Console.WriteLine("  platform is specified, cleans for the current platform.");
                Console.WriteLine();
                needToExit = true;
            };
            options.Parse(args);
            if (needToExit)
            {
                Environment.Exit(exitCode);
                return;
            }

            if (runModuleManager)
                RunModuleManager();
            else
                Actions.ResyncProjects(ModuleInfo.Load(Path.Combine("Build", "Module.xml")));
        }