make/scripts/update_copyright_year.sh

Mon, 14 Sep 2020 16:42:03 +0100

author
andrew
date
Mon, 14 Sep 2020 16:42:03 +0100
changeset 2554
7f60c2d9823e
parent 330
7e13dbf7e8af
child 1133
50aaf272884f
permissions
-rw-r--r--

Added tag jdk8u272-b08 for changeset 34c6baf21464

ohair@330 1 #!/bin/bash -f
ohair@280 2
ohair@280 3 #
ohair@280 4 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
ohair@280 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@280 6 #
ohair@280 7 # This code is free software; you can redistribute it and/or modify it
ohair@280 8 # under the terms of the GNU General Public License version 2 only, as
ohair@280 9 # published by the Free Software Foundation.
ohair@280 10 #
ohair@280 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@280 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@280 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@280 14 # version 2 for more details (a copy is included in the LICENSE file that
ohair@280 15 # accompanied this code).
ohair@280 16 #
ohair@280 17 # You should have received a copy of the GNU General Public License version
ohair@280 18 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@280 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@280 20 #
ohair@280 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@280 22 # or visit www.oracle.com if you need additional information or have any
ohair@280 23 # questions.
ohair@280 24 #
ohair@280 25
ohair@280 26 # Script to update the Copyright YEAR range in Mercurial sources.
ohair@280 27 # (Originally from xdono, Thanks!)
ohair@280 28
ohair@280 29 if [ "`uname -s`" = "SunOS" ] ; then
ohair@280 30 awk=nawk
ohair@280 31 else
ohair@280 32 awk=awk
ohair@280 33 fi
ohair@280 34
ohair@280 35 # Stop on any error
ohair@280 36 set -e
ohair@280 37
ohair@280 38 # Temp area
ohair@280 39 tmp=/tmp/`basename $0`.${USER}.$$
ohair@280 40 rm -f -r ${tmp}
ohair@280 41 mkdir -p ${tmp}
ohair@280 42 total=0
ohair@280 43
ohair@280 44 # This year or supplied year
ohair@280 45 if [ "$1" != "" ] ; then
ohair@280 46 year="$1"
ohair@280 47 else
ohair@280 48 year=`date +%Y`
ohair@280 49 fi
ohair@280 50
ohair@280 51 # Return true if it makes sense to edit this file
ohair@280 52 saneFileToCheck()
ohair@280 53 {
ohair@280 54 if [ "$1" != "" -a -f $1 ] ; then
ohair@280 55 isText=`file "$1" | egrep -i '(text|source)' | cat`
ohair@280 56 hasCopyright=`grep 'Copyright' "$1" | cat`
ohair@280 57 lastLineCount=`tail -1 "$1" | wc -l`
ohair@280 58 if [ "${isText}" != "" \
ohair@280 59 -a "${hasCopyright}" != "" \
ohair@280 60 -a ${lastLineCount} -eq 1 ] ; then
ohair@280 61 echo "true"
ohair@280 62 else
ohair@280 63 echo "false"
ohair@280 64 fi
ohair@280 65 else
ohair@280 66 echo "false"
ohair@280 67 fi
ohair@280 68 }
ohair@280 69
ohair@280 70 # Update the copyright year on a file
ohair@280 71 updateFile() # file
ohair@280 72 {
ohair@280 73 changed="false"
ohair@280 74 if [ `saneFileToCheck "$1"` = "true" ] ; then
ohair@280 75 copyright="Copyright (c)"
ohair@280 76 company="Oracle"
ohair@280 77 rm -f $1.OLD
ohair@280 78 mv $1 $1.OLD
ohair@280 79 cat $1.OLD | \
ohair@280 80 sed -e "s@\(${copyright} [12][0-9][0-9][0-9],\) [12][0-9][0-9][0-9], ${company}@\1 ${year}, ${company}@" | \
ohair@280 81 sed -e "s@\(${copyright} [12][0-9][0-9][0-9],\) ${company}@\1 ${year}, ${company}@" | \
ohair@280 82 sed -e "s@${copyright} ${year}, ${year}, ${company}@${copyright} ${year}, ${company}@" \
ohair@280 83 > $1
ohair@280 84 if ! diff -b -w $1.OLD $1 > /dev/null ; then \
ohair@280 85 changed="true"
ohair@280 86 rm -f $1.OLD
ohair@280 87 else
ohair@280 88 rm -f $1
ohair@280 89 mv $1.OLD $1
ohair@280 90 fi
ohair@280 91 fi
ohair@280 92 echo "${changed}"
ohair@280 93 }
ohair@280 94
ohair@280 95 # Update the copyright year on all files changed by this changeset
ohair@280 96 updateChangesetFiles() # changeset
ohair@280 97 {
ohair@280 98 count=0
ohair@280 99 files=${tmp}/files.$1
ohair@280 100 rm -f ${files}
ohair@280 101 hg log --rev $1 -v --template '{files}\n' | expand \
ohair@280 102 | ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}' \
ohair@280 103 > ${files}
ohair@280 104 if [ -f "${files}" -a -s "${files}" ] ; then
ohair@280 105 copyright="Copyright (c)"
ohair@280 106 company="Oracle"
ohair@280 107 fcount=`cat ${files}| wc -l`
ohair@280 108 for i in `cat ${files}` ; do
ohair@280 109 if [ `updateFile "${i}"` = "true" ] ; then
ohair@280 110 count=`expr ${count} '+' 1`
ohair@280 111 fi
ohair@280 112 done
ohair@280 113 if [ ${count} -gt 0 ] ; then
ohair@280 114 printf " UPDATED year on %d of %d files.\n" ${count} ${fcount}
ohair@280 115 total=`expr ${total} '+' ${count}`
ohair@280 116 else
ohair@280 117 printf " None of the %d files were changed.\n" ${fcount}
ohair@280 118 fi
ohair@280 119 else
ohair@280 120 printf " ERROR: No files changed in the changeset? Must be a mistake.\n"
ohair@280 121 set -x
ohair@280 122 ls -al ${files}
ohair@280 123 hg log --rev $1 -v --template '{files}\n'
ohair@280 124 hg log --rev $1 -v --template '{files}\n' | expand \
ohair@280 125 | ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}'
ohair@280 126 set +x
ohair@280 127 exit 1
ohair@280 128 fi
ohair@280 129 rm -f ${files}
ohair@280 130 }
ohair@280 131
ohair@280 132 # Check if repository is clean
ohair@280 133 previous=`hg status|wc -l`
ohair@280 134 if [ ${previous} -ne 0 ] ; then
ohair@280 135 echo "WARNING: This repository contains previously edited working set files."
ohair@280 136 echo " hg status | wc -l = `hg status | wc -l`"
ohair@280 137 fi
ohair@280 138
ohair@280 139 # Get all changesets this year
ohair@280 140 all_changesets=${tmp}/all_changesets
ohair@280 141 rm -f ${all_changesets}
ohair@280 142 hg log --no-merges -v -d "${year}-01-01 to ${year}-12-31" --template '{node}\n' > ${all_changesets}
ohair@280 143
ohair@280 144 # Check changeset to see if it is Copyright only changes, filter changesets
ohair@280 145 if [ -s ${all_changesets} ] ; then
ohair@280 146 echo "Changesets made in ${year}: `cat ${all_changesets} | wc -l`"
ohair@280 147 index=0
ohair@280 148 cat ${all_changesets} | while read changeset ; do
ohair@280 149 index=`expr ${index} '+' 1`
ohair@280 150 desc=${tmp}/desc.${changeset}
ohair@280 151 rm -f ${desc}
ohair@280 152 echo "------------------------------------------------"
ohair@280 153 hg log --rev ${changeset} --template '{desc}\n' > ${desc}
ohair@280 154 printf "%d: %s\n%s\n" ${index} "${changeset}" "`cat ${desc}|head -1`"
ohair@330 155 if [ "${year}" = "2010" ] ; then
ohair@330 156 if cat ${desc} | fgrep -i "Added tag" > /dev/null ; then
ohair@330 157 printf " EXCLUDED tag changeset.\n"
ohair@330 158 elif cat ${desc} | fgrep -i rebrand > /dev/null ; then
ohair@330 159 printf " EXCLUDED rebrand changeset.\n"
ohair@330 160 elif cat ${desc} | fgrep -i copyright > /dev/null ; then
ohair@330 161 printf " EXCLUDED copyright changeset.\n"
ohair@330 162 else
ohair@330 163 updateChangesetFiles ${changeset}
ohair@330 164 fi
ohair@280 165 else
ohair@330 166 if cat ${desc} | fgrep -i "Added tag" > /dev/null ; then
ohair@330 167 printf " EXCLUDED tag changeset.\n"
ohair@330 168 elif cat ${desc} | fgrep -i "copyright year" > /dev/null ; then
ohair@330 169 printf " EXCLUDED copyright year changeset.\n"
ohair@330 170 else
ohair@330 171 updateChangesetFiles ${changeset}
ohair@330 172 fi
ohair@280 173 fi
ohair@280 174 rm -f ${desc}
ohair@280 175 done
ohair@280 176 fi
ohair@280 177
ohair@280 178 if [ ${total} -gt 0 ] ; then
ohair@280 179 echo "---------------------------------------------"
ohair@280 180 echo "Updated the copyright year on a total of ${total} files."
ohair@280 181 if [ ${previous} -eq 0 ] ; then
ohair@280 182 echo "This count should match the count of modified files in the repository: hg status -m"
ohair@280 183 else
ohair@280 184 echo "WARNING: This repository contained previously edited working set files."
ohair@280 185 fi
ohair@280 186 echo " hg status -m | wc -l = `hg status -m | wc -l`"
ohair@280 187 else
ohair@280 188 echo "---------------------------------------------"
ohair@280 189 echo "No files were changed"
ohair@280 190 if [ ${previous} -ne 0 ] ; then
ohair@280 191 echo "WARNING: This repository contained previously edited working set files."
ohair@280 192 fi
ohair@280 193 echo " hg status -m | wc -l = `hg status -m | wc -l`"
ohair@280 194 fi
ohair@280 195
ohair@280 196 # Cleanup
ohair@280 197 rm -f -r ${tmp}
ohair@280 198 exit 0
ohair@280 199

mercurial