Skip to content

Commit

Permalink
add androidVariants option to use instead of sourceSets in android pr…
Browse files Browse the repository at this point in the history
…ojects (to declare what animalsniffer tasks would be called after check task)
  • Loading branch information
xvik committed Nov 20, 2024
1 parent e5d4593 commit 491aae8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
* (breaking) Drop gradle 5 and 6 support
* Add android projects support (activates for android library and application plugins
and use variants (debug, release) instead of source sets)
* Add androidVariants configuration option to use instead of sourceSets in android projects
(to define which animalsniffer tasks would run with check task (together with build))

### 1.7.2 (2024-11-18)
* Update animalsniffer 1.23 -> 1.24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ class AnimalSnifferExtension extends CodeQualityExtension {
*/
CheckCacheExtension cache = new CheckCacheExtension()

/**
* When used with android, {@link #sourceSets} can't be used to configure what tasks to link "check" task.
* Instead, use this option to specify target android variants. Leave empty to not run animalsniffer after
* "check" task execution.
*/
Set<String> androidVariants = ['debug'] as Set

/**
* @param cache cache configuration closure
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class AnimalSnifferPlugin implements Plugin<Project> {

private static final String CHECK_SIGNATURE = 'animalsniffer'
private static final String BUILD_SIGNATURE = 'animalsnifferSignature'
private static final String CHECK_TASK = 'check'

private Project project
private AnimalSnifferExtension extension
Expand Down Expand Up @@ -166,7 +167,7 @@ class AnimalSnifferPlugin implements Plugin<Project> {
}

// include required animalsniffer tasks in check lifecycle
project.tasks.named('check').configure {
project.tasks.named(CHECK_TASK).configure {
dependsOn {
extension.sourceSets*.getTaskName(CHECK_SIGNATURE, null)
}
Expand All @@ -177,6 +178,8 @@ class AnimalSnifferPlugin implements Plugin<Project> {
@CompileStatic(TypeCheckingMode.SKIP)
private void registerAndroidCheckTasks() {
Object androidComponents = project.androidComponents
Map<String, TaskProvider> sourceIndex = [:]

androidComponents.onVariants(androidComponents.selector().all()) { variant ->
String sourceSetName = variant.name
String capitalizedSourceSetName = sourceSetName.capitalize()
Expand All @@ -197,13 +200,23 @@ class AnimalSnifferPlugin implements Plugin<Project> {
})
}
}
sourceIndex.put(sourceSetName, checkTask)

configureCheckTask(checkTask,
project.provider { project.files(variant.sources.java.all, variant.sources.kotlin.all) },
ANIMALSNIFFER_CACHE + capitalizedSourceSetName,
classesCollectorTaskName,
variant.compileClasspath)
}

// include required animalsniffer tasks in check lifecycle
project.tasks.named(CHECK_TASK).configure { task ->
extension.androidVariants.each {
if (sourceIndex.containsKey(it)) {
task.dependsOn(sourceIndex[it])
}
}
}
}

@CompileStatic(TypeCheckingMode.SKIP)
Expand Down

0 comments on commit 491aae8

Please sign in to comment.