blob: 4ce374625a9ad0eba32d1862232d6e6445d8bdcb [file] [log] [blame]
Stephan Herrmannee73d532016-12-20 23:37:28 +01001#!/bin/bash
2#*******************************************************************************
3# Copyright (c) 2016 GK Software AG and others.
4# All rights reserved. This program and the accompanying materials
5# are made available under the terms of the Eclipse Public License v1.0
6# which accompanies this distribution, and is available at
7# http://www.eclipse.org/legal/epl-v10.html
8#
9# Contributors:
10# Stephan Herrmann - initial API and implementation
11#********************************************************************************
12
13#================================================================================
14# Parameters we might want to externalize into a properties file
15#================================================================================
16
17# ECLIPSE:
18DROPS4=/home/data/httpd/archive.eclipse.org/eclipse/downloads/drops4
19FILE_ECLIPSE=${DROPS4}/R-4.6.1-201609071200/eclipse-SDK-4.6.1-linux-gtk-x86_64.tar.gz
20APP_NAME_P2DIRECTOR=org.eclipse.equinox.p2.director
21
22# QUESTION: set tmpdir? (-vmargs not accepted by director application?)
23
24# AGGREGATOR:
25IU_AGG_PRODUCT=org.eclipse.cbi.p2repo.cli.product
26URL_AGG_UPDATES=http://download.eclipse.org/cbi/updates/aggregator/headless/4.6/
27
Stephan Herrmannb3148c62016-12-21 00:42:13 +010028FILE_SDK_AGGR=${WORKSPACE}/SDK4Mvn.aggr
Stephan Herrmannee73d532016-12-20 23:37:28 +010029
30# ENRICH POMS tool:
Stephan Herrmann8f2b5ab2016-12-21 00:23:47 +010031ENRICH_POMS_JAR=${WORKSPACE}/../../pomEnricher/workspace/EnrichPoms.jar
Stephan Herrmannee73d532016-12-20 23:37:28 +010032
33# LOCAL TOOLS:
34LOCAL_TOOLS=${WORKSPACE}/tools
35DIR_AGGREGATOR=aggregator
36AGGREGATOR=${LOCAL_TOOLS}/${DIR_AGGREGATOR}/cbiAggr
37ECLIPSE=${LOCAL_TOOLS}/eclipse/eclipse
38
39#================================================================================
40# Util functions
41#================================================================================
42function require_executable() {
43 if [ -x ${1} ]
44 then
45 echo "Successfully installed: ${1}"
46 else
47 echo "not executable: ${1}"
48 /bin/ls -l ${1}
49 exit 1
50 fi
51}
52
Stephan Herrmannb3148c62016-12-21 00:42:13 +010053# -------- fetch .aggr file **TEMP** will eventually move to the releng git: ------------
54git archive --remote=file://localhost/gitroot/objectteams/org.eclipse.objectteams.git \
55 master releng/EnrichPoms/SDK4Mvn.aggr \
56 | tar xv
57/bin/mv releng/EnrichPoms/SDK4Mvn.aggr ${WORKSPACE}/
58/bin/rmdir -p releng/EnrichPoms
59
Stephan Herrmannee73d532016-12-20 23:37:28 +010060#================================================================================
61# (1) Install and run the CBI aggregator
62#================================================================================
63if [ ! -d ${LOCAL_TOOLS} ]
64then
65 /bin/mkdir ${LOCAL_TOOLS}
66fi
67
68if [ ! -x ${ECLIPSE} ]
69then
70 cd ${LOCAL_TOOLS}
71 tar xf ${FILE_ECLIPSE}
72 cd ${WORKSPACE}
73fi
74require_executable ${ECLIPSE}
75
76if [ ! -x ${AGGREGATOR} ]
77then
78 ${ECLIPSE} -application ${APP_NAME_P2DIRECTOR} \
79 -r ${URL_AGG_UPDATES} \
80 -d ${LOCAL_TOOLS}/${DIR_AGGREGATOR} -p CBIProfile \
81 -installIU ${IU_AGG_PRODUCT}
82fi
83require_executable ${AGGREGATOR}
84
85RepoRaw=${WORKSPACE}/reporaw-${BUILD_NUMBER}
86Repo=${WORKSPACE}/repo-${BUILD_NUMBER}
87/bin/mkdir ${RepoRaw}
88
89${AGGREGATOR} aggregate --buildModel ${FILE_SDK_AGGR} --action CLEAN_BUILD --buildRoot ${RepoRaw}
90if [ "$?" != "0" ]
91then
92 echo "FAILURE $?"
93 exit 1
94fi
95/bin/mv ${RepoRaw}/final ${Repo}
96/bin/rm -rf ${RepoRaw}
97
98echo "========== Repo created: =========="
99/usr/bin/du -sc ${Repo}/*
100/usr/bin/du -sc ${Repo}/org/*
101/usr/bin/du -sc ${Repo}/org/eclipse/*
102echo "==================================="
103
104
105#================================================================================
106# (2) Remove irrelevant stuff
107#================================================================================
108# Removes from the build output of cbiAggregator everything that is not relevant for maven.
109# All removed directories / files will be logged to .logs/removed.txt
110
111echo "==== Remove irrelevant stuff ===="
112
113cd ${Repo}
114
115if [ ! -d .logs ]
116then
117 /bin/mkdir .logs
118elif [ -f .logs/removed.txt ]
119then
120 /bin/rm .logs/removed.txt
121fi
122
123#==== remove the p2 repository (not logged): ====
124
125/bin/rm -r p2.index p2.packed content.jar artifacts.jar
126
127#==== remove -sources artifacts, misplaced due to quirk from https://bugs.eclipse.org/508910: ====
128
129echo "== Misplaced -sources artifacts: ==" | tee >> .logs/removed.txt
130
131# works only outside org/eclipse/{platform,jdt,pde}:
132
133/usr/bin/find -type d -name platform -prune -o -name jdt -prune -o -name pde -prune -o \
134 -name \*-sources.jar\* -print -exec /bin/rm {} \; >> .logs/removed.txt
135
136#==== remove features: ====
137
138echo "== Features: ==" | tee >> .logs/removed.txt
139
140/usr/bin/find * -type d -name \*feature.group -print -exec /bin/rm -rf {} \; -prune >> .logs/removed.txt
141/usr/bin/find * -type d -name \*feature.jar -print -exec /bin/rm -rf {} \; -prune >> .logs/removed.txt
142
143#==== remove eclipse test plug-ins: ====
144
145echo "== Test plugins: ==" | tee >> .logs/removed.txt
146
147ls -d org/eclipse/*/*test* >> .logs/removed.txt
148/bin/rm -r org/eclipse/*/*test*
149
150#==== remove other non-artifacts: ====
151
152echo "== Other non-artifacts: ==" | tee >> .logs/removed.txt
153
154/usr/bin/find tooling -type d >> .logs/removed.txt
155/bin/rm -r tooling*
156
157# ... folders that contain only 1.2.3/foo-1.2.3.pom but no corresponding 1.2.3/foo-1.2.3.jar:
158function hasPomButNoJar() {
159 cd ${1}
160 # expect only one sub-directory, starting with a digit, plus maven-metadata.xml*:
161 other=`ls -d [!0-9]* 2> /dev/null`
162 if `echo "${other}" | egrep "^maven-metadata.xml\s*maven-metadata.xml.md5\s*maven-metadata.xml.sha1$"`
163 then
164 exit 1
165 fi
166 # scan all *.pom inside the version sub-directory
167 r=1
168 for pom in `ls [0-9]*/*.pom 2> /dev/null`
169 do
170 jar=`echo ${pom} | sed -e "s|\(.*\)\.pom|\1.jar|"`
171 if [ -f ${jar} ]
172 then
173 # jar found, so keep it
174 exit 1
175 fi
176 # pom without jar found, let's answer true below
177 r=0
178 done
179 exit $r
180}
181export -f hasPomButNoJar
182
183/usr/bin/find org/eclipse/{jdt,pde,platform} -type d \
184 -exec /bin/bash -c 'hasPomButNoJar "$@"' bash {} \; \
185 -print -exec /bin/rm -rf {} \; -prune >> .logs/removed.txt
186# second "bash" is used as $0 in the function
187
188cd ${WORKSPACE}
189
190echo "========== Repo reduced: =========="
191/usr/bin/du -sc ${Repo}/*
192/usr/bin/du -sc ${Repo}/org/*
193/usr/bin/du -sc ${Repo}/org/eclipse/*
194echo "==================================="
195
196#================================================================================
197# (2) Garbage Collector
198#================================================================================
199# Removes from the build output of cbiAggregator everything that is not referenced
200# from any pom below org/eclipse/{platform,jdt,pde}
201#
202# Log output:
203# .logs/removedGarbage.txt all directories during garbage collection
204# .logs/gc.log incoming dependencies of retained artifacts
205# .logs/empty-dirs.txt removed empty directories
206
207echo "==== Garbage Collector ===="
208
209cd ${Repo}
210
211#==== function gc_bundle(): ====
212# Test if pom ${1} is referenced in any other pom.
213# If not, append the containing directory to the file "toremove.txt"
214function gc_bundle {
215 AID=`echo ${1} | sed -e "s|.*/\(.*\)[_-].*|\1|"`
216 DIR=`echo ${1} | sed -e "s|\(.*\)/[0-9].*|\1|"`
217 POM=`basename ${1}`
218
219 ANSWER=`find org/eclipse/{platform,jdt,pde} -name \*.pom \! -name ${POM} \
220 -exec /bin/grep -q "<artifactId>${AID}</artifactId>" {} \; -print -quit`
221
222 if [ "$ANSWER" == "" ]
223 then
224 echo "Will remove $DIR"
225 echo $DIR >> toremove.txt
226 else
227 echo "$1 is used by $ANSWER"
228 fi
229}
230export -f gc_bundle
231
232#==== run the garbage collector: ====
233# iterate (max 5 times) in case artifacts were used only from garbage:
234for iteration in 1 2 3 4 5
235do
236 echo "== GC iteration ${iteration} =="
237
238 # look for garbage only outside platform, jdt or pde folders:
239 find -name platform -prune -o -name jdt -prune -o -name pde -prune -o \
240 -name \*.pom -exec /bin/bash -c 'gc_bundle "$@"' bash {} \; \
241 > gc-${iteration}.log
242 # second "bash" is used as $0 in the function
243
244 if [ ! -f toremove.txt ]
245 then
246 # no more garbage found
247 break
248 fi
249 cat toremove.txt >> .logs/removedGarbage.txt
250 for d in `cat toremove.txt`; do /bin/rm -r $d; done
251 /bin/rm toremove.txt
252done
253
254# merge gc logs:
255cat gc-*.log | sort --unique > .logs/gc.log
256/bin/rm gc-*.log
257
258#==== remove all directories that have become empty: ====
259for iteration in 1 2 3 4 5 ; do find -type d -empty -print \
260 -exec /bin/rmdir {} \; -prune; done \
261 >> .logs/empty-dirs.txt
262
263echo "========== Repo reduced: =========="
264/usr/bin/du -sc ${Repo}/*
265/usr/bin/du -sc ${Repo}/org/*
266/usr/bin/du -sc ${Repo}/org/eclipse/*
267echo "==================================="
268
269cd ${WORKSPACE}
270
271#================================================================================
272# (3) Enrich POMs
273#================================================================================
274# Add some required information to the generated poms:
275# - dynamic content (retrieved mostly from MANIFEST.MF):
276# - name
277# - url
278# - scm connection and tag
279# - static content
280# - license
281# - organization
282# - issue management
283
284
285echo "==== Enrich POMs ===="
286
287cd ${Repo}
288
289echo "platform"
290java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/platform &> .logs/enrich-platform.txt
291echo "jdt"
292java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/jdt &> .logs/enrich-jdt.txt
293echo "pde"
294java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/pde &> .logs/enrich-pde.txt
295
296echo "== updated checksums =="
297
298function updateCheckSums() {
299 /usr/bin/md5sum ${1} | cut -d " " -f 1 > ${1}.md5
300 /usr/bin/sha1sum ${1} | cut -d " " -f 1 > ${1}.sha1
301}
302
303for pom in org/eclipse/{platform,jdt,pde}/*/*/*.pom
304do
305 updateCheckSums ${pom}
306done
307
Stephan Herrmann42f24c92016-12-31 16:53:10 +0100308echo "==== Add Javadoc Stubs ===="
309
310# (groupSimpleName, javadocArtifactGA)
311function createJavadocs() {
312 group=${1}
313 jar="${1}-javadoc.jar"
314 artifact=${2}
315 if [ -r ${jar} ]
316 then
317 /bin/rm ${jar}
318 fi
Stephan Herrmann9fc05c92016-12-31 17:35:26 +0100319 echo -e "Corresponding javadoc can be found in artifact ${artifact}\n" > README.txt
Stephan Herrmann42f24c92016-12-31 16:53:10 +0100320 jar cf ${jar} README.txt
321 for pom in org/eclipse/${group}/*/*/*.pom
322 do
323 javadoc=`echo ${pom} | sed -e "s|\(.*\)\.pom|\1-javadoc.jar|"`
324 /bin/cp ${jar} ${javadoc}
325 done
326}
327
328createJavadocs platform org.eclipse.platform:org.eclipse.platform.doc.isv
329createJavadocs jdt org.eclipse.jdt:org.eclipse.jdt.doc.isv
330createJavadocs pde org.eclipse.pde:org.eclipse.pde.doc.user
Stephan Herrmannee73d532016-12-20 23:37:28 +0100331
332echo "========== Repo completed ========="
333
334cd ${WORKSPACE}