Skip to content

Commit

Permalink
Merge branch 'master' into rfvc
Browse files Browse the repository at this point in the history
  • Loading branch information
IlnurHA committed May 3, 2024
2 parents e83d59e + 4f9d096 commit 054a23d
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 16 deletions.
56 changes: 56 additions & 0 deletions metrics/rfvh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2021-2024 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -e
set -o pipefail

java=$1
output=$(realpath "$2")

cd "$(dirname "${java}")"
base=$(basename "${java}")

# To check that file was added in commit any time
if git status > /dev/null 2>&1 && test -n "$(git log --oneline -- "${base}")"; then
my_rvh=$(git log -L:"class\s:${java}" | grep -E "^[+-].*$" | grep -Ev "^\-\-\-\s\S+$" | grep -Evc "^\+\+\+\s\S+$")
files=$(git ls-tree -r "$(git branch --show-current)" --name-only)
all_rvhs=0

# source: https://stackoverflow.com/questions/44440506/split-string-with-literal-n-in-a-for-loop
while [[ $files ]]; do # iterate as long as we have input
if [[ $files = *$'\n'* ]]; then # if there's a '\n' sequence later...
first=${files%%$'\n'*} # put everything before it into 'first'
rest=${files#*$'\n'} # and put everything after it in 'rest'
else # if there's no '\n' later...
first=${files} # then put the whole rest of the string in 'first'
rest='' # and there is no 'rest'
fi
rvh=$(git log -L:"class\s:${first}" | grep -E "^[+-].*$" | grep -Ev "^\-\-\-\s\S+$" | grep -Evc "^\+\+\+\s\S+$")
((all_rvhs+=rvh))
files=$rest
done
rfvh=$(python3 -c "print(${my_rvh} / ${all_rvhs})")
else
rfvh=0
fi

echo "rfvh ${rfvh} Relative File Volatility by Hits for file" > "${output}"
70 changes: 70 additions & 0 deletions tests/metrics/test-rfvh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2021-2024 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -e
set -o pipefail

temp=$1
stdout=$2

{
metric_script_path="${LOCAL}/metrics/rfvh.sh"
cd "${temp}"

rm -rf ./*
rm -rf .git

git init --quiet .
git config user.email '[email protected]'
git config user.name 'Foo'
git config commit.gpgsign false

java_dir="./foo/dir/"
java1="FooTest.java"
java2="FooTest2.java"
java3="FooTest3.java"

mkdir -p "${java_dir}"
cd ${java_dir}

touch "${java1}"
touch "stdout"

printf "class Foo {}" > "${java1}"
git add "${java1}"
git commit --quiet -m "first commit"
${metric_script_path} "${java1}" "stdout"
grep "rfvh 1" "stdout"

printf "class Foo {}" > "${java2}"
git add "${java2}"
git commit --quiet -m "+second commit"
${metric_script_path} "${java1}" "stdout"
grep "rfvh 0.5" "stdout"

printf "class Foo {}" > "${java3}"
git add "${java3}"
git commit --quiet -m "-third commit"
${metric_script_path} "${java1}" "stdout"
grep "rfvh 0.33" "stdout"
} > "${stdout}" 2>&1
echo "👍🏻 Correctly calculated relative file volatility by hits"
32 changes: 16 additions & 16 deletions tex/report.bib
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ @misc{fernandez2006
year = {2006},
}


@inproceedings{5463348,
author = {Robles, Gregorio},
booktitle = {{Proceedings of the Working Conference on Mining Software Repositories}},
Expand All @@ -67,18 +66,18 @@ @article{7887704
author = {Cosentino, Valerio and C\'{a}novas Izquierdo, Javier L. and Cabot, Jordi},
doi = {10.1109/ACCESS.2017.2682323},
journal = {{IEEE Access}},
number = {1},
pages = {7173--7192},
title = {{A Systematic Mapping Study of Software Development With GitHub}},
volume = {5},
number = {1},
year = {2017},
}

@article{nunez2017source,
author = {Nu{\~n}ez-Varela, Alberto S. and P{\'e}rez-Gonzalez, H{\'e}ctor G. and Mart{\'\i}nez-Perez, Francisco E. and Soubervielle-Montalvo, Carlos},
doi = {10.1016/j.jss.2017.03.044},
number = {1},
journal = {{Journal of Systems and Software}},
number = {1},
pages = {164--197},
publisher = {Elsevier},
title = {{Source Code Metrics: A Systematic Mapping Study}},
Expand All @@ -91,10 +90,10 @@ @article{mccabe1976complexity
doi = {10.1109/TSE.1976.233837},
journal = {{IEEE Transactions on Software Engineering}},
number = {4},
volume = {1},
pages = {308--320},
publisher = {IEEE},
title = {{A Complexity Measure}},
volume = {1},
year = {1976},
}

Expand All @@ -109,7 +108,7 @@ @inproceedings{campbell2018cognitive

@misc{henderson1996coupling,
author = {Henderson-Sellers, Brian and Constantine, Larry L. and Graham, Ian M.},
publisher = {{Object Oriented Systems}},
publisher = {Object Oriented Systems},
title = {{Coupling and Cohesion (Towards a Valid Metrics Suite for Object-Oriented Analysis and Design)}},
year = {1996},
}
Expand Down Expand Up @@ -155,25 +154,25 @@ @misc{daigle2023
}

@article{munaiah2017curating,
title={{Curating GitHub for Engineered Software Projects}},
author={Munaiah, Nuthan and Kroh, Steven and Cabrey, Craig and Nagappan, Meiyappan},
journal={{Empirical Software Engineering}},
volume={22},
number={1},
pages={3219--3253},
year={2017},
publisher={Springer},
doi={10.1007/s10664-017-9512-6}
author = {Munaiah, Nuthan and Kroh, Steven and Cabrey, Craig and Nagappan, Meiyappan},
doi = {10.1007/s10664-017-9512-6},
journal = {{Empirical Software Engineering}},
number = {1},
pages = {3219--3253},
publisher = {Springer},
title = {{Curating GitHub for Engineered Software Projects}},
volume = {22},
year = {2017},
}

@article{coleman1994,
author = {Coleman, Don and Ash, Dan and Lowther, Bruce and Oman, Paul},
doi = {10.1109/2.303623},
journal = {{Computer}},
volume={27},
number={8},
number = {8},
publisher = {IEEE},
title = {{Using Metrics to Evaluate Software System Maintainability}},
volume = {27},
year = {1994},
}

Expand All @@ -184,3 +183,4 @@ @book{halstead1977elements
title = {{Elements of Software Science (Operating and Programming Systems Series)}},
year = {1977},
}

0 comments on commit 054a23d

Please sign in to comment.