-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_dependencies.sh
160 lines (156 loc) · 4.24 KB
/
load_dependencies.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
#!/bin/bash
function GenerateProjectListFile
{
local buildFiles=("$@")
first=""
second=""
for ix in ${!buildFiles[*]}
do
if [[ $first == "" ]]
then # This is the very first element to be read
first=${buildFiles[$ix]}
else
local fileDirname=$(dirname ${buildFiles[$ix]})
local fileBasename=$(basename ${buildFiles[$ix]})
local firstDirname=$(dirname $first)
local firstBasename=$(basename $first)
if [[ $fileDirname == $firstDirname ]]
then # a pom.xml and a build.gradle may coexist
second=${buildFiles[$ix]}
fi
fi
local item=$ix+1
if [[ "$item" -eq "${#buildFiles[*]}" ]]
then
firstDirname=$(dirname $first)
firstBasename=$(basename $first)
if [[ $first == *"pom.xml" ]]
then
echo $firstDirname","$first","$second >> $outFile
else
echo $firstDirname","$second","$first >> $outFile
fi
else
local fileDirname=$(dirname ${buildFiles[$ix]})
local fileBasename=$(basename ${buildFiles[$ix]})
local firstDirname=$(dirname $first)
local firstBasename=$(basename $first)
if [[ $fileDirname != $firstDirname* ]]
then # This is another project
if [[ $first == *"pom.xml" ]]
then
echo $firstDirname","$first","$second >> $outFile
else
echo $firstDirname","$second","$first >> $outFile
fi
second=""
first=${buildFiles[$ix]}
fi
fi
done
}
function LoadDependencies
{
while IFS=, read -r project pom gradle; do
if [[ $project != "project" ]] # so it is not the first line
then
cd $project
# if [ -d "./.gradle" ]
# then
# rm -rf "$project/.gradle"
# fi
# if [ -d "./.m2" ]
# then
# rm -rf "$project/.m2"
# fi
if [[ $gradle != "" ]] # a build.gradle exists
then
gradle --refresh-dependencies --gradle-user-home "$project/.gradle" --continue > "$project/log_gradleOutput.txt"
STATUS=$?
if [ $STATUS -eq 0 ]
then
echo "$project,gradle,SUCCESS" >> $logFile
else
echo "$project,gradle,FAILED" >> $logFile
fi
fi
if [[ $pom != "" ]] # a pom.xml exists
then
mvn dependency:resolve -T 3 -fn -Dmaven.repo.local="$project/.m2" > "$project/log_mvnOutput.txt"
STATUS=$?
if [ $STATUS -eq 0 ]
then
echo "$project,mvn,SUCCESS" >> $logFile
else
echo "$project,mvn,FAILED" >> $logFile
fi
fi
fi
done < $1
}
function ExploreSandbox
{
local sandboxDir=$1
echo $sandboxDir
for owner in $sandboxDir/*
do
for repository in $owner/*
do
if [ -d $repository ]
then
local txt="buildFilesCSV.txt"
local outFile="$repository/$txt"
if [ -f $outFile ]
then
rm $outFile
fi
touch $outFile
echo "project,pom,gradle" >> $outFile
local repoDir=$(basename $repository)
echo $repository
# Trouver et trier tous les pom.xml et gradle.build du repository
local first=""
local second=""
buildFiles=($(find $repository -type f -name "pom.xml" -printf '%h\0%d\0%p\n' -o -type f -name "build.gradle" -printf '%h\0%d\0%p\n' | sort -t '\0' -n | awk -F'\0' '{print $3}'|
while read file; do
if [[ $first == "" ]]
then # This is the very first element to be read
first=$file
echo $first " "
else
local fileDirname=$(dirname $file)
local fileBasename=$(basename $file)
local firstDirname=$(dirname $first)
local firstBasename=$(basename $first)
if [[ $fileDirname == $firstDirname ]] && [[ $fileBasename != $firstBasename ]]
then # a pom.xml and a build.gradle may coexist
second=$file
echo $second " "
else
if [[ $fileDirname != $firstDirname* ]]
then # This is another project
first=$file
echo $first " "
fi
fi
fi
done))
GenerateProjectListFile "${buildFiles[@]}"
LoadDependencies $outFile
fi
done
done
}
#Main
[ $1 ] && {
export MAVEN_OPTS="-Xmx4000m"
logFile="$(pwd)/logDep.txt"
if [ -f $logFile ]
then
rm $logFile
fi
touch $logFile
ExploreSandbox $1
} || {
echo "You must give the path of the sandbox."
}