Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议增加jenkins插件 #47

Closed
zmywly8866 opened this issue Oct 16, 2017 · 5 comments
Closed

建议增加jenkins插件 #47

zmywly8866 opened this issue Oct 16, 2017 · 5 comments

Comments

@zmywly8866
Copy link

建议增加jenkins插件,方便持续集成时自动检测

@xuantan
Copy link
Collaborator

xuantan commented Oct 31, 2017

@smiler158 看看可以统一提供一个集成的样例

@smiler158
Copy link
Contributor

smiler158 commented Nov 2, 2017

p3c规则是基于pmd规则上修改而来,可以直接参数pmd与jekins集成文档,将规则包换成p3c的包就可以,可参考 http://blog.csdn.net/hwhua1986/article/details/48342745 。 另插件已在云效公有云产品中集成,立即体验!https://rdc-test.aliyun.com/

@smiler158
Copy link
Contributor

另附,直接使用p3c-pmd包扫描示例。
java -cp p3c-pmd.jar net.sourceforge.pmd.PMD -d /usr/src -R rule/ali-comment.xml -f text
参数解释:
-d 源码目录
-R 指定规则,多个规则以,号分开
-f 报告格式,text html等。

@ouyangpeng
Copy link

@zmywly8866 尴尬,我提了个Issue,然后看到了你提的Issue。#182

@smiler158 回复说是基于pmd规则做的,那么应该是可以配置检测到Issue规则的话就停止编译。

task pmd(type: Pmd) {
    description 'Run PMD'
    group 'verification'

    ignoreFailures = false
    ruleSetFiles = files("$configDir/pmd/pmd-ruleset.xml")
    ruleSets = []

    source 'src'
    include '**/*.java'
    exclude '**/gen/**'

    reports {
        xml.enabled = false
        html.enabled = true
        xml {
            destination "$reportsDir/pmd/pmd.xml"
        }
        html {
            destination "$reportsDir/pmd/pmd.html"
        }
    }
}

pmd的规则类似

<?xml version="1.0"?>
<!--
  ~ Copyright 2015 Vincent Brison.
  ~
  ~ 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.
  -->

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Android Application Rules"
    xmlns="http://pmd.sf.net/ruleset/1.0.0"
    xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
    xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd">

    <description>Custom ruleset for Android application</description>

    <exclude-pattern>.*/R.java</exclude-pattern>
    <exclude-pattern>.*/gen/.*</exclude-pattern>

    <!-- Android -->
    <!-- http://pmd.sourceforge.net/pmd-4.3.0/rules/android.html -->
    <rule ref="rulesets/java/android.xml"/>

    <!-- Design -->
    <!-- http://pmd.sourceforge.net/pmd-4.3.0/rules/design.html -->
    <rule ref="rulesets/java/design.xml">
        <exclude name="UncommentedEmptyMethod"/>
    </rule>

    <!-- Naming -->
    <!-- http://pmd.sourceforge.net/pmd-4.3.0/rules/naming.html -->
    <rule ref="rulesets/java/naming.xml/ShortClassName">
        <properties>
            <property name="minimum" value="3"/>
        </properties>
    </rule>
    <!-- other rules ignored for brevity -->

    <rule ref="rulesets/java/clone.xml" />
    <rule ref="rulesets/java/finalizers.xml" />
    <rule ref="rulesets/java/imports.xml">
        <!-- Espresso is designed this way !-->
        <exclude name="TooManyStaticImports" />
    </rule>
    <rule ref="rulesets/java/logging-java.xml" />
    <rule ref="rulesets/java/braces.xml" />
    <rule ref="rulesets/java/strings.xml" />
    <rule ref="rulesets/java/basic.xml" />
    <rule ref="rulesets/java/naming.xml">
        <exclude name="AbstractNaming" />
        <exclude name="LongVariable" />
        <exclude name="ShortMethodName" />
        <exclude name="ShortVariable" />
        <exclude name="VariableNamingConventions" />
    </rule>
</ruleset>

@smiler158 只是阿里这个插件的rules是否可以列出来呢??

@xuantan xuantan closed this as completed Nov 16, 2017
@michael-ancestor
Copy link

maven下使用p3c-pmd检测不出来任何问题,使用插件是可以检测出来的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants