Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Groovy journey in Open Source -- Greach 2016

A Groovy journey in Open Source -- Greach 2016

137d3908243acfc30e126615d59d4e6d?s=128

Guillaume Laforge

April 08, 2016
Tweet

More Decks by Guillaume Laforge

Other Decks in Technology

Transcript

  1. A Groovy Journey in Open Source

  2. We know about APIs! http://restlet.com

  3. We know about APIs! http://restlet.com

  4. None
  5. GR8Conf Promo Code: ctwgreach http://www.manning.com/koenig2/ GROOVY IN ACTION 2ND EDITION

  6. From 2003 onward…

  7. 2003

  8. Bob McWhirter James Strachan

  9. Bob McWhirter James Strachan James Strachan and Bob McWhirter gave

    birth to Groovy: a dynamic and agile scripting language for the JVM. […] James always used to say that it was all Bob's fault, but indeed, James had so many groovy ideas that it's hard to believe it's not his own fault. He kept saying: "Wouldn't it be groovy if we could do this and that...". Hence the name "Groovy". That's roughly how it all started.
  10. None
  11. 8 Groovy pre-1.0 • Closures available since 2003 on Java

    1.4+ • All the nice shortcuts already, inspired by Python & Ruby • native syntax for lists, maps, etc… • Tons of useful methods to simplify 
 common Java boiler-plate code • Initially dynamically-typed only
  12. None
  13. I join the project in 2003, patches after patches, become

    committer, then lead when founders left
  14. 2004

  15. 5

  16. 12 Groovy in 2004 • A brand new parser based

    on Antlr • after two hand-rolled versions • by John Rose and Jeremy Rainer • Jochen « blackdrag » Theodorou joins the project
  17. None
  18. None
  19. 2005

  20. None
  21. 2006

  22. 6

  23. 18 First paid committer • Jochen becomes the first full-time

    paid committer • sponsored by BigSky Technologies / No Fluff Just Stuff
  24. 2007

  25. None
  26. 1.0

  27. None
  28. None
  29. None
  30. None
  31. None
  32. Spock the Enterprise testing framework

  33. 25 Groovy in 2007 — Groovy 1.5 • The long

    awaited Java 5 update • annotations, enums, generics… • Joint compiler! • Varargs support • Static imports (including import aliasing) • Named parameters without parentheses
  34. None
  35. Paul King, #1 committer from 2007 to 2010, and overall

    #1 committer too!
  36. 2008

  37. None
  38. None
  39. 30 Griffon and Easyb

  40. 31 Groovy++ fork! • Not the first fork, but 3rd

    • by Alex Tkachman (former G2One co-founder) • Big focus on static compilation • interesting playground for our forthcoming static type checking and static compilation support
  41. 2009

  42. I can honestly say if someone had shown me the

    Programming Scala book back in 2003, I’d probably have never created Groovy
  43. Have I had JPA back then, I would certainly not

    have created Hibernate!
  44. None
  45. None
  46. None
  47. None
  48. None
  49. None
  50. None
  51. None
  52. None
  53. None
  54. None
  55. 40 The Groovy Ecosystem grows…

  56. 41 Groovy 1.6 • Performance improvements with call-site caching •

    Multiple assignments • Optional return in if/else, try/catch, switch/case • More AST transformations • @Singleton, @Lazy, @Immutable, @Delegate • The Grape module system with @Grab • OSGi support
  57. 42 Groovy 1.7 • Nested and inner classes, and nested

    static classes • Missing annotation definition support • Power Asserts from Spock • Customize the Groovy Truth! • AST viewer and AST builder • SQL support improvements
  58. 2010

  59. 44 Groovy ecosystem marching on… GContracts

  60. 2011

  61. None
  62. 7

  63. 48 More Groovy ecosystem…

  64. 49 Groovy 1.8 • Command chain expressions • GPars bundled

    with the Groovy distribution • Primitive calculation optimizations • Closures • as annotation parameters • currying, memoization and tail recursion • Built-in JSON support
  65. I’m joining the Groovy team!

  66. None
  67. 2012

  68. 53 Groovy ecosystem continued… • Netflix • Asgard, • Zuul

    • LinkedIn Glu • GroovyStream
  69. 54 Groovy 2.0 • Static type checking and static compilation

    • type inference, flow typing… • « Project Coin » enhancements • binary literals, underscore in numbers, multicatch block • Initial « invoke dynamic » support • Modularity of the Groovy code base with modules
  70. 2013

  71. None
  72. 57 Richer Groovy ecosystem…

  73. 58 Groovy 2.1 • Full « invoke dynamic » support

    • Type-checking extensions • Meta-annotations • @DelegatesTo annotation • Compiler customization scripts • Distribution bundling GPars 1.0
  74. 59 Groovy 2.2 • Implicit closure coercion to SAM types

    • Java lambda friendly! • Pre-compiled type checking extensions • @Memoized transformations for methods
  75. 2014

  76. 8

  77. 62 Groovy ecosystem

  78. 63 Groovy 2.3 • Traits! • Improved JDK 8 support

    • Drastic performance improvement for JSON • New AST transformations & improvements • @Builder,@Sortable,@SourceURI, @BaseScript • New markup template engine • More NIO support
  79. A look back at the past year+

  80. FIRED!

  81. MARCH 31st

  82. MARCH 31st RELEASE GROOVY 2.4 GRAILS 3.0

  83. None
  84. What could possibly go wrong?

  85. None
  86. THE CODEHAUS DEMISE

  87. IMPACT?

  88. 2012 2013 2014 2015 Downloads

  89. 2012 2013 2014 2015 1.7M 3M 4.5M ? Downloads

  90. 8 MILLIONS FROM MAVEN CENTRAL IN 2015

  91. MAVEN CENTRAL ONLY

  92. MAVEN CENTRAL ONLY +CODEHAUS LEGACY

  93. MAVEN CENTRAL ONLY +CODEHAUS LEGACY +BINTRAY

  94. 4.7 MILLIONS FROM BINTRAY

  95. 12.7 MILLIONS

  96. 4.7 MILLIONS ALREADY IN 2016/Q1

  97. GROOVY 2.4

  98. 77 Groovy 2.4 — Android support • Write your Android

    applications fully in Groovy! • Dedicated Gradle plugin
  99. 77 Groovy 2.4 — Android support • Write your Android

    applications fully in Groovy! • Dedicated Gradle plugin
  100. 78 Groovy 2.4 — Android support SwissKnife
 a dedicated 


    Groovy / Android 
 library
  101. 79 Groovy 2.4 — Performance & bytecode • Improved bytecode

    • cheaper comparison operations • optimization of primitive type coercions with ‘as’ • Reduced bytecode size • no MOP generated methods in static context • uneeded inner class distributor methods when no inner • timestamp removal • Reduced memory consumption
  102. 80 Groovy 2.4 — Traits @SelfType class Component {
 void

    doSomething() {
 println "Done!"
 }
 }
  103. 80 Groovy 2.4 — Traits @SelfType class Component {
 void

    doSomething() {
 println "Done!"
 }
 } import groovy.transform.* 
 @SelfType(Component)
 @TypeChecked
 trait ComponentDecorator {
 void logAndDoSomething() {
 println "Going to do something"
 doSomething()
 }
 }
  104. 80 Groovy 2.4 — Traits @SelfType class Component {
 void

    doSomething() {
 println "Done!"
 }
 } import groovy.transform.* 
 @SelfType(Component)
 @TypeChecked
 trait ComponentDecorator {
 void logAndDoSomething() {
 println "Going to do something"
 doSomething()
 }
 } class ConcreteComponent
 extends Component
 implements ComponentDecorator {}
 
 def c = new ConcreteComponent()
 c.logAndDoSomething()
  105. 81 Groovy 2.4 — GDK improvements • New methods •

    System.currentTimeSeconds() • List: removeAt(index), getIndices() • Collection: removeElement(Object) • Iterable: disjoin(), size(), dropRight(), takeRight() • More collection methods moved to iterator-based • Favor stream-like traversal methods leveraging iterables • Consistency for mutation in place vs new collection creation
  106. 82 Groovy 2.4 — AST transformations • @ToString added includeSuperProperties

    parameter • Can define compilation phase for @ASTTest • @Synchronized supports explicit static locks used by instance methods if needed • Cleaned-up code for @AutoExternalizable and @EqualsAndHashCode when used with @CompileStatic • Improved Java integration for @Builder • @PackageScope allowed on constructors
  107. 83 Groovy 2.4 — Groovysh improvements • Custom .rc and

    .profile scripts • instanceof completion • Static members completion only in a static context • Completion candidates in color • :set interpreterMode to remember locally-defined variables • :load command supports file names with spaces • Align arguments & flags with the groovy command • Script launch on startup & continue execution of Groovysh • Easier to subclass Groovysh for embedded reuse
  108. And what happened next?

  109. MUSICAL CHAIRS

  110. GRAILS GROOVY CEDRIC GUILLAUME JOCHEN LARI JEFF GRAEME

  111. GRAILS GROOVY CEDRIC GUILLAUME JOCHEN LARI JEFF GRAEME

  112. None
  113. MESSAGE TO THE COMMUNITY

  114. HERE TO STAY

  115. HERE TO STAY INDEPENDENCE

  116. HERE TO STAY COMMUNITY ABOVE ALL INDEPENDENCE

  117. APACHE INCUBATOR

  118. APACHE INCUBATOR MARCH 2015

  119. 91 Incubation — mentors • Emmanuel Lécharny • Bertrand Delacrétaz

    • Roman Shaposhnik • Jim Jagielski • Andrew Bayer
  120. 92 Incubation — initial committers • Paul King • Cédric

    Champeau • Pascal Schumacher • Jochen Theodorou • Guillaume Laforge
  121. 93 New committers • Joined the project as committer afterwards

    • Andrés Almiray • Dierk König • Russel Winder • Shil Sinha • Graeme Rocher • John Wagenleitner
  122. 94 Infrastructure • Everything migrated to the Apache infrastructure •

    Mailing-lists • JIRA • Sources moved to Apache’s Git • with a mirror on Github • Still need to see what we do 
 with the groovy-lang.org website Please Star it!
  123. 95 Top Level Project at Apache! • PMC & Incubator

    PMC voted for graduation • Apache Board agreed to the graduation! • (last November) • Call us Apache Groovy :-) • 2.4.6 was released on February 2016
  124. 96 Entering the TIOBE index • 3 months in a

    row in the top-20 TIOBE index • 17th for January • 20th for February • 17th for March
  125. Little nuggets… For Groovy 2.4.4+ and Groovy 2.5

  126. 98 Groovy 2.4.4/5/6 / 2.5 • Improved compiler performance •

    with an ASM class reader • @Canonical becomes a meta-annotation • More control on the meta-annotation collector • New @MapConstructor transformation • Property validation in transformation parameters • Further AST transformation improvements
  127. 99 @Canonical becomes a meta-annotation import groovy.transform.*
 
 @Canonical(includeNames =

    true)
 class Person {
 String name
 int age
 }
 
 assert new Person('Guillaume', 38).toString() ==
 'Person(name:Guillaume, age:38)'
  128. 99 @Canonical becomes a meta-annotation import groovy.transform.*
 
 @Canonical(includeNames =

    true)
 class Person {
 String name
 int age
 }
 
 assert new Person('Guillaume', 38).toString() ==
 'Person(name:Guillaume, age:38)' includeNames from @ToString
  129. 100 More control on annotation collector DUPLICATE Annotations from the

    annotation collection will always be inserted. PREFER_COLLECTOR Annotations from the collector will be added and any existing annotations with the same name will be removed. PREFER_EXPLICIT Annotations from the collector will be ignored if any existing annotations with the same name are found. PREFER_EXPLICIT_MERGED Annotations from the collector will be ignored if any existing annotations with the same name are found but any new parameters on the collector annotation will be added to existing annotations. PREFER_COLLECTOR_MERGED Annotations from the collector will be added and any existing annotations with the same name will be removed but any new parameters found within existing annotations will be merged into the added annotation.
  130. 101 New @MapConstructor transformation import groovy.transform.*
 
 @TupleConstructor
 class Person

    {
 String first, last
 }
 
 @CompileStatic // optional
 @ToString(includeSuperProperties = true)
 @MapConstructor(pre = { super(args?.first, args?.last);
 args = args ?: [:] },
 post = { first = first?.toUpperCase() })
 class Author extends Person {
 String bookName
 } assert new Author(first: 'Dierk', last: 'Koenig', bookName: 'ReGinA').toString() == 'Author(ReGinA, DIERK, Koenig)'
 
 assert new Author().toString() == 'Author(null, null, null)'
  131. 101 New @MapConstructor transformation import groovy.transform.*
 
 @TupleConstructor
 class Person

    {
 String first, last
 }
 
 @CompileStatic // optional
 @ToString(includeSuperProperties = true)
 @MapConstructor(pre = { super(args?.first, args?.last);
 args = args ?: [:] },
 post = { first = first?.toUpperCase() })
 class Author extends Person {
 String bookName
 } assert new Author(first: 'Dierk', last: 'Koenig', bookName: 'ReGinA').toString() == 'Author(ReGinA, DIERK, Koenig)'
 
 assert new Author().toString() == 'Author(null, null, null)' Can decorate map ctor with pre / post- instructions
  132. 102 Properties validated in AST xforms import groovy.transform.AutoClone
 
 @AutoClone(excludes

    = 'sirName')
 class Person {
 String firstName
 String surName
 }
 
 new Person(firstName: "John", surName: "Doe").clone()
  133. 102 Properties validated in AST xforms import groovy.transform.AutoClone
 
 @AutoClone(excludes

    = 'sirName')
 class Person {
 String firstName
 String surName
 }
 
 new Person(firstName: "John", surName: "Doe").clone() Error during @AutoClone processing: 'excludes' property 'sirName' does not exist.
  134. 103 Prevent @TupleConstructor default ctors @TupleConstructor
 class Person {
 String

    first, last
 int age
 }
  135. 103 Prevent @TupleConstructor default ctors @TupleConstructor
 class Person {
 String

    first, last
 int age
 } Generates: Person(String first, String last, int age) { /*...*/ } Person(String first, String last) { this(first, last, 0) } Person(String first) { this(first, null) } Person() { this(null) }
  136. 104 Prevent @TupleConstructor default ctors @TupleConstructor(defaults = true)
 class Person

    { String first, last
 int age
 }
  137. 104 Prevent @TupleConstructor default ctors @TupleConstructor(defaults = true)
 class Person

    { String first, last
 int age
 } Generates only: Person(String first, String last, int age) { /*...*/ }
  138. 105 @Immutable support in class hierarchy import groovy.transform.*
 
 @EqualsAndHashCode


    class Person {
 String name
 }
  139. 105 @Immutable support in class hierarchy import groovy.transform.*
 
 @EqualsAndHashCode


    class Person {
 String name
 } @Immutable
 @TupleConstructor(includeSuperProperties = true)
 @EqualsAndHashCode(callSuper = true)
 @ToString(includeNames = true, includeSuperProperties = true)
 class Athlete extends Person {
 String sport
 }
  140. 105 @Immutable support in class hierarchy import groovy.transform.*
 
 @EqualsAndHashCode


    class Person {
 String name
 } @Immutable
 @TupleConstructor(includeSuperProperties = true)
 @EqualsAndHashCode(callSuper = true)
 @ToString(includeNames = true, includeSuperProperties = true)
 class Athlete extends Person {
 String sport
 } def d1 = new Athlete('Michael Jordan', 'BasketBall')
 def d2 = new Athlete(name: 'Roger Federer', sport: ‘Tennis') assert d1 != d2
 assert d1.toString() == 
 'Athlete(sport:BasketBall, name:Michael Jordan)'
 assert d2.toString() == 
 'Athlete(sport:Tennis, name:Roger Federer)'
  141. 106 Miscellaneous • GDK’s createSimilarCollection() and createSimilarMap() methods support all

    the JDK’s collections and maps • New File#relativePath(file) method
  142. To conclude…

  143. None
  144. None
  145. None
  146. None
  147. Thanks for your attention!

  148. Questions & Answers