예제 #1
0
        public int Execute(Execution execution)
        {
            if (Directory.Exists("Build"))
            {
                using (var writer = new StreamWriter(Path.Combine("Build", "GenerateProject.CSharp.xslt")))
                {
                    ResourceExtractor.GetTransparentDecompressionStream(
                        Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("GenerateProject.CSharp.xslt.lzma"))
                    .CopyTo(writer.BaseStream);
                    writer.Flush();
                }
                using (var writer = new StreamWriter(Path.Combine("Build", "GenerateProject.CPlusPlus.VisualStudio.xslt")))
                {
                    ResourceExtractor.GetTransparentDecompressionStream(
                        Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("GenerateProject.CPlusPlus.VisualStudio.xslt.lzma"))
                    .CopyTo(writer.BaseStream);
                    writer.Flush();
                }
                using (var writer = new StreamWriter(Path.Combine("Build", "GenerateProject.CPlusPlus.MonoDevelop.xslt")))
                {
                    ResourceExtractor.GetTransparentDecompressionStream(
                        Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("GenerateProject.CPlusPlus.MonoDevelop.xslt.lzma"))
                    .CopyTo(writer.BaseStream);
                    writer.Flush();
                }
                using (var writer = new StreamWriter(Path.Combine("Build", "GenerateSolution.xslt")))
                {
                    ResourceExtractor.GetTransparentDecompressionStream(
                        Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("GenerateSolution.xslt.lzma"))
                    .CopyTo(writer.BaseStream);
                    writer.Flush();
                }
                using (var writer = new StreamWriter(Path.Combine("Build", "GenerationFunctions.cs")))
                {
                    ResourceExtractor.GetTransparentDecompressionStream(
                        Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("GenerationFunctions.cs.lzma"))
                    .CopyTo(writer.BaseStream);
                    writer.Flush();
                }
                using (var writer = new StreamWriter(Path.Combine("Build", "SelectSolution.xslt")))
                {
                    ResourceExtractor.GetTransparentDecompressionStream(
                        Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("SelectSolution.xslt.lzma"))
                    .CopyTo(writer.BaseStream);
                    writer.Flush();
                }
            }

            return(0);
        }
예제 #2
0
        public override void CreateFiles(string name, string projectRoot)
        {
            var buildFolder = Path.Combine(projectRoot, "Build");

            if (!Directory.Exists(buildFolder))
            {
                Directory.CreateDirectory(buildFolder);
            }
            if (projectRoot != Environment.CurrentDirectory)
            {
                File.Copy(Assembly.GetExecutingAssembly().Location,
                          Path.Combine(projectRoot, "Protobuild.exe"));
            }
            ResourceExtractor.ExtractAll(buildFolder, name);
        }
예제 #3
0
        public int Execute(Execution execution)
        {
            if (!File.Exists(Path.Combine("Build", "Module.xml")))
            {
                Directory.CreateDirectory("Build");
                ResourceExtractor.ExtractAll(Path.Combine(Environment.CurrentDirectory, "Build"), "MyProject");
                Console.WriteLine("Build" + Path.DirectorySeparatorChar + "Module.xml has been created.");
                ExecEnvironment.Exit(0);
            }

            return(this.m_ActionDispatch.DefaultAction(
                       ModuleInfo.Load(Path.Combine("Build", "Module.xml")),
                       enabledServices: execution.EnabledServices.ToArray(),
                       disabledServices: execution.DisabledServices.ToArray(),
                       serviceSpecPath: execution.ServiceSpecificationPath) ? 0 : 1);
        }
예제 #4
0
        public static void Main(string[] args)
        {
            Application.Init();

            MainWindow win = new MainWindow();

            // Detect if there is a Build directory in the local folder.  If not,
            // prompt to create a new module.
            if (!Directory.Exists("Build"))
            {
                var confirm = new MessageDialog(
                    win,
                    DialogFlags.Modal,
                    MessageType.Question,
                    ButtonsType.YesNo,
                    false,
                    "The current directory is not a Protobuild module.  Would " +
                    "you like to turn this directory into a module?");
                var result = (ResponseType)confirm.Run();
                if (result == ResponseType.No)
                {
                    // We can't run the module manager if the current directory
                    // isn't actually a module!
                    confirm.Destroy();
                    win.Destroy();
                    return;
                }
                confirm.Destroy();

                var create = new CreateProjectDialog(win, "Module", true);
                create.Modal = true;
                if ((ResponseType)create.Run() != ResponseType.Ok)
                {
                    create.Destroy();
                    win.Destroy();
                    return;
                }
                string error;
                if (!win.CreateProject(create.ProjectName, "Module", out error, true))
                {
                    var errorDialog = new MessageDialog(
                        win,
                        DialogFlags.Modal,
                        MessageType.Error,
                        ButtonsType.Ok,
                        "Unable to create module: " + error);
                    errorDialog.Run();
                    errorDialog.Destroy();
                    create.Destroy();
                    win.Destroy();
                    return;
                }
                Directory.CreateDirectory("Build");
                ResourceExtractor.ExtractAll(Path.Combine(
                                                 Environment.CurrentDirectory,
                                                 "Build"), create.ProjectName);
                create.Destroy();
            }

            // Load the module.
            win.Module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
            win.InitializeToolbar();
            win.Update();

            win.Show();
            Application.Run();
        }
        public XmlDocument Generate(
            List <XmlDocument> definitions,
            string rootPath,
            string projectName,
            string platformName,
            string packagesPath,
            IEnumerable <XmlElement> properties,
            List <Service> services)
        {
            var doc = new XmlDocument();

            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null));
            var input = doc.CreateElement("Input");

            doc.AppendChild(input);

            input.AppendChild(this.m_ServiceInputGenerator.Generate(doc, projectName, services));

            var generation      = doc.CreateElement("Generation");
            var projectNameNode = doc.CreateElement("ProjectName");

            projectNameNode.AppendChild(doc.CreateTextNode(projectName));
            var platformNameNode = doc.CreateElement("Platform");

            platformNameNode.AppendChild(doc.CreateTextNode(platformName));
            var hostPlatformName = doc.CreateElement("HostPlatform");

            hostPlatformName.AppendChild(doc.CreateTextNode(this.m_HostPlatformDetector.DetectPlatform()));

            if (string.Compare(platformName, "Web", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                // Add JSIL properties
                string jsilDirectory, jsilCompilerFile;
                if (!this.m_JSILProvider.GetJSIL(out jsilDirectory, out jsilCompilerFile))
                {
                    throw new InvalidOperationException("JSIL not found, but previous check passed.");
                }

                var jsilDirectoryNode = doc.CreateElement("JSILDirectory");
                jsilDirectoryNode.AppendChild(doc.CreateTextNode(jsilDirectory));
                generation.AppendChild(jsilDirectoryNode);
                var jsilCompilerPathNode = doc.CreateElement("JSILCompilerFile");
                jsilCompilerPathNode.AppendChild(doc.CreateTextNode(jsilCompilerFile));
                generation.AppendChild(jsilCompilerPathNode);

                var jsilLibrariesNode = doc.CreateElement("JSILLibraries");

                foreach (var entry in this.m_JSILProvider.GetJSILLibraries())
                {
                    var entryNode     = doc.CreateElement("Library");
                    var pathAttribute = doc.CreateAttribute("Path");
                    pathAttribute.Value = entry.Key;
                    var nameAttribute = doc.CreateAttribute("Name");
                    nameAttribute.Value = entry.Value;
                    entryNode.Attributes.Append(pathAttribute);
                    entryNode.Attributes.Append(nameAttribute);
                    jsilLibrariesNode.AppendChild(entryNode);
                }

                generation.AppendChild(jsilLibrariesNode);

                // Automatically extract the JSIL template if not already present.
                var currentProject =
                    definitions.Select(x => x.DocumentElement)
                    .Where(x => x.Attributes != null)
                    .Where(x => x.Attributes["Name"] != null)
                    .FirstOrDefault(x => x.Attributes["Name"].Value == projectName);
                if (currentProject != null)
                {
                    string type = null;
                    string path = null;
                    if (currentProject.Attributes != null && currentProject.Attributes["Type"] != null)
                    {
                        type = currentProject.Attributes["Type"].Value;
                    }
                    if (currentProject.Attributes != null && currentProject.Attributes["Path"] != null)
                    {
                        path = currentProject.Attributes["Path"].Value;
                    }

                    if (string.Compare(type, "App", StringComparison.InvariantCultureIgnoreCase) == 0 ||
                        string.Compare(type, "Console", StringComparison.InvariantCultureIgnoreCase) == 0 ||
                        string.Compare(type, "GUI", StringComparison.InvariantCultureIgnoreCase) == 0 ||
                        string.Compare(type, "GTK", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        if (path != null)
                        {
                            var srcDir = Path.Combine(rootPath, path);
                            if (Directory.Exists(srcDir))
                            {
                                if (!File.Exists(Path.Combine(srcDir, "index.htm")))
                                {
                                    Console.WriteLine("Extracting JSIL HTML template...");
                                    ResourceExtractor.ExtractJSILTemplate(projectName, Path.Combine(srcDir, "index.htm"));
                                }
                            }
                        }
                    }
                }
            }

            var rootName = doc.CreateElement("RootPath");

            rootName.AppendChild(doc.CreateTextNode(
                                     new DirectoryInfo(rootPath).FullName));
            generation.AppendChild(projectNameNode);
            generation.AppendChild(platformNameNode);
            generation.AppendChild(hostPlatformName);
            generation.AppendChild(rootName);
            input.AppendChild(generation);

            var propertiesNode = doc.CreateElement("Properties");

            foreach (var property in properties)
            {
                if (property.Name.ToLower() == "property")
                {
                    var nodeName = doc.CreateElement(property.GetAttribute("Name"));
                    nodeName.AppendChild(doc.CreateTextNode(
                                             property.GetAttribute("Value")));
                    propertiesNode.AppendChild(nodeName);
                }
                else
                {
                    propertiesNode.AppendChild(
                        doc.ImportNode(property, true));
                }
            }
            input.AppendChild(propertiesNode);

            var featuresNode = doc.CreateElement("Features");

            foreach (var feature in _featureManager.GetAllEnabledFeatures())
            {
                var featureNode = doc.CreateElement(feature.ToString());
                featureNode.AppendChild(doc.CreateTextNode("True"));
                featuresNode.AppendChild(featureNode);
            }
            input.AppendChild(featuresNode);

            var nuget = doc.CreateElement("NuGet");

            input.AppendChild(nuget);

            var projects = doc.CreateElement("Projects");

            input.AppendChild(projects);
            foreach (var projectDoc in definitions)
            {
                var importedProject = this.m_ServiceReferenceTranslator.TranslateProjectWithServiceReferences(
                    doc.ImportNode(projectDoc.DocumentElement, true),
                    services);

                // Convert <Property> tags in projects other than the one we're currently
                // generating, so that we can lookup properties in other projects in the XSLT.
                var importedProjectProperties = importedProject.ChildNodes
                                                .OfType <XmlElement>()
                                                .FirstOrDefault(x => x.Name.ToLower() == "properties");
                if (importedProjectProperties != null)
                {
                    var existingProperties = importedProjectProperties.ChildNodes
                                             .OfType <XmlElement>().ToList();
                    foreach (var property in existingProperties)
                    {
                        if (property.Name.ToLower() == "property")
                        {
                            if (property.GetAttribute("Name") == null)
                            {
                                throw new Exception(
                                          "A property is missing the Name attribute in the '" +
                                          projectDoc.DocumentElement.GetAttribute("Name") +
                                          "' project.");
                            }

                            var nodeName = doc.CreateElement(property.GetAttribute("Name"));
                            nodeName.AppendChild(doc.CreateTextNode(
                                                     property.GetAttribute("Value")));
                            importedProjectProperties.AppendChild(nodeName);
                        }
                    }
                }

                projects.AppendChild(importedProject);
            }

            // Also check if there are NuGet packages.config file for
            // this project and if there is, include all of the relevant
            // NuGet package information for referencing the correct DLLs.
            if (File.Exists(packagesPath))
            {
                this.m_NuGetReferenceDetector.ApplyNuGetReferences(
                    rootPath,
                    packagesPath,
                    doc,
                    nuget);
            }

            return(doc);
        }
예제 #6
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")));
            }
        }