-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone-and-compile-modules.sh
executable file
·102 lines (96 loc) · 3.95 KB
/
clone-and-compile-modules.sh
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
100
101
102
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
projectFile=$1
if [[ -z "$projectFile" ]]; then
printf "\n Usage: ./clone-and-compile-project.sh projects/my-folio.json\n\n"
printf " The script will 'git clone' modules that are not present in the specified directories\n"
printf " and 'mvn install' and optionally 'docker build' those that have no target directory.\n\n"
exit
fi
if [[ ! -f "$projectFile" ]]; then
printf "\n Could not find project file [%s] to clone and compile modules from.\n\n" "$projectFile"
exit
fi
started=$(date)
# Import jq functions for retrieving settings from the config file
source "$here/lib/ConfigReader.sh"
source "$here/lib/Utils.sh"
mainSourceDirectory=$(sourceDirectory "$projectFile")
if [[ -z "$mainSourceDirectory" ]]; then
printf "\n !! Project configuration has no main source directory ('sourceDirectory' not set), cannot continue.\n\n"
exit
elif [[ ! -d "$mainSourceDirectory" ]]; then
printf "\n !! The projects main source directory for module check-outs does not exist. Please create '%s' to run with this configuration.\n\n" "$mainSourceDirectory"
exit
fi
printf "\nGit clone and Maven install of selected modules"
printf "\n***********************************************\n"
# Checking file system status for all requested modules
moduleNames=$(jq -r '(.basicModules, .selectedModules)[] | .name ' "$projectFile")
clone=""
compile=""
skip=""
printf "\nChecking file system status of selected modules\n"
for moduleName in $moduleNames ; do
sourceDirectory=$(moduleDirectory "$moduleName" "$projectFile")
modulePath="$sourceDirectory/$moduleName"
if [ -d "$sourceDirectory" ]; then
if [ -d "$modulePath" ]; then
gitStatus=$(gitStatus "$modulePath")
if [ -f "$modulePath/target/ModuleDescriptor.json" ]; then
printf " - %-25s%-35s Got %s/target\n" "$moduleName" "$gitStatus" "$modulePath"
skip="$skip $moduleName"
else
printf " - %-60s - Detected no build in %s\n" "$moduleName $gitStatus" "$modulePath"
compile="$compile $moduleName$gitStatus"
fi
else
printf " - %-60s - Module check-out not found in %s\n" "$moduleName" "$sourceDirectory"
clone="$clone $moduleName"
compile="$compile $moduleName"
fi
else
printf "Cannot check out %s to %s. Directory does not exist.\n" "$moduleName" "$sourceDirectory"
fi
done
if [[ -z "$cloneAndCompile" && -z "$compile" ]]; then
printf "\nAll selected modules already checked out and compiled."
else
printf "\nWill clone: %s\n" "${clone:-" NONE"}"
printf "Will compile: %s\n" "${compile:-" NONE"}"
printf "Skipping: %s\n" "${skip:-" NONE"}"
printf "\nUsing main source directory: %s" "$mainSourceDirectory"
sourceDirectories=$(jq -r '(.basicModules,.selectedModules) | unique_by(.sourceDirectory)[].sourceDirectory' "$projectFile")
for symbol in $sourceDirectories ; do
if [[ "$symbol" != "null" ]]; then
printf " Alternative directory: %s:%s " "$symbol" "$(alternativeDirectory "$symbol" "$projectFile")"
fi
done
fi
printf "\n\n"
while true
do
read -r -p 'Continue [y/N]? ' choice
choice=${choice:-N}
case "$choice" in
y|Y) break;;
*) exit;;
esac
done
for moduleName in $moduleNames ; do
sourceDirectory=$(moduleDirectory "$moduleName" "$projectFile")
modulePath="$sourceDirectory/$moduleName"
gitHost=$(moduleRepoOrDefault "$moduleName" "$projectFile")
if [ -d "$sourceDirectory" ]; then
if [ ! -d "$modulePath" ]; then
printf "\n$(date) Cloning %s to %s from %s/%s\n" "$moduleName" "$sourceDirectory" "$gitHost" "$moduleName"
git clone -q --recurse-submodules "$gitHost/$moduleName" "$modulePath"
fi
if [ ! -f "$modulePath/target/ModuleDescriptor.json" ]; then
"$here"/mod-compile.sh "$moduleName" "$projectFile"
fi
else
printf "Cannot clone %s to %s. Directory does not exist.\n" "$moduleName" "$sourceDirectory"
fi
done
printf "\nStarted %s" "$started"
printf "\nFinished %s\n" "$(date)"