public void Autopackage(
            FileFilter fileFilter,
            Execution execution,
            ModuleInfo module,
            string rootPath,
            string platform)
        {
            var definitions    = module.GetDefinitionsRecursively(platform).ToArray();
            var loadedProjects = new List <XmlDocument>();

            foreach (var definition in definitions)
            {
                Console.WriteLine("Loading: " + definition.Name);
                loadedProjects.Add(
                    this.m_ProjectLoader.Load(
                        Path.Combine(
                            definition.ModulePath,
                            "Build",
                            "Projects",
                            definition.Name + ".definition"),
                        platform,
                        module.Path,
                        definition.ModulePath));
            }

            var            serviceManager = new ServiceManager(platform);
            List <Service> services;

            serviceManager.SetRootDefinitions(module.GetDefinitions());

            var enabledServices  = execution.EnabledServices.ToArray();
            var disabledServices = execution.DisabledServices.ToArray();

            foreach (var service in enabledServices)
            {
                serviceManager.EnableService(service);
            }

            foreach (var service in disabledServices)
            {
                serviceManager.DisableService(service);
            }

            services = serviceManager.CalculateDependencyGraph(loadedProjects);

            foreach (var service in services)
            {
                if (service.ServiceName != null)
                {
                    Console.WriteLine("Enabled service: " + service.FullName);
                }
            }

            foreach (var definition in definitions)
            {
                if (definition.SkipAutopackage)
                {
                    Console.WriteLine("Skipping: " + definition.Name);
                    continue;
                }

                switch (definition.Type)
                {
                case "External":
                    Console.WriteLine("Packaging: " + definition.Name);
                    this.AutomaticallyPackageExternalProject(definitions, services, fileFilter, rootPath, platform, definition);
                    break;

                case "Content":
                    Console.WriteLine("Content project definition skipped: " + definition.Name);
                    break;

                default:
                    Console.WriteLine("Packaging: " + definition.Name);
                    this.AutomaticallyPackageNormalProject(definitions, services, fileFilter, rootPath, platform, definition);
                    break;
                }
            }

            // If there is no Module.xml in the source mappings already, then copy the current module.
            var filterDictionary = fileFilter.ToDictionary(k => k.Key, v => v.Value);

            if (!filterDictionary.ContainsValue("Build/Module.xml"))
            {
                fileFilter.AddManualMapping(Path.Combine(module.Path, "Build", "Module.xml"), "Build/Module.xml");
            }
        }
예제 #2
0
        public int Execute(Execution execution)
        {
            if (!Directory.Exists(execution.PackageSourceFolder))
            {
                throw new InvalidOperationException("The source folder " + execution.PackageSourceFolder + " does not exist.");
            }

            var        allowAutopackage   = true;
            var        moduleExpectedPath = Path.Combine(execution.PackageSourceFolder, "Build", "Module.xml");
            ModuleInfo rootModule         = null;

            if (!File.Exists(moduleExpectedPath))
            {
                if (execution.PackageFilterFile == null)
                {
                    Console.WriteLine(
                        "There is no module in the path '" + execution.PackageSourceFolder + "' (expected to " +
                        "find a Build\\Module.xml file within that directory).");
                    return(1);
                }
                else
                {
                    // We allow this mode if the user has provided a filter file and are constructing
                    // the package manually.
                    allowAutopackage = false;
                }
            }
            else
            {
                rootModule = ModuleInfo.Load(moduleExpectedPath);
            }

            var customDirectives = new Dictionary <string, Action <FileFilter> >()
            {
                {
                    "autopackage",
                    f =>
                    {
                        if (allowAutopackage && rootModule != null)
                        {
                            this.m_AutomaticProjectPackager.Autopackage(
                                f,
                                execution,
                                rootModule,
                                execution.PackageSourceFolder,
                                execution.PackagePlatform);
                        }
                        else
                        {
                            Console.WriteLine(
                                "WARNING: There is no module in the path '" + execution.PackageSourceFolder + "' (expected to " +
                                "find a Build\\Module.xml file within that directory).  Ignoring the 'autopackage' directive.");
                        }
                    }
                }
            };

            Console.WriteLine("Starting package creation for " + execution.PackagePlatform);

            var filter = new FileFilter(GetRecursiveFilesInPath(execution.PackageSourceFolder));

            if (execution.PackageFilterFile != null)
            {
                using (var reader = new StreamReader(execution.PackageFilterFile))
                {
                    var contents = reader.ReadToEnd();
                    contents = contents.Replace("%PLATFORM%", execution.PackagePlatform);

                    using (var inputStream = new MemoryStream(Encoding.ASCII.GetBytes(contents)))
                    {
                        this.m_FileFilterParser.ParseAndApply(filter, inputStream, customDirectives);
                    }
                }
            }
            else
            {
                customDirectives["autopackage"](filter);
            }

            if (File.Exists(execution.PackageDestinationFile))
            {
                Console.WriteLine("The destination file " + execution.PackageDestinationFile + " already exists; it will be overwritten.");
                File.Delete(execution.PackageDestinationFile);
            }

            filter.ImplyDirectories();

            var filterDictionary = filter.ToDictionary(k => k.Key, v => v.Value);

            if (!filterDictionary.ContainsValue("Build/"))
            {
                Console.WriteLine("ERROR: The Build directory does not exist in the source folder.");
                if (execution.PackageFilterFile != null)
                {
                    this.PrintFilterMappings(filterDictionary);
                }
                return(1);
            }

            if (!filterDictionary.ContainsValue("Build/Projects/"))
            {
                Console.WriteLine("ERROR: The Build\\Projects directory does not exist in the source folder.");
                if (execution.PackageFilterFile != null)
                {
                    this.PrintFilterMappings(filterDictionary);
                }
                return(1);
            }

            if (!filterDictionary.ContainsValue("Build/Module.xml"))
            {
                Console.WriteLine("ERROR: The Build\\Module.xml file does not exist in the source folder.");
                if (execution.PackageFilterFile != null)
                {
                    this.PrintFilterMappings(filterDictionary);
                }
                return(1);
            }

            if (filterDictionary.ContainsValue("Protobuild.exe"))
            {
                Console.WriteLine("ERROR: The Protobuild.exe file should not be included in the package file.");
                if (execution.PackageFilterFile != null)
                {
                    this.PrintFilterMappings(filterDictionary);
                }
                return(1);
            }

            using (var target = new FileStream(execution.PackageDestinationFile, FileMode.CreateNew, FileAccess.Write, FileShare.None))
            {
                var archive = new MemoryStream();

                switch (execution.PackageFormat)
                {
                case PackageManager.ARCHIVE_FORMAT_TAR_GZIP:
                {
                    Console.WriteLine("Writing package in tar/gzip format...");
                    break;
                }

                case PackageManager.ARCHIVE_FORMAT_TAR_LZMA:
                default:
                {
                    Console.WriteLine("Writing package in tar/lzma format...");
                    break;
                }
                }

                switch (execution.PackageFormat)
                {
                case PackageManager.ARCHIVE_FORMAT_TAR_GZIP:
                case PackageManager.ARCHIVE_FORMAT_TAR_LZMA:
                default:
                {
                    var state = this.m_Deduplicator.CreateState();

                    Console.Write("Deduplicating files in package...");

                    var progressHelper = new DedupProgressRenderer(filter.Count());
                    var current        = 0;

                    foreach (var kv in filter.OrderBy(kv => kv.Value))
                    {
                        if (kv.Value.EndsWith("/"))
                        {
                            // Directory
                            this.m_Deduplicator.AddDirectory(state, kv.Value);
                        }
                        else
                        {
                            // File
                            var realFile     = Path.Combine(execution.PackageSourceFolder, kv.Key);
                            var realFileInfo = new FileInfo(realFile);

                            this.m_Deduplicator.AddFile(state, realFileInfo, kv.Value);
                        }

                        current++;

                        progressHelper.SetProgress(current);
                    }

                    Console.WriteLine();
                    Console.WriteLine("Adding files to package...");

                    using (var writer = new tar_cs.TarWriter(archive))
                    {
                        this.m_Deduplicator.PushToTar(state, writer);
                    }

                    break;
                }
                }

                archive.Seek(0, SeekOrigin.Begin);

                switch (execution.PackageFormat)
                {
                case PackageManager.ARCHIVE_FORMAT_TAR_GZIP:
                {
                    Console.WriteLine("Compressing package...");

                    using (var compress = new GZipStream(target, CompressionMode.Compress))
                    {
                        archive.CopyTo(compress);
                    }

                    break;
                }

                case PackageManager.ARCHIVE_FORMAT_TAR_LZMA:
                default:
                {
                    Console.Write("Compressing package...");

                    var progressHelper = new CompressProgressRenderer(archive.Length);

                    LZMA.LzmaHelper.Compress(archive, target, progressHelper);

                    Console.WriteLine();

                    break;
                }
                }
            }

            Console.WriteLine("\rPackage written to " + execution.PackageDestinationFile + " successfully.");
            return(0);
        }
예제 #3
0
        public int ExecuteForTemplate(Execution execution)
        {
            if (!Directory.Exists(execution.PackageSourceFolder))
            {
                throw new InvalidOperationException("The source folder " + execution.PackageSourceFolder + " does not exist.");
            }

            RedirectableConsole.WriteLine("Starting package creation for " + execution.PackagePlatform);

            var filter = new FileFilter(_getRecursiveUtilitiesInPath.GetRecursiveFilesInPath(execution.PackageSourceFolder));

            if (execution.PackageFilterFile != null)
            {
                using (var reader = new StreamReader(execution.PackageFilterFile))
                {
                    var contents = reader.ReadToEnd();
                    contents = contents.Replace("%PLATFORM%", execution.PackagePlatform);

                    using (var inputStream = new MemoryStream(Encoding.ASCII.GetBytes(contents)))
                    {
                        this.m_FileFilterParser.ParseAndApply(filter, inputStream, new Dictionary <string, Action <FileFilter> >());
                    }
                }
            }
            else
            {
                filter.ApplyInclude("^.*$");
                filter.ApplyExclude("^\\.git/.*$");
                filter.ApplyExclude("^\\.hg/.*$");
                filter.ApplyExclude("^\\.svn/.*$");
            }

            if (File.Exists(execution.PackageDestinationFile))
            {
                RedirectableConsole.WriteLine("The destination file " + execution.PackageDestinationFile + " already exists; it will be overwritten.");
                File.Delete(execution.PackageDestinationFile);
            }

            filter.ImplyDirectories();

            var filterDictionary = filter.ToDictionary(k => k.Key, v => v.Value);

            if (!filter.ContainsTargetPath("Build/"))
            {
                RedirectableConsole.WriteLine("ERROR: The Build directory does not exist in the source folder.");
                if (execution.PackageFilterFile != null)
                {
                    this.PrintFilterMappings(filter);
                }
                return(1);
            }

            if (!filter.ContainsTargetPath("Build/Projects/"))
            {
                RedirectableConsole.WriteLine("ERROR: The Build\\Projects directory does not exist in the source folder.");
                if (execution.PackageFilterFile != null)
                {
                    this.PrintFilterMappings(filter);
                }
                return(1);
            }

            if (!filter.ContainsTargetPath("Build/Module.xml"))
            {
                RedirectableConsole.WriteLine("ERROR: The Build\\Module.xml file does not exist in the source folder.");
                if (execution.PackageFilterFile != null)
                {
                    this.PrintFilterMappings(filter);
                }
                return(1);
            }

            if (filter.ContainsTargetPath("Protobuild.exe"))
            {
                RedirectableConsole.WriteLine("ERROR: The Protobuild.exe file should not be included in the package file.");
                if (execution.PackageFilterFile != null)
                {
                    this.PrintFilterMappings(filter);
                }
                return(1);
            }

            using (var target = new FileStream(execution.PackageDestinationFile, FileMode.CreateNew, FileAccess.Write, FileShare.None))
            {
                _packageCreator.Create(
                    target,
                    filter,
                    execution.PackageSourceFolder,
                    execution.PackageFormat,
                    execution.PackagePlatform,
                    execution.PackageDestinationFile);
            }

            RedirectableConsole.WriteLine("\rPackage written to " + execution.PackageDestinationFile + " successfully.");
            return(0);
        }
        public int Execute(Execution execution)
        {
            if (!Directory.Exists(execution.PackageSourceFolder))
            {
                throw new InvalidOperationException("The source folder " + execution.PackageSourceFolder + " does not exist.");
            }

            if (execution.PackagePlatform == "Template")
            {
                return(ExecuteForTemplate(execution));
            }

            var        allowAutopackage   = true;
            var        moduleExpectedPath = Path.Combine(execution.PackageSourceFolder, "Build", "Module.xml");
            ModuleInfo rootModule         = null;

            if (!File.Exists(moduleExpectedPath))
            {
                if (execution.PackageFilterFile == null)
                {
                    Console.WriteLine(
                        "There is no module in the path '" + execution.PackageSourceFolder + "' (expected to " +
                        "find a Build\\Module.xml file within that directory).");
                    return(1);
                }
                else
                {
                    // We allow this mode if the user has provided a filter file and are constructing
                    // the package manually.
                    allowAutopackage = false;
                }
            }
            else
            {
                rootModule = ModuleInfo.Load(moduleExpectedPath);
            }

            var temporaryFiles = new List <string>();

            try
            {
                var customDirectives = new Dictionary <string, Action <FileFilter> >()
                {
                    {
                        "autopackage",
                        f =>
                        {
                            if (allowAutopackage && rootModule != null)
                            {
                                this.m_AutomaticProjectPackager.Autopackage(
                                    f,
                                    execution,
                                    rootModule,
                                    execution.PackageSourceFolder,
                                    execution.PackagePlatform,
                                    temporaryFiles);
                            }
                            else
                            {
                                Console.WriteLine(
                                    "WARNING: There is no module in the path '" + execution.PackageSourceFolder +
                                    "' (expected to " +
                                    "find a Build\\Module.xml file within that directory).  Ignoring the 'autopackage' directive.");
                            }
                        }
                    }
                };

                Console.WriteLine("Starting package creation for " + execution.PackagePlatform);

                var filter =
                    new FileFilter(_getRecursiveUtilitiesInPath.GetRecursiveFilesInPath(execution.PackageSourceFolder));
                if (execution.PackageFilterFile != null)
                {
                    using (var reader = new StreamReader(execution.PackageFilterFile))
                    {
                        var contents = reader.ReadToEnd();
                        contents = contents.Replace("%PLATFORM%", execution.PackagePlatform);

                        using (var inputStream = new MemoryStream(Encoding.ASCII.GetBytes(contents)))
                        {
                            this.m_FileFilterParser.ParseAndApply(filter, inputStream, customDirectives);
                        }
                    }
                }
                else
                {
                    customDirectives["autopackage"](filter);
                }

                if (File.Exists(execution.PackageDestinationFile))
                {
                    Console.WriteLine("The destination file " + execution.PackageDestinationFile +
                                      " already exists; it will be overwritten.");
                    File.Delete(execution.PackageDestinationFile);
                }

                filter.ImplyDirectories();

                var filterDictionary = filter.ToDictionary(k => k.Key, v => v.Value);

                if (!filterDictionary.ContainsValue("Build/"))
                {
                    Console.WriteLine("ERROR: The Build directory does not exist in the source folder.");
                    if (execution.PackageFilterFile != null)
                    {
                        this.PrintFilterMappings(filterDictionary);
                    }
                    return(1);
                }

                if (!filterDictionary.ContainsValue("Build/Projects/"))
                {
                    Console.WriteLine("ERROR: The Build\\Projects directory does not exist in the source folder.");
                    if (execution.PackageFilterFile != null)
                    {
                        this.PrintFilterMappings(filterDictionary);
                    }
                    return(1);
                }

                if (!filterDictionary.ContainsValue("Build/Module.xml"))
                {
                    Console.WriteLine("ERROR: The Build\\Module.xml file does not exist in the source folder.");
                    if (execution.PackageFilterFile != null)
                    {
                        this.PrintFilterMappings(filterDictionary);
                    }
                    return(1);
                }

                if (filterDictionary.ContainsValue("Protobuild.exe"))
                {
                    Console.WriteLine("ERROR: The Protobuild.exe file should not be included in the package file.");
                    if (execution.PackageFilterFile != null)
                    {
                        this.PrintFilterMappings(filterDictionary);
                    }
                    return(1);
                }

                using (
                    var target = new FileStream(execution.PackageDestinationFile, FileMode.CreateNew, FileAccess.Write,
                                                FileShare.None))
                {
                    _packageCreator.Create(
                        target,
                        filter,
                        execution.PackageSourceFolder,
                        execution.PackageFormat);
                }

                Console.WriteLine("\rPackage written to " + execution.PackageDestinationFile + " successfully.");
                return(0);
            }
            finally
            {
                foreach (var file in temporaryFiles)
                {
                    File.Delete(file);
                }
            }
        }