Skip to content

Commit acad41a

Browse files
committed
internal magic
1 parent 29f5b54 commit acad41a

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

buildSrc/src/main/kotlin/toolkit-jacoco-report.gradle.kts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import org.gradle.api.plugins.jvm.internal.JvmPluginServices
2+
import org.gradle.kotlin.dsl.support.serviceOf
3+
14
// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
25
// SPDX-License-Identifier: Apache-2.0
36

@@ -21,26 +24,27 @@ val aggregateCoverage by configurations.creating {
2124
isCanBeConsumed = false
2225
}
2326

24-
// Resolvable configuration to resolve the classes of all dependencies
25-
val classPath by configurations.creating {
27+
val aggregateCoverageReportResults by configurations.creating {
2628
isVisible = false
27-
isCanBeResolved = true
28-
isCanBeConsumed = false
2929
extendsFrom(aggregateCoverage)
30+
}
31+
// magic to resolve all project dependencies transitively
32+
serviceOf<JvmPluginServices>().configureAsRuntimeClasspath(aggregateCoverageReportResults)
33+
34+
35+
// view to resolve the classes of all dependencies
36+
val classPath = aggregateCoverageReportResults.incoming.artifactView {
37+
componentFilter { it is ProjectComponentIdentifier }
3038
attributes {
31-
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
32-
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
3339
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.CLASSES))
34-
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
3540
}
3641
}
3742

38-
// A resolvable configuration to collect source code
39-
val sourcesPath by configurations.creating {
40-
isVisible = false
41-
isCanBeResolved = true
42-
isCanBeConsumed = false
43-
extendsFrom(aggregateCoverage)
43+
44+
// view to collect source code
45+
val sourcesPath = aggregateCoverageReportResults.incoming.artifactView {
46+
withVariantReselection()
47+
componentFilter { it is ProjectComponentIdentifier }
4448
attributes {
4549
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.VERIFICATION))
4650
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
@@ -49,29 +53,27 @@ val sourcesPath by configurations.creating {
4953
}
5054

5155
// A resolvable configuration to collect JaCoCo coverage data
52-
val coverageDataPath by configurations.creating {
53-
isVisible = false
54-
isCanBeResolved = true
55-
isCanBeConsumed = false
56-
extendsFrom(aggregateCoverage)
56+
val coverageDataPath = aggregateCoverageReportResults.incoming.artifactView {
57+
withVariantReselection()
58+
componentFilter { it is ProjectComponentIdentifier }
5759
attributes {
58-
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
59-
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data"))
60-
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
60+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.VERIFICATION))
61+
attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.JACOCO_RESULTS))
62+
attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.BINARY_DATA_TYPE)
6163
}
6264
}
6365

6466
// Register a code coverage report task to generate the aggregated report
6567
tasks.register<JacocoReport>("coverageReport") {
6668
additionalClassDirs(
67-
classPath.filter { it.isDirectory }.asFileTree.matching {
69+
classPath.files.filter { it.isDirectory }.asFileTree.matching {
6870
include("**/software/aws/toolkits/**")
6971
exclude("**/software/aws/toolkits/telemetry/**")
7072
}
7173
)
7274

73-
additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files)
74-
executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() && it.extension == "exec" })
75+
additionalSourceDirs(sourcesPath.files)
76+
executionData(coverageDataPath.files)
7577

7678
reports {
7779
html.required.set(true)

buildSrc/src/main/kotlin/toolkit-testing.gradle.kts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ tasks.jacocoTestReport.configure {
102102
enabled = false
103103
}
104104

105-
// Share the coverage data to be aggregated for the whole product
106-
// this can be removed once we're using jvm-test-suites properly
107-
configurations.register("coverageDataElements") {
108-
isVisible = false
109-
isCanBeResolved = false
110-
isCanBeConsumed = true
111-
extendsFrom(configurations.implementation.get())
112-
attributes {
113-
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
114-
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
115-
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data"))
116-
}
117-
tasks.withType<Test>().configureEach {
118-
outgoing.artifact(extensions.getByType<JacocoTaskExtension>().destinationFile!!)
119-
}
120-
}
105+
//// Share the coverage data to be aggregated for the whole product
106+
//// this can be removed once we're using jvm-test-suites properly
107+
//configurations.register("coverageDataElements") {
108+
// isVisible = false
109+
// isCanBeResolved = false
110+
// isCanBeConsumed = true
111+
// extendsFrom(configurations.implementation.get())
112+
// attributes {
113+
// attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
114+
// attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
115+
// attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data"))
116+
// }
117+
// tasks.withType<Test>().configureEach {
118+
// outgoing.artifact(extensions.getByType<JacocoTaskExtension>().destinationFile!!)
119+
// }
120+
//}

buildspec/linuxTests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ phases:
3535
fi
3636
3737
- chmod +x gradlew
38-
- su codebuild-user -c "./gradlew -PideProfileName=$ALTERNATIVE_IDE_PROFILE_NAME check testCodeCoverageReport --info --console plain --continue"
38+
- su codebuild-user -c "./gradlew -PideProfileName=$ALTERNATIVE_IDE_PROFILE_NAME check coverageReport --info --console plain --continue"
3939
- su codebuild-user -c "./gradlew -PideProfileName=$ALTERNATIVE_IDE_PROFILE_NAME buildPlugin"
4040
- VCS_COMMIT_ID="${CODEBUILD_RESOLVED_SOURCE_VERSION}"
4141
- CI_BUILD_URL=$(echo $CODEBUILD_BUILD_URL | sed 's/#/%23/g') # Encode `#` in the URL because otherwise the url is clipped in the Codecov.io site

0 commit comments

Comments
 (0)