@@ -23,8 +23,46 @@ SKIP_TESTS=false
2323if [ -z " $GOOGLE_APPLICATION_CREDENTIALS " ] ; then
2424 SKIP_TESTS=true
2525fi
26+
27+ # Finds the closest parent dir that encompasses all changed files, and has a
28+ # pom.xml
29+ travis_changed_files_parent () {
30+ [ -z " $TRAVIS_PULL_REQUEST " ] && return 0 # If we're not in a PR, forget it
31+
32+ (
33+ set +e
34+
35+ changed=" $( git diff --name-only " $TRAVIS_COMMIT " " $TRAVIS_BRANCH " ) "
36+ if [ $? -ne 0 ]; then
37+ # Fall back to git head
38+ changed=" $( git diff --name-only " $( git rev-parse HEAD) " " $TRAVIS_BRANCH " ) "
39+ [ $? -ne 0 ] && return 0 # Give up. Just run everything.
40+ fi
41+
42+ # Find the common prefix
43+ prefix=" $( echo " $changed " | sed -e ' N;s/^\(.*\).*\n\1.*$/\1\n\1/;D' ) "
44+
45+ while [ ! -z " $prefix " ] && [ ! -r " $prefix /pom.xml" ] && [ " ${prefix%/* } " != " $prefix " ]; do
46+ prefix=" ${prefix%/* } "
47+ done
48+
49+ [ -r " $prefix /pom.xml" ] || return 0
50+
51+ echo " $prefix "
52+ )
53+ }
54+
55+ git branch
56+ exit 1
57+ travis_changed_files_parent
58+ common_travis_dir=" $( travis_changed_files_parent) "
59+
60+ [ -z " $common_travis_dir " ] || pushd " $common_travis_dir "
61+
2662mvn --batch-mode clean verify -DskipTests=$SKIP_TESTS | egrep -v " (^\[INFO\] Download|^\[INFO\].*skipping)"
2763
64+ [ -z " $common_travis_dir " ] || popd
65+
2866# Check that all shell scripts in this repo (including this one) pass the
2967# Shell Check linter.
3068shellcheck ./** /* .sh
@@ -44,7 +82,9 @@ test_localhost() {
4482 appengine/datastore/indexes-perfect
4583 )
4684 for testdir in " ${devserver_tests[@]} " ; do
47- ./java-repo-tools/scripts/test-localhost.sh appengine " ${testdir} "
85+ if [ -z " $common_travis_dir " ] || [[ $testdir = $common_travis_dir * ]]; then
86+ ./java-repo-tools/scripts/test-localhost.sh appengine " ${testdir} "
87+ fi
4888 done
4989
5090 # newplugin_std_tests=(
0 commit comments