blob: 094d541b7960a85128626326f1079940f5466230 [file] [log] [blame]
Stephan Herrmannee73d532016-12-20 23:37:28 +01001#!/bin/bash
2#*******************************************************************************
Stephan Herrmann95fbf622017-03-05 13:43:09 +01003# Copyright (c) 2016, 2017 GK Software AG and others.
Stephan Herrmannee73d532016-12-20 23:37:28 +01004# 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
Stephan Herrmann4e843b02017-01-26 21:18:42 +010017source `dirname ${0}`/properties.sh
Stephan Herrmannee73d532016-12-20 23:37:28 +010018
Stephan Herrmannee73d532016-12-20 23:37:28 +010019
20#================================================================================
21# Util functions
22#================================================================================
23function require_executable() {
24 if [ -x ${1} ]
25 then
26 echo "Successfully installed: ${1}"
27 else
28 echo "not executable: ${1}"
29 /bin/ls -l ${1}
30 exit 1
31 fi
32}
33
Stephan Herrmann0d566b52017-10-17 17:58:14 +020034function create_baseline() {
35 cd ${Repo}
36 for line in `find -name org/eclipse \*.jar`
37 do
38 file=`basename $line`
39 name=`echo $file | sed -e 's/\(.*\)_.*/\1/' | tr '.' '_'`
40 version=`echo $file | sed -e 's/.*_\(.*\)\.v[0-9-]*\.jar/\1/'`
41 echo VERSION_$name=$version
42 done > ${WORKSPACE}/baseline.txt
43 cd -
44}
45
Stephan Herrmann9a981012017-01-01 11:05:54 +010046#================================================================================
47# (1) Install and run the CBI aggregator
48#================================================================================
49echo "==== CBI aggregator ===="
50
Stephan Herrmannb3148c62016-12-21 00:42:13 +010051# -------- fetch .aggr file **TEMP** will eventually move to the releng git: ------------
52git archive --remote=file://localhost/gitroot/objectteams/org.eclipse.objectteams.git \
53 master releng/EnrichPoms/SDK4Mvn.aggr \
54 | tar xv
55/bin/mv releng/EnrichPoms/SDK4Mvn.aggr ${WORKSPACE}/
56/bin/rmdir -p releng/EnrichPoms
57
Stephan Herrmannee73d532016-12-20 23:37:28 +010058if [ ! -d ${LOCAL_TOOLS} ]
59then
60 /bin/mkdir ${LOCAL_TOOLS}
61fi
62
63if [ ! -x ${ECLIPSE} ]
64then
65 cd ${LOCAL_TOOLS}
Stephan Herrmann9a981012017-01-01 11:05:54 +010066 echo "Extracting Eclipse from ${FILE_ECLIPSE} ..."
Stephan Herrmannee73d532016-12-20 23:37:28 +010067 tar xf ${FILE_ECLIPSE}
68 cd ${WORKSPACE}
69fi
70require_executable ${ECLIPSE}
71
72if [ ! -x ${AGGREGATOR} ]
73then
Stephan Herrmann9a981012017-01-01 11:05:54 +010074 echo "Installing the CBI aggregator into ${LOCAL_TOOLS}/${DIR_AGGREGATOR} ..."
Stephan Herrmannee73d532016-12-20 23:37:28 +010075 ${ECLIPSE} -application ${APP_NAME_P2DIRECTOR} \
76 -r ${URL_AGG_UPDATES} \
77 -d ${LOCAL_TOOLS}/${DIR_AGGREGATOR} -p CBIProfile \
78 -installIU ${IU_AGG_PRODUCT}
79fi
80require_executable ${AGGREGATOR}
81
82RepoRaw=${WORKSPACE}/reporaw-${BUILD_NUMBER}
83Repo=${WORKSPACE}/repo-${BUILD_NUMBER}
84/bin/mkdir ${RepoRaw}
85
Stephan Herrmann9a981012017-01-01 11:05:54 +010086echo "Running the aggregator with build model ${FILE_SDK_AGGR} ..."
Stephan Herrmannee73d532016-12-20 23:37:28 +010087${AGGREGATOR} aggregate --buildModel ${FILE_SDK_AGGR} --action CLEAN_BUILD --buildRoot ${RepoRaw}
88if [ "$?" != "0" ]
89then
90 echo "FAILURE $?"
91 exit 1
92fi
93/bin/mv ${RepoRaw}/final ${Repo}
94/bin/rm -rf ${RepoRaw}
95
96echo "========== Repo created: =========="
97/usr/bin/du -sc ${Repo}/*
98/usr/bin/du -sc ${Repo}/org/*
99/usr/bin/du -sc ${Repo}/org/eclipse/*
100echo "==================================="
101
102
103#================================================================================
104# (2) Remove irrelevant stuff
105#================================================================================
106# Removes from the build output of cbiAggregator everything that is not relevant for maven.
107# All removed directories / files will be logged to .logs/removed.txt
108
109echo "==== Remove irrelevant stuff ===="
110
111cd ${Repo}
112
113if [ ! -d .logs ]
114then
115 /bin/mkdir .logs
116elif [ -f .logs/removed.txt ]
117then
118 /bin/rm .logs/removed.txt
119fi
120
121#==== remove the p2 repository (not logged): ====
122
123/bin/rm -r p2.index p2.packed content.jar artifacts.jar
124
Stephan Herrmannee73d532016-12-20 23:37:28 +0100125#==== remove features: ====
126
127echo "== Features: ==" | tee >> .logs/removed.txt
128
129/usr/bin/find * -type d -name \*feature.group -print -exec /bin/rm -rf {} \; -prune >> .logs/removed.txt
130/usr/bin/find * -type d -name \*feature.jar -print -exec /bin/rm -rf {} \; -prune >> .logs/removed.txt
131
132#==== remove eclipse test plug-ins: ====
133
134echo "== Test plugins: ==" | tee >> .logs/removed.txt
135
136ls -d org/eclipse/*/*test* >> .logs/removed.txt
137/bin/rm -r org/eclipse/*/*test*
138
139#==== remove other non-artifacts: ====
140
141echo "== Other non-artifacts: ==" | tee >> .logs/removed.txt
142
143/usr/bin/find tooling -type d >> .logs/removed.txt
144/bin/rm -r tooling*
145
146# ... folders that contain only 1.2.3/foo-1.2.3.pom but no corresponding 1.2.3/foo-1.2.3.jar:
147function hasPomButNoJar() {
148 cd ${1}
149 # expect only one sub-directory, starting with a digit, plus maven-metadata.xml*:
150 other=`ls -d [!0-9]* 2> /dev/null`
Stephan Herrmann0b6f3932017-01-01 21:17:57 +0100151 if echo "${other}" | tr "\n" " " | egrep "^maven-metadata.xml maven-metadata.xml.md5 maven-metadata.xml.sha1 \$"
Stephan Herrmannee73d532016-12-20 23:37:28 +0100152 then
Stephan Herrmann0a358922017-01-01 11:19:36 +0100153 : # clean -> proceed below
Stephan Herrmann9a981012017-01-01 11:05:54 +0100154 else
155 exit 1 # unexpected content found, don't remove
Stephan Herrmannee73d532016-12-20 23:37:28 +0100156 fi
157 # scan all *.pom inside the version sub-directory
158 r=1
159 for pom in `ls [0-9]*/*.pom 2> /dev/null`
160 do
161 jar=`echo ${pom} | sed -e "s|\(.*\)\.pom|\1.jar|"`
162 if [ -f ${jar} ]
163 then
164 # jar found, so keep it
165 exit 1
166 fi
167 # pom without jar found, let's answer true below
168 r=0
169 done
170 exit $r
171}
172export -f hasPomButNoJar
173
174/usr/bin/find org/eclipse/{jdt,pde,platform} -type d \
175 -exec /bin/bash -c 'hasPomButNoJar "$@"' bash {} \; \
176 -print -exec /bin/rm -rf {} \; -prune >> .logs/removed.txt
177# second "bash" is used as $0 in the function
178
179cd ${WORKSPACE}
180
181echo "========== Repo reduced: =========="
182/usr/bin/du -sc ${Repo}/*
183/usr/bin/du -sc ${Repo}/org/*
184/usr/bin/du -sc ${Repo}/org/eclipse/*
185echo "==================================="
186
187#================================================================================
188# (2) Garbage Collector
189#================================================================================
190# Removes from the build output of cbiAggregator everything that is not referenced
191# from any pom below org/eclipse/{platform,jdt,pde}
192#
193# Log output:
194# .logs/removedGarbage.txt all directories during garbage collection
195# .logs/gc.log incoming dependencies of retained artifacts
196# .logs/empty-dirs.txt removed empty directories
197
198echo "==== Garbage Collector ===="
199
200cd ${Repo}
201
202#==== function gc_bundle(): ====
203# Test if pom ${1} is referenced in any other pom.
204# If not, append the containing directory to the file "toremove.txt"
205function gc_bundle {
206 AID=`echo ${1} | sed -e "s|.*/\(.*\)[_-].*|\1|"`
207 DIR=`echo ${1} | sed -e "s|\(.*\)/[0-9].*|\1|"`
208 POM=`basename ${1}`
209
210 ANSWER=`find org/eclipse/{platform,jdt,pde} -name \*.pom \! -name ${POM} \
211 -exec /bin/grep -q "<artifactId>${AID}</artifactId>" {} \; -print -quit`
212
213 if [ "$ANSWER" == "" ]
214 then
215 echo "Will remove $DIR"
216 echo $DIR >> toremove.txt
217 else
218 echo "$1 is used by $ANSWER"
219 fi
220}
221export -f gc_bundle
222
223#==== run the garbage collector: ====
224# iterate (max 5 times) in case artifacts were used only from garbage:
225for iteration in 1 2 3 4 5
226do
227 echo "== GC iteration ${iteration} =="
228
229 # look for garbage only outside platform, jdt or pde folders:
230 find -name platform -prune -o -name jdt -prune -o -name pde -prune -o \
231 -name \*.pom -exec /bin/bash -c 'gc_bundle "$@"' bash {} \; \
232 > gc-${iteration}.log
233 # second "bash" is used as $0 in the function
234
235 if [ ! -f toremove.txt ]
236 then
237 # no more garbage found
238 break
239 fi
240 cat toremove.txt >> .logs/removedGarbage.txt
241 for d in `cat toremove.txt`; do /bin/rm -r $d; done
242 /bin/rm toremove.txt
243done
244
245# merge gc logs:
246cat gc-*.log | sort --unique > .logs/gc.log
247/bin/rm gc-*.log
248
249#==== remove all directories that have become empty: ====
Stephan Herrmann3b557672017-01-26 22:26:12 +0100250for iteration in 1 2 3 4 5 6 ; do find -type d -empty -print \
Stephan Herrmannee73d532016-12-20 23:37:28 +0100251 -exec /bin/rmdir {} \; -prune; done \
252 >> .logs/empty-dirs.txt
253
254echo "========== Repo reduced: =========="
255/usr/bin/du -sc ${Repo}/*
256/usr/bin/du -sc ${Repo}/org/*
257/usr/bin/du -sc ${Repo}/org/eclipse/*
258echo "==================================="
259
260cd ${WORKSPACE}
261
262#================================================================================
263# (3) Enrich POMs
264#================================================================================
265# Add some required information to the generated poms:
266# - dynamic content (retrieved mostly from MANIFEST.MF):
267# - name
268# - url
Stephan Herrmann9a981012017-01-01 11:05:54 +0100269# - scm connection, tag and url
270# - semi dynamic
271# - developers (based on static map git-repo-base -> project leads)
Stephan Herrmannee73d532016-12-20 23:37:28 +0100272# - static content
273# - license
274# - organization
275# - issue management
276
277
278echo "==== Enrich POMs ===="
279
280cd ${Repo}
281
282echo "platform"
283java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/platform &> .logs/enrich-platform.txt
284echo "jdt"
285java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/jdt &> .logs/enrich-jdt.txt
286echo "pde"
287java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/pde &> .logs/enrich-pde.txt
288
Stephan Herrmannee73d532016-12-20 23:37:28 +0100289
Stephan Herrmann9a981012017-01-01 11:05:54 +0100290echo "==== Add Javadoc stubs ===="
Stephan Herrmann42f24c92016-12-31 16:53:10 +0100291
Stephan Herrmann07ae09f2017-01-01 18:58:28 +0100292cd ${Repo}
293
Stephan Herrmann42f24c92016-12-31 16:53:10 +0100294# (groupSimpleName, javadocArtifactGA)
295function createJavadocs() {
296 group=${1}
297 jar="${1}-javadoc.jar"
298 artifact=${2}
299 if [ -r ${jar} ]
300 then
301 /bin/rm ${jar}
302 fi
Stephan Herrmann9fc05c92016-12-31 17:35:26 +0100303 echo -e "Corresponding javadoc can be found in artifact ${artifact}\n" > README.txt
Stephan Herrmann42f24c92016-12-31 16:53:10 +0100304 jar cf ${jar} README.txt
305 for pom in org/eclipse/${group}/*/*/*.pom
306 do
307 javadoc=`echo ${pom} | sed -e "s|\(.*\)\.pom|\1-javadoc.jar|"`
308 /bin/cp ${jar} ${javadoc}
309 done
310}
311
312createJavadocs platform org.eclipse.platform:org.eclipse.platform.doc.isv
313createJavadocs jdt org.eclipse.jdt:org.eclipse.jdt.doc.isv
314createJavadocs pde org.eclipse.pde:org.eclipse.pde.doc.user
Stephan Herrmannee73d532016-12-20 23:37:28 +0100315
Stephan Herrmann07ae09f2017-01-01 18:58:28 +0100316echo "==== Create missing sources artifacts ===="
317
318cd ${Repo}
319
320function buildSourceJar() {
321 if [ -d assemble ]
322 then
323 /bin/rm -r assemble
324 fi
325 /bin/mkdir assemble
Stephan Herrmannc6c07eb2017-01-01 20:50:11 +0100326 giturl=file://localhost/gitroot/${1}
Stephan Herrmann07ae09f2017-01-01 18:58:28 +0100327 gitpath=${2}
328 gittag=${3}
329 group=${4}
330 artifact=${5}
331 version=${6}
332 git archive --remote=${giturl} \
333 ${gittag} ${gitpath} \
334 | tar xv
335 /bin/mv ${gitpath}/src/* assemble/
336 /bin/mv ${gitpath}/META-INF assemble/
337 if [ -d ${gitpath}/OSGI-INF ]
338 then
339 /bin/mv ${gitpath}/OSGI-INF assemble/
340 fi
341 /bin/mv ${gitpath}/about.html assemble/
Stephan Herrmannc6c07eb2017-01-01 20:50:11 +0100342 if [ $# > 6 ]
343 then
344 shift 6
345 for src in "$@"
346 do
347 /bin/mv "${gitpath}/${src}" assemble/
348 done
349 fi
Stephan Herrmann07ae09f2017-01-01 18:58:28 +0100350 /bin/rm -rf ${gitpath}
351 cd assemble
352 jar cf ../${group}/${artifact}/${version}/${artifact}-${version}-sources.jar *
353 cd -
354}
355
Stephan Herrmann4e843b02017-01-26 21:18:42 +0100356while read line
357do
358 buildSourceJar $line
Stephan Herrmann3b557672017-01-26 22:26:12 +0100359done < ${WORKSPACE}/sourceBundles.txt
Stephan Herrmann07ae09f2017-01-01 18:58:28 +0100360
Stephan Herrmann95fbf622017-03-05 13:43:09 +0100361# copy ecj-src from build output (NB: we are mapping from SDK version (4.x) back to ECJ version (3.x)):
Stephan Herrmann9fb254e2017-03-05 13:53:22 +0100362/bin/cp ${DROPS4}/${SDK_BUILD_DIR}/ecjsrc-${SDK_VERSION}.jar org/eclipse/jdt/ecj/${ECJ_VERSION}/ecj-${ECJ_VERSION}-sources.jar
Stephan Herrmann95fbf622017-03-05 13:43:09 +0100363
Stephan Herrmann4e843b02017-01-26 21:18:42 +0100364# special hack for missing source bundle with several source folders with blanks:
Stephan Herrmannc6c07eb2017-01-01 20:50:11 +0100365buildSourceJar platform/eclipse.platform.swt.git \
366 bundles/org.eclipse.swt.tools \
Stephan Herrmann99ad6fb2017-07-26 21:50:23 +0200367 R4_7 \
368 org/eclipse/platform org.eclipse.swt.tools 3.106.0 \
Stephan Herrmannc6c07eb2017-01-01 20:50:11 +0100369 "JNI Generation" \
370 "Mac Generation" \
371 "Icon Exe" \
372 "NativeStats" \
373 "Mozilla Generation" \
374 "JavadocBasher"
375
Stephan Herrmannee73d532016-12-20 23:37:28 +0100376echo "========== Repo completed ========="
377
Stephan Herrmann0d566b52017-10-17 17:58:14 +0200378create_baseline
379
380echo "========== Next baseline created ========="
381
Stephan Herrmannee73d532016-12-20 23:37:28 +0100382cd ${WORKSPACE}