예제 #1
0
        private static PListDocument CompileInternal(String xibFile, String destination)
        {
            if (FileExtensions.UpToDate(xibFile, destination))
            {
                return(null);
            }
            String        arguments = String.Format(CultureInfo.InvariantCulture, "--errors --warnings --notices --compile \"{0}\" \"{1}\"", destination, xibFile);
            ProcessHelper helper    = new ProcessHelper(Executable, arguments);
            String        output    = helper.ExecuteAndReturnOutput();

            try
            {
                output = output.Trim();
                PListDocument document = PListDocument.LoadFromXml(output);
                return(document);
            }
            catch (Exception)
            {
                Console.WriteLine("XibTool cannot parse output:");
                Console.WriteLine("-----");
                Console.WriteLine(output);
                Console.WriteLine("-----");
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Generate the specified infoPlist and outputFolder.
        /// </summary>
        /// <param name='infoPlist'>
        /// Info plist.
        /// </param>
        /// <param name='outputFolder'>
        /// Output folder.
        /// </param>
        public String Generate(String infoPlist, String outputFolder)
        {
            // Load the Info.plist file
            PListDocument document = PListDocument.LoadFromFile(infoPlist);

            if (document == null)
            {
                this.Logger.LogError("Cannot parse document: " + infoPlist);
                return(String.Empty);
            }
            if (document.Root == null)
            {
                this.Logger.LogError("Document has no root: " + infoPlist);
                return(String.Empty);
            }
            if (document.Root.Dict == null)
            {
                this.Logger.LogError("Document has no dict: " + infoPlist);
                return(String.Empty);
            }

            // Extract bundle identifier
            PListString identifier = document.Root.Dict ["CFBundleIdentifier"] as PListString;

            if (identifier == null || String.IsNullOrWhiteSpace(identifier.Value))
            {
                this.Logger.LogError("Document has no 'CFBundleIdentifier': " + infoPlist);
                return(String.Empty);
            }

            // Extract bundle version
            PListString version = document.Root.Dict ["CFBundleShortVersionString"] as PListString;

            if (version == null || String.IsNullOrWhiteSpace(version.Value))
            {
                this.Logger.LogError("Document has no 'CFBundleShortVersionString': " + infoPlist);
                return(String.Empty);
            }

            // Launch the generation
            String        file      = Path.Combine(outputFolder, "receigen.h");
            StringBuilder arguments = new StringBuilder();

            arguments.AppendFormat(" --identifier {0} ", identifier.Value);
            arguments.AppendFormat(" --version {0} ", version.Value);

            this.Logger.LogDebug("Calling '" + this.Executable + "' with '" + arguments + "'");

            ProcessHelper helper = new ProcessHelper(this.Executable, arguments.ToString());
            String        output = helper.ExecuteAndReturnOutput();

            Directory.CreateDirectory(Path.GetDirectoryName(file));
            File.WriteAllText(file, output);

            return("Done");
        }
예제 #3
0
        public void TestPListReading010()
        {
            String        content  = ReadResource(Resources.Info_010);
            PListDocument document = PListDocument.LoadFromXml(content);

            CheckDocument(document);

            Assert.AreEqual(String.Empty, (String)(PListString)document.Root.Dict["CFBundleIconFile"]);
            Assert.AreEqual("net.monobjc.${PRODUCT_NAME:rfc1034identifier}", (String)(PListString)document.Root.Dict["CFBundleIdentifier"]);
        }
예제 #4
0
        public void TestPListReading005()
        {
            String        content  = ReadResource(Resources.Info_005);
            PListDocument document = PListDocument.LoadFromXml(content);

            CheckDocument(document);

            Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleDocumentTypes"));
            PListItemBase item = document.Root.Dict["CFBundleDocumentTypes"];

            Assert.IsTrue(item is PListArray);
            PListArray array = (PListArray)item;

            Assert.AreEqual(1, array.Count);
        }
예제 #5
0
 private static void CheckDocument(PListDocument document)
 {
     Assert.IsNotNull(document.Root);
     Assert.IsNotNull(document.Root.Dict);
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleDevelopmentRegion"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleExecutable"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleIconFile"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleIdentifier"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleInfoDictionaryVersion"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleName"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundlePackageType"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleSignature"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleShortVersionString"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("LSMinimumSystemVersion"));
     Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleVersion"));
     Assert.AreEqual("1", (String)(PListString)document.Root.Dict["CFBundleVersion"]);
     Assert.IsTrue(document.Root.Dict.ContainsKey("NSMainNibFile"));
     Assert.AreEqual("MainMenu", (String)(PListString)document.Root.Dict["NSMainNibFile"]);
     Assert.IsTrue(document.Root.Dict.ContainsKey("NSPrincipalClass"));
     Assert.AreEqual("NSApplication", (String)(PListString)document.Root.Dict["NSPrincipalClass"]);
 }
예제 #6
0
        /// <summary>
        ///   Generates the Info.plist content.
        /// </summary>
        public void WriteTo(string path)
        {
            if (this.Content == null)
            {
                this.Logger.LogDebug("Using default template");

                // Load template
                this.Content = Resources.InfoPlist;
            }

            // Parse the template content
            PListDocument document = PListDocument.LoadFromXml(this.Content);
            PList         list     = document.Root;
            PListDict     dict     = list.Dict;

            // Set default values
            this.Identifier     = this.Identifier ?? "net.monobjc.app";
            this.Version        = this.Version ?? "1.0";
            this.MainNibFile    = (this.MainNibFile != null) ? Path.GetFileNameWithoutExtension(this.MainNibFile) : "MainMenu";
            this.PrincipalClass = this.PrincipalClass ?? "NSApplication";

            // Replace template values
            Replace(dict, "CFBundleDevelopmentRegion", this.DevelopmentRegion);
            Replace(dict, "CFBundleExecutable", this.ApplicationName);
            Replace(dict, "CFBundleIconFile", this.Icon);
            Replace(dict, "CFBundleIdentifier", this.Identifier);
            Replace(dict, "CFBundleName", this.ApplicationName);
            Replace(dict, "CFBundleShortVersionString", this.Version);
            switch (this.TargetOSVersion)
            {
            case MacOSVersion.MacOS105:
                Replace(dict, "LSMinimumSystemVersion", "10.5");
                break;

            case MacOSVersion.MacOS106:
                Replace(dict, "LSMinimumSystemVersion", "10.6");
                break;

            case MacOSVersion.MacOS107:
                Replace(dict, "LSMinimumSystemVersion", "10.7");
                break;

            case MacOSVersion.MacOS108:
                Replace(dict, "LSMinimumSystemVersion", "10.8");
                break;

            case MacOSVersion.MacOS109:
                Replace(dict, "LSMinimumSystemVersion", "10.9");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            Replace(dict, "NSMainNibFile", this.MainNibFile);
            Replace(dict, "NSPrincipalClass", this.PrincipalClass);

            // Resassign content
            this.Content = document.ToString();

            File.WriteAllText(path, this.Content, Encoding.UTF8);
        }
예제 #7
0
        /// <summary>
        ///   Compiles the specified XIB file.
        /// </summary>
        /// <param name = "xibFile">The XIB file.</param>
        /// <param name = "directory">The directory.</param>
        /// <returns><code>true</code> if the compilation is successful, <code>false</code> otherwise.</returns>
        public bool Compile(String xibFile, String directory)
        {
            // TODO: I18N
            this.Logger.LogDebug(String.Format(CultureInfo.CurrentCulture, "Compiling {0} into {1}", xibFile, directory));

            PListDocument result = XibTool.Compile(xibFile, directory);

            if (result == null)
            {
                this.Logger.LogInfo(String.Format(CultureInfo.CurrentCulture, Resources.IBFileUpToDate, xibFile));
                return(true);
            }

            PList     root = result.Root;
            PListDict dict = root.Dict;

            if (dict == null)
            {
                this.Logger.LogError(Resources.NoDictionaryFound);
                return(false);
            }

            // Global errors
            if (dict.ContainsKey(XibTool.ERRORS))
            {
                PListArray errors = (PListArray)dict[XibTool.ERRORS];
                foreach (PListItemBase item in errors)
                {
                    PListDict error = item as PListDict;
                    if (error == null)
                    {
                        continue;
                    }
                    PListString description = error[XibTool.KEY_DESCRIPTION] as PListString;
                    if (description != null)
                    {
                        this.Logger.LogError(description.Value);
                    }
                }

                // If there was global errors, return
                if (errors.Count > 0)
                {
                    return(false);
                }
            }

            // Document errors
            PListDict documentErrors = (PListDict)dict[XibTool.DOCUMENT_ERRORS];

            foreach (String key in documentErrors.Keys)
            {
                PListArray elementErrors = documentErrors[key] as PListArray;
                if (elementErrors == null)
                {
                    continue;
                }
                foreach (PListItemBase item in elementErrors)
                {
                    PListDict   error   = item as PListDict;
                    PListString type    = error[XibTool.KEY_TYPE] as PListString;
                    PListString message = error[XibTool.KEY_MESSAGE] as PListString;
                    if (type != null && message != null)
                    {
                        this.Logger.LogError(String.Format(CultureInfo.CurrentCulture, Resources.ValueDescriptionFormat, type.Value, message.Value));
                    }
                }
            }

            // If there was document errors, return
            if (documentErrors.Count > 0)
            {
                return(false);
            }

            // Document warnings
            PListDict documentWarnings = (PListDict)dict[XibTool.DOCUMENT_WARNINGS];

            foreach (String key in documentWarnings.Keys)
            {
                PListArray elementWarnings = documentWarnings[key] as PListArray;
                if (elementWarnings == null)
                {
                    continue;
                }
                foreach (PListItemBase item in elementWarnings)
                {
                    PListDict   error   = item as PListDict;
                    PListString type    = error[XibTool.KEY_TYPE] as PListString;
                    PListString message = error[XibTool.KEY_MESSAGE] as PListString;
                    if (type != null && message != null)
                    {
                        this.Logger.LogWarning(String.Format(CultureInfo.CurrentCulture, Resources.ValueDescriptionFormat, type.Value, message.Value));
                    }
                }
            }

            // Document notices
            PListDict documentNotices = (PListDict)dict[XibTool.DOCUMENT_NOTICES];

            foreach (String key in documentNotices.Keys)
            {
                PListArray elementNotices = documentNotices[key] as PListArray;
                if (elementNotices == null)
                {
                    continue;
                }
                foreach (PListItemBase item in elementNotices)
                {
                    PListDict   error   = item as PListDict;
                    PListString type    = error[XibTool.KEY_TYPE] as PListString;
                    PListString message = error[XibTool.KEY_MESSAGE] as PListString;
                    if (type != null && message != null)
                    {
                        this.Logger.LogInfo(String.Format(CultureInfo.CurrentCulture, Resources.ValueDescriptionFormat, type.Value, message.Value));
                    }
                }
            }

            return(true);
        }
예제 #8
0
        public void WriteInfoPList(PListDocument document)
        {
            String path = Path.Combine(this.ContentsDirectory, "Info.plist");

            document.WriteToFile(path);
        }