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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
#!/usr/bin/env bash
#*******************************************************************************
# Copyright (c) 2015, 2016 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# IBM Corporation - initial API and implementation
#*******************************************************************************
# To allow this cron job to work from hudson, or traditional crontab
if [[ -z "${WORKSPACE}" ]]
then
export UTILITIES_HOME=/shared/eclipse
else
export UTILITIES_HOME=${WORKSPACE}/utilities/production
fi
function writeHeader ()
{
compositeRepoDir="$1"
antBuildFile=$2
if [[ -z "${compositeRepoDir}" ]]
then
echo -e "\n\tWARNING: compositeRepoDir not passed to writeHeader function as expected. But will continue with variablei for later use?"
compositeRepoDir="\$\{compositeRepoDir\}"
fi
echo -e "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $antBuildFile
echo -e "<project" >> $antBuildFile
echo -e " basedir=\".\"" >>$antBuildFile
echo -e " default=\"cleanup\">" >>$antBuildFile
echo -e " <target name=\"cleanup\">" >>$antBuildFile
echo -e " <p2.composite.repository>" >>$antBuildFile
echo -e " <repository location=\"file://${compositeRepoDir}\" />" >>$antBuildFile
echo -e " <remove>" >> $antBuildFile
}
function writeReposToRemove ()
{
antBuildFile=$1
for repo in "${reposToRemove[@]}"
do
echo " <repository location=\"$repo\" />" >> $antBuildFile
done
}
function writeClosing ()
{
antBuildFile=$1
echo -e " </remove>" >> $antBuildFile
echo -e " </p2.composite.repository>" >> $antBuildFile
echo -e " </target>" >> $antBuildFile
echo -e "</project>" >> $antBuildFile
}
function generateCleanupXML ()
{
mainRepoDir=$1
antBuildFile=$2
if [[ -z "${mainRepoDir}" || ! -e "${mainRepoDir}" ]]
then
echo -e "\n\tERROR: main repo to work with was not defined or did not exist"
else
writeHeader $mainRepoDir $antBuildFile
writeReposToRemove $antBuildFile
writeClosing $antBuildFile
fi
}
function getReposToRemove ()
{
cDir="$1"
buildType=$2
nRetain=$3
if [[ ! -e "${cDir}" ]]
then
echo -e "\n\tERROR: expected directory did not exist" >&2
echo -e "\t\t${cDir}" >&2
reposToRemove=()
return 1
else
echo -e "\n\tDEBUG: working with directory ${cDir}"
# for "repo names" we want only the last segment of the directory, so use -printf %f. The %C@ is seconds since the beginning of time, for sorting.
# Some caution is needed here. Seems on eclipse.org "atime" is the one that reflects "when created",
# whereas ctime and mtime are all identical, in every directory?! Turns out, mine is that
# say too. Apparently p2 "touches" every directory, for some reason. Perhaps only in the "atomic" case?
# But, atime can vary from system to system, depending .. some systems do update, when accessed?
sortedallOldRepos=( $(find ${cDir} -maxdepth 1 -type d -name "${buildType}*" -printf "%C@ %f\n" | sort -n | cut -d\ -f2 ) )
#nOldRepos=${#sortedallOldRepos[@]}
# all builds "find" command should match above, except for age related (and printf) arguments
nbuilds=$( find ${cDir} -maxdepth 1 -type d -name "${buildType}*" | wc -l )
echo -e "\tNumber of repos before cleaning: $nbuilds"
#echo -e "\tNumber of old repos ${nOldRepos}"
echo -e "\tDEBUG contents of sortedallOldRepos array"
for item in "${sortedallOldRepos[@]}"
do
echo -e "\t${item}"
done
#totalMinusOld=$(( nbuilds - nOldRepos ))
#echo -e "\tDEBUG: total minus old: $totalMinusOld"
if [[ $nbuilds -gt $nRetain ]]
then
# remove all old ones, except for nRetain
nToRemove=$(( nbuilds - nRetain ))
echo -e "\tDEBUG: nToRemove: $nToRemove"
#remove all except newest nRetain (if more than nRetain)
if [[ ${nToRemove} -gt 0 ]]
then
echo -e "\tDEBUG: number of old repos to remove found to be ${nToRemove}"
reposToRemove=("${sortedallOldRepos[@]:0:$nToRemove}")
else
echo -e "\tDEBUG: number of old repos to remove found to be ${nToRemove} so we will remove none"
reposToRemove=()
fi
fi
fi
}
function cleanRepo ()
{
eclipseRepo=$1
buildType=$2
nRetain=$3
dryRun=$4
# Changed to "hard coded" location of where to expect on Hudson.
baseBuilder=utilities/eclipse.platform.releng.tychoeclipsebuilder/eclipse/org.eclipse.releng.basebuilder
eclipseexe=${baseBuilder}/eclipse
if [[ ! -x ${eclipseexe} ]]
then
echo -e "\n\tERROR: expected eclipse location not found, or not executable"
echo -e "\t${eclipseexe}"
exit 1
fi
JAVA_8_HOME=/shared/common/jdk1.8.0_x64-latest
export JAVA_HOME=${JAVA_8_HOME}
javaexe=${JAVA_HOME}/jre/bin/java
if [[ ! -x ${javaexe} ]]
then
echo -e "\n\tERROR: expected java location not found, or not executable"
echo -e "\t${javaexe}"
exit 1
fi
antBuildFile=cleanupRepoScript${buildType}.xml
antRunner=org.eclipse.ant.core.antRunner
# To allow this cron job to work from hudson, or traditional crontab
if [[ -z "${WORKSPACE}" ]]
then
export devWorkspace=/shared/eclipse/sdk/cleaners/workspace-cleanup
else
# we don't put under "utilities" or "sdk" to keep the git tree clean when on Hudson
export devWorkspace=${WORKSPACE}/workspace-cleanup
fi
echo -e "\tDEBUG: Cleaning repository ${eclipseRepo} on $HOSTNAME on $(date ) " >&2
getReposToRemove "${eclipseRepo}" $buildType $nRetain
RC=$?
if [[ $RC == 0 ]]
then
# be sure there are some to remove
nToRemove=${#reposToRemove[@]}
if [[ $nToRemove == 0 ]]
then
echo -e "\tfound no files to remove for current repo"
else
echo -e "\n\tfound $nToRemove so generating ant file"
generateCleanupXML "${eclipseRepo}" $antBuildFile
if [[ -z "${dryRun}" ]]
then
$eclipseexe -nosplash --launcher.suppressErrors -data "${devWorkspace}" -application ${antRunner} -f $antBuildFile -vm ${javaexe}
RC=$?
fi
if [[ $RC == 0 ]]
then
# we only clean N-build directories, others need to be manually cleaned
# after every milestone, or after every release
if [[ $buildType == "N" ]]
then
for file in "${reposToRemove[@]}"
do
echo -e "\tDEBUG: directories to remove: ${eclipseRepo}/${file}"
if [[ -z "${dryRun}" ]]
then
rm -rf ${eclipseRepo}/${file}
fi
done
else
echo -e "\n\tReminder: only composite cleaned. For $buildType builds must cleanup simple repos ever milestone or release".
fi
fi
if [[ -n "${dryRun}" ]]
then
echo "Since dryrun printing $antBuildFile"
cat $antBuildFile
fi
fi
fi
}
remoteBase="/home/data/httpd/download.eclipse.org"
eclipseIRepo="${remoteBase}/eclipse/updates/4.9-I-builds"
eclipseSRepo="${remoteBase}/eclipse/updates/4.9milestones"
eclipseYRepo="${remoteBase}/eclipse/updates/4.9-Y-builds"
eclipsePRepo="${remoteBase}/eclipse/updates/4.9-P-builds"
#doDryrun=dryrun
doDryrun=
# global
declare -a reposToRemove=()
cleanRepo $eclipseIRepo I 4 $doDryrun
declare -a reposToRemove=()
cleanRepo $eclipseSRepo S 2 $doDryrun
declare -a reposToRemove=()
cleanRepo $eclipseYRepo I 2 $doDryrun
declare -a reposToRemove=()
cleanRepo $eclipsePRepo S 2 $doDryrun
unset reposToRemove
|