make/scripts/lic_check.sh
author vlivanov
Mon, 23 Sep 2013 19:51:40 +0400
changeset 20494 cf77ae5ff678
parent 12926 7964b3f43b86
permissions -rw-r--r--
8001107: @Stable annotation for constant folding of lazily evaluated variables Reviewed-by: twisti, kvn, rbackman Contributed-by: john.r.rose@oracle.com, vladimir.x.ivanov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12926
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
     1
#! /bin/sh -f
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
     2
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
     3
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
     4
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
     5
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
     6
# This code is free software; you can redistribute it and/or modify it
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
     7
# under the terms of the GNU General Public License version 2 only, as
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
     8
# published by the Free Software Foundation.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
     9
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    10
# This code is distributed in the hope that it will be useful, but WITHOUT
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    13
# version 2 for more details (a copy is included in the LICENSE file that
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    14
# accompanied this code).
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    15
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    16
# You should have received a copy of the GNU General Public License version
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    17
# 2 along with this work; if not, write to the Free Software Foundation,
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    18
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    19
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    20
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    21
# or visit www.oracle.com if you need additional information or have any
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    22
# questions.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    23
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    24
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    25
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    26
# This script checks a copyright notice.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    27
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    28
# The script should be located in the main jdk repository under make/scripts.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    29
# It works with the templates in the make/templates directory of the jdk source.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    30
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    31
# Usage: "lic_check.sh [-gpl] or [-gplcp] or [-bsd] file(s)"
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    32
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    33
script_directory=`dirname $0`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    34
script_name=`basename $0`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    35
first_option=$1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    36
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    37
# parse the first argument
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    38
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    39
case "$1" in
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    40
	"-gpl")
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    41
		header="gpl-header"
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    42
		;;
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    43
	"-gplcp")
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    44
		header="gpl-cp-header"
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    45
		;;
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    46
	"-bsd")
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    47
		header="bsd-header"
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    48
                ;;
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    49
	*)
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    50
		echo "Usage: $0 [-gpl] or [-gplcp] or [-bsd] file(s)" 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    51
		exit 1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    52
		;;
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    53
esac
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    54
shift
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    55
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    56
#initialize error status
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    57
error_status=0
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    58
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    59
# determine and set the absolute path for the script directory
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    60
D=`dirname "${script_directory}"`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    61
B=`basename "${script_directory}"`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    62
script_dir="`cd \"${D}\" 2>/dev/null && pwd || echo \"${D}\"`/${B}"
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    63
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    64
# set up a variable for the templates directory
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    65
template_dir=${script_dir}/../templates
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    66
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    67
# Check existence of the template directory.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    68
if [ ! -d ${template_dir} ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    69
        echo "ERROR: The templates directory "${template_dir}" doesn't exist." 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    70
        exit 1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    71
fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    72
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    73
# set the temporary file location
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    74
tmpfile=/tmp/source_file.$$
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    75
rm -f ${tmpfile}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    76
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    77
# check number of lines in the template file
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    78
lines=`cat ${template_dir}/${header} | wc -l`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    79
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    80
# the template file has one empty line at the end, we need to ignore it
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    81
lines=`expr ${lines} - 1`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    82
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    83
# A loop through the all script parameters:
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    84
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    85
# 1. Given a set of source files and a license template header, read a file name of each source file.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    86
# 2. Check if a given file exists. When a directory is encountered, dive in and process all sources in those directories.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    87
# 3. Read each line of the given file and check it for a copyright string.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    88
# 4. If a copyright string found, check the correctness of the years format in the string and replace years with %YEARS%.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    89
# 5. Continue reading the file until the number of lines is equal to the length of the license template header ($lines) and remove a comment prefix for each line.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    90
# 6. Store the result (the license header from a given file) into a temporary file.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    91
# 7. If a temporary file is not empty, compare it with a template file to verify if the license text is the same as in a template.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    92
# 8. Produce a error in case a temporary file is empty, it means we didn't find a copyright string, or it's not correct
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    93
#
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    94
while [ "$#" -gt "0" ] ; do
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    95
	touch ${tmpfile}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    96
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    97
	# In case of the directory as a parameter check recursively every file inside.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    98
	if [ -d $1 ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
    99
		curdir=`pwd`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   100
		cd $1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   101
		echo "*** Entering directory: "`pwd`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   102
		echo "***"
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   103
		files=`ls .`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   104
		sh ${script_dir}/${script_name} ${first_option} ${files}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   105
		status=$?
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   106
		if [ ${error_status} -ne 1 ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   107
			error_status=${status}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   108
		fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   109
		cd ${curdir}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   110
		shift
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   111
		continue
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   112
	else
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   113
		echo "### Checking copyright notice in the file: "$1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   114
		echo "###"
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   115
	fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   116
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   117
	# Check the existence of the source file.
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   118
	if [ ! -f $1 ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   119
        	echo "ERROR: The source file "$1" doesn't exist." 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   120
		error_status=1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   121
		shift
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   122
        	continue
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   123
	fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   124
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   125
	# read the source file and determine where the header starts, then get license header without prefix
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   126
	counter=0
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   127
	while read line ; do
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   128
		# remove windows "line feed" character from the line (if any)
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   129
		line=`echo "${line}" | tr -d '\r'`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   130
		# check if the given line contains copyright
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   131
		check_copyright=`echo "${line}" | grep "Copyright (c) "`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   132
		if [ "${check_copyright}" != "" ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   133
			# determine the comment prefix
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   134
			prefix=`echo "${line}" | cut -d "C" -f 1`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   135
			# remove prefix (we use "_" as a sed delimiter, since the prefix could be like //)
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   136
			copyright_without_prefix=`echo "${line}" | sed s_"^${prefix}"__g`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   137
			# copyright years
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   138
			year1=`echo "${copyright_without_prefix}" | cut -d " " -f 3`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   139
			year2=`echo "${copyright_without_prefix}" | cut -d " " -f 4`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   140
			# Processing the first year in the copyright string
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   141
			length=`expr "${year1}" : '.*'`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   142
			if [ ${length} -ne 5 ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   143
        			break
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   144
			fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   145
			check_year1=`echo ${year1} | egrep "19[0-9][0-9],|2[0-9][0-9][0-9],"`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   146
			if [ "${check_year1}" = "" ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   147
        			break
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   148
			fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   149
			# Processing the second year in the copyright string
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   150
			if [ "${year2}" != "Oracle" ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   151
        			length=`expr "${year2}" : '.*'`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   152
        			if [ ${length} -ne 5 ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   153
                			break
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   154
        			else
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   155
                			check_year2=`echo ${year2} | egrep "19[0-9][0-9],|2[0-9][0-9][0-9],"`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   156
                			if [ "${check_year2}" = "" ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   157
                        			break
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   158
                			fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   159
        			fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   160
			fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   161
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   162
			# copyright string without copyright years
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   163
			no_years=`echo "${copyright_without_prefix}" | sed 's/[0-9,]*//g'`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   164
			# copyright string before years
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   165
			before_years=`echo "${no_years}" | cut -d "O" -f 1`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   166
			# copyright string after years
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   167
			after_years=`echo "${no_years}" | cut -d ")" -f 2`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   168
			# form a new copyright string with %YEARS%
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   169
			new_copyright=`echo ${before_years}"%YEARS%"${after_years}`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   170
			# save the new copyright string to a file
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   171
			echo "${new_copyright}" > ${tmpfile}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   172
			# start counting the lines
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   173
                       	counter=1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   174
			# move to the next line
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   175
			continue
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   176
		fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   177
		if [ ${counter} -ne 0 ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   178
			# this should be a license header line, hence increment counter
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   179
			counter=`expr ${counter} + 1`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   180
			# record a string without a prefix to a file
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   181
			newline=`echo "${line}" | sed s_"^${prefix}"__`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   182
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   183
			# we need to take care of the empty lines in the header, i.e. check the prefix without spaces
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   184
			trimmed_prefix=`echo "${prefix}" | tr -d " "`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   185
			trimmed_line=`echo "${line}"  | tr -d " "`
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   186
			if [ "${trimmed_line}" = "${trimmed_prefix}" ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   187
				echo "" >> ${tmpfile}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   188
			else
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   189
				echo "${newline}" >> ${tmpfile}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   190
			fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   191
		fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   192
		# stop reading lines when a license header ends and add an empty line to the end
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   193
		if [ ${counter} -eq ${lines} ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   194
			echo "" >> ${tmpfile}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   195
			break
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   196
		fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   197
	done < $1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   198
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   199
	# compare the license header with a template file
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   200
	if [ -s ${tmpfile} ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   201
		diff -c ${tmpfile} ${template_dir}/${header} 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   202
		if [ "$?" = "0" ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   203
			echo "SUCCESS: The license header for "`pwd`"/"$1" has been verified."
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   204
			echo "###"
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   205
		else
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   206
			echo "ERROR: License header is not correct in "`pwd`"/"$1 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   207
			echo "See diffs above. " 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   208
			echo "###" 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   209
			echo "" 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   210
			error_status=1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   211
		fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   212
	else
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   213
		# If we don't have a temporary file, there is a problem with a copyright string (or no copyright string)
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   214
		echo "ERROR: Copyright string is not correct or missing in "`pwd`"/"$1 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   215
		echo "###" 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   216
		echo "" 1>&2
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   217
		error_status=1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   218
	fi
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   219
	rm -f ${tmpfile}
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   220
	shift
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   221
done
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   222
if [ ${error_status} -ne 0 ] ; then
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   223
	exit 1
7964b3f43b86 7178241: Basic script for JDK source code legal headers conformance verification
mbykov
parents:
diff changeset
   224
fi