1+ #! /usr/bin/env bash
2+
3+ # Executes selected "Artifact_Dependencies" Cypher queries for GraphViz visualization.
4+ # It contains lists of dependencies across artifacts and their build levels (topologically sorted).
5+ # It requires an already running Neo4j graph database with already scanned and analyzed artifacts.
6+ # The reports (csv, dot and svg files) will be written into the sub directory reports/artifact-dependencies-visualization.
7+
8+ # Requires executeQueryFunctions.sh, cleanupAfterReportGeneration.sh
9+
10+ # Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
11+ set -o errexit -o pipefail
12+
13+ # Overrideable Constants (defaults also defined in sub scripts)
14+ REPORTS_DIRECTORY=${REPORTS_DIRECTORY:- " reports" }
15+
16+ # # Get this "scripts/reports" directory if not already set
17+ # Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
18+ # CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
19+ # This way non-standard tools like readlink aren't needed.
20+ REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR:- $( CDPATH=. cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " && pwd -P )}
21+ echo " InternalDependenciesVisualization: REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR} "
22+
23+ # Get the "scripts" directory by taking the path of this script and going one directory up.
24+ SCRIPTS_DIR=${SCRIPTS_DIR:- " ${REPORTS_SCRIPT_DIR} /.." } # Repository directory containing the shell scripts
25+ echo " InternalDependenciesVisualization SCRIPTS_DIR=${SCRIPTS_DIR} "
26+
27+ # Get the "scripts/visualization" directory.
28+ VISUALIZATION_SCRIPTS_DIR=${VISUALIZATION_SCRIPTS_DIR:- " ${SCRIPTS_DIR} /visualization" } # Repository directory containing the shell scripts for visualization
29+ echo " InternalDependenciesVisualization VISUALIZATION_SCRIPTS_DIR=${VISUALIZATION_SCRIPTS_DIR} "
30+
31+ # Get the "cypher" directory by taking the path of this script and going two directory up and then to "cypher".
32+ CYPHER_DIR=${CYPHER_DIR:- " ${REPORTS_SCRIPT_DIR} /../../cypher" }
33+ echo " InternalDependenciesVisualization CYPHER_DIR=${CYPHER_DIR} "
34+
35+ if ! command -v " npx" & > /dev/null ; then
36+ echo " InternalDependenciesVisualization: Error: Command npx (run npm locally) not found. It's needed for Graph visualization with GraphViz." >&2
37+ exit 1
38+ fi
39+
40+ # Define functions to execute cypher queries from within a given file
41+ source " ${SCRIPTS_DIR} /executeQueryFunctions.sh"
42+
43+ # Create report directory
44+ REPORT_NAME=" internal-dependencies-visualization"
45+ FULL_REPORT_DIRECTORY=" ${REPORTS_DIRECTORY} /${REPORT_NAME} "
46+ mkdir -p " ${FULL_REPORT_DIRECTORY} "
47+
48+ # Local Constants
49+ INTERNAL_DEPENDENCIES_CYPHER_DIR=" ${CYPHER_DIR} /Internal_Dependencies"
50+
51+ visualizeGraphAndGenerateSvg () {
52+ if [ -f " ${reportName} .gv" ]; then
53+ # Run GraphViz command line interface (CLI) wrapped utilizing WASM (WebAssembly)
54+ # to convert the DOT file to SVG operating system independently.
55+ npx --yes @hpcc-js/
[email protected] -T svg
" ${reportName} .gv" > " ${reportName} .svg" 56+ fi
57+ }
58+
59+ # Java Artifacts: Dependencies Visualization
60+ reportName=" ${FULL_REPORT_DIRECTORY} /JavaArtifactBuildLevels"
61+ echo " InternalDependenciesVisualization Generating ${reportName} ..."
62+ execute_cypher " ${INTERNAL_DEPENDENCIES_CYPHER_DIR} /Java_Artifact_build_levels_for_graphviz.cypher" > " ${reportName} .csv"
63+ source " ${VISUALIZATION_SCRIPTS_DIR} /convertQueryResultCsvToGraphVizDotFile.sh" --filename " ${reportName} .csv"
64+ visualizeGraphAndGenerateSvg
65+
66+ # TypeScript Modules: Dependencies Visualization
67+ reportName=" ${FULL_REPORT_DIRECTORY} /TypeScriptModuleBuildLevels"
68+ echo " InternalDependenciesVisualization Generating ${reportName} ..."
69+ execute_cypher " ${INTERNAL_DEPENDENCIES_CYPHER_DIR} /Typescript_Module_build_levels_for_graphviz.cypher" > " ${reportName} .csv"
70+ source " ${VISUALIZATION_SCRIPTS_DIR} /convertQueryResultCsvToGraphVizDotFile.sh" --filename " ${reportName} .csv"
71+ visualizeGraphAndGenerateSvg
72+
73+ # Clean-up after report generation. Empty reports will be deleted.
74+ source " ${SCRIPTS_DIR} /cleanupAfterReportGeneration.sh" " ${FULL_REPORT_DIRECTORY} "
0 commit comments