-
Notifications
You must be signed in to change notification settings - Fork 15
/
code_statistics
executable file
·52 lines (42 loc) · 2.16 KB
/
code_statistics
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
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------
# This file is part of Fim - File Integrity Manager
#
# Copyright (C) 2017 Etienne Vrignaud
#
# Fim is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Fim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Fim. If not, see <https://www.gnu.org/licenses/>.
#-----------------------------------------------------------------------------------------------------------------------
if [ ! -d build ]; then
mkdir build
fi
allJavaLines=build/all_java_lines
trimmedLines=build/all_java_lines_trimed
meaningfulLines=build/all_java_lines_meaningful
uniqDuplicatedLines=build/uniq_duplicated_lines
find . -name "*.java" -exec cat {} \; > ${allJavaLines}
totalJavaLines=`cat ${allJavaLines} | wc -l`
# Trim all lines, remove empty lines and remove ^M
cat ${allJavaLines} | awk '{$1=$1;print}' | tr -d $'\r' > ${trimmedLines}
# Remove non meaningful lines
cat ${trimmedLines} | egrep -v "^$|^\{$|^\}$|^//|^/\*|^\*|^import|^package|^try|^continue|^else|^break|^return|^@Test" > ${meaningfulLines}
meaningfulLinesCount=`cat ${meaningfulLines} | wc -l`
differentLinesCount=`cat ${meaningfulLines} | sort | uniq | wc -l`
duplicatedLines=`echo "$meaningfulLinesCount - $differentLinesCount" | bc`
duplicatePercent=`echo "$duplicatedLines * 100 / $meaningfulLinesCount" | bc`
cat ${meaningfulLines} | sort | uniq -d > ${uniqDuplicatedLines}
echo "Total java lines: $totalJavaLines"
echo "$duplicatedLines duplicated lines ($duplicatePercent% of the meaningful lines)"
echo ""
echo "More details in ${uniqDuplicatedLines}"
#-----------------------------------------------------------------------------------------------------------------------