forked from dosoudil/maven-repository-builder
-
Notifications
You must be signed in to change notification settings - Fork 12
/
maven_repo_builder.sh
executable file
·216 lines (198 loc) · 8.68 KB
/
maven_repo_builder.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
help ()
{
echo 'Usage: '"$1"' -u URL [-r REPO_FILENAME] [-o OUTPUT] [-b OUTPUT_REPO] [-m] [-l LOGLEVEL] [-d ADDITION] FILE...'
echo 'Usage: '"$1"' -c CONFIG [-r REPO_FILENAME] [-o OUTPUT] [-b OUTPUT_REPO] [-m] [-l LOGLEVEL] [-d ADDITION]'
echo 'Usage: '"$1"' -h'
echo ''
echo 'Options:'
echo ' -h show this help message and exit'
echo ' -c CONFIG'
echo ' Configuration file to use for generation of an'
echo ' artifact list for the repository builder'
echo ' -u URL'
echo ' Comma-separated list of URLs of the remote repositories from'
echo ' which artifacts are downloaded. It is used along with artifact'
echo ' list files when no config file is specified.'
echo ' -o OUTPUT'
echo ' Local output directory for the new repository. By default'
echo ' "local-maven-repository" will be used.'
echo ' -b OUTPUT_REPO'
echo ' Name of directory in which will be the artifacts'
echo ' contained in the output directory. It can be empty or'
echo ' multi-level path, e.g. path/to/repo. Defaults to'
echo ' "maven-repository".'
echo ' -a CLASSIFIERS'
echo ' Colon-separated list of additional classifiers to download.'
echo ' By default "sources" will be used. There can be a type specified '
echo ' with each classifiers separated by colon, e.g. jar:sources.'
echo ' The old way of separation of classifiers by colon is deprecated.'
echo ' -t THREADNUM'
echo ' Number of download threads per server when downloading artifacts.'
echo ' Default is 5, max is 20.'
echo ' -r REPO_FILENAME'
echo ' Zip the created repository in a file with provided name'
echo ' -s CHECKSUM_MODE'
echo ' Mode of dealing with MD5 and SHA1 checksums. Possible options are:'
echo ' generate - generates the checksums (default)'
echo ' download - download the checksums if available, if not, generates them'
echo ' check - checks if downloaded and generated checksums are equal'
echo ' -x EXCLUDED_TYPES'
echo ' Colon-separated list of filetypes to exclude. Defaults to '
echo ' zip:ear:war:tar:gz:tar.gz:bz2:tar.bz2:7z:tar.7z.'
echo ' -w GATCV_WHITELIST'
echo ' Name of a file containing GATCV patterns allowing usage of stars'
echo ' or regular expressions when enclosed in "r/pattern/". It can force'
echo ' inclusion of artifacts with excluded types.'
echo ' -O REPORT_DIR'
echo ' Dir where to generate the repository analysis report. If not specified'
echo ' no report will be generated. By default "maven-repository-report" will '
echo ' be used.'
echo ' -R REPORT_FILENAME'
echo ' Zip the created repository report in a file with provided name'
echo ' -m'
echo ' Generate metadata in the created repository'
echo ' -l LOGLEVEL'
echo ' Set the level of log output. Can be set to debug,'
echo ' info, warning, error, or critical'
echo ' -L LOGFILE'
echo ' Set the file in which the log output should be written'
echo ' -d ADDITION'
echo ' Directory containing additional files for the repository.'
echo ' Content of directory ADDITION will be copied to the repository.'
echo ' -n'
echo ' Disable producing a nested structure for the maven repository zip,'
echo ' in which the maven-repository directory and the extras files were nested'
echo ' under a parent directory.'
echo ''
}
isvarset()
{
local v="$1"
[[ ! ${!v} && ${!v-unset} ]] && return 1 || return 0
}
if [ $# -lt 1 ]; then
help $0
exit 1
fi
WORKDIR=$(cd $(dirname $0) && pwd)
# defaults
HELP=false
METADATA=false
OUTPUT_DIR="local-maven-repository"
OUTPUT_REPO="maven-repository"
NESTED=true
# =======================================
# ====== reading command arguments ======
# =======================================
while getopts hc:u:r:a:t:o:b:l:L:s:x:w:O:R:md:n OPTION
do
case "${OPTION}" in
h) HELP=true;;
c) CONFIG=${OPTARG};;
u) URL=${OPTARG};;
r) REPO_FILE=${OPTARG};;
a) CLASSIFIERS=${OPTARG};;
t) THREADNUM=${OPTARG};;
s) CHECKSUM_MODE=${OPTARG};;
x) EXCLUDED_TYPES=${OPTARG};;
w) GATCV_WHITELIST=${OPTARG};;
o) OUTPUT_DIR=${OPTARG};;
b) OUTPUT_REPO=${OPTARG};;
O) REPORT_DIR=${OPTARG};;
R) REPORT_FILE=${OPTARG};;
m) METADATA=true;;
l) LOGLEVEL=${OPTARG};;
L) LOGFILE=${OPTARG};;
d) ADDITION=${OPTARG};;
n) NESTED=false;;
esac
done
if [ -z $OUTPUT_REPO ]; then
OUTPUT_REPO_DIR=$OUTPUT_DIR
else
OUTPUT_REPO_DIR=$OUTPUT_DIR/$OUTPUT_REPO
fi
if [ -z $REPORT_DIR ]; then
if [ ! -z $REPORT_FILE ]; then
REPORT_DIR="maven-repository-report"
fi
fi
if ${HELP}; then
help $0
exit
fi
# ================================================
# ============== 1. create GAV list ==============
# ============== 2. filter the list ==============
# ============== 3. fetch artifacts ==============
# ================================================
# creation of list of parameters passed to the python script
MRB_PARAMS=()
isvarset CONFIG && MRB_PARAMS+=("-c") && MRB_PARAMS+=("${CONFIG}")
isvarset URL && MRB_PARAMS+=("-u") && MRB_PARAMS+=("${URL}")
isvarset CLASSIFIERS && MRB_PARAMS+=("-a") && MRB_PARAMS+=("${CLASSIFIERS}")
isvarset THREADNUM && MRB_PARAMS+=("-t") && MRB_PARAMS+=("${THREADNUM}")
isvarset OUTPUT_REPO_DIR && MRB_PARAMS+=("-o") && MRB_PARAMS+=("${OUTPUT_REPO_DIR}")
isvarset CHECKSUM_MODE && MRB_PARAMS+=("-s") && MRB_PARAMS+=("${CHECKSUM_MODE}")
isvarset EXCLUDED_TYPES && MRB_PARAMS+=("-x") && MRB_PARAMS+=("${EXCLUDED_TYPES}")
isvarset GATCV_WHITELIST && MRB_PARAMS+=("-w") && MRB_PARAMS+=("${GATCV_WHITELIST}")
isvarset REPORT_DIR && MRB_PARAMS+=("-O") && MRB_PARAMS+=("${REPORT_DIR}")
isvarset LOGLEVEL && MRB_PARAMS+=("-l") && MRB_PARAMS+=("${LOGLEVEL}")
isvarset LOGFILE && MRB_PARAMS+=("-L") && MRB_PARAMS+=("${LOGFILE}")
# skip all named parameters and leave just unnamed ones (filenames)
if [ $# -gt 0 ]; then
while [ $# -gt 0 ] && [ ${1:0:1} = '-' ]; do
L=${1:1:2}
if [ $L = 'c' ] || [ $L = 'r' ] || [ $L = 'a' ] || [ $L = 't' ] || [ $L = 'o' ] || [ $L = 'b' ] || [ $L = 'u' ] || [ $L = 's' ] || [ $L = 'x' ] || [ $L = 'w' ] || [ $L = 'O' ] || [ $L = 'R' ] || [ $L = 'l' ] || [ $L = 'L' ] || [ $L = 'd' ] ; then
shift
fi
shift
done
fi
while [ $# -gt 0 ]; do
MRB_PARAMS+=("${1}")
shift
done
python2 $WORKDIR/maven_repo_builder.py "${MRB_PARAMS[@]}"
if test $? != 0; then
echo "Creation of repository failed."
exit 1
fi
# ================================================
# == 4. generate metadata (opt), zip repo (opt) ==
# ================================================
if [ -d "$ADDITION" ]; then
cp -rf $ADDITION/. ${OUTPUT_DIR}
fi
if ${METADATA}; then
$WORKDIR/generate_maven_metadata.sh ${OUTPUT_REPO_DIR}
fi
if [ ! -z ${REPO_FILE} ]; then
REPO_FILE_DIR=$(dirname ${REPO_FILE})
if [ ! -d "${REPO_FILE_DIR}" ]; then
mkdir -p "${REPO_FILE_DIR}"
fi
ABS_REPO_FILE=$(cd "${REPO_FILE_DIR}" && pwd -P)/$(basename ${REPO_FILE})
if ${NESTED}; then
cd `dirname ${OUTPUT_DIR}`
zip -qr ${ABS_REPO_FILE} $(basename ${OUTPUT_DIR})
else
# Zip inside the output directory to avoid a nested structure. If OUTPUT_REPO
# is default value (of maven-repository) this zip will have the correct structure.
cd ${OUTPUT_DIR}
zip -qr ${ABS_REPO_FILE} *
fi
cd $WORKDIR
fi
if [ ! -z ${REPORT_FILE} ]; then
REPORT_FILE_DIR=$(dirname ${REPORT_FILE})
if [ -d "${REPORT_FILE_DIR}" ]; then
rm -rf ${REPORT_FILE_DIR}
fi
mkdir -p "${REPORT_FILE_DIR}"
ABS_REPORT_FILE=$(cd "${REPORT_FILE_DIR}" && pwd -P)/$(basename ${REPORT_FILE})
cd `dirname ${REPORT_DIR}`
zip -qr ${ABS_REPORT_FILE} $(basename ${REPORT_DIR})
cd $WORKDIR
fi