11// Copyright (c) 2025 SIL Global
22// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
3+
34using System ;
4- using System . IO ;
55using System . Collections . Generic ;
6+ using System . IO ;
67using System . Text ;
8+ using System . Text . RegularExpressions ;
9+ using SIL . Acknowledgements ;
10+ using static System . String ;
711
812namespace SIL . ExtractCopyright
913{
@@ -18,22 +22,20 @@ public enum ExitValue {
1822 NoDebianFolder ,
1923 NoAssemblyFolder ,
2024 NoPrefixFolder
21- } ;
25+ }
2226
2327 public CopyrightFile ( )
2428 {
2529 }
2630
27- public CopyrightFile ( string filename )
28- : base ( filename )
31+ public CopyrightFile ( string filename ) : base ( filename )
2932 {
3033 }
3134
3235 /// <summary>
3336 /// Create or update the copyright file in the given debian folder.
3437 /// </summary>
3538 /// <param name="debianFolder">Debian folder.</param>
36- /// <param name="assemblyFolder">Assembly folder.</param>
3739 /// <param name="prefixFolder">Prefix folder.</param>
3840 public static int CreateOrUpdateCopyrightFile ( string debianFolder , string prefixFolder )
3941 {
@@ -47,17 +49,17 @@ public static int CreateOrUpdateCopyrightFile(string debianFolder, string prefix
4749 var controlFile = new DebianControl ( Path . Combine ( debianFolder , "control" ) ) ;
4850 ParseControlContentForValues ( controlFile , ref programName , ref contactEmail , ref sourceUrl ) ;
4951 // If necessary, try to read some primary information from the changelog file.
50- if ( String . IsNullOrEmpty ( programName ) || String . IsNullOrEmpty ( contactEmail ) )
52+ if ( IsNullOrEmpty ( programName ) || IsNullOrEmpty ( contactEmail ) )
5153 {
5254 var lines = File . ReadAllLines ( Path . Combine ( debianFolder , "changelog" ) , Encoding . UTF8 ) ;
5355 ParseChangelogContentForValues ( lines , ref programName , ref contactEmail ) ;
5456 }
5557 // If we can't derive any information, flag it as unknown.
56- if ( String . IsNullOrEmpty ( programName ) )
58+ if ( IsNullOrEmpty ( programName ) )
5759 programName = "UNKNOWN" ;
58- if ( String . IsNullOrEmpty ( contactEmail ) )
60+ if ( IsNullOrEmpty ( contactEmail ) )
5961 contactEmail = "UNKNOWN" ;
60- if ( String . IsNullOrEmpty ( sourceUrl ) )
62+ if ( IsNullOrEmpty ( sourceUrl ) )
6163 sourceUrl = "UNKNOWN" ;
6264 copyrights = CreateNewCopyrightFile ( programName , contactEmail , sourceUrl ) ;
6365 copyrights . _filepath = Path . Combine ( debianFolder , "copyright" ) ;
@@ -70,7 +72,7 @@ public static int CreateOrUpdateCopyrightFile(string debianFolder, string prefix
7072 Console . WriteLine ( "ExtractCopyright: updating existing file at \" {0}\" " , copyrights . _filepath ) ;
7173 }
7274
73- var ackDict = SIL . Acknowledgements . AcknowledgementsProvider . CollectAcknowledgements ( ) ;
75+ var ackDict = AcknowledgementsProvider . CollectAcknowledgements ( ) ;
7476 foreach ( var key in ackDict . Keys )
7577 copyrights . AddOrUpdateParagraphFromAcknowledgement ( ackDict [ key ] , prefixFolder ) ;
7678
@@ -101,11 +103,9 @@ internal static void ParseControlContentForValues(DebianControl controlFile, ref
101103 // 1) Vcs-Browser (url to see source code repository in the browser), or if that isn't provided
102104 // 2) HomePage (url to see some sort of project home page in the browser), or if that isn't provided
103105 // 3) Vcs-Git (url to clone git repository on local machine)
104- var urlField = sourcePara . FindField ( "Vcs-Browser" ) ;
105- if ( urlField == null )
106- urlField = sourcePara . FindField ( "HomePage" ) ;
107- if ( urlField == null )
108- urlField = sourcePara . FindField ( "Vcs-Git" ) ;
106+ var urlField = sourcePara . FindField ( "Vcs-Browser" ) ??
107+ sourcePara . FindField ( "HomePage" ) ??
108+ sourcePara . FindField ( "Vcs-Git" ) ;
109109 if ( urlField != null )
110110 sourceUrl = urlField . Value ;
111111 }
@@ -118,22 +118,22 @@ internal static void ParseChangelogContentForValues(string[] lines, ref string p
118118 {
119119 // The first line of an entry in the changelog looks like this:
120120 // "bloom-desktop-alpha (3.9.0) stable; urgency=medium"
121- if ( String . IsNullOrEmpty ( programName ) && lines [ i ] . Contains ( " urgency=" ) && lines [ i ] . Contains ( ";" ) )
121+ if ( IsNullOrEmpty ( programName ) && lines [ i ] . Contains ( " urgency=" ) && lines [ i ] . Contains ( ";" ) )
122122 {
123- var headerPieces = lines [ i ] . Trim ( ) . Split ( new char [ ] { ' ' } ) ;
123+ var headerPieces = lines [ i ] . Trim ( ) . Split ( ' ' ) ;
124124 programName = headerPieces [ i ] ;
125125 }
126126 // The closing line of an entry in the changelog looks like this:
127127 // " -- Stephen McConnel <stephen_mcconnel@sil.org> Wed, 18 Jan 2017 11:38:31 -0600"
128128 // the two spaces following the <email@address> are significant
129- else if ( String . IsNullOrEmpty ( contactEmail ) && lines [ i ] . StartsWith ( " -- " ) && lines [ i ] . Contains ( "@" ) )
129+ else if ( IsNullOrEmpty ( contactEmail ) && lines [ i ] . StartsWith ( " -- " ) && lines [ i ] . Contains ( "@" ) )
130130 {
131131 var line = lines [ i ] . Substring ( 4 ) . Trim ( ) ;
132- var idx = line . IndexOf ( " " ) ;
132+ var idx = line . IndexOf ( " " , StringComparison . Ordinal ) ;
133133 if ( idx > 0 )
134134 contactEmail = line . Substring ( 0 , idx ) ;
135135 }
136- if ( ! String . IsNullOrEmpty ( programName ) && ! String . IsNullOrEmpty ( contactEmail ) )
136+ if ( ! IsNullOrEmpty ( programName ) && ! IsNullOrEmpty ( contactEmail ) )
137137 return ;
138138 }
139139 }
@@ -156,7 +156,7 @@ public static CopyrightFile CreateNewCopyrightFile(string programName, string co
156156 para . Fields . Add ( new DebianField ( "Source" , sourceUrl ) ) ;
157157
158158 // REVIEW: can we assume these values?
159- var programCopyright = String . Format ( "{0} SIL Global" , DateTime . Now . Year ) ;
159+ var programCopyright = Format ( "{0} SIL Global" , DateTime . Now . Year ) ;
160160 var programLicense = "MIT" ;
161161
162162 para = new DebianParagraph ( ) ;
@@ -170,10 +170,10 @@ public static CopyrightFile CreateNewCopyrightFile(string programName, string co
170170 return copyrights ;
171171 }
172172
173- internal void AddOrUpdateParagraphFromAcknowledgement ( Acknowledgements . AcknowledgementAttribute ack , string prefix )
173+ internal void AddOrUpdateParagraphFromAcknowledgement ( AcknowledgementAttribute ack , string prefix )
174174 {
175- string fileSpec = null ;
176- if ( ! string . IsNullOrEmpty ( ack . Location ) )
175+ string fileSpec ;
176+ if ( ! IsNullOrEmpty ( ack . Location ) )
177177 {
178178 fileSpec = ack . Location ;
179179 if ( ! fileSpec . StartsWith ( "/" ) )
@@ -183,7 +183,7 @@ internal void AddOrUpdateParagraphFromAcknowledgement(Acknowledgements.Acknowled
183183 {
184184 fileSpec = ack . Key ;
185185 }
186- if ( ! String . IsNullOrEmpty ( prefix ) )
186+ if ( ! IsNullOrEmpty ( prefix ) )
187187 fileSpec = Path . Combine ( prefix , fileSpec ) ;
188188
189189 if ( IsWindowsSpecific ( Path . GetFileName ( fileSpec ) ) )
@@ -207,18 +207,14 @@ internal void AddOrUpdateParagraphFromAcknowledgement(Acknowledgements.Acknowled
207207 Paragraphs . Add ( para ) ;
208208 para . Fields . Add ( new DebianField ( "Files" , fileSpec ) ) ;
209209
210- string person ;
211- string year ;
212- ExtractCopyrightInformation ( ack . Copyright , out person , out year ) ;
210+ ExtractCopyrightInformation ( ack . Copyright , out var person , out var year ) ;
213211 var copyright = year + " " + person ;
214212 para . Fields . Add ( new DebianField ( "Copyright" , copyright ) ) ;
215213
216- string shortLicense ;
217- List < string > longLicense ;
218- ExtractLicenseInformation ( ack . LicenseUrl , out shortLicense , out longLicense ) ;
214+ ExtractLicenseInformation ( ack . LicenseUrl , out var shortLicense , out var longLicense ) ;
219215 para . Fields . Add ( new DebianField ( "License" , shortLicense ) ) ;
220216
221- if ( ! string . IsNullOrEmpty ( ack . Url ) )
217+ if ( ! IsNullOrEmpty ( ack . Url ) )
222218 para . Fields . Add ( new DebianField ( "Comment" , "URL = " + ack . Url ) ) ;
223219
224220 if ( shortLicense != "????" && longLicense . Count > 0 )
@@ -227,7 +223,7 @@ internal void AddOrUpdateParagraphFromAcknowledgement(Acknowledgements.Acknowled
227223 }
228224 }
229225
230- private bool IsWindowsSpecific ( string name )
226+ private static bool IsWindowsSpecific ( string name )
231227 {
232228 switch ( name )
233229 {
@@ -261,19 +257,15 @@ internal void AddLicenseParagraphIfNeeded(string license, IEnumerable<string> de
261257 }
262258
263259 private void UpdateParagraphFromAcknowledgement ( DebianParagraph para ,
264- Acknowledgements . AcknowledgementAttribute ack )
260+ AcknowledgementAttribute ack )
265261 {
266- string person ;
267- string year ;
268- ExtractCopyrightInformation ( ack . Copyright , out person , out year ) ;
262+ ExtractCopyrightInformation ( ack . Copyright , out var person , out var year ) ;
269263 if ( year == "????" )
270264 return ; // we don't know if this information is newer or not
271265 var copyrightField = para . FindField ( "Copyright" ) ;
272266 if ( copyrightField != null )
273267 {
274- string prevYear ;
275- string prevPerson ;
276- ExtractCopyrightInformation ( copyrightField . Value , out prevYear , out prevPerson ) ;
268+ ExtractCopyrightInformation ( copyrightField . Value , out var prevYear , out _ ) ;
277269 if ( prevYear == "????" || prevYear . CompareTo ( year ) < 0 )
278270 {
279271 copyrightField . Value = year + " " + person ;
@@ -284,9 +276,7 @@ private void UpdateParagraphFromAcknowledgement(DebianParagraph para,
284276 }
285277 }
286278
287- string shortLicense ;
288- List < string > longLicense ;
289- ExtractLicenseInformation ( ack . LicenseUrl , out shortLicense , out longLicense ) ;
279+ ExtractLicenseInformation ( ack . LicenseUrl , out var shortLicense , out var longLicense ) ;
290280 if ( shortLicense != "????" )
291281 {
292282 var licenseField = para . FindField ( "License" ) ;
@@ -296,7 +286,7 @@ private void UpdateParagraphFromAcknowledgement(DebianParagraph para,
296286 AddLicenseParagraphIfNeeded ( shortLicense , longLicense ) ;
297287 }
298288
299- if ( ! string . IsNullOrEmpty ( ack . Url ) )
289+ if ( ! IsNullOrEmpty ( ack . Url ) )
300290 {
301291 var commentField = para . FindField ( "Comment" ) ;
302292 if ( commentField == null )
@@ -318,7 +308,7 @@ private void ExtractCopyrightInformation(string original, out string person, out
318308 copyright = copyright . Replace ( "(c)" , "" ) ;
319309 copyright = copyright . Replace ( "©" , "" ) ;
320310 // extract year and person if present
321- var match = System . Text . RegularExpressions . Regex . Match ( copyright , "([0-9][0-9][0-9][0-9][-0-9]*)" ) ;
311+ var match = Regex . Match ( copyright , "([0-9][0-9][0-9][0-9][-0-9]*)" ) ;
322312 if ( match . Success )
323313 {
324314 year = copyright . Substring ( match . Index , match . Length ) ;
@@ -329,15 +319,15 @@ private void ExtractCopyrightInformation(string original, out string person, out
329319 person = copyright ;
330320 }
331321 person = person . Trim ( ) ;
332- if ( string . IsNullOrEmpty ( person ) )
322+ if ( IsNullOrEmpty ( person ) )
333323 person = "????" ;
334324 }
335325
336326 private void ExtractLicenseInformation ( string original , out string shortLicense , out List < string > longLicense )
337327 {
338328 shortLicense = "????" ;
339329 longLicense = new List < string > ( ) ;
340- if ( ! string . IsNullOrEmpty ( original ) )
330+ if ( ! IsNullOrEmpty ( original ) )
341331 {
342332 shortLicense = original ;
343333 var idx = shortLicense . LastIndexOf ( '/' ) ;
@@ -362,7 +352,7 @@ private void ExtractLicenseInformation(string original, out string shortLicense,
362352 /// <summary>
363353 /// The standard MIT license used for SIL software.
364354 /// </summary>
365- public static string [ ] StandardMITLicense = new string [ ] {
355+ public static string [ ] StandardMITLicense = {
366356 "Permission is hereby granted, free of charge, to any person obtaining a" ,
367357 "copy of this software and associated documentation files (the \" Software\" )," ,
368358 "to deal in the Software without restriction, including without limitation" ,
0 commit comments