|
| 1 | +# This is for forcibly stopping the job from a subshell (see test |
| 2 | +# below). |
| 3 | +trap "exit 1" TERM |
| 4 | +export TOP_PID=$$ |
| 5 | +set -e |
| 6 | + |
| 7 | +# Known problems : does not fare well with interrupted, partial |
| 8 | +# compilations. We should perhaps have a multi-dependency version |
| 9 | +# of do_i_have below |
| 10 | + |
| 11 | +LOGGINGDIR="$WORKSPACE/logs" |
| 12 | +mkdir -p $LOGGINGDIR |
| 13 | + |
| 14 | +unset SBT_HOME |
| 15 | +SBT_HOME="$WORKSPACE/.sbt" |
| 16 | +mkdir -p $SBT_HOME |
| 17 | +IVY_CACHE="$WORKSPACE/.ivy2" |
| 18 | +mkdir -p $IVY_CACHE |
| 19 | +rm -rf $IVY_CACHE/cache/org.scala-lang |
| 20 | + |
| 21 | +# temp dir where all 'non-build' operation are performed |
| 22 | +TMP_ROOT_DIR=$(mktemp -d -t pr-scala.XXXX) |
| 23 | +TMP_DIR="${TMP_ROOT_DIR}/tmp" |
| 24 | +mkdir "${TMP_DIR}" |
| 25 | + |
| 26 | + |
| 27 | +# detect sed version and how to enable extended regexes |
| 28 | +SEDARGS="-n$(if (echo "a" | sed -nE "s/a/b/" &> /dev/null); then echo E; else echo r; fi)" |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +# :docstring test: |
| 33 | +# Usage: test <argument ..> |
| 34 | +# Executes <argument ..>, logging the launch of the command to the |
| 35 | +# main log file, and kills global script execution with the TERM |
| 36 | +# signal if the commands ends up failing. |
| 37 | +# DO NOT USE ON FUNCTIONS THAT DECLARE VARIABLES, |
| 38 | +# AS YOU'LL BE RUNNING IN A SUBSHELL AND VARIABLE DECLARATIONS WILL BE LOST |
| 39 | +# :end docstring: |
| 40 | + |
| 41 | +function test() { |
| 42 | + echo "### $@" |
| 43 | + "$@" |
| 44 | + status=$? |
| 45 | + if [ $status -ne 0 ]; then |
| 46 | + say "### ERROR with $1" |
| 47 | + kill -s TERM $TOP_PID |
| 48 | + fi |
| 49 | +} |
| 50 | + |
| 51 | +# :docstring say: |
| 52 | +# Usage: say <argument ..> |
| 53 | +# Prints <argument ..> to both console and the main log file. |
| 54 | +# :end docstring: |
| 55 | + |
| 56 | +function say(){ |
| 57 | + (echo "$@") | tee -a $LOGGINGDIR/compilation-$SCALADATE-$SCALAHASH.log |
| 58 | +} |
| 59 | + |
| 60 | +# General debug logging |
| 61 | +# $* - message |
| 62 | +function debug () { |
| 63 | + echo "----- $*" |
| 64 | +} |
| 65 | + |
| 66 | +function parseScalaProperties(){ |
| 67 | + propFile="$baseDir/$1" |
| 68 | + if [ ! -f $propFile ]; then |
| 69 | + echo "Property file $propFile not found." |
| 70 | + exit 1 |
| 71 | + else |
| 72 | + awk -f "$scriptsDir/readproperties.awk" "$propFile" > "$propFile.sh" |
| 73 | + . "$propFile.sh" # yeah yeah, not that secure, improvements welcome (I tried, but bash made me cry again) |
| 74 | + fi |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | +## TAKEN FROM UBER-BUILD, except that it "returns" (via $RES) true/false |
| 79 | +# Check if an artifact is available |
| 80 | +# $1 - groupId |
| 81 | +# $2 - artifacId |
| 82 | +# $3 - version |
| 83 | +# $4 - extra repository to look in (optional) |
| 84 | +# return value in $RES |
| 85 | +function checkAvailability () { |
| 86 | + pushd "${TMP_DIR}" |
| 87 | + rm -rf * |
| 88 | + |
| 89 | +# pom file for the test project |
| 90 | + cat > pom.xml << EOF |
| 91 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| 92 | + <modelVersion>4.0.0</modelVersion> |
| 93 | + <groupId>com.typesafe</groupId> |
| 94 | + <artifactId>typesafeDummy</artifactId> |
| 95 | + <packaging>war</packaging> |
| 96 | + <version>1.0-SNAPSHOT</version> |
| 97 | + <name>Dummy</name> |
| 98 | + <url>http://127.0.0.1</url> |
| 99 | + <dependencies> |
| 100 | + <dependency> |
| 101 | + <groupId>$1</groupId> |
| 102 | + <artifactId>$2</artifactId> |
| 103 | + <version>$3</version> |
| 104 | + </dependency> |
| 105 | + </dependencies> |
| 106 | + <repositories> |
| 107 | + <repository> |
| 108 | + <id>sonatype.snapshot</id> |
| 109 | + <name>Sonatype maven snapshot repository</name> |
| 110 | + <url>https://oss.sonatype.org/content/repositories/snapshots</url> |
| 111 | + <snapshots> |
| 112 | + <updatePolicy>daily</updatePolicy> |
| 113 | + </snapshots> |
| 114 | + </repository> |
| 115 | +EOF |
| 116 | + |
| 117 | + if [ -n "$4" ] |
| 118 | + then |
| 119 | +# adds the extra repository |
| 120 | + cat >> pom.xml << EOF |
| 121 | + <repository> |
| 122 | + <id>extrarepo</id> |
| 123 | + <name>extra repository</name> |
| 124 | + <url>$4</url> |
| 125 | + </repository> |
| 126 | +EOF |
| 127 | + fi |
| 128 | + |
| 129 | + cat >> pom.xml << EOF |
| 130 | + </repositories> |
| 131 | +</project> |
| 132 | +EOF |
| 133 | + |
| 134 | + set +e |
| 135 | + mvn "${MAVEN_ARGS[@]}" compile &> "${TMP_DIR}/mvn.log" |
| 136 | + RES=$? |
| 137 | + # Quiet the maven, but allow diagnosing problems. |
| 138 | + grep -i downloading "${TMP_DIR}/mvn.log" |
| 139 | + grep -i exception "${TMP_DIR}/mvn.log" |
| 140 | + grep -i error "${TMP_DIR}/mvn.log" |
| 141 | + set -e |
| 142 | + |
| 143 | +# log the result |
| 144 | + if [ ${RES} == 0 ] |
| 145 | + then |
| 146 | + debug "$1:$2:jar:$3 found !" |
| 147 | + RES=true |
| 148 | + else |
| 149 | + debug "$1:$2:jar:$3 not found !" |
| 150 | + RES=false |
| 151 | + fi |
| 152 | + popd |
| 153 | +} |
0 commit comments