forked from scala-ide/uber-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uber-build.sh
executable file
·1506 lines (1254 loc) · 37.9 KB
/
uber-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash -e
if [ -n "$DEBUG" ]
then
set -x
fi
# Initialize file descriptors. May be modified later.
exec 4>&1 6>&1 7>&1
#################################################################
# Unification script
#
# This script was created to support multiple test cases:
# * generating Scala IDE + plugins releases
# * being run during Scala PR validation
# * being run locally to reproduce Scala PR validation results
# * run every night to check the script itself
#
# Main features:
# * rebuilds and cache each piece as required
# * gets instructions from a 'config' file
##################################################################
# temp dir were all 'non-build' operation are performed
TMP_ROOT_DIR=$(mktemp -d -t uber-build.XXXX)
TMP_DIR="${TMP_ROOT_DIR}/tmp"
TMP_CACHE_DIR="${TMP_ROOT_DIR}/cacheLink"
mkdir "${TMP_DIR}"
# Timestamp used for logging and marking zip files
TIMESTAMP=`date '+%Y%m%d-%H%M'`
# dbuild needs a JOB_NAME and a NODE_NAME. Provide one if it is not set yet.
true ${JOB_NAME:=local}
true ${NODE_NAME:=local}
true ${BUILD_URL:=http://to.no.where/}
export JOB_NAME
export NODE_NAME
export BUILD_URL
# Load configuration variables
UBER_BUILD_DIR="$(cd "$(dirname "$0")" && pwd)"
source $UBER_BUILD_DIR/uber-build-config.sh
####################
# logging functions
####################
# Logging about step being performed
# $1 - title
function printStep () {
echo ">>>>> $1" >&6
}
# General logging
# $* - message
function info () {
echo ">> $*" >&6
}
# Debug logging for variable
# $1 - variable name
function debugValue () {
echo "----- $1=${!1}" >&4
}
# General debug logging
# $* - message
function debug () {
echo "----- $*" >&4
}
# General error logging
# $* - message
function error () {
echo "!!!!! $*" >&2
exit 3
}
# Error logging for wrong variable value
# $1 - variable name
# $2 - possible choices
function missingParameterChoice () {
echo "!!!!! Bad value for $1. Was '${!1}', should be one of: $2." >&2
exit 2
}
#########
# Checks
#########
# Check if the given parameters are defined
# $* - parameter names to check non-empty
function checkParameters () {
for i in $*
do
if [ -z "${!i}" ]
then
echo "!!!!! Bad value for $i. It should be defined." >&2
exit 2
fi
done
}
# Check if an artifact is available
# $1 - groupId
# $2 - artifacId
# $3 - version
# $4 - extra repository to look in (optional)
# return value is 0 if the artifact is available
function checkAvailability () {
cd "${TMP_DIR}"
rm -rf *
# pom file for the test project
cat > pom.xml << EOF
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.typesafe</groupId>
<artifactId>typesafeDummy</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Dummy</name>
<url>http://127.0.0.1</url>
<dependencies>
<dependency>
<groupId>$1</groupId>
<artifactId>$2</artifactId>
<version>$3</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>sonatype.snapshot</id>
<name>Sonatype maven snapshot repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
EOF
if [ -n "$4" ]
then
# adds the extra repository
cat >> pom.xml << EOF
<repository>
<id>extrarepo</id>
<name>extra repository</name>
<url>$4</url>
</repository>
EOF
fi
cat >> pom.xml << EOF
</repositories>
</project>
EOF
set +e
mvn "${MAVEN_ARGS[@]}" compile >&7 2>&7
RES=$?
set -e
# log the result
if [ ${RES} == 0 ]
then
debug "$1:$2:jar:$3 found !"
else
debug "$1:$2:jar:$3 not found !"
fi
return ${RES}
}
# Like check availability, but fail if not available.
# $1 - groupId
# $2 - artifactId
# $3 - version
# $4 - extra repository (optional)
function checkNeeded () {
if ! checkAvailability "$1" "$2" "$3" "$4"
then
error "$1:$2:jar:$3 is needed !!!"
fi
}
# Check if the given executable is in the PATH.
# $1 - executable
# return value is 0 if the executable was found.
function checkExecutableOnPath () {
BIN_LOCATION=$(which $1)
}
########################
# cache support
########################
# Check if a directory is available in the cache.
# $1 - cache id
# $2 - force cache usage ("true"|"false", optional)
# return values
# 0 - found
# 1 - not found
# 2 - caching disabled
function checkCache () {
FORCE_CACHE="${2:-false}"
if ${FORCE_CACHE} || ${WITH_CACHE}
then
if [ -d "${P2_CACHE_DIR}/$1" ]
then
debug "$1 found !"
return 0
else
debug "$1 not found !"
return 1
fi
else
debug "caching disabled"
return 2
fi
}
# Store a directory in the cache.
# $1 - cache id
# $2 - directory to cache
# $3 - force cache usage ("true"|"false", optional)
function storeCache () {
FORCE_CACHE="${3:-false}"
if ${FORCE_CACHE} || ${WITH_CACHE}
then
mkdir -p "$(dirname "${P2_CACHE_DIR}/$1")"
cp -r "$2" "${P2_CACHE_DIR}/$1"
debug "$1 cached !"
else
# only caching the original location
mkdir -p "${TMP_CACHE_DIR}/$1"
echo -n "$2" > "${TMP_CACHE_DIR}/$1/link"
fi
}
# Return the location in the file system of the cached p2 repo.
# $1 - p2 cache id
# $2 - force cache usage ("true"|"false", optional)
function getCacheLocation () {
FORCE_CACHE="${2:-false}"
if ${FORCE_CACHE} || ${WITH_CACHE}
then
echo "${P2_CACHE_DIR}/$1"
else
cat "${TMP_CACHE_DIR}/$1/link"
fi
}
# Return the location in the file system of the cached p2 repo.
# $1 - p2 cache id
# $2 - force cache usage ("true"|"false", optional)
function getCacheURL () {
FORCE_CACHE="${2:-false}"
if ${FORCE_CACHE} || ${WITH_CACHE}
then
FOLDER="${P2_CACHE_DIR}/$1"
else
FOLDER=$(cat "${TMP_CACHE_DIR}/$1/link")
fi
echo "file://${FOLDER/ /%20}"
}
# Merge a p2 repo into an other one.
# $1 - repository to merge
# $2 - location to merge it to
function mergeP2Repo () {
BUILD_TOOLS_DIR="${BUILD_DIR}/build-tools"
fetchGitBranch "$BUILD_TOOLS_DIR" "git://github.com/scala-ide/build-tools.git" master
cd "$BUILD_TOOLS_DIR/maven-tool/merge-site/"
mvn ${MAVEN_ARGS[@]} -Drepo.source="$1" -Drepo.dest="$2" package
}
############
# m2 + osgi
############
# Extract the osgi version form a META-INF/MANIFEST.MF file
# in the current directory.
function extractOsgiVersion () {
# used \r as an extra field separator, to avoid problem with Windows style new lines.
grep Bundle-Version META-INF/MANIFEST.MF | awk -F '[ \r]' '{printf $2;}'
}
# Extract the osgi version from the MANIFEST.MF file
# of an artifact available in the local m2 repo.
# $1 - groupId
# $2 - artifactId
# $3 - version
function osgiVersion () {
cd "${TMP_DIR}"
rm -rf *
unzip -q "${LOCAL_M2_REPO}/${1//\.//}/$2/$3/$2-$3.jar"
extractOsgiVersion
}
# Extract the osgi version from the MANIFEST.MF file of a jar.
# $1 - jar location
function osgiVersionFromJar () {
cd "${TMP_DIR}"
rm -rf *
unzip -q "$1" "META-INF/MANIFEST.MF"
extractOsgiVersion
}
##############
# GIT support
##############
# Checkout the given branch. Clone and fetch the remote repo as needed.
# $1 - local dir
# $2 - remote repo
# $3 - branch, tag or hash
# $4 - depth (TODO: really needed?)
# $5 - extra fetch (optional)
function fetchGitBranch () {
if [ ! -d "$1/.git" ]
then
info "Cloning git repo $2"
REMOTE_ID="remote01"
rm -rf "$1"
git clone -o ${REMOTE_ID} "$2" "$1"
cd "$1"
else
cd "$1"
# check if the remote repo is already defined
REMOTE_ID=$(git config --get-regexp 'remote\..*\.url' | grep "$2" | awk -F '.' '{print $2;}')
if [ -z "${REMOTE_ID}" ]
then
info "Adding remote git repo $2"
LAST_REMOTE_ID=$(git config --get-regexp 'remote\.remote..\.url' | awk -F '.' '{print $2;}' | sort | tail -1)
NEW_INDEX=$(( ${LAST_REMOTE_ID:6} + 1 ))
REMOTE_ID="remote"$(printf '%02d' ${NEW_INDEX})
git remote add ${REMOTE_ID} $2
fi
info "Fetching update for $2"
git fetch --tag ${REMOTE_ID}
git fetch ${REMOTE_ID}
fi
# add extra fetch config if needed
if [ -n "$5" ]
then
FETCH_STRING="+refs/pull/*/head:refs/remotes/${REMOTE_ID}/$5/*"
if git config --get-all "remote.${REMOTE_ID}.fetch" | grep -Fc "${FETCH_STRING}"
then
:
else
info "Add extra fetch config"
git config --add "remote.${REMOTE_ID}.fetch" ${FETCH_STRING}
git fetch ${REMOTE_ID}
fi
fi
info "Checking out $3"
IS_A_REMOTE_BRANCH=$(git branch -r | grep -q " ${REMOTE_ID}/$3\$"; echo $?)
if [ $IS_A_REMOTE_BRANCH == 0 ]
then
# it is a known remote branch
git checkout -f -q ${REMOTE_ID}/$3
else
# assumes it is a tag or a hash
git checkout -f -q $3
fi
git clean -d -f -q
}
##################
##################
# The build steps
##################
##################
##################
# Check arguments
##################
# $1 - error message
function printErrorUsageAndExit () {
echo "$1" >&2
echo "Usage:" >&2
echo " $0 <config_file> [scala_git_hash]" >&2
exit 1
}
# $* - arguments
function stepCheckArguments () {
printStep "Check arguments"
if [ $# -gt 3 ]
then
printErrorUsageAndExit "Wrong arguments"
fi
CONFIG_FILE="$1"
ARG_GIT_HASH=$2
ARG_SCALA_VERSION=$3
if [ ! -f "${CONFIG_FILE}" ]
then
printErrorUsageAndExit "'${CONFIG_FILE}' doesn't exists or is not a file"
fi
}
####################
# Build parameters
####################
function stepLoadConfig () {
printStep "Load config: ${CONFIG_FILE}"
# set the working folders
CURRENT_DIR=$(pwd)
SCRIPT_DIR=$(cd "$( dirname "$0" )" && pwd)
# load the default parameters
. "${SCRIPT_DIR}/config/default.conf"
# load the config
. "${CONFIG_FILE}"
# override the git hash with the one given as argument, if available
if [ -n "${ARG_GIT_HASH}" ]
then
SCALA_GIT_HASH="${ARG_GIT_HASH}"
fi
# override the Scala version with the one given as argument, if available
if [ -n "${ARG_SCALA_VERSION}" ]
then
SCALA_VERSION="${ARG_SCALA_VERSION}"
fi
# needed to ensure that SBT only relies on local directories
export JAVA_TOOL_OPTIONS="-Divy.home=$LOCAL_IVY_REPO -Dsbt.ivy.home=$LOCAL_IVY_REPO -Dsbt.dir=$LOCAL_IVY_REPO/global -Dsbt.global.base=$LOCAL_IVY_REPO/global"
}
################
# Setup logging
################
function stepSetupLogging () {
printStep "Setup logging"
if [ -z "${DEBUG}" ]
# enable in file logging only if not in debug mode
then
mkdir -p "${BUILD_DIR}"
# 1 - command standard output
# 2 - command error output
# 3 - log file
# 4 - renamed general standard output
# 5 - renamed general standard error
# 6 - fd always pushed to general standard output
# 7 - extra log file
case "${LOGGING}" in
file )
LOG_FILE="${BUILD_DIR}/log-${TIMESTAMP}.txt"
> "${LOG_FILE}"
rm -rf "${BUILD_DIR}/log.txt"
ln -s "${LOG_FILE}" "${BUILD_DIR}/log.txt"
exec 3>> "${LOG_FILE}" 4>&1 5>&2 6>&1
exec 1>&3 2> >(tee -a /dev/fd/3 >&5) 6> >(tee -a /dev/fd/3 >&4)
;;
console)
;;
* )
missingParameterChoice "LOGGING" "file, console"
;;
esac
exec 7> "${BUILD_DIR}/log-extra.txt"
echo "############################################################" >&7
echo "#### Log file containing usually non-interesting output ####" >&7
echo "#### look for '>&7' in uber-build.sh ####" >&7
echo "############################################################" >&7
echo "" >&7
fi
}
############
# Set flags
############
function stepSetFlags () {
printStep "Set flags"
# the flags
RELEASE=false
DRY_RUN=true
IDE_BUILD=false
SCALA_RELEASE=false
SCALA_VALIDATOR=false
SCALA_REBUILD=false
SIGN_ARTIFACTS=false
WORKSHEET_PLUGIN=false
PLAY_PLUGIN=false
SEARCH_PLUGIN=false
SCALATEST_PLUGIN=false
LAGOM_PLUGIN=false
PUBLISH=false
# set in during check configuration
USE_SCALA_VERSIONS_PROPERTIES_FILE=false
# Check what to do
case "${OPERATION}" in
release )
RELEASE=true
DRY_RUN=false
IDE_BUILD=true
SIGN_ARTIFACTS=true
;;
release-dryrun )
RELEASE=true
DRY_RUN=true
IDE_BUILD=true
SIGN_ARTIFACTS=true
;;
nightly )
RELEASE=true
DRY_RUN=true
IDE_BUILD=true
;;
scala-pr-validator )
SCALA_VALIDATOR=true
SCALA_REBUILD=false
IDE_BUILD=true
;;
scala-pr-rebuild )
SCALA_VALIDATOR=true
SCALA_REBUILD=true
IDE_BUILD=true
;;
scala-local-build )
SCALA_REBUILD=true
IDE_BUILD=true
;;
* )
missingParameterChoice "OPERATION" "release, release-dryrun, nightly, scala-pr-validator, scala-pr-rebuild, scala-local-build"
;;
esac
# Check the plugins to build.
for PLUGIN in ${PLUGINS}
do
case "${PLUGIN}" in
worksheet )
WORKSHEET_PLUGIN=true
;;
play )
PLAY_PLUGIN=true
;;
search )
SEARCH_PLUGIN=true
;;
scalatest )
SCALATEST_PLUGIN=true
;;
lagom )
LAGOM_PLUGIN=true
;;
* )
error "Unknown value in PLUGINS. Should be one of: worksheet play search scalatest lagom."
esac
done
if ${RELEASE}
then
# Check the type of release.
case "${BUILD_TYPE}" in
dev | stable )
if ${DRY_RUN}
then
PUBLISH=false
else
PUBLISH=true
fi
;;
* )
missingParameterChoice "PUBLISH" "dev, stable"
;;
esac
fi
# Check the cache flag
case "${WITH_CACHE}" in
true | false )
;;
* )
missingParameterChoice "WITH_CACHE" "true, false"
;;
esac
}
#################
# Pre-requisites
#################
function stepCheckPrerequisites () {
printStep "Check prerequisites"
# ant is need to rebuild Scala
if ${SCALA_REBUILD}
then
if [ -n "${ANT}" ]
then
if [ -x "${ANT}" ]
then
ANT_BIN="${ANT}"
else
error "The variable ANT is set, but doesn't point to an executable."
fi
else
if ! checkExecutableOnPath "ant"
then
error "To be able to rebuild a special version of Scala, 'ant' should be in the PATH, or the variable ANT should be set"
else
ANT_BIN=$(which ant)
fi
fi
fi
# eclipse and keytool are needed to sign the jars
if ${SIGN_ARTIFACTS}
then
if ! checkExecutableOnPath "keytool"
then
error "'keytool' is required on PATH to sign the jars"
fi
if [ -n "${ECLIPSE}" ]
then
if [ -x "${ECLIPSE}" ]
then
export ECLIPSE="${ECLIPSE}"
else
error "The variable ECLIPSE is set, but doesn't point to an executable."
fi
else
if ! checkExecutableOnPath "eclipse"
then
error "to sign the jars, 'eclipse' should be in the PATH, or the variable ECLIPSE should be set."
else
export ECLIPSE=$(which eclipse)
fi
fi
fi
# maven is used in most of the phases
if ! checkExecutableOnPath "mvn"
then
error "'mvn' is required on PATH for any build."
fi
# Check if aws tools are installed
if ${PUBLISH}
then
if [ ! -e "$AWS" ]
then
error "AWS tools could not be found but are needed for the publish step. Install them first by running the 'install-aws.sh' script!"
fi
fi
}
######################
# Check configuration
######################
# Checks that all needed parameters are correctly defined.
function stepCheckConfiguration () {
printStep "Check configuration"
if echo "${BUILD_DIR}" | grep -c ' '
then
error "BUILD_DIR contains space characters. This is not correctly supported by some of the builds. Please set BUILD_DIR to a different location: '${BUILD_DIR}'."
fi
checkParameters "SCRIPT_DIR" "BUILD_DIR" "LOCAL_M2_REPO" "P2_CACHE_DIR"
# configure maven here. Needed for some checks
# preserve MAVEN_ARGS coming in from outside
MAVEN_ARGS=(${MAVEN_ARGS} -e -B -U "-Dmaven.repo.local=${LOCAL_M2_REPO}")
mkdir -p "${BUILD_DIR}"
checkParameters "SCALA_VERSION"
if ${SCALA_REBUILD}
then
checkParameters "SCALA_GIT_REPO" "SCALA_GIT_HASH" "SCALA_DIR"
fi
if ${IDE_BUILD}
then
checkParameters "ECLIPSE_PLATFORM"
checkParameters "SCALA_IDE_DIR" "SCALA_IDE_GIT_REPO" "SCALA_IDE_GIT_BRANCH" "SCALA_IDE_VERSION_TAG"
fi
if ${WORKSHEET_PLUGIN}
then
checkParameters "WORKSHEET_PLUGIN_DIR" "WORKSHEET_PLUGIN_GIT_REPO" "WORKSHEET_PLUGIN_GIT_BRANCH" "WORKSHEET_PLUGIN_VERSION_TAG"
fi
if ${PLAY_PLUGIN}
then
checkParameters "PLAY_PLUGIN_DIR" "PLAY_PLUGIN_GIT_REPO" "PLAY_PLUGIN_GIT_BRANCH" "PLAY_PLUGIN_VERSION_TAG"
fi
if ${LAGOM_PLUGIN}
then
checkParameters "LAGOM_PLUGIN_DIR" "LAGOM_PLUGIN_GIT_REPO" "LAGOM_PLUGIN_GIT_BRANCH" "LAGOM_PLUGIN_VERSION_TAG"
fi
if ${SEARCH_PLUGIN}
then
checkParameters "SEARCH_PLUGIN_DIR" "SEARCH_PLUGIN_GIT_REPO" "SEARCH_PLUGIN_GIT_BRANCH" "SEARCH_PLUGIN_VERSION_TAG"
fi
if ${SCALATEST_PLUGIN}
then
checkParameters "SCALATEST_PLUGIN_P2_REPO" "SCALATEST_PLUGIN_VERSION"
fi
if ${PRODUCT}
then
checkParameters "PRODUCT_DIR" "PRODUCT_GIT_REPO" "PRODUCT_GIT_BRANCH" "PRODUCT_VERSION_TAG"
fi
if ${SIGN_ARTIFACTS}
then
checkParameters "KEYSTORE_DIR" "KEYSTORE_PASS"
# clone the keystore repo. Needed to check if the pass is fine.
if [ ! -d "${KEYSTORE_DIR}" ]
then
checkParameters "KEYSTORE_GIT_REPO"
fetchGitBranch "${KEYSTORE_DIR}" "${KEYSTORE_GIT_REPO}" master
fi
cd "$KEYSTORE_DIR"
keytool -list -keystore "${KEYSTORE_DIR}/typesafe.keystore" -storepass "${KEYSTORE_PASS}" -alias typesafe
MAVEN_SIGN_ARGS=("-Djarsigner.storepass=${KEYSTORE_PASS}" -Djarsigner.keypass=${KEYSTORE_PASS} -Djarsigner.keystore=${KEYSTORE_DIR}/typesafe.keystore)
fi
# set extra variables. There are different ways to reference the Scala and Eclipse versions.
SCALA_210_OR_LATER=false
SCALA_211_OR_LATER=false
SCALA_212_OR_LATER=false
case "${SCALA_VERSION}" in
2.10.* )
SCALA_PROFILE="scala-2.10.x"
ECOSYSTEM_SCALA_VERSION="scala210"
SHORT_SCALA_VERSION="2.10"
USE_SCALA_VERSIONS_PROPERTIES_FILE=false
SCALA_210_OR_LATER=true
;;
2.11.* )
SCALA_PROFILE="scala-2.11.x"
ECOSYSTEM_SCALA_VERSION="scala211"
SHORT_SCALA_VERSION="2.11"
USE_SCALA_VERSIONS_PROPERTIES_FILE=true
SCALA_210_OR_LATER=true
SCALA_211_OR_LATER=true
;;
2.12.* )
SCALA_PROFILE="scala-2.12.x"
ECOSYSTEM_SCALA_VERSION="scala212"
SHORT_SCALA_VERSION="2.12"
USE_SCALA_VERSIONS_PROPERTIES_FILE=true
SCALA_210_OR_LATER=true
SCALA_211_OR_LATER=true
SCALA_212_OR_LATER=true
;;
* )
error "Not supported version of Scala: ${SCALA_VERSION}."
;;
esac
if ${IDE_BUILD}
then
case "${ECLIPSE_PLATFORM}" in
indigo )
ECLIPSE_PROFILE="eclipse-indigo"
ECOSYSTEM_ECLIPSE_VERSION="e37"
;;
juno )
ECLIPSE_PROFILE="eclipse-juno"
ECOSYSTEM_ECLIPSE_VERSION="e38"
;;
kepler )
ECLIPSE_PROFILE="eclipse-kepler"
ECOSYSTEM_ECLIPSE_VERSION="e38"
;;
luna )
ECLIPSE_PROFILE="eclipse-luna"
ECOSYSTEM_ECLIPSE_VERSION="e44"
;;
neon )
ECLIPSE_PROFILE="eclipse-neon"
ECOSYSTEM_ECLIPSE_VERSION="e46"
;;
oxygen )
ECLIPSE_PROFILE="eclipse-oxygen"
ECOSYSTEM_ECLIPSE_VERSION="e47"
;;
* )
error "Not supported eclipse platform: ${ECLIPSE_PLATFORM}."
;;
esac
fi
}
########
# Scala
########
# Attempt to recreate the version.properties file from the data contained inside the pom of scala-library-all
# This will work only for released version of Scala
function extrapolateVersionPropertiesFile () {
info "Attempt to recreate the Scala version.properties file from maven data"
if ! checkCache ${SCALA_P2_ID} "true"
then
cd "${TMP_DIR}"
rm -rf *
local SCALA_LIBRARY_ALL_POM="scala-library-all.pom"
# get the pom file
set +e
wget -O "${SCALA_LIBRARY_ALL_POM}" "http://repo1.maven.org/maven2/org/scala-lang/scala-library-all/${FULL_SCALA_VERSION}/scala-library-all-${FULL_SCALA_VERSION}.pom"
RES=$?
set -e
if [ ${RES} != 0 ]
then
# this only work if a scala-library-all is available
error "unable to find the versions file at '${SCALA_VERSIONS_PROPERTIES_PATH}' and to recreate one for Scala '${FULL_SCALA_VERSION}'."
fi
local SCALA_LIBRARY_ALL_CLEANED="scala-library-cleaned.txt"
# extract the artifact ids and versions from the pom file
grep -A 1 artifactId scala-library-all.pom | grep -v -- '--' | sed '1~2 {N;s/\n//g}' | grep version | awk -F '[<>]' '{print $3" "$7;}' > "${SCALA_LIBRARY_ALL_CLEANED}"
# Returns the version number for the given artifact id from the previously generated list
# $1 artifact id
function extractVersionNumber () {
grep "$1" "${SCALA_LIBRARY_ALL_CLEANED}" | awk '{print $2;}'
}
# extract the version information needed
local PROPERTY_MAVEN_VERSION=$(extractVersionNumber "scala-library")
local PROPERTY_SCALA_XML_VERSION=$(extractVersionNumber "scala-xml")
local PROPERTY_PARSER_COMBINATORS_VERSION=$(extractVersionNumber "scala-parser-combinators")
local PROPERTY_CONTINUATION_VERSION=$(extractVersionNumber "scala-continuations-library")
local PROPERTY_SWING_VERSION=$(extractVersionNumber "scala-swing")
local PROPERTY_AKKA_VERSION=$(extractVersionNumber "akka-actor")
local PROPERTY_ACTOR_MIGRATION_VERSION=$(extractVersionNumber "scala-actors-migration")
# find the Scala binary version from the end of the scala-xml_xxx artifact id
local PROPERTY_SCALA_BINARY_VERSION=$(grep "scala-xml" "${SCALA_LIBRARY_ALL_CLEANED}" | awk -F '[_ ]' '{print $2;}')
# create the properties file
mkdir tmp
cat > "tmp/versions.properties" << EOF
maven.version.number=${PROPERTY_MAVEN_VERSION}
starr.version=${FULL_SCALA_VERSION}
scala.binary.version=${PROPERTY_SCALA_BINARY_VERSION}
scala.full.version=${FULL_SCALA_VERSION}
scala-xml.version.number=${PROPERTY_SCALA_XML_VERSION}
scala-parser-combinators.version.number=${PROPERTY_PARSER_COMBINATORS_VERSION}
scala-continuations-plugin.version.number=${PROPERTY_CONTINUATION_VERSION}
scala-continuations-library.version.number=${PROPERTY_CONTINUATION_VERSION}
scala-swing.version.number=${PROPERTY_SWING_VERSION}
akka-actor.version.number=${PROPERTY_AKKA_VERSION}
actors-migration.version.number=${PROPERTY_ACTOR_MIGRATION_VERSION}
EOF
# cache the generated file
storeCache "${SCALA_P2_ID}" tmp "true"
fi
# return the location
echo $(getCacheLocation ${SCALA_P2_ID} "true")/versions.properties
}
function stepScala () {
printStep "Scala"
if ${SCALA_VALIDATOR}
then
# for Scala pr validation, version.properties file is provided.
SCALA_VERSIONS_PROPERTIES_PATH=${CURRENT_DIR}/versions.properties
fi
if ${SCALA_REBUILD}
then
fetchGitBranch "${SCALA_DIR}" "${SCALA_GIT_REPO}" "${SCALA_GIT_HASH}" NaN "pr"
SCALA_UID=$(git rev-parse HEAD)
FULL_SCALA_VERSION="${SCALA_VERSION}-${SCALA_UID}-SNAPSHOT"
SCALA_VERSION_SUFFIX="-${SCALA_UID}-SNAPSHOT"
SCALA_P2_ID=scala/${SCALA_UID}
if checkAvailability "org.scala-lang" "scala-compiler" "${FULL_SCALA_VERSION}"
then
if ${USE_SCALA_VERSIONS_PROPERTIES_FILE}
then
if ! checkCache ${SCALA_P2_ID} "true"
then
error "Cannot find cached version of versions.properties for ${SCALA_P2_ID}"
fi
SCALA_VERSIONS_PROPERTIES_PATH=$(getCacheLocation ${SCALA_P2_ID} "true")/versions.properties
fi
else
info "Building Scala from source"
cd "${SCALA_DIR}"
# full clean
${ANT_BIN} -Divy.cache.ttl.default=eternal all.clean
git clean -fxd
if ${SCALA_211_OR_LATER}
then
${ANT_BIN} \
publish-local-opt \
-Darchives.skipxz=true \
-Dlocal.snapshot.repository="${LOCAL_M2_REPO}" \
-Dversion.suffix="${SCALA_VERSION_SUFFIX}"
else
# before 2.11.0
${ANT_BIN} \
distpack-maven-opt \
-Darchives.skipxz=true \
-Dlocal.snapshot.repository="${LOCAL_M2_REPO}" \
-Dversion.suffix="${SCALA_VERSION_SUFFIX}"
cd dists/maven/latest
${ANT_BIN} \
-Dlocal.snapshot.repository="${LOCAL_M2_REPO}" \
-Dmaven.version.suffix="-${SCALA_VERSION_SUFFIX}" \
deploy.local
fi
if ${USE_SCALA_VERSIONS_PROPERTIES_FILE}
then
# caching the versions file
cd "${TMP_DIR}"
rm -rf *
mkdir tmp
cp ${SCALA_DIR}/buildcharacter.properties tmp/versions.properties
storeCache ${SCALA_P2_ID} tmp "true"
SCALA_VERSIONS_PROPERTIES_PATH=$(getCacheLocation ${SCALA_P2_ID} "true")/versions.properties
fi
fi
else
# already existing Scala binaries are used.
FULL_SCALA_VERSION="${SCALA_VERSION}"
SCALA_P2_ID="scala/${FULL_SCALA_VERSION}"
fi
if ${USE_SCALA_VERSIONS_PROPERTIES_FILE} && [ -z "${SCALA_VERSIONS_PROPERTIES_PATH}" ]
then
# We need a versions.properties file, but none has been set yet
if ${RELEASE}
then
# for releases, against released version of Scala, we should be able to recreate the file
SCALA_VERSIONS_PROPERTIES_PATH=$(extrapolateVersionPropertiesFile)
fi
fi
checkNeeded "org.scala-lang" "scala-compiler" "${FULL_SCALA_VERSION}"
SCALA_UID=$(osgiVersion "org.scala-lang" "scala-compiler" "${FULL_SCALA_VERSION}")