├── .gitignore ├── LICENSE.txt ├── README.md ├── add_license.groovy ├── appB └── IntroGroovy │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ ├── main │ └── groovy │ │ ├── Precision.java │ │ ├── ast │ │ ├── delegate │ │ │ ├── phone_delegate.groovy │ │ │ └── string_delegate.groovy │ │ ├── singleton │ │ │ └── SingletonPoint.groovy │ │ └── tostring │ │ │ └── tostring_and_equals.groovy │ │ ├── builders │ │ ├── antbuilder.groovy │ │ ├── htmlBuilder.groovy │ │ ├── markupBuilder.groovy │ │ └── swingBuilder.groovy │ │ ├── closures │ │ ├── closures.groovy │ │ └── return_from_closure.groovy │ │ ├── collections │ │ ├── Circle.java │ │ ├── Shape.java │ │ ├── SortingLists.java │ │ ├── WordCountGroovy.groovy │ │ ├── lists.groovy │ │ ├── maps.groovy │ │ ├── passage.txt │ │ └── ranges.groovy │ │ ├── conditionals │ │ ├── conditionals.groovy │ │ └── loops.groovy │ │ ├── db │ │ ├── ManageProducts.java │ │ ├── Product.java │ │ ├── products.groovy │ │ └── products2xml.groovy │ │ ├── groovystrings │ │ └── strings.groovy │ │ ├── hello_world.groovy │ │ ├── intro │ │ ├── hello_world.groovy │ │ └── numbers.groovy │ │ ├── io │ │ ├── SumNumbers.java │ │ ├── data.txt │ │ ├── files.groovy │ │ ├── sum_numbers.groovy │ │ └── sum_numbers_loop.groovy │ │ ├── json │ │ └── chuck_norris.groovy │ │ ├── metaprogramming │ │ ├── CustomLevel.groovy │ │ ├── complex_numbers.groovy │ │ ├── currency_category.groovy │ │ ├── expando_demo.groovy │ │ ├── print_currency.groovy │ │ ├── use_emc.groovy │ │ ├── use_slang_category.groovy │ │ └── without_custom_levels.groovy │ │ ├── oop │ │ ├── Circle.groovy │ │ ├── Person.groovy │ │ ├── use_circle.groovy │ │ └── use_person.groovy │ │ ├── precision_groovy.groovy │ │ ├── regex │ │ └── regular_expressions.groovy │ │ ├── strategy │ │ ├── groovy │ │ │ └── Multiplier.groovy │ │ └── java │ │ │ ├── AddStrategy.java │ │ │ ├── Multiplier.java │ │ │ ├── Multiply.java │ │ │ └── TimesStrategy.java │ │ └── xml │ │ ├── books.xml │ │ ├── books.xsd │ │ ├── booksNS.xml │ │ ├── booksWithDTD.xml │ │ ├── library.dtd │ │ ├── namespaces.groovy │ │ ├── parsing.groovy │ │ ├── sample_weather.xml │ │ ├── validate.groovy │ │ └── weather.groovy │ └── test │ └── groovy │ ├── ast │ └── singleton │ │ └── SingletonPointSpec.groovy │ ├── collections │ └── WordCountGroovyTest.groovy │ ├── db │ └── ManageProductsTest.java │ ├── json │ └── ChuckNorrisScriptTests.groovy │ ├── metaprogramming │ ├── ComplexSpec.groovy │ └── LoggingTests.groovy │ ├── scripts │ └── ScriptTests.groovy │ └── strategy │ ├── groovy │ └── MultiplierTest.groovy │ └── java │ └── MultiplierTest.java ├── appC ├── CalculatorClient │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── readme.txt │ ├── src │ │ └── mjg │ │ │ └── calc │ │ │ └── service │ │ │ ├── Add.java │ │ │ ├── AddResponse.java │ │ │ ├── Calculator.java │ │ │ ├── CalculatorService.java │ │ │ ├── Divide.java │ │ │ ├── DivideResponse.java │ │ │ ├── Multiply.java │ │ │ ├── MultiplyResponse.java │ │ │ ├── ObjectFactory.java │ │ │ ├── Subtract.java │ │ │ ├── SubtractResponse.java │ │ │ └── package-info.java │ └── test │ │ └── mjg │ │ └── calc │ │ └── client │ │ └── CalculatorTest.groovy ├── CalculatorService │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── readme.txt │ ├── resources │ │ ├── CalculatorService.wsdl │ │ └── CalculatorService_schema1.xsd │ └── src │ │ └── mjg │ │ └── calc │ │ └── service │ │ ├── Calculator.java │ │ ├── CalculatorServer.java │ │ └── jaxws │ │ ├── Add.java │ │ ├── AddResponse.java │ │ ├── Divide.java │ │ ├── DivideResponse.java │ │ ├── Multiply.java │ │ ├── MultiplyResponse.java │ │ ├── Subtract.java │ │ └── SubtractResponse.java ├── GenericCalculatorClient │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── readme.txt │ ├── src │ │ └── mjg │ │ │ └── calc │ │ │ └── service │ │ │ ├── Add.java │ │ │ ├── AddResponse.java │ │ │ ├── Calculator.java │ │ │ ├── Divide.java │ │ │ ├── DivideResponse.java │ │ │ ├── GenericCalculatorService.java │ │ │ ├── Multiply.java │ │ │ ├── MultiplyResponse.java │ │ │ ├── ObjectFactory.java │ │ │ ├── Subtract.java │ │ │ ├── SubtractResponse.java │ │ │ └── package-info.java │ └── test │ │ └── mjg │ │ └── calc │ │ └── client │ │ └── GenericCalculatorTest.groovy ├── GenericCalculatorService │ ├── .gitignore │ ├── build.gradle │ ├── readme.txt │ ├── resources │ │ ├── GenericCalculatorService.wsdl │ │ └── GenericCalculatorService_schema1.xsd │ └── src │ │ └── mjg │ │ └── calc │ │ └── service │ │ ├── Calculator.java │ │ ├── GenericCalculator.groovy │ │ ├── GroovyCalculator.groovy │ │ ├── JavaCalculator.java │ │ ├── groovy_generic_calculator_server.groovy │ │ ├── java_generic_calculator_server.groovy │ │ └── jaxws │ │ ├── Add.java │ │ ├── AddResponse.java │ │ ├── Divide.java │ │ ├── DivideResponse.java │ │ ├── Multiply.java │ │ ├── MultiplyResponse.java │ │ ├── Subtract.java │ │ └── SubtractResponse.java ├── GlobalWeatherClient │ ├── .gitignore │ ├── build.gradle │ ├── global_weather.wsdl │ ├── readme.txt │ ├── src │ │ ├── client.groovy │ │ ├── mjg │ │ │ └── soap │ │ │ │ └── client │ │ │ │ ├── GlobalWeatherClient.groovy │ │ │ │ └── Weather.groovy │ │ └── net │ │ │ └── webservicex │ │ │ ├── GetCitiesByCountry.java │ │ │ ├── GetCitiesByCountryResponse.java │ │ │ ├── GetWeather.java │ │ │ ├── GetWeatherResponse.java │ │ │ ├── GlobalWeather.java │ │ │ ├── GlobalWeatherSoap.java │ │ │ ├── ObjectFactory.java │ │ │ └── package-info.java │ └── test │ │ └── mjg │ │ └── soap │ │ └── client │ │ └── GlobalWeatherClientTests.groovy ├── GroovyCalculatorClient │ ├── .gitignore │ ├── build.gradle │ └── test │ │ └── mjg │ │ └── calc │ │ └── client │ │ └── GroovyCalculatorTest.groovy └── PottersPotions │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── readme.txt │ ├── resources │ ├── .gitignore │ └── handler-chain.xml │ ├── src │ └── mjg │ │ └── pp │ │ ├── entities │ │ ├── Cauldron.java │ │ ├── Ingredient.groovy │ │ └── Potion.java │ │ ├── handlers │ │ ├── CauldronHandler.java │ │ ├── CauldronProcessor.groovy │ │ └── Sneakoscope.java │ │ └── service │ │ ├── Granger.groovy │ │ ├── HogwartsWizard.groovy │ │ ├── JavaWizard.java │ │ ├── Wizard.groovy │ │ ├── jaxws │ │ ├── BrewPotion.java │ │ └── BrewPotionResponse.java │ │ ├── wizard_client.groovy │ │ ├── wizard_server.groovy │ │ └── wizard_server_and_client.groovy │ └── test │ └── mjg │ └── pp │ ├── entities │ └── CauldronTests.groovy │ └── service │ └── HogwartsWizardTest.groovy ├── ch01 └── Intro │ ├── .gitignore │ ├── README.md │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ ├── main │ ├── groovy │ │ ├── sorting │ │ │ └── sort_strings.groovy │ │ └── tasks │ │ │ └── GroovyTask.groovy │ └── java │ │ ├── sorting │ │ ├── SortStrings.java │ │ └── StringSorter.java │ │ └── tasks │ │ └── JavaTask.java │ └── test │ └── groovy │ ├── sorting │ ├── ScriptTests.groovy │ └── StringSorterTest.groovy │ └── tasks │ └── TaskTests.groovy ├── ch02 ├── .gitignore ├── build.gradle ├── chuckgroovy │ ├── .gitignore │ └── src │ │ └── main │ │ └── groovy │ │ └── mjg │ │ ├── icndb_script_only.groovy │ │ ├── icndb_with_label_and_button.groovy │ │ ├── icndb_with_textarea_and_button.groovy │ │ └── icndb_with_textarea_only.groovy ├── googlechart │ ├── .gitignore │ └── src │ │ └── main │ │ └── groovy │ │ └── mjg │ │ ├── hello_google_chart.groovy │ │ └── mjg_book_sales.groovy ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── groovybaseball │ ├── .gitignore │ ├── baseball.h2.db.backup │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── readme.txt │ ├── settings.gradle │ └── src │ │ ├── integrationTest │ │ └── groovy │ │ │ └── service │ │ │ └── GameServiceIntegrationTests.groovy │ │ ├── main │ │ ├── groovy │ │ │ ├── beans │ │ │ │ ├── GameResult.groovy │ │ │ │ └── Stadium.groovy │ │ │ └── service │ │ │ │ ├── Geocoder.groovy │ │ │ │ ├── GeocoderJSON.groovy │ │ │ │ ├── GetGameData.groovy │ │ │ │ └── populate_stadium_data.groovy │ │ └── webapp │ │ │ ├── GamesService.groovy │ │ │ ├── GamesServiceJSON.groovy │ │ │ ├── KousenIT_LoRes.jpg │ │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ │ ├── WEB-INF │ │ │ └── web.xml │ │ │ ├── css │ │ │ └── calendarview.css │ │ │ ├── index.jsp │ │ │ └── js │ │ │ └── calendarview.js │ │ └── test │ │ └── groovy │ │ └── service │ │ ├── GeocoderIntegrationSpec.groovy │ │ ├── GeocoderUnitSpec.groovy │ │ ├── GetGameDataTest.groovy │ │ └── StadiumLocationsSpec.groovy ├── openweather │ ├── api_key.txt │ ├── build.gradle │ └── src │ │ ├── main │ │ └── groovy │ │ │ └── mjg │ │ │ ├── Model.groovy │ │ │ ├── OpenWeather.groovy │ │ │ ├── parse_weather.groovy │ │ │ └── use_open_weather.groovy │ │ └── test │ │ └── groovy │ │ └── mjg │ │ ├── ModelSpec.groovy │ │ └── OpenWeatherSpec.groovy └── settings.gradle ├── ch03 └── Integration │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── readme.txt │ ├── src │ ├── geocode.groovy │ ├── geocodeV3.groovy │ └── mjg │ │ └── scripting │ │ ├── ExecuteGroovyFromJSR223.java │ │ ├── Geocoder.groovy │ │ ├── GeocoderV3.groovy │ │ ├── Location.groovy │ │ ├── ScriptEngineFactories.java │ │ ├── hello_world.groovy │ │ └── stock_prices.groovy │ └── test │ └── mjg │ └── scripting │ └── GroovyIntegrationTests.java ├── ch04 └── Integration │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── readme.txt │ ├── src │ └── mjg │ │ ├── ast │ │ ├── delegate │ │ │ ├── Camera.java │ │ │ ├── Phone.java │ │ │ └── SmartPhone.groovy │ │ ├── immutable │ │ │ ├── ImmutableLine.groovy │ │ │ ├── ImmutablePath.groovy │ │ │ ├── ImmutablePoint.groovy │ │ │ └── ImmutablePointFactory.groovy │ │ └── sortable │ │ │ └── sortable_persons.groovy │ │ ├── hr │ │ ├── Department.java │ │ └── Employee.java │ │ ├── jdk │ │ ├── basic_auth.groovy │ │ └── groundhog.groovy │ │ ├── json │ │ └── chuck_norris.groovy │ │ ├── pojo │ │ ├── Person.java │ │ └── use_pojo.groovy │ │ ├── scripting │ │ └── hello_groovy.groovy │ │ ├── sorting │ │ ├── SortStringsByLength.java │ │ └── sort_list.groovy │ │ └── xml │ │ ├── ProcessBooks.java │ │ ├── Song.java │ │ ├── SongXMLConverter.groovy │ │ ├── books.xml │ │ ├── process_books.groovy │ │ └── sample_result.xml │ └── test │ └── mjg │ ├── ast │ ├── delegate │ │ └── SmartPhoneTest.groovy │ └── immutable │ │ ├── ImmutableLineSpec.groovy │ │ ├── ImmutablePathSpec.groovy │ │ ├── ImmutablePointFactoryTest.java │ │ ├── ImmutablePointJUnitTest.java │ │ └── ImmutablePointSpec.groovy │ ├── hr │ └── DepartmentSpec.groovy │ ├── pojo │ └── PersonTest.groovy │ ├── scripting │ └── ScriptTests.groovy │ └── xml │ └── SongXMLConverterTest.groovy ├── ch05 ├── GradleLocal │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── lib │ │ ├── groovy-all-2.1.6.jar │ │ ├── hamcrest-core-1.3.jar │ │ ├── junit-4.11.jar │ │ └── spock-core-0.7-groovy-2.0.jar ├── Grapes │ ├── .gitignore │ └── src │ │ └── main │ │ └── groovy │ │ └── mjg │ │ ├── complex_h2.groovy │ │ ├── complex_numbers.groovy │ │ └── h2_db.groovy ├── GroovyAnt │ ├── .gitignore │ └── build.xml ├── GroovyGradle │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ └── java │ │ │ ├── HelloWorld.java │ │ │ └── mjg │ │ │ └── Greeting.java │ │ └── test │ │ ├── groovy │ │ └── mjg │ │ │ └── GroovyGreetingTests.groovy │ │ └── java │ │ └── mjg │ │ └── GreetingTests.java ├── HelloAnt │ ├── .gitignore │ ├── build.xml │ ├── lib │ │ ├── hamcrest-core-1.3.jar │ │ └── junit-4.11.jar │ └── src │ │ └── mjg │ │ ├── Greeting.java │ │ ├── GreetingTest.java │ │ └── HelloWorld.java ├── HelloAntBuilder │ ├── .gitignore │ ├── build.xml │ ├── lib │ │ ├── ant-junit-1.8.2.jar │ │ ├── ant-launcher-1.8.2.jar │ │ ├── hamcrest-core-1.3.jar │ │ └── junit-4.11.jar │ └── src │ │ ├── build.groovy │ │ └── mjg │ │ ├── Greeting.java │ │ ├── GreetingTest.java │ │ └── HelloWorld.java ├── HelloAntWithGroovy │ ├── .gitignore │ ├── build.xml │ ├── lib │ │ ├── hamcrest-core-1.3.jar │ │ └── junit-4.11.jar │ └── src │ │ └── mjg │ │ ├── Greeting.groovy │ │ ├── GreetingTest.groovy │ │ └── HelloWorld.java ├── HelloGradle │ ├── .gitignore │ ├── build.gradle │ └── src │ │ ├── main │ │ └── java │ │ │ ├── HelloWorld.java │ │ │ └── mjg │ │ │ └── Greeting.java │ │ └── test │ │ └── java │ │ └── mjg │ │ └── GreetingTests.java ├── HelloWorld │ └── build.gradle ├── MinimalGradle │ ├── .gitignore │ └── build.gradle ├── weather_gmaven │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── pom.xml │ ├── settings.gradle │ └── src │ │ ├── main │ │ ├── groovy │ │ │ └── mjg │ │ │ │ ├── RunDemo.groovy │ │ │ │ ├── Weather.groovy │ │ │ │ └── YahooParser.groovy │ │ └── java │ │ │ └── mjg │ │ │ └── RunInJava.java │ │ └── test │ │ └── groovy │ │ └── mjg │ │ └── YahooParserTest.groovy └── weather_groovyeclipse │ ├── .gitignore │ ├── pom.xml │ └── src │ ├── main │ ├── groovy │ │ └── mjg │ │ │ ├── Weather.groovy │ │ │ └── YahooParser.groovy │ └── java │ │ └── mjg │ │ ├── RunDemo.groovy │ │ └── RunInJava.java │ └── test │ └── java │ └── mjg │ └── YahooParserTest.groovy ├── ch06 ├── Banking │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ └── groovy │ │ │ └── mjg │ │ │ └── bank │ │ │ ├── Account.java │ │ │ ├── AccountDAO.java │ │ │ ├── AccountService.java │ │ │ ├── FileAccountDAO.groovy │ │ │ └── coerced_map_as_accountdao.groovy │ │ └── test │ │ └── groovy │ │ └── mjg │ │ └── bank │ │ ├── AccountServiceTest.groovy │ │ ├── FileAccountDAOIntegrationTest.groovy │ │ └── FileAccountDAOUnitTests.groovy ├── JUnitTests │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ ├── groovy │ │ │ └── mjg │ │ │ │ └── GroovyUtilityMethods.groovy │ │ └── java │ │ │ └── mjg │ │ │ ├── JavaUtilityMethods.java │ │ │ └── UtilityMethods.java │ │ └── test │ │ ├── groovy │ │ └── mjg │ │ │ ├── JavaImplGTCTest.groovy │ │ │ └── JavaImplGroovyTest.groovy │ │ └── java │ │ └── mjg │ │ └── GroovyImplJavaTest.java ├── Spock-Examples.zip ├── Spock-Examples │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ └── groovy │ │ │ └── mjg │ │ │ ├── PalindromeChecker.groovy │ │ │ ├── tng │ │ │ └── Klingon.groovy │ │ │ └── tos │ │ │ ├── LibraryComputer.groovy │ │ │ ├── Tribble.groovy │ │ │ └── Vulcan.groovy │ │ └── test │ │ └── groovy │ │ └── mjg │ │ ├── ArrayListSpec.groovy │ │ ├── HelloSpock.groovy │ │ ├── ListSpec.groovy │ │ ├── MyFirstSpec.groovy │ │ ├── PalindromeCheckerSpec.groovy │ │ ├── PalindromeCheckerTest.groovy │ │ ├── StringSpec.groovy │ │ └── tos │ │ ├── LibraryComputerSpec.groovy │ │ ├── QuoteSpec.groovy │ │ └── TribbleSpec.groovy └── Testing │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ ├── main │ └── groovy │ │ └── mjg │ │ ├── CallDefMethods.java │ │ ├── DefMethods.groovy │ │ ├── assert_demo.groovy │ │ ├── baseball │ │ ├── Geocoder.groovy │ │ └── Stadium.groovy │ │ ├── calc.groovy │ │ ├── calc_with_logger.groovy │ │ ├── chuck_norris.groovy │ │ ├── expando_demo.groovy │ │ ├── hello_name.groovy │ │ ├── hello_world.groovy │ │ ├── number_processor.groovy │ │ └── run_calc_with_logger.groovy │ └── test │ └── groovy │ └── mjg │ ├── CalcTests.groovy │ ├── CalcWithLoggerTests.groovy │ ├── NumberProcessorTests.groovy │ ├── ScriptShellTests.groovy │ ├── ScriptTests.groovy │ ├── baseball │ ├── GeocoderIntegrationTest.groovy │ └── GeocoderUnitTest.groovy │ └── gtc_immutable.groovy ├── ch07 ├── AccountManagement │ ├── .gitignore │ ├── build.gradle │ └── src │ │ ├── main │ │ ├── groovy │ │ │ └── mjg │ │ │ │ └── spring │ │ │ │ ├── aspects │ │ │ │ └── AccountAspect.groovy │ │ │ │ ├── config │ │ │ │ ├── GroovyConfig.groovy │ │ │ │ └── JavaConfig.java │ │ │ │ ├── dao │ │ │ │ ├── AccountDAO.java │ │ │ │ └── JdbcAccountDAO.groovy │ │ │ │ ├── entities │ │ │ │ └── Account.groovy │ │ │ │ └── services │ │ │ │ ├── AccountProcessor.java │ │ │ │ └── AccountService.java │ │ └── resources │ │ │ ├── applicationContext.xml │ │ │ ├── schema.sql │ │ │ └── test-data.sql │ │ └── test │ │ └── groovy │ │ └── mjg │ │ └── spring │ │ ├── dao │ │ └── JdbcAccountDAOSpec.groovy │ │ ├── entities │ │ └── AccountSpec.groovy │ │ └── services │ │ ├── AccountProcessorSpec.groovy │ │ └── AccountServiceSpec.groovy ├── GroovyAspect │ ├── .gitignore │ ├── build.gradle │ └── src │ │ ├── main │ │ ├── groovy │ │ │ └── mjg │ │ │ │ └── aspects │ │ │ │ ├── ChangeLogger.java │ │ │ │ └── UpdateReporter.groovy │ │ ├── java │ │ │ └── mjg │ │ │ │ └── POJO.java │ │ └── resources │ │ │ └── applicationContext.xml │ │ └── test │ │ ├── groovy │ │ └── mjg │ │ │ ├── POJOIntegrationSpec.groovy │ │ │ └── POJOUnitSpec.groovy │ │ └── java │ │ └── mjg │ │ └── POJOTest.java └── GroovyMortgage │ ├── .gitignore │ ├── build.gradle │ ├── resources │ ├── GroovyEvaluator.groovy │ └── applicationContext.xml │ ├── src │ └── main │ │ └── groovy │ │ └── mjg │ │ └── spring │ │ ├── Demo.java │ │ ├── Evaluator.java │ │ ├── JavaEvaluator.java │ │ └── MortgageApplication.groovy │ └── test │ └── mjg │ └── spring │ └── JavaEvaluatorSpec.groovy ├── ch08 ├── HibernateJPA │ ├── .gitignore │ ├── build.gradle │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── mjg │ │ │ │ ├── JpaProductDAO.java │ │ │ │ ├── Product.java │ │ │ │ └── ProductDAO.java │ │ └── resources │ │ │ ├── applicationContext.xml │ │ │ ├── schema.sql │ │ │ └── test-data.sql │ │ └── test │ │ └── java │ │ └── mjg │ │ ├── JpaConfigTest.java │ │ └── JpaProductDAOTest.java ├── RawJDBC │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ ├── groovy │ │ │ └── mjg │ │ │ │ └── SqlProductDAO.groovy │ │ └── java │ │ │ └── mjg │ │ │ ├── JDBCProductDAO.java │ │ │ ├── Product.java │ │ │ └── ProductDAO.java │ │ └── test │ │ └── groovy │ │ └── mjg │ │ ├── JDBCProductDAOTest.java │ │ └── SqlProductDAOTest.java ├── VampireMovies │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ └── groovy │ │ │ └── mjg │ │ │ ├── blazing_saddles.groovy │ │ │ ├── blazing_saddles.json │ │ │ ├── entities │ │ │ ├── CastMember.groovy │ │ │ ├── MPAARating.java │ │ │ ├── Movie.groovy │ │ │ ├── Rating.groovy │ │ │ └── SearchResult.groovy │ │ │ ├── json_to_gson.groovy │ │ │ ├── map_metaclass_qs.groovy │ │ │ ├── populate_mongodb_from_rotten_tomatoes.groovy │ │ │ ├── query_db.groovy │ │ │ ├── retrieve_movies.groovy │ │ │ ├── save_mongo_in_mongo.groovy │ │ │ └── twilight_db_query.groovy │ │ └── test │ │ └── groovy │ │ └── mjg │ │ └── entities │ │ └── MovieTest.groovy └── shopping │ ├── .gitignore │ ├── application.properties │ ├── grails-app │ ├── conf │ │ ├── ApplicationResources.groovy │ │ ├── BootStrap.groovy │ │ ├── BuildConfig.groovy │ │ ├── Config.groovy │ │ ├── DataSource.groovy │ │ ├── UrlMappings.groovy │ │ └── spring │ │ │ └── resources.groovy │ ├── controllers │ │ └── mjg │ │ │ ├── CustomerController.groovy │ │ │ ├── OrderController.groovy │ │ │ ├── OrderLineController.groovy │ │ │ └── ProductController.groovy │ ├── domain │ │ └── mjg │ │ │ ├── Customer.groovy │ │ │ ├── Order.groovy │ │ │ ├── OrderLine.groovy │ │ │ └── Product.groovy │ ├── i18n │ │ ├── messages.properties │ │ ├── messages_cs_CZ.properties │ │ ├── messages_da.properties │ │ ├── messages_de.properties │ │ ├── messages_es.properties │ │ ├── messages_fr.properties │ │ ├── messages_it.properties │ │ ├── messages_ja.properties │ │ ├── messages_nb.properties │ │ ├── messages_nl.properties │ │ ├── messages_pl.properties │ │ ├── messages_pt_BR.properties │ │ ├── messages_pt_PT.properties │ │ ├── messages_ru.properties │ │ ├── messages_sv.properties │ │ ├── messages_th.properties │ │ └── messages_zh_CN.properties │ └── views │ │ ├── error.gsp │ │ ├── index.gsp │ │ └── layouts │ │ └── main.gsp │ ├── shopping.mwb │ ├── shopping.png │ ├── test │ └── unit │ │ └── mjg │ │ ├── CustomerControllerTests.groovy │ │ ├── CustomerTests.groovy │ │ ├── OrderControllerTests.groovy │ │ ├── OrderLineControllerTests.groovy │ │ ├── OrderLineTests.groovy │ │ ├── OrderTests.groovy │ │ ├── ProductControllerTests.groovy │ │ └── ProductTests.groovy │ └── web-app │ ├── WEB-INF │ ├── applicationContext.xml │ ├── sitemesh.xml │ └── tld │ │ ├── c.tld │ │ ├── fmt.tld │ │ ├── grails.tld │ │ └── spring.tld │ ├── css │ ├── errors.css │ ├── main.css │ └── mobile.css │ ├── images │ ├── apple-touch-icon-retina.png │ ├── apple-touch-icon.png │ ├── favicon.ico │ ├── grails_logo.jpg │ ├── grails_logo.png │ ├── leftnav_btm.png │ ├── leftnav_midstretch.png │ ├── leftnav_top.png │ ├── skin │ │ ├── database_add.png │ │ ├── database_delete.png │ │ ├── database_edit.png │ │ ├── database_save.png │ │ ├── database_table.png │ │ ├── exclamation.png │ │ ├── house.png │ │ ├── information.png │ │ ├── shadow.jpg │ │ ├── sorted_asc.gif │ │ └── sorted_desc.gif │ ├── spinner.gif │ └── springsource.png │ └── js │ └── application.js ├── ch09 ├── HelloRestlet │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── mjg │ │ ├── HelloRestlet.java │ │ └── HelloServerResource.java ├── Jersey16 │ ├── build.gradle │ └── src │ │ ├── main │ │ └── groovy │ │ │ └── mjg │ │ │ └── GroovyResource.groovy │ │ └── test │ │ └── groovy │ │ └── mjg │ │ └── GroovyResourceTest.java ├── people │ ├── .gitignore │ ├── build.gradle │ ├── db.trace.db │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ └── groovy │ │ │ └── mjg │ │ │ └── rest │ │ │ ├── JdbcPersonDAO.groovy │ │ │ ├── MyApplication.java │ │ │ ├── Person.groovy │ │ │ ├── PersonDAO.java │ │ │ └── PersonResource.groovy │ │ └── test │ │ └── groovy │ │ └── mjg │ │ └── rest │ │ ├── PersonDAOSpec.groovy │ │ ├── PersonResourceSpec.groovy │ │ └── PersonSpec.groovy ├── people_hate │ ├── .gitignore │ ├── .idea │ │ └── gradle.xml │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── src │ │ ├── main │ │ └── groovy │ │ │ └── mjg │ │ │ └── rest │ │ │ ├── JdbcPersonDAO.groovy │ │ │ ├── MyApplication.java │ │ │ ├── Person.groovy │ │ │ ├── PersonDAO.java │ │ │ └── PersonResource.groovy │ │ └── test │ │ └── groovy │ │ └── mjg │ │ └── rest │ │ ├── PersonDAOSpec.groovy │ │ ├── PersonResourceSpec.groovy │ │ ├── PersonResourceTest.groovy │ │ └── PersonSpec.groovy ├── people_java │ ├── .gitignore │ ├── build.gradle │ ├── db.trace.db │ └── src │ │ ├── main │ │ └── java │ │ │ └── mjg │ │ │ └── rest │ │ │ ├── JdbcPersonDAO.java │ │ │ ├── MyApplication.java │ │ │ ├── Person.java │ │ │ ├── PersonDAO.java │ │ │ └── PersonResource.java │ │ └── test │ │ └── groovy │ │ └── mjg │ │ └── rest │ │ ├── PersonDAOSpec.groovy │ │ ├── PersonResourceSpec.groovy │ │ └── PersonSpec.groovy ├── people_readwrite │ ├── .gitignore │ ├── build.gradle │ ├── db.trace.db │ └── src │ │ ├── main │ │ └── groovy │ │ │ └── mjg │ │ │ └── rest │ │ │ ├── JdbcPersonDAO.groovy │ │ │ ├── MyApplication.java │ │ │ ├── Person.groovy │ │ │ ├── PersonDAO.java │ │ │ ├── PersonProvider.groovy │ │ │ └── PersonResource.groovy │ │ └── test │ │ └── groovy │ │ └── mjg │ │ └── rest │ │ ├── PersonDAOSpec.groovy │ │ ├── PersonResourceSpec.groovy │ │ └── PersonSpec.groovy └── shopping │ ├── .gitignore │ ├── application.properties │ ├── grails-app │ ├── conf │ │ ├── ApplicationResources.groovy │ │ ├── BootStrap.groovy │ │ ├── BuildConfig.groovy │ │ ├── Config.groovy │ │ ├── DataSource.groovy │ │ ├── UrlMappings.groovy │ │ └── spring │ │ │ └── resources.groovy │ ├── controllers │ │ └── mjg │ │ │ ├── CustomerController.groovy │ │ │ ├── OrderController.groovy │ │ │ ├── OrderLineController.groovy │ │ │ └── ProductController.groovy │ ├── domain │ │ └── mjg │ │ │ ├── Customer.groovy │ │ │ ├── Order.groovy │ │ │ ├── OrderLine.groovy │ │ │ └── Product.groovy │ ├── i18n │ │ ├── messages.properties │ │ ├── messages_cs_CZ.properties │ │ ├── messages_da.properties │ │ ├── messages_de.properties │ │ ├── messages_es.properties │ │ ├── messages_fr.properties │ │ ├── messages_it.properties │ │ ├── messages_ja.properties │ │ ├── messages_nb.properties │ │ ├── messages_nl.properties │ │ ├── messages_pl.properties │ │ ├── messages_pt_BR.properties │ │ ├── messages_pt_PT.properties │ │ ├── messages_ru.properties │ │ ├── messages_sv.properties │ │ ├── messages_th.properties │ │ └── messages_zh_CN.properties │ └── views │ │ ├── error.gsp │ │ ├── index.gsp │ │ └── layouts │ │ └── main.gsp │ ├── test │ └── unit │ │ └── mjg │ │ ├── CustomerControllerTests.groovy │ │ ├── CustomerTests.groovy │ │ ├── OrderControllerTests.groovy │ │ ├── OrderLineControllerTests.groovy │ │ ├── OrderLineTests.groovy │ │ ├── OrderTests.groovy │ │ ├── ProductControllerTests.groovy │ │ └── ProductTests.groovy │ └── web-app │ ├── WEB-INF │ ├── applicationContext.xml │ ├── sitemesh.xml │ └── tld │ │ ├── c.tld │ │ ├── fmt.tld │ │ ├── grails.tld │ │ └── spring.tld │ ├── css │ ├── errors.css │ ├── main.css │ └── mobile.css │ ├── images │ ├── apple-touch-icon-retina.png │ ├── apple-touch-icon.png │ ├── favicon.ico │ ├── grails_logo.jpg │ ├── grails_logo.png │ ├── leftnav_btm.png │ ├── leftnav_midstretch.png │ ├── leftnav_top.png │ ├── skin │ │ ├── database_add.png │ │ ├── database_delete.png │ │ ├── database_edit.png │ │ ├── database_save.png │ │ ├── database_table.png │ │ ├── exclamation.png │ │ ├── house.png │ │ ├── information.png │ │ ├── shadow.jpg │ │ ├── sorted_asc.gif │ │ └── sorted_desc.gif │ ├── spinner.gif │ └── springsource.png │ └── js │ └── application.js └── ch10 ├── CategoryDemo ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ └── groovy │ │ └── mjg │ │ ├── AnnotationCurrencyCategory.groovy │ │ └── CurrencyCategory.groovy │ └── test │ └── groovy │ └── mjg │ └── CurrencyCategoryTest.groovy ├── HelloGroovlet ├── .gradletasknamecache ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── integrationTest │ └── groovy │ │ └── mjg │ │ └── HelloGroovletTest.groovy │ ├── main │ └── webapp │ │ ├── WEB-INF │ │ └── web.xml │ │ └── hello.groovy │ └── test │ └── groovy │ └── mjg │ ├── HelloGroovletShellTest.groovy │ └── HelloGroovletUnitTest.groovy ├── HelloServlet ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── integrationTest │ └── groovy │ │ └── mjg │ │ └── ServletIntegrationTests.groovy │ ├── main │ ├── groovy │ │ └── mjg │ │ │ └── HelloGroovyServlet.groovy │ ├── java │ │ └── mjg │ │ │ └── HelloServlet.java │ └── webapp │ │ └── WEB-INF │ │ └── web.xml │ └── test │ ├── groovy │ └── mjg │ │ ├── HelloGroovyServletTest.groovy │ │ └── HelloServletGroovyTest.groovy │ └── java │ └── mjg │ └── HelloServletJavaTest.java ├── HelloServletWithHttpBuilder ├── .gitignore ├── build.gradle └── src │ ├── integrationTest │ └── groovy │ │ └── mjg │ │ └── ServletIntegrationTests.groovy │ ├── main │ ├── groovy │ │ └── mjg │ │ │ ├── HelloGroovyServlet.groovy │ │ │ ├── HelloNameServlet.groovy │ │ │ └── ServletWithBinding.groovy │ ├── java │ │ └── mjg │ │ │ ├── HelloServlet.java │ │ │ └── ServletWithSessionAndRequest.java │ └── webapp │ │ ├── WEB-INF │ │ └── web.xml │ │ ├── hello.gsp │ │ └── hello.jsp │ └── test │ ├── groovy │ └── mjg │ │ ├── HelloGroovyServletTest.groovy │ │ ├── HelloNameServletTest.groovy │ │ ├── HelloServletGroovyTest.groovy │ │ ├── ServletWithBindingTest.groovy │ │ └── ServletWithSessionAndRequestTest.groovy │ └── java │ └── mjg │ └── HelloServletJavaTest.java ├── SongService ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── integrationTest │ └── java │ │ └── mjg │ │ ├── SongClient.java │ │ └── SongClientTest.java │ ├── main │ ├── groovy │ │ └── mjg │ │ │ ├── Song.groovy │ │ │ ├── Song2XML.groovy │ │ │ └── SongDAO.groovy │ ├── resources │ │ └── applicationContext.xml │ └── webapp │ │ ├── SongService.groovy │ │ └── WEB-INF │ │ └── web.xml │ └── test │ └── groovy │ └── mjg │ ├── Song2XMLTest.groovy │ └── SongDAOTest.groovy └── holygrails ├── .gitignore ├── application.properties ├── grails-app ├── conf │ ├── ApplicationResources.groovy │ ├── BootStrap.groovy │ ├── BuildConfig.groovy │ ├── Config.groovy │ ├── DataSource.groovy │ ├── UrlMappings.groovy │ └── spring │ │ └── resources.groovy ├── controllers │ └── mjg │ │ ├── CastleController.groovy │ │ ├── KnightController.groovy │ │ ├── QuestController.groovy │ │ └── TaskController.groovy ├── domain │ └── mjg │ │ ├── Castle.groovy │ │ ├── Knight.groovy │ │ ├── Quest.groovy │ │ └── Task.groovy ├── i18n │ ├── messages.properties │ ├── messages_cs_CZ.properties │ ├── messages_da.properties │ ├── messages_de.properties │ ├── messages_es.properties │ ├── messages_fr.properties │ ├── messages_it.properties │ ├── messages_ja.properties │ ├── messages_nl.properties │ ├── messages_pt_BR.properties │ ├── messages_pt_PT.properties │ ├── messages_ru.properties │ ├── messages_sv.properties │ ├── messages_th.properties │ └── messages_zh_CN.properties ├── services │ └── mjg │ │ └── GeocoderService.groovy └── views │ ├── castle │ ├── _form.gsp │ ├── create.gsp │ ├── edit.gsp │ ├── list.gsp │ └── show.gsp │ ├── error.gsp │ ├── index.gsp │ └── layouts │ └── main.gsp ├── test └── unit │ └── mjg │ ├── CastleControllerTests.groovy │ ├── CastleTests.groovy │ ├── GeocoderServiceTests.groovy │ ├── KnightControllerTests.groovy │ ├── KnightTests.groovy │ ├── QuestControllerTests.groovy │ ├── QuestTests.groovy │ ├── TaskControllerTests.groovy │ └── TaskTests.groovy └── web-app ├── WEB-INF ├── applicationContext.xml ├── sitemesh.xml └── tld │ ├── c.tld │ ├── fmt.tld │ ├── grails.tld │ └── spring.tld ├── css ├── errors.css ├── main.css └── mobile.css ├── images ├── apple-touch-icon-retina.png ├── apple-touch-icon.png ├── favicon.ico ├── grails_logo.jpg ├── grails_logo.png ├── leftnav_btm.png ├── leftnav_midstretch.png ├── leftnav_top.png ├── skin │ ├── database_add.png │ ├── database_delete.png │ ├── database_edit.png │ ├── database_save.png │ ├── database_table.png │ ├── exclamation.png │ ├── house.png │ ├── information.png │ ├── shadow.jpg │ ├── sorted_asc.gif │ └── sorted_desc.gif ├── spinner.gif └── springsource.png └── js └── application.js /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | Servers 4 | .gradle 5 | .project 6 | .classpath 7 | .settings 8 | .metadata 9 | *.iml 10 | *.ipr 11 | *.iws 12 | .idea 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Source code for [Making Java Groovy](http://manning.com/kousen) by Ken Kousen 2 | 3 | Repo is organized into individual chapters. Each chapter 4 | contains one or more projects, each with its own gradle 5 | build file. Most have their own README files to describe 6 | how to build and test, normally using Gradle. 7 | 8 | As additional chapters are completed, their code will be 9 | added here. 10 | 11 | Please send any questions or comments to: 12 | 13 | Ken Kousen ([email](mailto:ken.kousen@kousenit.com)) 14 | [Kousen IT, Inc.](http://www.kousenit.com) 15 | [@kenkousen](http://twitter.com/kenkousen) 16 | -------------------------------------------------------------------------------- /appB/IntroGroovy/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | .gradletasknamecache 8 | -------------------------------------------------------------------------------- /appB/IntroGroovy/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | task wrapper(type:Wrapper) { 10 | gradleVersion = '2.0' 11 | } 12 | 13 | task collectJars(type: Copy) { 14 | into "$buildDir/lib" 15 | from configurations.testRuntime 16 | } 17 | 18 | dependencies { 19 | compile 'org.codehaus.groovy:groovy-all:2.3.3' 20 | compile 'org.apache.commons:commons-math3:3.0' 21 | testCompile 'org.spockframework:spock-core:0.7-groovy-2.0' 22 | runtime 'com.h2database:h2:1.2.140' 23 | compile 'org.apache.ant:ant:1.9.4' 24 | } 25 | -------------------------------------------------------------------------------- /appB/IntroGroovy/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/appB/IntroGroovy/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /appB/IntroGroovy/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 09:20:21 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/ast/singleton/SingletonPoint.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package ast.singleton 17 | 18 | @Singleton 19 | class SingletonPoint { 20 | BigDecimal x 21 | BigDecimal y 22 | } 23 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/collections/Shape.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package collections; 17 | 18 | public abstract class Shape { 19 | public abstract double getArea(); 20 | } 21 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/collections/passage.txt: -------------------------------------------------------------------------------- 1 | Groovy... 2 | 3 | * is an agile and dynamic language for the Java Virtual Machine 4 | * builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk 5 | * makes modern programming features available to Java developers with almost-zero learning curve 6 | * supports Domain-Specific Languages and other compact syntax so your code becomes easy to read and maintain 7 | * makes writing shell and build scripts easy with its powerful processing primitives, OO abilities and an Ant DSL 8 | * increases developer productivity by reducing scaffolding code when developing web, GUI, database or console applications 9 | * simplifies testing by supporting unit testing and mocking out-of-the-box 10 | * seamlessly integrates with all existing Java objects and libraries 11 | * compiles straight to Java bytecode so you can use it anywhere you can use Java 12 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/hello_world.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | println 'Hello, World!' -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/intro/hello_world.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package intro 17 | 18 | println 'Hello, World!' 19 | println('Hello, World!') 20 | 21 | assert 5 == Math.max(3,5) 22 | assert(5 == Math.max(3,5)) -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/io/data.txt: -------------------------------------------------------------------------------- 1 | 1,2,3 2 | a,b,c 3 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/io/sum_numbers.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package io 17 | 18 | println 'Please enter some numbers' 19 | System.in.withReader { br -> 20 | println br.readLine().tokenize()*.toBigDecimal().sum() 21 | } 22 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/io/sum_numbers_loop.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package io 17 | 18 | println 'Sum numbers with looping' 19 | System.in.eachLine { line -> 20 | if (!line) System.exit(0) 21 | println line.split(' ')*.toBigDecimal().sum() 22 | } 23 | 24 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/metaprogramming/CustomLevel.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package metaprogramming 17 | 18 | import groovy.transform.InheritConstructors; 19 | 20 | import java.util.logging.Level; 21 | 22 | @InheritConstructors 23 | class CustomLevel extends Level { 24 | } 25 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/oop/Circle.groovy: -------------------------------------------------------------------------------- 1 | package oop 2 | 3 | class Circle { 4 | double radius 5 | private String name 6 | 7 | double getArea() { 8 | return Math.PI*radius*radius 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/oop/Person.groovy: -------------------------------------------------------------------------------- 1 | package oop 2 | 3 | class Person { 4 | String firstName 5 | String lastName 6 | 7 | String toString() { "$firstName $lastName" } 8 | } 9 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/oop/use_circle.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package oop 17 | 18 | Circle c = new Circle() 19 | println c.radius 20 | println c.area 21 | 22 | c.radius = 1 23 | println "Circle of radius $c.radius has area $c.area" 24 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/oop/use_person.groovy: -------------------------------------------------------------------------------- 1 | package oop 2 | 3 | Person mrIncredible = new Person() 4 | mrIncredible.firstName = 'Robert' 5 | mrIncredible.setLastName('Parr') 6 | assert 'Robert Parr' == "${mrIncredible.firstName} ${mrIncredible.getLastName()}" 7 | Person elastigirl = new Person(firstName: 'Helen', lastName: 'Parr') 8 | assert 'Helen Parr' == elastigirl.toString() 9 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/precision_groovy.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | total = 0.0 17 | (0..9).each { total += 0.1 } 18 | assert total == 1.0 -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/strategy/java/Multiply.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package strategy.java; 17 | 18 | public interface Multiply { 19 | int multiply(int x, int y); 20 | } 21 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/strategy/java/TimesStrategy.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package strategy.java; 17 | 18 | 19 | public class TimesStrategy implements Multiply { 20 | 21 | public int multiply(int x, int y) { 22 | return x*y; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/xml/books.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | Groovy in Action 10 | Dierk Koenig 11 | 39.99 12 | 13 | 14 | Making Java Groovy 15 | Ken Kousen 16 | 35.99 17 | 18 | 19 | Griffon in Action 20 | Andres Almiray 21 | 35.99 22 | 23 | 24 | Grails in Action 25 | Glen Smith 26 | 27.50 27 | 28 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/xml/booksNS.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | Making Java Groovy 5 | Ken Kousen 6 | 35.99 7 | 8 | 9 | Groovy Recipes 10 | Scott Davis 11 | 34.95 12 | 13 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/xml/booksWithDTD.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Groovy in Action 6 | Dierk Koenig 7 | 39.999 8 | 9 | 10 | Making Java Groovy 11 | Ken Kousen 12 | 35.99 13 | 14 | 15 | Griffon in Action 16 | Andres Almiray 17 | 35.99 18 | 19 | 20 | Grails in Action 21 | Glen Smith 22 | 27.50 23 | 24 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/xml/library.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /appB/IntroGroovy/src/main/groovy/xml/weather.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | url = 'http://weather.yahooapis.com/forecastrss?w=2480318' 17 | def root = new XmlSlurper().parse(url) 18 | println( root.channel.location.@city ) 19 | -------------------------------------------------------------------------------- /appC/CalculatorClient/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /appC/CalculatorClient/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/appC/CalculatorClient/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /appC/CalculatorClient/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jun 12 11:40:18 EDT 2012 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.0-bin.zip 7 | -------------------------------------------------------------------------------- /appC/CalculatorClient/readme.txt: -------------------------------------------------------------------------------- 1 | Source code for Chapter 8 of Making Java Groovy by Ken Kousen. 2 | 3 | The source includes a Gradle build file that will compile 4 | all the code and run all the tests, ultimately producing HTML 5 | output in build/reports/test/index.html. 6 | 7 | If you have gradle installed, run 8 | > gradle build 9 | 10 | otherwise, the wrapper will download and install gradle for you: 11 | 12 | > gradlew build 13 | 14 | Notes: 15 | 1. In order for the tests to work in the gradle build, you have 16 | to run the mjg.calc.service.CalculatorServer application in the 17 | Ch07_CalculatorService project using the normal java command. 18 | The client project generates its stubs from the deployed 19 | application, which is running on http://localhost:1234/calc 20 | -------------------------------------------------------------------------------- /appC/CalculatorClient/src/mjg/calc/service/package-info.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://service.calc.mjg/") 17 | package mjg.calc.service; 18 | -------------------------------------------------------------------------------- /appC/CalculatorService/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /appC/CalculatorService/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/appC/CalculatorService/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /appC/CalculatorService/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Nov 16 22:58:39 EST 2011 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-5-bin.zip 7 | -------------------------------------------------------------------------------- /appC/CalculatorService/readme.txt: -------------------------------------------------------------------------------- 1 | Source code for Chapter 1 of Making Java Groovy by Ken Kousen. 2 | 3 | The source includes a Gradle build file that will compile 4 | all the code and run all the tests, ultimately producing HTML 5 | output in build/reports/test/index.html. 6 | 7 | If you have gradle installed, run 8 | > gradle build 9 | 10 | otherwise, the wrapper will download and install gradle for you: 11 | 12 | > gradlew build 13 | 14 | Notes: 15 | 1. I included the WSDL and schema files in the repo, 16 | even though they're generated by the build, just in case 17 | you don't want to generate them or you want to see them 18 | ahead of time. 19 | 20 | 2. In order for the tests to work in the Ch07_CalculatorClient 21 | project to work, you have to run the mjg.calc.service.CalculatorServer 22 | application using the normal java command. The client project 23 | generates its stubs from the deployed application, which is 24 | running on http://localhost:1234/calc 25 | -------------------------------------------------------------------------------- /appC/GenericCalculatorClient/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /appC/GenericCalculatorClient/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/appC/GenericCalculatorClient/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /appC/GenericCalculatorClient/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Nov 17 00:59:01 EST 2011 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-5-bin.zip 7 | -------------------------------------------------------------------------------- /appC/GenericCalculatorClient/readme.txt: -------------------------------------------------------------------------------- 1 | Source code for Chapter 7, SOAP-based Web Services, 2 | of Making Java Groovy by Ken Kousen, http://manning.com/kousen. 3 | 4 | The source includes a Gradle build file that will compile 5 | all the code and run all the tests, ultimately producing HTML 6 | output in build/reports/test/index.html. 7 | 8 | If you have gradle installed, run 9 | > gradle build 10 | 11 | otherwise, the wrapper will download and install gradle for you: 12 | 13 | > gradlew build 14 | 15 | Notes: 16 | 1. In order for the tests to work, one of the servers in the 17 | Ch07_GenericCalculatorService has to be running. This project 18 | generates its stubs from the deployed application, which is 19 | running on http://localhost:1234/calc 20 | -------------------------------------------------------------------------------- /appC/GenericCalculatorClient/src/mjg/calc/service/package-info.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://service.calc.mjg/") 17 | package mjg.calc.service; 18 | -------------------------------------------------------------------------------- /appC/GenericCalculatorService/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /appC/GenericCalculatorService/readme.txt: -------------------------------------------------------------------------------- 1 | Source code for Chapter 1 of Making Java Groovy by Ken Kousen. 2 | 3 | The project is set up in typical Maven structure, with the 4 | Java source and the Groovy source separated in both the src 5 | and test folders. This is unlike the rest of the book, where 6 | both are merged together. 7 | 8 | The source includes a Gradle build file that will compile 9 | all the code and run all the tests, ultimately producing HTML 10 | output in build/reports/test/index.html. -------------------------------------------------------------------------------- /appC/GlobalWeatherClient/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /appC/GlobalWeatherClient/readme.txt: -------------------------------------------------------------------------------- 1 | Source code for Chapter 1 of Making Java Groovy by Ken Kousen. 2 | 3 | The project is set up in typical Maven structure, with the 4 | Java source and the Groovy source separated in both the src 5 | and test folders. This is unlike the rest of the book, where 6 | both are merged together. 7 | 8 | The source includes a Gradle build file that will compile 9 | all the code and run all the tests, ultimately producing HTML 10 | output in build/reports/test/index.html. -------------------------------------------------------------------------------- /appC/GlobalWeatherClient/src/net/webservicex/package-info.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.webserviceX.NET", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 17 | package net.webservicex; 18 | -------------------------------------------------------------------------------- /appC/GroovyCalculatorClient/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /appC/PottersPotions/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /appC/PottersPotions/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/appC/PottersPotions/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /appC/PottersPotions/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jul 06 19:38:29 EDT 2012 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.0-bin.zip 7 | -------------------------------------------------------------------------------- /appC/PottersPotions/readme.txt: -------------------------------------------------------------------------------- 1 | Source code for Chapter 8 of Making Java Groovy by Ken Kousen. 2 | 3 | -------------------------------------------------------------------------------- /appC/PottersPotions/resources/.gitignore: -------------------------------------------------------------------------------- 1 | /HogwartsWizardService_schema1.xsd 2 | /HogwartsWizardService.wsdl 3 | -------------------------------------------------------------------------------- /appC/PottersPotions/resources/handler-chain.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | mjg.pp.handlers.Sneakoscope 7 | 8 | 9 | mjg.pp.handlers.CauldronHandler 10 | 11 | 12 | -------------------------------------------------------------------------------- /ch01/Intro/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /ch01/Intro/README.md: -------------------------------------------------------------------------------- 1 | Source code for Chapter 1 of _Making Java Groovy_ by Ken Kousen. 2 | 3 | The project is set up in typical Maven structure, with the 4 | Java source and the Groovy source separated in both the src 5 | and test folders. This is unlike the rest of the book, where 6 | both are merged together. 7 | 8 | The source includes a Gradle build file that will compile 9 | all the code and run all the tests, ultimately producing HTML 10 | output in build/reports/test/index.html. 11 | 12 | If you have gradle installed, run 13 | > gradle build 14 | 15 | otherwise, the wrapper will download and install gradle for you: 16 | 17 | > gradlew build 18 | -------------------------------------------------------------------------------- /ch01/Intro/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | 8 | task wrapper(type:Wrapper) { 9 | gradleVersion = '2.0' 10 | } 11 | 12 | dependencies { 13 | compile "org.codehaus.groovy:groovy-all:2.3.2" 14 | 15 | testCompile "org.spockframework:spock-core:0.7-groovy-2.0" 16 | } 17 | -------------------------------------------------------------------------------- /ch01/Intro/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch01/Intro/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch01/Intro/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 08:47:04 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch01/Intro/src/main/groovy/tasks/GroovyTask.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package tasks 17 | 18 | import groovy.transform.Canonical 19 | 20 | @Canonical 21 | class GroovyTask { 22 | String name 23 | int priority 24 | Date startDate 25 | Date endDate 26 | } 27 | -------------------------------------------------------------------------------- /ch02/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | 12 | # Idea 13 | .idea 14 | out 15 | 16 | .vscode/ 17 | -------------------------------------------------------------------------------- /ch02/build.gradle: -------------------------------------------------------------------------------- 1 | subprojects { 2 | apply plugin: 'groovy' 3 | apply plugin: 'eclipse' 4 | 5 | test { 6 | reports.html.enabled = false 7 | } 8 | 9 | repositories { 10 | jcenter() 11 | } 12 | 13 | dependencies { 14 | implementation 'org.codehaus.groovy:groovy:2.5.8' 15 | implementation 'org.codehaus.groovy:groovy-json:2.5.8' 16 | implementation 'org.codehaus.groovy:groovy-swing:2.5.8' 17 | } 18 | } 19 | 20 | task generateTestReport(type: TestReport) { 21 | destinationDir = file("$buildDir/reports/allTests") 22 | reportOn subprojects*.test 23 | } 24 | 25 | //gradle.taskGraph.whenReady { graph -> 26 | // if (graph.hasTask('test')) { 27 | // test.finalizedBy(generateTestReport) 28 | // } 29 | //} 30 | 31 | task('test').finalizedBy(generateTestReport) -------------------------------------------------------------------------------- /ch02/chuckgroovy/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | -------------------------------------------------------------------------------- /ch02/chuckgroovy/src/main/groovy/mjg/icndb_script_only.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import groovy.json.JsonSlurper 4 | 5 | String base = 'http://api.icndb.com/jokes/random?limitTo=[nerdy]' 6 | def json = new JsonSlurper().parseText(base.toURL().text) 7 | println json?.value?.joke -------------------------------------------------------------------------------- /ch02/chuckgroovy/src/main/groovy/mjg/icndb_with_textarea_only.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import groovy.json.JsonSlurper 4 | import groovy.swing.SwingBuilder 5 | 6 | import java.awt.BorderLayout as BL 7 | import java.awt.Color 8 | import java.awt.Font 9 | 10 | import javax.swing.WindowConstants as WC 11 | 12 | 13 | String base = 'http://api.icndb.com/jokes/random?limitTo=[nerdy]' 14 | def json = new JsonSlurper().parseText(base.toURL().text) 15 | String joke = json?.value?.joke 16 | 17 | new SwingBuilder().edt { 18 | frame(title:'ICNDB', visible: true, pack: true, 19 | defaultCloseOperation:WC.EXIT_ON_CLOSE) { 20 | panel(layout:new BL(), preferredSize:[300, 250], background: Color.WHITE) { 21 | scrollPane { 22 | textArea(joke, 23 | constraints:BL.NORTH, 24 | font: new Font('Serif', Font.PLAIN, 24), 25 | lineWrap: true, 26 | wrapStyleWord: true, 27 | editable: false) 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /ch02/googlechart/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | -------------------------------------------------------------------------------- /ch02/googlechart/src/main/groovy/mjg/hello_google_chart.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import groovy.swing.SwingBuilder 4 | 5 | import java.awt.BorderLayout as BL 6 | import javax.swing.ImageIcon 7 | import javax.swing.WindowConstants as WC 8 | 9 | String base = 'https://chart.googleapis.com/chart?' 10 | def params = [cht:'p3', chs:'250x100', chd:'t:60,40', chl:'Hello|World'] 11 | String qs = params.collect { k,v -> "$k=$v" }.join('&') 12 | println "$base$qs" 13 | 14 | new SwingBuilder().edt { 15 | frame(title:'Hello, Chart!', visible: true, pack: true, 16 | defaultCloseOperation: WC.EXIT_ON_CLOSE) { 17 | label(icon:new ImageIcon("$base$qs".toURL()), constraints: BL.CENTER) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ch02/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch02/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch02/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /ch02/groovybaseball/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | classes 6 | 7 | # Eclipse 8 | .project 9 | .classpath 10 | .settings 11 | bin 12 | 13 | # Idea 14 | .idea/ 15 | *.iml 16 | *.ipr 17 | -------------------------------------------------------------------------------- /ch02/groovybaseball/baseball.h2.db.backup: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch02/groovybaseball/baseball.h2.db.backup -------------------------------------------------------------------------------- /ch02/groovybaseball/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch02/groovybaseball/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch02/groovybaseball/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Mar 12 00:13:02 EDT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip 7 | -------------------------------------------------------------------------------- /ch02/groovybaseball/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'groovybaseball' -------------------------------------------------------------------------------- /ch02/groovybaseball/src/main/groovy/beans/GameResult.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package beans; 17 | 18 | class GameResult { 19 | String home 20 | String away 21 | String hScore 22 | String aScore 23 | Stadium stadium 24 | 25 | String toString() { "$home $hScore, $away $aScore" } 26 | } 27 | -------------------------------------------------------------------------------- /ch02/groovybaseball/src/main/webapp/GamesService.groovy: -------------------------------------------------------------------------------- 1 | import beans.GameResult; 2 | import beans.Stadium; 3 | import service.GetGameData; 4 | 5 | response.contentType = 'text/xml' 6 | def month = params.month 7 | def day = params.day 8 | def year = params.year 9 | 10 | m = month.toInteger() < 10 ? '0' + month : month 11 | d = day.toInteger() < 10 ? '0' + day : day 12 | y = year 13 | 14 | results = new GetGameData(month:m,day:d,year:y).games 15 | 16 | html.games { 17 | results.each { g -> 18 | game( 19 | outcome:"$g.away $g.aScore, $g.home $g.hScore", 20 | lat:g.stadium?.latitude, 21 | lng:g.stadium?.longitude 22 | ) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ch02/groovybaseball/src/main/webapp/KousenIT_LoRes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch02/groovybaseball/src/main/webapp/KousenIT_LoRes.jpg -------------------------------------------------------------------------------- /ch02/groovybaseball/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /ch02/openweather/api_key.txt: -------------------------------------------------------------------------------- 1 | d82ee6ea026dd986ea1e975d14875060 2 | -------------------------------------------------------------------------------- /ch02/openweather/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation 'com.google.code.gson:gson:2.8.5' 3 | testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5' 4 | } 5 | -------------------------------------------------------------------------------- /ch02/openweather/src/main/groovy/mjg/OpenWeather.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import com.google.gson.FieldNamingPolicy 4 | import com.google.gson.Gson 5 | import com.google.gson.GsonBuilder 6 | 7 | class OpenWeather { 8 | String appid = 'd82ee6ea026dd986ea1e975d14875060' 9 | String base = "http://api.openweathermap.org/data/2.5/weather?APPID=$appid&q=" 10 | Gson gson = new GsonBuilder().setFieldNamingPolicy( 11 | FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create() 12 | 13 | String getWeather(city='Hartford', state='US') { 14 | String loc = "$city,$state" 15 | String jsonTxt = "$base${URLEncoder.encode(loc, 'UTF-8')}".toURL().text 16 | gson.fromJson(jsonTxt, Model).toString() 17 | } 18 | 19 | String getWeather(String zip) { 20 | String loc = "$zip" 21 | String jsonTxt = "$base${URLEncoder.encode(loc, 'UTF-8')}".toURL().text 22 | gson.fromJson(jsonTxt, Model).toString() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ch02/openweather/src/main/groovy/mjg/parse_weather.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import com.google.gson.FieldNamingPolicy 4 | import com.google.gson.GsonBuilder 5 | import groovy.json.JsonOutput; 6 | 7 | import com.google.gson.Gson 8 | 9 | String appid = 'd82ee6ea026dd986ea1e975d14875060' 10 | def url = "http://api.openweathermap.org/data/2.5/weather?APPID=$appid&q=marlborough,us" 11 | def jsonTxt = url.toURL().text 12 | println JsonOutput.prettyPrint(jsonTxt) 13 | Gson gson = new GsonBuilder().setFieldNamingPolicy( 14 | FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create() 15 | println gson.fromJson(jsonTxt, Model) 16 | -------------------------------------------------------------------------------- /ch02/openweather/src/main/groovy/mjg/use_open_weather.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | OpenWeather ow = new OpenWeather() 4 | println ow.weather // called Marlborough, CT, but really Hartford 5 | 6 | println ow.getWeather('San Diego', 'US') 7 | 8 | // Home of Paul King, co-author of _Groovy in Action_ and my personal hero 9 | println ow.getWeather('Brisbane', 'Australia') 10 | 11 | // Home of Guillaume Laforge, head of the Groovy project 12 | // (also one of my heroes, along with Dierk Koenig, Graeme Rocher, Tom Brady, David Ortiz, ...) 13 | println ow.getWeather('Paris', 'France') 14 | 15 | // Have to check the weather in Java, right? 16 | println ow.getWeather('Java','Indonesia') 17 | 18 | // Is it always sunny in Philadelphia? 19 | println ow.getWeather('Philadelphia', 'US') 20 | 21 | // Any weather stations in Antarctica? 22 | println ow.getWeather('', 'Antarctica') 23 | 24 | // Is it colder in Denver than in Antarctica? 25 | println ow.getWeather('Denver', 'US') 26 | -------------------------------------------------------------------------------- /ch02/openweather/src/test/groovy/mjg/ModelSpec.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import spock.lang.Specification 4 | 5 | class ModelSpec extends Specification { 6 | Model model = new Model() 7 | 8 | def 'convertTemp converts from Kelvin to F'() { 9 | expect: 10 | 32 == model.convertTemp(273.15) 11 | 212 == model.convertTemp(373.15) 12 | } 13 | 14 | def 'convertSpeed converts from meters/sec to miles/hour'() { 15 | expect: 16 | (2.23694 - model.convertSpeed(1)).abs() < 0.00001 17 | } 18 | 19 | 20 | // def 'convertTime converts from Unix time to java.util.Date'() { 21 | // given: 22 | // Calendar cal = Calendar.instance 23 | // cal.set(1992, Calendar.MAY, 5) 24 | // Date d = cal.time 25 | // long time = d.time / 1000 // Java time in ms, Unix time in sec 26 | // 27 | // when: 28 | // Date date = model.convertTime(time) 29 | // 30 | // then: 31 | // d - date < 1 32 | // } 33 | } 34 | -------------------------------------------------------------------------------- /ch02/settings.gradle: -------------------------------------------------------------------------------- 1 | include 'googlechart' 2 | include 'chuckgroovy' 3 | include 'openweather' 4 | -------------------------------------------------------------------------------- /ch03/Integration/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | *~ 8 | -------------------------------------------------------------------------------- /ch03/Integration/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | sourceSets { 10 | main { 11 | java { srcDirs = [] } 12 | groovy { srcDir 'src' } 13 | } 14 | test { 15 | java { srcDirs = [] } 16 | groovy { srcDir 'test' } 17 | resources { srcDir 'resources' } 18 | } 19 | } 20 | 21 | task wrapper(type:Wrapper) { 22 | gradleVersion = '2.0' 23 | } 24 | 25 | dependencies { 26 | compile "org.codehaus.groovy:groovy-all:2.3.3" 27 | testCompile "org.spockframework:spock-core:0.7-groovy-2.0" 28 | } 29 | -------------------------------------------------------------------------------- /ch03/Integration/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch03/Integration/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch03/Integration/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 08:54:02 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch03/Integration/readme.txt: -------------------------------------------------------------------------------- 1 | Source code for Chapter 3, Code-level Integration, 2 | of Making Java Groovy by Ken Kousen, http://manning.com/kousen. 3 | 4 | The source includes a Gradle build file that will compile 5 | all the code and run all the tests, ultimately producing HTML 6 | output in build/reports/test/index.html. 7 | 8 | If you have gradle installed, run 9 | > gradle build 10 | 11 | otherwise, the wrapper will download and install gradle for you: 12 | 13 | > gradlew build 14 | -------------------------------------------------------------------------------- /ch03/Integration/src/geocodeV3.groovy: -------------------------------------------------------------------------------- 1 | // undeclared street, city, state part of binding 2 | String encoded = [street,city,state].collect { 3 | URLEncoder.encode(it,'UTF-8') 4 | }.join(',') 5 | String qs = [address: encoded, sensor: false].collect { it }.join('&') 6 | String base = 'http://maps.googleapis.com/maps/api/geocode/xml?' 7 | println "$base$qs" 8 | def root = new XmlSlurper().parse("$base$qs") 9 | 10 | // undeclared lat, lng part of binding 11 | lat = root.result[0].geometry.location.lat.toString() 12 | lng = root.result[0].geometry.location.lng.toString() 13 | println "($lat,$lng)" -------------------------------------------------------------------------------- /ch03/Integration/src/mjg/scripting/Location.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.scripting 17 | 18 | class Location { 19 | String street 20 | String city 21 | String state 22 | 23 | double latitude 24 | double longitude 25 | } 26 | -------------------------------------------------------------------------------- /ch03/Integration/src/mjg/scripting/hello_world.groovy: -------------------------------------------------------------------------------- 1 | package mjg.scripting 2 | 3 | println 'Hello, World!' 4 | -------------------------------------------------------------------------------- /ch03/Integration/src/mjg/scripting/stock_prices.groovy: -------------------------------------------------------------------------------- 1 | package mjg.scripting 2 | 3 | import java.text.NumberFormat 4 | 5 | String base = 'http://finance.yahoo.com/d/quotes.csv?' 6 | String symbols = ['GOOG','YHOO','MSFT'].join(',') 7 | String qs = [s:symbols, f:'sl1'].collect { it }.join('&') 8 | def results = "$base$qs".toURL().text.trim() 9 | NumberFormat nf = NumberFormat.currencyInstance 10 | results.eachLine { 11 | def (symbol, price) = it.split(',') 12 | println "$symbol last trade at ${nf.format(price.toDouble())}" 13 | } -------------------------------------------------------------------------------- /ch04/Integration/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | bin/ 3 | out/ 4 | .gradle 5 | .project 6 | .classpath 7 | .settings 8 | *~ 9 | -------------------------------------------------------------------------------- /ch04/Integration/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | sourceSets { 10 | main { 11 | java { srcDirs = [] } 12 | groovy { srcDir 'src' } 13 | } 14 | test { 15 | java { srcDirs = [] } 16 | groovy { srcDir 'test' } 17 | resources { srcDir 'resources' } 18 | } 19 | } 20 | 21 | task wrapper(type:Wrapper) { 22 | gradleVersion = '2.0' 23 | } 24 | 25 | dependencies { 26 | compile "org.codehaus.groovy:groovy-all:2.3.3" 27 | testCompile "org.spockframework:spock-core:0.7-groovy-2.0" 28 | } 29 | -------------------------------------------------------------------------------- /ch04/Integration/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch04/Integration/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch04/Integration/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 08:54:40 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch04/Integration/readme.txt: -------------------------------------------------------------------------------- 1 | Source code for Chapter 4, Using Groovy Features In Java, 2 | of Making Java Groovy by Ken Kousen, http://manning.com/kousen. 3 | 4 | The source includes a Gradle build file that will compile 5 | all the code and run all the tests, ultimately producing HTML 6 | output in build/reports/test/index.html. 7 | 8 | If you have gradle installed, run 9 | > gradle build 10 | 11 | otherwise, the wrapper will download and install gradle for you: 12 | 13 | > gradlew build 14 | -------------------------------------------------------------------------------- /ch04/Integration/src/mjg/ast/delegate/Camera.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.ast.delegate; 17 | 18 | public class Camera { 19 | public String takePicture() { 20 | return "taking picture"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ch04/Integration/src/mjg/ast/delegate/Phone.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.ast.delegate; 17 | 18 | public class Phone { 19 | public String dial(String number) { return "dialing " + number; } 20 | } 21 | -------------------------------------------------------------------------------- /ch04/Integration/src/mjg/ast/delegate/SmartPhone.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.ast.delegate 17 | 18 | class SmartPhone { 19 | @Delegate Camera camera = new Camera() 20 | @Delegate Phone phone = new Phone() 21 | } 22 | -------------------------------------------------------------------------------- /ch04/Integration/src/mjg/ast/immutable/ImmutablePath.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.ast.immutable 17 | 18 | import java.util.List; 19 | import groovy.transform.Immutable 20 | 21 | @Immutable 22 | class ImmutablePath { 23 | List segments = [] 24 | } 25 | -------------------------------------------------------------------------------- /ch04/Integration/src/mjg/ast/immutable/ImmutablePoint.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.ast.immutable 17 | 18 | import groovy.transform.Immutable; 19 | 20 | @Immutable 21 | class ImmutablePoint { 22 | double x 23 | double y 24 | 25 | String toString() { "($x,$y)" } 26 | } 27 | -------------------------------------------------------------------------------- /ch04/Integration/src/mjg/ast/sortable/sortable_persons.groovy: -------------------------------------------------------------------------------- 1 | package mjg.ast.sortable 2 | 3 | import groovy.transform.Sortable 4 | 5 | @Sortable 6 | class Person { 7 | String last 8 | String first 9 | 10 | String toString() { "$first $last" } 11 | } 12 | 13 | def people = [ 14 | new Person(first: 'Fred', last: 'Flintstone'), 15 | new Person(first: 'Barney', last: 'Rubble'), 16 | new Person(first: 'Betty', last: 'Rubble'), 17 | new Person(first: 'Wilma', last: 'Flintstone'), 18 | new Person(first: 'Pebbles', last: 'Flintstone') 19 | ] 20 | 21 | def sorted = people.sort() 22 | assert sorted*.toString() == [ 23 | 'Fred Flintstone', 'Pebbles Flintstone', 'Wilma Flintstone', 24 | 'Barney Rubble', 'Betty Rubble' 25 | ] 26 | -------------------------------------------------------------------------------- /ch04/Integration/src/mjg/scripting/hello_groovy.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.scripting 17 | println 'Hello, Groovy!' -------------------------------------------------------------------------------- /ch04/Integration/src/mjg/xml/books.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Groovy in Action 4 | Dierk Koenig 5 | 6 | 7 | Grails in Action 8 | Glen Smith 9 | Peter Ledbrook 10 | 11 | 12 | Making Java Groovy 13 | Ken Kousen 14 | 15 | -------------------------------------------------------------------------------- /ch04/Integration/src/mjg/xml/process_books.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.xml 17 | 18 | root = new XmlSlurper().parse('books.xml') 19 | println root.book[1].title -------------------------------------------------------------------------------- /ch04/Integration/test/mjg/ast/delegate/SmartPhoneTest.groovy: -------------------------------------------------------------------------------- 1 | package mjg.ast.delegate 2 | 3 | import org.junit.Test; 4 | 5 | class SmartPhoneTest { 6 | SmartPhone sp = new SmartPhone() 7 | 8 | @Test 9 | void testPhone() { 10 | assert 'dialing 555-1234' == sp.dial('555-1234') 11 | } 12 | 13 | @Test 14 | void testCamera() { 15 | assert 'taking picture' == sp.takePicture() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch05/GradleLocal/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | .groovy 8 | -------------------------------------------------------------------------------- /ch05/GradleLocal/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | 4 | repositories { 5 | flatDir { 6 | dirs 'lib' 7 | } 8 | // mavenCentral() 9 | } 10 | 11 | task wrapper(type:Wrapper) { 12 | gradleVersion = '2.0' 13 | } 14 | 15 | dependencies { 16 | compile "org.codehaus.groovy:groovy-all:2.3.3" 17 | 18 | testCompile "org.spockframework:spock-core:0.7-groovy-2.0" 19 | } 20 | -------------------------------------------------------------------------------- /ch05/GradleLocal/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/GradleLocal/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch05/GradleLocal/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 08:55:17 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch05/GradleLocal/lib/groovy-all-2.1.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/GradleLocal/lib/groovy-all-2.1.6.jar -------------------------------------------------------------------------------- /ch05/GradleLocal/lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/GradleLocal/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /ch05/GradleLocal/lib/junit-4.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/GradleLocal/lib/junit-4.11.jar -------------------------------------------------------------------------------- /ch05/GradleLocal/lib/spock-core-0.7-groovy-2.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/GradleLocal/lib/spock-core-0.7-groovy-2.0.jar -------------------------------------------------------------------------------- /ch05/Grapes/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Maven 7 | target 8 | 9 | # Eclipse 10 | .project 11 | .classpath 12 | .settings 13 | bin 14 | -------------------------------------------------------------------------------- /ch05/GroovyAnt/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | -------------------------------------------------------------------------------- /ch05/GroovyAnt/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 16 | 17 | 18 | 19 | println 'Hello, World!' 20 | ant.echo 'Hello, World!' 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /ch05/GroovyGradle/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | -------------------------------------------------------------------------------- /ch05/GroovyGradle/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | 4 | repositories { 5 | jcenter() 6 | } 7 | 8 | task wrapper(type:Wrapper) { 9 | gradleVersion = 2.3 10 | } 11 | 12 | dependencies { 13 | compile 'org.codehaus.groovy:groovy-all:2.4.3' 14 | testCompile 'junit:junit:4.10' 15 | } 16 | -------------------------------------------------------------------------------- /ch05/GroovyGradle/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/GroovyGradle/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch05/GroovyGradle/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Apr 18 09:59:39 EDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip 7 | -------------------------------------------------------------------------------- /ch05/GroovyGradle/src/main/java/HelloWorld.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | public class HelloWorld { 17 | public static void main(String[] args) { 18 | System.out.println("Hello, World, what up?"); 19 | } 20 | } -------------------------------------------------------------------------------- /ch05/HelloAnt/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | 12 | 13 | .ant_targets 14 | -------------------------------------------------------------------------------- /ch05/HelloAnt/lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/HelloAnt/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /ch05/HelloAnt/lib/junit-4.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/HelloAnt/lib/junit-4.11.jar -------------------------------------------------------------------------------- /ch05/HelloAnt/src/mjg/HelloWorld.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg; 17 | 18 | public class HelloWorld { 19 | public static void main(String[] args) { 20 | System.out.println("Hello, World!"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ch05/HelloAntBuilder/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | .ant_targets 12 | -------------------------------------------------------------------------------- /ch05/HelloAntBuilder/lib/ant-junit-1.8.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/HelloAntBuilder/lib/ant-junit-1.8.2.jar -------------------------------------------------------------------------------- /ch05/HelloAntBuilder/lib/ant-launcher-1.8.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/HelloAntBuilder/lib/ant-launcher-1.8.2.jar -------------------------------------------------------------------------------- /ch05/HelloAntBuilder/lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/HelloAntBuilder/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /ch05/HelloAntBuilder/lib/junit-4.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/HelloAntBuilder/lib/junit-4.11.jar -------------------------------------------------------------------------------- /ch05/HelloAntBuilder/src/mjg/HelloWorld.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg; 17 | 18 | public class HelloWorld { 19 | public static void main(String[] args) { 20 | System.out.println("Hello, World!"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ch05/HelloAntWithGroovy/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | 12 | 13 | .ant_targets 14 | -------------------------------------------------------------------------------- /ch05/HelloAntWithGroovy/lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/HelloAntWithGroovy/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /ch05/HelloAntWithGroovy/lib/junit-4.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/HelloAntWithGroovy/lib/junit-4.11.jar -------------------------------------------------------------------------------- /ch05/HelloAntWithGroovy/src/mjg/Greeting.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | class Greeting { 19 | String message = "Hello, World!" 20 | } 21 | -------------------------------------------------------------------------------- /ch05/HelloAntWithGroovy/src/mjg/HelloWorld.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg; 17 | 18 | public class HelloWorld { 19 | public static void main(String[] args) { 20 | System.out.println("Hello, World!"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ch05/HelloGradle/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | -------------------------------------------------------------------------------- /ch05/HelloGradle/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'java' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | testCompile 'junit:junit:4.10' 11 | } 12 | -------------------------------------------------------------------------------- /ch05/HelloGradle/src/main/java/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | public static void main(String[] args) { 3 | System.out.println("Hello, World, what up?"); 4 | } 5 | } -------------------------------------------------------------------------------- /ch05/HelloGradle/src/main/java/mjg/Greeting.java: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | public class Greeting { 4 | private String message = "Hello, World!"; 5 | 6 | public String getMessage() { 7 | return message; 8 | } 9 | 10 | public void setMessage(String message) { 11 | this.message = message; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /ch05/HelloGradle/src/test/java/mjg/GreetingTests.java: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | import static org.junit.Assert.*; 4 | import org.junit.Test; 5 | 6 | public class GreetingTests { 7 | private Greeting greeting = new Greeting(); 8 | 9 | @Test 10 | public void testGetGreeting() { 11 | assertEquals("Hello, World!", greeting.getMessage()); 12 | } 13 | 14 | @Test 15 | public void testSetGreeting() { 16 | greeting.setMessage("What up?"); 17 | assertEquals("What up?", greeting.getMessage()); 18 | } 19 | } -------------------------------------------------------------------------------- /ch05/HelloWorld/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'java' 2 | -------------------------------------------------------------------------------- /ch05/MinimalGradle/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Eclipse 7 | .project 8 | .classpath 9 | .settings 10 | bin 11 | -------------------------------------------------------------------------------- /ch05/MinimalGradle/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'java' 2 | apply plugin:'eclipse' 3 | -------------------------------------------------------------------------------- /ch05/weather_gmaven/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Maven 7 | target 8 | 9 | # Eclipse 10 | .project 11 | .classpath 12 | .settings 13 | bin 14 | -------------------------------------------------------------------------------- /ch05/weather_gmaven/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'maven' 3 | 4 | group = 'mjg' 5 | version = '1.0-SNAPSHOT' 6 | 7 | description = """weather project""" 8 | 9 | sourceCompatibility = 1.5 10 | targetCompatibility = 1.5 11 | 12 | 13 | 14 | repositories { 15 | 16 | maven { url "http://repo.maven.apache.org/maven2" } 17 | } 18 | dependencies { 19 | compile group: 'org.codehaus.groovy', name: 'groovy-all', version:'2.1.5' 20 | testCompile group: 'junit', name: 'junit', version:'4.10' 21 | } 22 | -------------------------------------------------------------------------------- /ch05/weather_gmaven/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch05/weather_gmaven/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch05/weather_gmaven/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 07 15:11:10 EDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip 7 | -------------------------------------------------------------------------------- /ch05/weather_gmaven/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'weather' 2 | -------------------------------------------------------------------------------- /ch05/weather_groovyeclipse/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | .gradletasknamecache 4 | build 5 | 6 | # Maven 7 | target 8 | 9 | # Eclipse 10 | .project 11 | .classpath 12 | .settings 13 | bin 14 | -------------------------------------------------------------------------------- /ch06/Banking/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /ch06/Banking/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | 8 | task wrapper(type:Wrapper) { 9 | gradleVersion = '2.0' 10 | } 11 | 12 | dependencies { 13 | compile "org.codehaus.groovy:groovy-all:2.3.3" 14 | testCompile 'junit:junit:4.11' 15 | } 16 | -------------------------------------------------------------------------------- /ch06/Banking/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch06/Banking/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch06/Banking/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 08:56:55 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch06/Banking/src/main/groovy/mjg/bank/coerced_map_as_accountdao.groovy: -------------------------------------------------------------------------------- 1 | package mjg.bank 2 | 3 | Account a1 = new Account(1, 100) 4 | Account a2 = new Account(2, 100) 5 | def accounts = [1:a1, 2:a2] 6 | int nextId = 3 7 | 8 | def mock = [findAccountById: { int id -> accounts[id] }, 9 | findAllAccounts: { -> accounts.values() }, 10 | createNewAccount: { double bal -> nextId++ }, 11 | deleteAccount: { int id -> } ] as AccountDAO 12 | 13 | assert mock.findAccountById(1) == a1 14 | mock.findAllAccounts().each { 15 | assert accounts.containsValue(it) 16 | } 17 | assert 3 == mock.createNewAccount(200) 18 | assert !mock.deleteAccount(3) -------------------------------------------------------------------------------- /ch06/JUnitTests/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build 4 | 5 | # Eclipse 6 | .project 7 | .classpath 8 | .settings 9 | bin -------------------------------------------------------------------------------- /ch06/JUnitTests/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | 8 | task wrapper(type:Wrapper) { 9 | gradleVersion = '2.0' 10 | } 11 | 12 | dependencies { 13 | compile "org.codehaus.groovy:groovy-all:2.3.3" 14 | testCompile "junit:junit:4.11" 15 | } 16 | -------------------------------------------------------------------------------- /ch06/JUnitTests/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch06/JUnitTests/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch06/JUnitTests/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Oct 23 08:31:32 CDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch06/JUnitTests/src/main/java/mjg/UtilityMethods.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg; 17 | 18 | public interface UtilityMethods { 19 | int[] getPositives(int... values); 20 | boolean isPrime(int x); 21 | boolean isPalindrome(String s); 22 | } 23 | -------------------------------------------------------------------------------- /ch06/Spock-Examples.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch06/Spock-Examples.zip -------------------------------------------------------------------------------- /ch06/Spock-Examples/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build 4 | 5 | # Eclipse 6 | .project 7 | .classpath 8 | .settings 9 | bin -------------------------------------------------------------------------------- /ch06/Spock-Examples/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "groovy" 2 | apply plugin: "eclipse" 3 | apply plugin: 'idea' 4 | 5 | repositories { 6 | jcenter() 7 | } 8 | 9 | dependencies { 10 | compile "org.codehaus.groovy:groovy-all:2.4.3" 11 | testCompile "org.spockframework:spock-core:1.0-groovy-2.4" 12 | } 13 | 14 | task wrapper(type: Wrapper) { 15 | gradleVersion = "2.3" 16 | } 17 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch06/Spock-Examples/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch06/Spock-Examples/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 08:57:56 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/main/groovy/mjg/PalindromeChecker.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class PalindromeChecker { 4 | boolean isPalindrome(String s) { 5 | String testString = s.replaceAll(/\W/,'').toLowerCase() 6 | return testString.reverse() == testString 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/main/groovy/mjg/tng/Klingon.groovy: -------------------------------------------------------------------------------- 1 | package mjg.tng 2 | 3 | interface Klingon { 4 | def annoy() 5 | def fight() 6 | def howlAtDeath() 7 | } 8 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/main/groovy/mjg/tos/LibraryComputer.groovy: -------------------------------------------------------------------------------- 1 | package mjg.tos 2 | 3 | class LibraryComputer { 4 | double computePi() { Math.PI } 5 | String makeTypewriterNoises() { "clickity-clickity-click" } 6 | 7 | def start() { "starting computer..." } 8 | def stop() { "stopping computer..." } 9 | } 10 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/main/groovy/mjg/tos/Tribble.groovy: -------------------------------------------------------------------------------- 1 | package mjg.tos 2 | 3 | import mjg.tng.Klingon; 4 | 5 | class Tribble { 6 | 7 | String react(Klingon klingon) { 8 | klingon.annoy() 9 | "wheep! wheep!" 10 | } 11 | 12 | String react(Vulcan vulcan) { 13 | vulcan.soothe() 14 | "purr, purr" 15 | } 16 | 17 | def feed() { 18 | def tribbles = [this] 19 | 10.times { tribbles << new Tribble() } 20 | return tribbles 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/main/groovy/mjg/tos/Vulcan.groovy: -------------------------------------------------------------------------------- 1 | package mjg.tos 2 | 3 | interface Vulcan { 4 | def soothe() 5 | boolean decideIfLogical() 6 | } 7 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/test/groovy/mjg/ArrayListSpec.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import spock.lang.Specification 4 | 5 | class ArrayListSpec extends Specification { 6 | ArrayList nums = [3, 1, 4, 1, 5, 9, 2, 6, 5] 7 | 8 | def 'size method returns number of elements'() { 9 | expect: 10 | nums.size() == 9 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/test/groovy/mjg/MyFirstSpec.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import spock.lang.Specification 4 | 5 | class MyFirstSpec extends Specification { 6 | def "max of two numbers"() { 7 | expect: 8 | Math.max(1, 2) == 2 9 | } 10 | 11 | def 'max method on a list works'() { 12 | expect: 13 | [3, 1, 4, 1, 5, 9].max() == 9 14 | [3, -1, 4, -5].min() == -5 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/test/groovy/mjg/PalindromeCheckerSpec.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import spock.lang.Specification; 4 | import spock.lang.Unroll; 5 | 6 | class PalindromeCheckerSpec extends Specification { 7 | PalindromeChecker checker = new PalindromeChecker() 8 | 9 | def palindromes = [ 10 | 'racecar', 11 | 'Sex at noon taxes', 12 | 'Do geese see God?', 13 | 'Flee to me, remote elf!', 14 | "Madam, in Eden, I'm Adam", 15 | "Go hang a salami; I'm a lasagna hog!" 16 | ] 17 | 18 | def "all the listed strings are palindromes"() { 19 | expect: 20 | palindromes.every { str -> checker.isPalindrome(str) } 21 | } 22 | 23 | def "this is not a palindrome"() { 24 | expect: 25 | !checker.isPalindrome('this is NOT a palindrome') 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/test/groovy/mjg/PalindromeCheckerTest.groovy: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | class PalindromeCheckerTest { 9 | PalindromeChecker checker = new PalindromeChecker() 10 | 11 | // @Before 12 | // public void setUp() throws Exception { 13 | // checker = new PalindromeChecker() 14 | // } 15 | 16 | @Test(expected=IllegalArgumentException) 17 | void testThrowsException() { 18 | throw new IllegalArgumentException() 19 | } 20 | 21 | @Test 22 | public void testIsPalindrome() { 23 | assert checker.isPalindrome("Flee to me, remote elf!") 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/test/groovy/mjg/tos/LibraryComputerSpec.groovy: -------------------------------------------------------------------------------- 1 | package mjg.tos 2 | 3 | import static spock.util.matcher.HamcrestMatchers.closeTo 4 | import spock.lang.Shared 5 | import spock.lang.Specification 6 | 7 | class LibraryComputerSpec extends Specification { 8 | @Shared LibraryComputer computer 9 | 10 | def setupSpec() { 11 | computer = new LibraryComputer() 12 | println computer.start() 13 | } 14 | 15 | def "compute to the last decimal the value of PI"() { 16 | expect: 17 | (computer.computePi() - 3.1415926535).abs() < 0.0001 18 | } 19 | 20 | def "in the 60's, TV thought computers made typewriter noises"() { 21 | expect: 22 | computer.makeTypewriterNoises().is("clickity-clickity-click") 23 | } 24 | 25 | def cleanupSpec() { 26 | println computer?.stop() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ch06/Spock-Examples/src/test/groovy/mjg/tos/QuoteSpec.groovy: -------------------------------------------------------------------------------- 1 | package mjg.tos 2 | 3 | import spock.lang.Specification; 4 | 5 | class QuoteSpec extends Specification { 6 | String quote = """I am endeavoring, ma'am, to construct a 7 | mnemonic memory circuit using stone knives and bear skins.""" 8 | 9 | List strings 10 | 11 | def setup() { 12 | strings = quote.tokenize(" ,.") 13 | } 14 | 15 | def "should be 16 words"() { 16 | expect: strings.size() == 16 17 | } 18 | 19 | def "add a word increases total by 1"() { 20 | when: 21 | strings << '(eyebrow)' 22 | 23 | then: 24 | strings.size() == old(strings.size()) + 1 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ch06/Testing/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /ch06/Testing/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | 8 | task wrapper(type:Wrapper) { 9 | gradleVersion = '2.0' 10 | } 11 | 12 | dependencies { 13 | compile "org.codehaus.groovy:groovy-all:2.3.6" 14 | testCompile "org.spockframework:spock-core:0.7-groovy-2.0" 15 | } 16 | -------------------------------------------------------------------------------- /ch06/Testing/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch06/Testing/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch06/Testing/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 08:58:37 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch06/Testing/src/main/groovy/mjg/DefMethods.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | class DefMethods { 19 | def multiplyByTwo(val) { val*2 } 20 | } 21 | -------------------------------------------------------------------------------- /ch06/Testing/src/main/groovy/mjg/assert_demo.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | int x = 3 19 | int y = 4 20 | int sum = x + y 21 | assert sum == 7 22 | -------------------------------------------------------------------------------- /ch06/Testing/src/main/groovy/mjg/calc.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | z = x + y -------------------------------------------------------------------------------- /ch06/Testing/src/main/groovy/mjg/calc_with_logger.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | import java.util.logging.Logger; 19 | 20 | Logger log = Logger.getLogger(this.class.name) 21 | 22 | log.info("Received (x,y) = ($x,$y)") 23 | 24 | z = x + y -------------------------------------------------------------------------------- /ch06/Testing/src/main/groovy/mjg/expando_demo.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | def ex = new Expando() 19 | ex.name = 'Fido' 20 | ex.speak = { "$name says Woof!" } 21 | println ex 22 | println ex.speak() -------------------------------------------------------------------------------- /ch06/Testing/src/main/groovy/mjg/hello_name.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | println "Hello, $name!" -------------------------------------------------------------------------------- /ch06/Testing/src/main/groovy/mjg/hello_world.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | println 'Hello, World!' -------------------------------------------------------------------------------- /ch06/Testing/src/main/groovy/mjg/number_processor.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | List findPositives(numbers) { 19 | numbers.findAll { it > 0 } 20 | } -------------------------------------------------------------------------------- /ch06/Testing/src/main/groovy/mjg/run_calc_with_logger.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | Binding b = new Binding(x:3, y:4) 4 | GroovyShell shell = new GroovyShell(b) 5 | shell.evaluate(new File('src/main/groovy/mjg/calc_with_logger.groovy')) 6 | println shell.context.z -------------------------------------------------------------------------------- /ch07/AccountManagement/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | .springBeans 8 | -------------------------------------------------------------------------------- /ch07/AccountManagement/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | repositories { 6 | jcenter() 7 | } 8 | 9 | def springVersion = '4.1.6.RELEASE' 10 | def spockVersion = '1.0-groovy-2.4' 11 | 12 | dependencies { 13 | compile 'org.codehaus.groovy:groovy-all:2.4.3' 14 | compile "org.springframework:spring-context:$springVersion" 15 | compile "org.springframework:spring-jdbc:$springVersion" 16 | runtime "com.h2database:h2:1.3.172" 17 | 18 | runtime "org.slf4j:slf4j-nop:1.7.5" 19 | runtime "org.slf4j:slf4j-api:1.7.5" 20 | testCompile "commons-dbcp:commons-dbcp:1.4" 21 | testCompile "org.grails:grails-spring:2.2.2" 22 | compile "aopalliance:aopalliance:1.0" 23 | compile "org.aspectj:aspectjrt:1.7.2" 24 | compile "org.aspectj:aspectjweaver:1.7.2" 25 | 26 | testCompile "org.springframework:spring-test:$springVersion" 27 | testCompile "org.spockframework:spock-core:$spockVersion" 28 | testCompile "org.spockframework:spock-spring:$spockVersion" 29 | } 30 | -------------------------------------------------------------------------------- /ch07/AccountManagement/src/main/groovy/mjg/spring/config/JavaConfig.java: -------------------------------------------------------------------------------- 1 | package mjg.spring.config; 2 | 3 | import mjg.spring.dao.AccountDAO; 4 | import mjg.spring.services.AccountProcessor; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | public class JavaConfig { 11 | @Autowired 12 | private AccountDAO accountDAO; 13 | 14 | @Bean 15 | public AccountProcessor accountProcessor() { 16 | AccountProcessor ap = new AccountProcessor(); 17 | ap.setAccounts(accountDAO.findAllAccounts()); 18 | return ap; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ch07/AccountManagement/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table accounts if exists; 2 | create table accounts (id integer primary key, balance decimal not null); -------------------------------------------------------------------------------- /ch07/AccountManagement/src/main/resources/test-data.sql: -------------------------------------------------------------------------------- 1 | insert into accounts(id, balance) values(0, 100.0); 2 | insert into accounts(id, balance) values(1, 200.0); 3 | insert into accounts(id, balance) values(2, 150.0); -------------------------------------------------------------------------------- /ch07/GroovyAspect/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | .springBeans 8 | -------------------------------------------------------------------------------- /ch07/GroovyAspect/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | jcenter() 7 | } 8 | 9 | def springVersion = '4.1.6.RELEASE' 10 | def spockVersion = '1.0-groovy-2.4' 11 | 12 | dependencies { 13 | compile group:'org.codehaus.groovy', name:'groovy-all', version:'2.4.3' 14 | compile "org.springframework:spring-context:$springVersion" 15 | compile "aopalliance:aopalliance:1.0" 16 | compile "org.aspectj:aspectjrt:1.6.10" 17 | compile "org.aspectj:aspectjweaver:1.6.10" 18 | 19 | testCompile "org.springframework:spring-test:$springVersion" 20 | testCompile group:'org.spockframework', name:'spock-core', version:spockVersion 21 | testCompile "org.spockframework:spock-spring:$spockVersion" 22 | } 23 | -------------------------------------------------------------------------------- /ch07/GroovyMortgage/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | .springBeans 8 | -------------------------------------------------------------------------------- /ch07/GroovyMortgage/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | jcenter() 7 | } 8 | 9 | def springVersion = '4.1.6.RELEASE' 10 | def spockVersion = '1.0-groovy-2.4' 11 | 12 | dependencies { 13 | compile "org.codehaus.groovy:groovy-all:2.4.3" 14 | compile "org.springframework:spring-context:$springVersion" 15 | compile "org.springframework:spring-jdbc:$springVersion" 16 | 17 | testCompile "org.springframework:spring-test:$springVersion" 18 | testCompile "org.spockframework:spock-core:$spockVersion" 19 | testCompile "org.spockframework:spock-spring:$spockVersion" 20 | } 21 | -------------------------------------------------------------------------------- /ch07/GroovyMortgage/resources/GroovyEvaluator.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | import groovy.transform.CompileStatic; 17 | import mjg.spring.* 18 | 19 | @CompileStatic 20 | class GroovyEvaluator implements Evaluator { 21 | boolean approve(MortgageApplication application) { 22 | true 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ch07/GroovyMortgage/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ch07/GroovyMortgage/src/main/groovy/mjg/spring/Evaluator.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.spring; 17 | 18 | public interface Evaluator { 19 | boolean approve(MortgageApplication application); 20 | } 21 | -------------------------------------------------------------------------------- /ch07/GroovyMortgage/src/main/groovy/mjg/spring/JavaEvaluator.java: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.spring; 17 | 18 | public class JavaEvaluator implements Evaluator { 19 | public boolean approve(MortgageApplication application) { 20 | return true; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ch07/GroovyMortgage/src/main/groovy/mjg/spring/MortgageApplication.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg.spring 17 | 18 | class MortgageApplication { 19 | BigDecimal amount 20 | BigDecimal rate 21 | int years 22 | } 23 | -------------------------------------------------------------------------------- /ch08/HibernateJPA/.gitignore: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | build 3 | bin 4 | target 5 | ======= 6 | *.iws 7 | *Db.properties 8 | *Db.script 9 | *.h2.db 10 | *.h2.data 11 | eclipse 12 | target-eclipse 13 | plugin.xml 14 | site-config.groovy 15 | stacktrace.log 16 | target 17 | /plugins 18 | /web-app/plugins 19 | /web-app/WEB-INF/classes 20 | build 21 | bin 22 | >>>>>>> rest 23 | .gradle 24 | .project 25 | .classpath 26 | .settings 27 | -------------------------------------------------------------------------------- /ch08/HibernateJPA/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'eclipse' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | 8 | def springVersion = '3.2.2.RELEASE' 9 | 10 | dependencies { 11 | compile "org.codehaus.groovy:groovy-all:2.3.3" 12 | compile "org.springframework:spring-context:$springVersion" 13 | compile "org.springframework:spring-jdbc:$springVersion" 14 | compile "org.springframework:spring-orm:$springVersion" 15 | compile 'org.hibernate:hibernate-entitymanager:4.2.2.Final' 16 | 17 | testCompile "commons-dbcp:commons-dbcp:1.4" 18 | testCompile "org.springframework:spring-test:$springVersion" 19 | testCompile 'junit:junit:4.10' 20 | 21 | runtime "com.h2database:h2:1.3.172" 22 | runtime "cglib:cglib:2.2.2" 23 | runtime "org.slf4j:slf4j-nop:1.7.5" 24 | runtime "org.slf4j:slf4j-api:1.7.5" 25 | } 26 | -------------------------------------------------------------------------------- /ch08/HibernateJPA/src/main/java/mjg/JpaProductDAO.java: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.EntityManager; 6 | import javax.persistence.PersistenceContext; 7 | 8 | import org.springframework.stereotype.Repository; 9 | 10 | @Repository 11 | public class JpaProductDAO implements ProductDAO { 12 | @PersistenceContext 13 | private EntityManager entityManager; 14 | 15 | @SuppressWarnings("unchecked") 16 | @Override 17 | public List getAllProducts() { 18 | return entityManager.createQuery("from Product p").getResultList(); 19 | } 20 | 21 | @Override 22 | public Product findProductById(int id) { 23 | return entityManager.find(Product.class, id); 24 | } 25 | 26 | @Override 27 | public int insertProduct(Product p) { 28 | entityManager.persist(p); 29 | return p.getId(); 30 | } 31 | 32 | @Override 33 | public void deleteProduct(int id) { 34 | entityManager.remove(findProductById(id)); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /ch08/HibernateJPA/src/main/java/mjg/ProductDAO.java: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | import java.util.List; 4 | 5 | public interface ProductDAO { 6 | 7 | List getAllProducts(); 8 | Product findProductById(int id); 9 | int insertProduct(Product p); 10 | void deleteProduct(int id); 11 | } -------------------------------------------------------------------------------- /ch08/HibernateJPA/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | drop table PRODUCT if exists 2 | 3 | create table PRODUCT (id bigint generated by default as identity (start with 1), name varchar(255), price double, primary key (id)) 4 | -------------------------------------------------------------------------------- /ch08/HibernateJPA/src/main/resources/test-data.sql: -------------------------------------------------------------------------------- 1 | insert into PRODUCT(name, price) values('baseball', 5.99) 2 | insert into PRODUCT(name, price) values('basketball', 10.99) 3 | insert into PRODUCT(name, price) values('football', 7.99) 4 | -------------------------------------------------------------------------------- /ch08/RawJDBC/.gitignore: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | ======= 3 | *.iws 4 | *Db.properties 5 | *Db.script 6 | *.h2.db 7 | *.h2.data 8 | eclipse 9 | target-eclipse 10 | plugin.xml 11 | site-config.groovy 12 | stacktrace.log 13 | target 14 | /plugins 15 | /web-app/plugins 16 | /web-app/WEB-INF/classes 17 | >>>>>>> rest 18 | build 19 | bin 20 | .gradle 21 | .project 22 | .classpath 23 | .settings 24 | <<<<<<< HEAD 25 | /src/main/groovy/mjg/rotten_tomatoes_apiKey.txt 26 | ======= 27 | >>>>>>> rest 28 | -------------------------------------------------------------------------------- /ch08/RawJDBC/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | task wrapper(type:Wrapper) { 10 | gradleVersion = '2.0' 11 | } 12 | 13 | dependencies { 14 | compile 'org.codehaus.groovy:groovy-all:2.3.3' 15 | runtime 'com.h2database:h2:1.3.172' 16 | testCompile 'junit:junit:4.10' 17 | } 18 | -------------------------------------------------------------------------------- /ch08/RawJDBC/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/RawJDBC/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch08/RawJDBC/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 09:04:20 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch08/RawJDBC/src/main/java/mjg/Product.java: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | public class Product { 4 | private int id; 5 | private String name; 6 | private double price; 7 | 8 | public Product() {} 9 | 10 | public Product(int id, String name, double price) { 11 | this.id = id; 12 | this.name = name; 13 | this.price = price; 14 | } 15 | 16 | public int getId() { 17 | return id; 18 | } 19 | 20 | public void setId(int id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public double getPrice() { 33 | return price; 34 | } 35 | 36 | public void setPrice(double price) { 37 | this.price = price; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "ProductJava [id=" + id + ", name=" + name + ", price=" + price 43 | + "]"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ch08/RawJDBC/src/main/java/mjg/ProductDAO.java: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | import java.util.List; 4 | 5 | public interface ProductDAO { 6 | List getAllProducts(); 7 | Product findProductById(int id); 8 | void insertProduct(Product p); 9 | void deleteProduct(int id); 10 | } -------------------------------------------------------------------------------- /ch08/VampireMovies/.gitignore: -------------------------------------------------------------------------------- 1 | *.iws 2 | build 3 | bin 4 | classes 5 | .gradle 6 | .project 7 | .classpath 8 | .settings 9 | 10 | /src/main/groovy/mjg/rotten_tomatoes_apiKey.txt 11 | -------------------------------------------------------------------------------- /ch08/VampireMovies/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | task wrapper(type:Wrapper) { 10 | gradleVersion = '2.0' 11 | } 12 | 13 | dependencies { 14 | compile 'org.codehaus.groovy:groovy-all:2.3.6' 15 | compile 'com.gmongo:gmongo:1.3' 16 | compile 'com.google.code.gson:gson:2.2.4' 17 | testCompile 'junit:junit:4.10' 18 | } 19 | -------------------------------------------------------------------------------- /ch08/VampireMovies/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/VampireMovies/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch08/VampireMovies/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 09:04:51 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/blazing_saddles.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import groovy.json.* 4 | 5 | String apiKey = new File('rotten_tomatoes_apiKey.txt').text 6 | String base = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?" 7 | String qs = [apiKey:apiKey, 8 | q: URLEncoder.encode('Blazing Saddles','UTF-8')].collect { it }.join('&') 9 | String url = "$base$qs" 10 | println JsonOutput.prettyPrint(url.toURL().text) 11 | def json = new JsonSlurper().parseText(url.toURL().text) 12 | def movie = json.movies[0] 13 | def allCast = new JsonSlurper().parseText("${movie.links.cast}?apiKey=$apiKey".toURL().text) 14 | println '---------- All Cast ----------' 15 | allCast.cast.each { println it } 16 | println '------------------------------' 17 | assert allCast.cast.find { it.characters =~ /Mongo/ } 18 | -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/entities/CastMember.groovy: -------------------------------------------------------------------------------- 1 | package mjg.entities 2 | 3 | import groovy.transform.ToString; 4 | 5 | @ToString(includeNames=true) 6 | class CastMember { 7 | String name 8 | long id 9 | List characters = [] 10 | } 11 | -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/entities/MPAARating.java: -------------------------------------------------------------------------------- 1 | package mjg.entities; 2 | 3 | public enum MPAARating { 4 | G, PG, PG_13, R, X, NC_17, Unrated 5 | } 6 | -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/entities/Rating.groovy: -------------------------------------------------------------------------------- 1 | package mjg.entities 2 | 3 | import groovy.transform.ToString; 4 | 5 | @ToString(includeNames=true) 6 | class Rating { 7 | String rating 8 | int score 9 | } 10 | -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/entities/SearchResult.groovy: -------------------------------------------------------------------------------- 1 | package mjg.entities 2 | 3 | class SearchResult { 4 | int total 5 | List movies = [] 6 | Map links = [:] 7 | String link_template 8 | } 9 | -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/map_metaclass_qs.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | Map.metaClass.toQueryString = { 4 | delegate.collect { it }.join('&') 5 | } 6 | 7 | def map = [a:1, b:2, c:3] 8 | assert 'a=1&b=2&c=3' == map.toQueryString() -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/populate_mongodb_from_rotten_tomatoes.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import groovy.json.* 4 | import com.gmongo.GMongo 5 | 6 | GMongo mongo = new GMongo() 7 | def db = mongo.getDB('movies') 8 | db.vampireMovies.drop() 9 | 10 | def slurper = new JsonSlurper() 11 | 12 | String key = new File('rotten_tomatoes_apiKey.txt').text 13 | String base = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?" 14 | String qs = [apiKey:key, q:'vampire'].collect { it }.join('&') 15 | String url = "$base$qs" 16 | println url 17 | def vampMovies = new JsonSlurper().parseText(url.toURL().text) 18 | db.vampireMovies << vampMovies.movies 19 | def next = vampMovies?.links?.next 20 | 21 | while (next) { 22 | println next 23 | vampMovies = slurper.parseText("$next&apiKey=$key".toURL().text) 24 | db.vampireMovies << vampMovies.movies 25 | next = vampMovies?.links?.next 26 | } 27 | 28 | println db.vampireMovies.find().count() 29 | -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/query_db.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import mjg.entities.Movie; 4 | 5 | import com.gmongo.GMongo; 6 | 7 | GMongo mongo = new GMongo() 8 | def db = mongo.getDB('movies') 9 | 10 | println db.vampireMovies.find().count() 11 | db.vampireMovies.find(critics_consensus : ~/.*/).each { movie -> 12 | println "$movie.id $movie.title : $movie.critics_consensus" 13 | //println Movie.fromJSON(movie) 14 | } 15 | 16 | //def bs = db.otherMovies.findOne(title: 'Blazing Saddles') 17 | //println bs 18 | //println Movie.fromJSON(bs) -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/retrieve_movies.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import groovy.json.* 4 | 5 | String apiKey = new File('rotten_tomatoes_apiKey.txt').text 6 | String url = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apiKey=$apiKey" 7 | 8 | def vampMovies = new JsonSlurper().parseText("$url&q=vampire".toURL().text) 9 | println vampMovies.size() 10 | -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/save_mongo_in_mongo.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import com.gmongo.GMongo 4 | import groovy.json.JsonSlurper 5 | 6 | GMongo mongo = new GMongo() 7 | def db = mongo.getDB('movies') 8 | int before = db.otherMovies?.find().count() 9 | 10 | def blazingSaddles = new JsonSlurper().parseText( 11 | new File('blazing_saddles.json').text).movies 12 | 13 | println blazingSaddles.title[0] 14 | 15 | if (!db.otherMovies.findOne(title:'Blazing Saddles')) { 16 | db.otherMovies << blazingSaddles 17 | int after = db.otherMovies.find().count() 18 | assert after == before + 1 19 | } 20 | 21 | assert db.otherMovies.findOne(title:'Blazing Saddles') -------------------------------------------------------------------------------- /ch08/VampireMovies/src/main/groovy/mjg/twilight_db_query.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import mjg.entities.Movie; 4 | 5 | import com.gmongo.GMongo; 6 | 7 | GMongo mongo = new GMongo() 8 | def db = mongo.getDB('movies') 9 | 10 | // Twilight series: Twilight, New Moon, Eclipse, Breaking Dawn 11 | def results = db.vampireMovies.find().findAll { 12 | it.title =~ /Twilight|Dawn|Eclipse|Moon/ 13 | }*.title 14 | println "Twilight series movies in DB: $results" -------------------------------------------------------------------------------- /ch08/shopping/.gitignore: -------------------------------------------------------------------------------- 1 | *.iws 2 | <<<<<<< HEAD 3 | ======= 4 | *.iml 5 | >>>>>>> rest 6 | *Db.properties 7 | *Db.script 8 | *.h2.db 9 | *.h2.data 10 | eclipse 11 | target-eclipse 12 | plugin.xml 13 | site-config.groovy 14 | stacktrace.log 15 | target 16 | /plugins 17 | /web-app/plugins 18 | /web-app/WEB-INF/classes 19 | build 20 | bin 21 | <<<<<<< HEAD 22 | ======= 23 | out 24 | >>>>>>> rest 25 | .gradle 26 | .project 27 | .classpath 28 | .settings 29 | <<<<<<< HEAD 30 | ======= 31 | .idea 32 | >>>>>>> rest 33 | -------------------------------------------------------------------------------- /ch08/shopping/application.properties: -------------------------------------------------------------------------------- 1 | #Grails Metadata file 2 | #Fri Jan 24 07:06:41 CST 2014 3 | app.grails.version=2.2.4 4 | app.name=shopping 5 | app.version=0.1 6 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/conf/ApplicationResources.groovy: -------------------------------------------------------------------------------- 1 | modules = { 2 | application { 3 | resource url:'js/application.js' 4 | } 5 | } -------------------------------------------------------------------------------- /ch08/shopping/grails-app/conf/BootStrap.groovy: -------------------------------------------------------------------------------- 1 | import mjg.* 2 | 3 | class BootStrap { 4 | 5 | def init = { servletContext -> 6 | if (!Product.findByName('baseball')) { 7 | Product baseball = new Product(name:'baseball', price:5.99).save() 8 | Product football = new Product(name:'football', price:12.99).save() 9 | Customer cb = new Customer(name:'Charlie Brown').save() 10 | Order o1 = new Order(number:'1', customer:cb) 11 | .addToOrderLines(product:baseball, quantity:2) 12 | .addToOrderLines(product:football, quantity:1) 13 | .save() 14 | } 15 | } 16 | 17 | def destroy = { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/conf/UrlMappings.groovy: -------------------------------------------------------------------------------- 1 | class UrlMappings { 2 | 3 | static mappings = { 4 | "/$controller/$action?/$id?"{ 5 | constraints { 6 | // apply constraints here 7 | } 8 | } 9 | 10 | "/"(view:"/index") 11 | "500"(view:'/error') 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/conf/spring/resources.groovy: -------------------------------------------------------------------------------- 1 | // Place your Spring DSL code here 2 | beans = { 3 | } 4 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/controllers/mjg/CustomerController.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class CustomerController { 4 | static scaffold = true 5 | } 6 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/controllers/mjg/OrderController.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class OrderController { 4 | static scaffold = true 5 | } 6 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/controllers/mjg/OrderLineController.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class OrderLineController { 4 | static scaffold = true 5 | } 6 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/controllers/mjg/ProductController.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class ProductController { 4 | static scaffold = true 5 | } 6 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/domain/mjg/Customer.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class Customer { 4 | String name 5 | String toString() { name } 6 | 7 | static hasMany = [orders:Order] 8 | 9 | static constraints = { 10 | name blank: false 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/domain/mjg/Order.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import java.text.NumberFormat 4 | 5 | class Order { 6 | String number 7 | 8 | Date dateCreated 9 | Date lastUpdated 10 | 11 | static hasMany = [orderLines:OrderLine] 12 | static belongsTo = [customer:Customer] 13 | 14 | double getPrice() { 15 | orderLines*.price.sum() 16 | } 17 | 18 | String toString() { 19 | NumberFormat nf = NumberFormat.currencyInstance 20 | "#$number: ${orderLines.size()} lines, total cost ${nf.format(price)}" 21 | } 22 | 23 | static mapping = { 24 | table 'orders' 25 | orderLines fetch: 'join' 26 | } 27 | 28 | static constraints = { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/domain/mjg/OrderLine.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class OrderLine { 4 | Product product 5 | int quantity 6 | 7 | double getPrice() { quantity * product?.price } 8 | 9 | String toString() { 10 | "$quantity $product @ $product.price = $price" 11 | } 12 | 13 | static belongsTo = Order 14 | 15 | static constraints = { 16 | quantity min:0 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/domain/mjg/Product.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class Product { 4 | String name 5 | double price 6 | 7 | String toString() { name } 8 | 9 | static constraints = { 10 | name blank: false 11 | price min: 0.0d 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ch08/shopping/grails-app/views/error.gsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Grails Runtime Exception 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ch08/shopping/shopping.mwb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/shopping.mwb -------------------------------------------------------------------------------- /ch08/shopping/shopping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/shopping.png -------------------------------------------------------------------------------- /ch08/shopping/test/unit/mjg/CustomerControllerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | 4 | 5 | import grails.test.mixin.* 6 | import org.junit.* 7 | 8 | /** 9 | * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions 10 | */ 11 | @TestFor(CustomerController) 12 | class CustomerControllerTests { 13 | 14 | void testSomething() { 15 | assert 'scaffolded' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch08/shopping/test/unit/mjg/CustomerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import grails.test.mixin.* 4 | import org.junit.* 5 | 6 | @TestFor(Customer) 7 | class CustomerTests { 8 | Customer customer = new Customer(name: 'name') 9 | 10 | @Before 11 | void setUp() { 12 | mockForConstraintsTests(Customer) 13 | } 14 | 15 | void testValid() { 16 | assert customer.validate() 17 | } 18 | 19 | void testBlankName() { 20 | customer.name = ' ' 21 | assert !customer.validate() 22 | assert 'blank' == customer.errors['name'] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ch08/shopping/test/unit/mjg/OrderControllerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | 4 | 5 | import grails.test.mixin.* 6 | import org.junit.* 7 | 8 | /** 9 | * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions 10 | */ 11 | @TestFor(OrderController) 12 | class OrderControllerTests { 13 | 14 | void testSomething() { 15 | assert 'scaffolded' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch08/shopping/test/unit/mjg/OrderLineControllerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | 4 | 5 | import grails.test.mixin.* 6 | import org.junit.* 7 | 8 | /** 9 | * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions 10 | */ 11 | @TestFor(OrderLineController) 12 | class OrderLineControllerTests { 13 | 14 | void testSomething() { 15 | assert 'scaffolded' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch08/shopping/test/unit/mjg/OrderLineTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import grails.test.mixin.* 4 | import org.junit.* 5 | 6 | @TestFor(OrderLine) 7 | class OrderLineTests { 8 | OrderLine line 9 | 10 | @Before 11 | void setUp() { 12 | mockForConstraintsTests(OrderLine) 13 | Product p = new Product(name: 'p0', price: 2) 14 | line = new OrderLine(product: p, quantity: 3) 15 | } 16 | 17 | void testPrice() { 18 | assert 3 * 2 == line.price 19 | } 20 | 21 | void testValid() { 22 | assert line.validate() 23 | } 24 | 25 | void testNegQuantity() { 26 | line.quantity = -1 27 | assert !line.validate() 28 | assert 'min' == line.errors['quantity'] 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ch08/shopping/test/unit/mjg/OrderTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import grails.test.mixin.* 4 | import org.junit.* 5 | 6 | @TestFor(Order) 7 | class OrderTests { 8 | Order order 9 | Product p0 = new Product(name: 'p0', price: 2.5) 10 | Product p1 = new Product(name: 'p1', price: 3) 11 | Customer c = new Customer(name: 'c') 12 | 13 | @Before 14 | void setUp() { 15 | mockForConstraintsTests(Order) 16 | order = new Order(customer: c, number: 1) 17 | .addToOrderLines(new OrderLine(quantity: 2, product: p0)) 18 | .addToOrderLines(new OrderLine(quantity: 1, product: p1)) 19 | } 20 | 21 | void testPrice() { 22 | assert 8 == order.price 23 | } 24 | 25 | void testValid() { 26 | assert order.validate() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ch08/shopping/test/unit/mjg/ProductControllerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | 4 | 5 | import grails.test.mixin.* 6 | import org.junit.* 7 | 8 | /** 9 | * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions 10 | */ 11 | @TestFor(ProductController) 12 | class ProductControllerTests { 13 | 14 | void testSomething() { 15 | assert 'scaffolded' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch08/shopping/test/unit/mjg/ProductTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import grails.test.mixin.* 4 | import org.junit.* 5 | 6 | @TestFor(Product) 7 | class ProductTests { 8 | Product p = new Product(name: 'p0', price: 1) 9 | 10 | @Before 11 | void setUp() { 12 | mockForConstraintsTests(Product) 13 | } 14 | 15 | void testValid() { 16 | assert p.validate() 17 | } 18 | 19 | void testBlankName() { 20 | p.name = ' ' 21 | assert !p.validate() 22 | assert 'blank' == p.errors.name 23 | } 24 | 25 | void testNegativePrice() { 26 | p.price = -1 27 | assert !p.validate() 28 | assert 'min' == p.errors.price 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ch08/shopping/web-app/WEB-INF/sitemesh.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/apple-touch-icon-retina.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/apple-touch-icon-retina.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/apple-touch-icon.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/favicon.ico -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/grails_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/grails_logo.jpg -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/grails_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/grails_logo.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/leftnav_btm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/leftnav_btm.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/leftnav_midstretch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/leftnav_midstretch.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/leftnav_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/leftnav_top.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/database_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/database_add.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/database_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/database_delete.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/database_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/database_edit.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/database_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/database_save.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/database_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/database_table.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/exclamation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/exclamation.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/house.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/house.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/information.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/information.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/shadow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/shadow.jpg -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/sorted_asc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/sorted_asc.gif -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/skin/sorted_desc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/skin/sorted_desc.gif -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/spinner.gif -------------------------------------------------------------------------------- /ch08/shopping/web-app/images/springsource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch08/shopping/web-app/images/springsource.png -------------------------------------------------------------------------------- /ch08/shopping/web-app/js/application.js: -------------------------------------------------------------------------------- 1 | if (typeof jQuery !== 'undefined') { 2 | (function($) { 3 | $('#spinner').ajaxStart(function() { 4 | $(this).fadeIn(); 5 | }).ajaxStop(function() { 6 | $(this).fadeOut(); 7 | }); 8 | })(jQuery); 9 | } 10 | -------------------------------------------------------------------------------- /ch09/HelloRestlet/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | Servers 4 | .gradle 5 | .project 6 | .classpath 7 | .settings 8 | .metadata 9 | *.iml 10 | *.ipr 11 | *.iws 12 | -------------------------------------------------------------------------------- /ch09/HelloRestlet/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | maven { url "http://oss.sonatype.org/content/repositories/snapshots" } 8 | maven { url "http://maven.restlet.org" } 9 | } 10 | 11 | task wrapper(type:Wrapper) { 12 | gradleVersion = '2.0' 13 | } 14 | 15 | dependencies { 16 | compile 'org.codehaus.groovy:groovy-all:2.3.3' 17 | compile 'org.restlet.jse:org.restlet:2.1-RC6' 18 | compile 'org.restlet.jse:org.restlet.ext.simple:2.1-RC6' 19 | 20 | testCompile 'org.spockframework:spock-core:0.7-groovy-2.0-SNAPSHOT' 21 | } 22 | -------------------------------------------------------------------------------- /ch09/HelloRestlet/src/main/java/mjg/HelloRestlet.java: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | import org.restlet.Request; 4 | import org.restlet.Response; 5 | import org.restlet.Restlet; 6 | import org.restlet.Server; 7 | import org.restlet.data.MediaType; 8 | import org.restlet.data.Protocol; 9 | import org.restlet.resource.ClientResource; 10 | 11 | public class HelloRestlet { 12 | public static void main(String[] args) throws Exception { 13 | Server server = new Server(Protocol.HTTP, 8182, new Restlet() { 14 | @Override 15 | public void handle(Request request, Response response) { 16 | response.setEntity("Hello, World", MediaType.TEXT_PLAIN); 17 | } 18 | }); 19 | 20 | server.start(); 21 | 22 | new ClientResource("http://localhost:8182").get().write(System.out); 23 | 24 | server.stop(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ch09/HelloRestlet/src/main/java/mjg/HelloServerResource.java: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | import org.restlet.resource.Get; 4 | import org.restlet.resource.ServerResource; 5 | 6 | public class HelloServerResource extends ServerResource { 7 | @Get 8 | public String represent() { 9 | return "Hello, World!"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ch09/Jersey16/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | apply plugin:'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | task wrapper(type:Wrapper) { 10 | gradleVersion = '2.0' 11 | } 12 | 13 | dependencies { 14 | compile 'org.codehaus.groovy:groovy-all:2.3.3' 15 | compile 'asm:asm:3.3' 16 | compile 'com.sun.jersey:jersey-core:1.16' 17 | compile 'com.sun.jersey:jersey-server:1.16' 18 | compile 'com.sun.jersey:jersey-client:1.16' 19 | compile 'com.sun.jersey:jersey-grizzly2:1.16' 20 | compile 'com.sun.jersey:jersey-servlet:1.16' 21 | compile 'javax.servlet:javax.servlet-api:3.0.1' 22 | compile 'javax.ws.rs:jsr311-api:1.1.1' 23 | 24 | testCompile 'org.spockframework:spock-core:0.7-groovy-2.0' 25 | testCompile 'com.sun.jersey.jersey-test-framework:jersey-test-framework-core:1.16' 26 | testCompile 'com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly2:1.13' 27 | testCompile 'org.glassfish.grizzly:grizzly-http-servlet:2.2.4' 28 | } 29 | -------------------------------------------------------------------------------- /ch09/Jersey16/src/main/groovy/mjg/GroovyResource.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import javax.ws.rs.GET 4 | import javax.ws.rs.Path 5 | import javax.ws.rs.Produces 6 | 7 | @Path('/helloworld') 8 | class GroovyResource { 9 | @GET 10 | @Produces(["text/plain"]) 11 | def show() { 12 | "Hello, World!" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ch09/Jersey16/src/test/groovy/mjg/GroovyResourceTest.java: -------------------------------------------------------------------------------- 1 | package mjg; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.sun.jersey.api.client.WebResource; 8 | import com.sun.jersey.test.framework.JerseyTest; 9 | 10 | public class GroovyResourceTest extends JerseyTest { 11 | 12 | public GroovyResourceTest() { 13 | super("mjg"); 14 | } 15 | 16 | @Test 17 | public void testShow() { 18 | WebResource webResource = resource(); 19 | String responseMsg = webResource.path("helloworld").get(String.class); 20 | assertEquals("Hello, World!", responseMsg); 21 | } 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /ch09/people/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | db.h2.db 8 | -------------------------------------------------------------------------------- /ch09/people/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | maven { 8 | url 'https://maven.java.net/content/repositories/releases/' 9 | } 10 | } 11 | 12 | dependencies { 13 | compile 'org.codehaus.groovy:groovy-all:2.4.3' 14 | compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.0' 15 | compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.0' 16 | runtime "com.h2database:h2:1.3.148" 17 | testCompile "org.spockframework:spock-core:1.0-groovy-2.4" 18 | testCompile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6' 19 | } 20 | -------------------------------------------------------------------------------- /ch09/people/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/people/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch09/people/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Sep 26 19:29:22 EDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-all.zip 7 | -------------------------------------------------------------------------------- /ch09/people/src/main/groovy/mjg/rest/MyApplication.java: -------------------------------------------------------------------------------- 1 | package mjg.rest; 2 | 3 | import org.glassfish.jersey.jackson.JacksonFeature; 4 | import org.glassfish.jersey.server.ResourceConfig; 5 | 6 | public class MyApplication extends ResourceConfig { 7 | public MyApplication() { 8 | super(PersonResource.class, JacksonFeature.class); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ch09/people/src/main/groovy/mjg/rest/PersonDAO.java: -------------------------------------------------------------------------------- 1 | package mjg.rest; 2 | 3 | import java.util.List; 4 | 5 | public interface PersonDAO { 6 | List findAll(); 7 | Person findById(long id); 8 | List findByLastName(String name); 9 | Person create(Person c); 10 | Person update(Person c); 11 | boolean delete(long id); 12 | } 13 | -------------------------------------------------------------------------------- /ch09/people_hate/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .idea/ 5 | .project 6 | .classpath 7 | .settings 8 | db.h2.db 9 | db.trace.db 10 | -------------------------------------------------------------------------------- /ch09/people_hate/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /ch09/people_hate/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | maven { 8 | url 'https://maven.java.net/content/repositories/releases/' 9 | } 10 | } 11 | 12 | dependencies { 13 | compile 'org.codehaus.groovy:groovy-all:2.4.3' 14 | compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.0' 15 | compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.0' 16 | runtime "com.h2database:h2:1.3.148" 17 | testCompile "org.spockframework:spock-core:1.0-groovy-2.4" 18 | testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.6') { 19 | exclude group:'org.codehaus.groovy' 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ch09/people_hate/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/people_hate/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch09/people_hate/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 07 11:54:08 EST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip 7 | -------------------------------------------------------------------------------- /ch09/people_hate/src/main/groovy/mjg/rest/MyApplication.java: -------------------------------------------------------------------------------- 1 | package mjg.rest; 2 | 3 | import org.glassfish.jersey.jackson.JacksonFeature; 4 | import org.glassfish.jersey.server.ResourceConfig; 5 | 6 | public class MyApplication extends ResourceConfig { 7 | public MyApplication() { 8 | super(PersonResource.class, JacksonFeature.class); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ch09/people_hate/src/main/groovy/mjg/rest/PersonDAO.java: -------------------------------------------------------------------------------- 1 | package mjg.rest; 2 | 3 | import java.util.List; 4 | 5 | public interface PersonDAO { 6 | List findAll(); 7 | Person findById(long id); 8 | List findByLastName(String name); 9 | Person create(Person c); 10 | Person update(Person c); 11 | boolean delete(long id); 12 | Long getMinId(); 13 | Long getMaxId(); 14 | } 15 | -------------------------------------------------------------------------------- /ch09/people_java/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | db.h2.db 8 | -------------------------------------------------------------------------------- /ch09/people_java/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | maven { 8 | url 'https://maven.java.net/content/repositories/releases/' 9 | } 10 | } 11 | 12 | dependencies { 13 | compile 'org.codehaus.groovy:groovy-all:2.3.6' 14 | compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.0' 15 | compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.0' 16 | runtime "com.h2database:h2:1.3.148" 17 | testCompile "org.spockframework:spock-core:0.7-groovy-2.0" 18 | testCompile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6' 19 | } 20 | -------------------------------------------------------------------------------- /ch09/people_java/src/main/java/mjg/rest/MyApplication.java: -------------------------------------------------------------------------------- 1 | package mjg.rest; 2 | 3 | import org.glassfish.jersey.jackson.JacksonFeature; 4 | import org.glassfish.jersey.server.ResourceConfig; 5 | 6 | public class MyApplication extends ResourceConfig { 7 | public MyApplication() { 8 | super(PersonResource.class, JacksonFeature.class); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ch09/people_java/src/main/java/mjg/rest/PersonDAO.java: -------------------------------------------------------------------------------- 1 | package mjg.rest; 2 | 3 | import java.util.List; 4 | 5 | public interface PersonDAO { 6 | List findAll(); 7 | Person findById(long id); 8 | List findByLastName(String name); 9 | Person create(Person p); 10 | Person update(Person p); 11 | boolean delete(long id); 12 | } 13 | -------------------------------------------------------------------------------- /ch09/people_java/src/test/groovy/mjg/rest/PersonSpec.groovy: -------------------------------------------------------------------------------- 1 | package mjg.rest 2 | 3 | import spock.lang.Specification 4 | 5 | class PersonSpec extends Specification { 6 | 7 | def 'add to set to verify equals and hashcode'() { 8 | given: 'two equivalent people and one different one' 9 | Person p1 = new Person(first:'Johnathan', last:'Archer') 10 | Person p2 = new Person(first:'Johnathan', last:'Archer') 11 | Person p3 = new Person(first:'Peter Quincy', last:'Taggart') 12 | 13 | when: 'add them all to a set' 14 | Set people = [p1, p2, p3] 15 | 16 | then: 'set only contains two of them' 17 | people.size() == 2 18 | p1 == p2 19 | p1 != p3 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ch09/people_readwrite/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | db.h2.db 8 | -------------------------------------------------------------------------------- /ch09/people_readwrite/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'eclipse' 3 | apply plugin: 'idea' 4 | 5 | repositories { 6 | mavenCentral() 7 | maven { 8 | url 'https://maven.java.net/content/repositories/releases/' 9 | } 10 | } 11 | 12 | dependencies { 13 | compile 'org.codehaus.groovy:groovy-all:2.4.3' 14 | compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.0' 15 | compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.0' 16 | runtime "com.h2database:h2:1.3.148" 17 | testCompile "org.spockframework:spock-core:1.0-groovy-2.4" 18 | testCompile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6' 19 | } 20 | -------------------------------------------------------------------------------- /ch09/people_readwrite/src/main/groovy/mjg/rest/MyApplication.java: -------------------------------------------------------------------------------- 1 | package mjg.rest; 2 | 3 | import org.glassfish.jersey.jackson.JacksonFeature; 4 | import org.glassfish.jersey.server.ResourceConfig; 5 | 6 | public class MyApplication extends ResourceConfig { 7 | public MyApplication() { 8 | super(PersonResource.class, PersonProvider.class, JacksonFeature.class); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ch09/people_readwrite/src/main/groovy/mjg/rest/PersonDAO.java: -------------------------------------------------------------------------------- 1 | package mjg.rest; 2 | 3 | import java.util.List; 4 | 5 | public interface PersonDAO { 6 | List findAll(); 7 | Person findById(long id); 8 | List findByLastName(String name); 9 | Person create(Person c); 10 | Person update(Person c); 11 | boolean delete(long id); 12 | Long getMinId(); 13 | Long getMaxId(); 14 | } 15 | -------------------------------------------------------------------------------- /ch09/shopping/.gitignore: -------------------------------------------------------------------------------- 1 | *.iws 2 | *.iml 3 | *Db.properties 4 | *Db.script 5 | *.h2.db 6 | *.h2.data 7 | eclipse 8 | target-eclipse 9 | plugin.xml 10 | site-config.groovy 11 | stacktrace.log 12 | target 13 | /plugins 14 | /web-app/plugins 15 | /web-app/WEB-INF/classes 16 | build 17 | bin 18 | out 19 | .gradle 20 | .project 21 | .classpath 22 | .settings 23 | .idea 24 | -------------------------------------------------------------------------------- /ch09/shopping/application.properties: -------------------------------------------------------------------------------- 1 | #Grails Metadata file 2 | #Wed Jan 30 22:59:42 EST 2013 3 | app.grails.version=2.2.0 4 | app.name=shopping 5 | app.version=0.1 6 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/conf/ApplicationResources.groovy: -------------------------------------------------------------------------------- 1 | modules = { 2 | application { 3 | resource url:'js/application.js' 4 | } 5 | } -------------------------------------------------------------------------------- /ch09/shopping/grails-app/conf/BootStrap.groovy: -------------------------------------------------------------------------------- 1 | import mjg.* 2 | 3 | class BootStrap { 4 | 5 | def init = { servletContext -> 6 | Customer brown = new Customer(name: 'Charlie Brown').save() 7 | Product fb = new Product(name: 'football', price: 6).save() 8 | Product bb = new Product(name: 'baseball', price: 12).save() 9 | Order order = new Order(number: '1', customer: brown) 10 | .addToOrderLines(quantity: 2, product: fb) 11 | .addToOrderLines(quantity: 1, product: bb) 12 | .save(failOnError: true) 13 | } 14 | 15 | def destroy = { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/conf/UrlMappings.groovy: -------------------------------------------------------------------------------- 1 | class UrlMappings { 2 | 3 | static mappings = { 4 | "/$controller/$action?/$id?"{ 5 | constraints { 6 | // apply constraints here 7 | } 8 | } 9 | 10 | "/"(view:"/index") 11 | "500"(view:'/error') 12 | 13 | "/product/$id?"(resource: "product") 14 | "/customer/$id?"(resource: "customer") 15 | "/order/$id"(resource: "order") 16 | "/orderLine/$id"(resource: "orderLine") 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/conf/spring/resources.groovy: -------------------------------------------------------------------------------- 1 | // Place your Spring DSL code here 2 | beans = { 3 | } 4 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/controllers/mjg/CustomerController.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class CustomerController { 4 | static scaffold = true 5 | } 6 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/controllers/mjg/OrderController.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class OrderController { 4 | 5 | static scaffold = true 6 | } 7 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/controllers/mjg/OrderLineController.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class OrderLineController { 4 | 5 | static scaffold = true 6 | } 7 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/controllers/mjg/ProductController.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import grails.converters.JSON 4 | import grails.converters.XML 5 | 6 | class ProductController { 7 | 8 | static scaffold = true 9 | 10 | def list() { 11 | def products = Product.list() 12 | withFormat { 13 | html productList: products 14 | xml { render products as XML } 15 | json { render products as JSON } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/domain/mjg/Customer.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class Customer { 4 | String name 5 | 6 | String toString() { name } 7 | 8 | static hasMany = [orders:Order] 9 | 10 | static constraints = { 11 | name blank: false 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/domain/mjg/Order.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import java.text.NumberFormat 4 | 5 | class Order { 6 | String number 7 | 8 | static hasMany = [orderLines:OrderLine] 9 | static belongsTo = [customer:Customer] 10 | 11 | double getPrice() { 12 | orderLines*.price.sum() 13 | } 14 | 15 | String toString() { 16 | NumberFormat nf = NumberFormat.currencyInstance 17 | "#$number: ${orderLines.size()} lines, total cost ${nf.format(price)}" 18 | } 19 | 20 | static mapping = { 21 | table 'orders' 22 | orderLines fetch: 'join' 23 | } 24 | 25 | static constraints = { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/domain/mjg/OrderLine.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class OrderLine { 4 | Product product 5 | int quantity 6 | 7 | double getPrice() { quantity * product.price } 8 | 9 | String toString() { "$quantity $product @ $product.price = $price" } 10 | 11 | static constraints = { 12 | quantity min: 0 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/domain/mjg/Product.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | class Product { 4 | String name 5 | double price 6 | 7 | String toString() { name } 8 | 9 | static constraints = { 10 | name blank: false 11 | price min: 0.0d 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ch09/shopping/grails-app/views/error.gsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <g:if env="development">Grails Runtime Exception</g:if><g:else>Error</g:else> 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
    14 |
  • An error has occurred
  • 15 |
16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /ch09/shopping/test/unit/mjg/CustomerControllerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | 4 | 5 | import grails.test.mixin.* 6 | import org.junit.* 7 | 8 | /** 9 | * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions 10 | */ 11 | @TestFor(CustomerController) 12 | class CustomerControllerTests { 13 | 14 | void testSomething() { 15 | assert 'scaffolded' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch09/shopping/test/unit/mjg/CustomerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import grails.test.mixin.* 4 | import org.junit.* 5 | 6 | @TestFor(Customer) 7 | class CustomerTests { 8 | Customer customer = new Customer(name: 'name') 9 | 10 | @Before 11 | void setUp() { 12 | mockForConstraintsTests(Customer) 13 | } 14 | 15 | void testValid() { 16 | assert customer.validate() 17 | } 18 | 19 | void testBlankName() { 20 | customer.name = ' ' 21 | assert !customer.validate() 22 | assert 'blank' == customer.errors['name'] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ch09/shopping/test/unit/mjg/OrderControllerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | 4 | 5 | import grails.test.mixin.* 6 | import org.junit.* 7 | 8 | /** 9 | * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions 10 | */ 11 | @TestFor(OrderController) 12 | class OrderControllerTests { 13 | 14 | void testSomething() { 15 | assert 'scaffolded' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch09/shopping/test/unit/mjg/OrderLineControllerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | 4 | 5 | import grails.test.mixin.* 6 | import org.junit.* 7 | 8 | /** 9 | * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions 10 | */ 11 | @TestFor(OrderLineController) 12 | class OrderLineControllerTests { 13 | 14 | void testSomething() { 15 | assert 'scaffolded' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch09/shopping/test/unit/mjg/OrderLineTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import grails.test.mixin.* 4 | import org.junit.* 5 | 6 | @TestFor(OrderLine) 7 | class OrderLineTests { 8 | OrderLine line 9 | 10 | @Before 11 | void setUp() { 12 | mockForConstraintsTests(OrderLine) 13 | Product p = new Product(name: 'p0', price: 2) 14 | line = new OrderLine(product: p, quantity: 3) 15 | } 16 | 17 | void testPrice() { 18 | assert 3 * 2 == line.price 19 | } 20 | 21 | void testValid() { 22 | assert line.validate() 23 | } 24 | 25 | void testNegQuantity() { 26 | line.quantity = -1 27 | assert !line.validate() 28 | assert 'min' == line.errors['quantity'] 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ch09/shopping/test/unit/mjg/OrderTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import grails.test.mixin.* 4 | import org.junit.* 5 | 6 | @TestFor(Order) 7 | class OrderTests { 8 | Order order 9 | Product p0 = new Product(name: 'p0', price: 2.5) 10 | Product p1 = new Product(name: 'p1', price: 3) 11 | Customer c = new Customer(name: 'c') 12 | 13 | @Before 14 | void setUp() { 15 | mockForConstraintsTests(Order) 16 | order = new Order(customer: c, number: 1) 17 | .addToOrderLines(new OrderLine(quantity: 2, product: p0)) 18 | .addToOrderLines(new OrderLine(quantity: 1, product: p1)) 19 | } 20 | 21 | void testPrice() { 22 | assert 8 == order.price 23 | } 24 | 25 | void testValid() { 26 | assert order.validate() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ch09/shopping/test/unit/mjg/ProductControllerTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | 4 | 5 | import grails.test.mixin.* 6 | import org.junit.* 7 | 8 | /** 9 | * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions 10 | */ 11 | @TestFor(ProductController) 12 | class ProductControllerTests { 13 | 14 | void testSomething() { 15 | assert 'scaffolded' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ch09/shopping/test/unit/mjg/ProductTests.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import grails.test.mixin.* 4 | import org.junit.* 5 | 6 | @TestFor(Product) 7 | class ProductTests { 8 | Product p = new Product(name: 'p0', price: 1) 9 | 10 | @Before 11 | void setUp() { 12 | mockForConstraintsTests(Product) 13 | } 14 | 15 | void testValid() { 16 | assert p.validate() 17 | } 18 | 19 | void testBlankName() { 20 | p.name = ' ' 21 | assert !p.validate() 22 | assert 'blank' == p.errors.name 23 | } 24 | 25 | void testNegativePrice() { 26 | p.price = -1 27 | assert !p.validate() 28 | assert 'min' == p.errors.price 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ch09/shopping/web-app/WEB-INF/sitemesh.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/apple-touch-icon-retina.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/apple-touch-icon-retina.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/apple-touch-icon.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/favicon.ico -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/grails_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/grails_logo.jpg -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/grails_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/grails_logo.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/leftnav_btm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/leftnav_btm.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/leftnav_midstretch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/leftnav_midstretch.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/leftnav_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/leftnav_top.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/database_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/database_add.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/database_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/database_delete.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/database_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/database_edit.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/database_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/database_save.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/database_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/database_table.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/exclamation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/exclamation.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/house.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/house.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/information.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/information.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/shadow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/shadow.jpg -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/sorted_asc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/sorted_asc.gif -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/skin/sorted_desc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/skin/sorted_desc.gif -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/spinner.gif -------------------------------------------------------------------------------- /ch09/shopping/web-app/images/springsource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch09/shopping/web-app/images/springsource.png -------------------------------------------------------------------------------- /ch09/shopping/web-app/js/application.js: -------------------------------------------------------------------------------- 1 | if (typeof jQuery !== 'undefined') { 2 | (function($) { 3 | $('#spinner').ajaxStart(function() { 4 | $(this).fadeIn(); 5 | }).ajaxStop(function() { 6 | $(this).fadeOut(); 7 | }); 8 | })(jQuery); 9 | } 10 | -------------------------------------------------------------------------------- /ch10/CategoryDemo/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /ch10/CategoryDemo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'eclipse' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | 8 | task wrapper(type:Wrapper) { 9 | gradleVersion = '2.0' 10 | } 11 | 12 | dependencies { 13 | compile "org.codehaus.groovy:groovy-all:2.3.3" 14 | 15 | testCompile "junit:junit:4.10" 16 | } 17 | -------------------------------------------------------------------------------- /ch10/CategoryDemo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/CategoryDemo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch10/CategoryDemo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 09:10:11 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch10/CategoryDemo/src/main/groovy/mjg/AnnotationCurrencyCategory.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import java.text.NumberFormat 4 | 5 | @Category(Number) 6 | class AnnotationCurrencyCategory { 7 | String asCurrency() { 8 | NumberFormat.currencyInstance.format(this) 9 | } 10 | 11 | String asCurrency(Locale loc) { 12 | NumberFormat.getCurrencyInstance(loc).format(this) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ch10/CategoryDemo/src/main/groovy/mjg/CurrencyCategory.groovy: -------------------------------------------------------------------------------- 1 | package mjg 2 | 3 | import java.text.NumberFormat 4 | 5 | class CurrencyCategory { 6 | static String asCurrency(Number amount) { 7 | NumberFormat.currencyInstance.format(amount) 8 | } 9 | 10 | static String asCurrency(Number amount, Locale loc) { 11 | NumberFormat.getCurrencyInstance(loc).format(amount) 12 | } 13 | } -------------------------------------------------------------------------------- /ch10/HelloGroovlet/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'groovy' 2 | apply plugin:'war' 3 | apply plugin:'jetty' 4 | apply plugin:'eclipse' 5 | apply plugin:'eclipse-wtp' 6 | apply plugin:'idea' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | sourceSets { 13 | integrationTest 14 | } 15 | 16 | httpPort = 8163 17 | stopPort = 9451 18 | stopKey = 'foo' 19 | 20 | [jettyRun, jettyRunWar]*.daemon = true 21 | 22 | task intTest(type: Test, dependsOn: jettyRun) { 23 | testClassesDir = sourceSets.integrationTest.output.classesDir 24 | classpath = sourceSets.integrationTest.runtimeClasspath 25 | jettyStop.execute() 26 | } 27 | 28 | check.dependsOn intTest 29 | 30 | task wrapper(type:Wrapper) { 31 | gradleVersion = '2.0' 32 | } 33 | 34 | dependencies { 35 | compile "org.codehaus.groovy:groovy-all:2.3.3" 36 | 37 | testCompile "junit:junit:4.10" 38 | 39 | integrationTestCompile configurations.testCompile 40 | integrationTestRuntime configurations.testRuntime 41 | } 42 | -------------------------------------------------------------------------------- /ch10/HelloGroovlet/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/HelloGroovlet/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch10/HelloGroovlet/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 09:10:55 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch10/HelloGroovlet/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | GroovyServlet 11 | groovy.servlet.GroovyServlet 12 | 13 | 14 | GroovyServlet 15 | *.groovy 16 | 17 | 18 | -------------------------------------------------------------------------------- /ch10/HelloGroovlet/src/main/webapp/hello.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | name = params.name ?: 'World' 17 | println "Hello, $name!" -------------------------------------------------------------------------------- /ch10/HelloServlet/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /ch10/HelloServlet/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/HelloServlet/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch10/HelloServlet/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 09:11:37 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch10/HelloServlet/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | hello 11 | mjg.HelloServlet 12 | 13 | 14 | hello 15 | /hello 16 | 17 | 18 | hellogs 19 | mjg.HelloGroovyServlet 20 | 21 | 22 | hellogs 23 | /hellogs 24 | 25 | 26 | -------------------------------------------------------------------------------- /ch10/HelloServletWithHttpBuilder/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /ch10/HelloServletWithHttpBuilder/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | hello 11 | mjg.HelloServlet 12 | 13 | 14 | hello 15 | /hello 16 | 17 | 18 | hellogs 19 | mjg.HelloGroovyServlet 20 | 21 | 22 | hellogs 23 | /hellogs 24 | 25 | 26 | -------------------------------------------------------------------------------- /ch10/HelloServletWithHttpBuilder/src/main/webapp/hello.gsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello, Servlet 4 | 5 | 6 | <% use (groovy.servlet.ServletCategory) { %> 7 |

Hello, ${request.name}!

8 | <% } %> 9 | 10 | -------------------------------------------------------------------------------- /ch10/HelloServletWithHttpBuilder/src/main/webapp/hello.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello, JSP 5 | 6 | 7 |

Hello, ${name}!

8 |

The servlet has been accessed ${session.count} times

9 | 10 | -------------------------------------------------------------------------------- /ch10/SongService/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | .gradle 4 | .project 5 | .classpath 6 | .settings 7 | -------------------------------------------------------------------------------- /ch10/SongService/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/SongService/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ch10/SongService/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 01 09:14:24 EDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /ch10/SongService/src/main/groovy/mjg/Song.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg; 17 | 18 | class Song { 19 | String id 20 | String title 21 | String artist 22 | String year 23 | } 24 | -------------------------------------------------------------------------------- /ch10/SongService/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 14 | 15 | -------------------------------------------------------------------------------- /ch10/SongService/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | GroovyServlet 11 | groovy.servlet.GroovyServlet 12 | 13 | 14 | GroovyServlet 15 | *.groovy 16 | 17 | 18 | -------------------------------------------------------------------------------- /ch10/holygrails/.gitignore: -------------------------------------------------------------------------------- 1 | *.iws 2 | *Db.properties 3 | *Db.script 4 | *.h2.db 5 | *.h2.data 6 | eclipse 7 | target-eclipse 8 | plugin.xml 9 | site-config.groovy 10 | stacktrace.log 11 | target 12 | /plugins 13 | /web-app/plugins 14 | /web-app/WEB-INF/classes 15 | build 16 | bin 17 | .gradle 18 | .project 19 | .classpath 20 | .settings 21 | -------------------------------------------------------------------------------- /ch10/holygrails/application.properties: -------------------------------------------------------------------------------- 1 | #Grails Metadata file 2 | #Mon Jul 01 00:46:53 CDT 2013 3 | app.grails.version=2.2.3 4 | app.name=holygrails 5 | app.servlet.version=2.5 6 | app.version=0.1 7 | plugins.google-visualization=0.5 8 | -------------------------------------------------------------------------------- /ch10/holygrails/grails-app/conf/ApplicationResources.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | modules = { 17 | application { 18 | resource url:'js/application.js' 19 | } 20 | } -------------------------------------------------------------------------------- /ch10/holygrails/grails-app/conf/UrlMappings.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | class UrlMappings { 17 | 18 | static mappings = { 19 | "/$controller/$action?/$id?"{ 20 | constraints { 21 | // apply constraints here 22 | } 23 | } 24 | 25 | "/"(view:"/index") 26 | "500"(view:'/error') 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ch10/holygrails/grails-app/conf/spring/resources.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | // Place your Spring DSL code here 17 | beans = { 18 | } 19 | -------------------------------------------------------------------------------- /ch10/holygrails/grails-app/controllers/mjg/KnightController.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | class KnightController { 19 | 20 | def scaffold = Knight 21 | } 22 | -------------------------------------------------------------------------------- /ch10/holygrails/grails-app/controllers/mjg/QuestController.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | class QuestController { 19 | 20 | def scaffold = Quest 21 | } 22 | -------------------------------------------------------------------------------- /ch10/holygrails/grails-app/controllers/mjg/TaskController.groovy: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * Copyright 2012 Kousen IT, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ========================================================== */ 16 | package mjg 17 | 18 | class TaskController { 19 | 20 | def scaffold = Task 21 | } 22 | -------------------------------------------------------------------------------- /ch10/holygrails/grails-app/views/error.gsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Grails Runtime Exception 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ch10/holygrails/web-app/WEB-INF/sitemesh.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/apple-touch-icon-retina.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/apple-touch-icon-retina.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/apple-touch-icon.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/favicon.ico -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/grails_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/grails_logo.jpg -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/grails_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/grails_logo.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/leftnav_btm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/leftnav_btm.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/leftnav_midstretch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/leftnav_midstretch.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/leftnav_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/leftnav_top.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/database_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/database_add.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/database_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/database_delete.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/database_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/database_edit.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/database_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/database_save.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/database_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/database_table.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/exclamation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/exclamation.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/house.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/house.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/information.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/information.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/shadow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/shadow.jpg -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/sorted_asc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/sorted_asc.gif -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/skin/sorted_desc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/skin/sorted_desc.gif -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/spinner.gif -------------------------------------------------------------------------------- /ch10/holygrails/web-app/images/springsource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kousen/Making-Java-Groovy/8d7e95b90155da0b1bd4a395230c11bd6672ff9c/ch10/holygrails/web-app/images/springsource.png -------------------------------------------------------------------------------- /ch10/holygrails/web-app/js/application.js: -------------------------------------------------------------------------------- 1 | if (typeof jQuery !== 'undefined') { 2 | (function($) { 3 | $('#spinner').ajaxStart(function() { 4 | $(this).fadeIn(); 5 | }).ajaxStop(function() { 6 | $(this).fadeOut(); 7 | }); 8 | })(jQuery); 9 | } 10 | --------------------------------------------------------------------------------