• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// COMMON PATTERNS
6
7const String kIndent = r'^((?:[-;@#<!.\\"/* ]*(?:REM[-;@#<!.\\"/* ]*)?[-;@#<!.\"/*]+)?)( *)';
8
9final RegExp stripDecorations = RegExp(
10  r'^((?:(?:[-;@#<!.\\"/* ]*(?:REM[-;@#<!.\\"/* ]*)?[-;@#<!.\"/*]+)?)(?:(?: |\t)*))(.*?)[ */]*$',
11  multiLine: true,
12  caseSensitive: false
13);
14
15final RegExp newlinePattern = RegExp(r'\r\n?');
16
17final RegExp beginLicenseBlock = RegExp(
18  r'^([#;/* ]*) (?:\*\*\*\*\* BEGIN LICENSE BLOCK \*\*\*\*\*[ */]*'
19                r'|@APPLE_LICENSE_HEADER_START@)$'
20);
21
22final RegExp endLicenseBlock = RegExp(
23  r'^([#;/* ]*) (?:\*\*\*\*\* END LICENSE BLOCK \*\*\*\*\*[ */]*'
24                r'|@APPLE_LICENSE_HEADER_END@)$'
25);
26
27final RegExp nonSpace = RegExp('[^ ]');
28final RegExp trailingComma = RegExp(r',[ */]*$');
29final RegExp trailingColon = RegExp(r':(?: |\*|/|\n|=|-)*$');
30final RegExp copyrightMentionPattern = RegExp(r'©| \(c\) (?!{)|copy\s*right\b|copy\s*left', caseSensitive: false);
31final RegExp licenseMentionPattern = RegExp(r'license|warrant[iy]', caseSensitive: false);
32final RegExp copyrightMentionOkPattern = RegExp(
33  // if a (multiline) block matches this, we ignore it even if it matches copyrightMentionPattern/licenseMentionPattern
34  r'(?:These are covered by the following copyright:'
35     r'|^((?:[-;#<!.\\"/* ]*(?:REM[-;#<!.\\"/* ]*)?[-;#<!.\"/*]+)?)((?: |\t)*)COPYRIGHT: *\r?\n'
36     r'|copyright.*\\n"' // clearly part of a string
37     r'|\$YEAR' // clearly part of a template string
38     r'|LICENSE BLOCK' // MPL license block header/footer
39     r'|2117.+COPYRIGHT' // probably U+2117 mention...
40     r'|// The copyright below was added in 2009, but I see no record'
41     r'|This ICU code derived from:'
42     r'|the contents of which are also included in zip.h' // seen in minizip's unzip.c, but the upshot of the crazy license situation there is that we don't have to do anything
43     r'|hold font names, copyright info, notices, etc' // seen in a comment in freetype's src/include/ftsnames.h
44     r'|' // the following is from android_tools/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/ext/pb_ds/detail/splay_tree_/splay_tree_.hpp
45     r'^ \* This implementation uses an idea from the SGI STL \(using a @a header node\n'
46     r'^ \*    which is needed for efficient iteration\)\. Following is the SGI STL\n'
47     r'^ \*    copyright\.\n'
48  r')',
49  caseSensitive: false, multiLine: true);
50final RegExp halfCopyrightPattern = RegExp(r'^(?:Copyright(?: \(c\))? [-0-9, ]+(?: by)?|Written [0-9]+)[ */]*$', caseSensitive: false);
51final RegExp authorPattern = RegExp(r'Copyright .+(The .+ Authors)\. +All rights reserved\.', caseSensitive: false);
52
53// copyright blocks start with the first line matching this
54final List<RegExp> copyrightStatementLeadingPatterns = <RegExp>[
55  RegExp(r'^ *(?:Portions(?: are)? )?Copyright .+$', caseSensitive: false),
56  RegExp(r'^.*All rights? reserved\.$', caseSensitive: false),
57  RegExp(r'^ *\(C\) .+$', caseSensitive: false),
58  RegExp(r'^:copyright: .+$', caseSensitive: false),
59  RegExp(r'[-_a-zA-Z0-9()]+ function provided freely by .+'),
60  RegExp(r'^.+ optimized code \(C\) COPYRIGHT .+$', caseSensitive: false),
61  RegExp(r'©'),
62
63  // TODO(ianh): I wish there was a way around including the next few lines so many times in the output:
64  RegExp(r"^This file (?:is|was) part of the Independent JPEG Group's software[:.]$"),
65  RegExp(r'^It was modified by The libjpeg-turbo Project to include only code$'),
66  RegExp(r'^relevant to libjpeg-turbo\.$'),
67  RegExp(r'^It was modified by The libjpeg-turbo Project to include only code relevant$'),
68  RegExp(r'^to libjpeg-turbo\.$'),
69  RegExp(r'^It was modified by The libjpeg-turbo Project to include only code and$'),
70  RegExp(r'^information relevant to libjpeg-turbo\.$'),
71];
72
73// copyright blocks end with the last line that matches this, rest is considered license
74final List<RegExp> copyrightStatementPatterns = <RegExp>[
75  RegExp(r'^ *(?:Portions(?: created by the Initial Developer)?(?: are)? )?Copyright .+$', caseSensitive: false),
76  RegExp(r'^\(Version [-0-9.:, ]+ Copyright .+\)$', caseSensitive: false),
77  RegExp(r'^.*(?:All )?rights? reserved\.$', caseSensitive: false),
78  RegExp(r'^ *\(C\) .+$', caseSensitive: false),
79  RegExp(r'^:copyright: .+$', caseSensitive: false),
80  RegExp(r'^ *[0-9][0-9][0-9][0-9].+ [<(].+@.+[)>]$'),
81  RegExp(r'^                   [^ ].* [<(].+@.+[)>]$'), // that's exactly the number of spaces to line up with the X if "Copyright (c) 2011 X" is on the previous line
82  RegExp(r'^ *and .+$', caseSensitive: false),
83  RegExp(r'^ *others\.?$', caseSensitive: false),
84  RegExp(r'^for more details\.$', caseSensitive: false),
85  RegExp(r'^ *For more info read ([^ ]+)$', caseSensitive: false),
86  RegExp(r'^(?:Google )?Author\(?s?\)?: .+', caseSensitive: false),
87  RegExp(r'^Written by .+', caseSensitive: false),
88  RegExp(r'^Based on$', caseSensitive: false),
89  RegExp(r"^based on (?:code in )?['`][^'`]+['`]$", caseSensitive: false),
90  RegExp(r'^Based on .+, written by .+, [0-9]+\.$', caseSensitive: false),
91  RegExp(r'^(?:Based on the )?x86 SIMD extension for IJG JPEG library(?: - version [0-9.]+|,)?$'),
92  RegExp(r'^This software originally derived from .+\.$'),
93  RegExp(r'^Derived from .+, which was$'),
94  RegExp(r'^ *This is part of .+, a .+ library\.$'),
95  RegExp(r'^This file is part of [^ ]+\.$'),
96  RegExp(r'^(?:Modification )?[Dd]eveloped [-0-9]+ by .+\.$', caseSensitive: false),
97  RegExp(r'^Modified .+[:.]$', caseSensitive: false),
98  RegExp(r'^(?:[^ ]+ )?Modifications:$', caseSensitive: false),
99  RegExp(r'^ *Modifications for', caseSensitive: false),
100  RegExp(r'^ *Modifications of', caseSensitive: false),
101  RegExp(r'^Last changed in .+$', caseSensitive: false),
102  RegExp(r'[-_a-zA-Z0-9()]+ function provided freely by .+'), // TODO(ianh): file a bug on analyzer about what happens if you omit this comma
103  RegExp(r'^.+ optimized code \(C\) COPYRIGHT .+$', caseSensitive: false),
104  RegExp(r'^\(Royal Institute of Technology, Stockholm, Sweden\)\.$'),
105  RegExp(r'^\(?https?://[^ ]+$\)?'),
106
107  RegExp(r'^The Original Code is Mozilla Communicator client code, released$'),
108  RegExp(r'^March 31, 1998.$'), // mozilla first release date
109
110  RegExp(r'^The Elliptic Curve Public-Key Crypto Library \(ECC Code\) included$'),
111  RegExp(r'^herein is developed by SUN MICROSYSTEMS, INC\., and is contributed$'),
112  RegExp(r'^to the OpenSSL project\.$'),
113
114  RegExp(r'^This code is derived from software contributed to The NetBSD Foundation$'),
115  RegExp(r'^by (?:Atsushi Onoe|Dieter Baron|Klaus Klein|Luke Mewburn|Thomas Klausner|,| |and)*\.$'),
116
117  RegExp(r'^FT_Raccess_Get_HeaderInfo\(\) and raccess_guess_darwin_hfsplus\(\) are$'),
118  RegExp(r'^derived from ftobjs\.c\.$'),
119
120  // TODO(ianh): I wish there was a way around including the next few lines so many times in the output:
121  RegExp(r"^This file (?:is|was) part of the Independent JPEG Group's software[:.]$"),
122  RegExp(r'^It was modified by The libjpeg-turbo Project to include only code$'),
123  RegExp(r'^relevant to libjpeg-turbo\.$'),
124  RegExp(r'^It was modified by The libjpeg-turbo Project to include only code relevant$'),
125  RegExp(r'^to libjpeg-turbo\.$'),
126  RegExp(r'^It was modified by The libjpeg-turbo Project to include only code and$'),
127  RegExp(r'^information relevant to libjpeg-turbo\.$'),
128
129  RegExp(r'^All or some portions of this file are derived from material licensed$'),
130  RegExp(r'^to the University of California by American Telephone and Telegraph$'),
131  RegExp(r'^Co\. or Unix System Laboratories, Inc\. and are reproduced herein with$'),
132  RegExp(r'^the permission of UNIX System Laboratories, Inc.$'),
133
134  RegExp(r'^This software was developed by the Computer Systems Engineering group$'),
135  RegExp(r'^at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and$'),
136  RegExp(r'^contributed to Berkeley\.$'),
137
138  RegExp(r'^This code is derived from software contributed to Berkeley by$'),
139  RegExp(r'^Ralph Campbell\. +This file is derived from the MIPS RISC$'),
140  RegExp(r'^Architecture book by Gerry Kane\.$'),
141
142  RegExp(r'^All advertising materials mentioning features or use of this software$'),
143  RegExp(r'^must display the following acknowledgement:$'),
144  RegExp(r'^This product includes software developed by the University of$'),
145  RegExp(r'^California, Lawrence Berkeley Laboratory\.$'),
146
147  RegExp(r'^ *Condition of use and distribution are the same than zlib :$'),
148  RegExp(r'^The MIT License:$'),
149
150  RegExp(r'^$'), // TODO(ianh): file an issue on what happens if you omit the close quote
151
152];
153
154// patterns that indicate we're running into another license
155final List<RegExp> licenseFragments = <RegExp>[
156  RegExp(r'"as is" without express or implied warranty\.'),
157  RegExp(r'version of this file under any of the LGPL, the MPL or the GPL\.'),
158  RegExp(r'SUCH DAMAGE\.'),
159  RegExp(r'found in the LICENSE file'),
160  RegExp(r'<http://www\.gnu\.org/licenses/>'),
161  RegExp(r'License & terms of use'),
162];
163
164const String _linebreak      = r' *(?:(?:\*/ *|[*#])?(?:\n\1 *(?:\*/ *)?)*\n\1\2 *)?';
165const String _linebreakLoose = r' *(?:(?:\*/ *|[*#])?\n(?:-|;|#|<|!|/|\*| |REM)*)*';
166
167// LICENSE RECOGNIZERS
168
169final RegExp lrApache = RegExp(r'^(?: |\r|\n)*Apache License\b');
170final RegExp lrMPL = RegExp(r'^(?: |\r|\n)*Mozilla Public License Version 2\.0\n');
171final RegExp lrGPL = RegExp(r'^(?: |\r|\n)*GNU GENERAL PUBLIC LICENSE\n');
172final RegExp lrAPSL = RegExp(r'^APPLE PUBLIC SOURCE LICENSE Version 2\.0 +- +August 6, 2003');
173final RegExp lrMIT = RegExp(r'Permission(?: |\n)+is(?: |\n)+hereby(?: |\n)+granted,(?: |\n)+free(?: |\n)+of(?: |\n)+charge,(?: |\n)+to(?: |\n)+any(?: |\n)+person(?: |\n)+obtaining(?: |\n)+a(?: |\n)+copy(?: |\n)+of(?: |\n)+this(?: |\n)+software(?: |\n)+and(?: |\n)+associated(?: |\n)+documentation(?: |\n)+files(?: |\n)+\(the(?: |\n)+"Software"\),(?: |\n)+to(?: |\n)+deal(?: |\n)+in(?: |\n)+the(?: |\n)+Software(?: |\n)+without(?: |\n)+restriction,(?: |\n)+including(?: |\n)+without(?: |\n)+limitation(?: |\n)+the(?: |\n)+rights(?: |\n)+to(?: |\n)+use,(?: |\n)+copy,(?: |\n)+modify,(?: |\n)+merge,(?: |\n)+publish,(?: |\n)+distribute,(?: |\n)+sublicense,(?: |\n)+and/or(?: |\n)+sell(?: |\n)+copies(?: |\n)+of(?: |\n)+the(?: |\n)+Software,(?: |\n)+and(?: |\n)+to(?: |\n)+permit(?: |\n)+persons(?: |\n)+to(?: |\n)+whom(?: |\n)+the(?: |\n)+Software(?: |\n)+is(?: |\n)+furnished(?: |\n)+to(?: |\n)+do(?: |\n)+so,(?: |\n)+subject(?: |\n)+to(?: |\n)+the(?: |\n)+following(?: |\n)+conditions:');
174final RegExp lrOpenSSL = RegExp(r'Copyright \(c\) 1998-2011 The OpenSSL Project\.  All rights reserved\.(.|\n)*Original SSLeay License');
175final RegExp lrBSD = RegExp(r'Redistribution(?: |\n)+and(?: |\n)+use(?: |\n)+in(?: |\n)+source(?: |\n)+and(?: |\n)+binary(?: |\n)+forms(?:(?: |\n)+of(?: |\n)+the(?: |\n)+software(?: |\n)+as(?: |\n)+well(?: |\n)+as(?: |\n)+documentation)?,(?: |\n)+with(?: |\n)+or(?: |\n)+without(?: |\n)+modification,(?: |\n)+are(?: |\n)+permitted(?: |\n)+provided(?: |\n)+that(?: |\n)+the(?: |\n)+following(?: |\n)+conditions(?: |\n)+are(?: |\n)+met:');
176final RegExp lrZlib = RegExp(r'Permission(?: |\n)+is(?: |\n)+granted(?: |\n)+to(?: |\n)+anyone(?: |\n)+to(?: |\n)+use(?: |\n)+this(?: |\n)+software(?: |\n)+for(?: |\n)+any(?: |\n)+purpose,(?: |\n)+including(?: |\n)+commercial(?: |\n)+applications,(?: |\n)+and(?: |\n)+to(?: |\n)+alter(?: |\n)+it(?: |\n)+and(?: |\n)+redistribute(?: |\n)+it(?: |\n)+freely,(?: |\n)+subject(?: |\n)+to(?: |\n)+the(?: |\n)+following(?: |\n)+restrictions:');
177final RegExp lrPNG = RegExp(r'This code is released under the libpng license\.');
178final RegExp lrBison = RegExp(r'This special exception was added by the Free Software Foundation in *\n *version 2.2 of Bison.');
179
180
181// "NO COPYRIGHT" STATEMENTS
182
183final List<RegExp> csNoCopyrights = <RegExp>[
184
185  // used with _tryNone
186  // groups are ignored
187
188  // Seen in Expat files
189  RegExp(
190    r'^// No copyright notice; this file based on autogenerated header',
191    multiLine: true,
192    caseSensitive: false
193  ),
194
195  // Seen in Android NDK
196  RegExp(
197    r'^[/* ]*This header was automatically generated from a Linux kernel header\n'
198    r'^[/* ]*of the same name, to make information necessary for userspace to\n'
199    r'^[/* ]*call into the kernel available to libc.  It contains only constants,\n'
200    r'^[/* ]*structures, and macros generated from the original header, and thus,\n'
201    r'^[/* ]*contains no copyrightable information.',
202    multiLine: true,
203    caseSensitive: false
204  ),
205
206  RegExp(
207    kIndent +
208    r'These constants were taken from version 3 of the DWARF standard, *\n'
209    r'^\1\2which is Copyright \(c\) 2005 Free Standards Group, and *\n'
210    r'^\1\2Copyright \(c\) 1992, 1993 UNIX International, Inc\. *\n',
211    multiLine: true,
212    caseSensitive: false
213  ),
214
215  // Freetype
216  RegExp(
217    kIndent +
218    (r'This is a dummy file, used to please the build system\. It is never included by the auto-fitter sources\.'.replaceAll(' ', _linebreak)),
219    multiLine: true,
220    caseSensitive: false
221  ),
222
223  // Freetype
224  RegExp(
225    kIndent +
226    (
227      r'This software was written by Alexander Peslyak in 2001\. No copyright is '
228      r'claimed, and the software is hereby placed in the public domain\. In case '
229      r'this attempt to disclaim copyright and place the software in the public '
230      r'domain is deemed null and void, then the software is Copyright \(c\) 2001 '
231      r'Alexander Peslyak and it is hereby released to the general public under the '
232      r'following terms: Redistribution and use in source and binary forms, with or '
233      r"without modification, are permitted\. There\'s ABSOLUTELY NO WARRANTY, "
234      r'express or implied\.(?: \(This is a heavily cut-down "BSD license"\.\))?'
235      .replaceAll(' ', _linebreak)
236    ),
237    multiLine: true,
238    caseSensitive: false
239  ),
240
241];
242
243
244// ATTRIBUTION STATEMENTS
245
246final List<RegExp> csAttribution = <RegExp>[
247
248  // used with _tryAttribution
249  // group 1 is the prefix, group 2 is the attribution
250
251  // Seen in musl in Android SDK
252  RegExp(
253    r'^([/* ]*)This code was written by (.+) in [0-9]+; no copyright is claimed\.\n'
254    r'^\1This code is in the public domain\. +Attribution is appreciated but\n'
255    r'^\1unnecessary\.',
256    multiLine: true,
257    caseSensitive: false
258  ),
259
260];
261
262
263// REFERENCES TO OTHER FILES
264
265class LicenseFileReferencePattern {
266  LicenseFileReferencePattern({
267    this.firstPrefixIndex,
268    this.indentPrefixIndex,
269    this.copyrightIndex,
270    this.authorIndex,
271    this.fileIndex,
272    this.pattern,
273    this.needsCopyright = true
274  });
275  final int firstPrefixIndex;
276  final int indentPrefixIndex;
277  final int copyrightIndex;
278  final int authorIndex;
279  final int fileIndex;
280  final bool needsCopyright;
281  final RegExp pattern;
282}
283
284final List<LicenseFileReferencePattern> csReferencesByFilename = <LicenseFileReferencePattern>[
285
286  // used with _tryReferenceByFilename
287
288  // libpng files
289  LicenseFileReferencePattern(
290    firstPrefixIndex: 1,
291    indentPrefixIndex: 2,
292    fileIndex: 3,
293    needsCopyright: true,
294    pattern: RegExp(
295      kIndent +
296      r'This code is released under the libpng license. For conditions of distribution and use, see the disclaimer and license in (png.h)\b'.replaceAll(' ', _linebreak),
297      multiLine: true,
298      caseSensitive: false
299    ),
300  ),
301
302  // typical of much Google-written code
303  LicenseFileReferencePattern(
304    firstPrefixIndex: 1,
305    indentPrefixIndex: 2,
306    fileIndex: 3,
307    pattern: RegExp(
308      kIndent +
309      r'Use of this source(?: code)? is governed by a BS?D-style license that can be found in the '.replaceAll(' ', _linebreak) +
310      r'([^ ]+) file\b(?! or at)',
311      multiLine: true,
312      caseSensitive: false,
313    )
314  ),
315
316  // Mojo code
317  LicenseFileReferencePattern(
318    firstPrefixIndex: 1,
319    indentPrefixIndex: 2,
320    copyrightIndex: 3,
321    authorIndex: 4,
322    fileIndex: 5,
323    pattern: RegExp(
324      kIndent +
325      r'(Copyright .+(the .+ authors)\. +All rights reserved.) +' +
326      r'Use of this source(?: code)? is governed by a BS?D-style license that can be found in the '.replaceAll(' ', _linebreak) +
327      r'([^ ]+) file\b(?! or at)',
328      multiLine: true,
329      caseSensitive: false,
330    )
331  ),
332
333  // ANGLE .json files
334  LicenseFileReferencePattern(
335    firstPrefixIndex: 1,
336    indentPrefixIndex: 2,
337    copyrightIndex: 3,
338    authorIndex: 4,
339    fileIndex: 5,
340    pattern: RegExp(
341      kIndent +
342      r'(Copyright .+(The .+ Authors)\. +All rights reserved.)", *\n'
343      r'^\1\2Use of this source code is governed by a BSD-style license that can be", *\n'
344      r'^\1\2found in the ([^ ]+) file.",',
345      multiLine: true,
346      caseSensitive: false,
347    )
348  ),
349
350  // typical of Dart-derived files
351  LicenseFileReferencePattern(
352    firstPrefixIndex: 2,
353    indentPrefixIndex: 3,
354    copyrightIndex: 1,
355    authorIndex: 4,
356    fileIndex: 5,
357    pattern: RegExp(
358      r'(' + kIndent +
359      r'Copyright .+(the .+ authors)\[?\. '
360      r'Please see the AUTHORS file for details. All rights (?:re|solve)served\.) '
361      r'Use of this source(?: code)? is governed by a BS?D-style license '
362      r'that can be found in the '.replaceAll(' ', _linebreakLoose) +
363      r'([^ ]+) file\b(?! or at)',
364      multiLine: true,
365      caseSensitive: false,
366    )
367  ),
368
369  // Seen in libjpeg-turbo
370  LicenseFileReferencePattern(
371    firstPrefixIndex: 1,
372    indentPrefixIndex: 2,
373    fileIndex: 3,
374    pattern: RegExp(
375      kIndent + r'For conditions of distribution and use, see (?:the accompanying|copyright notice in)? ([-_.a-zA-Z0-9]+)',
376      multiLine: true,
377      caseSensitive: false,
378    )
379  ),
380
381  // Seen in Expat files
382  LicenseFileReferencePattern(
383    firstPrefixIndex: 1,
384    indentPrefixIndex: 2,
385    fileIndex: 3,
386    pattern: RegExp(
387      kIndent + r'See the file ([^ ]+) for copying permission\.',
388      multiLine: true,
389      caseSensitive: false,
390    )
391  ),
392
393  // Seen in Expat files
394  LicenseFileReferencePattern(
395    firstPrefixIndex: 1,
396    indentPrefixIndex: 2,
397    fileIndex: 3,
398    pattern: RegExp(
399      kIndent +
400      r'This is free software. You are permitted to copy, distribute, or modify *\n'
401      r'^\1\2it under the terms of the MIT/X license \(contained in the ([^ ]+) file *\n'
402      r'^\1\2with this distribution\.\)',
403      multiLine: true,
404      caseSensitive: false,
405    )
406  ),
407
408  // Seen in FreeType software
409  LicenseFileReferencePattern(
410    firstPrefixIndex: 1,
411    indentPrefixIndex: 2,
412    fileIndex: 3,
413    pattern: RegExp(
414      kIndent +
415      r'This file (?:is part of the FreeType project, and )?may only be used,? '
416      r'modified,? and distributed under the terms of the FreeType project '
417      r'license, (LICENSE\.TXT). By continuing to use, modify, or distribute this '
418      r'file you indicate that you have read the license and understand and '
419      r'accept it fully\.'.replaceAll(' ', _linebreak),
420      multiLine: true,
421      caseSensitive: false,
422    )
423  ),
424
425  // Seen in FreeType cff software from Adobe
426  LicenseFileReferencePattern(
427    firstPrefixIndex: 1,
428    indentPrefixIndex: 2,
429    fileIndex: 3,
430    pattern: RegExp(
431      kIndent +
432      r'This software, and all works of authorship, whether in source or '
433      r'object code form as indicated by the copyright notice\(s\) included '
434      r'herein \(collectively, the "Work"\) is made available, and may only be '
435      r'used, modified, and distributed under the FreeType Project License, '
436      r'(LICENSE\.TXT)\. Additionally, subject to the terms and conditions of the '
437      r'FreeType Project License, each contributor to the Work hereby grants '
438      r'to any individual or legal entity exercising permissions granted by '
439      r'the FreeType Project License and this section \(hereafter, "You" or '
440      r'"Your"\) a perpetual, worldwide, non-exclusive, no-charge, '
441      r'royalty-free, irrevocable \(except as stated in this section\) patent '
442      r'license to make, have made, use, offer to sell, sell, import, and '
443      r'otherwise transfer the Work, where such license applies only to those '
444      r'patent claims licensable by such contributor that are necessarily '
445      r'infringed by their contribution\(s\) alone or by combination of their '
446      r'contribution\(s\) with the Work to which such contribution\(s\) was '
447      r'submitted\. If You institute patent litigation against any entity '
448      r'\(including a cross-claim or counterclaim in a lawsuit\) alleging that '
449      r'the Work or a contribution incorporated within the Work constitutes '
450      r'direct or contributory patent infringement, then any patent licenses '
451      r'granted to You under this License for that Work shall terminate as of '
452      r'the date such litigation is filed\. '
453      r'By using, modifying, or distributing the Work you indicate that you '
454      r'have read and understood the terms and conditions of the '
455      r'FreeType Project License as well as those provided in this section, '
456      r'and you accept them fully\.'.replaceAll(' ', _linebreak),
457      multiLine: true,
458      caseSensitive: false,
459    )
460  ),
461
462  // Seen in Jinja files
463  LicenseFileReferencePattern(
464    firstPrefixIndex: 1,
465    indentPrefixIndex: 2,
466    fileIndex: 3,
467    pattern: RegExp(
468      kIndent + r':license: [A-Z0-9]+, see (.+) for more details\.',
469      multiLine: true,
470      caseSensitive: false,
471    )
472  ),
473
474  // Seen in modp_b64
475  LicenseFileReferencePattern(
476    firstPrefixIndex: 1,
477    indentPrefixIndex: 2,
478    fileIndex: 3,
479    pattern: RegExp(
480      kIndent + r'Released under [^ ]+ license\. +See ([^ ]+) for details\.$',
481      multiLine: true,
482      caseSensitive: false,
483    )
484  ),
485
486  // Seen in libxml files
487  LicenseFileReferencePattern(
488    firstPrefixIndex: 1,
489    indentPrefixIndex: 2,
490    fileIndex: 3,
491    pattern: RegExp(
492      kIndent + r'(?:Copy: )?See ([A-Z0-9]+) for the status of this software\.?',
493      multiLine: true,
494      caseSensitive: false,
495    )
496  ),
497
498  // Seen in libxml files
499  LicenseFileReferencePattern(
500    firstPrefixIndex: 1,
501    indentPrefixIndex: 2,
502    fileIndex: 3,
503    needsCopyright: false,
504    pattern: RegExp(
505      kIndent +
506      r'// This file is dual licensed under the MIT and the University of Illinois Open *\n'
507      r'^\1\2// Source Licenses. See (LICENSE\.TXT) for details\.',
508      multiLine: true,
509      caseSensitive: false,
510    )
511  ),
512
513  // BoringSSL
514  LicenseFileReferencePattern(
515    firstPrefixIndex: 1,
516    indentPrefixIndex: 2,
517    fileIndex: 3,
518    needsCopyright: true,
519    pattern: RegExp(
520      kIndent +
521      r'Licensed under the OpenSSL license \(the "License"\)\. You may not use '
522      r'this file except in compliance with the License\. You can obtain a copy '
523      r'in the file (LICENSE) in the source distribution or at '
524      r'https://www\.openssl\.org/source/license\.html'
525      .replaceAll(' ', _linebreak),
526      multiLine: true,
527      caseSensitive: false,
528    )
529  ),
530
531  // Seen in Fuchsia SDK files
532  LicenseFileReferencePattern(
533    firstPrefixIndex: 1,
534    indentPrefixIndex: 2,
535    fileIndex: 3,
536    needsCopyright: false,
537    pattern: RegExp(
538      kIndent +
539      r'Copyright .+\. All rights reserved\. '
540      r'This is a GENERATED file, see //zircon/.+/abigen\. '
541      r'The license governing this file can be found in the (LICENSE) file\.'
542      .replaceAll(' ', _linebreak),
543      multiLine: true,
544      caseSensitive: false,
545    )
546  ),
547
548  // Seen in Fuchsia SDK files.
549  // TODO(chinmaygarde): This is a broken license file that is being patched
550  // upstream. Remove this once DX-1477 is patched.
551  LicenseFileReferencePattern(
552    firstPrefixIndex: 1,
553    indentPrefixIndex: 2,
554    fileIndex: 3,
555    needsCopyright: false,
556    pattern: RegExp(
557      kIndent +
558      r'Use of this source code is governed by a BSD-style license that can be '
559      r'Copyright .+\. All rights reserved\. '
560      r'found in the (LICENSE) file\.'
561      .replaceAll(' ', _linebreak),
562      multiLine: true,
563      caseSensitive: false,
564    )
565  ),
566
567];
568
569
570// INDIRECT REFERENCES TO OTHER FILES
571
572final List<RegExp> csReferencesByType = <RegExp>[
573
574  // used with _tryReferenceByType
575  // groups 1 and 2 are the prefix, group 3 is the license type
576
577  // Seen in Jinja files, markupsafe files
578  RegExp(
579    kIndent + r':license: ([A-Z0-9]+)',
580    multiLine: true,
581    caseSensitive: false
582  ),
583
584  RegExp(
585    kIndent +
586    r'This software is made available under the terms of the (ICU) License -- ICU 1\.\8\.1 and later\.'.replaceAll(' ', _linebreak),
587    multiLine: true,
588    caseSensitive: false
589  ),
590
591  RegExp(
592    kIndent +
593    (
594      r'(?:@APPLE_LICENSE_HEADER_START@)? '
595      r'This file contains Original Code and/or Modifications of Original Code '
596      r'as defined in and that are subject to the (Apple Public Source License) '
597      r"Version (2\.0) \(the 'License'\)\. You may not use this file except in "
598      r'compliance with the License\. Please obtain a copy of the License at '
599      r'(http://www\.opensource\.apple\.com/apsl/) and read it before using this '
600      r'file\. '
601      r'The Original Code and all software distributed under the License are '
602      r"distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER "
603      r'EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, '
604      r'INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, '
605      r'FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT\. '
606      r'Please see the License for the specific language governing rights and '
607      r'limitations under the License\.'
608      r'(?:@APPLE_LICENSE_HEADER_END@)? '
609      .replaceAll(' ', _linebreak)
610    ),
611    multiLine: true,
612    caseSensitive: false
613  ),
614
615];
616
617final List<RegExp> csReferencesByTypeNoCopyright = <RegExp>[
618
619  // used with _tryReferenceByType
620  // groups 1 and 2 are the prefix, group 3 is the license type
621
622  RegExp(
623    kIndent +
624    r'Written by Andy Polyakov <appro@openssl\.org> for the OpenSSL '
625    r'project\. The module is, however, dual licensed under (OpenSSL) and '
626    r'CRYPTOGAMS licenses depending on where you obtain it\. For further '
627    r'details see http://www\.openssl\.org/~appro/cryptogams/\. '
628    r'Permission to use under GPL terms is granted\.'.replaceAll(' ', _linebreak),
629    multiLine: true,
630    caseSensitive: false
631  ),
632
633];
634
635class MultipleVersionedLicenseReferencePattern {
636  MultipleVersionedLicenseReferencePattern({
637    this.firstPrefixIndex,
638    this.indentPrefixIndex,
639    this.licenseIndices,
640    this.versionIndicies,
641    this.checkLocalFirst = true,
642    this.pattern
643  });
644
645  final int firstPrefixIndex;
646  final int indentPrefixIndex;
647  final List<int> licenseIndices;
648  final bool checkLocalFirst;
649  final Map<int, int> versionIndicies;
650  final RegExp pattern;
651}
652
653final List<MultipleVersionedLicenseReferencePattern> csReferencesByUrl = <MultipleVersionedLicenseReferencePattern>[
654
655  // used with _tryReferenceByUrl
656
657  // AFL
658  MultipleVersionedLicenseReferencePattern(
659    firstPrefixIndex: 1,
660    indentPrefixIndex: 2,
661    licenseIndices: const <int>[3],
662    versionIndicies: const <int, int>{ 3:4 },
663    checkLocalFirst: false,
664    pattern: RegExp(
665      kIndent + r'Licensed under the (Academic Free License) version (3\.0)',
666      multiLine: true,
667      caseSensitive: false,
668    )
669  ),
670
671  // Eclipse
672  // Seen in auto-generated Java code in the Dart repository.
673  MultipleVersionedLicenseReferencePattern(
674    firstPrefixIndex: 1,
675    indentPrefixIndex: 2,
676    licenseIndices: const <int>[3],
677    checkLocalFirst: false,
678    pattern: RegExp(
679      r'^(?:[-;#<!.\\"/* ]*[-;#<!.\"/*]+)?( *)Licensed under the Eclipse Public License v1\.0 \(the "License"\); you may not use this file except *\n'
680      r'^\1\2in compliance with the License\. +You may obtain a copy of the License at *\n'
681      r'^\1\2 *\n'
682      r'^\1\2 *(http://www\.eclipse\.org/legal/epl-v10\.html) *\n'
683      r'^\1\2 *\n'
684      r'^\1\2Unless required by applicable law or agreed to in writing, software distributed under the License *\n'
685      r'^\1\2is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express *\n'
686      r'^\1\2or implied\. +See the License for the specific language governing permissions and limitations under *\n'
687      r'^\1\2the License\.',
688      multiLine: true,
689      caseSensitive: false,
690    )
691  ),
692
693  // Apache reference.
694  // Seen in Android code.
695  // TODO(ianh): For this license we only need to include the text once, not once per copyright
696  // TODO(ianh): For this license we must also include all the NOTICE text (see section 4d)
697  MultipleVersionedLicenseReferencePattern(
698    firstPrefixIndex: 1,
699    indentPrefixIndex: 2,
700    licenseIndices: const <int>[3],
701    checkLocalFirst: false,
702    pattern: RegExp(
703      kIndent +
704      r'Licensed under the Apache License, Version 2\.0 \(the "License"\); *\n'
705      r'^\1\2you may not use this file except in compliance with the License\. *\n'
706      r'^\1\2You may obtain a copy of the License at *\n'
707      r'^(?:(?:\1\2? *)? *\n)*'
708      r'^\1\2 *(https?://www\.apache\.org/licenses/LICENSE-2\.0) *\n'
709      r'^(?:(?:\1\2? *)? *\n)*'
710      r'^\1\2Unless required by applicable law or agreed to in writing, software *\n'
711      r'^\1\2distributed under the License is distributed on an "AS IS" BASIS, *\n'
712      r'^\1\2WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\. *\n'
713      r'^\1\2See the License for the specific language governing permissions and *\n'
714      r'^\1\2limitations under the License\.',
715      multiLine: true,
716      caseSensitive: false,
717    )
718  ),
719
720  // BSD
721  MultipleVersionedLicenseReferencePattern(
722    firstPrefixIndex: 1,
723    indentPrefixIndex: 2,
724    licenseIndices: const <int>[3],
725    checkLocalFirst: false,
726    pattern: RegExp(
727      kIndent +
728      r'Use of this source code is governed by a BS?D-style *\n'
729      r'^\1\2license that can be found in the LICENSE file or at *\n'
730      r'^\1\2(https://developers.google.com/open-source/licenses/bsd)',
731      multiLine: true,
732      caseSensitive: false,
733    )
734  ),
735
736  // MIT
737  MultipleVersionedLicenseReferencePattern(
738    firstPrefixIndex: 1,
739    indentPrefixIndex: 2,
740    licenseIndices: const <int>[3],
741    checkLocalFirst: false,
742    pattern: RegExp(
743      kIndent +
744      (
745       r'Use of this source code is governed by a MIT-style '
746       r'license that can be found in the LICENSE file or at '
747       r'(https://opensource.org/licenses/MIT)'
748       .replaceAll(' ', _linebreak)
749      ),
750      multiLine: true,
751      caseSensitive: false,
752    )
753  ),
754
755  // MIT
756  // the crazy s/./->/ thing is someone being over-eager with search-and-replace in rapidjson
757  MultipleVersionedLicenseReferencePattern(
758    firstPrefixIndex: 1,
759    indentPrefixIndex: 2,
760    licenseIndices: const <int>[3],
761    checkLocalFirst: false,
762    pattern: RegExp(
763      kIndent +
764      r'Licensed under the MIT License \(the "License"\); you may not use this file except *\n'
765      r'^\1\2in compliance with the License(?:\.|->) You may obtain a copy of the License at *\n'
766      r'^\1\n'
767      r'^\1\2(http://opensource(?:\.|->)org/licenses/MIT) *\n'
768      r'^\1\n'
769      r'^\1\2Unless required by applicable law or agreed to in writing, software distributed *\n'
770      r'^\1\2under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR *\n'
771      r'^\1\2CONDITIONS OF ANY KIND, either express or implied(?:\.|->) See the License for the *\n'
772      r'^\1\2specific language governing permissions and limitations under the License(?:\.|->)',
773      multiLine: true,
774      caseSensitive: false,
775    )
776  ),
777
778  // Observatory (polymer)
779  MultipleVersionedLicenseReferencePattern(
780    firstPrefixIndex: 1,
781    indentPrefixIndex: 2,
782    licenseIndices: const <int>[3],
783    checkLocalFirst: false,
784    pattern: RegExp(
785      kIndent +
786      r'This code may only be used under the BSD style license found at (http://polymer.github.io/LICENSE.txt)$',
787      multiLine: true,
788      caseSensitive: false,
789    )
790  ),
791
792  // ashmem
793  MultipleVersionedLicenseReferencePattern(
794    firstPrefixIndex: 1,
795    indentPrefixIndex: 2,
796    licenseIndices: const <int>[3],
797    versionIndicies: const <int, int>{3:4},
798    checkLocalFirst: false,
799    pattern: RegExp(
800      kIndent +
801      r'This file is dual licensed. +It may be redistributed and/or modified *\n'
802      r'^\1\2under the terms of the (Apache) (2\.0) License OR version 2 of the GNU *\n'
803      r'^\1\2General Public License\.',
804      multiLine: true,
805      caseSensitive: false,
806    )
807  ),
808
809  // GNU ISO C++ GPL+Exception
810  // Seen in gnu-libstdc++ in Android NDK
811  MultipleVersionedLicenseReferencePattern(
812    firstPrefixIndex: 1,
813    indentPrefixIndex: 2,
814    licenseIndices: const <int>[5, 6],
815    versionIndicies: const <int, int>{5:3, 6:4},
816    pattern: RegExp(
817      kIndent +
818      r'This file is part of the GNU ISO C\+\+ Library\. +This library is free *\n'
819      r'^\1\2software; you can redistribute _?_?it and/or modify _?_?it under the terms *\n'
820      r'^\1\2of the GNU General Public License as published by the Free Software *\n'
821      r'^\1\2Foundation; either version (3), or \(at your option\) any later *\n'
822      r'^\1\2version\. *\n'
823      r'^(?:(?:\1\2? *)? *\n)*'
824      r'^\1\2This library is distributed in the hope that _?_?it will be useful, but *\n'
825      r'^\1\2WITHOUT ANY WARRANTY; without even the implied warranty of *\n'
826      r'^\1\2MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\. +See the GNU *\n'
827      r'^\1\2General Public License for more details\. *\n'
828      r'^(?:(?:\1\2? *)? *\n)*'
829      r'^\1\2Under Section 7 of GPL version \3, you are granted additional *\n'
830      r'^\1\2permissions described in the GCC Runtime Library Exception, version *\n'
831      r'^\1\2(3\.1), as published by the Free Software Foundation\. *\n'
832      r'^(?:(?:\1\2? *)? *\n)*'
833      r'^\1\2You should have received a copy of the GNU General Public License and *\n'
834      r'^\1\2a copy of the GCC Runtime Library Exception along with this program; *\n'
835      r'^\1\2see the files (COPYING3) and (COPYING\.RUNTIME) respectively\. +If not, see *\n'
836      r'^\1\2<http://www\.gnu\.org/licenses/>\.',
837      multiLine: true,
838      caseSensitive: false,
839    )
840  ),
841
842  // GNU ISO C++ GPL+Exception, alternative wrapping
843  // Seen in gnu-libstdc++ in Android NDK
844  MultipleVersionedLicenseReferencePattern(
845    firstPrefixIndex: 1,
846    indentPrefixIndex: 2,
847    licenseIndices: const <int>[5, 6],
848    versionIndicies: const <int, int>{5:3, 6:4},
849    pattern: RegExp(
850      kIndent +
851      r'This file is part of the GNU ISO C\+\+ Library\. +This library is free *\n'
852      r'^\1\2software; you can redistribute it and/or modify it under the *\n'
853      r'^\1\2terms of the GNU General Public License as published by the *\n'
854      r'^\1\2Free Software Foundation; either version (3), or \(at your option\) *\n'
855      r'^\1\2any later version\. *\n'
856      r'^(?:(?:\1\2? *)? *\n)*'
857      r'^\1\2This library is distributed in the hope that it will be useful, *\n'
858      r'^\1\2but WITHOUT ANY WARRANTY; without even the implied warranty of *\n'
859      r'^\1\2MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\. +See the *\n'
860      r'^\1\2GNU General Public License for more details\. *\n'
861      r'^(?:(?:\1\2? *)? *\n)*'
862      r'^\1\2Under Section 7 of GPL version \3, you are granted additional *\n'
863      r'^\1\2permissions described in the GCC Runtime Library Exception, version *\n'
864      r'^\1\2(3\.1), as published by the(?:, 2009)? Free Software Foundation\. *\n'
865      r'^(?:(?:\1\2? *)? *\n)*'
866      r'^\1\2You should have received a copy of the GNU General Public License and *\n'
867      r'^\1\2a copy of the GCC Runtime Library Exception along with this program; *\n'
868      r'^\1\2see the files (COPYING3) and (COPYING\.RUNTIME) respectively\. +If not, see *\n'
869      r'^\1\2<http://www\.gnu\.org/licenses/>\.',
870      multiLine: true,
871      caseSensitive: false,
872    )
873  ),
874
875  // GNU ISO C++ GPL+Exception, alternative footer without exception filename
876  // Seen in gnu-libstdc++ in Android NDK
877  MultipleVersionedLicenseReferencePattern(
878    firstPrefixIndex: 1,
879    indentPrefixIndex: 2,
880    licenseIndices: const <int>[6, 4],
881    versionIndicies: const <int, int>{6:3, 4:5},
882    pattern: RegExp(
883      kIndent +
884      r'This file is part of the GNU ISO C\+\+ Library\. +This library is free *\n'
885      r'^\1\2software; you can redistribute it and/or modify it under the *\n'
886      r'^\1\2terms of the GNU General Public License as published by the *\n'
887      r'^\1\2Free Software Foundation; either version (3), or \(at your option\) *\n' // group 3 is the version of the gpl
888      r'^\1\2any later version\. *\n'
889      r'^(?:(?:\1\2? *)? *\n)*'
890      r'^\1\2This library is distributed in the hope that it will be useful, *\n'
891      r'^\1\2but WITHOUT ANY WARRANTY; without even the implied warranty of *\n'
892      r'^\1\2MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\. +See the *\n'
893      r'^\1\2GNU General Public License for more details\. *\n'
894      r'^(?:(?:\1\2? *)? *\n)*'
895      r'^\1\2Under Section 7 of GPL version \3, you are granted additional *\n'
896      r'^\1\2permissions described in the (GCC Runtime Library Exception), version *\n' // group 4 is the "file name" of the exception (it's missing in this version, so we use this as a hook to later, see the url mappings)
897      r'^\1\2(3\.1), as published by the Free Software Foundation\. *\n' // group 5 is the version of the exception
898      r'^(?:(?:\1\2? *)? *\n)*'
899      r'^\1\2You should have received a copy of the GNU General Public License along *\n'
900      r'^\1\2with this library; see the file (COPYING3)\. +If not see *\n' // group 6 is the gpl file name
901      r'^\1\2<http://www\.gnu\.org/licenses/>\.',
902      multiLine: true,
903      caseSensitive: false,
904    )
905  ),
906
907  // GCC GPL+Exception
908  // Seen in gnu-libstdc++ in Android NDK
909  MultipleVersionedLicenseReferencePattern(
910    firstPrefixIndex: 1,
911    indentPrefixIndex: 2,
912    licenseIndices: const <int>[5, 6],
913    versionIndicies: const <int, int>{5:3, 6:4},
914    pattern: RegExp(
915      kIndent +
916      r'This file is part of GCC. *\n'
917      r'^(?:(?:\1\2? *)? *\n)*'
918      r'^\1\2GCC is free software; you can redistribute it and/or modify it under *\n'
919      r'^\1\2the terms of the GNU General Public License as published by the Free *\n'
920      r'^\1\2Software Foundation; either version (3), or \(at your option\) any later *\n'
921      r'^\1\2version\. *\n'
922      r'^(?:(?:\1\2? *)? *\n)*'
923      r'^\1\2GCC is distributed in the hope that it will be useful, but WITHOUT ANY *\n'
924      r'^\1\2WARRANTY; without even the implied warranty of MERCHANTABILITY or *\n'
925      r'^\1\2FITNESS FOR A PARTICULAR PURPOSE\. +See the GNU General Public License *\n'
926      r'^\1\2for more details\. *\n'
927      r'^(?:(?:\1\2? *)? *\n)*'
928      r'^\1\2Under Section 7 of GPL version \3, you are granted additional *\n'
929      r'^\1\2permissions described in the GCC Runtime Library Exception, version *\n'
930      r'^\1\2(3\.1), as published by the Free Software Foundation\. *\n'
931      r'^(?:(?:\1\2? *)? *\n)*'
932      r'^\1\2You should have received a copy of the GNU General Public License and *\n'
933      r'^\1\2a copy of the GCC Runtime Library Exception along with this program; *\n'
934      r'^\1\2see the files (COPYING3) and (COPYING\.RUNTIME) respectively\. +If not, see *\n'
935      r'^\1\2<http://www\.gnu\.org/licenses/>\.',
936      multiLine: true,
937      caseSensitive: false,
938    )
939  ),
940
941  // GCC GPL+Exception, alternative line wrapping
942  // Seen in gnu-libstdc++ in Android NDK
943  MultipleVersionedLicenseReferencePattern(
944    firstPrefixIndex: 1,
945    indentPrefixIndex: 2,
946    licenseIndices: const <int>[5, 6],
947    versionIndicies: const <int, int>{ 5:3, 6:4 },
948    pattern: RegExp(
949      kIndent +
950      r'This file is part of GCC. *\n'
951      r'^(?:(?:\1\2? *)? *\n)*'
952      r'^\1\2GCC is free software; you can redistribute it and/or modify *\n'
953      r'^\1\2it under the terms of the GNU General Public License as published by *\n'
954      r'^\1\2the Free Software Foundation; either version (3), or \(at your option\) *\n'
955      r'^\1\2any later version\. *\n'
956      r'^(?:(?:\1\2? *)? *\n)*'
957      r'^\1\2GCC is distributed in the hope that it will be useful, *\n'
958      r'^\1\2but WITHOUT ANY WARRANTY; without even the implied warranty of *\n'
959      r'^\1\2MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\. +See the *\n'
960      r'^\1\2GNU General Public License for more details\. *\n'
961      r'^(?:(?:\1\2? *)? *\n)*'
962      r'^\1\2Under Section 7 of GPL version \3, you are granted additional *\n'
963      r'^\1\2permissions described in the GCC Runtime Library Exception, version *\n'
964      r'^\1\2(3\.1), as published by the Free Software Foundation\. *\n'
965      r'^(?:(?:\1\2? *)? *\n)*'
966      r'^\1\2You should have received a copy of the GNU General Public License and *\n'
967      r'^\1\2a copy of the GCC Runtime Library Exception along with this program; *\n'
968      r'^\1\2see the files (COPYING3) and (COPYING\.RUNTIME) respectively\. +If not, see *\n'
969      r'^\1\2<http://www\.gnu\.org/licenses/>\.',
970      multiLine: true,
971      caseSensitive: false,
972    )
973  ),
974
975  // LGPL 2.1
976  // some engine code
977  MultipleVersionedLicenseReferencePattern(
978    firstPrefixIndex: 1,
979    indentPrefixIndex: 2,
980    licenseIndices: const <int>[4],
981    versionIndicies: const <int, int>{ 4:3 },
982    pattern: RegExp(
983      kIndent +
984      r'This library is free software; you can redistribute it and/or *\n'
985      r'^\1\2modify it under the terms of the GNU Library General Public *\n'
986      r'^\1\2License as published by the Free Software Foundation; either *\n'
987      r'^\1\2version (2) of the License, or \(at your option\) any later version\. *\n'
988      r'^(?:(?:\1\2? *)? *\n)*'
989      r'^\1\2This library is distributed in the hope that it will be useful, *\n'
990      r'^\1\2but WITHOUT ANY WARRANTY; without even the implied warranty of *\n?'
991       r'\1\2MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\. +See the GNU *\n?'
992       r'\1\2Library General Public License for more details\. *\n'
993      r'^(?:(?:\1\2? *)? *\n)*'
994      r'^\1\2You should have received a copy of the GNU Library General Public License *\n'
995      r'^\1\2(?:along|aint) with this library; see the file (COPYING\.LI(?:B|other\.m_))\.?  If not, write to *\n'
996      r'^\1\2the Free Software Foundation, Inc\., (?:51 Franklin Street, Fifth Floor|59 Temple Place - Suite 330), *\n'
997      r'^\1\2Boston, MA 0211[01]-130[17], US(?:A\.|m_)',
998      multiLine: true,
999      caseSensitive: false,
1000    )
1001  ),
1002
1003  // AFL/LGPL
1004  // xdg_mime
1005  MultipleVersionedLicenseReferencePattern(
1006    firstPrefixIndex: 1,
1007    indentPrefixIndex: 2,
1008    licenseIndices: const <int>[4],
1009    versionIndicies: const <int, int>{ 4:3 },
1010    pattern: RegExp(
1011      kIndent +
1012      r'Licensed under the Academic Free License version 2.0 *\n'
1013      r'^\1\2Or under the following terms: *\n'
1014      r'^(?:(?:\1\2? *)? *\n)*'
1015      r'^\1\2This library is free software; you can redistribute it and/or *\n'
1016      r'^\1\2modify it under the terms of the GNU Lesser General Public *\n'
1017      r'^\1\2License as published by the Free Software Foundation; either *\n'
1018      r'^\1\2version (2) of the License, or \(at your option\) any later version\. *\n'
1019      r'^(?:(?:\1\2? *)? *\n)*'
1020      r'^\1\2This library is distributed in the hope that it will be useful, *\n'
1021      r'^\1\2but WITHOUT ANY WARRANTY; without even the implied warranty of *\n'
1022      r'^\1\2MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\.\t? +See the GNU *\n'
1023      r'^\1\2Lesser General Public License for more details\. *\n'
1024      r'^(?:(?:\1\2? *)? *\n)*'
1025      r'^\1\2You should have received a copy of the (GNU Lesser) General Public *\n'
1026      r'^\1\2License along with this library; if not, write to the *\n'
1027      r'^\1\2Free Software Foundation, Inc\., 59 Temple Place - Suite 330, *\n'
1028      r'^\1\2Boston, MA 0211[01]-1307, USA\.',
1029      multiLine: true,
1030      caseSensitive: false,
1031    )
1032  ),
1033
1034  // MPL
1035  // root_certificates
1036  MultipleVersionedLicenseReferencePattern(
1037    firstPrefixIndex: 1,
1038    indentPrefixIndex: 2,
1039    licenseIndices: const <int>[4],
1040    versionIndicies: const <int, int>{ 4:3 },
1041    pattern: RegExp(
1042      kIndent +
1043      r'This Source Code Form is subject to the terms of the Mozilla Public *\n'
1044      r'^\1\2License, v\. (2.0)\. +If a copy of the MPL was not distributed with this *\n'
1045      r'^\1\2file, You can obtain one at (http://mozilla\.org/MPL/2\.0/)\.',
1046      multiLine: true,
1047      caseSensitive: false,
1048    )
1049  ),
1050
1051  // MPL/GPL/LGPL
1052  // engine
1053  MultipleVersionedLicenseReferencePattern(
1054    firstPrefixIndex: 1,
1055    indentPrefixIndex: 2,
1056    licenseIndices: const <int>[3], // 5 is lgpl, which we're actively not selecting
1057    versionIndicies: const <int, int>{ 3:4 }, // 5:6 for lgpl
1058    pattern: RegExp(
1059      kIndent +
1060      r'(?:Version: [GMPL/012. ]+ *\n'
1061      r'^(?:(?:\1\2? *)? *\n)*'
1062      r'^\1\2)?The contents of this file are subject to the (Mozilla Public License) Version *\n'
1063      r'^\1\2(1\.1) \(the "License"\); you may not use this file except in compliance with *\n'
1064      r'^\1\2the License\. +You may obtain a copy of the License at *\n'
1065      r'^\1\2http://www\.mozilla\.org/MPL/ *\n'
1066      r'^(?:(?:\1\2? *)? *\n)*'
1067      r'^\1\2Software distributed under the License is distributed on an "AS IS" basis, *\n'
1068      r'^\1\2WITHOUT WARRANTY OF ANY KIND, either express or implied\. +See the License *\n'
1069      r'^\1\2for the specific language governing rights and limitations under the *\n'
1070      r'^\1\2License\. *\n'
1071      r'^(?:(?:\1\2? *)? *\n)*'
1072      r'^\1\2The Original Code is .+?(?:released\n'
1073      r'^\1\2March 31, 1998\.)?\n'
1074      r'^(?:(?:\1\2? *)? *\n)*'
1075      r'^\1\2The Initial Developer of the Original Code is *\n'
1076      r'^\1\2.+\n'
1077      r'^\1\2Portions created by the Initial Developer are Copyright \(C\) [0-9]+ *\n'
1078      r'^\1\2the Initial Developer\. +All Rights Reserved\. *\n'
1079      r'^(?:(?:\1\2? *)? *\n)*'
1080      r'^\1\2Contributor\(s\): *\n'
1081      r'(?:\1\2  .+\n)*'
1082      r'^(?:(?:\1\2? *)? *\n)*'
1083      r'^\1\2'
1084      +
1085      (
1086        r'Alternatively, the contents of this file may be used under the terms of '
1087        r'either (?:of )?the GNU General Public License Version 2 or later \(the "GPL"\), '
1088        r'or the (GNU Lesser) General Public License Version (2\.1) or later \(the '
1089        r'"LGPL"\), in which case the provisions of the GPL or the LGPL are '
1090        r'applicable instead of those above\. If you wish to allow use of your '
1091        r'version of this file only under the terms of either the GPL or the LGPL, '
1092        r'and not to allow others to use your version of this file under the terms '
1093        r'of the MPL, indicate your decision by deleting the provisions above and '
1094        r'replace them with the notice and other provisions required by the GPL or '
1095        r'the LGPL\. If you do not delete the provisions above, a recipient may use '
1096        r'your version of this file under the terms of any one of the MPL, the GPL or '
1097        r'the LGPL\.'
1098        .replaceAll(' ', _linebreak)
1099      ),
1100      multiLine: true,
1101      caseSensitive: false,
1102    )
1103  ),
1104
1105  // LGPL/MPL/GPL
1106  // engine
1107  MultipleVersionedLicenseReferencePattern(
1108    firstPrefixIndex: 1,
1109    indentPrefixIndex: 2,
1110    licenseIndices: const <int>[4],
1111    versionIndicies: const <int, int>{ 4:3 },
1112    pattern: RegExp(
1113      kIndent +
1114      r'This library is free software; you can redistribute it and/or *\n'
1115      r'^\1\2modify it under the terms of the GNU Lesser General Public *\n'
1116      r'^\1\2License as published by the Free Software Foundation; either *\n'
1117      r'^\1\2version (2\.1) of the License, or \(at your option\) any later version\. *\n'
1118      r'^(?:(?:\1\2? *)? *\n)*'
1119      r'^\1\2This library is distributed in the hope that it will be useful, *\n'
1120      r'^\1\2but WITHOUT ANY WARRANTY; without even the implied warranty of *\n'
1121      r'^\1\2MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\. +See the GNU *\n'
1122      r'^\1\2Lesser General Public License for more details\. *\n'
1123      r'^(?:(?:\1\2? *)? *\n)*'
1124      r'^\1\2You should have received a copy of the (GNU Lesser) General Public *\n'
1125      r'^\1\2License along with this library; if not, write to the Free Software *\n'
1126      r'^\1\2Foundation, Inc\., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 +USA *\n'
1127      r'^(?:(?:\1\2? *)? *\n)*'
1128      r'^\1\2Alternatively, the contents of this file may be used under the terms *\n'
1129      r'^\1\2of either the Mozilla Public License Version 1\.1, found at *\n'
1130      r'^\1\2http://www\.mozilla\.org/MPL/ \(the "MPL"\) or the GNU General Public *\n'
1131      r'^\1\2License Version 2\.0, found at http://www\.fsf\.org/copyleft/gpl\.html *\n'
1132      r'^\1\2\(the "GPL"\), in which case the provisions of the MPL or the GPL are *\n'
1133      r'^\1\2applicable instead of those above\. +If you wish to allow use of your *\n'
1134      r'^\1\2version of this file only under the terms of one of those two *\n'
1135      r'^\1\2licenses \(the MPL or the GPL\) and not to allow others to use your *\n'
1136      r'^\1\2version of this file under the LGPL, indicate your decision by *\n'
1137      r'^\1\2deletingthe provisions above and replace them with the notice and *\n'
1138      r'^\1\2other provisions required by the MPL or the GPL, as the case may be\. *\n'
1139      r'^\1\2If you do not delete the provisions above, a recipient may use your *\n'
1140      r'^\1\2version of this file under any of the LGPL, the MPL or the GPL\.',
1141      multiLine: true,
1142      caseSensitive: false,
1143    )
1144  ),
1145
1146  // ICU (Unicode)
1147  MultipleVersionedLicenseReferencePattern(
1148    firstPrefixIndex: 1,
1149    indentPrefixIndex: 2,
1150    licenseIndices: const <int>[3],
1151    checkLocalFirst: false,
1152    pattern: RegExp(
1153      kIndent +
1154      r'(?:©|Copyright \(C\)) 20.. and later: Unicode, Inc. and others.[ *]*\n'
1155      r'^\1\2License & terms of use: (http://www.unicode.org/copyright.html)',
1156      multiLine: true,
1157      caseSensitive: false,
1158    )
1159  ),
1160
1161  // ICU (Unicode)
1162  MultipleVersionedLicenseReferencePattern(
1163    firstPrefixIndex: 1,
1164    indentPrefixIndex: 2,
1165    licenseIndices: const <int>[3],
1166    checkLocalFirst: false,
1167    pattern: RegExp(
1168      kIndent +
1169      r'Copyright \(C\) 2016 and later: Unicode, Inc. and others. License & terms of use: (http://www.unicode.org/copyright.html) *\n',
1170      multiLine: true,
1171      caseSensitive: false,
1172    )
1173  ),
1174
1175  // ICU (Unicode)
1176  MultipleVersionedLicenseReferencePattern(
1177    firstPrefixIndex: 1,
1178    indentPrefixIndex: 2,
1179    licenseIndices: const <int>[3],
1180    checkLocalFirst: false,
1181    pattern: RegExp(
1182      kIndent +
1183      r'© 2016 and later: Unicode, Inc. and others. *\n'
1184      r'^ *License & terms of use: (http://www.unicode.org/copyright.html)#License *\n'
1185      r'^ *\n'
1186      r'^ *Copyright \(c\) 2000 IBM, Inc. and Others. *\n',
1187      multiLine: true,
1188      caseSensitive: false,
1189    )
1190  ),
1191];
1192
1193
1194// INLINE LICENSES
1195
1196final List<RegExp> csLicenses = <RegExp>[
1197
1198  // used with _tryInline, with needsCopyright: true (will only match if preceded by a copyright notice)
1199  // should have two groups, prefixes 1 and 2
1200
1201  // BoringSSL
1202  RegExp(
1203    kIndent +
1204    r'Redistribution and use in source and binary forms, with or without *\n'
1205    r'^\1\2modification, are permitted provided that the following conditions *\n'
1206    r'^\1\2are met: *\n'
1207    r'^(?:(?:\1\2? *)? *\n)*'
1208    r'^\1\2(?:[-*1-9.)/ ]+)Redistributions of source code must retain the above copyright *\n'
1209    r'^\1\2 *notice, this list of conditions and the following disclaimer\. *\n'
1210    r'^(?:(?:\1\2? *)? *\n)*'
1211    r'^\1\2(?:[-*1-9.)/ ]+)Redistributions in binary form must reproduce the above copyright *\n'
1212    r'^\1\2 *notice, this list of conditions and the following disclaimer in *\n'
1213    r'^\1\2 *the documentation and/or other materials provided with the *\n'
1214    r'^\1\2 *distribution\. *\n'
1215    r'^(?:(?:\1\2? *)? *\n)*'
1216    r'^\1\2(?:[-*1-9.)/ ]+)All advertising materials mentioning features or use of this *\n'
1217    r'^\1\2 *software must display the following acknowledgment: *\n'
1218    r'^\1\2 *"This product includes software developed by the OpenSSL Project *\n'
1219    r'^\1\2 *for use in the OpenSSL Toolkit\. \(http://www\.OpenSSL\.org/\)" *\n'
1220    r'^(?:(?:\1\2? *)? *\n)*'
1221    r'^\1\2(?:[-*1-9.)/ ]+)The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to *\n'
1222    r'^\1\2 *endorse or promote products derived from this software without *\n'
1223    r'^\1\2 *prior written permission\. +For written permission, please contact *\n'
1224    r'^\1\2 *[^@ ]+@OpenSSL\.org\. *\n'
1225    r'^(?:(?:\1\2? *)? *\n)*'
1226    r'^\1\2(?:[-*1-9.)/ ]+)Products derived from this software may not be called "OpenSSL" *\n'
1227    r'^\1\2 *nor may "OpenSSL" appear in their names without prior written *\n'
1228    r'^\1\2 *permission of the OpenSSL Project\. *\n'
1229    r'^(?:(?:\1\2? *)? *\n)*'
1230    r'^\1\2(?:[-*1-9.)/ ]+)Redistributions of any form whatsoever must retain the following *\n'
1231    r'^\1\2 *acknowledgment: *\n'
1232    r'^\1\2 *"This product includes software developed by the OpenSSL Project *\n'
1233    r'^\1\2 *for use in the OpenSSL Toolkit \(http://www\.OpenSSL\.org/\)" *\n'
1234    r'^(?:(?:\1\2? *)? *\n)*'
1235    r"^\1\2THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY *\n"
1236    r'^\1\2EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *\n'
1237    r'^\1\2IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR *\n'
1238    r'^\1\2PURPOSE ARE DISCLAIMED\. +IN NO EVENT SHALL THE OpenSSL PROJECT OR *\n'
1239    r'^\1\2ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *\n'
1240    r'^\1\2SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \(INCLUDING, BUT *\n'
1241    r'^\1\2NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *\n'
1242    r'^\1\2LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION\) *\n'
1243    r'^\1\2HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *\n'
1244    r'^\1\2STRICT LIABILITY, OR TORT \(INCLUDING NEGLIGENCE OR OTHERWISE\) *\n'
1245    r'^\1\2ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED *\n'
1246    r'^\1\2OF THE POSSIBILITY OF SUCH DAMAGE\.',
1247    multiLine: true,
1248    caseSensitive: false
1249  ),
1250
1251  RegExp(
1252    kIndent +
1253    r'(?:This package is an SSL implementation written *\n'
1254    r'^\1\2by Eric Young \(eay@cryptsoft\.com\)\. *\n'
1255    r'^\1\2The implementation was written so as to conform with Netscapes SSL\. *\n'
1256    r'^(?:(?:\1\2?g? *)? *\n)*'
1257    r'^\1\2This library is free for commercial and non-commercial use as long as *\n'
1258    r'^\1\2the following conditions are aheared to\. +The following conditions *\n'
1259    r'^\1\2apply to all code found in this distribution, be it the RC4, RSA, *\n'
1260    r'^\1\2lhash, DES, etc\., code; not just the SSL code\. +The SSL documentation *\n'
1261    r'^\1\2included with this distribution is covered by the same copyright terms *\n'
1262    r'^\1\2except that the holder is Tim Hudson \(tjh@cryptsoft\.com\)\. *\n'
1263    r'^(?:(?:\1\2?g? *)? *\n)*'
1264    r"^\1\2Copyright remains Eric Young's, and as such any Copyright notices in *\n"
1265    r'^\1\2the code are not to be removed\. *\n'
1266    r'^\1\2If this package is used in a product, Eric Young should be given attribution *\n'
1267    r'^\1\2as the author of the parts of the library used\. *\n'
1268    r'^\1\2This can be in the form of a textual message at program startup or *\n'
1269    r'^\1\2in documentation \(online or textual\) provided with the package\. *\n'
1270    r'^(?:(?:\1\2?g? *)? *\n)*'
1271    r'^\1\2)?Redistribution and use in source and binary forms, with or without *\n'
1272    r'^\1\2modification, are permitted provided that the following conditions *\n'
1273    r'^\1\2are met: *\n'
1274    r'^\1\2(?:[-*1-9.)/ ]+)Redistributions of source code must retain the copyright *\n'
1275    r'^\1\2 *notice, this list of conditions and the following disclaimer\. *\n'
1276    r'^\1\2(?:[-*1-9.)/ ]+)Redistributions in binary form must reproduce the above copyright *\n'
1277    r'^\1\2 *notice, this list of conditions and the following disclaimer in the *\n'
1278    r'^\1\2 *documentation and/or other materials provided with the distribution\. *\n'
1279    r'^\1\2(?:[-*1-9.)/ ]+)All advertising materials mentioning features or use of this software *\n'
1280    r'^\1\2 *must display the following acknowledgement: *\n'
1281    r'^\1\2 *"This product includes cryptographic software written by *\n'
1282    r'^\1\2 *Eric Young \(eay@cryptsoft\.com\)" *\n'
1283    r"^\1\2 *The word 'cryptographic' can be left out if the rouines from the library *\n" // TODO(ianh): File a bug on the number of analyzer errors you get if you replace the " characters on this line with '
1284    r'^\1\2 *being used are not cryptographic related :-\)\. *\n'
1285    r'^\1\2(?:[-*1-9.)/ ]+)If you include any Windows specific code \(or a derivative thereof\) fromg? *\n'
1286    r'^\1\2 *the apps directory \(application code\) you must include an acknowledgement: *\n'
1287    r'^\1\2 *"This product includes software written by Tim Hudson \(tjh@cryptsoft\.com\)" *\n'
1288    r'^(?:(?:\1\2?g? *)? *\n)*'
1289    r"^\1\2THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND *\n"
1290    r'^\1\2ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *\n'
1291    r'^\1\2IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *\n'
1292    r'^\1\2ARE DISCLAIMED\. +IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE *\n'
1293    r'^\1\2FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *\n'
1294    r'^\1\2DAMAGES \(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *\n'
1295    r'^\1\2OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION\) *\n'
1296    r'^\1\2HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *\n'
1297    r'^\1\2LIABILITY, OR TORT \(INCLUDING NEGLIGENCE OR OTHERWISE\) ARISING IN ANY WAY *\n'
1298    r'^\1\2OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *\n'
1299    r'^\1\2SUCH DAMAGE\. *\n'
1300    r'^(?:(?:\1\2?g? *)? *\n)*'
1301    r'^\1\2The licence and distribution terms for any publically available version or *\n'
1302    r'^\1\2derivative of this code cannot be changed\. +i\.e\. +this code cannot simply be *\n'
1303    r'^\1\2copied and put under another distribution licence *\n'
1304    r'^\1\2\[including the GNU Public Licence\.\]',
1305    multiLine: true,
1306    caseSensitive: false
1307  ),
1308
1309  RegExp(
1310    kIndent +
1311    (
1312      r'License to copy and use this software is granted provided that it '
1313      r'is identified as the "RSA Data Security, Inc\. MD5 Message-Digest '
1314      r'Algorithm" in all material mentioning or referencing this software '
1315      r'or this function\. '
1316      r'License is also granted to make and use derivative works provided '
1317      r'that such works are identified as "derived from the RSA Data '
1318      r'Security, Inc\. MD5 Message-Digest Algorithm" in all material '
1319      r'mentioning or referencing the derived work\. '
1320      r'RSA Data Security, Inc\. makes no representations concerning either '
1321      r'the merchantability of this software or the suitability of this '
1322      r'software for any particular purpose\. It is provided "as is" '
1323      r'without express or implied warranty of any kind\. '
1324      r'These notices must be retained in any copies of any part of this '
1325      r'documentation and/or software\.'
1326      .replaceAll(' ', _linebreak)
1327    ),
1328    multiLine: true,
1329    caseSensitive: false,
1330  ),
1331
1332  // BSD-DERIVED LICENSES
1333
1334  RegExp(
1335    kIndent +
1336
1337    // Some files in ANGLE prefix the license with a description of the license.
1338    r'(?:BSD 2-Clause License \(http://www.opensource.org/licenses/bsd-license.php\))?' +
1339    _linebreak +
1340
1341    (
1342      'Redistribution and use in source and binary forms, with or without '
1343      'modification, are permitted provided that the following conditions are met:'
1344      .replaceAll(' ', _linebreak)
1345    )
1346    +
1347
1348    // the conditions:
1349    r'(?:' +
1350
1351    // indented blank lines
1352    _linebreak +
1353
1354    // truly blank lines
1355    r'|[\r\n]+' +
1356
1357    // ad clause - ucb
1358    r'|(?:[-*1-9.)/ ]*)' +
1359    (
1360      'All advertising materials mentioning features or use of this software '
1361      'must display the following acknowledgement: This product includes software '
1362      'developed by the University of California, Berkeley and its contributors\\.'
1363      .replaceAll(' ', _linebreak)
1364    )
1365    +
1366
1367    // ad clause - netbsd
1368    r'|(?:[-*1-9.)/ ]*)' +
1369    (
1370      'All advertising materials mentioning features or use of this software '
1371      'must display the following acknowledgement: This product includes software '
1372      'developed by the NetBSD Foundation, Inc\\. and its contributors\\.'
1373      .replaceAll(' ', _linebreak)
1374    )
1375    +
1376
1377    // ack clause
1378    r'|(?:[-*1-9.)/ ]*)' +
1379    (
1380      r'The origin of this software must not be misrepresented; you must not claim '
1381      r'that you wrote the original software\. If you use this software in a product, '
1382      r'an acknowledgment in the product documentation would be appreciated but is '
1383      r'not required\.'
1384      .replaceAll(' ', _linebreak)
1385    )
1386    +
1387
1388    r'|(?:[-*1-9.)/ ]*)' +
1389    (
1390      r'Altered source versions must be plainly marked as such, and must not be '
1391      r'misrepresented as being the original software\.'
1392      .replaceAll(' ', _linebreak)
1393    )
1394    +
1395
1396    // no ad clauses
1397    r'|(?:[-*1-9.)/ ]*)' +
1398    (
1399      'Neither my name, .+, nor the names of any other contributors to the code '
1400      'use may not be used to endorse or promote products derived from this '
1401      'software without specific prior written permission\\.'
1402      .replaceAll(' ', _linebreak)
1403    )
1404    +
1405
1406    r'|(?:[-*1-9.)/ ]*)' +
1407    (
1408      'The name of the author may not be used to endorse or promote products '
1409      'derived from this software without specific prior written permission\\.?'
1410      .replaceAll(' ', _linebreak)
1411    )
1412    +
1413
1414    r'|(?:[-*1-9.)/ ]*)' +
1415    (
1416      'Neither the name of .+ nor the names of its contributors may be used '
1417      'to endorse or promote products derived from this software without '
1418      'specific prior written permission\\.'
1419      .replaceAll(' ', _linebreak)
1420    )
1421    +
1422
1423    // notice clauses
1424    r'|(?:[-*1-9.)/ ]*)' +
1425    (
1426      'Redistributions of source code must retain the above copyright notice, '
1427      'this list of conditions and the following disclaimer\\.'
1428      .replaceAll(' ', _linebreak)
1429    )
1430    +
1431
1432    r'|(?:[-*1-9.)/ ]*)' +
1433    (
1434      'Redistributions in binary form must reproduce the above copyright notice, '
1435      'this list of conditions and the following disclaimer in the documentation '
1436      'and/or other materials provided with the distribution\\.'
1437      .replaceAll(' ', _linebreak)
1438    )
1439    +
1440
1441    r'|(?:[-*1-9.)/ ]*)' +
1442    (
1443      'Redistributions in binary form must reproduce the above copyright notice, '
1444      'this list of conditions and the following disclaimer\\.'
1445      .replaceAll(' ', _linebreak)
1446    )
1447    +
1448
1449    // end of conditions
1450    r')*'
1451    +
1452
1453    // disclaimers
1454    (
1455      'THIS SOFTWARE IS PROVIDED (?:BY .+(?: .+)? )?["“`]+AS IS["”\']+,? AND ANY EXPRESS OR IMPLIED '
1456      'WARRANTIES,(?::tabnew)? INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF '
1457      'MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED\\. IN NO EVENT '
1458      'SHALL .+(?: .+)? BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR '
1459      'CONSEQUENTIAL DAMAGES \\(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS '
1460      'OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION\\) HOWEVER CAUSED '
1461      'AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \\(INCLUDING '
1462      'NEGLIGENCE OR OTHERWISE\\) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF '
1463      'ADVISED OF THE POSSIBILITY OF SUCH DAMAGE\\.'
1464      .replaceAll(' ', _linebreak)
1465    ),
1466    multiLine: true,
1467    caseSensitive: false,
1468  ),
1469
1470
1471  // THREE-CLAUSE LICENSES
1472  // licenses in this section are sorted first by the length of the last line, in words,
1473  // and then by the length of the bulletted clauses, in total lines.
1474
1475  // Seen in libjpeg-turbo
1476  // TODO(ianh): Mark License as not needing to be shown
1477  RegExp(
1478    kIndent +
1479    r"This software is provided 'as-is', without any express or implied *\n"
1480    r'^\1\2warranty\. +In no event will the authors be held liable for any damages *\n'
1481    r'^\1\2arising from the use of this software\. *\n'
1482    r'^(?:(?:\1\2? *)? *\n)*'
1483    r'^\1\2Permission is granted to anyone to use this software for any purpose, *\n'
1484    r'^\1\2including commercial applications, and to alter it and redistribute it *\n'
1485    r'^\1\2freely, subject to the following restrictions: *\n'
1486    r'^(?:(?:\1\2? *)? *\n)*'
1487    r'^\1\2(?:[-*1-9.)/ ]+)The origin of this software must not be misrepresented; you must not *\n'
1488    r'^\1\2 *claim that you wrote the original software\. +If you use this software *\n'
1489    r'^\1\2 *in a product, an acknowledgment in the product documentation would be *\n'
1490    r'^\1\2 *appreciated but is not required\. *\n'
1491    r'^\1\2(?:[-*1-9.)/ ]+)Altered source versions must be plainly marked as such, and must not be *\n'
1492    r'^\1\2 *misrepresented as being the original software\. *\n'
1493    r'^\1\2(?:[-*1-9.)/ ]+)This notice may not be removed or altered from any source distribution\.',
1494    multiLine: true,
1495    caseSensitive: false
1496  ),
1497
1498  // seen in GLFW
1499  RegExp(
1500    kIndent +
1501    r"This software is provided 'as-is', without any express or implied *\n"
1502    r'^\1\2warranty\. +In no event will the authors be held liable for any damages *\n'
1503    r'^\1\2arising from the use of this software\. *\n'
1504    r'^(?:(?:\1\2? *)? *\n)*'
1505    r'^\1\2Permission is granted to anyone to use this software for any purpose, *\n'
1506    r'^\1\2including commercial applications, and to alter it and redistribute it *\n'
1507    r'^\1\2freely, subject to the following restrictions: *\n'
1508    r'^(?:(?:\1\2? *)? *\n)*'
1509    r'^\1\2(?:[-*1-9.)/ ]+)The origin of this software must not be misrepresented; you must not *\n'
1510    r'^\1\2 *claim that you wrote the original software\. +If you use this software *\n'
1511    r'^\1\2 *in a product, an acknowledgment in the product documentation would *\n'
1512    r'^\1\2 *be appreciated but is not required\. *\n'
1513    r'^(?:(?:\1\2? *)? *\n)*'
1514    r'^\1\2(?:[-*1-9.)/ ]+)Altered source versions must be plainly marked as such, and must not *\n'
1515    r'^\1\2 *be misrepresented as being the original software\. *\n'
1516    r'^(?:(?:\1\2? *)? *\n)*'
1517    r'^\1\2(?:[-*1-9.)/ ]+)This notice may not be removed or altered from any source *\n'
1518    r'^\1\2 *distribution\.',
1519    multiLine: true,
1520    caseSensitive: false
1521  ),
1522
1523
1524  // MIT-DERIVED LICENSES
1525
1526  // Seen in Mesa
1527  RegExp(
1528    kIndent +
1529    (
1530      r'Permission is hereby granted, free of charge, to any person obtaining '
1531      r'a copy of this software and(?: /or)? associated documentation files \(the "(?:Software|Materials) "\), '
1532      r'to deal in the (?:Software|Materials) without restriction, including without limitation '
1533      r'the rights to use, copy, modify, merge, publish, distribute, sub license, '
1534      r'and/or sell copies of the (?:Software|Materials), and to permit persons to whom the '
1535      r'(?:Software|Materials) (?:is|are) furnished to do so, subject to the following conditions:'
1536      .replaceAll(' ', _linebreak)
1537    )
1538    +
1539    r'(?:'
1540    +
1541    (
1542      r'(?:(?:\1\2? *)? *\n)*'
1543
1544      +
1545
1546      r'|'
1547
1548      r'\1\2 '
1549      r'The above copyright notice and this permission notice'
1550      r'(?: \(including the next paragraph\))? '
1551      r'shall be included in all copies or substantial portions '
1552      r'of the (?:Software|Materials)\.'
1553
1554      r'|'
1555
1556      r'\1\2 '
1557      r'In addition, the following condition applies:'
1558
1559      r'|'
1560
1561      r'\1\2 '
1562      r'All redistributions must retain an intact copy of this copyright notice and disclaimer\.'
1563
1564      r'|'
1565
1566      r'\1\2 '
1567      r'THE (?:SOFTWARE|MATERIALS) (?:IS|ARE) PROVIDED "AS -? IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS '
1568      r'OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, '
1569      r'FITNESS FOR A PARTICULAR PURPOSE AND NON-?INFRINGEMENT\. IN NO EVENT SHALL '
1570      r'.+(?: .+)? BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER '
1571      r'IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN '
1572      r'CONNECTION WITH THE (?:SOFTWARE|MATERIALS) OR THE USE OR OTHER DEALINGS IN THE (?:SOFTWARE|MATERIALS)\.'
1573
1574      r'|'
1575
1576      r'\1\2 '
1577      r'THE (?:SOFTWARE|MATERIALS) (?:IS|ARE) PROVIDED "AS -? IS" AND WITHOUT WARRANTY OF ANY KIND, '
1578      r'EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY '
1579      r'OR FITNESS FOR A PARTICULAR PURPOSE\.'
1580
1581      r'|'
1582
1583      r'\1\2 '
1584      r'IN NO EVENT SHALL .+ BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL '
1585      r'DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, '
1586      r'WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING '
1587      r'OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE\.'
1588
1589      .replaceAll(' ', _linebreak)
1590    )
1591    +
1592    r')*',
1593    multiLine: true,
1594    caseSensitive: false
1595  ),
1596
1597  // BISON LICENSE
1598  // Seen in some ANGLE source. The usage falls under the "special exception" clause.
1599  RegExp(
1600    kIndent +
1601    r'This program is free software: you can redistribute it and/or modify\n'
1602    r'^(?:\1\2)?it under the terms of the GNU General Public License as published by\n'
1603    r'^(?:\1\2)?the Free Software Foundation, either version 3 of the License, or\n'
1604    r'^(?:\1\2)?\(at your option\) any later version.\n'
1605    r'^(?:\1\2)?\n*'
1606    r'^(?:\1\2)?This program is distributed in the hope that it will be useful,\n'
1607    r'^(?:\1\2)?but WITHOUT ANY WARRANTY; without even the implied warranty of\n'
1608    r'^(?:\1\2)?MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n'
1609    r'^(?:\1\2)?GNU General Public License for more details.\n'
1610    r'^(?:\1\2)?\n*'
1611    r'^(?:\1\2)?You should have received a copy of the GNU General Public License\n'
1612    r'^(?:\1\2)?along with this program.  If not, see <http://www.gnu.org/licenses/>.  \*/\n'
1613    r'^(?:\1\2)?\n*' +
1614    kIndent +
1615    r'As a special exception, you may create a larger work that contains\n'
1616    r'^(?:\1\2)?part or all of the Bison parser skeleton and distribute that work\n'
1617    r"^(?:\1\2)?under terms of your choice, so long as that work isn't itself a\n"
1618    r'^(?:\1\2)?parser generator using the skeleton or a modified version thereof\n'
1619    r'^(?:\1\2)?as a parser skeleton.  Alternatively, if you modify or redistribute\n'
1620    r'^(?:\1\2)?the parser skeleton itself, you may \(at your option\) remove this\n'
1621    r'^(?:\1\2)?special exception, which will cause the skeleton and the resulting\n'
1622    r'^(?:\1\2)?Bison output files to be licensed under the GNU General Public\n'
1623    r'^(?:\1\2)?License without this special exception.\n'
1624    r'^(?:\1\2)?\n*'
1625    r'^(?:\1\2)?This special exception was added by the Free Software Foundation in\n'
1626    r'^(?:\1\2)?version 2.2 of Bison.  \*/\n',
1627    multiLine: true,
1628    caseSensitive: false
1629  ),
1630
1631  // OTHER BRIEF LICENSES
1632
1633  RegExp(
1634    kIndent +
1635    r'Permission to use, copy, modify, and distribute this software for any *\n'
1636    r'^(?:\1\2)?purpose with or without fee is hereby granted, provided that the above *\n'
1637    r'^(?:\1\2)?copyright notice and this permission notice appear in all copies(?:, and that *\n'
1638    r'^(?:\1\2)?the name of .+ not be used in advertising or *\n'
1639    r'^(?:\1\2)?publicity pertaining to distribution of the document or software without *\n'
1640    r'^(?:\1\2)?specific, written prior permission)?\. *\n'
1641    r'^(?:(?:\1\2? *)? *\n)*'
1642    r'^(?:\1\2)?THE SOFTWARE IS PROVIDED "AS IS" AND .+ DISCLAIMS ALL(?: WARRANTIES)? *\n'
1643    r'^(?:\1\2)?(?:WARRANTIES )?WITH REGARD TO THIS SOFTWARE,? INCLUDING ALL IMPLIED WARRANTIES(?: OF)? *\n'
1644    r'^(?:\1\2)?(?:OF )?MERCHANTABILITY AND FITNESS\. +IN NO EVENT SHALL .+(?: BE LIABLE FOR)? *\n'
1645    r'^(?:\1\2)?(?:.+ BE LIABLE FOR )?ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL(?: DAMAGES OR ANY DAMAGES)? *\n'
1646    r'^(?:\1\2)?(?:DAMAGES OR ANY DAMAGES )?WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR(?: PROFITS, WHETHER IN AN)? *\n'
1647    r'^(?:\1\2)?(?:PROFITS, WHETHER IN AN )?ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS(?: ACTION, ARISING OUT OF)? *\n'
1648    r'^(?:\1\2)?(?:ACTION, ARISING OUT OF )?OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS(?: SOFTWARE)?(?: *\n'
1649    r'^(?:\1\2)?SOFTWARE)?\.',
1650    multiLine: true,
1651    caseSensitive: false
1652  ),
1653
1654  // Seen in the NDK
1655  RegExp(
1656    kIndent +
1657    r'Permission to use, copy, modify, and/or distribute this software for any *\n'
1658    r'^\1\2purpose with or without fee is hereby granted, provided that the above *\n'
1659    r'^\1\2copyright notice and this permission notice appear in all copies\. *\n'
1660    r'^(?:(?:\1\2? *)? *\n)*'
1661    r'^\1\2THE SOFTWARE IS PROVIDED "AS IS" AND .+ DISCLAIMS ALL WARRANTIES(?: WITH)? *\n'
1662    r'^\1\2(?:WITH )?REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF(?: MERCHANTABILITY)? *\n'
1663    r'^\1\2(?:MERCHANTABILITY )?AND FITNESS\. +IN NO EVENT SHALL .+ BE LIABLE FOR(?: ANY(?: SPECIAL, DIRECT,)?)? *\n'
1664    r'^\1\2(?:(?:ANY )?SPECIAL, DIRECT, )?INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES(?: WHATSOEVER RESULTING FROM)? *\n'
1665    r'^\1\2(?:WHATSOEVER RESULTING FROM )?LOSS OF USE, DATA OR PROFITS, WHETHER IN AN(?: ACTION(?: OF CONTRACT, NEGLIGENCE)?)? *\n'
1666    r'^\1\2(?:(?:ACTION )?OF CONTRACT, NEGLIGENCE )?OR OTHER TORTIOUS ACTION, ARISING OUT OF(?: OR IN(?: CONNECTION WITH THE USE OR)?)? *\n'
1667    r'^\1\2(?:(?:OR IN )?CONNECTION WITH THE USE OR )?PERFORMANCE OF THIS SOFTWARE\.',
1668    multiLine: true,
1669    caseSensitive: false
1670  ),
1671
1672  // seen in GLFW
1673  RegExp(
1674    kIndent +
1675    r'Permission to use, copy, modify, and distribute this software for any *\n'
1676    r'^\1\2purpose with or without fee is hereby granted, provided that the above *\n'
1677    r'^\1\2copyright notice and this permission notice appear in all copies\. *\n'
1678    r'^(?:(?:\1\2? *)? *\n)*'
1679    r"^\1\2THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *\n"
1680    r'^\1\2WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *\n'
1681    r'^\1\2MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE\. +THE AUTHORS AND *\n'
1682    r'^\1\2CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER\.',
1683    multiLine: true,
1684    caseSensitive: false
1685  ),
1686
1687  // seen in GLFW, base
1688  RegExp(
1689    kIndent +
1690    r'Permission to use, copy, modify, and distribute this software for any *\n'
1691    r'^\1\2purpose without fee is hereby granted, provided that this entire notice *\n'
1692    r'^\1\2is included in all copies of any software which is or includes a copy *\n'
1693    r'^\1\2or modification of this software and in all copies of the supporting *\n'
1694    r'^\1\2documentation for such software\. *\n'
1695    r'^(?:(?:\1\2? *)? *\n)*'
1696    r'^\1\2THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED *\n'
1697    r'^\1\2WARRANTY\. +IN PARTICULAR, NEITHER THE AUTHOR NOR .+ MAKES ANY *\n'
1698    r'^\1\2REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY *\n'
1699    r'^\1\2OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE\.',
1700    multiLine: true,
1701    caseSensitive: false
1702  ),
1703
1704  // harfbuzz
1705  RegExp(
1706    kIndent +
1707    r'Permission is hereby granted, without written agreement and without *\n'
1708    r'^\1\2license or royalty fees, to use, copy, modify, and distribute this *\n'
1709    r'^\1\2software and its documentation for any purpose, provided that the *\n'
1710    r'^\1\2above copyright notice and the following two paragraphs appear in *\n'
1711    r'^\1\2all copies of this software\. *\n'
1712    r'^(?:(?:\1\2? *)? *\n)*'
1713    r'^\1\2IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR *\n'
1714    r'^\1\2DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES *\n'
1715    r'^\1\2ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN *\n'
1716    r'^\1\2IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH *\n'
1717    r'^\1\2DAMAGE\. *\n'
1718    r'^(?:(?:\1\2? *)? *\n)*'
1719    r'^\1\2THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, *\n'
1720    r'^\1\2BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND *\n'
1721    r'^\1\2FITNESS FOR A PARTICULAR PURPOSE\. +THE SOFTWARE PROVIDED HEREUNDER IS *\n'
1722    r'^\1\2ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO *\n'
1723    r'^\1\2PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS\. *\n',
1724    multiLine: true,
1725    caseSensitive: false
1726  ),
1727
1728  // NDK
1729  RegExp(
1730    kIndent +
1731    r'Permission to use, copy, modify and distribute this software and *\n'
1732    r'^\1\2its documentation is hereby granted, provided that both the copyright *\n'
1733    r'^\1\2notice and this permission notice appear in all copies of the *\n'
1734    r'^\1\2software, derivative works or modified versions, and any portions *\n'
1735    r'^\1\2thereof, and that both notices appear in supporting documentation. *\n'
1736    r'^(?:(?:\1\2? *)? *\n)*'
1737    r'^\1\2CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" *\n'
1738    r'^\1\2CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND *\n'
1739    r'^\1\2FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. *\n'
1740    r'^(?:(?:\1\2? *)? *\n)*'
1741    r'^\1\2Carnegie Mellon requests users of this software to return to *\n'
1742    r'^(?:(?:\1\2? *)? *\n)*'
1743    r'^\1\2 Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU *\n'
1744    r'^\1\2 School of Computer Science *\n'
1745    r'^\1\2 Carnegie Mellon University *\n'
1746    r'^\1\2 Pittsburgh PA 15213-3890 *\n'
1747    r'^(?:(?:\1\2? *)? *\n)*'
1748    r'^\1\2any improvements or extensions that they make and grant Carnegie the *\n'
1749    r'^\1\2rights to redistribute these changes. *\n',
1750    multiLine: true,
1751    caseSensitive: false
1752  ),
1753
1754  // seen in Android NDK gnu-libstdc++
1755  RegExp(
1756    kIndent +
1757    (
1758      r'Permission to use, copy, modify, (?:distribute and sell|sell, and distribute) this software '
1759      r'(?:and its documentation for any purpose )?is hereby granted without fee, '
1760      r'provided that the above copyright notice appears? in all copies,? and '
1761      r'that both that copyright notice and this permission notice appear '
1762      r'in supporting documentation\. '
1763      r'(?:.+'
1764        r'|Hewlett-Packard Company'
1765        r'|Silicon Graphics'
1766        r'|None of the above authors, nor IBM Haifa Research Laboratories,'
1767      r') makes? (?:no|any) '
1768      r'representations? about the suitability of this software for any '
1769      r'(?:purpose\. It is provi)?ded "as is" without express or implied warranty\.'
1770      .replaceAll(' ', _linebreak)
1771    ),
1772    multiLine: true,
1773    caseSensitive: false
1774  ),
1775
1776  // Seen in Android NDK
1777  RegExp(
1778    kIndent +
1779    r'Developed at (?:SunPro|SunSoft), a Sun Microsystems, Inc. business. *\n'
1780    r'^\1\2Permission to use, copy, modify, and distribute this *\n'
1781    r'^\1\2software is freely granted, provided that this notice *\n'
1782    r'^\1\2is preserved.',
1783    multiLine: true,
1784    caseSensitive: false
1785  ),
1786
1787  // Seen in Android NDK (stlport)
1788  RegExp(
1789    kIndent +
1790    r'This material is provided "as is", with absolutely no warranty expressed *\n'
1791    r'^\1\2or implied\. +Any use is at your own risk\. *\n'
1792    r'^(?:(?:\1\2? *)? *\n)*'
1793    r'^\1\2Permission to use or copy this software for any purpose is hereby granted *\n'
1794    r'^\1\2without fee, provided the above notices are retained on all copies\. *\n'
1795    r'^\1\2Permission to modify the code and to distribute modified code is granted, *\n'
1796    r'^\1\2provided the above notices are retained, and a notice that the code was *\n'
1797    r'^\1\2modified is included with the above copyright notice\.',
1798    multiLine: true,
1799    caseSensitive: false
1800  ),
1801
1802  // freetype2.
1803  RegExp(
1804    kIndent +
1805    (
1806      r'Permission to use, copy, modify, distribute, and sell this software and its '
1807      r'documentation for any purpose is hereby granted without fee, provided that '
1808      r'the above copyright notice appear in all copies and that both that '
1809      r'copyright notice and this permission notice appear in supporting '
1810      r'documentation\. '
1811      r'The above copyright notice and this permission notice shall be included in '
1812      r'all copies or substantial portions of the Software\. '
1813      r'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR '
1814      r'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, '
1815      r'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT\.  IN NO EVENT SHALL THE '
1816      r'OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN '
1817      r'AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN '
1818      r'CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE\. '
1819      r'Except as contained in this notice, the name of The Open Group shall not be '
1820      r'used in advertising or otherwise to promote the sale, use or other dealings '
1821      r'in this Software without prior written authorization from The Open Group\. '
1822      .replaceAll(' ', _linebreak)
1823    ),
1824    multiLine: true,
1825    caseSensitive: false
1826  ),
1827
1828  // TODO(ianh): File a bug on what happens if you replace the // with a #
1829  // ICU
1830  RegExp(
1831    kIndent +
1832    r'This file is provided as-is by Unicode, Inc\. \(The Unicode Consortium\)\. '
1833    r'No claims are made as to fitness for any particular purpose\. No '
1834    r'warranties of any kind are expressed or implied\. The recipient '
1835    r'agrees to determine applicability of information provided\. If this '
1836    r'file has been provided on optical media by Unicode, Inc\., the sole '
1837    r'remedy for any claim will be exchange of defective media within 90 '
1838    r'days of receipt\. '
1839    r'Unicode, Inc\. hereby grants the right to freely use the information '
1840    r'supplied in this file in the creation of products supporting the '
1841    r'Unicode Standard, and to make copies of this file in any form for '
1842    r'internal or external distribution as long as this notice remains '
1843    r'attached\.'
1844    .replaceAll(' ', _linebreak),
1845    multiLine: true,
1846    caseSensitive: false
1847  ),
1848
1849  // OpenSSL
1850  RegExp(
1851    kIndent +
1852    r'The portions of the attached software \("Contribution"\) is developed by *\n'
1853    r'^\1\2Nokia Corporation and is licensed pursuant to the OpenSSL open source *\n'
1854    r'^\1\2license\. *\n'
1855    r'^(?:(?:\1\2? *)? *\n)*'
1856    r'^\1\2The Contribution, originally written by Mika Kousa and Pasi Eronen of *\n'
1857    r'^\1\2Nokia Corporation, consists of the "PSK" \(Pre-Shared Key\) ciphersuites *\n'
1858    r'^\1\2support \(see RFC 4279\) to OpenSSL\. *\n'
1859    r'^(?:(?:\1\2? *)? *\n)*'
1860    r'^\1\2No patent licenses or other rights except those expressly stated in *\n'
1861    r'^\1\2the OpenSSL open source license shall be deemed granted or received *\n'
1862    r'^\1\2expressly, by implication, estoppel, or otherwise\. *\n'
1863    r'^(?:(?:\1\2? *)? *\n)*'
1864    r'^\1\2No assurances are provided by Nokia that the Contribution does not *\n'
1865    r'^\1\2infringe the patent or other intellectual property rights of any third *\n'
1866    r'^\1\2party or that the license provides you with all the necessary rights *\n'
1867    r'^\1\2to make use of the Contribution\. *\n'
1868    r'^(?:(?:\1\2? *)? *\n)*'
1869    r'^\1\2THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND\. IN *\n'
1870    r'^\1\2ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA *\n'
1871    r'^\1\2SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY *\n'
1872    r'^\1\2OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR *\n'
1873    r'^\1\2OTHERWISE\.',
1874    multiLine: true,
1875    caseSensitive: false
1876  ),
1877
1878];
1879
1880final List<RegExp> csNotices = <RegExp>[
1881
1882  // used with _tryInline, with needsCopyright: false
1883  // should have two groups, prefixes 1 and 2
1884
1885  RegExp(
1886    kIndent +
1887    r'The Graphics Interchange Format\(c\) is the copyright property of CompuServe *\n'
1888    r'^\1\2Incorporated\. +Only CompuServe Incorporated is authorized to define, redefine, *\n'
1889    r'^\1\2enhance, alter, modify or change in any way the definition of the format\. *\n'
1890    r'^(?:(?:\1\2? *)? *\n)*'
1891    r'^\1\2CompuServe Incorporated hereby grants a limited, non-exclusive, royalty-free *\n'
1892    r'^\1\2license for the use of the Graphics Interchange Format\(sm\) in computer *\n'
1893    r'^\1\2software; computer software utilizing GIF\(sm\) must acknowledge ownership of the *\n'
1894    r'^\1\2Graphics Interchange Format and its Service Mark by CompuServe Incorporated, in *\n'
1895    r'^\1\2User and Technical Documentation\. +Computer software utilizing GIF, which is *\n'
1896    r'^\1\2distributed or may be distributed without User or Technical Documentation must *\n'
1897    r'^\1\2display to the screen or printer a message acknowledging ownership of the *\n'
1898    r'^\1\2Graphics Interchange Format and the Service Mark by CompuServe Incorporated; in *\n'
1899    r'^\1\2this case, the acknowledgement may be displayed in an opening screen or leading *\n'
1900    r'^\1\2banner, or a closing screen or trailing banner\. +A message such as the following *\n'
1901    r'^\1\2may be used: *\n'
1902    r'^(?:(?:\1\2? *)? *\n)*'
1903    r'^\1\2 *"The Graphics Interchange Format\(c\) is the Copyright property of *\n'
1904    r'^\1\2 *CompuServe Incorporated\. +GIF\(sm\) is a Service Mark property of *\n'
1905    r'^\1\2 *CompuServe Incorporated\." *\n',
1906    multiLine: true,
1907    caseSensitive: false
1908  ),
1909
1910  // NSPR
1911  // (Showing the entire block instead of the LGPL for this file is based
1912  // on advice specifically regarding the prtime.cc file.)
1913  RegExp(
1914    r'()()/\* Portions are Copyright \(C\) 2011 Google Inc \*/\n'
1915    r'/\* \*\*\*\*\* BEGIN LICENSE BLOCK \*\*\*\*\*\n'
1916    r' \* Version: MPL 1\.1/GPL 2\.0/LGPL 2\.1\n'
1917    r' \*\n'
1918    r' \* The contents of this file are subject to the Mozilla Public License Version\n'
1919    r' \* 1\.1 \(the "License"\); you may not use this file except in compliance with\n'
1920    r' \* the License\. +You may obtain a copy of the License at\n'
1921    r' \* http://www\.mozilla\.org/MPL/\n'
1922    r' \*\n'
1923    r' \* Software distributed under the License is distributed on an "AS IS" basis,\n'
1924    r' \* WITHOUT WARRANTY OF ANY KIND, either express or implied\. +See the License\n'
1925    r' \* for the specific language governing rights and limitations under the\n'
1926    r' \* License\.\n'
1927    r' \*\n'
1928    r' \* The Original Code is the Netscape Portable Runtime \(NSPR\)\.\n'
1929    r' \*\n'
1930    r' \* The Initial Developer of the Original Code is\n'
1931    r' \* Netscape Communications Corporation\.\n'
1932    r' \* Portions created by the Initial Developer are Copyright \(C\) 1998-2000\n'
1933    r' \* the Initial Developer\. +All Rights Reserved\.\n'
1934    r' \*\n'
1935    r' \* Contributor\(s\):\n'
1936    r' \*\n'
1937    r' \* Alternatively, the contents of this file may be used under the terms of\n'
1938    r' \* either the GNU General Public License Version 2 or later \(the "GPL"\), or\n'
1939    r' \* the GNU Lesser General Public License Version 2\.1 or later \(the "LGPL"\),\n'
1940    r' \* in which case the provisions of the GPL or the LGPL are applicable instead\n'
1941    r' \* of those above\. +If you wish to allow use of your version of this file only\n'
1942    r' \* under the terms of either the GPL or the LGPL, and not to allow others to\n'
1943    r' \* use your version of this file under the terms of the MPL, indicate your\n'
1944    r' \* decision by deleting the provisions above and replace them with the notice\n'
1945    r' \* and other provisions required by the GPL or the LGPL\. +If you do not delete\n'
1946    r' \* the provisions above, a recipient may use your version of this file under\n'
1947    r' \* the terms of any one of the MPL, the GPL or the LGPL\.\n'
1948    r' \*\n'
1949    r' \* \*\*\*\*\* END LICENSE BLOCK \*\*\*\*\* \*/\n'
1950  ),
1951
1952  // Advice for this was "text verbatim".
1953  RegExp(
1954    kIndent +
1955    r'Copyright \(c\) 2015-2016 Khronos Group\. This work is licensed under a\n'
1956    r'\1\2Creative Commons Attribution 4\.0 International License; see\n'
1957    r'\1\2http://creativecommons\.org/licenses/by/4\.0/',
1958    multiLine: true,
1959    caseSensitive: false,
1960  ),
1961
1962  // by analogy to the above one
1963  // seen in jsr305
1964  RegExp(
1965    kIndent +
1966    r'Copyright .+\n'
1967    r'\1\2Released under the Creative Commons Attribution License\n'
1968    r'\1\2 *\(?http://creativecommons\.org/licenses/by/2\.5/?\)?\n'
1969    r'\1\2Official home: .+',
1970    multiLine: true,
1971    caseSensitive: false,
1972  ),
1973
1974  // Advice for this was "Just display its text as a politeness. Nothing else required".
1975  RegExp(
1976    r'()()/\* mdXhl\.c \* ----------------------------------------------------------------------------\n'
1977    r' \* "THE BEER-WARE LICENSE" \(Revision 42\):\n'
1978    r' \* <phk@FreeBSD\.org> wrote this file\. +As long as you retain this notice you\n'
1979    r' \* can do whatever you want with this stuff\. If we meet some day, and you think\n'
1980    r' \* this stuff is worth it, you can buy me a beer in return\. +Poul-Henning Kamp\n'
1981    r' \* ----------------------------------------------------------------------------\n'
1982    r' \* libjpeg-turbo Modifications:\n'
1983    r' \* Copyright \(C\) 2016, D\. R\. Commander\.?\n'
1984    r' \* Modifications are under the same license as the original code \(see above\)\n'
1985    r' \* ----------------------------------------------------------------------------'
1986  ),
1987];
1988
1989
1990// FALLBACK PATTERNS
1991
1992final List<RegExp> csFallbacks = <RegExp>[
1993
1994  // used with _tryNone
1995  // groups are ignored
1996
1997];
1998
1999
2000// FORWARD REFERENCE
2001
2002class ForwardReferencePattern {
2003  ForwardReferencePattern({ this.firstPrefixIndex, this.indentPrefixIndex, this.pattern, this.targetPattern });
2004  final int firstPrefixIndex;
2005  final int indentPrefixIndex;
2006  final RegExp pattern;
2007  final RegExp targetPattern;
2008}
2009
2010final List<ForwardReferencePattern> csForwardReferenceLicenses = <ForwardReferencePattern>[
2011
2012  // used with _tryForwardReferencePattern
2013
2014  // OpenSSL (in Dart third_party)
2015  ForwardReferencePattern(
2016    firstPrefixIndex: 1,
2017    indentPrefixIndex: 2,
2018    pattern: RegExp(
2019      kIndent + r'(?:'
2020      +
2021      (
2022        r'Portions of the attached software \("Contribution"\) are developed by .+ and are contributed to the OpenSSL project\.'
2023        .replaceAll(' ', _linebreak)
2024      )
2025      +
2026      r'|'
2027      +
2028      (
2029        r'The .+ included herein is developed by .+, and is contributed to the OpenSSL project\.'
2030        .replaceAll(' ', _linebreak)
2031      )
2032      +
2033      r'|'
2034      r'(?:\1? *\n)+'
2035      r')*'
2036      r'\1\2 *'
2037      +
2038      (
2039        r'The .+ is licensed pursuant to the OpenSSL open source license provided (?:below|above)\.'
2040        .replaceAll(' ', _linebreak)
2041      ),
2042      multiLine: true,
2043      caseSensitive: false,
2044    ),
2045    targetPattern: RegExp('Redistribution and use in source and binary forms(?:.|\n)+OpenSSL')
2046  ),
2047
2048  // libevent
2049  ForwardReferencePattern(
2050    firstPrefixIndex: 1,
2051    indentPrefixIndex: 2,
2052    pattern: RegExp(
2053      kIndent + r'Use is subject to license terms\.$',
2054      multiLine: true,
2055      caseSensitive: false,
2056    ),
2057    targetPattern: RegExp('Redistribution and use in source and binary forms(?:.|\n)+SUN MICROSYSTEMS')
2058  ),
2059
2060];
2061