-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfindPathsToScan.sh
More file actions
executable file
·99 lines (85 loc) · 4.73 KB
/
findPathsToScan.sh
File metadata and controls
executable file
·99 lines (85 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
# Finds all files and directories to scan and analyze and provides them as comma-separated list.
# This includes the scan of Typescript projects that leads to the intermediate json data file for jQAssistant.
# Uses: patchJQAssistantTypescriptPlugin.sh
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
set -o errexit -o pipefail
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"}
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"}
## Get this "scripts" directory if not already set
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
# This way non-standard tools like readlink aren't needed.
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} # Repository directory containing the shell scripts
echo "findPathsToScan SCRIPTS_DIR=${SCRIPTS_DIR}" >&2
# This function returns the argument followed by a comma (separator) if it is not empty
# and just an empty string otherwise.
appendNonEmpty() {
if [ -n "${1}" ] ; then
echo "${1},"
else
echo ""
fi
}
findPackageJsonFiles() {
find -L "${1}" \
-type d -name "node_modules" -prune -o \
-type d -name "dist" -prune -o \
-type d -name ".yalc" -prune -o \
-type d -name "target" -prune -o \
-type d -name "temp" -prune -o \
-type d -name "lib" -prune -o \
-type d -name "libs" -prune -o \
-type d -name ".git" -prune -o \
-name 'package.json' \
-print0 | \
xargs -0 -r -I {} echo {}
}
# Collect all files and directories to scan
directoriesAndFilesToScan=""
if [ -d "./${ARTIFACTS_DIRECTORY}" ] ; then
# Scan all files in the artifacts directory (e.g. *.ear, *.war, *.jar for Java)
directoriesAndFilesToScan="$(appendNonEmpty "${directoriesAndFilesToScan}")./${ARTIFACTS_DIRECTORY}"
else
echo "findPathsToScan: Artifacts directory ${ARTIFACTS_DIRECTORY} doesn't exist and will therefore be skipped." >&2
fi
if [ -d "./${SOURCE_DIRECTORY}" ] ; then
# Scan package.json files for npm (nodes package manager) in the source directory
# Since the following issue had been resolved, the scan can be done here again:
# https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5
npmPackageJsonFiles="$(findPackageJsonFiles "./${SOURCE_DIRECTORY}")"
if [ -n "${npmPackageJsonFiles}" ]; then
directoriesAndFilesToScan="$(appendNonEmpty "${directoriesAndFilesToScan}")${npmPackageJsonFiles}"
fi
# Scan Typescript analysis json data files in the source directory
# Since Typescript scan might produce duplicate fileName properties on File nodes,
# it is done after the npm package.json scan, that breaks the scan on duplicate fileName properties.
# This order fixes "XOException: Expected exactly one result, but got CompositeRowObject".
typescriptAnalysisFiles="$(find -L "./${SOURCE_DIRECTORY}" \
-type d -name "node_modules" -prune -o \
-type d -name "dist" -prune -o \
-type d -name "target" -prune -o \
-type d -name ".yalc" -prune -o \
-type d -name ".git" -prune -o \
-type d -name "temp" -prune -o \
-type f -path "*/.reports/jqa/ts-output.json" \
-exec echo typescript:project::{} \; | tr '\n' ',' | sed 's/,$/\n/')"
if [ -n "${typescriptAnalysisFiles}" ]; then
directoriesAndFilesToScan="$(appendNonEmpty "${directoriesAndFilesToScan}")${typescriptAnalysisFiles}"
fi
# Scan git repositories in the artifacts directory
if [ "${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT}" = "" ] || [ "${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT}" = "plugin" ] ; then
gitDirectories="$(find -L "./${SOURCE_DIRECTORY}" \
-type d -name "node_modules" -prune -o \
-type d -name "dist" -prune -o \
-type d -name "target" -prune -o \
-type d -name "temp" -prune -o \
-type d -name ".git" -exec echo {} \; | tr '\n' ',' | sed 's/,$/\n/')"
if [ -n "${gitDirectories}" ]; then
directoriesAndFilesToScan="$(appendNonEmpty "${directoriesAndFilesToScan}")${gitDirectories}"
fi
fi
else
echo "findPathsToScan: Source directory ${SOURCE_DIRECTORY} doesn't exist and will therefore be skipped." >&2
fi
echo -n "${directoriesAndFilesToScan}"