checkstyle 사용

7100 단어 규범.checkstyle
다운로드:checkstyle 규범(codeformatter codetemplates checkstyle 파일 포함)
http://download.csdn.net/download/knight_black_bob/9640991
 
checkstyle 플러그 인 다운로드
http://download.csdn.net/download/knight_black_bob/9643244
 
 
 
1.설정 코드 템 플 릿
 Eclipse 코드 모드 설정
Eclipse 설정 패 널 을 열 고 Java->코드 스타일->코드 템 플 릿 을 선택 하 십시오.
그림: 
checkstyle 使用_第1张图片  
오른쪽 Import...단 추 를 누 르 고 codetemplates.xml 파일 을 선택 하 십시오.
그런데 
 
 
 
2.tab 키 대신 4 개의 빈 칸 사용 설정
tab 키 는 다른 IDE,편집기(예:EditPlus,UltraEdit 등)에서 사 용 됩 니 다.
의 빈 칸 수가 다 르 기 때문에 통일 을 위해 개발 자 들 은 tab 대신 4 개의 빈 칸 을 통일 적 으로 사용한다.
키.
Eclipse 설정 패 널 을 열 고 General->Editors->Text Editors 를 선택 하 십시오.
그림: 
 
Insert spaces for tabs 를 선택 하고 Displayed tab width 를 4 로 설정 합 니 다.
3.설정 코드 Formatter
3.1 Eclipse 의 코드 포맷 모드 설정
Eclipse 설정 패 널 을 열 고 Java->Code Style->Formatter 를 선택 하 십시오.그림:
  
오른쪽 Import...단 추 를 누 르 고 codeformatter.xml 파일 을 선택 하 십시오.
그런데
3.2 포맷 사용 설명
어떤 파일 을 포맷 하려 면 다음 과 같은 몇 가지 방법 을 사용 할 수 있 습 니 다.
1.파일 을 열 면 코드 영역 에서"CTRL+SHIFT+F"단축 키 를 사용 합 니 다.
2.파일 을 열 고 코드 영역 에서 오른쪽 단 추 를 눌 러 Source->Format 를 선택
네.
   【설명]CTRL+Shift+F 단축 사용 을 권장 합 니 다.
 
4.Checkstyle 설정 
4.1 ant 와 통합
ant 프로젝트 에서 Checkstyle 을 사용 하려 면 먼저 checkstyle 의 jar 패 키 지 를 설치 해 야 합 니 다.
checkstyle-6.15-all.jar 의 경우 이 가방 에는 Checkstyle 을 실행 하 는 데 필요 한 클래스 파일 이 포함 되 어 있 습 니 다.
다음은 build.xml 파일 에 taskdef 성명 을 추가 합 니 다. 
 
<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"          classpath="/path/to/checkstyle-6.15-all.jar"/>        checkstyle   target。
<target name="checkstyle" >
  <checkstyle config="checkstyle.xml" failureProperty="checkstyle.failure"
failOnViolation="false">
  <formatter type="xml" tofile="${result.xml}/checkstyle_report.xml"/>
    <fileset dir="/home/jenkins/workspace/JAVA_checkstyle_ANT"
includes="**/*.java"/>
  </checkstyle>
  <style in="${result.xml}/checkstyle_report.xml" 
out="${result.html}/checkstyle_report.html"  style="${basedir}/checkstyle.xsl" /> 
  <fail if="checkstyle.failure">
          Checkstyle failed.
        </fail>
</target> 

 
ant checkstyle 을 실행 하여 스 캔 할 수 있 습 니 다.자세 한 결과 정보 저장
${result.xml}/checkstyle_report.xml 중.
4.2 MAVEN 과 통합
maven 에서 maven-checkstyle-plugin 이라는 플러그 인 을 실행 합 니 다.
CheckStyle task。다음은 간단 한 설정 입 니 다.
 
<reporting> 

     <plugins> 

      <plugin> 

        <groupId>org.apache.maven.plugins</groupId> 

        <artifactId>maven-checkstyle-plugin</artifactId> 

        <version>2.9.1</version> 

<configuration> 

           <configLocation> config/maven_checks.xml</configLocation> 

<includes> 

            **\/package\/**.java,**\/otherpackage\/**.java 

             </includes> 

            </configuration> 

    </plugin> 

        <plugin> 

            <groupId>org.apache.maven.plugins</groupId> 

            <artifactId>maven-jxr-plugin</artifactId> 

            <version>2.3</version> 

         </plugin> 

        </plugins> 

</reporting> 

 
mvn checkstyle:checkstyle 을 실행 하여 스 캔 할 수 있 습 니 다.checkstye 의 상세 한 결과 정보
target/checkstyle-result.xml 에 저장 합 니 다.
4.3 지정 한 파일 에 대한 검사 건 너 뛰 기
지정 한 파일 의 일부 줄 에 문제 가 있 지만 무시 하려 면 suppression 을 사용 할 수 있 습 니 다.방법 은 checkstyle-suppressions.xml 파일 을 만 드 는 것 입 니 다.그 중 에 아래 의 내용 을 첨가 하 다
 
<?xml version="1.0"?> 
<!DOCTYPE suppressions PUBLIC       
  "-//Puppy Crawl//DTD Suppressions 1.0//EN"        
 "http://www.puppycrawl.com/dtds/suppressions_1_0.dtd"> 
 
<suppressions>     
<suppress checks="MagicNumberCheck"              
 files="SessionMessageSource.java"               
lines="221,250-295"/>

 </suppressions> 

 
 
그리고 maven-checkstyel-plugin 을 설정 합 니 다....
다음 두 문장 을 추가 합 니 다:path/to/checkstylessuppressions.xmlcheckstyle.suppressions.file
4.4 Jenkins 출력 보고서
checkstyle 을 실행 한 후 Publish Checkstyle analysis results 플러그 를 사용 할 수 있 습 니 다.
파일,생 성 된 xml 결과 파일 을 분석 할 수 있 습 니 다. 
그림 1 Checkstyle 보고서 출력 플러그 인 
checkstyle 使用_第2张图片  
그림 2 jenkins 출력 Checkstyle 보고서
 
 
 
 
checkstyle 플러그 인 추가
checkstyle 使用_第3张图片  
 
 
checkstyle.xml 를 기본 검색 으로 추가 합 니 다.
checkstyle 使用_第4张图片  
 
eclipse > preferences > checkstyle > new > external configuration file > ok
> set as default
 
기본 값 으로 설정
 
항목 오른쪽 단추 format 을 누 르 면 checkstyle 오류 가 발생 합 니 다.
checkstyle 使用_第5张图片  
 
 
 
 
 _NA_SA  설정 명령
mvn clean install checkstyle:checkstyle findbugs:findbugs -Dmaven.test.skip=true
 
 
 
 
 

좋은 웹페이지 즐겨찾기