原文:http://www.open-open.com/lib/view/open1425647692009.html (Jenkins+PMD构建自动化静态代码检测)
前言:软件缺陷是不可避免的,要尽量减少错误并提高软件质量,主要有两在类技术,即缺陷预防和缺陷检测
缺陷预防包括编写更好的设计规范、实施代码审核制度、运行代码静态分析工具、运行单元测试等
PMD是一种开源分析Java代码的工具,通过静态分析获知代码错误,该工具可以做到检查Java代码中是否含有未使用的变量、是否含有空的抓取块、是否含有不必要的对象等等
因此Jenkins+PMD构建自动化静态代码检测是很有必要的
PMD下载地址:http://sourceforge.net/projects/pmd/
下载后解压即可
PMD主要可以通过ant脚本来执行,编写ant的build文件,这里新建的为如buildPMD.xml
<?xml version="1.0" encoding="UTF-8"?> <project name="pmd" default="pmd" basedir="."> <property environment="env"> <property name="ExampleProject.location" value="../ExampleProject"> <!-- 定义pmd的classpath,均为下载的pmd包解压后lib目录下的jar包--> <path id="pmd.classpath"> <pathelement location="${basedir}/lib/asm-3.2.jar"> <pathelement location="${basedir}/lib/jaxen-1.1.1.jar"> <pathelement location="${basedir}/lib/junit-4.4.jar"> <pathelement location="${basedir}/lib/pmd-5.0.4.jar"> <!-- <fileset dir="${basedir}/lib/"> <include name="**/*.jar"> --> </include></pathelement></pathelement></pathelement></pathelement></path> <target depends="pmd_html" name="pmd"> <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath"> <!-- 定义代码检测规则,这里直接列出规则imports.xml和java-unusedcode规则,本例注释了,使用下面一种在另一文件中定义规则集--> <!-- <pmd rulesetfiles="rulesets/java/imports.xml,java-unusedcode"> --> <!-- 定义PMD检测规则所在的文件,规则集在pmdrule.xml文件中定义--> <pmd rulesetfiles="${basedir}/pmdrule.xml" encoding="UTF-8"> <!-- 输出XML格式的报告--> <formatter type="html" tofile="pmd_report.html" toconsole="true"> <!-- 静态代码检测ExampleProject工程下src目录下的所有java文件--> <fileset dir="${ExampleProject.location}/src"> <include name="**/*.java"> </include></fileset> </formatter></pmd> </taskdef></target> <target name="pmd_html"> <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath"> <!-- <pmd rulesetfiles="rulesets/java/imports.xml,java-unusedcode"> --> <pmd rulesetfiles="${basedir}/pmdrule.xml" encoding="UTF-8"> <!-- 输出HTML格式的报告--> <formatter type="xml" tofile="pmd_report.html" toconsole="true"> <fileset dir="${ExampleProject.location}/src"> <include name="**/*.java"> </include></fileset> </formatter></pmd> </taskdef></target> </project> 本文中定义了两个target,分别生成了XML和HTML格式的报告,因为在Jenkins中的分析插件需要用XML格式才能生成视图报告,而XML格式对于团队来说不直观,不宜发送邮件,因此生成两份报告,一份用于Jenkins分析,一份发送邮件用于团队成员直接查看 编写好buildPMD.xml,直接使用ant -f buildPMD.xml即可在CMD命令或Linux shell下执行PMD静态代码检测 在Jenkins中新建个任务,Build项Add build step中选择“Execute Shell”,输入ant -f buildPMD.xml即可 附:pmdrule.xml [xml] view plaincopy <?xml version="1.0" encoding="UTF-8"?> <ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="pmdrule" xsi:schemalocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"> <description>PMD Plugin preferences rule set</description> <rule ref="rulesets/java/design.xml/AbstractClassWithoutAbstractMethod"> <rule ref="rulesets/java/design.xml/AbstractClassWithoutAnyMethod"> <rule ref="rulesets/java/naming.xml/AbstractNaming"> <rule ref="rulesets/java/design.xml/AccessorClassGeneration"> <rule ref="rulesets/java/optimizations.xml/AddEmptyString"> <rule ref="rulesets/java/strings.xml/AppendCharacterWithChar"> <rule ref="rulesets/java/sunsecure.xml/ArrayIsStoredDirectly"> <rule ref="rulesets/ecmascript/basic.xml/AssignmentInOperand"> <rule ref="rulesets/java/controversial.xml/AssignmentInOperand"> <rule ref="rulesets/java/design.xml/AssignmentToNonFinalStatic"> <rule ref="rulesets/java/controversial.xml/AtLeastOneConstructor"> <rule ref="rulesets/java/controversial.xml/AvoidAccessibilityAlteration"> <rule ref="rulesets/java/optimizations.xml/AvoidArrayLoops"> <rule ref="rulesets/java/migrating.xml/AvoidAssertAsIdentifier"> <rule ref="rulesets/xsl/xpath.xml/AvoidAxisNavigation"> <rule ref="rulesets/java/basic.xml/AvoidBranchingStatementAsLastInLoop"> <rule ref="rulesets/java/finalizers.xml/AvoidCallingFinalize"> <rule ref="rulesets/java/strictexception.xml/AvoidCatchingGenericException"> <rule ref="rulesets/java/strictexception.xml/AvoidCatchingNPE"> <rule ref="rulesets/java/strictexception.xml/AvoidCatchingThrowable"> <rule ref="rulesets/java/design.xml/AvoidConstantsInterface"> <rule ref="rulesets/java/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor"> <rule ref="rulesets/java/design.xml/AvoidDeeplyNestedIfStmts"> <rule ref="rulesets/java/naming.xml/AvoidDollarSigns"> <rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals"> <rule ref="rulesets/java/migrating.xml/AvoidEnumAsIdentifier"> <rule ref="rulesets/java/naming.xml/AvoidFieldNameMatchingMethodName"> <rule ref="rulesets/java/naming.xml/AvoidFieldNameMatchingTypeName"> <rule ref="rulesets/java/controversial.xml/AvoidFinalLocalVariable"> <rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause"> <rule ref="rulesets/java/optimizations.xml/AvoidInstantiatingObjectsInLoops"> <rule ref="rulesets/java/controversial.xml/AvoidLiteralsInIfCondition"> <rule ref="rulesets/java/strictexception.xml/AvoidLosingExceptionInformation"> <rule ref="rulesets/java/basic.xml/AvoidMultipleUnaryOperators"> <rule ref="rulesets/java/controversial.xml/AvoidPrefixingMethodParameters"> <rule ref="rulesets/java/logging-java.xml/AvoidPrintStackTrace"> <rule ref="rulesets/java/design.xml/AvoidProtectedFieldInFinalClass"> <rule ref="rulesets/java/design.xml/AvoidReassigningParameters"> <rule ref="rulesets/java/strictexception.xml/AvoidRethrowingException"> <rule ref="rulesets/java/strings.xml/AvoidStringBufferField"> <rule ref="rulesets/java/design.xml/AvoidSynchronizedAtMethodLevel"> <rule ref="rulesets/java/basic.xml/AvoidThreadGroup"> <rule ref="rulesets/java/strictexception.xml/AvoidThrowingNewInstanceOfSameException"> <rule ref="rulesets/java/strictexception.xml/AvoidThrowingNullPointerException"> <rule ref="rulesets/java/strictexception.xml/AvoidThrowingRawExceptionTypes"> <rule ref="rulesets/ecmascript/basic.xml/AvoidTrailingComma"> <rule ref="rulesets/java/basic.xml/AvoidUsingHardCodedIP"> <rule ref="rulesets/java/controversial.xml/AvoidUsingNativeCode"> <rule ref="rulesets/java/basic.xml/AvoidUsingOctalValues"> <rule ref="rulesets/java/controversial.xml/AvoidUsingShortType"> <rule ref="rulesets/java/controversial.xml/AvoidUsingVolatile"> <rule ref="rulesets/java/design.xml/BadComparison"> <rule ref="rulesets/java/javabeans.xml/BeanMembersShouldSerialize"> <rule ref="rulesets/java/basic.xml/BigIntegerInstantiation"> <rule ref="rulesets/java/naming.xml/BooleanGetMethodName"> <rule ref="rulesets/java/basic.xml/BooleanInstantiation"> <rule ref="rulesets/java/controversial.xml/BooleanInversion"> <rule ref="rulesets/java/basic.xml/BrokenNullCheck"> <rule ref="rulesets/java/migrating.xml/ByteInstantiation"> <rule ref="rulesets/java/android.xml/CallSuperFirst"> <rule ref="rulesets/java/controversial.xml/CallSuperInConstructor"> <rule ref="rulesets/java/android.xml/CallSuperLast"> <rule ref="rulesets/java/basic.xml/CheckResultSet"> <rule ref="rulesets/java/basic.xml/CheckSkipResult"> <rule ref="rulesets/java/basic.xml/ClassCastExceptionWithToArray"> <rule ref="rulesets/java/naming.xml/ClassNamingConventions"> <rule ref="rulesets/java/design.xml/ClassWithOnlyPrivateConstructorsShouldBeFinal"> <rule ref="rulesets/java/clone.xml/CloneMethodMustImplementCloneable"> <rule ref="rulesets/java/clone.xml/CloneThrowsCloneNotSupportedException"> <rule ref="rulesets/java/design.xml/CloseResource"> <rule ref="rulesets/java/basic.xml/CollapsibleIfStatements"> <rule ref="rulesets/java/comments.xml/CommentContent"> <rule ref="rulesets/java/comments.xml/CommentRequired"> <rule ref="rulesets/java/comments.xml/CommentSize"> <rule ref="rulesets/java/design.xml/CompareObjectsWithEquals"> <rule ref="rulesets/java/design.xml/ConfusingTernary"> <rule ref="rulesets/java/strings.xml/ConsecutiveLiteralAppends"> <rule ref="rulesets/ecmascript/basic.xml/ConsistentReturn"> <rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod"> <rule ref="rulesets/java/coupling.xml/CouplingBetweenObjects"> <rule ref="rulesets/java/codesize.xml/CyclomaticComplexity"> <rule ref="rulesets/java/controversial.xml/DataflowAnomalyAnalysis"> <rule ref="rulesets/java/design.xml/DefaultLabelNotLastInSwitchStmt"> <rule ref="rulesets/java/controversial.xml/DefaultPackage"> <rule ref="rulesets/java/controversial.xml/DoNotCallGarbageCollectionExplicitly"> <rule ref="rulesets/java/j2ee.xml/DoNotCallSystemExit"> <rule ref="rulesets/java/strictexception.xml/DoNotExtendJavaLangError"> <rule ref="rulesets/java/android.xml/DoNotHardCodeSDCard"> <rule ref="rulesets/java/strictexception.xml/DoNotThrowExceptionInFinally"> <rule ref="rulesets/java/j2ee.xml/DoNotUseThreads"> <rule ref="rulesets/java/basic.xml/DontCallThreadRun"> <rule ref="rulesets/java/imports.xml/DontImportJavaLang"> <rule ref="rulesets/java/controversial.xml/DontImportSun"> <rule ref="rulesets/jsp/basic-jsf.xml/DontNestJsfInJstlIteration"> <rule ref="rulesets/java/basic.xml/DontUseFloatTypeForLoopIndices"> <rule ref="rulesets/java/basic.xml/DoubleCheckedLocking"> <rule ref="rulesets/java/imports.xml/DuplicateImports"> <rule ref="rulesets/jsp/basic.xml/DuplicateJspImports"> <rule ref="rulesets/java/basic.xml/EmptyCatchBlock"> <rule ref="rulesets/java/empty.xml/EmptyCatchBlock"> <rule ref="rulesets/java/finalizers.xml/EmptyFinalizer"> <rule ref="rulesets/java/basic.xml/EmptyFinallyBlock"> <rule ref="rulesets/java/empty.xml/EmptyFinallyBlock"> <rule ref="rulesets/java/basic.xml/EmptyIfStmt"> <rule ref="rulesets/java/empty.xml/EmptyIfStmt"> <rule ref="rulesets/java/basic.xml/EmptyInitializer"> <rule ref="rulesets/java/empty.xml/EmptyInitializer"> <rule ref="rulesets/java/design.xml/EmptyMethodInAbstractClassShouldBeAbstract"> <rule ref="rulesets/java/basic.xml/EmptyStatementBlock"> <rule ref="rulesets/java/empty.xml/EmptyStatementBlock"> <rule ref="rulesets/java/basic.xml/EmptyStatementNotInLoop"> <rule ref="rulesets/java/empty.xml/EmptyStatementNotInLoop"> <rule ref="rulesets/java/basic.xml/EmptyStaticInitializer"> <rule ref="rulesets/java/empty.xml/EmptyStaticInitializer"> <rule ref="rulesets/java/basic.xml/EmptySwitchStatements"> <rule ref="rulesets/java/empty.xml/EmptySwitchStatements"> <rule ref="rulesets/java/basic.xml/EmptySynchronizedBlock"> <rule ref="rulesets/java/empty.xml/EmptySynchronizedBlock"> <rule ref="rulesets/java/basic.xml/EmptyTryBlock"> <rule ref="rulesets/java/empty.xml/EmptyTryBlock"> <rule ref="rulesets/java/basic.xml/EmptyWhileStmt"> <rule ref="rulesets/java/empty.xml/EmptyWhileStmt"> <rule ref="rulesets/ecmascript/basic.xml/EqualComparison"> <rule ref="rulesets/java/design.xml/EqualsNull"> <rule ref="rulesets/java/strictexception.xml/ExceptionAsFlowControl"> <rule ref="rulesets/java/codesize.xml/ExcessiveClassLength"> <rule ref="rulesets/java/coupling.xml/ExcessiveImports"> <rule ref="rulesets/java/codesize.xml/ExcessiveMethodLength"> <rule ref="rulesets/java/codesize.xml/ExcessiveParameterList"> <rule ref="rulesets/java/codesize.xml/ExcessivePublicCount"> <rule ref="rulesets/java/basic.xml/ExtendsObject"> <rule ref="rulesets/java/design.xml/FieldDeclarationsShouldBeAtStartOfClass"> <rule ref="rulesets/java/design.xml/FinalFieldCouldBeStatic"> <rule ref="rulesets/java/finalizers.xml/FinalizeDoesNotCallSuperFinalize"> <rule ref="rulesets/java/finalizers.xml/FinalizeOnlyCallsSuperFinalize"> <rule ref="rulesets/java/finalizers.xml/FinalizeOverloaded"> <rule ref="rulesets/java/finalizers.xml/FinalizeShouldBeProtected"> <rule ref="rulesets/java/basic.xml/ForLoopShouldBeWhileLoop"> <rule ref="rulesets/ecmascript/braces.xml/ForLoopsMustUseBraces"> <rule ref="rulesets/java/braces.xml/ForLoopsMustUseBraces"> <rule ref="rulesets/java/naming.xml/GenericsNaming"> <rule ref="rulesets/ecmascript/basic.xml/GlobalVariable"> <rule ref="rulesets/java/design.xml/GodClass"> <rule ref="rulesets/java/logging-jakarta-commons.xml/GuardDebugLogging"> <rule ref="rulesets/java/design.xml/IdempotentOperations"> <rule ref="rulesets/ecmascript/braces.xml/IfElseStmtsMustUseBraces"> <rule ref="rulesets/java/braces.xml/IfElseStmtsMustUseBraces"> <rule ref="rulesets/ecmascript/braces.xml/IfStmtsMustUseBraces"> <rule ref="rulesets/java/braces.xml/IfStmtsMustUseBraces"> <rule ref="rulesets/jsp/basic.xml/IframeMissingSrcAttribute"> <rule ref="rulesets/java/design.xml/ImmutableField"> <rule ref="rulesets/java/imports.xml/ImportFromSamePackage"> <rule ref="rulesets/java/strings.xml/InefficientEmptyStringCheck"> <rule ref="rulesets/java/strings.xml/InefficientStringBuffering"> <rule ref="rulesets/ecmascript/basic.xml/InnaccurateNumericLiteral"> <rule ref="rulesets/java/design.xml/InstantiationToGetClass"> <rule ref="rulesets/java/strings.xml/InsufficientStringBufferDeclaration"> <rule ref="rulesets/java/migrating.xml/IntegerInstantiation"> <rule ref="rulesets/java/migrating.xml/JUnit4SuitesShouldUseSuiteAnnotation"> <rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseAfterAnnotation"> <rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseBeforeAnnotation"> <rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseTestAnnotation"> <rule ref="rulesets/java/junit.xml/JUnitAssertionsShouldIncludeMessage"> <rule ref="rulesets/java/junit.xml/JUnitSpelling"> <rule ref="rulesets/java/junit.xml/JUnitStaticSuite"> <rule ref="rulesets/java/junit.xml/JUnitTestContainsTooManyAsserts"> <rule ref="rulesets/java/junit.xml/JUnitTestsShouldIncludeAssert"> <rule ref="rulesets/java/migrating.xml/JUnitUseExpected"> <rule ref="rulesets/jsp/basic.xml/JspEncoding"> <rule ref="rulesets/java/basic.xml/JumbledIncrementer"> <rule ref="rulesets/java/coupling.xml/LawOfDemeter"> <rule ref="rulesets/java/j2ee.xml/LocalHomeNamingConvention"> <rule ref="rulesets/java/j2ee.xml/LocalInterfaceSessionNamingConvention"> <rule ref="rulesets/java/optimizations.xml/LocalVariableCouldBeFinal"> <rule ref="rulesets/java/logging-java.xml/LoggerIsNotStaticFinal"> <rule ref="rulesets/java/design.xml/LogicInversion"> <rule ref="rulesets/java/migrating.xml/LongInstantiation"> <rule ref="rulesets/java/naming.xml/LongVariable"> <rule ref="rulesets/java/coupling.xml/LooseCoupling"> <rule ref="rulesets/java/coupling.xml/LoosePackageCoupling"> <rule ref="rulesets/java/j2ee.xml/MDBAndSessionBeanNamingConvention"> <rule ref="rulesets/java/optimizations.xml/MethodArgumentCouldBeFinal"> <rule ref="rulesets/java/naming.xml/MethodNamingConventions"> <rule ref="rulesets/java/sunsecure.xml/MethodReturnsInternalArray"> <rule ref="rulesets/java/naming.xml/MethodWithSameNameAsEnclosingClass"> <rule ref="rulesets/java/naming.xml/MisleadingVariableName"> <rule ref="rulesets/java/basic.xml/MisplacedNullCheck"> <rule ref="rulesets/java/design.xml/MissingBreakInSwitch"> <rule ref="rulesets/java/javabeans.xml/MissingSerialVersionUID"> <rule ref="rulesets/java/design.xml/MissingStaticMethodInNonInstantiatableClass"> <rule ref="rulesets/xml/basic.xml/MistypedCDATASection"> <rule ref="rulesets/java/logging-java.xml/MoreThanOneLogger"> <rule ref="rulesets/java/codesize.xml/NPathComplexity"> <rule ref="rulesets/java/codesize.xml/NcssConstructorCount"> <rule ref="rulesets/java/codesize.xml/NcssMethodCount"> <rule ref="rulesets/java/codesize.xml/NcssTypeCount"> <rule ref="rulesets/jsp/basic.xml/NoClassAttribute"> <rule ref="rulesets/jsp/basic.xml/NoHtmlComments"> <rule ref="rulesets/jsp/basic.xml/NoInlineScript"> <rule ref="rulesets/jsp/basic.xml/NoInlineStyleInformation"> <rule ref="rulesets/jsp/basic.xml/NoJspForward"> <rule ref="rulesets/jsp/basic.xml/NoLongScripts"> <rule ref="rulesets/java/naming.xml/NoPackage"> <rule ref="rulesets/jsp/basic.xml/NoScriptlets"> <rule ref="rulesets/java/design.xml/NonCaseLabelInSwitchStatement"> <rule ref="rulesets/java/design.xml/NonStaticInitializer"> <rule ref="rulesets/java/design.xml/NonThreadSafeSingleton"> <rule ref="rulesets/java/controversial.xml/NullAssignment"> <rule ref="rulesets/java/controversial.xml/OneDeclarationPerLine"> <rule ref="rulesets/java/controversial.xml/OnlyOneReturn"> <rule ref="rulesets/java/design.xml/OptimizableToArrayCall"> <rule ref="rulesets/java/basic.xml/OverrideBothEqualsAndHashcode"> <rule ref="rulesets/java/naming.xml/PackageCase"> <rule ref="rulesets/java/design.xml/PositionLiteralsFirstInComparisons"> <rule ref="rulesets/java/optimizations.xml/PrematureDeclaration"> <rule ref="rulesets/java/design.xml/PreserveStackTrace"> <rule ref="rulesets/java/clone.xml/ProperCloneImplementation"> <rule ref="rulesets/java/logging-jakarta-commons.xml/ProperLogger"> <rule ref="rulesets/java/optimizations.xml/RedundantFieldInitializer"> <rule ref="rulesets/java/j2ee.xml/RemoteInterfaceNamingConvention"> <rule ref="rulesets/java/j2ee.xml/RemoteSessionInterfaceNamingConvention"> <rule ref="rulesets/java/migrating.xml/ReplaceEnumerationWithIterator"> <rule ref="rulesets/java/migrating.xml/ReplaceHashtableWithMap"> <rule ref="rulesets/java/migrating.xml/ReplaceVectorWithList"> <rule ref="rulesets/java/design.xml/ReturnEmptyArrayRatherThanNull"> <rule ref="rulesets/java/basic.xml/ReturnFromFinallyBlock"> <rule ref="rulesets/ecmascript/basic.xml/ScopeForInVariable"> <rule ref="rulesets/java/naming.xml/ShortClassName"> <rule ref="rulesets/java/migrating.xml/ShortInstantiation"> <rule ref="rulesets/java/naming.xml/ShortMethodName"> <rule ref="rulesets/java/naming.xml/ShortVariable"> <rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException"> <rule ref="rulesets/java/design.xml/SimpleDateFormatNeedsLocale"> <rule ref="rulesets/java/junit.xml/SimplifyBooleanAssertion"> <rule ref="rulesets/java/design.xml/SimplifyBooleanExpressions"> <rule ref="rulesets/java/design.xml/SimplifyBooleanReturns"> <rule ref="rulesets/java/design.xml/SimplifyConditional"> <rule ref="rulesets/java/optimizations.xml/SimplifyStartsWith"> <rule ref="rulesets/java/design.xml/SingularField"> <rule ref="rulesets/java/j2ee.xml/StaticEJBFieldShouldBeFinal"> <rule ref="rulesets/java/strings.xml/StringBufferInstantiationWithChar"> <rule ref="rulesets/java/strings.xml/StringInstantiation"> <rule ref="rulesets/java/strings.xml/StringToString"> <rule ref="rulesets/java/naming.xml/SuspiciousConstantFieldName"> <rule ref="rulesets/java/naming.xml/SuspiciousEqualsMethodName"> <rule ref="rulesets/java/naming.xml/SuspiciousHashcodeMethodName"> <rule ref="rulesets/java/controversial.xml/SuspiciousOctalEscape"> <rule ref="rulesets/java/design.xml/SwitchDensity"> <rule ref="rulesets/java/design.xml/SwitchStmtsShouldHaveDefault"> <rule ref="rulesets/java/logging-java.xml/SystemPrintln"> <rule ref="rulesets/java/junit.xml/TestClassWithoutTestCases"> <rule ref="rulesets/java/design.xml/TooFewBranchesForASwitchStatement"> <rule ref="rulesets/java/codesize.xml/TooManyFields"> <rule ref="rulesets/java/codesize.xml/TooManyMethods"> <rule ref="rulesets/java/imports.xml/TooManyStaticImports"> <rule ref="rulesets/java/design.xml/UncommentedEmptyConstructor"> <rule ref="rulesets/java/design.xml/UncommentedEmptyMethod"> <rule ref="rulesets/java/basic.xml/UnconditionalIfStatement"> <rule ref="rulesets/ecmascript/unnecessary.xml/UnnecessaryBlock"> <rule ref="rulesets/java/junit.xml/UnnecessaryBooleanAssertion"> <rule ref="rulesets/java/strings.xml/UnnecessaryCaseChange"> <rule ref="rulesets/java/controversial.xml/UnnecessaryConstructor"> <rule ref="rulesets/java/unnecessary.xml/UnnecessaryConversionTemporary"> <rule ref="rulesets/java/basic.xml/UnnecessaryConversionTemporary"> <rule ref="rulesets/java/unnecessary.xml/UnnecessaryFinalModifier"> <rule ref="rulesets/java/basic.xml/UnnecessaryFinalModifier"> <rule ref="rulesets/java/imports.xml/UnnecessaryFullyQualifiedName"> <rule ref="rulesets/java/design.xml/UnnecessaryLocalBeforeReturn"> <rule ref="rulesets/ecmascript/unnecessary.xml/UnnecessaryParentheses"> <rule ref="rulesets/java/controversial.xml/UnnecessaryParentheses"> <rule ref="rulesets/java/unnecessary.xml/UnnecessaryReturn"> <rule ref="rulesets/java/basic.xml/UnnecessaryReturn"> <rule ref="rulesets/java/optimizations.xml/UnnecessaryWrapperObjectCreation"> <rule ref="rulesets/ecmascript/basic.xml/UnreachableCode"> <rule ref="rulesets/java/design.xml/UnsynchronizedStaticDateFormatter"> <rule ref="rulesets/java/unusedcode.xml/UnusedFormalParameter"> <rule ref="rulesets/java/imports.xml/UnusedImports"> <rule ref="rulesets/java/unusedcode.xml/UnusedLocalVariable"> <rule ref="rulesets/java/unusedcode.xml/UnusedModifier"> <rule ref="rulesets/java/unnecessary.xml/UnusedNullCheckInEquals"> <rule ref="rulesets/java/basic.xml/UnusedNullCheckInEquals"> <rule ref="rulesets/java/unusedcode.xml/UnusedPrivateField"> <rule ref="rulesets/java/unusedcode.xml/UnusedPrivateMethod"> <rule ref="rulesets/java/optimizations.xml/UseArrayListInsteadOfVector"> <rule ref="rulesets/java/optimizations.xml/UseArraysAsList"> <rule ref="rulesets/java/junit.xml/UseAssertEqualsInsteadOfAssertTrue"> <rule ref="rulesets/java/junit.xml/UseAssertNullInsteadOfAssertTrue"> <rule ref="rulesets/java/junit.xml/UseAssertSameInsteadOfAssertTrue"> <rule ref="rulesets/java/junit.xml/UseAssertTrueInsteadOfAssertEquals"> <rule ref="rulesets/java/design.xml/UseCollectionIsEmpty"> <rule ref="rulesets/xsl/xpath.xml/UseConcatOnce"> <rule ref="rulesets/java/controversial.xml/UseConcurrentHashMap"> <rule ref="rulesets/java/logging-jakarta-commons.xml/UseCorrectExceptionLogging"> <rule ref="rulesets/java/strings.xml/UseEqualsToCompareStrings"> <rule ref="rulesets/java/strings.xml/UseIndexOfChar"> <rule ref="rulesets/java/design.xml/UseLocaleWithCaseConversions"> <rule ref="rulesets/java/design.xml/UseNotifyAllInsteadOfNotify"> <rule ref="rulesets/java/controversial.xml/UseObjectForClearerAPI"> <rule ref="rulesets/java/j2ee.xml/UseProperClassLoader"> <rule ref="rulesets/java/design.xml/UseSingleton"> <rule ref="rulesets/java/optimizations.xml/UseStringBufferForStringAppends"> <rule ref="rulesets/java/strings.xml/UseStringBufferLength"> <rule ref="rulesets/java/design.xml/UseVarargs"> <rule ref="rulesets/java/unnecessary.xml/UselessOperationOnImmutable"> <rule ref="rulesets/java/basic.xml/UselessOperationOnImmutable"> <rule ref="rulesets/java/unnecessary.xml/UselessOverridingMethod"> <rule ref="rulesets/java/basic.xml/UselessOverridingMethod"> <rule ref="rulesets/java/unnecessary.xml/UselessParentheses"> <rule ref="rulesets/java/basic.xml/UselessParentheses"> <rule ref="rulesets/java/strings.xml/UselessStringValueOf"> <rule ref="rulesets/java/naming.xml/VariableNamingConventions"> <rule ref="rulesets/ecmascript/braces.xml/WhileLoopsMustUseBraces"> <rule ref="rulesets/java/braces.xml/WhileLoopsMustUseBraces">
关于PMD rulesets规则的意思可以查看:http://pmd.sourceforge.net/pmd-5.0.4/rules/index.html
相关推荐
Jenkins 是一个流行的自动化构建和 Continuous Integration(CI)工具,通过安装和配置静态分析工具,可以对 Java 代码进行检测和改进。本文将详细介绍 Jenkins 中 FindBugs、PMD、CheckStyle 和 Violations 静态...
它允许开发团队自动化构建、测试和部署软件,确保代码的质量和稳定性。通过定期检查代码仓库的变更,Hudson可以快速发现并报告构建失败,从而帮助团队及时解决问题。Hudson支持多种版本控制系统、构建工具和测试框架...
对于Java静态代码分析工具的未来展望,文章指出随着技术的发展,将会出现更多集成度更高、自动化更强的工具,这将有助于进一步提升开发效率和软件质量。同时,文章也鼓励开发者对集成过程中的问题进行反馈,以便不断...
5. **重复代码检测**:PMD的CPD(Copy-Paste Detector)模块可以查找代码中的重复片段,这对于避免代码冗余和提高代码复用率非常有帮助。 6. **自定义规则集**:除了预设的规则外,用户还可以自定义自己的规则集,...
- **Gradle版本**:本知识点中提到的Gradle版本为2.6,它是一个构建自动化工具,支持多种语言的项目构建,包括Java、Groovy、Scala等。 - **操作系统环境**:所使用的操作系统为Windows Server 2008,这表明Gradle...
通过自动化构建和测试,CI确保每次合并的代码都能够正常工作。Eclipse作为一款流行的开源集成开发环境(IDE),支持多种语言和框架,可以与各种CI工具如Jenkins、Travis CI或GitLab CI等集成,实现自动构建和测试。 ...
3. **重复代码检测**:减少不必要的代码重复,提高代码复用性和维护性。 4. **注释完整性评估**:确保代码具有恰当的注释水平,增强可读性和可理解性。 5. **架构依赖性分析**:分析代码中的包和类之间的依赖关系,...
2. PMD:PMD 插件能检测出潜在的代码问题,如冗余代码、未使用的变量、复杂的表达式等,有助于改善代码质量和可维护性。 3. FindBugs:通过分析字节码,FindBugs 能发现可能存在的错误和缺陷,提前预防潜在问题。 ...
在实际操作中,开发者通常会设置构建工具(如Maven或Gradle)来自动化这些检测过程,确保每次构建时都执行代码质量检查,确保代码始终保持良好的状态。通过持续集成服务器(如Jenkins),可以进一步确保代码质量的...
总的来说,`jenkins.war`、PMD、Checkstyle 和 FindBugs 结合使用,可以创建一个强大的自动化CI流程,保证代码质量,减少缺陷,同时提高开发效率。通过持续集成,开发团队能够更快地发现和解决问题,从而更快地交付...
Jenkins是一款广泛应用的持续集成工具,它允许开发者自动化软件构建、测试和部署过程。为了实现这些功能,Jenkins依赖于一系列插件来扩展其核心能力。在“jenkins所需基本插件”这个压缩包中,包含了一些关键的插件...
10. **集成测试与静态代码分析**:通过 Jenkins,开发者可以在构建过程中执行集成测试和静态代码分析,如 JUnit 测试、FindBugs 或 PMD,以提升代码质量和稳定性。 11. **持续部署(Continuous Deployment/Release...
Jenkins是一款广泛应用于持续集成(Continuous Integration)的开源自动化服务器,它支持各种软件项目的构建、测试和部署。在这个场景中,我们关注的是Jenkins的2.32.3版本,这是一个WAR包,意味着它是Web应用程序的...
Jenkins是一款广泛使用的持续集成工具,它允许开发者自动化各种任务,包括构建、测试和部署软件。在本实践中,我们将深入探讨如何使用Jenkins配合checkstyle、findbugs和pmd进行代码质量检查,以及如何配置Maven项目...
7. **集成其他工具**:PMD插件可以与其他持续集成工具(如Jenkins)或构建工具(如Maven)集成,实现自动化代码质量检查。 通过学习和应用PMD插件,开发者不仅可以提升代码质量,还能培养良好的编程习惯,降低维护...
- PMD支持Ant和Jenkins等持续集成工具,可以自动化代码审查流程。 - 通过PMD的API,开发者可以开发自定义的代码分析模块,实现更深度的代码质量控制。 总的来说,"pmd-bin-5.2.3"是一个用于代码质量检测的实用...
这使得自动化代码检查成为可能,比如在构建过程中自动触发PMD分析。 4. **支持IDE插件**:PMD与流行的开发环境如Eclipse、IntelliJ IDEA、NetBeans等有集成插件,可以直接在IDE内查看和修复PMD报告的问题,提高了...
1. 自动化构建:Jenkins能自动化执行构建任务,包括编译代码、打包应用、运行测试等,确保每次代码更改后都能快速发现并修复问题。 2. 代码质量检查:通过集成静态代码分析工具,如Checkstyle、PMD,检查代码规范性...
Jenkins 是一个开源的持续集成(Continuous Integration, CI)服务器,广泛用于自动化各种软件构建、测试和部署任务。它的灵活性和强大的插件生态系统使得它在软件开发过程中扮演着至关重要的角色。通过定时触发构建...
Jenkins作为一款开源的CI/CD工具,广泛应用于自动化构建、测试和部署。Maven则是一个项目管理工具,用于构建、管理和打包Java项目。而Tomcat是一款流行的Java Servlet容器,用于运行Web应用程序。本篇文章将深入探讨...