Implementing quality in Java projects
Upcoming SlideShare
Loading in...5
×
 

Implementing quality in Java projects

on

  • 2,575 views

Based on the example of the XWiki Open Source project (http://xwiki.org) this session will describe a number of practices to improve the quality of a Java project. Also, it will show how to implement ...

Based on the example of the XWiki Open Source project (http://xwiki.org) this session will describe a number of practices to improve the quality of a Java project. Also, it will show how to implement these practices so that they are automatically checked and enforced. Some examples include: *How to make sure your project does not break binary compatibility unintentionally and, more generally, how to successfully evolve an API without breaking your users; *How to manage the JAR hell and avoid duplication of classes in your application at runtime; *How to automatically control the test coverage and the associated policies; *How to automate functional testing of web applications and how to avoid false-positives that plague any project..

Statistics

Views

Total Views
2,575
Slideshare-icon Views on SlideShare
1,033
Embed Views
1,542

Actions

Likes
4
Downloads
10
Comments
0

11 Embeds 1,542

http://massol.myxwiki.org 1482
http://sorin2.myxwiki.org 20
http://cloud.feedly.com 10
http://sorin.myxwiki.org 10
http://feeds.feedburner.com 6
http://www.radiology.no 4
http://192.168.3.38 3
http://translate.googleusercontent.com 3
http://localhost 2
http://incubator.myxwiki.org 1
http://smashingreader.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Implementing quality in Java projects Implementing quality in Java projects Presentation Transcript

    • Implementing Qualityon Java projectsVincent MassolCommitter XWikiCTO XWiki SAS@vmassolSaturday, April 20, 13
    • Vincent Massol• Speaker Bio•CTO XWiki SAS• Your Projects•XWiki (community-driven open source project)•Past: Maven, Apache Cargo, Apache Cactus, PatternTesting• Other Credentials:•LesCastCodeurs podcast•Creator of OSSGTP open source group in ParisSaturday, April 20, 13
    • What is Quality?Saturday, April 20, 13
    • The XWiki project in summary• 9 years old• 28 activecommitters• 7 committersdo 80% ofwork• 700KNCLOC• 11 commits/daySaturday, April 20, 13
    • Examples of Quality actions• Coding rules (Checkstyle, ...)• Test coverage• Track bugs• Don’t use Commons Lang 2.x• Use SLF4J and don’t drawLog4J/JCL in dependencies• Automated build• Automated unit tests• Stable automated functionaltests• Ensure API stability• Code reviews• License header checks• Release with Java 6• Ensure javadoc exist• Prevent JAR hell• Release often (every 2 weeks)• Collaborative design• Test on supportedenvironments (DB & Browsers)Saturday, April 20, 13
    • Quality Tip #1API StabilitySaturday, April 20, 13
    • The ProblemClass Not Found or Method NotFoundSaturday, April 20, 13
    • API Stability - Deprecations/*** ...* @deprecated since 2.4M1 use {@link #transform(* Block, TransformationContext)}*/@Deprecatedvoid transform(XDOM dom, Syntax syntax)throws TransformationException;Saturday, April 20, 13
    • API Stability - CLIRR (1/2)<plugin><groupId>org.codehaus.mojo</groupId><artifactId>clirr-maven-plugin</artifactId><configuration><ignored><difference><differenceType>7006</differenceType><className>org/xwiki/.../MetaDataBlock</className><method>org.xwiki....block.Block clone()</method><to>org.xwiki.rendering.block.MetaDataBlock</to><justification>XDOM#clone() doesnt clone the metadata</justification></difference>...Saturday, April 20, 13
    • API Stability - CLIRR (2/2)Example from XWiki 5.0M1 Release notesSaturday, April 20, 13
    • API Stability - Internal PackageJavadocCLIRR<plugin><groupId>org.codehaus.mojo</groupId><artifactId>clirr-maven-plugin</artifactId><excludes><exclude>**/internal/**</exclude><exclude>**/test/**</exclude><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin<configuration><excludePackageNames>*.internal.*</excludePackageNames>Saturday, April 20, 13
    • API Stability - Legacy ModuleAspect Weaving+ “Legacy” Profile<plugin><groupId>org.codehaus.mojo</groupId><artifactId>aspectj-maven-plugin</...>...<configuration><weaveDependencies><weaveDependency><groupId>org.xwiki.rendering</...><artifactId>xwiki-rendering-api</...>...Saturday, April 20, 13
    • API Stability - Young APIs/*** ...* @since 5.0M1*/@Unstable(<optional explanation>)public EntityReference createEntityReference(String name,...){...}+ max duration for keeping the annotation!Saturday, April 20, 13
    • API Stability - Next steps• Annotation or package for SPI?• Better define when to use the @Unstableannotation• Not possible to add a new method to an existingInterface without breaking compatibility•Java 8 and Virtual Extension/Defender methodsinterface TestInterface {  public void testMe();  public void newMethod() default {    System.out.println("Default from interface"); }Saturday, April 20, 13
    • Quality Tip #2JAR HellSaturday, April 20, 13
    • The ProblemClass Not Found or Method NotFound or not working featureSaturday, April 20, 13
    • No duplicate classes @ runtime<plugin><groupId>com.ning.maven.plugins</groupId><artifactId>maven-duplicate-finder-plugin</artifactId><executions><execution><phase>verify</phase><goals><goal>check</goal></goals><configuration><failBuildInCaseOfConflict>true</...><exceptions>...Saturday, April 20, 13
    • Surprising results...• Commons Beanutils bundles some classes from CommonsCollections, apparently to avoid drawing a dependency to it...• Xalan bundles a lot of other projects (org/apache/xml/**, org/apache/bcel/**, JLex/**, java_cup/**, org/apache/regexp/**). Inaddition, it even has these jars in its source tree without anyindication about their versions...• stax-api, geronimo-stax-api_1.0_spec and xml-apis all drawjavax.xml.stream.* classes• xmlbeans and xml-apis draw incompatible versions oforg.w3c.dom.* classes14 exceptions in total!Saturday, April 20, 13
    • Maven: dependency version issue<dependencies><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.4.0</version></dependency><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>0.9.9</version><!-- Depends on org.slf4j:slf4j-api:1.5.0 --></dependency></dependencies>Will run logback 0.9.9with slf4J-api 1.4.0instead of 1.5.0!Saturday, April 20, 13
    • Maven: ensure correct version<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-enforcer-plugin</artifactId><executions><execution><id>enforce-version-compatibility</id><phase>verify</phase><goals><goal>enforce</goal></goals><configuration><rules><requireUpperBoundDeps/></rules>Saturday, April 20, 13
    • Quality Tip #3Test CoverageSaturday, April 20, 13
    • The ProblemMore bugs reported, overallquality goes down and harder todebug softwareSaturday, April 20, 13
    • Use Jacoco to fail the build<plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><executions><execution><id>jacoco-prepare</id><goals><goal>prepare-agent</goal></goals></execution><execution><id>jacoco-check</id><goals><goal>check</goal></goals></execution></executions><configuration><check><instructionRatio>${xwiki.jacoco.instructionRatio}</...></check>}Saturday, April 20, 13
    • Strategy• When devs add code (and thustests), increase the TPC percentage• Put the Jacoco check in “Quality”Maven Profile• Have a CI job to execute thatprofile regularly•About 15% overhead compared to buildwithout checks• “Cheat mode”: Add easier-to-writetestSaturday, April 20, 13
    • Quizz Time![INFO] --- jacoco-maven-plugin:0.6.2.201302030002:check (jacoco-check)[INFO] All coverage checks have been met.[INFO] --- jacoco-maven-plugin:0.6.2.201302030002:check (jacoco-check)[WARNING] Insufficient code coverage for INSTRUCTION: 75.52% < 75.53%Step 1: Building on my local machine gives the following:Step 2: Building on the CI machine gave:Non determinism! Why?Saturday, April 20, 13
    • Quizz Answerprivate Map componentEntries = new ConcurrentHashMap();...for (Map.Entry entry : componentEntries.entrySet()){if (entry.getValue().instance == component) {  key = entry.getKey();    oldDescriptor = entry.getValue().descriptor;    break;  }}... because the JVM is non deterministic!Saturday, April 20, 13
    • Quality Tip #4Functional TestingStabilitySaturday, April 20, 13
    • The ProblemToo many false positivesleading to developers notpaying attention to CI emailsanymore... leading to failingsoftwareSaturday, April 20, 13
    • False positives examples• The JVM has crashed• VNC is down (we run Selenium tests)• Browser crash (we run Selenium tests)• Git connection issue• Machine slowness (if XWiki cannot start under 2 minutesthen it means the machine has some problems)• Nexus is down (we deploy our artifacts to a Nexusrepository)• Connection issue (Read time out)Saturday, April 20, 13
    • Step 1: Groovy PostBuild Plugin (1/2)def messages = [[".*A fatal error has been detected by the Java Runtime Environment.*","JVM Crash", "A JVM crash happened!"],[".*Error: cannot open display: :1.0.*","VNC not running", "VNC connection issue!"],...]def shouldSendEmail = truemessages.each { message ->if (manager.logContains(message.get(0))) {manager.addWarningBadge(message.get(1))manager.createSummary("warning.gif").appendText(...)manager.buildUnstable()shouldSendEmail = false}}Saturday, April 20, 13
    • Step 1: Groovy PostBuild Plugin (2/2)... continued from previous slide...if (!shouldSendEmail) {def pa = new ParametersAction([new BooleanParameterValue("noEmail", true)])manager.build.addAction(pa)}Saturday, April 20, 13
    • Step 2: Mail Ext Pluginimport hudson.model.*build.actions.each { action ->if (action instanceof ParametersAction) {if (action.getParameter("noEmail")) {cancel = true}}}Pre-send ScriptSaturday, April 20, 13
    • Results+ use the Scriptler plugin to automate configuration for all jobsSaturday, April 20, 13
    • Quality Tip #5Bug Fixing DaySaturday, April 20, 13
    • The ProblemBugs increasing, evensimple to fixones, devs focusing too much onnew features (i.e. scope creep)vs fixing what existsBugs created vs closedSaturday, April 20, 13
    • Bug Fixing Day• Every Thursday• Goal is to close the max number of bugs• Triaging: Can be closed with Won’t fix,Duplicate, Cannot Reproduce, etc• Close low hanging fruits in priority• Started with last 365 days then with last 547days and currently with last 730 days (weneed to catch up with 6 bugs!)Saturday, April 20, 13
    • ResultsSaturday, April 20, 13
    • ConclusionSaturday, April 20, 13
    • Parting words• Slowly add new quality check over time• Everyone must be on board• Favor Active Quality (i.e. make the build fail) overPassive checks• Be ready to adapt/remove checks if found not usefulenough• Quality brings some risks:•Potentially less committers for your project (especially opensource)Saturday, April 20, 13
    • Be proud of your Quality!“I have offended God andmankind because my workdidnt reach the quality it shouldhave.”Leonardo da Vinci, on his death bedSaturday, April 20, 13