GR8Conf 2009: Industrial Strength Groovy by Paul King

15
Industrial Strength Groovy Tools for the Professional Groovy Developer Dr Paul King ASERT Brisbane, Australia Draft Only Updated Version will be on gr8conf site and/or SlideShare

description

Paul King presents various ways and tools to push your Groovy and Java development to an industrial level

Transcript of GR8Conf 2009: Industrial Strength Groovy by Paul King

Page 1: GR8Conf 2009: Industrial Strength Groovy by Paul King

Industrial Strength Groovy

Tools for the Professional Groovy Developer

Dr Paul KingASERT

Brisbane, Australia

Draft Only – Updated Version will be on gr8conf site and/or SlideShare

Page 2: GR8Conf 2009: Industrial Strength Groovy by Paul King

Topics

Testing: JUnit, TestNG, EasyB, Spock, Instinct

Mocking: MockFor, GMock, Spock, EasyMock

Injection: Spring, Guice

Coverage: Cobertura

Code style: CodeNarc, IntelliJ

Duplication: Simian

Documentation: GroovyDoc

Builds: Maven, Ant, Gant, Graven, Gradle, Hudson

Modularisation: Grapes, OSGi

Page 3: GR8Conf 2009: Industrial Strength Groovy by Paul King

Groovy’s Appeal

Innovators/Thought leaders

Ideas, power, flexibility, novelty, thinking community

Early adopters

Productivity benefits and collegiate community

Leverage JVM and potential for mainstream

Mainstream

Leverage existing Java skills, low learning curve

Leverage JVM and production infrastructure

Professional community

Tools, tools, tools

Page 4: GR8Conf 2009: Industrial Strength Groovy by Paul King

Testing: JUnit, TestNG, EasyB, Spock, Instinct

Page 5: GR8Conf 2009: Industrial Strength Groovy by Paul King

Mocking: MockFor, GMock, Spock, EasyMock

Page 6: GR8Conf 2009: Industrial Strength Groovy by Paul King

Dependency Injection

Hollywood Principle

Don’t call us, we’ll call you

“All problems in computer science canbe solved by another level of indirection”

"...except for the problem of too many layers of indirection“

For attributions, seehttp://en.wikipedia.org/wiki/Inversion_of_control

Page 7: GR8Conf 2009: Industrial Strength Groovy by Paul King

Dependency Injection

Pattern for loosely coupled & testable objects

class Client {Calculator calcdef executeCalc(a, b) {

calc.add(a, b)}

}

class Client {Calculator calc =

new CalculatorImpl()def executeCalc(a, b) {

calc.add(a, b)}

}

Service locator/factory

Tightly coupled?

Hard to test?

Easy to understand?

Refactoring/navigation?

Need to select setter, constructor, field style

Can add complexity

Manage configuration

Direct or framework

Consistency/lifecycle

Page 8: GR8Conf 2009: Industrial Strength Groovy by Paul King

Dependency Injection: Guice

import com.google.inject.*

@ImplementedBy(CalculatorImpl)interface Calculator {

def add(a, b)}

@Singletonclass CalculatorImpl implements Calculator {

private total = 0def add(a, b) { total++; a + b }def getTotalCalculations() { 'Total Calculations: ' + total }String toString() { 'Calc: ' + hashCode()}

}

class Client {@Inject Calculator calc// ...

}

def injector = Guice.createInjector()// ...

Page 9: GR8Conf 2009: Industrial Strength Groovy by Paul King

Dependency Injection: Metaprogramming Style

class Calculator {def total = 0def add(a, b) { total++; a + b }

}

def INSTANCE = new Calculator()Calculator.metaClass.constructor = { -> INSTANCE }

def c1 = new Calculator()def c2 = new Calculator()

assert c1.add(1, 2) == 3assert c2.add(3, 4) == 7

assert c1.is(c2)assert [c1, c2].total == [2, 2]

Page 10: GR8Conf 2009: Industrial Strength Groovy by Paul King

Coverage: Cobertura

Page 11: GR8Conf 2009: Industrial Strength Groovy by Paul King

Code style: CodeNarc, IntelliJ

Page 12: GR8Conf 2009: Industrial Strength Groovy by Paul King

Duplication: Simian

Similarity Analyser 2.2.23 -http://www.redhillconsulting.com.au/products/simian/index.html

Copyright (c) 2003-08 RedHill Consulting Pty. Ltd. All rights reserved.

Simian is not free unless used solely for non-commercial or evaluation purposes.

{failOnDuplication=true, ignoreCharacterCase=true, ignoreCurlyBraces=true, ignoreIdentifierCase=true, ignoreModifiers=true, ignoreStringCase=true, threshold=6}

Found 6 duplicate lines in the following files:

Between lines 201 and 207 in /Users/haruki_zaemon/Projects/redhill/simian/build/dist/src/java/awt/image/WritableRaster.java

...

Found 66375 duplicate lines in 5949 blocks in 1260 files

Processed a total of 390309 significant (1196065 raw) lines in 4242 files

Processing time: 9.490sec

Page 13: GR8Conf 2009: Industrial Strength Groovy by Paul King

Documentation: GroovyDoc

Page 14: GR8Conf 2009: Industrial Strength Groovy by Paul King

Builds: Maven, Ant, Gant, Graven, Gradle, Hudson

Page 15: GR8Conf 2009: Industrial Strength Groovy by Paul King

Modularisation: Grapes, OSGi