Table of Contents
Groovy 2 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
The Groovy language
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started with Groovy
Introduction
Installing Groovy on Windows
Getting ready
How to do it…
There's more...
Installing Groovy on Linux and OS X
How to do it...
How it works...
There's more...
See also
Executing Groovy code from the command line
How to do it...
How it works...
There's more...
See also
Using Groovy as a command-line text file editor
How to do it...
How it works...
There's more...
See also
Using Groovy to start a server on the command line
How to do it...
See also
Running Groovy with invokedynamic support
Getting ready
How to do it...
There's more...
See also
Building Groovy from source
Getting ready
How to do it...
How it works...
Managing multiple Groovy installations on Linux
Getting ready
How to do it...
How it works...
There's more...
See also
Using groovysh to try out Groovy commands
How to do it...
How it works...
There's more...
Starting groovyConsole to execute Groovy snippets
How to do it...
There's more...
Configuring Groovy in Eclipse
Getting ready
How to do it...
How it works...
There's more...
See also
Configuring Groovy in IntelliJ IDEA
Getting ready
How to do it...
There's more...
2. Using Groovy Ecosystem
Introduction
Using Java classes from Groovy
How to do it...
How it works...
There's more...
See also
Embedding Groovy into Java
Getting ready
How to do it...
How it works...
There's more...
See also
Compiling Groovy code
Getting ready
How to do it...
How it works...
See also
Simplifying dependency management with Grape
Getting ready
How to do it...
How it works...
There's more...
See also
Integrating Groovy into the build process using Ant
Getting ready
How to do it...
How it works...
There's more...
See also
Integrating Groovy into the build process using Maven
Getting ready
How to do it...
How it works...
There's more...
See also
Integrating Groovy into the build process using Gradle
Getting ready
How to do it...
How it works...
There's more...
See also
Generating documentation for Groovy code
Getting ready
How to do it...
How it works...
There's more...
See also
Checking Groovy code's quality with CodeNarc
Getting ready
How to do it...
How it works...
There's more...
See also
3. Using Groovy Language Features
Introduction
Searching strings with regular expressions
Getting ready
How to do it...
There's more...
See also
Writing less verbose Java Beans with Groovy Beans
Getting ready
How to do it...
How it works...
There's more...
Inheriting constructors in Groovy classes
How to do it...
How it works...
Adding the cloning functionality to Groovy Beans
How to do it...
How it works...
There's more...
Defining code as data in Groovy
Getting ready
How to do it...
There's more...
Defining data structures as code in Groovy
Getting ready
How to do it...
How it works...
See also
Implementing multiple inheritance in Groovy
Getting ready
How to do it...
How it works...
There's more...
See also
Adding a functionality to the existing Java/Groovy classes
Getting ready
How to do it...
How it works...
There's more...
See also
Defining type-checking rules for dynamic code
Getting ready
How to do it...
How it works...
There's more...
Adding automatic logging to Groovy classes
How to do it...
How it works...
There's more...
See also
4. Working with Files in Groovy
Introduction
Reading from a file
Getting ready
How to do it...
How it works...
There's more...
See also
Reading a text file line by line
Getting ready
How to do it...
There's more...
See also
Processing every word in a text file
Getting ready
How to do it...
How it works...
There's more...
See also
Writing to a file
Getting ready
How to do it...
How it works...
There's more...
See also
Replacing tabs with spaces in a text file
Getting ready
How to do it...
How it works...
There's more...
See also
Filtering a text file's content
Getting ready
How to do it...
How it works...
There's more...
See also
Deleting a file or directory
Getting ready
How to do it...
How it works...
There's more...
See also
Walking through a directory recursively
Getting ready
How to do it...
How it works...
There's more...
See also
Searching for files
Getting ready
How to do it...
How it works...
There's more...
See also
Changing file attributes on Windows
Getting ready
How to do it...
How it works...
There's more...
Reading data from a ZIP file
Getting ready
How to do it...
How it works...
There's more...
See also
Reading an Excel file
Getting ready
How to do it...
How it works...
See also
Extracting data from a PDF
Getting ready
How to do it...
How it works...
There's more...
See also
5. Working with XML in Groovy
Introduction
Reading XML using XmlSlurper
Getting ready
How to do it...
How it works...
See also
Reading XML using XmlParser
How...