Пример #1
0
        Serialize()
        {
            var workspaceDoc = new System.Xml.XmlDocument();
            var workspaceEl  = workspaceDoc.CreateElement("Workspace");

            workspaceEl.SetAttribute("version", "1.0");
            workspaceDoc.AppendChild(workspaceEl);

            var generateProjectSchemes = Bam.Core.CommandLineProcessor.Evaluate(new Options.GenerateXcodeSchemes());

            foreach (var project in this.ProjectMap.Values)
            {
                project.FixupPerConfigurationData();

                var text = new System.Text.StringBuilder();
                text.AppendLine("// !$*UTF8*$!");
                text.AppendLine("{");
                var indentLevel = 1;
                var indent      = new string('\t', indentLevel);
                text.AppendFormat("{0}archiveVersion = 1;", indent);
                text.AppendLine();
                text.AppendFormat("{0}classes = {{", indent);
                text.AppendLine();
                text.AppendFormat("{0}}};", indent);
                text.AppendLine();
                text.AppendFormat("{0}objectVersion = 46;", indent);
                text.AppendLine();
                text.AppendFormat("{0}objects = {{", indent);
                text.AppendLine();
                project.Serialize(text, indentLevel + 1);
                text.AppendFormat("{0}}};", indent);
                text.AppendLine();
                text.AppendFormat("{0}rootObject = {1} /* Project object */;", indent, project.GUID);
                text.AppendLine();
                text.AppendLine("}");

                var projectDir = project.ProjectDir;
                if (!System.IO.Directory.Exists(projectDir.Parse()))
                {
                    System.IO.Directory.CreateDirectory(projectDir.Parse());
                }

                //Bam.Core.Log.DebugMessage(text.ToString());
                using (var writer = new System.IO.StreamWriter(project.ProjectPath))
                {
                    writer.Write(text.ToString());
                }

                if (generateProjectSchemes)
                {
                    var projectSchemeCache = new ProjectSchemeCache(project);
                    projectSchemeCache.Serialize();
                }

                var workspaceFileRef = workspaceDoc.CreateElement("FileRef");
                workspaceFileRef.SetAttribute("location", System.String.Format("group:{0}", projectDir));
                workspaceEl.AppendChild(workspaceFileRef);
            }

            var workspacePath      = Bam.Core.TokenizedString.Create("$(buildroot)/$(masterpackagename).xcworkspace/contents.xcworkspacedata", null);
            var workspaceDir       = Bam.Core.TokenizedString.Create("@dir($(0))", null, positionalTokens: new Bam.Core.TokenizedStringArray(workspacePath));
            var workspaceDirectory = workspaceDir.Parse();

            if (!System.IO.Directory.Exists(workspaceDirectory))
            {
                System.IO.Directory.CreateDirectory(workspaceDirectory);
            }

            var settings = new System.Xml.XmlWriterSettings();

            settings.OmitXmlDeclaration = false;
            settings.Encoding           = new System.Text.UTF8Encoding(false); // no BOM
            settings.NewLineChars       = System.Environment.NewLine;
            settings.Indent             = true;
            settings.ConformanceLevel   = System.Xml.ConformanceLevel.Document;

            using (var xmlwriter = System.Xml.XmlWriter.Create(workspacePath.Parse(), settings))
            {
                workspaceDoc.WriteTo(xmlwriter);
            }

            return(workspaceDirectory);
        }
Пример #2
0
        Serialize()
        {
            var workspacePath      = Bam.Core.TokenizedString.Create("$(buildroot)/$(masterpackagename).xcworkspace/contents.xcworkspacedata", null);
            var workspaceDir       = Bam.Core.TokenizedString.Create("@dir($(0))", null, positionalTokens: new Bam.Core.TokenizedStringArray(workspacePath));
            var workspaceDirectory = workspaceDir.Parse();

            var workspaceDoc = new System.Xml.XmlDocument();
            var workspaceEl  = workspaceDoc.CreateElement("Workspace");

            workspaceEl.SetAttribute("version", "1.0");
            workspaceDoc.AppendChild(workspaceEl);

            var generateProjectSchemes = true; // used to be based on a command line option, but now needed for working directory

            foreach (var project in this.ProjectMap.Values)
            {
                project.ResolveDeferredSetup();

                var text = new System.Text.StringBuilder();
                text.AppendLine("// !$*UTF8*$!");
                text.AppendLine("{");
                var indentLevel = 1;
                var indent      = new string('\t', indentLevel);
                text.AppendFormat("{0}archiveVersion = 1;", indent);
                text.AppendLine();
                text.AppendFormat("{0}classes = {{", indent);
                text.AppendLine();
                text.AppendFormat("{0}}};", indent);
                text.AppendLine();
                text.AppendFormat("{0}objectVersion = 46;", indent);
                text.AppendLine();
                text.AppendFormat("{0}objects = {{", indent);
                text.AppendLine();
                project.Serialize(text, indentLevel + 1);
                text.AppendFormat("{0}}};", indent);
                text.AppendLine();
                text.AppendFormat("{0}rootObject = {1} /* Project object */;", indent, project.GUID);
                text.AppendLine();
                text.AppendLine("}");

                var projectDir = project.ProjectDir;
                Bam.Core.IOWrapper.CreateDirectoryIfNotExists(projectDir.Parse());

                WriteProjectFileIfDifferent(project.ProjectPath, text);

                if (generateProjectSchemes)
                {
                    var projectSchemeCache = new ProjectSchemeCache(project);
                    projectSchemeCache.Serialize();
                }

                var relativeProjectDir = Bam.Core.RelativePathUtilities.GetPath(projectDir.Parse(), workspaceDirectory);
                var workspaceFileRef   = workspaceDoc.CreateElement("FileRef");
                workspaceFileRef.SetAttribute("location", System.String.Format("group:{0}", relativeProjectDir));
                workspaceEl.AppendChild(workspaceFileRef);
            }

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(workspaceDirectory);

            var settings = new System.Xml.XmlWriterSettings();

            settings.OmitXmlDeclaration = false;
            settings.Encoding           = new System.Text.UTF8Encoding(false); // no BOM
            settings.NewLineChars       = System.Environment.NewLine;
            settings.Indent             = true;
            settings.ConformanceLevel   = System.Xml.ConformanceLevel.Document;
            WriteXMLIfDifferent(workspacePath.Parse(), settings, workspaceDoc);

            return(workspaceDirectory);
        }
Пример #3
0
        public string Serialize()
        {
            var workspaceDoc = new System.Xml.XmlDocument();
            var workspaceEl = workspaceDoc.CreateElement("Workspace");
            workspaceEl.SetAttribute("version", "1.0");
            workspaceDoc.AppendChild(workspaceEl);

            var generateProjectSchemes = Bam.Core.CommandLineProcessor.Evaluate(new Options.GenerateXcodeSchemes());
            foreach (var project in this.ProjectMap.Values)
            {
                project.FixupPerConfigurationData();

                var text = new System.Text.StringBuilder();
                text.AppendLine("// !$*UTF8*$!");
                text.AppendLine("{");
                var indentLevel = 1;
                var indent = new string('\t', indentLevel);
                text.AppendFormat("{0}archiveVersion = 1;", indent);
                text.AppendLine();
                text.AppendFormat("{0}classes = {{", indent);
                text.AppendLine();
                text.AppendFormat("{0}}};", indent);
                text.AppendLine();
                text.AppendFormat("{0}objectVersion = 46;", indent);
                text.AppendLine();
                text.AppendFormat("{0}objects = {{", indent);
                text.AppendLine();
                project.Serialize(text, indentLevel + 1);
                text.AppendFormat("{0}}};", indent);
                text.AppendLine();
                text.AppendFormat("{0}rootObject = {1} /* Project object */;", indent, project.GUID);
                text.AppendLine();
                text.AppendLine("}");

                var projectDir = project.ProjectDir;
                if (!System.IO.Directory.Exists(projectDir.Parse()))
                {
                    System.IO.Directory.CreateDirectory(projectDir.Parse());
                }

                //Bam.Core.Log.DebugMessage(text.ToString());
                using (var writer = new System.IO.StreamWriter(project.ProjectPath))
                {
                    writer.Write(text.ToString());
                }

                if (generateProjectSchemes)
                {
                    var projectSchemeCache = new ProjectSchemeCache(project);
                    projectSchemeCache.Serialize();
                }

                var workspaceFileRef = workspaceDoc.CreateElement("FileRef");
                workspaceFileRef.SetAttribute("location", System.String.Format("group:{0}", projectDir));
                workspaceEl.AppendChild(workspaceFileRef);
            }

            var workspacePath = Bam.Core.TokenizedString.Create("$(buildroot)/$(masterpackagename).xcworkspace/contents.xcworkspacedata", null);
            var workspaceDir = Bam.Core.TokenizedString.Create("@dir($(0))", null, positionalTokens: new Bam.Core.TokenizedStringArray(workspacePath));
            var workspaceDirectory = workspaceDir.Parse();
            if (!System.IO.Directory.Exists(workspaceDirectory))
            {
                System.IO.Directory.CreateDirectory(workspaceDirectory);
            }

            var settings = new System.Xml.XmlWriterSettings();
            settings.OmitXmlDeclaration = false;
            settings.Encoding = new System.Text.UTF8Encoding(false); // no BOM
            settings.NewLineChars = System.Environment.NewLine;
            settings.Indent = true;
            settings.ConformanceLevel = System.Xml.ConformanceLevel.Document;

            using (var xmlwriter = System.Xml.XmlWriter.Create(workspacePath.Parse(), settings))
            {
                workspaceDoc.WriteTo(xmlwriter);
            }

            return workspaceDirectory;
        }