Class ScanContractsTask
java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
com.arc_e_tect.gradle.doppelganger.ScanContractsTask
- All Implemented Interfaces:
Comparable<org.gradle.api.Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.TaskInternal,org.gradle.api.Named,org.gradle.api.plugins.ExtensionAware,org.gradle.api.Task,org.gradle.util.Configurable<org.gradle.api.Task>
@DisableCachingByDefault(because="Report depends on source, test, contract, and OpenAPI document content and is cheap to regenerate")
public abstract class ScanContractsTask
extends org.gradle.api.DefaultTask
Gradle task that, for every endpoint both declared in the configured OpenAPI documentation and
implemented by a
@RestController method, reports how many response codes its operation
declares and how many contract tests exist for it - and, when
DoppelgangerApiDetectorExtension.getIncludeResponseCoverage() is enabled, how many of
those tests cover each declared response code.
Unlike DetectDoppelgangerApisTask, this task never fails the build on its own
initiative - it is purely a reporting task, answering "how well is this API covered", not "is
this API compliant".
Registered automatically by DoppelgangerApiDetectorPlugin under the name
scanContracts.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gradle.api.Named
org.gradle.api.Named.Namer -
Field Summary
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate()Task action: scans the same candidate endpointsDetectDoppelgangerApisTaskdoes, but reports response-code and contract-test coverage rather than a pass/fail verdict.abstract org.gradle.api.file.DirectoryPropertyDirectory searched for Spring Cloud Contract DSL files whengetUseSpringCloudContract()istrue.abstract org.gradle.api.file.ConfigurableFileCollectionDirectories to search recursively for@RestControllerclasses.abstract org.gradle.api.file.ConfigurableFileCollectionExternal exclusion rule files - seeDoppelgangerApiDetectorExtension.getExcludeFiles().abstract org.gradle.api.provider.ListProperty<String> Exclusion rule strings - seeDoppelgangerApiDetectorExtension.getExcludePaths().abstract org.gradle.api.provider.ListProperty<String> Bundled well-known exclusion set names - seeDoppelgangerApiDetectorExtension.getExcludeWellKnown().abstract org.gradle.api.provider.Property<Boolean> Whether to additionally compute, for every declared response code, how many contract tests cover it.abstract org.gradle.api.file.DirectoryPropertyDirectory where OpenAPI descriptions are stored.abstract org.gradle.api.provider.ListProperty<String> Helper-method conventions used to resolve indirectly-referenced request paths in contract tests - seeDoppelgangerApiDetectorExtension.getPathResolverHelperMethods().abstract org.gradle.api.file.ConfigurableFileCollectionProperty files used to resolve indirectly-referenced request paths in contract tests - seeDoppelgangerApiDetectorExtension.getPropertyFiles().abstract org.gradle.api.file.DirectoryPropertyDirectory the AsciiDoc report is written to.abstract org.gradle.api.provider.Property<String> Name of the generated AsciiDoc report file (without path).abstract org.gradle.api.file.RegularFilePropertyFile that the persisted response coverage history is read from and, whengetUpdateResponseCoverageHistory()istrue, written back to.The absolute path ofgetResponseCoverageHistoryFile(), tracked as a plain@Inputvalue - seeDetectDoppelgangerApisTask.getContractHistoryFilePath().abstract org.gradle.api.file.RegularFilePropertyThe root OpenAPI document describing the API.abstract org.gradle.api.provider.Property<String> Version of the system under test whose@RestControllerclasses were scanned.abstract org.gradle.api.file.ConfigurableFileCollectionDirectories to search recursively for test classes.abstract org.gradle.api.provider.Property<Boolean> abstract org.gradle.api.provider.Property<Boolean> Whether to persist, across builds, a history of response code coverage.abstract org.gradle.api.provider.Property<Boolean> WhethergetResponseCoverageHistoryFile()is written back to disk after being updated with the current run's coverage.abstract org.gradle.api.provider.Property<Boolean> Whether to treat Atlassian OpenAPI request validator usage as verification evidence.abstract org.gradle.api.provider.Property<Boolean> Whether to treat Spring RestDocs test methods as verification evidence.abstract org.gradle.api.provider.Property<Boolean> Whether to treat Spring Cloud Contract DSL files as verification evidence.Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.Task
doNotTrackState, notCompatibleWithConfigurationCache
-
Constructor Details
-
ScanContractsTask
@Inject public ScanContractsTask()Creates the task. Instantiated by Gradle infrastructure viaInject.
-
-
Method Details
-
getControllerDirs
@InputFiles @PathSensitive(RELATIVE) public abstract org.gradle.api.file.ConfigurableFileCollection getControllerDirs()Directories to search recursively for@RestControllerclasses.- Returns:
- mutable file collection of controller source directories
-
getTestDirs
@InputFiles @PathSensitive(RELATIVE) public abstract org.gradle.api.file.ConfigurableFileCollection getTestDirs()Directories to search recursively for test classes.- Returns:
- mutable file collection of test source directories
-
getTestDirsUserConfigured
- Returns:
- mutable boolean property,
truewhengetTestDirs()reflects the user's own configuration rather than only the plugin's default
-
getRootDocument
@Optional @InputFiles @PathSensitive(RELATIVE) public abstract org.gradle.api.file.RegularFileProperty getRootDocument()The root OpenAPI document describing the API.- Returns:
- mutable file property for the root OpenAPI document
-
getOpenApiDir
@Optional @InputFiles @PathSensitive(RELATIVE) public abstract org.gradle.api.file.DirectoryProperty getOpenApiDir()Directory where OpenAPI descriptions are stored.- Returns:
- mutable directory property for the OpenAPI description directory
-
getContractsDir
@Optional @InputFiles @PathSensitive(RELATIVE) public abstract org.gradle.api.file.DirectoryProperty getContractsDir()Directory searched for Spring Cloud Contract DSL files whengetUseSpringCloudContract()istrue.- Returns:
- mutable directory property for the Spring Cloud Contract directory
-
getUseRestDocs
Whether to treat Spring RestDocs test methods as verification evidence.- Returns:
- mutable boolean property controlling whether the Spring RestDocs source is enabled
-
getUseOpenApiRequestValidator
Whether to treat Atlassian OpenAPI request validator usage as verification evidence.- Returns:
- mutable boolean property controlling whether the OpenAPI request validator source is enabled
-
getUseSpringCloudContract
Whether to treat Spring Cloud Contract DSL files as verification evidence.- Returns:
- mutable boolean property controlling whether the Spring Cloud Contract source is enabled
-
getIncludeResponseCoverage
Whether to additionally compute, for every declared response code, how many contract tests cover it. Defaults tofalse: the breakdown is not merely hidden when disabled, it is never computed.- Returns:
- mutable boolean property controlling whether response coverage is computed
-
getReportDir
@OutputDirectory public abstract org.gradle.api.file.DirectoryProperty getReportDir()Directory the AsciiDoc report is written to.- Returns:
- mutable directory property for the report output directory
-
getReportFileName
Name of the generated AsciiDoc report file (without path).- Returns:
- mutable string property for the report file name
-
getSystemUnderTestVersion
Version of the system under test whose@RestControllerclasses were scanned.- Returns:
- mutable string property for the system-under-test version
-
getTrackResponseCoverageHistory
Whether to persist, across builds, a history of response code coverage. Only meaningful together withgetIncludeResponseCoverage()- seegenerate()'s eager validation of that combination.- Returns:
- mutable boolean property controlling whether response coverage history is tracked
-
getResponseCoverageHistoryFile
@Internal public abstract org.gradle.api.file.RegularFileProperty getResponseCoverageHistoryFile()File that the persisted response coverage history is read from and, whengetUpdateResponseCoverageHistory()istrue, written back to. SeeDetectDoppelgangerApisTask.getContractHistoryFile()for why this is@Internalrather than tracked through Gradle's file-content-based up-to-date checking.- Returns:
- mutable file property for the response coverage history file
-
getResponseCoverageHistoryFilePath
The absolute path ofgetResponseCoverageHistoryFile(), tracked as a plain@Inputvalue - seeDetectDoppelgangerApisTask.getContractHistoryFilePath().- Returns:
- the response coverage history file's absolute path, or
nullif unset
-
getUpdateResponseCoverageHistory
WhethergetResponseCoverageHistoryFile()is written back to disk after being updated with the current run's coverage. Only consulted whengetTrackResponseCoverageHistory()istrue; the history file is always read regardless.- Returns:
- mutable boolean property controlling whether the response coverage history file is written back
-
getExcludePaths
Exclusion rule strings - seeDoppelgangerApiDetectorExtension.getExcludePaths().- Returns:
- mutable list property of exclusion rule strings
-
getExcludeFiles
@InputFiles @PathSensitive(RELATIVE) public abstract org.gradle.api.file.ConfigurableFileCollection getExcludeFiles()External exclusion rule files - seeDoppelgangerApiDetectorExtension.getExcludeFiles().- Returns:
- mutable file collection of exclusion rule files
-
getExcludeWellKnown
Bundled well-known exclusion set names - seeDoppelgangerApiDetectorExtension.getExcludeWellKnown().- Returns:
- mutable list property of well-known exclusion set names
-
getPropertyFiles
@InputFiles @PathSensitive(RELATIVE) public abstract org.gradle.api.file.ConfigurableFileCollection getPropertyFiles()Property files used to resolve indirectly-referenced request paths in contract tests - seeDoppelgangerApiDetectorExtension.getPropertyFiles().- Returns:
- mutable file collection of
.properties/.yml/.yamlfiles
-
getPathResolverHelperMethods
Helper-method conventions used to resolve indirectly-referenced request paths in contract tests - seeDoppelgangerApiDetectorExtension.getPathResolverHelperMethods().- Returns:
- mutable list property of
"ClassName.methodName"conventions
-
generate
public void generate()Task action: scans the same candidate endpointsDetectDoppelgangerApisTaskdoes, but reports response-code and contract-test coverage rather than a pass/fail verdict. Never fails the build on its own initiative. Bootstrapping-gap handling (a missinggetRootDocument(), emptygetControllerDirs(), etc.) follows the same "warn, don't fail" philosophy asDetectDoppelgangerApisTask.generate()- see that method's javadoc for the full rationale.Two DSL configurations are rejected eagerly: every verification source disabled at once (no test evidence could ever be gathered),
getUseSpringCloudContract()enabled withgetContractsDir()unconfigured, and - specific to this task -getTrackResponseCoverageHistory()enabled whilegetIncludeResponseCoverage()is disabled, since there would be no per-response-code data to persist.
-