#!/bin/bash
set -ex
cd $(dirname $0)
MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
MVN="mvn --batch-mode -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
TEST_VERSION=`grep "^ <version>.*</version>" pom.xml | sed "s| <version>\(.*\)</version>|\1|"`
OLD_VERSION=$1
OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/$OLD_VERSION/protoc-$OLD_VERSION-linux-x86_64.exe
VERSION_NUMBER=`grep "^ <version>.*</version>" ../../pom.xml | sed "s| <version>\(.*\)</version>|\1|"`
echo "Running compatibility tests between current $VERSION_NUMBER and released $OLD_VERSION"
[ -f ../../../src/protoc ] || {
echo "[ERROR]: Please build protoc first."
exit 1
}
[ -f ../../core/target/protobuf-java-$VERSION_NUMBER.jar ] || {
pushd ../..
$MVN install -Dmaven.test.skip=true
popd
}
[ -d protobuf ] || {
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git reset --hard v$TEST_VERSION
cd ..
}
wget $OLD_VERSION_PROTOC -O protoc
chmod +x protoc
$MVN clean test \
-Dprotobuf.test.source.path=$(pwd)/protobuf \
-Dprotoc.path=$(pwd)/protoc \
-Dprotos.protoc.path=$(pwd)/../../../src/protoc \
-Dprotobuf.version=$VERSION_NUMBER
$MVN clean test \
-Dprotobuf.test.source.path=$(pwd)/protobuf \
-Dprotoc.path=$(pwd)/protoc \
-Dmore_protos.protoc.path=$(pwd)/../../../src/protoc \
-Dprotobuf.version=$VERSION_NUMBER
cd deps
$MVN assembly:single
cd ..
cp -f deps/target/compatibility-test-deps-${TEST_VERSION}-jar-with-dependencies.jar deps.jar
$MVN clean install -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/protoc -Dprotobuf.version=$OLD_VERSION
cp -f protos/target/compatibility-protos-${TEST_VERSION}.jar protos.jar
cp -f more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar more_protos.jar
cp -f tests/target/compatibility-tests-${TEST_VERSION}.jar tests.jar
TESTS=`find tests -name "*Test.java" | sed "s|/|.|g;s/.java$//g;s/tests.src.main.java.//g"`
cd protobuf
java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos.jar:../more_protos.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
cd ..
cd protos
$MVN clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
cd ..
cd protobuf
java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos/target/compatibility-protos-${TEST_VERSION}.jar:../more_protos.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
cd ..
cd more_protos
$MVN clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
cd ..
cd protobuf
java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos.jar:../more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
cd ..