2011-08-27 4 views
5

나는 다음 소나 개미의 목표는 정의 : 나는 '개미 수중 음파 탐지기'를 실행하고 브라우저에서 수중 음파 탐지기를 가져 오면소나가 테스트 통계를 내보내는 방법?

<target name='sonar'> 
    <property name='sonar.sources' value='${src.dir}'/> 
    <property name='sonar.tests' value='${test.src.dir}'/> 
    <property name='sonar.binaries' value='build/classes'/> 
    <path id='jars'> 
     <fileset dir='${env.JAVA_HOME}/jre/lib' includes='*.jar'/> 
     <fileset dir='build/lib/test' includes='*.jar'/> 
    </path> 
    <pathconvert property='sonar.libraries' refid='jars' pathsep=','/> 

    <exec executable='p4' outputproperty='p4.P4CLIENT'> 
     <arg value='set'/> 
     <arg value='P4CLIENT'/> 
    </exec> 
    <propertyregex 
      property='p4client' 
      input='${p4.P4CLIENT}' 
      regexp='P4CLIENT=([^ ]+) *.*' 
      replace='\1'/> 
    <propertyregex 
      property='sonar.timestamp' 
      input='${build.time}' 
      regexp='_' 
      replace='T'/> 
    <sonar:sonar key='com.netflix:${module.name}' version='${p4client}@${sonar.timestamp}' xmlns:sonar='antlib:org.sonar.ant'/> 

    <property name='sonar.dynamicAnalysis' value='reuseReports'/> 
    <property name='sonar.emma.reportPath' value='${coverage.dir}'/> 
</target> 

, 내가 src 디렉토리의 클래스에 대한 정보를 볼 수 있지만 물건에 대해 아무것도 테스트 디렉토리.

sonar.sources에 $ {test.src.dir}을 추가하고 sonar.tests를 설정하지 않은 경우 테스트 클래스에 대한 정보가 표시되지만 Sonar는 여전히 0 테스트 성공을보고합니다.

어떻게하면 각 테스트 방법과 통계로 드릴 수 있습니까?

답변

2

'sonar.surefire.reportsPath'속성은 음파 탐지기 대상을 정의하기 전에 정의해야합니다. (여전히 커버리지 정보를 수출 아니에요 있지만)

다음 정의는 수출 테스트 정보를 가져옵니다

<property name='sonar.surefire.reportsPath' value='${test.dir}'/> 

<property name='sonar.dynamicAnalysis' value='reuseReports'/> 
<property name='sonar.emma.reportPath' value='${coverage.report.dir}'/> 

<target name='sonar'> 
    <property name='sonar.sources' value='${src.dir}'/> 
    <property name='sonar.tests' value='${test.src.dir}'/> 
    <property name='sonar.binaries' value='${build.dir}'/> 
    <path id='jars'> 
     <fileset dir='${env.JAVA_HOME}/jre/lib' includes='*.jar'/> 
     <fileset dir='${ivy.lib.dir}/test' includes='*.jar'/> 
    </path> 
    <pathconvert property='sonar.libraries' refid='jars' pathsep=','/> 

    <exec executable='p4' outputproperty='p4.P4CLIENT'> 
     <arg value='set'/> 
     <arg value='P4CLIENT'/> 
    </exec> 
    <propertyregex 
      property='p4client' 
      input='${p4.P4CLIENT}' 
      regexp='P4CLIENT=([^ ]+) *.*' 
      replace='\1'/> 
    <propertyregex 
      property='sonar.timestamp' 
      input='${build.time}' 
      regexp='_' 
      replace='T'/> 

    <sonar:sonar key='com.netflix:${module.name}' version='${p4client}@${sonar.timestamp}' xmlns:sonar='antlib:org.sonar.ant'/> 
</target> 
+0

안녕하세요, [비슷한 문제가] 안녕하세요 (http://stackoverflow.com/questions/21267948/sonarqube-test-coverage-report-for-android-built-with-ant)하지만 꽤 동일하지 않습니다. .emma 파일을 어떻게 가져 왔니? – JaKXz

+0

실제로 Sonar 사용을 중단했으며 자체 빌드 데이터 저장소를 구축 할 예정입니다. –

6

이 문제에 걸쳐, 나는 마침내 우리의 엠마 코드 커버리지에 대해보고하기 위해 수중 음파 탐지기를 가지고 실행 다른 사람을 위해. 첫 번째 문제는 Emma 플러그인이 사용중인 Sonar 버전 (3.1.1)과 함께 제공되지 않았다는 것입니다. 나는 download it을 가지고 Sonar의 extensions/plugins 디렉토리에 설치하고 다시 시작해야합니다.

가 그럼 난 내 build.xml 파일에서 다음 속성을 설정했다 : 일부 후

[sonar:sonar] 13:41:49.705 WARN  org.sonar.INFO - No coverage (*.ec) file found in /my/local/path 
[sonar:sonar] 13:41:49.708 WARN  org.sonar.INFO - No metadata (*.em) file found in /my/local/path 

:이 후

<property name="sonar.core.codeCoveragePlugin" value="emma" /> 
<property name="sonar.emma.reportPath" value="${coverage.dir}" /> 

을, 나는이어야은 소나 개미 작업을 실행 한 후 다음과 같은 출력을 보았다 파기, 나는 Sonar Emma plugin의 내부에서 그것이 .ec (커버리지) 파일과 .em (메타 데이터) 파일을 찾기 위해 하드 코딩된다는 것을 알았다. 불행히도, 나의 커버리지 파일은 나의 메타 데이터 파일과 마찬가지로 .emma 확장자를 가지며, 다른 기능을 깨뜨릴 수 있기 때문에 이름을 바꿀 수 없었다. 그래서 나는 Sonar Emma Plugin이 기대하는 명명 표준과 일치하는 파일을 복사하기 위해 다음 Ant 태스크를 작성했다.

<target name="createEmmaFilesWithSonarNamingStandard" depends="defineAntContribTasks"> 
    <if> 
     <available file="${coverage.dir}/metadata.emma" /> 
     <then> 
      <copyfile src="${coverage.dir}/metadata.emma" dest="${coverage.dir}/metadata.em" /> 
     </then> 
    </if> 
    <if> 
     <available file="${coverage.dir}/coverage.emma" /> 
     <then> 
      <copyfile src="${coverage.dir}/coverage.emma" dest="${coverage.dir}/coverage.ec" /> 
     </then> 
    </if> 
</target> 

다시이를 실행 한 후, 나는 새로운 문제를 건너 왔어요 : 좀 더 파고 후

org.sonar.api.utils.SonarException: java.io.IOException: cannot read [/my/local/path/build/coverage/metadata.em]: created by another EMMA version [2.0.5312] 

, 나는 소나 엠마 1.0.1 플러그인 엠마 2.0.5312과에 대해 컴파일 된 것을 발견 Sonar Emma 1.1 및 1.2.x를 Sonar Emma plugin 페이지에 명시된 Emma 버전 2.1.5320에 대한 것입니다.

Emma의 2.1.5320 버전을 다운로드했으며 emma.jaremma_ant.jar을 모두 Ant 라이브러리 디렉토리에 바꿨습니다. 깨끗한 재 컴파일과 테스트 후, 나는 Sonar Ant 태스크를 재실행 할 수 있었고, Sonar에 코드 커버리지를 반영시킬 수있었습니다.

관련 문제