From c987ae88f278da86425dad73ba88fcf2d6ec8ab2 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Fri, 13 Oct 2023 04:58:07 +0300 Subject: [PATCH] #25 multimetric --- metrics/multimetric.sh | 36 +++++++++++++++++++++ requirements.txt | 4 ++- steps/env.sh | 4 +++ steps/install.sh | 9 ++++++ tests/metrics/test-cloc.sh | 6 ++-- tests/metrics/test-multimetric.sh | 52 +++++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 3 deletions(-) create mode 100755 metrics/multimetric.sh create mode 100755 tests/metrics/test-multimetric.sh diff --git a/metrics/multimetric.sh b/metrics/multimetric.sh new file mode 100755 index 00000000..cee52322 --- /dev/null +++ b/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 < "${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 diff --git a/requirements.txt b/requirements.txt index ba653309..1d364992 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ javalang==0.13.0 pygments==2.16.1 flake8==6.1.0 -pylint==3.0.1 \ No newline at end of file +pylint==3.0.1 +multimetric=2.0.5 +chardet=5.2.0 \ No newline at end of file diff --git a/steps/env.sh b/steps/env.sh index e0a70c7e..13082ff0 100755 --- a/steps/env.sh +++ b/steps/env.sh @@ -64,6 +64,10 @@ pdflatex --version aspell --version +jq --version + +multimetric --help > /dev/null + rubocop -v inkscape --version diff --git a/steps/install.sh b/steps/install.sh index c8b8a3e2..5b31cb98 100755 --- a/steps/install.sh +++ b/steps/install.sh @@ -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 diff --git a/tests/metrics/test-cloc.sh b/tests/metrics/test-cloc.sh index 377a1b5e..cb33e127 100755 --- a/tests/metrics/test-cloc.sh +++ b/tests/metrics/test-cloc.sh @@ -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" diff --git a/tests/metrics/test-multimetric.sh b/tests/metrics/test-multimetric.sh new file mode 100755 index 00000000..c17caf0d --- /dev/null +++ b/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}" <> "${stdout}" 2>&1 +echo "👍🏻 Correctly counted lines of code"