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

Groovy State of the Union — GR8Conf Europe 2015

Groovy State of the Union — GR8Conf Europe 2015

Guillaume Laforge

June 03, 2015
Tweet

More Decks by Guillaume Laforge

Other Decks in Technology

Transcript

  1. State of
    the Union
    Guillaume Laforge
    @glaforge
    Restlet — the Web API platform
    Groovy project team

    View Slide

  2. We know
    about
    APIs!

    View Slide

  3. STATE
    OF THE
    UNION

    View Slide

  4. View Slide

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

    View Slide

  6. A look back at
    the past 6 months

    View Slide

  7. FIRED!

    View Slide

  8. MARCH
    31st

    View Slide

  9. MARCH
    31st
    RELEASE
    GROOVY 2.4
    GRAILS 3.0

    View Slide

  10. View Slide

  11. What could
    possibly go
    wrong?

    View Slide

  12. View Slide

  13. THE CODEHAUS
    DEMISE

    View Slide

  14. IMPACT?

    View Slide

  15. 2012 2013 2014 2015
    Downloads

    View Slide

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

    View Slide

  17. 2.1 MILLIONS
    FOR FIRST 4 MONTHS
    OF 2015

    View Slide

  18. MAVEN
    CENTRAL
    ONLY

    View Slide

  19. MAVEN
    CENTRAL
    ONLY
    +CODEHAUS
    LEGACY

    View Slide

  20. MAVEN
    CENTRAL
    ONLY
    +CODEHAUS
    LEGACY
    +BINTRAY

    View Slide

  21. GROOVY
    2.4

    View Slide

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

    View Slide

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

    View Slide

  24. 16
    Groovy 2.4 — Android support
    SwissKnife

    a dedicated 

    Groovy / Android 

    library

    View Slide

  25. 17
    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

    View Slide

  26. 18
    Groovy 2.4 — Traits @SelfType
    class Component {

    void doSomething() {

    println "Done!"

    }

    }

    View Slide

  27. 18
    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()

    }

    }

    View Slide

  28. 18
    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()

    View Slide

  29. 19
    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

    View Slide

  30. 20
    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

    View Slide

  31. 21
    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

    View Slide

  32. And now, what’s next?

    View Slide

  33. MUSICAL
    CHAIRS

    View Slide

  34. GRAILS
    GROOVY
    CEDRIC
    GUILLAUME
    JOCHEN LARI
    JEFF
    GRAEME
    ?

    View Slide

  35. GRAILS
    GROOVY
    CEDRIC
    GUILLAUME
    JOCHEN
    LARI
    JEFF
    GRAEME
    ?

    View Slide

  36. View Slide

  37. MESSAGE TO THE
    COMMUNITY

    View Slide

  38. HERE TO
    STAY

    View Slide

  39. HERE TO
    STAY
    INDEPENDENCE

    View Slide

  40. HERE TO
    STAY
    COMMUNITY
    ABOVE ALL
    INDEPENDENCE

    View Slide

  41. APACHE
    INCUBATOR

    View Slide

  42. APACHE
    INCUBATOR
    MARCH
    24TH

    View Slide

  43. 29
    Incubation — mentors
    • Emmanuel Lécharny
    • Bertrand Delacrétaz
    • Roman Shaposhnik
    • Jim Jagielski
    • Andrew Bayer

    View Slide

  44. 30
    Incubation — initial committers
    • Paul King
    • Cédric Champeau
    • Pascal Schumacher
    • Jochen Theodorou
    • Guillaume Laforge

    View Slide

  45. 31
    Incubation — infrastructure
    • Mailing-lists created
    • please don’t use the old ones!
    • JIRA issues imported
    • Sources moved to Apache’s Git
    • with a mirror on Github
    Please
    Star it!

    View Slide

  46. 32
    Incubation — new committers
    • Officially joined the project as committer
    • Andrés Almiray
    • To be announced soon too!
    • Dierk König
    • Russel Winder

    View Slide

  47. 33
    Incubation — next steps
    • The next key step is make a first release!
    • following the Apache guidelines

    View Slide

  48. Little nuggets to come…
    For Groovy 2.4.4
    and Groovy 2.5

    View Slide

  49. 35
    @Canonical becomes a meta-annotation
    import groovy.transform.*


    @Canonical(includeNames = true)

    class Person {

    String name

    int age

    }


    assert new Person('Guillaume', 37).toString() ==

    'Person(name:Guillaume, age:37)'

    View Slide

  50. 35
    @Canonical becomes a meta-annotation
    import groovy.transform.*


    @Canonical(includeNames = true)

    class Person {

    String name

    int age

    }


    assert new Person('Guillaume', 37).toString() ==

    'Person(name:Guillaume, age:37)'
    includeNames
    from @ToString

    View Slide

  51. 36
    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.

    View Slide

  52. 37
    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)'

    View Slide

  53. 37
    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

    View Slide

  54. 38
    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()

    View Slide

  55. 38
    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.

    View Slide

  56. 39
    Prevent @TupleConstructor default ctors
    @TupleConstructor

    class Person {

    String first, last

    int age

    }

    View Slide

  57. 39
    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) }

    View Slide

  58. 40
    Prevent @TupleConstructor default ctors
    @TupleConstructor(defaults = true)

    class Person {
    String first, last

    int age

    }

    View Slide

  59. 40
    Prevent @TupleConstructor default ctors
    @TupleConstructor(defaults = true)

    class Person {
    String first, last

    int age

    }
    Generates only:
    Person(String first, String last, int age) { /*...*/ }

    View Slide

  60. 41
    @Immutable support in class hierarchy
    import groovy.transform.*


    @EqualsAndHashCode

    class Person {

    String name

    }

    View Slide

  61. 41
    @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

    }

    View Slide

  62. 41
    @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 Rederer', sport: ‘Tennis')
    assert d1 != d2

    assert d1.toString() == 

    'Athlete(sport:BasketBall, name:Michael Jordan)'

    assert d2.toString() == 

    'Athlete(sport:Tennis, name:Roger Rederer)'

    View Slide

  63. 42
    Miscellaneous
    • GDK’s createSimilarCollection() and
    createSimilarMap() methods support all the JDK’s
    collections and maps
    • Improve compiler performance with an ASM class reader
    instead of using a class loader
    • New File#relativePath(file) method

    View Slide

  64. Thanks for your attention!

    View Slide

  65. Questions & Answers

    View Slide