]> source.dussan.org Git - vaadin-framework.git/commitdiff
Checkstyle for Vaadin #9065 71/371/7
authorPekka Hyvönen <pekka@vaadin.com>
Mon, 10 Dec 2012 11:09:34 +0000 (13:09 +0200)
committerArtur Signell <artur@vaadin.com>
Fri, 4 Jan 2013 16:59:39 +0000 (18:59 +0200)
* Validates that all java files contains a license file and fails the build if a license is missing
* For now runs a lot of checks with a severity less than error to avoid failing the build
* Outputs test results to TeamCity for reporting

Change-Id: I24ca9cd0646a4bc530ef3a183eef1bc4addc555d

15 files changed:
all/build.xml
build.xml
buildhelpers/build.xml
checkstyle/header [new file with mode: 0644]
checkstyle/vaadin-checkstyle.xml [new file with mode: 0644]
client-compiled/build.xml
client-compiler/build.xml
client/build.xml
common.xml
ivy-taskdefs.xml
server/build.xml
shared/build.xml
theme-compiler/build.xml
themes/build.xml
uitest/build.xml

index e352cbbc0713595f72147c3a07cb9314442ae59a..d5a484a902f2e0b21e5de2bb7408ebfb7aa563f6 100644 (file)
        <target name="clean">
                <antcall target="common.clean" />
        </target>
-
-       <target name="tests">
+       <target name="checkstyle">
+               <!-- Checkstyle is handled by all separate modules -->
+       </target>
+       <target name="tests" depends="checkstyle">
                <!-- No tests for this zip.. -->
        </target>
 
index 50a4f4463f7078e99e500bafe9ac75203effda55..306b169bc77588da4774b9a3637436286c944590 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -37,7 +37,9 @@
                <delete dir="${ivy.cache.dir}/com.carrotsearch" />
 
        </target>
-
+       <target name="checkstyle" depends="buildorder">
+               <subant buildpathref="build-path" target="checkstyle"/>
+       </target>
        <target name="tests" depends="buildorder">
                <property name="war.file" location="result/artifacts/${vaadin.version}/vaadin-uitest/vaadin-uitest-${vaadin.version}.war" />
                <parallel>
index d50e024ce4bd21b3d27e51c03edc19875b245bf1..e3e7b434d6180df5a288a8da5f8ac2a1d3340c17 100644 (file)
                <antcall target="common.clean" />
        </target>
 
-       <target name="tests">
+       <target name="checkstyle">
+               <antcall target="common.checkstyle">
+                       <param name="cs.src" location="src" />
+               </antcall>
+       </target>
+
+       <target name="tests" depends="checkstyle">
                <!--<antcall target="common.tests.run" />-->
                <echo>WHAT? No JUnit tests for ${module.name}!</echo>
        </target>
diff --git a/checkstyle/header b/checkstyle/header
new file mode 100644 (file)
index 0000000..511f77e
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
\ No newline at end of file
diff --git a/checkstyle/vaadin-checkstyle.xml b/checkstyle/vaadin-checkstyle.xml
new file mode 100644 (file)
index 0000000..3e23370
--- /dev/null
@@ -0,0 +1,257 @@
+<?xml version="1.0"?>\r
+<!DOCTYPE module PUBLIC\r
+          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"\r
+          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">\r
+\r
+<!-- Checkstyle configuration for Vaadin that is based on the the sun coding\r
+       conventions from:\r
+       - the Java Language Specification at http://java.sun.com/docs/books/jls/second_edition/html/index.html\r
+       - the Sun Code Conventions at http://java.sun.com/docs/codeconv/\r
+       - the Javadoc guidelines at http://java.sun.com/j2se/javadoc/writingdoccomments/index.html\r
+       - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html\r
+       - some best practices Vaadin specific changes:\r
+       - Removed DoubleCheckedLocking because it doesn't work in CheckStyle 5.6\r
+       -> http://www.smartics.eu/bugzilla/show_bug.cgi?id=593\r
+       - Modified HiddenField Check to allow field shadowing on Constructor, Setter\r
+       and Abstract Method parameters.\r
+       - Modified StaticVariableName Check format for PUBLIC variables from ^[a-z][a-zA-Z0-9]*$\r
+       to ^[A-Z_]*$ . Others (protected, package and private) still have ^[a-z][a-zA-Z0-9]*$\r
+       - Modified the severity of the following Checks from error to info:\r
+       • JavadocPackage (checks for package-info.java)\r
+       • JavadocType (class and interface declarations, scope private)\r
+       • JavadocMethod (method declarations, scope private)\r
+       • JavadocVariable (variable declarations, scope private)\r
+       • JavadocStyle (Javadocs are "well formed")\r
+       - Modified the severity of the following Checks from error to warning because\r
+       not so critical:\r
+       • LineLenght (the default value is 80 which is also used in formatter, but\r
+       i.e. member declarations are not wrapped onto next line)\r
+       • RedundantModifier (i.e. using public in interface method declarations)\r
+       • RedundantThrows (causes unnecessary fails when can't get class information)\r
+       • MethodLength (default maxLength is 150)\r
+       • ParameterNumber (default maxLength is 7)\r
+       • EmptyBlock (if-else statements have some blocks if x -> no action)\r
+       • UpperEll (should use L instead of l with long)\r
+       • TodoComment (not serious)\r
+       • WhitespaceAroundCheck (expects whitespace around some operators)\r
+       NOTE other checks are also warning but should be error.\r
+       - Modified the severity of the following Checks from error to ignore:\r
+       • FinalParameters (method parameters can be modified)\r
+       • VisibilityModifier (i.e. in state classes public members are allowed)\r
+       • DesignForExtension (this design is not used)\r
+       • FileLength (bad design to have files with over 2000 lines? see VScrollTable)\r
+       • MagicNumber (MagicNumbers like error codes are used, but could just ignore\r
+       this in some classes)\r
+       • AvoidInlineConditionals ( you like these ? ignore : error ) -->\r
+\r
+<module name="Checker">\r
+       <!-- If you set the basedir property below, then all reported file names\r
+               will be relative to the specified directory. See http://checkstyle.sourceforge.net/5.x/config.html#Checker\r
+               <property name="basedir" value="${basedir}"/> -->\r
+\r
+       <!-- Checks that a package-info.java file exists for each package. -->\r
+       <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->\r
+       <module name="JavadocPackage">\r
+               <property name="severity" value="info" />\r
+       </module>\r
+\r
+       <!-- Checks whether files end with a new line. -->\r
+       <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->\r
+       <module name="NewlineAtEndOfFile">\r
+               <property name="severity" value="warning" />\r
+       </module>\r
+\r
+\r
+       <!-- Checks that property files contain the same keys. -->\r
+       <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->\r
+       <module name="Translation">\r
+               <property name="severity" value="warning" />\r
+       </module>\r
+\r
+       <!-- Checks for Size Violations. -->\r
+       <!-- See http://checkstyle.sf.net/config_sizes.html -->\r
+       <module name="FileLength">\r
+               <property name="severity" value="ignore" />\r
+       </module>\r
+\r
+       <!-- Checks for whitespace -->\r
+       <!-- See http://checkstyle.sf.net/config_whitespace.html -->\r
+       <module name="FileTabCharacter">\r
+               <property name="severity" value="warning" />\r
+       </module>\r
+\r
+       <!-- Checks for Headers -->\r
+       <!-- See http://checkstyle.sf.net/config_header.html -->\r
+       <module name="Header">\r
+               <property name="headerFile" value="${checkstyle.header.file}" />\r
+               <property name="fileExtensions" value="java" />\r
+       </module>\r
+\r
+       <module name="TreeWalker">\r
+               <property name="severity" value="warning" />\r
+\r
+               <!-- Custom checks to check serializable, neither is working because checkstyle\r
+                       can't load the classes. <module name="com.vaadin.checks.CheckClassesSerializable"/>\r
+                       <module name="com.vaadin.checks.IsSerializableClassCheck"/> -->\r
+\r
+               <!-- Checks for Javadoc comments. -->\r
+               <!-- See http://checkstyle.sf.net/config_javadoc.html -->\r
+               <module name="JavadocMethod">\r
+                       <property name="severity" value="info" />\r
+               </module>\r
+               <module name="JavadocType">\r
+                       <property name="severity" value="info" />\r
+               </module>\r
+               <module name="JavadocVariable">\r
+                       <property name="severity" value="info" />\r
+               </module>\r
+               <module name="JavadocStyle">\r
+                       <property name="severity" value="info" />\r
+               </module>\r
+\r
+               <!-- Checks for Naming Conventions. -->\r
+               <!-- See http://checkstyle.sf.net/config_naming.html -->\r
+               <module name="ConstantName" />\r
+               <module name="LocalFinalVariableName" />\r
+               <module name="LocalVariableName" />\r
+               <module name="MemberName" />\r
+               <module name="MethodName" />\r
+               <module name="PackageName" />\r
+               <module name="ParameterName" />\r
+               <module name="StaticVariableName">\r
+                       <property name="applyToPublic" value="false" />\r
+               </module>\r
+               <module name="StaticVariableName">\r
+                       <property name="applyToPublic" value="true" />\r
+                       <property name="applyToProtected" value="false" />\r
+                       <property name="applyToPackage" value="false" />\r
+                       <property name="applyToPrivate" value="false" />\r
+                       <property name="format" value="^[A-Z_]*$" />\r
+               </module>\r
+               <module name="TypeName" />\r
+\r
+\r
+               <!-- Checks for imports -->\r
+               <!-- See http://checkstyle.sf.net/config_import.html -->\r
+               <module name="AvoidStarImport" />\r
+               <module name="IllegalImport" /> <!-- defaults to sun.* packages -->\r
+               <module name="RedundantImport" />\r
+               <module name="UnusedImports" />\r
+\r
+\r
+               <!-- Checks for Size Violations. -->\r
+               <!-- See http://checkstyle.sf.net/config_sizes.html -->\r
+               <module name="LineLength">\r
+                       <property name="severity" value="warning" />\r
+               </module>\r
+               <module name="MethodLength">\r
+                       <property name="severity" value="warning" />\r
+               </module>\r
+               <module name="ParameterNumber">\r
+                       <property name="severity" value="warning" />\r
+               </module>\r
+\r
+\r
+               <!-- Checks for whitespace -->\r
+               <!-- See http://checkstyle.sf.net/config_whitespace.html -->\r
+               <module name="EmptyForIteratorPad" />\r
+               <module name="GenericWhitespace" />\r
+               <module name="MethodParamPad" />\r
+               <module name="NoWhitespaceAfter" />\r
+               <module name="NoWhitespaceBefore" />\r
+               <module name="OperatorWrap" />\r
+               <module name="ParenPad" />\r
+               <module name="TypecastParenPad" />\r
+               <module name="WhitespaceAfter" />\r
+               <module name="WhitespaceAround" />\r
+               <!-- Check for trailing white space in Java code -->\r
+               <module name="RegexpSinglelineJava">\r
+                       <!-- Ensure no whitespace at the end of line, excluding comments -->\r
+                       <property name="format" value="\s+$" />\r
+                       <property name="minimum" value="0" />\r
+                       <property name="maximum" value="0" />\r
+                       <property name="message" value="Java code has trailing white space." />\r
+                       <property name="severity" value="warning" />\r
+                       <property name="ignoreComments" value="true" />\r
+               </module>\r
+\r
+               <!-- Modifier Checks -->\r
+               <!-- See http://checkstyle.sf.net/config_modifiers.html -->\r
+               <module name="ModifierOrder" />\r
+               <module name="RedundantModifier">\r
+                       <property name="severity" value="warning" />\r
+               </module>\r
+\r
+\r
+               <!-- Checks for blocks. You know, those {}'s -->\r
+               <!-- See http://checkstyle.sf.net/config_blocks.html -->\r
+               <module name="AvoidNestedBlocks" />\r
+               <module name="EmptyBlock">\r
+                       <property name="severity" value="warning" />\r
+               </module>\r
+               <module name="LeftCurly" />\r
+               <module name="NeedBraces" />\r
+               <module name="RightCurly" />\r
+\r
+\r
+               <!-- Checks for common coding problems -->\r
+               <!-- See http://checkstyle.sf.net/config_coding.html -->\r
+               <module name="AvoidInlineConditionals">\r
+                       <property name="severity" value="ignore" />\r
+               </module>\r
+               <module name="EmptyStatement" />\r
+               <module name="EqualsHashCode" />\r
+               <module name="HiddenField">\r
+                       <property name="ignoreConstructorParameter" value="true" />\r
+                       <property name="ignoreSetter" value="true" />\r
+                       <property name="ignoreAbstractMethods" value="true" />\r
+               </module>\r
+               <module name="IllegalInstantiation" />\r
+               <module name="InnerAssignment" />\r
+               <module name="MagicNumber">\r
+                       <property name="severity" value="ignore" />\r
+               </module>\r
+               <module name="MissingSwitchDefault" />\r
+               <module name="RedundantThrows">\r
+                       <property name="severity" value="warning" />\r
+               </module>\r
+               <module name="SimplifyBooleanExpression" />\r
+               <module name="SimplifyBooleanReturn" />\r
+\r
+               <!-- Checks for class design -->\r
+               <!-- See http://checkstyle.sf.net/config_design.html -->\r
+               <module name="DesignForExtension">\r
+                       <property name="severity" value="ignore" />\r
+               </module>\r
+               <module name="FinalClass" />\r
+               <module name="HideUtilityClassConstructor" />\r
+               <module name="InterfaceIsType" />\r
+               <module name="VisibilityModifier">\r
+                       <property name="severity" value="ignore" />\r
+               </module>\r
+\r
+\r
+               <!-- Miscellaneous other checks. -->\r
+               <!-- See http://checkstyle.sf.net/config_misc.html -->\r
+               <module name="ArrayTypeStyle" />\r
+               <module name="FinalParameters">\r
+                       <property name="severity" value="ignore" />\r
+               </module>\r
+               <module name="TodoComment">\r
+                       <property name="severity" value="warning" />\r
+               </module>\r
+               <module name="UpperEll">\r
+                       <property name="severity" value="warning" />\r
+               </module>\r
+               \r
+               <!--  Check for System.err/out.println -->\r
+        <module name="RegexpSinglelineJava">\r
+            <property name="format" value="System\.out\.println"/>\r
+        </module>\r
+        <module name="RegexpSinglelineJava">\r
+            <property name="format" value="System\.err\.println"/>\r
+        </module>\r
+\r
+       </module>\r
+\r
+</module>\r
index d9f3da62714f5e86f901718cb74ac5d8f50d503e..d1f3eda674554f778ddbd25eb7aeb712108e6dd8 100644 (file)
                <antcall target="common.clean" />
        </target>
 
-       <target name="tests">
+       <target name="checkstyle">
+               <echo>No java files in module</echo>
+       </target>
+       <target name="tests" depends="checkstyle">
                <!--<antcall target="common.tests.run" />-->
                <echo>WHAT? No tests for ${module.name}!</echo>
        </target>
index 95544708c18f4a5468385b155b2236b1595c6c98..9d4e5c403c769b15785ea1616e4accd3fd2b33d3 100644 (file)
@@ -52,7 +52,13 @@ gwt.svnrev=${git.revision}</echo>
                <antcall target="common.clean" />
        </target>
 
-       <target name="tests">
+       <target name="checkstyle">
+               <antcall target="common.checkstyle">
+                       <param name="cs.src" location="src" />
+               </antcall>
+       </target>
+
+       <target name="tests" depends="checkstyle">
                <!--<antcall target="common.tests.run" />-->
                <echo>WHAT? No tests for ${module.name}!</echo>
        </target>
index 26f92ee33f7f654b8433a15f42ff84d1f3d48236..d2946be6e0813e5b6bae93214ccb1015582616bc 100644 (file)
                <antcall target="common.clean" />
        </target>
 
-       <target name="tests">
+       <target name="checkstyle">
+               <antcall target="common.checkstyle">
+                       <param name="cs.src" location="src" />
+               </antcall>
+       </target>
+
+       <target name="tests" depends="checkstyle">
                <antcall target="common.tests.run" />
        </target>
 
index 8df71cc177890292bfd6a23eb317ec2a2402ad32..e96037032b95451501712b2b6d0a15a9d9a2319f 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project name="common" basedir="." default="" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:antcontrib="antlib:net.sf.antcontrib">
+<project name="common" basedir="." default="" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:antcontrib="antlib:net.sf.antcontrib" xmlns:cs="antlib:com.puppycrawl.tools.checkstyle">
 
        <tstamp>
                <format property="build.date" pattern="yyyy-MM-dd" />
                <ivy:publish conf="${conf}" resolver="local-maven" overwrite="true">
                </ivy:publish>
        </target>
+
+       <!-- Checkstyle conf -->
+       <property name="cs.dir" location="${vaadin.basedir}/checkstyle" />
+       <property name="cs.xml" location="${cs.dir}/vaadin-checkstyle.xml" />
+       <property name="cs.header-file" location="${cs.dir}/header" />
+       <taskdef resource="checkstyletask.properties" uri="antlib:com.puppycrawl.tools.checkstyle" classpathref="taskdefs.classpath" />
+
+       <target name="checkstyle">
+               <fail unless="result.dir" message="No result.dir parameter given" />
+               <fail unless="cs.src" message="No cs.src parameter given" />
+               <property name="result.dir.full" location="${result.dir}"/>
+               <mkdir dir="${result.dir}" />
+               <echo>##teamcity[importData type='checkstyle' path='${result.dir.full}/checkstyle-errors.xml']</echo>
+               <cs:checkstyle config="${cs.xml}" failOnViolation="true">
+                       <fileset dir="${cs.src}" includes="**/*.java" />
+                       <formatter type="xml" toFile="${result.dir}/checkstyle-errors.xml"/>
+                       <property key="checkstyle.header.file" file="${cs.header-file}" />
+               </cs:checkstyle>
+       </target>
 </project>
index ccc4d75bcf45c4bb98f4343cb7130784706d50c4..64d5ec1be1d7a3d168ee41ab456bb74be5fa85bb 100644 (file)
@@ -1,18 +1,24 @@
 
-<ivy-module version="2.0" 
+<ivy-module version="2.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:noNamespaceSchemaLocation= "http://ant.apache.org/ivy/schemas/ivy.xsd">
-    
-    <info organisation="com.vaadin" module="vaadin"/>
-    <configurations>
-               <conf name="taskdefs" description="Ant task definitions" visibility="private" />
+       xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
+
+       <info organisation="com.vaadin" module="vaadin" />
+       <configurations>
+               <conf name="taskdefs" description="Ant task definitions"
+                       visibility="private" />
        </configurations>
-    <publications />        
+       <publications />
        <dependencies>
-               <!-- Ant tasks -->      
-               <dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" conf="taskdefs ->master"/>
-               <dependency org="org.apache.maven" name="maven-ant-tasks" rev="2.0.10" conf="taskdefs ->master"/>
-               <dependency org="com.googlecode.jarjar" name="jarjar" rev="1.3" conf="taskdefs ->master"/>
+               <!-- Ant tasks -->
+               <dependency org="ant-contrib" name="ant-contrib" rev="1.0b3"
+                       conf="taskdefs ->master" />
+               <dependency org="org.apache.maven" name="maven-ant-tasks"
+                       rev="2.0.10" conf="taskdefs ->master" />
+               <dependency org="com.googlecode.jarjar" name="jarjar" rev="1.3"
+                       conf="taskdefs ->master" />
+               <dependency org="com.puppycrawl.tools" name="checkstyle"
+                       rev="5.6" />
        </dependencies>
 
 </ivy-module>
index 6c61b7dc75b805ed98c54108c7812a7b4f39aeea..253d09a45b3b8c5e4e2bf75789422a9e85f35520 100644 (file)
                <antcall target="common.clean" />
        </target>
 
-       <target name="tests">
+       <target name="checkstyle">
+               <antcall target="common.checkstyle">
+                       <param name="cs.src" location="src" />
+               </antcall>
+       </target>
+
+       <target name="tests" depends="checkstyle">
                <antcall target="common.tests.run" />
        </target>
 
index 4cba76c85a876cecfc4802d27b35f6975a784f15..06a27b0ef96a06c0422296344a8aca6df29ac101 100644 (file)
        <target name="clean">
                <antcall target="common.clean" />
        </target>
+       
+       <target name="checkstyle">
+               <antcall target="common.checkstyle">
+                       <param name="cs.src" location="src" />
+               </antcall>
+       </target>
 
-       <target name="tests">
+       <target name="tests" depends="checkstyle">
                <!--<antcall target="common.tests.run" />-->
                <echo>WHAT? No tests for ${module.name}!</echo>
        </target>
index 1f9cddebd7268f7320e675ac7b06bd78da8e64f4..885cb6e589b8bb6e3b2c0d3bb6266d36fe4a309f 100644 (file)
                <antcall target="common.clean" />
        </target>
 
-       <target name="tests">
+       <target name="checkstyle">
+               <antcall target="common.checkstyle">
+                       <param name="cs.src" location="src" />
+               </antcall>
+       </target>
+
+       <target name="tests" depends="checkstyle">
                <antcall target="common.tests.run" />
        </target>
 
index a504d585ddf34a1a4b7f44566e66cb4aac36c1de..6e9e3c9951097c7cdac65af6d4b92366533814f2 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 
-<project name="vaadin-client-compiler" basedir="." default="publish-local" xmlns:ivy="antlib:org.apache.ivy.ant">
+<project name="vaadin-themes" basedir="." default="publish-local" xmlns:ivy="antlib:org.apache.ivy.ant">
        <description>
                Themes compiled to CSS 
        </description>
                <antcall target="common.clean" />
        </target>
 
-       <target name="tests">
+       <target name="checkstyle">
+               <echo>No java files in module</echo>
+       </target>
+       <target name="tests" depends="checkstyle">
                <!--<antcall target="common.tests.run" />-->
                <echo>WHAT? No tests for ${module.name}!</echo>
        </target>
index 8d5c1b28f9a38082b2f488c5fc33a973bdd64088..ee2b2c612457920c3e35d1786eaf928434a7de72 100644 (file)
        <target name="clean">
                <antcall target="common.clean" />
        </target>
-       <target name="tests">
+       <target name="checkstyle">
+               <echo>Checkstyle is disabled for uitest for now</echo>
+       </target>
+       <target name="tests" depends="checkstyle">
                <!--<antcall target="common.tests.run" />-->
                <echo>WHAT? No JUnit tests for ${module.name}!</echo>
        </target>