From 1b5803ff64a17cb6c70f817755db2fb436aa4d6c Mon Sep 17 00:00:00 2001 From: yauheni_patotski Date: Wed, 23 Oct 2024 16:17:53 +0300 Subject: [PATCH] 1. Code overage for java projects 2. Agregated coverage report --- build.gradle | 27 ++++++++ datahub-graphql-core/build.gradle | 21 +++++++ gradle/coverage/coverage.gradle | 61 +++++++++++++++++++ .../java/openlineage-converter/build.gradle | 4 +- metadata-models/build.gradle | 22 +++++++ .../restli-servlet-impl/build.gradle | 2 +- settings.gradle | 6 +- 7 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 gradle/coverage/coverage.gradle diff --git a/build.gradle b/build.gradle index 67968ce3ee2905..75daff11890e26 100644 --- a/build.gradle +++ b/build.gradle @@ -79,11 +79,13 @@ plugins { id 'com.palantir.docker' version '0.35.0' apply false id 'com.avast.gradle.docker-compose' version '0.17.6' id "com.diffplug.spotless" version "6.23.3" + id 'jacoco-report-aggregation' // https://blog.ltgt.net/javax-jakarta-mess-and-gradle-solution/ // TODO id "org.gradlex.java-ecosystem-capabilities" version "1.0" } apply from: "gradle/docker/docker.gradle" +apply from: "gradle/coverage/coverage.gradle" project.ext.spec = [ 'product' : [ @@ -281,6 +283,7 @@ project.ext.externalDependency = [ allprojects { apply plugin: 'idea' apply plugin: 'eclipse' + apply plugin: 'jacoco' // apply plugin: 'org.gradlex.java-ecosystem-capabilities' tasks.withType(Test).configureEach { task -> if (task.project.name != "metadata-io") { @@ -291,6 +294,7 @@ allprojects { .any { it.getName().contains("testng") }) { useTestNG() } + finalizedBy jacocoTestReport } } @@ -372,6 +376,7 @@ subprojects { apply plugin: 'maven-publish' apply plugin: 'com.gorylenko.gradle-git-properties' apply plugin: 'com.diffplug.spotless' + apply plugin: 'jacoco' gitProperties { keys = ['git.commit.id','git.commit.id.describe','git.commit.time'] @@ -402,6 +407,15 @@ subprojects { } } + jacocoTestReport { + reports { + xml.required = true + csv.required = true + html.outputLocation = layout.buildDirectory.dir('jacocoHtml') + } + dependsOn test // tests are required to run before generating the report + } + spotless { java { googleJavaFormat() @@ -486,3 +500,16 @@ subprojects { } } } + +reporting { + reports { + testCodeCoverageReport(JacocoCoverageReport) { + testType = TestSuiteType.UNIT_TEST + + } + } +} + +tasks.named('check') { + dependsOn tasks.named('testCodeCoverageReport', JacocoReport) +} \ No newline at end of file diff --git a/datahub-graphql-core/build.gradle b/datahub-graphql-core/build.gradle index 49a7fa7fbfbc2f..271058bfc37d92 100644 --- a/datahub-graphql-core/build.gradle +++ b/datahub-graphql-core/build.gradle @@ -55,3 +55,24 @@ tasks.withType(Checkstyle) { compileJava.dependsOn 'graphqlCodegen' sourceSets.main.java.srcDir "$projectDir/src/mainGeneratedGraphQL/java" + +test{ + useTestNG() + finalizedBy jacocoTestReport +} + +def jacocoExclusions = [ + '**/graphql/generated/**' +]; + +jacocoTestReport { + + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it, + exclude: jacocoExclusions + ) + })) + } + +} diff --git a/gradle/coverage/coverage.gradle b/gradle/coverage/coverage.gradle new file mode 100644 index 00000000000000..02cb4d3f92abdb --- /dev/null +++ b/gradle/coverage/coverage.gradle @@ -0,0 +1,61 @@ +dependencies { + jacocoAggregation project(':datahub-frontend') + jacocoAggregation project(':datahub-graphql-core') + jacocoAggregation project(':datahub-upgrade') + jacocoAggregation project(':entity-registry') + jacocoAggregation project(':ingestion-scheduler') + jacocoAggregation project(':li-utils') + jacocoAggregation project(':metadata-auth') + jacocoAggregation project(':metadata-dao-impl') + jacocoAggregation project(':metadata-events') + jacocoAggregation project(':metadata-integration') + jacocoAggregation project(':metadata-io') + jacocoAggregation project(':metadata-jobs') + jacocoAggregation project(':metadata-models') + jacocoAggregation project(':metadata-models-custom') + jacocoAggregation project(':metadata-models-validator') + jacocoAggregation project(':metadata-operation-context') + jacocoAggregation project(':metadata-service') + jacocoAggregation project(':metadata-utils') + jacocoAggregation project(':mock-entity-registry') + jacocoAggregation project(':metadata-auth:auth-api') + jacocoAggregation project(':metadata-dao-impl:kafka-producer') + jacocoAggregation project(':metadata-events:mxe-avro') + jacocoAggregation project(':metadata-events:mxe-registration') + jacocoAggregation project(':metadata-events:mxe-schemas') + jacocoAggregation project(':metadata-events:mxe-utils-avro') + jacocoAggregation project(':metadata-integration:java') + jacocoAggregation project(':metadata-io:metadata-io-api') + jacocoAggregation project(':metadata-jobs:common') + jacocoAggregation project(':metadata-jobs:mce-consumer') + jacocoAggregation project(':metadata-jobs:mce-consumer-job') + jacocoAggregation project(':metadata-jobs:pe-consumer') + jacocoAggregation project(':metadata-service:auth-config') + jacocoAggregation project(':metadata-service:auth-filter') + jacocoAggregation project(':metadata-service:auth-impl') + jacocoAggregation project(':metadata-service:auth-servlet-impl') + jacocoAggregation project(':metadata-service:configuration') + jacocoAggregation project(':metadata-service:factories') + jacocoAggregation project(':metadata-service:graphql-servlet-impl') + jacocoAggregation project(':metadata-service:openapi-analytics-servlet') + jacocoAggregation project(':metadata-service:openapi-entity-servlet') + jacocoAggregation project(':metadata-service:openapi-servlet') + jacocoAggregation project(':metadata-service:plugin') + jacocoAggregation project(':metadata-service:restli-api') + jacocoAggregation project(':metadata-service:restli-client') + jacocoAggregation project(':metadata-service:restli-client-api') + jacocoAggregation project(':metadata-service:restli-servlet-impl') + jacocoAggregation project(':metadata-service:schema-registry-api') + jacocoAggregation project(':metadata-service:schema-registry-servlet') + jacocoAggregation project(':metadata-service:services') + jacocoAggregation project(':metadata-service:servlet') + jacocoAggregation project(':metadata-integration:java:acryl-spark-lineage') + jacocoAggregation project(':metadata-integration:java:custom-plugin-lib') + jacocoAggregation project(':metadata-integration:java:datahub-client') + jacocoAggregation project(':metadata-integration:java:datahub-event') + jacocoAggregation project(':metadata-integration:java:datahub-protobuf') + jacocoAggregation project(':metadata-integration:java:examples') + jacocoAggregation project(':metadata-integration:java:openlineage-converter') + jacocoAggregation project(':metadata-service:openapi-entity-servlet:generators') + jacocoAggregation project(':metadata-service:openapi-servlet:models') +} \ No newline at end of file diff --git a/metadata-integration/java/openlineage-converter/build.gradle b/metadata-integration/java/openlineage-converter/build.gradle index 2e04881ab5ccda..6a2490aa536a20 100644 --- a/metadata-integration/java/openlineage-converter/build.gradle +++ b/metadata-integration/java/openlineage-converter/build.gradle @@ -33,12 +33,12 @@ jacocoTestReport { test { forkEvery = 1 - useJUnit() + useTestNG() finalizedBy jacocoTestReport } test { - useJUnit() + useTestNG() finalizedBy jacocoTestReport } shadowJar { diff --git a/metadata-models/build.gradle b/metadata-models/build.gradle index 179e1eac177ac8..04a06db4136b87 100644 --- a/metadata-models/build.gradle +++ b/metadata-models/build.gradle @@ -74,3 +74,25 @@ task cleanExtraDirs { delete "$projectDir/src/generatedJsonSchema" } clean.finalizedBy(cleanExtraDirs) + + +test{ + useTestNG() + finalizedBy jacocoTestReport +} + +def jacocoExclusions = [ + '**/openapi/generated/**' +]; + +jacocoTestReport { + + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it, + exclude: jacocoExclusions + ) + })) + } + +} \ No newline at end of file diff --git a/metadata-service/restli-servlet-impl/build.gradle b/metadata-service/restli-servlet-impl/build.gradle index 6b68abfe7fb15c..4a47c571bfb1de 100644 --- a/metadata-service/restli-servlet-impl/build.gradle +++ b/metadata-service/restli-servlet-impl/build.gradle @@ -79,7 +79,7 @@ dependencies { task integrationTest(type: Test) { description = 'Runs integration tests.' group = 'verification' - useJUnitPlatform() + useTestNG() testClassesDirs = sourceSets.integTest.output.classesDirs classpath = sourceSets.integTest.runtimeClasspath diff --git a/settings.gradle b/settings.gradle index fa1fdb9f1a67ce..04d122c63d3a9e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -39,8 +39,8 @@ include ':docker:datahub-ingestion' include ':docker:datahub-ingestion-base' include 'metadata-models' include 'metadata-models-validator' -include 'metadata-testing:metadata-models-test-utils' -include 'metadata-testing:metadata-test-utils' +//include 'metadata-testing:metadata-models-test-utils' +//include 'metadata-testing:metadata-test-utils' include 'entity-registry' include 'metadata-io' include 'metadata-io:metadata-io-api' @@ -48,7 +48,7 @@ include 'datahub-upgrade' include 'metadata-utils' include 'li-utils' include 'test-models' -include 'metadata-perf' +//include 'metadata-perf' include 'docs-website' include 'metadata-models-custom' include 'entity-registry:custom-test-model'