Skip to content

Commit

Permalink
#25 multimetric
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 13, 2023
1 parent 1a1b647 commit c987ae8
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 3 deletions.
36 changes: 36 additions & 0 deletions metrics/multimetric.sh
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2021-2023 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=$2

json=$(multimetric "${java}")
body=$(echo "${json}" | jq '.overall')
cat <<EOT> "${output}"
hsdif $(echo "${body}" | jq '.halstead_difficulty') Halstead Difficulty
hsef $(echo "${body}" | jq '.halstead_effort') Halstead Effort
midx $(echo "${body}" | jq '.maintainability_index') Maintainability Index
EOT
4 changes: 3 additions & 1 deletion requirements.txt
@@ -1,4 +1,6 @@
javalang==0.13.0
pygments==2.16.1
flake8==6.1.0
pylint==3.0.1
pylint==3.0.1
multimetric=2.0.5
chardet=5.2.0
4 changes: 4 additions & 0 deletions steps/env.sh
Expand Up @@ -64,6 +64,10 @@ pdflatex --version

aspell --version

jq --version

multimetric --help > /dev/null

rubocop -v

inkscape --version
Expand Down
9 changes: 9 additions & 0 deletions steps/install.sh
Expand Up @@ -61,6 +61,15 @@ if ! cloc --version 2>/dev/null; then
fi
fi

if ! jq --version 2>/dev/null; then
if [ -n "${linux}" ]; then
apt-get install -y jq
else
echo "Install 'jq' somehow"
exit 1
fi
fi

if ! shellcheck --version 2>/dev/null; then
if [ -n "${linux}" ]; then
apt-get install -y shellcheck
Expand Down
6 changes: 4 additions & 2 deletions tests/metrics/test-cloc.sh
Expand Up @@ -28,6 +28,8 @@ stdout=$2

java="${temp}/Foo long 'weird' name (--).java"
echo "class Foo {}" > "${java}"
"${LOCAL}/metrics/cloc.sh" "${java}" "${temp}/stdout" >> "${stdout}" 2>&1
grep "loc 1" "${temp}/stdout" >> "${stdout}" 2>&1
{
"${LOCAL}/metrics/cloc.sh" "${java}" "${temp}/stdout"
grep "loc 1" "${temp}/stdout"
} >> "${stdout}" 2>&1
echo "👍🏻 Correctly counted lines of code"
52 changes: 52 additions & 0 deletions tests/metrics/test-multimetric.sh
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2021-2023 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

# To make sure it is installed
multimetric --help >/dev/null

java="${temp}/Foo long 'weird' name (--).java"
cat > "${java}" <<EOT
class Foo extends Boo implements Bar {
// This is static
private static int X = 1;
private String z;
Foo(String zz) {
this.z = zz;
}
private final boolean boom() { return true; }
}
EOT
{
"${LOCAL}/metrics/multimetric.sh" "${java}" "${temp}/stdout"
cat "${temp}/stdout"
grep "hsdif 6.188" "${temp}/stdout"
grep "hsef 758.735" "${temp}/stdout"
grep "midx 100" "${temp}/stdout"
} >> "${stdout}" 2>&1
echo "👍🏻 Correctly counted lines of code"

0 comments on commit c987ae8

Please sign in to comment.