Skip to content

Commit 7a5a96c

Browse files
committed
issue #195: script to change scala version in maven
1 parent b02a28a commit 7a5a96c

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ sudo: required
22
language: scala
33
jdk:
44
- openjdk8
5-
scala:
6-
- 2.11.2
75
install:
86
- wget http://download.redis.io/releases/redis-5.0.1.tar.gz
97
- tar -xzvf redis-5.0.1.tar.gz
108
- make -C redis-5.0.1 -j4
119
- export PATH=$PWD/redis-5.0.1/src:$PATH
12-
script: make test
10+
script:
11+
- make test # test with scala 2.11
12+
- sleep 5s # let redis exit gracefully (we use kill, not kill -9 in makefile)
13+
- ps aux | grep redis
14+
- ./dev/change-scala-version.sh 2.12 # switch to scala 2.12
15+
- make test # test with scala 2.12
1316
cache:
1417
directories:
1518
- $HOME/.m2

dev/change-scala-version.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
VALID_VERSIONS=( 2.11 2.12 )
6+
7+
SCALA_211_MINOR_VERSION="12"
8+
SCALA_212_MINOR_VERSION="9"
9+
10+
usage() {
11+
echo "Usage: $(basename $0) [-h|--help] <version>
12+
where :
13+
-h| --help Display this help text
14+
valid version values : ${VALID_VERSIONS[*]}
15+
" 1>&2
16+
exit 1
17+
}
18+
19+
if [[ ($# -ne 1) || ( $1 == "--help") || $1 == "-h" ]]; then
20+
usage
21+
fi
22+
23+
TO_MAJOR_VERSION=$1
24+
25+
check_scala_version() {
26+
for i in ${VALID_VERSIONS[*]}; do [ $i = "$1" ] && return 0; done
27+
echo "Invalid Scala version: $1. Valid versions: ${VALID_VERSIONS[*]}" 1>&2
28+
exit 1
29+
}
30+
31+
check_scala_version "$TO_MAJOR_VERSION"
32+
33+
if [ $TO_MAJOR_VERSION = "2.12" ]; then
34+
FROM_MAJOR_VERSION="2.11"
35+
FROM_MINOR_VERSION=$SCALA_211_MINOR_VERSION
36+
TO_MINOR_VERSION=$SCALA_212_MINOR_VERSION
37+
else
38+
FROM_MAJOR_VERSION="2.12"
39+
FROM_MINOR_VERSION=$SCALA_212_MINOR_VERSION
40+
TO_MINOR_VERSION=$SCALA_211_MINOR_VERSION
41+
fi
42+
43+
sed_i() {
44+
sed -e "$1" "$2" > "$2.tmp" && mv "$2.tmp" "$2"
45+
}
46+
47+
export -f sed_i
48+
49+
# change <artifactId>
50+
BASEDIR=$(dirname $0)/..
51+
find "$BASEDIR" -name 'pom.xml' -not -path '*target*' -print \
52+
-exec bash -c "sed_i 's/\(artifactId.*\)_'$FROM_MAJOR_VERSION'/\1_'$TO_MAJOR_VERSION'/g' {}" \;
53+
54+
# change <scala.major.version>
55+
find "$BASEDIR" -name 'pom.xml' -not -path '*target*' -print \
56+
-exec bash -c "sed_i 's/\(<scala.major.version>\)'$FROM_MAJOR_VERSION'/\1'$TO_MAJOR_VERSION'/g' {}" \;
57+
58+
# change <scala.complete.version>
59+
find "$BASEDIR" -name 'pom.xml' -not -path '*target*' -print \
60+
-exec bash -c "sed_i 's/\(<scala.complete.version>.*\.\)'$FROM_MINOR_VERSION'/\1'$TO_MINOR_VERSION'/g' {}" \;
61+

0 commit comments

Comments
 (0)