Skip to content

Commit 8e4b9b4

Browse files
authored
Merge pull request #117 from JohT/feature/small-improvements
Small Improvements
2 parents 2c74dfa + eb2e9b8 commit 8e4b9b4

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

scripts/detectChangedArtifacts.sh

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,45 @@
22

33
# Detect changed files in the artifacts directory with a text file containing the last hash code of the contents.
44
# The hash value is generated based on all files (their names and properties) within the artifacts directory.
5-
# A change is detected when the current hash and the stored one differ.
5+
# A change is detected when the current hash and the stored differ.
6+
#
7+
# Command line options:
8+
# --readonly Detect changes without creating or updating the change detection file (stateless).
9+
# A second call without this option will be needed for the change detection to work.
10+
# This is helpful to decide if an operation should be done based on changes while waiting for its success to finally save the change state.
611

712
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
813
set -o errexit -o pipefail
914

15+
# Function to display script usage
16+
usage() {
17+
echo "Usage: $0 [--readonly]"
18+
exit 1
19+
}
20+
21+
# Default values
22+
readonlyMode=false
23+
24+
# Parse command line arguments
25+
while [[ $# -gt 0 ]]; do
26+
key="$1"
27+
case $key in
28+
--readonly)
29+
readonlyMode=true
30+
shift
31+
;;
32+
*)
33+
echo "detectChangedArtifacts: Error: Unknown option: ${key}"
34+
usage
35+
;;
36+
esac
37+
shift || true # ignore error when there are no more arguments
38+
done
39+
40+
if ${readonlyMode}; then
41+
echo "detectChangedArtifacts: Readonly mode activated. Change detection file won't be created." >&2
42+
fi
43+
1044
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"}
1145
ARTIFACTS_CHANGE_DETECTION_HASH_FILE=${ARTIFACTS_CHANGE_DETECTION_HASH_FILE:-"artifactsChangeDetectionHash.txt"} # Name of the file that contains the hash code of the file list for change detection
1246
ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH="./${ARTIFACTS_DIRECTORY}/$ARTIFACTS_CHANGE_DETECTION_HASH_FILE"
@@ -25,8 +59,11 @@ CURRENT_ARTIFACTS_HASH="$( find "./$ARTIFACTS_DIRECTORY" -type f -not -name "${A
2559

2660
# Assume that the files where changed if the file containing the hash of the file list does not exist yet.
2761
if [ ! -f "${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH}" ] ; then
28-
# Create the file containing the hash of the files list to a new file for the next call
29-
echo "${CURRENT_ARTIFACTS_HASH}" > "${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH}"
62+
if ! ${readonlyMode}; then
63+
# Create the file containing the hash of the files list to a new file for the next call
64+
echo "${CURRENT_ARTIFACTS_HASH}" > "${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH}"
65+
echo "detectChangedArtifacts: Change detection file created" >&2
66+
fi
3067
echo 1
3168
exit 0
3269
fi
@@ -36,7 +73,10 @@ fi
3673
if [[ $(< "${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH}") == "$CURRENT_ARTIFACTS_HASH" ]] ; then
3774
echo 0
3875
else
39-
# Write the updated hash into the file containing the hash of the files list for the next call
40-
echo "$CURRENT_ARTIFACTS_HASH" > "${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH}"
76+
if ! ${readonlyMode}; then
77+
# Write the updated hash into the file containing the hash of the files list for the next call
78+
echo "$CURRENT_ARTIFACTS_HASH" > "${ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH}"
79+
echo "detectChangedArtifacts: Change detection file updated" >&2
80+
fi
4181
echo 2
42-
fi
82+
fi

scripts/resetAndScan.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ echo "resetAndScan: SCRIPTS_DIR=${SCRIPTS_DIR}"
3232
# Internal constants
3333
JQASSISTANT_DIRECTORY="${TOOLS_DIRECTORY}/${JQASSISTANT_CLI_ARTIFACT}-${JQASSISTANT_CLI_VERSION}"
3434
JQASSISTANT_BIN="${JQASSISTANT_DIRECTORY}/bin"
35-
#JQASSISTANT_NEO4J_OPTIONS="-D jqassistant.store.uri=${NEO4J_BOLT_URI} -D jqassistant.store.remote.username=${NEO4J_USER} -D jqassistant.store.remote.password=${NEO4J_INITIAL_PASSWORD}"
36-
#JQASSISTANT_NEO4J_OPTIONS=-configurationLocations "${JQASSISTANT_CONFIG}/.jqassistant.yaml"
35+
JQASSISTANT_CONFIG_TEMPLATE_PATH="${SCRIPTS_DIR}/configuration/${JQASSISTANT_CONFIG_TEMPLATE}"
3736

3837
# Check if environment variable is set
3938
if [ -z "${NEO4J_INITIAL_PASSWORD}" ]; then
@@ -55,9 +54,16 @@ else
5554
echo "resetAndScan: Using jQAssistant binary directory ${JQASSISTANT_BIN}"
5655
fi
5756

58-
# Create jQAssistant configuration YAML file by copying a template for it
57+
# Create jQAssistant configuration YAML file by copying it from a corresponding template
5958
mkdir -p "./.jqassistant"
60-
cp "${SCRIPTS_DIR}/configuration/${JQASSISTANT_CONFIG_TEMPLATE}" "./.jqassistant/"
59+
60+
echo "resetAndScan: Check if ./.jqassistant/${JQASSISTANT_CONFIG_TEMPLATE} needs to be copied."
61+
if [ ! -f "./.jqassistant/${JQASSISTANT_CONFIG_TEMPLATE}" ]; then
62+
cp "${JQASSISTANT_CONFIG_TEMPLATE_PATH}" "./.jqassistant/"
63+
echo "resetAndScan: jQAssistant configuration copied from configuration template"
64+
else
65+
echo "resetAndScan: jQAssistant configuration won't be changed since it already exists."
66+
fi
6167

6268
# Use jQAssistant to scan the downloaded artifacts and write the results into the separate, local Neo4j Graph Database
6369
echo "resetAndScan: Scanning ${ARTIFACTS_DIRECTORY} with jQAssistant CLI version ${JQASSISTANT_CLI_VERSION}"

scripts/resetAndScanChanged.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ set -o errexit -o pipefail
1414
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
1515
# This way non-standard tools like readlink aren't needed.
1616
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} # Repository directory containing the shell scripts
17-
echo "resetAndScanChanged SCRIPTS_DIR=$SCRIPTS_DIR"
17+
echo "resetAndScanChanged SCRIPTS_DIR=${SCRIPTS_DIR}"
1818

1919
# Scan and analyze Artifacts when they were changed
20-
changeDetectionReturnCode=$( source "$SCRIPTS_DIR/detectChangedArtifacts.sh" )
20+
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedArtifacts.sh" --readonly)
2121
if [[ "${changeDetectionReturnCode}" == "0" ]] ; then
2222
echo "resetAndScanChanged: Artifacts unchanged. Scan skipped."
2323
else
2424
echo "resetAndScanChanged: Detected change (${changeDetectionReturnCode}). Resetting database and scanning artifacts."
2525
source "${SCRIPTS_DIR}/resetAndScan.sh"
26+
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedArtifacts.sh")
2627
fi

0 commit comments

Comments
 (0)