| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (config.xml)

This example Groovy source code file (config.xml) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

avoid, avoid, checkstyle, crawl//dtd, cyclomaticcomplexity, design, design, doctype, item, item, joshua, joshua, not, todo

The Groovy config.xml source code

<?xml version="1.0"?>
        "-//Puppy Crawl//DTD Check Configuration 1.1//EN"

  A Checkstyle configuration that checks against the recommendations
  in Joshua Bloch, Effective Java (highly recommended read!)

  This file does NOT duplicate the checks for whitespace settings,
  placement of curly braces, etc.  Only the rules that are explicitly
  mentioned in the book are enforced.

  Currently the amount of rules that can be automatically checked by
  Checkstyle is not very large, but adding more checks of this quality
  is a high priority goal for the development team.


<module name="Checker">
    <!-- checkstyle.basedir is the absolute path to sources, set in ant's build.xml -->
    <property name="basedir" value="${checkstyle.basedir}"/>
    <property name="localeCountry" value="en"/>
    <property name="localeLanguage" value="en"/>

    <module name="TreeWalker">

        <!-- Item 4 - Avoid creating duplicate objects -->
        <module name="IllegalInstantiation">
            <property name="classes" value="java.lang.Boolean, java.lang.String"/>

        <!-- Item 6 - Avoid finalizers -->
        <!-- this will not find violations that contain linebreaks -->
        <module name="GenericIllegalRegexp">
            <property name="format"

        <!-- Item 8 - Always override hashCode when you override equals -->
        <module name="EqualsHashCode"/>

        <!-- Item 12 - Make all fields private -->
        <module name="VisibilityModifier">
            <!-- TODO: add one or both of these back in? -->
            <property name="protectedAllowed" value="true"/>
            <property name="packageAllowed" value="true"/>

        <!-- Item 15 - Design and document for inheritance or else prohibit it -->
        <!-- the module actually implements a very strict rule, it would be
             interesting to know whether Joshua meant what checkstyle implements.
             We feel this implementation is well suited as a warning,
             i.e. if you get error messages from this check you should be
             able to name a good reason to implement your code the way you do it,
             especially if you are designing a library and not an application.

        <module name="DesignForExtension">
          <property name="severity" value="warning"/>

        <!-- Item 17 - Use interfaces only to define types -->
        <module name="InterfaceIsType"/>

        <!-- Item 25 - Design method signatures carefully -->
        <!-- Avoid long parameter lists -->
        <module name="ParameterNumber">
            <property name="max" value="6"/>

        <!-- Item 28 - Write doc comments for all exposed API elements

        <module name="JavadocType">
          <property name="scope" value="protected"/>
        <module name="JavadocMethod">
          <property name="scope" value="protected"/>
        <module name="JavadocVariable">
          <property name="scope" value="protected"/>

        <!-- Item 38 - Adhere to generally accepted naming conventions -->
        <module name="PackageName">
            <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,22})*$"/>
        <module name="TypeName"/>
        <module name="ConstantName"/>
        <module name="LocalFinalVariableName"/>
        <module name="LocalVariableName"/>
        <module name="MemberName"/>
        <module name="MethodName"/>
        <module name="ParameterName"/>
        <module name="StaticVariableName"/>

        <!-- Item 47 - Don't ignore exceptions -->
        <module name="EmptyBlock">
            <property name="tokens" value="LITERAL_CATCH"/>
            <!-- require a comment, change to stmt to require a statement -->
            <property name="option" value="text"/>

        <!-- other sun checks -->
        <module name="RedundantImport"/>
        <module name="UnusedImports"/>
        <module name="ModifierOrder"/>
        <module name="RedundantModifier"/>
        <!-- current style has lots of occurrences of this, off for now -->
        <module name="MissingSwitchDefault"/>
        <module name="DefaultComesLast"/>
        <!-- very liberal values for metrics, perhaps tighten some later -->
        <module name="JavaNCSS">
            <property name="methodMaximum" value="80"/>
            <property name="classMaximum" value="300"/>
        <module name="ClassFanOutComplexity">
            <property name="max" value="22"/>
        <module name="ClassDataAbstractionCoupling">
            <property name="max" value="14"/>
        <module name="CyclomaticComplexity">
            <property name="max" value="14"/>
        <!-- TODO: turn this back on? -->
        <!-- turned off - instead, keep methods short and make
             parameters final in cases where confusion is possible -->
        <module name="IllegalType">
            <property name="format" value="^$"/>
            <!-- otherwise default of '*Abstract' is illegal -->
            <property name="illegalClassNames" value="java.util.GregorianCalendar, java.util.Hashtable, java.util.HashSet, java.util.HashMap, java.util.ArrayList, java.util.LinkedHashMap, java.util.LinkedHashSet, java.util.TreeSet, java.util.TreeMap, java.util.Vector"/>
        <module name="UpperEll"/>
        <!-- off for now - to allow parenteses which add clarity -->
        <module name="JUnitTestCase"/>
        <module name="FinalClass"/>
        <!-- good to have but pollutes coverage -->
        <module name="MutableException"/>
        <!-- add below in eventually? -->
        <!-- add below in eventually for consistency -->
        <module name="RegexpHeader">
            <property name="headerFile" value="config/checkstyle/codeHeader.txt"/>
    <module name="PackageHtml"/>
    <module name="">
        <property name="threshold" value="8"/>
        <!-- remove language once Simian understands Groovy -->
        <property name="language" value="java"/>

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy config.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.