On Thu, Aug 2, 2018 at 7:22 AM Michelle Gao <[email protected]> 
wrote:

> Sure Evgeny, I attached the part of project, but can compile and create 
> the jacoco.xml 
>
I also added: 
>
> afterEvaluate {
>         classDirectories = files(classDirectories.files.collect {
>             fileTree(dir: it, exclude: ['**/**WebHandlers.class'])
>         })
>     }
>
>
> in the jacocoTestReport, but did not see it works.
>
> We are having multi subprojects, do not know how does it affect. Also 
> somewhere use excludes. Do they make difference  or not.
>
> thank you!
> Michelle
>

As I can see from build of your projects the name of class file that 
references "ServerRequestExtensions.kt"
is actually "ActivityWebHandlers$create$$inlined$bodyToMono$1.class"
so of course it won't be matched by pattern "*/WebHandlers.class"

Before attached patch command

gradle clean build jacocoTestReport

produces report in "service-activity/build/reports/jacoco"

<https://lh3.googleusercontent.com/-93v30nDToBI/W2MPx2ECAcI/AAAAAAAAB_4/LZzZBDouUywmD5qGH6lqdkyD0qiiIvLPgCLcBGAs/s1600/before1.png>

You also have task "jacoco", so after first command

gradle jacoco

produces report in "build/reports/jacoco"

<https://lh3.googleusercontent.com/-B-_RAi5p5BU/W2MP3njnxRI/AAAAAAAAB_8/w_09-LrrrIAv315M8nRkQrG7s4GO3HCyQCLcBGAs/s1600/before2.png>


After attached patch


<https://lh3.googleusercontent.com/-pqk5lZNiqKc/W2MQJ_bIsMI/AAAAAAAACAI/8euPbrXfsV4gXsGVDFN74EaqyEII5LV2wCLcBGAs/s1600/after1.png>

and

<https://lh3.googleusercontent.com/-L5t8ahAlnks/W2MQNVOYHpI/AAAAAAAACAM/7WnVIcDFhpcvPXF3kxg_iObjM71vA3hMACLcBGAs/s1600/after2.png>

respectively. And they disappear from XML also:

cat service-activity/build/reports/jacoco/test/jacocoTestReport.xml | grep 
"Extensions.kt" | wc -l
0

cat build/reports/jacoco/jacoco/jacoco.xml | grep "Extensions.kt" | wc -l
0


Regards,
Evgeny

On Thursday, August 2, 2018 at 12:19:32 AM UTC+2, Evgeny Mandrikov wrote:
>
>
>
> On Wednesday, August 1, 2018 at 11:22:12 PM UTC+2, Michelle wrote:
>>
>> Hey Evgeny,
>>
>> We know those files are created from AcitivityWebHandlers.kt, because of 
>> the serverRequest.bodyToMono<Activity>, it use library Extensions stuff. 
>> but might be a better way to do it or you have a better idea to help this.
>>
>
> If you know the *class files*, then
> as was said in 
> https://groups.google.com/d/msg/jacoco/6O5R8fHPrIc/h1yhcunyCQAJ
> you need to configure Gradle to exclude them
> similarly to example attached in 
> https://groups.google.com/d/msg/jacoco/6O5R8fHPrIc/G-ywuvnyCQAJ
>
>  
>
>>
>> I like to send you the project which I cut, but can do ./gradlew check 
>> and ./gradlew jacoco to create the jacoco.xml in 
>> build/reports/jacoco/jacoco/jacoco.xml
>>
>> Can I sent it to your email, instead of here.
>>
>> Thank you,
>> Michelle
>>
>> On Wednesday, 1 August 2018 13:12:54 UTC-5, Evgeny Mandrikov wrote:
>>>
>>>
>>>
>>> On Wednesday, August 1, 2018 at 5:16:40 PM UTC+2, Michelle wrote:
>>>>
>>>> Hey Evengy,
>>>>
>>>> I knew this, just think codeclimate will only read bar and ignore baz 
>>>> as now. Looks like the coverage report number is correct so far. 
>>>>
>>>> However, I do not like this solution and like to have as possible as 
>>>> better one. the solution you told, I could not use it. Because class files 
>>>> does not include the Extensions.class. so even I do that, the The 
>>>> extensions.kt are still in the source files. Do you know any one have this 
>>>> similar issue? or should go ask Kotlin or Gradle?
>>>>
>>>
>>> As was said before: "Extensions.kt" - is a name *in one of analyzed 
>>> class files* produced by Kotlin compiler.
>>>
>>> Similarly to the names recorded by Java compiler:
>>> e.g. in case of "class Foo { public static void main(String[] args) { } 
>>> }" as "Example.java" in directory "src" execution of
>>>
>>> javac src/Example.java
>>> javap -v Foo.class | grep "Compiled from"
>>>
>>> shows the name recorded by compiler as
>>>
>>>   Compiled from "Example.java"
>>>
>>> Notice that this source file name is completely different from class 
>>> file name.
>>> Exactly this name is extracted by JaCoCo from class files - for the same 
>>> above example execution of
>>>
>>> java -javaagent:jacoco-0.8.1/lib/jacocoagent.jar Foo
>>> java -jar jacoco-0.8.1/lib/jacococli.jar report jacoco.exec --classfiles 
>>> Foo.class --xml report.xml
>>>
>>> produces XML report that contains "Example.java"
>>> Note that commands after "javac" doesn't even know about existence of 
>>> "src" directory and file "Example.java" in it - you can even remove it 
>>> right after execution of "javac" and result of subsequent commands will 
>>> remain the same.
>>>
>>> And there is no other ways it can appear in XML. So check more carefully 
>>> class files in directories, subdirectories and archives (JARs, etc) that 
>>> you analyze.
>>>
>>> Or provide us full reproducer instead of snippets of build.gradle.
>>>
>>>
>>>  
>>>
>>>>
>>>> Thanks,
>>>> Michelle
>>>>
>>>> On Tuesday, 31 July 2018 05:17:00 UTC-5, Evgeny Mandrikov wrote:
>>>>>
>>>>> I hope you realize that you are not doing proper removal of nodes from 
>>>>> XML and  actually damaging XML report - for example
>>>>>
>>>>> <sourcefile name="Foo.java">
>>>>> bar
>>>>> </sourcefile><sourcefile name="ServerResponseExtensions.kt">
>>>>> baz
>>>>> </sourcefile>
>>>>>
>>>>> after your hack will become
>>>>>
>>>>> <sourcefile name="Foo.java">
>>>>> bar
>>>>> baz
>>>>> </sourcefile>
>>>>>
>>>>> what has completely different semantic.
>>>>>
>>>>> On Monday, July 30, 2018 at 10:09:20 PM UTC+2, Michelle wrote:
>>>>>>
>>>>>> I added up with the jacocoFix like this:
>>>>>>
>>>>>> task jacocoFix(type: Copy) {
>>>>>>     from 'build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml' 
>>>>>> into './'
>>>>>>     rename { fileName -> "jacoco.xml"}
>>>>>>     filter { line -> line.replaceAll("</sourcefile><sourcefile 
>>>>>> name=\"ServerResponseExtensions.kt\">", "")
>>>>>>     }
>>>>>>     filter { line -> line.replaceAll("</sourcefile><sourcefile 
>>>>>> name=\"ServerRequestExtensions.kt\">", "")
>>>>>>     }
>>>>>>     filter { line -> line.replaceAll("</sourcefile><sourcefile 
>>>>>> name=\"Extensions.kt\">", "")
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>>
>>>>>> filter out them for CodeClimate coverage reports
>>>>>>
>>>>>> On Sunday, 29 July 2018 17:04:32 UTC-5, Michelle wrote:
>>>>>>>
>>>>>>> Hey Evgeny and Marc,
>>>>>>>
>>>>>>> I understood the "ServerRespsonseExtensions.kt" is a dependency. I 
>>>>>>> tried to exclude them, but did not succeed. Could you please let me 
>>>>>>> know if 
>>>>>>> I can exclude the "Extensions.kt" in the sourceDirectories. If so, 
>>>>>>> could 
>>>>>>> you please let me know how to do it correctly.
>>>>>>>
>>>>>>> Here is what I did, but I do not think it is correct:
>>>>>>>
>>>>>>> def excludes = [
>>>>>>>       '**/**ActivityWebHandlers.kt',
>>>>>>>         '**/**ServerRequestExtensions.kt',
>>>>>>>         '**/**ServerResponseExtensions.kt',
>>>>>>>         ]
>>>>>>> def sourceDir = sourceSets.getByName("main").allSource.srcDirs.find{ 
>>>>>>> dir -> dir.toString().contains("kotlin")}
>>>>>>>
>>>>>>> def sourceTree = fileTree(
>>>>>>>
>>>>>>>         dir: sourceDir,
>>>>>>>         excludes: excludes
>>>>>>> )
>>>>>>> sourceDirectories = files([sourceTree])
>>>>>>>
>>>>>>>
>>>>>>> Thank you very much,
>>>>>>> Michelle
>>>>>>>
>>>>>>>
>>>>>>> On Monday, 23 July 2018 06:28:15 UTC-5, Evgeny Mandrikov wrote:
>>>>>>>>
>>>>>>>> In addition to what Marc said: "ServerResponseExtensions.kt" - is a 
>>>>>>>> name in one of analyzed class files produced by Kotlin compiler. In 
>>>>>>>> particular maybe one of analysed class directories contains JAR files 
>>>>>>>> of 
>>>>>>>> your dependencies.
>>>>>>>>
>>>>>>>> On Monday, July 23, 2018 at 12:46:00 PM UTC+2, Marc R. Hoffmann 
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Michelle,
>>>>>>>>>
>>>>>>>>> the JaCoCo XML report uses the “package” tag aggregate a Java 
>>>>>>>>> package. Therefore the name is the name of the Java package.
>>>>>>>>>
>>>>>>>>> Packages can be nested into groups with arbitrary names. Check the 
>>>>>>>>> parent “group” element to see whether it contains the correct 
>>>>>>>>> information.
>>>>>>>>>
>>>>>>>>> Other wise please contact the grade project. We’re not doing the 
>>>>>>>>> JaCoC integration for grade ourself.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>> -marc
>>>>>>>>>
>>>>>>>>> On 23. Jul 2018, at 01:23, Michelle <[email protected]> wrote:
>>>>>>>>>
>>>>>>>>> Hello,
>>>>>>>>>
>>>>>>>>> Jacoco html reports works for me, but for xml reports, the package 
>>>>>>>>> name does not include the sub project name. Could you please let me 
>>>>>>>>> know 
>>>>>>>>> how to add that. my gradle.build file is:
>>>>>>>>>
>>>>>>>>> allprojects {
>>>>>>>>>     apply plugin: 'jacoco'
>>>>>>>>>
>>>>>>>>>     repositories {
>>>>>>>>>         jcenter()
>>>>>>>>>     }
>>>>>>>>>
>>>>>>>>>     jacoco {
>>>>>>>>>         toolVersion = '0.8.1'
>>>>>>>>>     }
>>>>>>>>> }
>>>>>>>>> subprojects {
>>>>>>>>>     apply plugin: 'kotlin'
>>>>>>>>>     apply plugin: "kotlin-spring"
>>>>>>>>>     apply plugin: 'io.spring.dependency-management'
>>>>>>>>>
>>>>>>>>>     repositories {
>>>>>>>>>         mavenCentral()
>>>>>>>>>         maven { url 'https://repo.spring.io/libs-snapshot' }
>>>>>>>>>         maven { url 'https://repo.spring.io/libs-milestone' }
>>>>>>>>>     }
>>>>>>>>>
>>>>>>>>>     dependencyManagement {
>>>>>>>>>         imports {
>>>>>>>>>             mavenBom 
>>>>>>>>> "org.springframework.boot:spring-boot-dependencies:${spring_boot_version}"
>>>>>>>>>             mavenBom 
>>>>>>>>> 'org.springframework.cloud:spring-cloud-dependencies:Finchley.M9'
>>>>>>>>>         }
>>>>>>>>>     }
>>>>>>>>>
>>>>>>>>>     dependencies {
>>>>>>>>>         compile "com.github.wnameless:json-flattener:0.5.0"
>>>>>>>>>         compile "com.google.guava:guava:$guava_version"
>>>>>>>>>         compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
>>>>>>>>>         compile 
>>>>>>>>> "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
>>>>>>>>>
>>>>>>>>>         testCompile "junit:junit:$junit_version"
>>>>>>>>>         testCompile "org.mockito:mockito-core:$mockito_version"
>>>>>>>>>     }
>>>>>>>>>
>>>>>>>>>     compileKotlin {
>>>>>>>>>         kotlinOptions.jvmTarget = "1.8"
>>>>>>>>>     }
>>>>>>>>>     compileTestKotlin {
>>>>>>>>>         kotlinOptions.jvmTarget = "1.8"
>>>>>>>>>     }
>>>>>>>>>
>>>>>>>>>     jacocoTestReport {
>>>>>>>>>         sourceDirectories = 
>>>>>>>>> files(sourceSets.getByName("main").allSource.srcDirs.findAll{ dir -> 
>>>>>>>>> dir.toString().contains("kotlin")})
>>>>>>>>>         classDirectories =  
>>>>>>>>> files(sourceSets.getByName("main").output.findAll{ dir -> 
>>>>>>>>> dir.toString().contains("kotlin") })
>>>>>>>>>         println("**********source files******")
>>>>>>>>>         println(sourceDirectories.files.toListString())
>>>>>>>>>         println(classDirectories.files.toListString())
>>>>>>>>>         println("********class files end")
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>         reports {
>>>>>>>>>             html.enabled = true
>>>>>>>>>             xml.enabled = true
>>>>>>>>>             csv.enabled = false
>>>>>>>>>         }
>>>>>>>>>     }
>>>>>>>>> }
>>>>>>>>> //noinspection GroovyAssignabilityCheck
>>>>>>>>> task jacoco(type:JacocoReport) {
>>>>>>>>>     dependsOn subprojects.collect { it.tasks.getByPath('check')}
>>>>>>>>>     sourceDirectories = files()
>>>>>>>>>     classDirectories = files()
>>>>>>>>>     executionData = files()
>>>>>>>>>
>>>>>>>>>     getSubprojects()
>>>>>>>>>         .findAll{ subproject ->
>>>>>>>>>             subproject.name == "service-activity" }
>>>>>>>>>         .forEach{
>>>>>>>>>         subproject ->
>>>>>>>>>             def coverageFileLocation = 
>>>>>>>>> "${subproject.buildDir}/jacoco/test.exec"
>>>>>>>>>             if (new File(coverageFileLocation).exists()) {
>>>>>>>>>                 executionData += 
>>>>>>>>> subproject.tasks.findByName("jacocoTestReport").property("executionData")
>>>>>>>>>                 sourceDirectories += 
>>>>>>>>> subproject.tasks.findByName("jacocoTestReport").property("sourceDirectories")
>>>>>>>>>                 classDirectories += 
>>>>>>>>> subproject.tasks.findByName("jacocoTestReport").property("classDirectories")
>>>>>>>>>             }
>>>>>>>>>         }
>>>>>>>>>     reports {
>>>>>>>>>         xml.enabled = true
>>>>>>>>>         csv.enabled = false
>>>>>>>>>         html.enabled = true
>>>>>>>>>
>>>>>>>>>     }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> task jacocoFix(type: Copy) {
>>>>>>>>>     from 'build/reports/jacoco/jacoco/jacoco.xml' into './'
>>>>>>>>>     filter {
>>>>>>>>>         line -> line.replaceAll("<package name=\"com/cd/activity\">", 
>>>>>>>>> "<package name=\"service-activity/src/main/kotlin/com/cd/activity\">")
>>>>>>>>>     }
>>>>>>>>>     filter { line -> line.replaceAll("<sourcefile 
>>>>>>>>> name=\"ServerResponseExtensions.kt\">", "<sourcefile 
>>>>>>>>> name=\"ActivityWebHandlers.kt\">")
>>>>>>>>>     }
>>>>>>>>>     filter { line -> line.replaceAll("<sourcefile 
>>>>>>>>> name=\"ServerRequestExtensions.kt\">", "<sourcefile 
>>>>>>>>> name=\"ActivityWebHandlers.kt\">")
>>>>>>>>>     }
>>>>>>>>>     filter { line -> line.replaceAll("<sourcefile 
>>>>>>>>> name=\"Extensions.kt\">", "<sourcefile 
>>>>>>>>> name=\"ActivityWebHandlers.kt\">")
>>>>>>>>>     }
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> task wrapper(type: Wrapper) {
>>>>>>>>>     gradleVersion = '4.5.1' //version required
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I use jacocofix to fix the package name, but I have a lot 
>>>>>>>>> subprojects, I can not do this. also I do not know why the 
>>>>>>>>> Extenstions kt files are there.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> this is gradle.build config for multi kotlin projects.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Thank you for your response in advance.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Michelle
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -- 
>>>>>>>>> You received this message because you are subscribed to the Google 
>>>>>>>>> Groups "JaCoCo and EclEmma Users" group.
>>>>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>>>>> send an email to [email protected].
>>>>>>>>> To view this discussion on the web visit 
>>>>>>>>> https://groups.google.com/d/msgid/jacoco/4ff3c538-f25a-47b2-8646-c9061bd614cc%40googlegroups.com
>>>>>>>>>  
>>>>>>>>> <https://groups.google.com/d/msgid/jacoco/4ff3c538-f25a-47b2-8646-c9061bd614cc%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>>> .
>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/dc18ecfa-6e80-44c8-bdd6-65d60ba67e28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git i/build.gradle w/build.gradle
index 3a4022f..c031e52 100644
--- i/build.gradle
+++ w/build.gradle
@@ -81,7 +81,12 @@ subprojects {
 
     jacocoTestReport {
         sourceDirectories = files(sourceSets.getByName("main").allSource.srcDirs)
-        classDirectories =  files(sourceSets.getByName("main").output)
+
+        afterEvaluate {
+          classDirectories = files(sourceSets.getByName("main").output.files.collect {
+            fileTree(dir: it, exclude: '**/*WebHandlers*')
+          })
+        }
 
         reports {
             html.enabled = true
@@ -90,6 +95,7 @@ subprojects {
         }
     }
 }
+
 task jacoco(type: JacocoReport) {
     sourceDirectories = files()
     classDirectories = files()
@@ -104,7 +110,10 @@ task jacoco(type: JacocoReport) {
             if (new File(coverageFileLocation).exists()) {
                 executionData += subproject.tasks.findByName("jacocoTestReport").property("executionData")
                 sourceDirectories += subproject.tasks.findByName("jacocoTestReport").property("sourceDirectories")
-                classDirectories += subproject.tasks.findByName("jacocoTestReport").property("classDirectories")
+
+                classDirectories += files(subproject.sourceSets.getByName("main").output.files.collect {
+                  fileTree(dir: it, exclude: '**/*WebHandlers*')
+                })
             }
         }
 

Reply via email to