Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3c37f14
Fix tests for CB
okorach-sonar Oct 9, 2025
3d1157a
Adjust tests to CB
okorach-sonar Oct 10, 2025
37e1c2a
Adjust tests to CB
okorach-sonar Oct 10, 2025
fc3e349
Fixes #1996
okorach-sonar Oct 10, 2025
68efb91
Use format to generate external issues report
okorach-sonar Oct 10, 2025
ebe1754
Pass format to external linters
okorach-sonar Oct 10, 2025
70609ad
Fix issue type (always vuln)
okorach-sonar Oct 10, 2025
9ffac23
Adjust tests to 9.9
okorach-sonar Oct 10, 2025
a8c5b90
Automatically detect 9.9 and set external issues format and scanner t…
okorach-sonar Oct 10, 2025
ede2770
Adjust tests to 9.9
okorach-sonar Oct 10, 2025
07b3104
Fix tests for 9.9
okorach-sonar Oct 10, 2025
27033c1
Adjust test to 9.9
okorach-sonar Oct 10, 2025
33b421f
Adjust for 9.9
okorach-sonar Oct 10, 2025
d182e0c
Fix search by severity problem when severities are different between …
okorach-sonar Oct 10, 2025
42ad11e
Fix problem on filters on type of issues
okorach-sonar Oct 10, 2025
a633ea7
Move env is separate file
okorach-sonar Oct 12, 2025
ded12ee
unify scripts
okorach-sonar Oct 12, 2025
78ac89b
rename scan.sh
okorach-sonar Oct 12, 2025
0b159fa
Added env.sh
okorach-sonar Oct 12, 2025
a2913cb
Remove useless file
okorach-sonar Oct 12, 2025
a3df828
Fix CONFDIR for flake8
okorach-sonar Oct 12, 2025
9ccce30
Remove determination of localbuild
okorach-sonar Oct 12, 2025
7c631da
Add determination of URL is 9.x
okorach-sonar Oct 12, 2025
8683d59
Make linters to run configurable
okorach-sonar Oct 12, 2025
313f5ea
Change vars expansion
okorach-sonar Oct 12, 2025
9267213
Fix python coverage and test paths that have to be relative
okorach-sonar Oct 12, 2025
987c20b
Remove useless code
okorach-sonar Oct 12, 2025
2bc2107
Use class to update wh
okorach-sonar Oct 12, 2025
a6e9719
Quality pass
okorach-sonar Oct 12, 2025
074f2a3
Quality pass
okorach-sonar Oct 12, 2025
36f265c
Select all shell files
okorach-sonar Oct 12, 2025
61d5b40
Add create delete test
okorach-sonar Oct 12, 2025
8889129
Add one more test on refresh() after delete
okorach-sonar Oct 12, 2025
88a3e98
Update with test data
okorach-sonar Oct 12, 2025
71686f6
Quality pass
okorach-sonar Oct 12, 2025
395678c
Quality pass
okorach-sonar Oct 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"sonarlint.focusOnNewCode": true,
"pylint.args": [
"[\"--rcfile=conf/pylintrc\"]"
]
],
"python.testing.pytestArgs": [
"test"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
12 changes: 6 additions & 6 deletions conf/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONFDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SONAR_TOOLS_RELEASE="${ROOTDIR}/sonar/version.py"
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

build_docs=0
build_docker=0

. "${CONF_DIR}/env.sh"

while [[ $# -ne 0 ]]; do
case "${1}" in
docs|doc)
Expand All @@ -40,7 +41,7 @@ done
echo "======= FORMATTING CODE ========="
ruff format
echo "======= BUILDING PACKAGE ========="
rm -rf "${ROOTDIR}/build/lib/sonar" "${ROOTDIR}/build/lib/cli" "${ROOTDIR}"/build/scripts*/sonar-tools "${ROOTDIR}"/dist/sonar_tools*
rm -rf "${ROOT_DIR}/build/lib/sonar" "${ROOT_DIR}/build/lib/cli" "${ROOT_DIR}"/build/scripts*/sonar-tools "${ROOT_DIR}"/dist/sonar_tools*
# python -m build
poetry build

Expand All @@ -52,6 +53,5 @@ fi

if [[ "${build_docker}" = "1" ]]; then
echo "======= BUILDING DOCKER IMAGE WITH SNAPSHOT ========="
version=$(grep PACKAGE_VERSION "${SONAR_TOOLS_RELEASE}" | cut -d "=" -f 2 | cut -d '"' -f 2)
docker build -t "olivierkorach/sonar-tools:${version}-snapshot" -t olivierkorach/sonar-tools:latest -f "${CONFDIR}/snapshot.Dockerfile" "${ROOTDIR}" --load
docker build -t "olivierkorach/sonar-tools:${VERSION}-snapshot" -t olivierkorach/sonar-tools:latest -f "${CONF_DIR}/snapshot.Dockerfile" "${ROOT_DIR}" --load
fi
22 changes: 11 additions & 11 deletions conf/build_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"

cd "${ROOTDIR}/test/unit" || exit 1
cd "${ROOT_DIR}/test/unit" || exit 1

export GEN_LOC=test/gen

Expand All @@ -31,22 +31,22 @@ echo "Generating edition / version specific tests"
for target in lts latest cb 9 9-ce common
do
echo "Generating tests for ${target}"
rm -rf "${ROOTDIR:?}/${GEN_LOC:?}/${target}"
mkdir -p "${ROOTDIR:?}/${GEN_LOC:?}/${target}" 2>/dev/null
rm -rf "${ROOT_DIR:?}/${GEN_LOC:?}/${target}"
mkdir -p "${ROOT_DIR:?}/${GEN_LOC:?}/${target}" 2>/dev/null
if [[ "${target}" = "common" ]]; then
b=$(basename "${f}" .py)
cp conftest.py utilities.py credentials.py "${ROOTDIR}/${GEN_LOC}/${target}"
cp test_common*.py "${ROOTDIR}/${GEN_LOC}/${target}"
cp conftest.py utilities.py credentials.py "${ROOT_DIR}/${GEN_LOC}/${target}"
cp test_common*.py "${ROOT_DIR}/${GEN_LOC}/${target}"
else
for f in *.py
do
b=$(basename "${f}" .py)
cp "${f}" "${ROOTDIR}/${GEN_LOC}/${target}/${b}_${target}.py"
cp "${f}" "${ROOT_DIR}/${GEN_LOC}/${target}/${b}_${target}.py"
done
cp "credentials-${target}.py" "${ROOTDIR}/${GEN_LOC}/${target}/credentials.py"
mv "${ROOTDIR}/${GEN_LOC}/${target}/conftest_${target}.py" "${ROOTDIR}/${GEN_LOC}/${target}/conftest.py"
mv "${ROOTDIR}/${GEN_LOC}/${target}/utilities_${target}.py" "${ROOTDIR}/${GEN_LOC}/${target}/utilities.py"
rm "${ROOTDIR}/${GEN_LOC}/${target}/"test_common*.py
cp "credentials-${target}.py" "${ROOT_DIR}/${GEN_LOC}/${target}/credentials.py"
mv "${ROOT_DIR}/${GEN_LOC}/${target}/conftest_${target}.py" "${ROOT_DIR}/${GEN_LOC}/${target}/conftest.py"
mv "${ROOT_DIR}/${GEN_LOC}/${target}/utilities_${target}.py" "${ROOT_DIR}/${GEN_LOC}/${target}/utilities.py"
rm "${ROOT_DIR}/${GEN_LOC}/${target}/"test_common*.py
fi
done

8 changes: 4 additions & 4 deletions conf/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONFDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

deps=0
"${CONFDIR}"/build.sh "$@"
"${CONF_DIR}"/build.sh "$@"

while [[ $# -ne 0 ]]; do
case "${1}" in
Expand All @@ -42,4 +42,4 @@ if [[ "${deps}" = "1" ]]; then
else
pipopts="--no-deps"
fi
pip install "${pipopts}" --force-reinstall "${ROOTDIR}"/dist/sonar_tools-*-py3-*.whl
pip install "${pipopts}" --force-reinstall "${ROOT_DIR}"/dist/sonar_tools-*-py3-*.whl
30 changes: 30 additions & 0 deletions conf/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
#
# sonar-tools
# Copyright (C) 2025 Olivier Korach
# mailto:olivier.korach AT gmail DOT com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This program 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

VERSION=$(grep PACKAGE_VERSION "${ROOT_DIR}/sonar/version.py" | cut -d "=" -f 2 | cut -d '"' -f 2)
BUILD_DIR="${ROOT_DIR}/build"

PYLINT_REPORT="${BUILD_DIR}/pylint-report.out"
# banditReport="${BUILD_DIR}/bandit-report.json"
FLAKE8_REPORT="${BUILD_DIR}/flake8-report.out"
SHELLCHECK_REPORT="${BUILD_DIR}/external-issues-shellcheck.json"
TRIVY_REPORT="${BUILD_DIR}/external-issues-trivy.json"
RUFF_REPORT="${BUILD_DIR}/external-issues-ruff.json"
31 changes: 15 additions & 16 deletions conf/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
# VERSION 3 of the License, or (at your option) any later VERSION.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Expand All @@ -16,40 +16,39 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONFDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

"${CONFDIR}"/build.sh
. "${CONF_DIR}"/env.sh

SONAR_TOOLS_RELEASE="${ROOTDIR}/sonar/version.py"
DOCKERFILE_RELEASE="${CONFDIR}/release.Dockerfile"
"${CONF_DIR}"/build.sh

version=$(grep PACKAGE_VERSION "${SONAR_TOOLS_RELEASE}" | cut -d "=" -f 2 | cut -d '"' -f 2)
DOCKERFILE_RELEASE="${CONF_DIR}/release.Dockerfile"

docker_version=$(grep 'pip install sonar-tools==' "${DOCKERFILE_RELEASE}" | sed -E 's/.*sonar-tools==([0-9\.]+).*/\1/')
docker_VERSION=$(grep 'pip install sonar-tools==' "${DOCKERFILE_RELEASE}" | sed -E 's/.*sonar-tools==([0-9\.]+).*/\1/')

if [[ "${version}" != "${docker_version}" ]]; then
echo "Docker version and pypi version are different (${docker_version} vs ${version}), release aborted"
if [[ "${VERSION}" != "${docker_VERSION}" ]]; then
echo "Docker VERSION and pypi VERSION are different (${docker_VERSION} vs ${VERSION}), release aborted"
exit 1
fi

echo "Confirm release [y/n] ?"
read -r confirm
if [[ "${confirm}" = "y" ]]; then
version=$(grep PACKAGE_VERSION "${ROOTDIR}"/sonar/version.py | cut -d "=" -f 2 | sed -e "s/[\'\" ]//g" -e "s/^ +//" -e "s/ +$//")
VERSION=$(grep PACKAGE_VERSION "${ROOT_DIR}"/sonar/VERSION.py | cut -d "=" -f 2 | sed -e "s/[\'\" ]//g" -e "s/^ +//" -e "s/ +$//")

echo "Releasing on pypi.org"
python3 -m twine upload "${ROOTDIR}/dist/sonar_tools-${version}-py3-none-any.whl"
python3 -m twine upload "${ROOT_DIR}/dist/sonar_tools-${VERSION}-py3-none-any.whl"
echo -n "Waiting pypi release to be effective"
while [[ "$(get_pypi_latest_version sonar-tools)" != "${version}" ]]; do
while [[ "$(get_pypi_latest_VERSION sonar-tools)" != "${VERSION}" ]]; do
sleep 10
echo -n "."
done
echo " done"
echo "Releasing on dockerhub"
docker buildx build --push --platform linux/amd64,linux/arm64 -t "olivierkorach/sonar-tools:${version}" -t olivierkorach/sonar-tools:latest -f "${CONFDIR}/release.Dockerfile" "${ROOTDIR}"
cd "${ROOTDIR}" && docker pushrm olivierkorach/sonar-tools
docker buildx build --push --platform linux/amd64,linux/arm64 -t "olivierkorach/sonar-tools:${VERSION}" -t olivierkorach/sonar-tools:latest -f "${CONF_DIR}/release.Dockerfile" "${ROOT_DIR}"
cd "${ROOT_DIR}" && docker pushrm olivierkorach/sonar-tools

echo "Running scan"
"${CONFDIR}/scan.sh" -test
"${CONF_DIR}/scan.sh" -test
fi
14 changes: 11 additions & 3 deletions conf/ruff2sonar.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

def main() -> None:
"""Main script entry point"""
v1 = len(sys.argv) > 1 and sys.argv[1] == "v1"
rules_dict = {}
issue_list = []
lines = sys.stdin.read().splitlines()
Expand Down Expand Up @@ -65,6 +66,10 @@ def main() -> None:
"textRange": issue_range,
},
}
if v1:
sonar_issue["engineId"] = TOOLNAME
sonar_issue["severity"] = "MAJOR"
sonar_issue["type"] = "CODE_SMELL"
rules_dict[f"{TOOLNAME}:{rule_id}"] = {
"id": f"{TOOLNAME}:{rule_id}",
"name": f"{TOOLNAME}:{rule_id}",
Expand All @@ -89,9 +94,12 @@ def main() -> None:
end_line = int(m.group(1))
i += 1

if len(issue_list) > 0:
external_issues = {"rules": list(rules_dict.values()), "issues": issue_list}
print(json.dumps(external_issues, indent=3, separators=(",", ": ")))
if len(issue_list) == 0:
return
external_issues = {"rules": list(rules_dict.values()), "issues": issue_list}
if v1:
external_issues.pop("rules")
print(json.dumps(external_issues, indent=3, separators=(",", ": ")))


if __name__ == "__main__":
Expand Down
62 changes: 62 additions & 0 deletions conf/run_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
#
# sonar-tools
# Copyright (C) 2019-2025 Olivier Korach
# mailto:olivier.korach AT gmail DOT com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This program 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

# ME="$( basename "${BASH_SOURCE[0]}" )"
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

. "${CONF_DIR}/env.sh"

dolint="true"
dotest="false"
scanOpts=()

while [[ $# -ne 0 ]]
do
case "${1}" in
-nolint)
dolint="false"
;;
-test)
dotest="true"
;;
-9)
external_format="v1"
;;
-local)
localbuild="true"
;;
*)
scanOpts=("${scanOpts[@]}" "${1}")
;;
esac
shift
done

if [[ "${dolint}" != "false" ]]; then
"${CONF_DIR}"/run_linters.sh "${external_format}" "${localbuild}"
fi

if [[ "${dotest}" = "true" ]]; then
"${CONF_DIR}"/run_tests.sh
fi

"${CONF_DIR}"/run_scanner.sh "${scanOpts[@]}"
Loading