Skip to content

Commit

Permalink
Fix leftShift deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Silver committed Nov 28, 2016
1 parent a1aac1d commit 5cde870
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 105 deletions.
2 changes: 1 addition & 1 deletion 1.03-Demo-GroovyFundamentals/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ selecting View > Syntax > Open all with current extension as... > Groovy
*/

task groovy << {}
task groovy {}

println "Hello Groovy!"

Expand Down
2 changes: 1 addition & 1 deletion 1.04-Demo-GroovyClosuresAndObjects/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from the scope in which they're declared.
*/

task groovy << {}
task groovy {}

def foo = "One million dollars"
def myClosure = {
Expand Down
69 changes: 41 additions & 28 deletions 1.05-Exercise-ExperimentWithGroovy/build.gradle
Original file line number Diff line number Diff line change
@@ -1,50 +1,63 @@
/*
In these exercises we'll explore the Groovy features most relevant to Gradle
build scripts. Each topic will be contained in the action of a Gradle task, so
to test run your code you'll need to run that particular task. If you get
stuck, check out the solution.gradle file in this directory.
Welcome to the solutions to the Groovy Playground exercise! You can run these
tasks by telling Gradle to use this build script, instead of the default
build.gradle. To run the task below, use:
$ gradle -b solution.gradle stringsAndTypes
or, more compactly
$ gradle -b solution.gradle sAT
*/

task stringsAndTypes << {
// TODO: Run `$ gradle sAT`
println "Nice work abbreviating the task name"
task stringsAndTypes {
doLast {
// TODO: Run `$ gradle sAT`
println "Nice work abbreviating the task name"

// TODO: Create a variable named foo and assign it the value 4.2

// TODO: Create a variable named foo and assign it the value 4.2
// TODO: Print the value and class of foo

// TODO: Print the value and class of foo
// TODO: Use string interpolation to print the square root of 127
// HINT: http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html

// TODO: Use string interpolation to print the square root of 127
// HINT: http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html
// TODO: Assign the current date to foo and print it, along with its type
// HINT:
// http://docs.oracle.com/javase/7/docs/api/java/util/package-summary.html

// TODO: Assign the current date to foo and print it, along with its type
// HINT:
// http://docs.oracle.com/javase/7/docs/api/java/util/package-summary.html

// TODO: Use the `substring` method to extract my name from this string
def hello = "Hello, Jeremy.";
// TODO: Use the `substring` method to extract my name from this string
def hello = "Hello, Jeremy."

// TODO: Use `toUpperCase` to capitalize and print my name
// TODO: Use `toUpperCase` to capitalize and print my name

}
}

task closures << {
// TODO: Declare a closure that takes two arguments and adds them together
// HINT: http://www.groovy-lang.org/closures.html

// TODO: Call your closure with arguments 17 and 25, and print the result
// Beware that something like `println addTwo 17, 25` is ambiguous
task closures {
doLast {
// TODO: Declare a closure that takes two arguments and adds them together
// HINT: http://www.groovy-lang.org/closures.html

// TODO: Call your closure with arguments 17 and 25, and print the result
// Beware that something like `println addTwo 17, 25` is ambiguous

}
}

task lists << {
// TODO: Declare a list containing 5 of your favorite candies
// HINT: Try searching for "groovy list literal"
task lists {
doLast {
// TODO: Declare a list containing 5 of your favorite candies
// HINT: Try searching for "groovy list literal"

// TODO: Create a new list of your candies in all caps
// HINT: http://mrhaki.blogspot.ca/2010/05/groovy-goodness-use-collect-with.html
// TODO: Create a new list of your candies in all caps
// HINT: http://mrhaki.blogspot.ca/2010/05/groovy-goodness-use-collect-with.html

// TODO: Print each capital candy
// TODO: Print each capital candy

}
}
86 changes: 47 additions & 39 deletions 1.05-Exercise-ExperimentWithGroovy/solution.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,61 +12,69 @@ or, more compactly
*/

task stringsAndTypes << {
// TODO: Run `$ gradle sAT`
println "Nice work abbreviating the task name"
task stringsAndTypes {
doLast {
// TODO: Run `$ gradle sAT`
println "Nice work abbreviating the task name"

// TODO: Create a variable named foo and assign it the value 4.2
def foo = 4.2
// TODO: Create a variable named foo and assign it the value 4.2
def foo = 4.2

// TODO: Print the value and class of foo
println "foo is of type: ${foo.class} and has value: $foo"
// TODO: Print the value and class of foo
println "foo is of type: ${foo.class} and has value: $foo"

// TODO: Use string interpolation to print the square root of 127
// HINT: http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html
println "The square root of 127 is ${Math.sqrt(127)}"
// TODO: Use string interpolation to print the square root of 127
// HINT: http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html
println "The square root of 127 is ${Math.sqrt(127)}"

// TODO: Assign the current date to foo and print it, along with its type
// HINT:
// http://docs.oracle.com/javase/7/docs/api/java/util/package-summary.html
foo = new java.util.Date()
println "foo is now of type: ${foo.class} and has value: $foo"
// TODO: Assign the current date to foo and print it, along with its type
// HINT:
// http://docs.oracle.com/javase/7/docs/api/java/util/package-summary.html
foo = new java.util.Date()
println "foo is now of type: ${foo.class} and has value: $foo"


// TODO: Use the `substring` method to extract my name from this string
def hello = "Hello, Jeremy."
def name = hello.substring(7, 13)
// TODO: Use the `substring` method to extract my name from this string
def hello = "Hello, Jeremy."
def name = hello.substring(7, 13)

// TODO: Use `toUpperCase` to capitalize and print my name
println name.toUpperCase()
// TODO: Use `toUpperCase` to capitalize and print my name
println name.toUpperCase()
}
}


task closures << {
// TODO: Declare a closure that takes two arguments and adds them together
// HINT: http://www.groovy-lang.org/closures.html
def addTwo = {x, y -> x + y}
task closures {
doLast {
// TODO: Declare a closure that takes two arguments and adds them together
// HINT: http://www.groovy-lang.org/closures.html
def addTwo = {x, y -> x + y}

// TODO: Call your closure with arguments 17 and 25, and print the result
// Beware that something like `println addTwo 17, 25` is ambiguous
println addTwo(17,25)
// TODO: Call your closure with arguments 17 and 25, and print the result
// Beware that something like `println addTwo 17, 25` is ambiguous
println addTwo(17,25)
}
}

task lists << {
// TODO: Declare a list containing 5 of your favorite candies
// HINT: Try searching for "groovy list literal"
def candyList = ["Tomatoes","Carrots","Spinach","Radishes","Beef"]
task lists {
doLast {
// TODO: Declare a list containing 5 of your favorite candies
// HINT: Try searching for "groovy list literal"
def candyList = ["Tomatoes","Carrots","Spinach","Radishes","Beef"]

// TODO: Create a new list of your candies in all caps
// HINT: http://mrhaki.blogspot.ca/2010/05/groovy-goodness-use-collect-with.html
def capitalCandies = candyList.collect{it.toUpperCase()}
// TODO: Create a new list of your candies in all caps
// HINT: http://mrhaki.blogspot.ca/2010/05/groovy-goodness-use-collect-with.html
def capitalCandies = candyList.collect{it.toUpperCase()}

// TODO: Print each capital candy
capitalCandies.each{println it}
// TODO: Print each capital candy
capitalCandies.each{println it}
}
}

task foobar << {
def foo = "bar"
println "$foo + foo equals ${foo + 'foo'}"
task foobar {
doLast {
def foo = "bar"
println "$foo + foo equals ${foo + 'foo'}"
}
}

26 changes: 4 additions & 22 deletions 1.06-Demo-TaskConfiguration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,6 @@ myTask4.doFirst {println "Do this first"}

/*
We can also add actions using the `leftShift` operator.
*/

myTask4.leftShift {println "Do this even more last"}
myTask4 << {println "Do this last of all"}

/*
We can also declare a task and give it an action in a single stroke. This is a
very common pattern.
*/

task myTask5 << {
println "Here's how to declare a task and give it an action in one stroke"
}

/*
Instead of declaring a task and then setting its properties afterwards, we can
also give the task a configuration closure when it's declared.
Expand Down Expand Up @@ -140,8 +120,10 @@ using the following syntax:
*/

task myTask8(description: "Another description") << {
println "Doing something"
task myTask8(description: "Another description") {
doLast {
println "Doing something"
}
}

/*
Expand Down
6 changes: 4 additions & 2 deletions 1.13-Demo-ParameterisingYourBuild/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ Let's create a task that prints a greeting.
*/

task printGreeting << {
println greeting
task printGreeting {
doLast {
println greeting
}
}

/* If we just run that as is, we get the following error:
Expand Down
6 changes: 4 additions & 2 deletions 2.06-Exercise-DeclareARepositoryAndDependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ http://search.maven.org/

apply plugin: 'java'

task printDependencies << {
configurations.compile.each { println it.name }
task printDependencies {
doLast {
configurations.compile.each { println it.name }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies {
compile fileTree(dir: 'libs', include: '*.jar') // 3. Add 'lib' directory
}

task printDependencies << {
configurations.compile.each { println it.name }
task printDependencies {
doLast {
configurations.compile.each { println it.name }
}
}
2 changes: 1 addition & 1 deletion 2.13-Exercise-ConfigureTheGradleWrapper/solution.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-2.4-20150406220025+0000-bin.zip
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-3.3-20161128000019+0000-bin.zip
*/
18 changes: 11 additions & 7 deletions 3.01-Demo-ImportingGradleProjects/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ or build anything, it just tells a joke.
*/

task tellJoke << {
println "What's a build master's favorite black metal band?"
println "Gradle of Filth!"
task tellJoke {
doLast {
println "What's a build master's favorite black metal band?"
println "Gradle of Filth!"
}
}

/*
Expand Down Expand Up @@ -50,10 +52,12 @@ Let's try adding a second task to our project.
*/

//task tellAnotherJoke <<{
// println "How long does it take to master build tools?"
// println "From the Gradle to the grave."
//}
// task tellAnotherJoke {
// doLast {
// println "How long does it take to master build tools?"
// println "From the Gradle to the grave."
// }
// }

/*
Expand Down

0 comments on commit 5cde870

Please sign in to comment.