diff --git a/buildSrc/src/main/kotlin/toolkit-jacoco-report.gradle.kts b/buildSrc/src/main/kotlin/toolkit-jacoco-report.gradle.kts index 271dd95261a..44a08e4fd75 100644 --- a/buildSrc/src/main/kotlin/toolkit-jacoco-report.gradle.kts +++ b/buildSrc/src/main/kotlin/toolkit-jacoco-report.gradle.kts @@ -1,3 +1,6 @@ +import org.gradle.api.plugins.jvm.internal.JvmPluginServices +import org.gradle.kotlin.dsl.support.serviceOf + // Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 @@ -21,26 +24,27 @@ val aggregateCoverage by configurations.creating { isCanBeConsumed = false } -// Resolvable configuration to resolve the classes of all dependencies -val classPath by configurations.creating { +val aggregateCoverageReportResults by configurations.creating { isVisible = false - isCanBeResolved = true - isCanBeConsumed = false extendsFrom(aggregateCoverage) +} +// magic to resolve all project dependencies transitively +serviceOf().configureAsRuntimeClasspath(aggregateCoverageReportResults) + + +// view to resolve the classes of all dependencies +val classPath = aggregateCoverageReportResults.incoming.artifactView { + componentFilter { it is ProjectComponentIdentifier } attributes { - attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) - attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY)) attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.CLASSES)) - attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) } } -// A resolvable configuration to collect source code -val sourcesPath by configurations.creating { - isVisible = false - isCanBeResolved = true - isCanBeConsumed = false - extendsFrom(aggregateCoverage) + +// view to collect source code +val sourcesPath = aggregateCoverageReportResults.incoming.artifactView { + withVariantReselection() + componentFilter { it is ProjectComponentIdentifier } attributes { attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.VERIFICATION)) attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) @@ -49,29 +53,27 @@ val sourcesPath by configurations.creating { } // A resolvable configuration to collect JaCoCo coverage data -val coverageDataPath by configurations.creating { - isVisible = false - isCanBeResolved = true - isCanBeConsumed = false - extendsFrom(aggregateCoverage) +val coverageDataPath = aggregateCoverageReportResults.incoming.artifactView { + withVariantReselection() + componentFilter { it is ProjectComponentIdentifier } attributes { - attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) - attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) - attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.VERIFICATION)) + attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.JACOCO_RESULTS)) + attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.BINARY_DATA_TYPE) } } // Register a code coverage report task to generate the aggregated report tasks.register("coverageReport") { additionalClassDirs( - classPath.filter { it.isDirectory }.asFileTree.matching { + classPath.files.filter { it.isDirectory }.asFileTree.matching { include("**/software/aws/toolkits/**") exclude("**/software/aws/toolkits/telemetry/**") } ) - additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files) - executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() && it.extension == "exec" }) + additionalSourceDirs(sourcesPath.files) + executionData(coverageDataPath.files) reports { html.required.set(true) diff --git a/buildSrc/src/main/kotlin/toolkit-testing.gradle.kts b/buildSrc/src/main/kotlin/toolkit-testing.gradle.kts index ca37a88d9c1..00070ec7a84 100644 --- a/buildSrc/src/main/kotlin/toolkit-testing.gradle.kts +++ b/buildSrc/src/main/kotlin/toolkit-testing.gradle.kts @@ -102,19 +102,19 @@ tasks.jacocoTestReport.configure { enabled = false } -// Share the coverage data to be aggregated for the whole product -// this can be removed once we're using jvm-test-suites properly -configurations.register("coverageDataElements") { - isVisible = false - isCanBeResolved = false - isCanBeConsumed = true - extendsFrom(configurations.implementation.get()) - attributes { - attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) - attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) - attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) - } - tasks.withType().configureEach { - outgoing.artifact(extensions.getByType().destinationFile!!) - } -} +//// Share the coverage data to be aggregated for the whole product +//// this can be removed once we're using jvm-test-suites properly +//configurations.register("coverageDataElements") { +// isVisible = false +// isCanBeResolved = false +// isCanBeConsumed = true +// extendsFrom(configurations.implementation.get()) +// attributes { +// attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) +// attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) +// attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) +// } +// tasks.withType().configureEach { +// outgoing.artifact(extensions.getByType().destinationFile!!) +// } +//} diff --git a/buildspec/linuxTests.yml b/buildspec/linuxTests.yml index 8a6ce32d178..066b3ebf89b 100644 --- a/buildspec/linuxTests.yml +++ b/buildspec/linuxTests.yml @@ -42,7 +42,7 @@ phases: - CI_BUILD_ID="${CODEBUILD_BUILD_ID}" - test -n "$CODE_COV_TOKEN" && curl -Os https://uploader.codecov.io/latest/linux/codecov && chmod +x codecov || true # this sometimes times out but we don't want to fail the build - test -n "$CODE_COV_TOKEN" && test -n "$CODEBUILD_BUILD_SUCCEEDING" && ./codecov -t $CODE_COV_TOKEN -F unittest || true - - test -n "$CODE_COV_TOKEN" && test -n "$CODEBUILD_BUILD_SUCCEEDING" && ./codecov -t $CODE_COV_TOKEN -F codewhisperer || true +# - test -n "$CODE_COV_TOKEN" && test -n "$CODEBUILD_BUILD_SUCCEEDING" && ./codecov -t $CODE_COV_TOKEN -F codewhisperer || true post_build: commands: @@ -52,6 +52,7 @@ phases: - mkdir -p $BUILD_ARTIFACTS - rsync -rmq --include='*/' --include '**/build/idea-sandbox/**/log*/**' --exclude='*' . $TEST_ARTIFACTS/ || true - rsync -rmq --include='*/' --include '**/build/reports/**' --exclude='*' . $TEST_ARTIFACTS/ || true + - rsync -rmq --include='*/' --include '**/build/**/*.exec' --exclude='*' . $TEST_ARTIFACTS/ || true - rsync -rmq --include='*/' --include '**/test-results/**/*.xml' --exclude='*' . $TEST_ARTIFACTS/test-reports || true - find plugins -path '*/build/distributions/*.zip' -exec cp {} $BUILD_ARTIFACTS/ \; || touch $BUILD_ARTIFACTS/build_failed diff --git a/coverage-report/build.gradle.kts b/coverage-report/build.gradle.kts new file mode 100644 index 00000000000..45d6a576305 --- /dev/null +++ b/coverage-report/build.gradle.kts @@ -0,0 +1,38 @@ +import kotlin.io.extension + +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +plugins { + base + id("jacoco-report-aggregation") +} + +dependencies { + jacocoAggregation(project(":plugin-toolkit:intellij-standalone")) + jacocoAggregation(project(":plugin-core")) + jacocoAggregation(project(":plugin-amazonq")) + + project.findProject(":plugin-toolkit:jetbrains-gateway")?.let { + jacocoAggregation(it) + } + + jacocoAggregation(project(":ui-tests")) +} + +reporting { + reports { + val testCodeCoverageReport by creating(JacocoCoverageReport::class) { + testType = TestSuiteType.UNIT_TEST + // https://github.com/gradle/gradle/issues/20026 + reportTask.configure { + classDirectories.setFrom(classDirectories.map { + fileTree(it).matching { + include("**/software/aws/toolkits/**") + exclude("**/software/aws/toolkits/telemetry/**") + } + }) + } + } + } +}