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