示例#1
0
        /// <summary>
        /// Creates the data structure for a new copyright file (in memory only).
        /// </summary>
        /// <returns>A new CopyrightFile object</returns>
        /// <remarks>
        /// The format of the copyright file is defined at https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/.
        /// </remarks>
        public static CopyrightFile CreateNewCopyrightFile(string programName, string contactEmail, string sourceUrl)
        {
            var copyrights = new CopyrightFile();
            var para       = new DebianParagraph();

            copyrights.Paragraphs.Add(para);
            para.Fields.Add(new DebianField("Format", "http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/"));
            para.Fields.Add(new DebianField("Upstream-Name", programName));
            para.Fields.Add(new DebianField("Upstream-Contact", contactEmail));
            para.Fields.Add(new DebianField("Source", sourceUrl));

            // REVIEW: can we assume these values?
            var programCopyright = String.Format("{0} SIL International", DateTime.Now.Year);
            var programLicense   = "MIT";

            para = new DebianParagraph();
            copyrights.Paragraphs.Add(para);
            para.Fields.Add(new DebianField("Files", "*"));
            para.Fields.Add(new DebianField("Copyright", programCopyright));
            para.Fields.Add(new DebianField("License", programLicense));
            if (programLicense == "MIT")
            {
                copyrights.AddLicenseParagraphIfNeeded(programLicense, StandardMITLicense);
            }

            return(copyrights);
        }
示例#2
0
        private void UpdateParagraphFromAcknowledgement(DebianParagraph para,
                                                        Acknowledgements.AcknowledgementAttribute ack)
        {
            string person;
            string year;

            ExtractCopyrightInformation(ack.Copyright, out person, out year);
            if (year == "????")
            {
                return;                                 // we don't know if this information is newer or not
            }
            var copyrightField = para.FindField("Copyright");

            if (copyrightField != null)
            {
                string prevYear;
                string prevPerson;
                ExtractCopyrightInformation(copyrightField.Value, out prevYear, out prevPerson);
                if (prevYear == "????" || prevYear.CompareTo(year) < 0)
                {
                    copyrightField.Value = year + " " + person;
                }
                else
                {
                    return;                             // our current information is as new or newer.
                }
            }

            string        shortLicense;
            List <string> longLicense;

            ExtractLicenseInformation(ack.LicenseUrl, out shortLicense, out longLicense);
            if (shortLicense != "????")
            {
                var licenseField = para.FindField("License");
                if (licenseField != null)
                {
                    licenseField.Value = shortLicense;
                }
                if (longLicense.Count > 0)
                {
                    AddLicenseParagraphIfNeeded(shortLicense, longLicense);
                }
            }

            if (!string.IsNullOrEmpty(ack.Url))
            {
                var commentField = para.FindField("Comment");
                if (commentField == null)
                {
                    para.Fields.Add(new DebianField("Comment", "URL = " + ack.Url));
                }
                else
                {
                    commentField.Value = "URL = " + ack.Url;
                }
            }
        }
示例#3
0
        internal void ReadDebianParagraphs(TextReader reader)
        {
            string          line;
            int             lineNumber = 0;
            var             state      = ReadingState.BeginParagraph;
            DebianParagraph paragraph  = null;
            DebianField     field      = null;

            while ((line = reader.ReadLine()) != null)
            {
                ++lineNumber;
                if (line.Trim().Length == 0)
                {
                    state = ReadingState.BeginParagraph;
                    continue;
                }
                switch (state)
                {
                case ReadingState.BeginParagraph:
                    if (Char.IsLetter(line[0]))
                    {
                        paragraph = new DebianParagraph();
                        Paragraphs.Add(paragraph);
                        field = new DebianField(line);
                        paragraph.Fields.Add(field);
                        state = ReadingState.FieldStarted;
                    }
                    else
                    {
                        Console.WriteLine("ERROR");
                    }
                    break;

                case ReadingState.FieldStarted:
                    if (line[0] == ' ' || line[0] == '\t')                      // I've only ever seen spaces, but the standard allows tabs.
                    {
                        field.FullDescription.Add(line.Substring(1));
                    }
                    else
                    {
                        field = new DebianField(line);
                        paragraph.Fields.Add(field);
                    }
                    break;
                }
            }
        }
示例#4
0
        internal void AddLicenseParagraphIfNeeded(string license, IEnumerable <string> detailLines)
        {
            // Check whether we need a license paragraph, and add it if needed.
            foreach (var p in Paragraphs)
            {
                if (p.Fields.Count == 1 && p.Fields[0].Tag == "License" && p.Fields[0].Value == license)
                {
                    return;                             // license already written out
                }
            }
            var para = new DebianParagraph();

            Paragraphs.Add(para);
            var field = new DebianField("License", license);

            para.Fields.Add(field);
            foreach (var line in detailLines)
            {
                field.FullDescription.Add(line);
            }
        }
示例#5
0
        internal static void ParseControlContentForValues(DebianControl controlFile, ref string programName, ref string contactEmail, ref string sourceUrl)
        {
            DebianParagraph sourcePara = null;

            foreach (var para in controlFile.Paragraphs)
            {
                if (para.Fields.Count > 0 && para.Fields[0].Tag == "Source")
                {
                    sourcePara = para;
                    break;
                }
            }
            if (sourcePara != null)
            {
                var sourceField = sourcePara.FindField("Source");
                programName = sourceField.Value;
                var maintainerField = sourcePara.FindField("Maintainer");
                if (maintainerField != null)
                {
                    contactEmail = maintainerField.Value;
                }
                // Find the "source URL" from
                // 1) Vcs-Browser (url to see source code repository in the browser), or if that isn't provided
                // 2) HomePage (url to see some sort of project home page in the browser), or if that isn't provided
                // 3) Vcs-Git (url to clone git repository on local machine)
                var urlField = sourcePara.FindField("Vcs-Browser");
                if (urlField == null)
                {
                    urlField = sourcePara.FindField("HomePage");
                }
                if (urlField == null)
                {
                    urlField = sourcePara.FindField("Vcs-Git");
                }
                if (urlField != null)
                {
                    sourceUrl = urlField.Value;
                }
            }
        }
示例#6
0
        internal void AddOrUpdateParagraphFromAcknowledgement(Acknowledgements.AcknowledgementAttribute ack, string prefix)
        {
            string fileSpec = null;

            if (!string.IsNullOrEmpty(ack.Location))
            {
                fileSpec = ack.Location;
                if (!fileSpec.StartsWith("/"))
                {
                    fileSpec = Path.GetFileName(fileSpec);
                }
            }
            else
            {
                fileSpec = ack.Key;
            }
            if (!String.IsNullOrEmpty(prefix))
            {
                fileSpec = Path.Combine(prefix, fileSpec);
            }

            if (IsWindowsSpecific(Path.GetFileName(fileSpec)))
            {
                return;
            }

            foreach (var p in Paragraphs)
            {
                if (p.Fields.Count >= 3 && p.Fields[0].Tag == "Files")
                {
                    if (p.Fields[0].Value == fileSpec ||
                        Path.GetFileName(p.Fields[0].Value) == fileSpec ||
                        Path.GetFileName(fileSpec) == p.Fields[0].Value)
                    {
                        UpdateParagraphFromAcknowledgement(p, ack);
                        return;
                    }
                }
            }

            var para = new DebianParagraph();

            Paragraphs.Add(para);
            para.Fields.Add(new DebianField("Files", fileSpec));

            string person;
            string year;

            ExtractCopyrightInformation(ack.Copyright, out person, out year);
            var copyright = year + " " + person;

            para.Fields.Add(new DebianField("Copyright", copyright));

            string        shortLicense;
            List <string> longLicense;

            ExtractLicenseInformation(ack.LicenseUrl, out shortLicense, out longLicense);
            para.Fields.Add(new DebianField("License", shortLicense));

            if (!string.IsNullOrEmpty(ack.Url))
            {
                para.Fields.Add(new DebianField("Comment", "URL = " + ack.Url));
            }

            if (shortLicense != "????" && longLicense.Count > 0)
            {
                AddLicenseParagraphIfNeeded(shortLicense, longLicense);
            }
        }