Path: blob/aarch64-shenandoah-jdk8u272-b10/make/scripts/update_copyright_year.sh
32284 views
#!/bin/bash -f12#3# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5#6# This code is free software; you can redistribute it and/or modify it7# under the terms of the GNU General Public License version 2 only, as8# published by the Free Software Foundation.9#10# This code is distributed in the hope that it will be useful, but WITHOUT11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13# version 2 for more details (a copy is included in the LICENSE file that14# accompanied this code).15#16# You should have received a copy of the GNU General Public License version17# 2 along with this work; if not, write to the Free Software Foundation,18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19#20# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21# or visit www.oracle.com if you need additional information or have any22# questions.23#2425# Script to update the Copyright YEAR range in Mercurial sources.26# (Originally from xdono, Thanks!)2728if [ "`uname -s`" = "SunOS" ] ; then29awk=nawk30else31awk=awk32fi3334# Stop on any error35set -e3637# Temp area38tmp=/tmp/`basename $0`.${USER}.$$39rm -f -r ${tmp}40mkdir -p ${tmp}41total=04243# This year or supplied year44if [ "$1" != "" ] ; then45year="$1"46else47year=`date +%Y`48fi4950# Return true if it makes sense to edit this file51saneFileToCheck()52{53if [ "$1" != "" -a -f $1 ] ; then54isText=`file "$1" | egrep -i '(text|source)' | cat`55hasCopyright=`grep 'Copyright' "$1" | cat`56lastLineCount=`tail -1 "$1" | wc -l`57if [ "${isText}" != "" \58-a "${hasCopyright}" != "" \59-a ${lastLineCount} -eq 1 ] ; then60echo "true"61else62echo "false"63fi64else65echo "false"66fi67}6869# Update the copyright year on a file70updateFile() # file71{72changed="false"73if [ `saneFileToCheck "$1"` = "true" ] ; then74copyright="Copyright (c)"75company="Oracle"76rm -f $1.OLD77mv $1 $1.OLD78cat $1.OLD | \79sed -e "s@\(${copyright} [12][0-9][0-9][0-9],\) [12][0-9][0-9][0-9], ${company}@\1 ${year}, ${company}@" | \80sed -e "s@\(${copyright} [12][0-9][0-9][0-9],\) ${company}@\1 ${year}, ${company}@" | \81sed -e "s@${copyright} ${year}, ${year}, ${company}@${copyright} ${year}, ${company}@" \82> $183if ! diff -b -w $1.OLD $1 > /dev/null ; then \84changed="true"85rm -f $1.OLD86else87rm -f $188mv $1.OLD $189fi90fi91echo "${changed}"92}9394# Update the copyright year on all files changed by this changeset95updateChangesetFiles() # changeset96{97count=098files=${tmp}/files.$199rm -f ${files}100hg log --rev $1 -v --template '{files}\n' | expand \101| ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}' \102> ${files}103if [ -f "${files}" -a -s "${files}" ] ; then104copyright="Copyright (c)"105company="Oracle"106fcount=`cat ${files}| wc -l`107for i in `cat ${files}` ; do108if [ `updateFile "${i}"` = "true" ] ; then109count=`expr ${count} '+' 1`110fi111done112if [ ${count} -gt 0 ] ; then113printf " UPDATED year on %d of %d files.\n" ${count} ${fcount}114total=`expr ${total} '+' ${count}`115else116printf " None of the %d files were changed.\n" ${fcount}117fi118else119printf " ERROR: No files changed in the changeset? Must be a mistake.\n"120set -x121ls -al ${files}122hg log --rev $1 -v --template '{files}\n'123hg log --rev $1 -v --template '{files}\n' | expand \124| ${awk} -F' ' '{for(i=1;i<=NF;i++)print $i}'125set +x126exit 1127fi128rm -f ${files}129}130131# Check if repository is clean132previous=`hg status|wc -l`133if [ ${previous} -ne 0 ] ; then134echo "WARNING: This repository contains previously edited working set files."135echo " hg status | wc -l = `hg status | wc -l`"136fi137138# Get all changesets this year139all_changesets=${tmp}/all_changesets140rm -f ${all_changesets}141hg log --no-merges -v -d "${year}-01-01 to ${year}-12-31" --template '{node}\n' > ${all_changesets}142143# Check changeset to see if it is Copyright only changes, filter changesets144if [ -s ${all_changesets} ] ; then145echo "Changesets made in ${year}: `cat ${all_changesets} | wc -l`"146index=0147cat ${all_changesets} | while read changeset ; do148index=`expr ${index} '+' 1`149desc=${tmp}/desc.${changeset}150rm -f ${desc}151echo "------------------------------------------------"152hg log --rev ${changeset} --template '{desc}\n' > ${desc}153printf "%d: %s\n%s\n" ${index} "${changeset}" "`cat ${desc}|head -1`"154if [ "${year}" = "2010" ] ; then155if cat ${desc} | fgrep -i "Added tag" > /dev/null ; then156printf " EXCLUDED tag changeset.\n"157elif cat ${desc} | fgrep -i rebrand > /dev/null ; then158printf " EXCLUDED rebrand changeset.\n"159elif cat ${desc} | fgrep -i copyright > /dev/null ; then160printf " EXCLUDED copyright changeset.\n"161else162updateChangesetFiles ${changeset}163fi164else165if cat ${desc} | fgrep -i "Added tag" > /dev/null ; then166printf " EXCLUDED tag changeset.\n"167elif cat ${desc} | fgrep -i "copyright year" > /dev/null ; then168printf " EXCLUDED copyright year changeset.\n"169else170updateChangesetFiles ${changeset}171fi172fi173rm -f ${desc}174done175fi176177if [ ${total} -gt 0 ] ; then178echo "---------------------------------------------"179echo "Updated the copyright year on a total of ${total} files."180if [ ${previous} -eq 0 ] ; then181echo "This count should match the count of modified files in the repository: hg status -m"182else183echo "WARNING: This repository contained previously edited working set files."184fi185echo " hg status -m | wc -l = `hg status -m | wc -l`"186else187echo "---------------------------------------------"188echo "No files were changed"189if [ ${previous} -ne 0 ] ; then190echo "WARNING: This repository contained previously edited working set files."191fi192echo " hg status -m | wc -l = `hg status -m | wc -l`"193fi194195# Cleanup196rm -f -r ${tmp}197exit 0198199200201