5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 # Make sure there is a correctly formed copyright message containing
31 # We treat extant but incorrect copyrights of known format as present
32 # for the purposes of the "no copyright found" messages to avoid
33 # treating every otherwise incorrect copyright as also not present
38 def err(stream
, msg
, fname
, line
=None):
40 stream
.write("%s: %d: %s\n" % (fname
, line
, msg
))
42 stream
.write("%s: %s\n" % (fname
, msg
))
44 # pre-2002 copyright with '(c)'
45 oldcopyright
= re
.compile(r
'Copyright \(c\) .* Sun Microsystems, Inc\.')
47 # pre-2002 copyright with 'by'
48 oldcopyright1
= re
.compile(r
'Copyright .* by Sun Microsystems, Inc\.')
50 # last valid Sun copyright
51 suncopyright
= re
.compile(r
'Copyright ([\d, -]+) Sun Microsystems, Inc\.' +
52 r
'(\s+)(All rights reserved\.)?')
54 # old, check to make sure no longer present
55 licterms
= 'Use is subject to license terms.'
57 # initial Oracle copyright
58 goodcopyright
= re
.compile(r
'Copyright \(c\) (\d\d\d\d, )?(\d\d\d\d)(,)? ' +
59 r
'Oracle and/or its affiliates\.(\s+)' +
60 r
'All rights reserved\.')
62 def copyright(fh
, filename
=None, output
=sys
.stderr
):
63 ret
= lineno
= rights
= 0
75 err(output
, "old '%s' message found" % licterms
,
80 if oldcopyright
.search(line
):
81 err(output
, "ancient Sun copyright", filename
,
87 elif oldcopyright1
.search(line
):
88 err(output
, "pre-2002 Sun copyright", filename
, lineno
)
93 elif suncopyright
.search(line
):
94 err(output
, "old Sun copyright", filename
, lineno
)
101 # group 1 = optional initial year
102 # group 2 = current year
103 # group 3 = comma after current year
104 # group 4 = spacing between phrases
106 match
= goodcopyright
.search(line
)
108 # only check for the old license message on the line
109 # following a copyright match
113 year
= time
.strftime('%Y')
114 if match
.group(2) != year
:
115 err(output
, "wrong copyright year %s, should "
117 (match
.group(2), year
), filename
, lineno
)
120 if match
.group(3) != ',':
121 err(output
, "need comma after current year",
125 if match
.group(4) != ' ':
126 err(output
, "need one space between copyright "
127 "and all rights reserved phrases",
132 err(output
, "no copyright message found", filename
)