2012-04-18 2 views
7

라이브러리 (jar 파일)를 사용하는 Java 프로젝트가있는 경우이 jar 파일 안에 클래스의 코드 적용 범위를 얻을 수 있습니까?jacoco를 사용하여 외부 Java 라이브러리의 코드 적용 범위를 얻으려면 어떻게해야합니까?

이 아이디어는 프로젝트가 의존하는 외부 라이브러리의 비율 (스프링, 최대 절전 또는 스칼라 프로젝트 인 경우 스칼라 병일 수 있음, 왜 그렇지 않은지)을 확인하고자합니다. 실제로 사용됩니다. 나는 심지어 가능한 한 가장 작은 병을 얻기 위해 필요한 .class 파일 (예 : apache felix와 같은 플러그인)을 포함하는 단일 항아리에 파일을 나열하고 다시로드하려고 시도 할 수 있다고 상상합니다. 나는 정말로 이것을하고 싶어하는지 확신 할 수 없다. 나는 여러 가지 이유 때문에 아마도 나쁜 생각 일지 모른다. 그러나 나는 그것을 실험으로 생각한다.

jacoco는이를 수행하는 방법을 찾지 못했습니다. jacoco는 내 프로젝트에서 직접 클래스 파일에 대한 적용 범위만을보고합니다. 나는이 태그를 포함 변경 시도했습니다

 <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <version>0.5.6.2012</version> 
      <configuration> 
       <destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</destfile> 
       <datafile>${basedir}/target/coverage-reports/jacoco-unit.exec</datafile> 
       <includes> 
        <include>**</include> 
       </includes> 
      </configuration> 
      <executions> 
       <execution> 
        <id>jacoco-initialize</id> 
        <goals> 
         <goal>prepare-agent</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>jacoco-site</id> 
        <phase>package</phase> 
        <goals> 
         <goal>report</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

하지만 유일한 효과는 클래스 파일을 직접 내부에 포함하는 기본 제한됩니다 : 어쩌면 내가 뭔가 잘못하고있어,이 같은 받는다는 플러그인을 사용하고 있습니다 내 프로젝트.

미리 감사드립니다.


oers '답변 후 편집 : 나는 그것이 매우 복잡하지만, 내가 할 수없는 antrun 플러그인 버전 (와 함께 많은 문제가 있었다, 개미와 antrun - 플러그인으로 작업을 수행하는 방법을 발견

최근 버전 작업, 심지어 기본 작업) 그리고 나는 정말 메이븐에 충실하고 싶습니다. 개미 대신에 je jacoco maven plugin을 사용하는 방법을 아는 사람이 있다면, 나는 관심이있다.

개미가있는 부분적인 해결책 : 실제로 jacoco.exec 파일에는 이미 내 외부 항아리의 클래스에 대한 참조가 포함되어 있습니다. 따라서 생각했던대로 런타임 단계가 아니라 이러한 jar를 고려해야한다는 것은보고 작업입니다. 여기 내가 사용하는 받는다는 구성은 (내가 http://intellectualcramps.wordpress.com/2012/03/22/jacoco-tycho-and-coverage-reports/에 대한 도움말을 발견)입니다 : 당신은 보고서의 목표를 분석 할 라이브러리의 클래스를 줄 필요가

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <!--<version>1.7</version>--> 
      <dependencies> 
       <dependency> 
        <groupId>org.jacoco</groupId> 
        <artifactId>org.jacoco.ant</artifactId> 
        <version>0.5.6.2012</version> 
       </dependency> 
       <dependency> 
        <groupId>ant-contrib</groupId> 
        <artifactId>ant-contrib</artifactId> 
        <version>20020829</version> 
       </dependency> 
      </dependencies> 
      <executions> 
       <execution> 
        <id>jacoco-report</id> 
        <phase>package</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        <configuration> 
         <tasks> 

          <taskdef name="jacoco-report" 
            classname="org.jacoco.ant.ReportTask" 
            classpathref="maven.plugin.classpath" /> 
          <taskdef classpathref="maven.runtime.classpath" 
        resource="net/sf/antcontrib/antcontrib.properties" /> 
          <available 
       file="${project.basedir}/target/jacoco.exec" 
       property="jacoco.exec.file.exists" /> 
          <echo message="${project.basedir}/target/jacoco.exec" /> 
          <if> 
           <equals arg1="${jacoco.exec.file.exists}" 
         arg2="true" /> 
           <then> 
            <echo message="Executing jacoco report" /> 

            <trycatch> 
             <try> 
              <jacoco-report> 
               <executiondata> 
                <file 
           file="${project.basedir}/target/jacoco.exec" /> 
               </executiondata> 

               <structure name="Minerva"> 
                <classfiles> 
                 <fileset 
            dir="target/classes" /> 

                 <fileset dir="C:/Data/dev/m2Repository/com/groupama/framework/crypt/fwk-cryptage/1.0/"> 
                  <include name="**/*.jar"/> 
                 </fileset> 

                </classfiles> 

                <sourcefiles 
            encoding="UTF-8"> 
                 <fileset 
            dir="src/main/java" /> 
                </sourcefiles> 
               </structure> 
               <html destdir="${project.basedir}/target/jacoco/report" /> 
               <xml destfile="${project.basedir}/target/jacoco/report/jacoco.xml"/> 
              </jacoco-report> 
             </try> 
             <catch> 
              <echo>skipping</echo> 
             </catch> 
            </trycatch> 
           </then> 
           <else> 
            <echo message="No jacoco.exec file found." /> 
           </else> 
          </if> 
         </tasks> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

답변

1

. 불행히도 그것에 대한 문서를 찾을 수 없습니다. The official docu is ... hm ... sparse

개미를 실행할 수 있다면 report task을 살펴 보시기 바랍니다.

<jacoco:report> 

    <executiondata> 
     <file file="jacoco.exec"/> 
    </executiondata> 

    <structure name="Example Project"> 
     <classfiles> 
      <fileset dir="classes"/> <!-- HERE THE CLASSES FROM YOUR LIB --> 
     </classfiles> 
     <sourcefiles encoding="UTF-8"> 
      <fileset dir="src"/> <!-- HERE THE SORUCESFROM YOUR LIB --> 
     </sourcefiles> 
    </structure> 

    <html destdir="report"/> 

</jacoco:report> 
+0

정말 완벽해야 할 설명서가 있습니다. 나는 그것이 매개 변수화 될 필요가있는 실행 작업이라고 정말로 생각했다; 당신은 jacoco.exec 파일을 살펴 보았습니다. 이미 외부 항아리 내부의 클래스에 대한 참조를 포함하고 있다는 것을 알게되었습니다. 이는 올바르게 매개 변수 화되어야하는 보고서라는 것을 의미합니다. 개미를 모르는 나는 그것을하기 전에 모든 아침을 보냈지 만, 마침내 성공했다.그것은 부분적으로 나를 만족 시키지만, 내 대답은 아래를보십시오. 그러나 그것은 올바른 방향으로 나아가는 단계입니다. 어쨌든 고마워요! – Guillaume

+0

감사합니다. ores가 내 하루를 저장했습니다. – vinod

0

이 질문이 오래된 것은 사실이지만 여전히 관련성이 있습니다. 외부 라이브러리가 Maven 프로젝트 인 경우에는 라이브러리 소스 디렉토리로 이동하여 내에서있는 TestSuite로 이전에 얻은 JaCoCo 보고서를 요청할 수 있습니다

mvn org.jacoco:jacoco-maven-plugin:0.7.8:report -Djacoco.dataFile=/path/to/jacoco.exec 

당신은 $ {프로젝트}/대상/사이트의 보고서를 얻으을/jacoco 디렉토리.

관련 문제