Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 1 | #!/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: |
| 18 | DROPS4=/home/data/httpd/archive.eclipse.org/eclipse/downloads/drops4 |
| 19 | FILE_ECLIPSE=${DROPS4}/R-4.6.1-201609071200/eclipse-SDK-4.6.1-linux-gtk-x86_64.tar.gz |
| 20 | APP_NAME_P2DIRECTOR=org.eclipse.equinox.p2.director |
| 21 | |
| 22 | # QUESTION: set tmpdir? (-vmargs not accepted by director application?) |
| 23 | |
| 24 | # AGGREGATOR: |
| 25 | IU_AGG_PRODUCT=org.eclipse.cbi.p2repo.cli.product |
| 26 | URL_AGG_UPDATES=http://download.eclipse.org/cbi/updates/aggregator/headless/4.6/ |
| 27 | |
Stephan Herrmann | b3148c6 | 2016-12-21 00:42:13 +0100 | [diff] [blame] | 28 | FILE_SDK_AGGR=${WORKSPACE}/SDK4Mvn.aggr |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 29 | |
| 30 | # ENRICH POMS tool: |
Stephan Herrmann | 8f2b5ab | 2016-12-21 00:23:47 +0100 | [diff] [blame] | 31 | ENRICH_POMS_JAR=${WORKSPACE}/../../pomEnricher/workspace/EnrichPoms.jar |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 32 | |
| 33 | # LOCAL TOOLS: |
| 34 | LOCAL_TOOLS=${WORKSPACE}/tools |
| 35 | DIR_AGGREGATOR=aggregator |
| 36 | AGGREGATOR=${LOCAL_TOOLS}/${DIR_AGGREGATOR}/cbiAggr |
| 37 | ECLIPSE=${LOCAL_TOOLS}/eclipse/eclipse |
| 38 | |
| 39 | #================================================================================ |
| 40 | # Util functions |
| 41 | #================================================================================ |
| 42 | function 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 Herrmann | b3148c6 | 2016-12-21 00:42:13 +0100 | [diff] [blame] | 53 | # -------- fetch .aggr file **TEMP** will eventually move to the releng git: ------------ |
| 54 | git 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 Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 60 | #================================================================================ |
| 61 | # (1) Install and run the CBI aggregator |
| 62 | #================================================================================ |
| 63 | if [ ! -d ${LOCAL_TOOLS} ] |
| 64 | then |
| 65 | /bin/mkdir ${LOCAL_TOOLS} |
| 66 | fi |
| 67 | |
| 68 | if [ ! -x ${ECLIPSE} ] |
| 69 | then |
| 70 | cd ${LOCAL_TOOLS} |
| 71 | tar xf ${FILE_ECLIPSE} |
| 72 | cd ${WORKSPACE} |
| 73 | fi |
| 74 | require_executable ${ECLIPSE} |
| 75 | |
| 76 | if [ ! -x ${AGGREGATOR} ] |
| 77 | then |
| 78 | ${ECLIPSE} -application ${APP_NAME_P2DIRECTOR} \ |
| 79 | -r ${URL_AGG_UPDATES} \ |
| 80 | -d ${LOCAL_TOOLS}/${DIR_AGGREGATOR} -p CBIProfile \ |
| 81 | -installIU ${IU_AGG_PRODUCT} |
| 82 | fi |
| 83 | require_executable ${AGGREGATOR} |
| 84 | |
| 85 | RepoRaw=${WORKSPACE}/reporaw-${BUILD_NUMBER} |
| 86 | Repo=${WORKSPACE}/repo-${BUILD_NUMBER} |
| 87 | /bin/mkdir ${RepoRaw} |
| 88 | |
| 89 | ${AGGREGATOR} aggregate --buildModel ${FILE_SDK_AGGR} --action CLEAN_BUILD --buildRoot ${RepoRaw} |
| 90 | if [ "$?" != "0" ] |
| 91 | then |
| 92 | echo "FAILURE $?" |
| 93 | exit 1 |
| 94 | fi |
| 95 | /bin/mv ${RepoRaw}/final ${Repo} |
| 96 | /bin/rm -rf ${RepoRaw} |
| 97 | |
| 98 | echo "========== Repo created: ==========" |
| 99 | /usr/bin/du -sc ${Repo}/* |
| 100 | /usr/bin/du -sc ${Repo}/org/* |
| 101 | /usr/bin/du -sc ${Repo}/org/eclipse/* |
| 102 | echo "===================================" |
| 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 | |
| 111 | echo "==== Remove irrelevant stuff ====" |
| 112 | |
| 113 | cd ${Repo} |
| 114 | |
| 115 | if [ ! -d .logs ] |
| 116 | then |
| 117 | /bin/mkdir .logs |
| 118 | elif [ -f .logs/removed.txt ] |
| 119 | then |
| 120 | /bin/rm .logs/removed.txt |
| 121 | fi |
| 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 | |
| 129 | echo "== 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 | |
| 138 | echo "== 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 | |
| 145 | echo "== Test plugins: ==" | tee >> .logs/removed.txt |
| 146 | |
| 147 | ls -d org/eclipse/*/*test* >> .logs/removed.txt |
| 148 | /bin/rm -r org/eclipse/*/*test* |
| 149 | |
| 150 | #==== remove other non-artifacts: ==== |
| 151 | |
| 152 | echo "== 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: |
| 158 | function 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 | } |
| 181 | export -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 | |
| 188 | cd ${WORKSPACE} |
| 189 | |
| 190 | echo "========== Repo reduced: ==========" |
| 191 | /usr/bin/du -sc ${Repo}/* |
| 192 | /usr/bin/du -sc ${Repo}/org/* |
| 193 | /usr/bin/du -sc ${Repo}/org/eclipse/* |
| 194 | echo "===================================" |
| 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 | |
| 207 | echo "==== Garbage Collector ====" |
| 208 | |
| 209 | cd ${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" |
| 214 | function 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 | } |
| 230 | export -f gc_bundle |
| 231 | |
| 232 | #==== run the garbage collector: ==== |
| 233 | # iterate (max 5 times) in case artifacts were used only from garbage: |
| 234 | for iteration in 1 2 3 4 5 |
| 235 | do |
| 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 |
| 252 | done |
| 253 | |
| 254 | # merge gc logs: |
| 255 | cat gc-*.log | sort --unique > .logs/gc.log |
| 256 | /bin/rm gc-*.log |
| 257 | |
| 258 | #==== remove all directories that have become empty: ==== |
| 259 | for 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 | |
| 263 | echo "========== Repo reduced: ==========" |
| 264 | /usr/bin/du -sc ${Repo}/* |
| 265 | /usr/bin/du -sc ${Repo}/org/* |
| 266 | /usr/bin/du -sc ${Repo}/org/eclipse/* |
| 267 | echo "===================================" |
| 268 | |
| 269 | cd ${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 | |
| 285 | echo "==== Enrich POMs ====" |
| 286 | |
| 287 | cd ${Repo} |
| 288 | |
| 289 | echo "platform" |
| 290 | java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/platform &> .logs/enrich-platform.txt |
| 291 | echo "jdt" |
| 292 | java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/jdt &> .logs/enrich-jdt.txt |
| 293 | echo "pde" |
| 294 | java -jar ${ENRICH_POMS_JAR} `pwd`/org/eclipse/pde &> .logs/enrich-pde.txt |
| 295 | |
| 296 | echo "== updated checksums ==" |
| 297 | |
| 298 | function 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 | |
| 303 | for pom in org/eclipse/{platform,jdt,pde}/*/*/*.pom |
| 304 | do |
| 305 | updateCheckSums ${pom} |
| 306 | done |
| 307 | |
Stephan Herrmann | 42f24c9 | 2016-12-31 16:53:10 +0100 | [diff] [blame] | 308 | echo "==== Add Javadoc Stubs ====" |
| 309 | |
| 310 | # (groupSimpleName, javadocArtifactGA) |
| 311 | function 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 Herrmann | 9fc05c9 | 2016-12-31 17:35:26 +0100 | [diff] [blame^] | 319 | 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] | 320 | 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 | |
| 328 | createJavadocs platform org.eclipse.platform:org.eclipse.platform.doc.isv |
| 329 | createJavadocs jdt org.eclipse.jdt:org.eclipse.jdt.doc.isv |
| 330 | createJavadocs pde org.eclipse.pde:org.eclipse.pde.doc.user |
Stephan Herrmann | ee73d53 | 2016-12-20 23:37:28 +0100 | [diff] [blame] | 331 | |
| 332 | echo "========== Repo completed =========" |
| 333 | |
| 334 | cd ${WORKSPACE} |