Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

gw: always execute from same dir that gradle or gradlew would (#22) #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/gradle/
/gradlew
/gradlew.bat
.gradle/
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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

5 changes: 1 addition & 4 deletions bin/gw
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
13 changes: 13 additions & 0 deletions test/project-with-subproject/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
task speak {
doLast {
println 'rootProjectSpeak'
}
}

configure(subprojects.findAll {it.name == 'subproject'}) {
task speak {
doLast {
println 'subprojectSpeak'
}
}
}
1 change: 1 addition & 0 deletions test/project-with-subproject/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include 'subproject'
Empty file.
52 changes: 52 additions & 0 deletions test/project-with-subproject/test.sh
Original file line number Diff line number Diff line change
@@ -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; }