diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b75231e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/gradle/ +/gradlew +/gradlew.bat +.gradle/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..90c8c45 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +dist: trusty +language: java +install: true +script: + # test once without and with wrapper present + - gradle noWrapper + - gradle clean test + - gradle wrapper + - gradle clean test + diff --git a/bin/gw b/bin/gw index 4e552ea..0d5c443 100755 --- a/bin/gw +++ b/bin/gw @@ -56,10 +56,7 @@ execute_gradle() { local gradle=$(select_gradle "${working_dir}") local build_args=( ${BUILD_ARG} "$@" ) - if [[ -n "${build_gradle}" ]]; then - # We got a good build file, start gradlew there. - cd "$(dirname "${build_gradle}")" - else + if [[ -z "${build_gradle}" ]]; then err "Unable to find a gradle build file named ${GRADLE_BUILDFILE}." fi diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..e20ef23 --- /dev/null +++ b/build.gradle @@ -0,0 +1,22 @@ +plugins { + id 'java' +} + +task wrapper(type: Wrapper) { + gradleVersion = '4.3.1' +} + +task noWrapper() { + doLast { + delete 'gradle' + delete 'gradlew' + delete 'gradlew.bat' + } +} + +task testProjectWithSubproject(type: Exec) { + workingDir 'test/project-with-subproject' + commandLine './test.sh' +} + +test.dependsOn 'testProjectWithSubproject' diff --git a/test/project-with-subproject/build.gradle b/test/project-with-subproject/build.gradle new file mode 100644 index 0000000..f9cf58e --- /dev/null +++ b/test/project-with-subproject/build.gradle @@ -0,0 +1,13 @@ +task speak { + doLast { + println 'rootProjectSpeak' + } +} + +configure(subprojects.findAll {it.name == 'subproject'}) { + task speak { + doLast { + println 'subprojectSpeak' + } + } +} diff --git a/test/project-with-subproject/settings.gradle b/test/project-with-subproject/settings.gradle new file mode 100644 index 0000000..d76027c --- /dev/null +++ b/test/project-with-subproject/settings.gradle @@ -0,0 +1 @@ +include 'subproject' diff --git a/test/project-with-subproject/subproject/.gitignore b/test/project-with-subproject/subproject/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/test/project-with-subproject/test.sh b/test/project-with-subproject/test.sh new file mode 100755 index 0000000..d6b435f --- /dev/null +++ b/test/project-with-subproject/test.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +GW=${PWD}/../../bin/gw +GRADLEW=${PWD}/../../gradlew +GRADLE="gradle" + +if [ -x ${GRADLEW} ]; then +# gradlew from rootProject should find both speeches +gradlewSpeakInRootProject=$(${GRADLEW} speak) +echo $gradlewSpeakInRootProject | grep "rootProjectSpeak" || \ + { echo "FAILED: gradlew failed to find rootProjectSpeak running from rootProject";exit 1; } +echo $gradlewSpeakInRootProject | grep "subprojectSpeak" || \ + { echo "FAILED: gradlew failed to find subprojectSpeak running from rootProject";exit 1; } +fi + +# gradle from rootProject should find both speeches +gradleSpeakInRootProject=$(${GRADLE} speak) +echo $gradleSpeakInRootProject | grep "rootProjectSpeak" || \ + { echo "FAILED: gradlew failed to find rootProjectSpeak running from rootProject";exit 1; } +echo $gradleSpeakInRootProject | grep "subprojectSpeak" || \ + { echo "FAILED: gradlew failed to find subprojectSpeak running from rootProject";exit 1; } + +# gw from rootProject should find both speeches +gwSpeakInRootProject=$(${GW} speak) +echo $gwSpeakInRootProject | grep "rootProjectSpeak" || \ + { echo "FAILED: gw failed to find rootProjectSpeak running from rootProject";exit 1; } +echo $gwSpeakInRootProject | grep "subprojectSpeak" || \ + { echo "FAILED: gw failed to find subprojectSpeak running from rootProject";exit 1; } + +# and again from subproject +cd subproject + +if [ -x ${GRADLEW} ]; then +# gradlew from subproject should find only subproject speeches +gradlewSpeakInSubproject=$(${GRADLEW} speak) +echo $gradlewSpeakInSubproject | grep "rootProjectSpeak" && \ + { echo "FAILED: gradlew found rootProjectSpeak running from subproject";exit 1; } +echo $gradlewSpeakInSubproject | grep "subprojectSpeak" || \ + { echo "FAILED: gradlew failed to find subprojectSpeak running from subproject";exit 1; } +fi + +# gradle from subproject won't find rootProject speeches +gradleSpeakInSubproject=$(${GRADLE} speak) +echo $gradleSpeakInSubproject | grep "rootProjectSpeak" && \ + { echo "FAILED: gradle found rootProjectSpeak running from subproject";exit 1; } + +# gw from subproject should find only subproject speeches +gwSpeakInSubproject=$(${GW} speak) +echo $gwSpeakInSubproject | grep "rootProjectSpeak" && \ + { echo "FAILED: gw found rootProjectSpeak running from subproject";exit 1; } +echo $gwSpeakInSubproject | grep "subprojectSpeak" || \ + { echo "FAILED: gw failed to find subprojectSpeak running from subproject";exit 1; }