-
Notifications
You must be signed in to change notification settings - Fork 80
/
update_headers.sh
executable file
·106 lines (100 loc) · 3.4 KB
/
update_headers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
###############################################################################
# Copyright (c) 2016 Boundless and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Distribution License v1.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/org/documents/edl-v10.html
#
# Contributors:
# Erik Merkle (Boundless)
###############################################################################
###############################################################################
# Description:
# Script to update Java source code headers.
#
# 1) Run from the root of the project (i.e. parent directory of "src"
# 2) Run with no arguments to use the current system date, otherwise provide
# the desired 4 digit YEAR for the copyright end date.
#
# ex:
#
# $ ./update_headers.sh
#
# or
#
# $ ./update_headers.sh 2017
#
# NOTE: Inspect the results of the script by running "git diff" to ensure
# only the headers that should be updated are updated. Currently,
# only these files have a header that should not be overwritten:
#
# src/core/src/main/java/org/locationtech/geogig/plumbing/diff/DiffMatchPatch.java
# src/core/src/main/java/org/locationtech/geogig/storage/datastream/Varint.java
###############################################################################
function findCreateYear() {
FILE=${1}
END=`grep -n -m 1 "Contributors" ${FILE}|cut -f1 -d:`
if [ "$END" = "" ]
then
# couldn't find a copyright date already in the file, use the git history
git log --format=%cI --follow ${FILE}|tail -1|cut -f1 -d\-
else
# use the first 20XX date in the existing header
head -n ${END} ${FILE}|grep -m 1 20[0-9][0-9]|sed 's/^[^0-9]*\(20[0-9][0-9]\).*/\1/g'
fi
}
function updateHeader() {
FILE=${1}
START_DATE=${2}
END_DATE=${3}
echo -n "Processing ${FILE}"
if [ "$START_DATE" = "$END_DATE" ]
then
COPYRIGHT="Copyright (c) ${START_DATE} Boundless and others."
echo -n "."
else
COPYRIGHT="Copyright (c) ${START_DATE}-${END_DATE} Boundless and others."
echo -n "."
fi
# header
HEADER=$"/* ${COPYRIGHT}\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Distribution License v1.0\n * which accompanies this distribution, and is available at\n * https://www.eclipse.org/org/documents/edl-v10.html\n *"
echo -n "."
# see if the file has Authors. If not, use the initial committer author
CONTRIB_LINE=`grep -n -m 1 "Contributors" ${FILE}|cut -f1 -d:`
echo -n "."
if [ "$CONTRIB_LINE" = "" ]
then
# no authors
AUTHOR=`git log --format=%an --follow ${FILE}|tail -1`
echo -n "."
HEADER_ADD=$"\n * Contributors:\n * ${AUTHOR} - initial implementation\n */"
echo -n "."
HEADER=$"${HEADER}${HEADER_ADD}"
echo -n "."
PKG_LINE=`grep -n -m 1 "package" ${FILE}|cut -f1 -d':'`
echo -n "."
else
PKG_LINE=${CONTRIB_LINE}
echo -n "."
fi
# replace header
echo -e "${HEADER}" > tmp
echo -n "."
tail -n +${PKG_LINE} ${FILE} >> tmp
echo -n "."
mv tmp ${FILE}
echo "DONE!"
}
# main
mdofiedYear=${1}
if [ "$modifiedYear" = "" ]
then
# No end date provided, use current time
modifiedYear=`date +%Y`
fi
for javafile in `find src -type f -name "*.java"`
do
createYear=`findCreateYear ${javafile}`
updateHeader ${javafile} ${createYear} ${modifiedYear}
done