Groovy para programadores Java
-
Upload
alberto-vilches -
Category
Technology
-
view
4.856 -
download
0
description
Transcript of Groovy para programadores Java
![Page 1: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/1.jpg)
GROOVY PARA PROGRAMADORES JAVA
por Alberto Vilches http://albertovilches.com
Twitter: @albertovilches
![Page 2: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/2.jpg)
SOBRE MI
Alberto Vilches
• Programador freelance en Grails y Flex
• Evangelizador Groovy y Grails
• http://albertovilches.com
• Twitter: @albertovilches
![Page 3: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/3.jpg)
AGENDA
• Antes de empezar • Qué es Groovy • Groovy Console • Testing con Groovy • Compilandor • Config Slurper • Algunas cosas más
![Page 4: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/4.jpg)
ANTES DE EMPEZAR
GROOVY != GRAILS
![Page 5: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/5.jpg)
¿QUÉ DIFERENCIA HAY?
Groovy -> Lenguaje
Grails -> Plataforma desarrollo Web
![Page 6: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/6.jpg)
¿QUÉ DIFERENCIA HAY?
Groovy -> Lenguaje Compilador y GDK
• groovy-1.8.jar
Grails -> Plataforma desarrollo Web
Groovy + Spring + Hibernate + Sitemesh + DBCP + Apache commons + Log4J + Junit + Ant +
![Page 7: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/7.jpg)
ANTES DE EMPEZAR
![Page 8: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/8.jpg)
ANTES DE EMPEZAR
JPA
Java app
![Page 9: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/9.jpg)
ANTES DE EMPEZAR
¡No necesito Grails para usar Groovy
desde mi aplicación Java!
![Page 10: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/10.jpg)
¿QUÉ ES GROOVY?
• Groovy es Java • Dinámico • Inspirado en Ruby, Python y Smalltalk • OOP puro • Closures, Gstrings, Builders, DSL
![Page 11: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/11.jpg)
¿QUÉ ES GROOVY?
• Groovy es Java. • Dinámico • Inspirado en Ruby, Python y Smalltalk • OOP puro • Closures, Gstrings, Builders, DSL • No compile type-checking • Ligeramente más lento que Java
![Page 12: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/12.jpg)
Groovy Console
![Page 13: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/13.jpg)
GROOVY CONSOLE
http://groovyconsole.appspot.com
groovyConsole App
![Page 14: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/14.jpg)
Testing
![Page 15: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/15.jpg)
TESTING CON GROOVY
• Power Asserts
• GroovyTestCase
• Mocking • Closure as OnlyOneMethodInterface • Map as Interface • Expando • MOP • mockFor / stubFor
![Page 16: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/16.jpg)
GROOVY POWER ASSERTS
![Page 17: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/17.jpg)
GROOVY POWER ASSERTS
![Page 18: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/18.jpg)
GROOVY POWER ASSERTS
![Page 19: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/19.jpg)
GROOVY TEST CASE
• Añade nuevos assert*
• Y algunos métodos como shouldFail o notImplementedYet
• Nombres de métodos largos
![Page 20: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/20.jpg)
GROOVY TEST CASE
• Añade nuevos assert*
• Y algunos métodos como shouldFail o notImplementedYet
• Nombres de métodos largos
![Page 21: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/21.jpg)
MOCKING CON GROOVY
Closure as OnlyMethodInterface
![Page 22: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/22.jpg)
MOCKING CON GROOVY
Map as Interface
![Page 23: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/23.jpg)
MOCKING CON GROOVY
MOP: Meta Object Protocol
![Page 24: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/24.jpg)
MOCKING CON GROOVY
Expando
![Page 25: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/25.jpg)
MOCKING CON GROOVY
a
![Page 26: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/26.jpg)
MOCKING CON GROOVY
a
![Page 27: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/27.jpg)
MOCKING CON GROOVY
a
![Page 28: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/28.jpg)
TESTING
¿Qué necesito para usar todo esto?
• groovy-1.8.jar en tu CLASSPATH
• Tus tests deben ser clases Groovy
• Heredar de GroovyTestCase (opcional)
![Page 29: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/29.jpg)
TESTING: SPOCK
• http://code.google.com/p/spock/
![Page 30: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/30.jpg)
Compilador
![Page 31: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/31.jpg)
COMPILADOR
Leer
Compilar
Cargar
![Page 32: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/32.jpg)
COMPILADOR
![Page 33: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/33.jpg)
COMPILADOR: LEER
![Page 34: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/34.jpg)
COMPILADOR: COMPILAR
![Page 35: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/35.jpg)
COMPILADOR: CARGAR
![Page 36: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/36.jpg)
COMPILADOR: CARGAR
![Page 37: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/37.jpg)
COMPILADOR GROOVY
• GroovyShell
• Script
• Eval.me()
![Page 38: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/38.jpg)
COMPILADOR: LEER
![Page 39: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/39.jpg)
COMPILADOR: LEER
![Page 40: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/40.jpg)
COMPILADOR: LEER
![Page 41: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/41.jpg)
COMPILADOR
¡Leer + compilar + cargar + ejecutar!
![Page 42: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/42.jpg)
COMPILADOR
¡Leer + compilar + cargar + ejecutar!
![Page 43: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/43.jpg)
COMPILADOR
¡Leer + compilar + cargar + ejecutar!
baseImponible IRPF IVA codigo
String
ENTRADA
SALIDA
![Page 44: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/44.jpg)
COMPILADOR
¡Leer + compilar + cargar + ejecutar!
baseImponible IRPF IVA codigo
String
ENTRADA
SALIDA
![Page 45: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/45.jpg)
COMPILADOR
¡Leer + compilar + cargar + ejecutar!
baseImponible IRPF IVA codigo
String
ENTRADA
SALIDA
![Page 46: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/46.jpg)
Config Slurper
![Page 47: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/47.jpg)
CONFIG SLURPER
• Alternativa a los ficheros Properties
• No texto plano -> ¡código groovy! • Valores nativos, no solo Strings • Anidado opcional
![Page 48: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/48.jpg)
CONFIG SLURPER
![Page 49: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/49.jpg)
CONFIG SLURPER
![Page 50: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/50.jpg)
CONFIG SLURPER
![Page 51: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/51.jpg)
CONFIG SLURPER
![Page 52: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/52.jpg)
CONFIG SLURPER
![Page 53: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/53.jpg)
CONFIG SLURPER
![Page 54: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/54.jpg)
Y muchas cosas más…
![Page 55: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/55.jpg)
SCRIPTS + SQL
• a
![Page 56: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/56.jpg)
SCRIPTS + SQL
• a
![Page 57: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/57.jpg)
DSLS Y BUILDERS
• a
![Page 58: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/58.jpg)
¡GRACIAS!
¡¡¡¡NO!!!! ¿TE HA PARECIDO POCO?
![Page 59: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/59.jpg)
GREACH = EVENTO DEDICADO A GROOVY
![Page 60: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/60.jpg)
• 10€ (incluye comida)
![Page 61: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/61.jpg)
• 10€ (incluye comida) • En Madrid, 4 de Nov. de 2011
![Page 62: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/62.jpg)
• 10€ (incluye comida) • En Madrid, 4 de Nov. de 2011 • Apúntate en http://greach.es
![Page 63: Groovy para programadores Java](https://reader037.fdocument.pub/reader037/viewer/2022103017/5578ec44d8b42a5c5c8b4dbb/html5/thumbnails/63.jpg)
¡GRACIAS!
¡Hasta la próxima!