Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #******************************************************************************* |
Stephan Herrmann | 95fbf62 | 2017-03-05 13:43:09 +0100 | [diff] [blame] | 3 | # Copyright (c) 2016, 2017 GK Software AG and others. |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 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 | |
Stephan Herrmann | 4e843b0 | 2017-01-26 21:18:42 +0100 | [diff] [blame] | 17 | source `dirname ${0}`/properties.sh |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 18 | |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 19 | |
| 20 | #================================================================================ |
| 21 | # Util functions |
| 22 | #================================================================================ |
| 23 | function 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 Herrmann | 0d566b5 | 2017-10-17 17:58:14 +0200 | [diff] [blame] | 34 | function 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 Herrmann | 9a98101 | 2017-01-01 11:05:54 +0100 | [diff] [blame] | 46 | #================================================================================ |
| 47 | # (1) Install and run the CBI aggregator |
| 48 | #================================================================================ |
| 49 | echo "==== CBI aggregator ====" |
| 50 | |
Stephan Herrmann | b3148c6 | 2016-12-21 00:42:13 +0100 | [diff] [blame] | 51 | # -------- fetch .aggr file **TEMP** will eventually move to the releng git: ------------ |
| 52 | git 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 Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 58 | if [ ! -d ${LOCAL_TOOLS} ] |
| 59 | then |
| 60 | /bin/mkdir ${LOCAL_TOOLS} |
| 61 | fi |
| 62 | |
| 63 | if [ ! -x ${ECLIPSE} ] |
| 64 | then |
| 65 | cd ${LOCAL_TOOLS} |
Stephan Herrmann | 9a98101 | 2017-01-01 11:05:54 +0100 | [diff] [blame] | 66 | echo "Extracting Eclipse from ${FILE_ECLIPSE} ..." |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 67 | tar xf ${FILE_ECLIPSE} |
| 68 | cd ${WORKSPACE} |
| 69 | fi |
| 70 | require_executable ${ECLIPSE} |
| 71 | |
| 72 | if [ ! -x ${AGGREGATOR} ] |
| 73 | then |
Stephan Herrmann | 9a98101 | 2017-01-01 11:05:54 +0100 | [diff] [blame] | 74 | echo "Installing the CBI aggregator into ${LOCAL_TOOLS}/${DIR_AGGREGATOR} ..." |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 75 | ${ECLIPSE} -application ${APP_NAME_P2DIRECTOR} \ |
| 76 | -r ${URL_AGG_UPDATES} \ |
| 77 | -d ${LOCAL_TOOLS}/${DIR_AGGREGATOR} -p CBIProfile \ |
| 78 | -installIU ${IU_AGG_PRODUCT} |
| 79 | fi |
| 80 | require_executable ${AGGREGATOR} |
| 81 | |
| 82 | RepoRaw=${WORKSPACE}/reporaw-${BUILD_NUMBER} |
| 83 | Repo=${WORKSPACE}/repo-${BUILD_NUMBER} |
| 84 | /bin/mkdir ${RepoRaw} |
| 85 | |
Stephan Herrmann | 9a98101 | 2017-01-01 11:05:54 +0100 | [diff] [blame] | 86 | echo "Running the aggregator with build model ${FILE_SDK_AGGR} ..." |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 87 | ${AGGREGATOR} aggregate --buildModel ${FILE_SDK_AGGR} --action CLEAN_BUILD --buildRoot ${RepoRaw} |
| 88 | if [ "$?" != "0" ] |
| 89 | then |
| 90 | echo "FAILURE $?" |
| 91 | exit 1 |
| 92 | fi |
| 93 | /bin/mv ${RepoRaw}/final ${Repo} |
| 94 | /bin/rm -rf ${RepoRaw} |
| 95 | |
| 96 | echo "========== Repo created: ==========" |
| 97 | /usr/bin/du -sc ${Repo}/* |
| 98 | /usr/bin/du -sc ${Repo}/org/* |
| 99 | /usr/bin/du -sc ${Repo}/org/eclipse/* |
| 100 | echo "===================================" |
| 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 | |
| 109 | echo "==== Remove irrelevant stuff ====" |
| 110 | |
| 111 | cd ${Repo} |
| 112 | |
| 113 | if [ ! -d .logs ] |
| 114 | then |
| 115 | /bin/mkdir .logs |
| 116 | elif [ -f .logs/removed.txt ] |
| 117 | then |
| 118 | /bin/rm .logs/removed.txt |
| 119 | fi |
| 120 | |
| 121 | #==== remove the p2 repository (not logged): ==== |
| 122 | |
| 123 | /bin/rm -r p2.index p2.packed content.jar artifacts.jar |
| 124 | |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 125 | #==== remove features: ==== |
| 126 | |
| 127 | echo "== 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 | |
| 134 | echo "== Test plugins: ==" | tee >> .logs/removed.txt |
| 135 | |
| 136 | ls -d org/eclipse/*/*test* >> .logs/removed.txt |
| 137 | /bin/rm -r org/eclipse/*/*test* |
| 138 | |
| 139 | #==== remove other non-artifacts: ==== |
| 140 | |
| 141 | echo "== 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: |
| 147 | function 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 Herrmann | 0b6f393 | 2017-01-01 21:17:57 +0100 | [diff] [blame] | 151 | if echo "${other}" | tr "\n" " " | egrep "^maven-metadata.xml maven-metadata.xml.md5 maven-metadata.xml.sha1 \$" |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 152 | then |
Stephan Herrmann | 0a35892 | 2017-01-01 11:19:36 +0100 | [diff] [blame] | 153 | : # clean -> proceed below |
Stephan Herrmann | 9a98101 | 2017-01-01 11:05:54 +0100 | [diff] [blame] | 154 | else |
| 155 | exit 1 # unexpected content found, don't remove |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 156 | 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 | } |
| 172 | export -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 | |
| 179 | cd ${WORKSPACE} |
| 180 | |
| 181 | echo "========== Repo reduced: ==========" |
| 182 | /usr/bin/du -sc ${Repo}/* |
| 183 | /usr/bin/du -sc ${Repo}/org/* |
| 184 | /usr/bin/du -sc ${Repo}/org/eclipse/* |
| 185 | echo "===================================" |
| 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 | |
| 198 | echo "==== Garbage Collector ====" |
| 199 | |
| 200 | cd ${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" |
| 205 | function 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 | } |
| 221 | export -f gc_bundle |
| 222 | |
| 223 | #==== run the garbage collector: ==== |
| 224 | # iterate (max 5 times) in case artifacts were used only from garbage: |
| 225 | for iteration in 1 2 3 4 5 |
| 226 | do |
| 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 |
| 243 | done |
| 244 | |
| 245 | # merge gc logs: |
| 246 | cat gc-*.log | sort --unique > .logs/gc.log |
| 247 | /bin/rm gc-*.log |
| 248 | |
| 249 | #==== remove all directories that have become empty: ==== |
Stephan Herrmann | 3b55767 | 2017-01-26 22:26:12 +0100 | [diff] [blame] | 250 | for iteration in 1 2 3 4 5 6 ; do find -type d -empty -print \ |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 251 | -exec /bin/rmdir {} \; -prune; done \ |
| 252 | >> .logs/empty-dirs.txt |
| 253 | |
| 254 | echo "========== Repo reduced: ==========" |
| 255 | /usr/bin/du -sc ${Repo}/* |
| 256 | /usr/bin/du -sc ${Repo}/org/* |
| 257 | /usr/bin/du -sc ${Repo}/org/eclipse/* |
| 258 | echo "===================================" |
| 259 | |
| 260 | cd ${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 Herrmann | 9a98101 | 2017-01-01 11:05:54 +0100 | [diff] [blame] | 269 | # - scm connection, tag and url |
| 270 | # - semi dynamic |
| 271 | # - developers (based on static map git-repo-base -> project leads) |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 272 | # - static content |
| 273 | # - license |
| 274 | # - organization |
| 275 | # - issue management |
| 276 | |
| 277 | |
| 278 | echo "==== Enrich POMs ====" |
| 279 | |
| 280 | cd ${Repo} |
| 281 | |
| 282 | echo "platform" |
| 283 | java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/platform &> .logs/enrich-platform.txt |
| 284 | echo "jdt" |
| 285 | java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/jdt &> .logs/enrich-jdt.txt |
| 286 | echo "pde" |
| 287 | java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/pde &> .logs/enrich-pde.txt |
| 288 | |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 289 | |
Stephan Herrmann | 9a98101 | 2017-01-01 11:05:54 +0100 | [diff] [blame] | 290 | echo "==== Add Javadoc stubs ====" |
Stephan Herrmann | 42f24c9 | 2016-12-31 16:53:10 +0100 | [diff] [blame] | 291 | |
Stephan Herrmann | 07ae09f | 2017-01-01 18:58:28 +0100 | [diff] [blame] | 292 | cd ${Repo} |
| 293 | |
Stephan Herrmann | 42f24c9 | 2016-12-31 16:53:10 +0100 | [diff] [blame] | 294 | # (groupSimpleName, javadocArtifactGA) |
| 295 | function 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 Herrmann | 9fc05c9 | 2016-12-31 17:35:26 +0100 | [diff] [blame] | 303 | echo -e "Corresponding javadoc can be found in artifact ${artifact}\n" > README.txt |
Stephan Herrmann | 42f24c9 | 2016-12-31 16:53:10 +0100 | [diff] [blame] | 304 | 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 | |
| 312 | createJavadocs platform org.eclipse.platform:org.eclipse.platform.doc.isv |
| 313 | createJavadocs jdt org.eclipse.jdt:org.eclipse.jdt.doc.isv |
| 314 | createJavadocs pde org.eclipse.pde:org.eclipse.pde.doc.user |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 315 | |
Stephan Herrmann | 07ae09f | 2017-01-01 18:58:28 +0100 | [diff] [blame] | 316 | echo "==== Create missing sources artifacts ====" |
| 317 | |
| 318 | cd ${Repo} |
| 319 | |
| 320 | function buildSourceJar() { |
| 321 | if [ -d assemble ] |
| 322 | then |
| 323 | /bin/rm -r assemble |
| 324 | fi |
| 325 | /bin/mkdir assemble |
Stephan Herrmann | c6c07eb | 2017-01-01 20:50:11 +0100 | [diff] [blame] | 326 | giturl=file://localhost/gitroot/${1} |
Stephan Herrmann | 07ae09f | 2017-01-01 18:58:28 +0100 | [diff] [blame] | 327 | 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 Herrmann | c6c07eb | 2017-01-01 20:50:11 +0100 | [diff] [blame] | 342 | if [ $# > 6 ] |
| 343 | then |
| 344 | shift 6 |
| 345 | for src in "$@" |
| 346 | do |
| 347 | /bin/mv "${gitpath}/${src}" assemble/ |
| 348 | done |
| 349 | fi |
Stephan Herrmann | 07ae09f | 2017-01-01 18:58:28 +0100 | [diff] [blame] | 350 | /bin/rm -rf ${gitpath} |
| 351 | cd assemble |
| 352 | jar cf ../${group}/${artifact}/${version}/${artifact}-${version}-sources.jar * |
| 353 | cd - |
| 354 | } |
| 355 | |
Stephan Herrmann | 4e843b0 | 2017-01-26 21:18:42 +0100 | [diff] [blame] | 356 | while read line |
| 357 | do |
| 358 | buildSourceJar $line |
Stephan Herrmann | 3b55767 | 2017-01-26 22:26:12 +0100 | [diff] [blame] | 359 | done < ${WORKSPACE}/sourceBundles.txt |
Stephan Herrmann | 07ae09f | 2017-01-01 18:58:28 +0100 | [diff] [blame] | 360 | |
Stephan Herrmann | 95fbf62 | 2017-03-05 13:43:09 +0100 | [diff] [blame] | 361 | # copy ecj-src from build output (NB: we are mapping from SDK version (4.x) back to ECJ version (3.x)): |
Stephan Herrmann | 9fb254e | 2017-03-05 13:53:22 +0100 | [diff] [blame] | 362 | /bin/cp ${DROPS4}/${SDK_BUILD_DIR}/ecjsrc-${SDK_VERSION}.jar org/eclipse/jdt/ecj/${ECJ_VERSION}/ecj-${ECJ_VERSION}-sources.jar |
Stephan Herrmann | 95fbf62 | 2017-03-05 13:43:09 +0100 | [diff] [blame] | 363 | |
Stephan Herrmann | 4e843b0 | 2017-01-26 21:18:42 +0100 | [diff] [blame] | 364 | # special hack for missing source bundle with several source folders with blanks: |
Stephan Herrmann | c6c07eb | 2017-01-01 20:50:11 +0100 | [diff] [blame] | 365 | buildSourceJar platform/eclipse.platform.swt.git \ |
| 366 | bundles/org.eclipse.swt.tools \ |
Stephan Herrmann | 99ad6fb | 2017-07-26 21:50:23 +0200 | [diff] [blame] | 367 | R4_7 \ |
| 368 | org/eclipse/platform org.eclipse.swt.tools 3.106.0 \ |
Stephan Herrmann | c6c07eb | 2017-01-01 20:50:11 +0100 | [diff] [blame] | 369 | "JNI Generation" \ |
| 370 | "Mac Generation" \ |
| 371 | "Icon Exe" \ |
| 372 | "NativeStats" \ |
| 373 | "Mozilla Generation" \ |
| 374 | "JavadocBasher" |
| 375 | |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 376 | echo "========== Repo completed =========" |
| 377 | |
Stephan Herrmann | 0d566b5 | 2017-10-17 17:58:14 +0200 | [diff] [blame] | 378 | create_baseline |
| 379 | |
| 380 | echo "========== Next baseline created =========" |
| 381 | |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 382 | cd ${WORKSPACE} |