Skip to content

Commit 52c336e

Browse files
committed
Fix android lint config download
- The task was defined multiple times since we do so for each lint task
1 parent 287fcb7 commit 52c336e

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

src/integTest/groovy/com/monits/gradle/sca/AndroidLintIntegTest.groovy

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ class AndroidLintIntegTest extends AbstractIntegTestFixture {
113113
BuildResult secondRun = gradleRunner.build()
114114

115115
then:
116-
file('build/outputs/').list().each { println it }
117-
118116
firstRun.task(taskName()).outcome == SUCCESS
119117
secondRun.task(taskName()).outcome == UP_TO_DATE
120118

@@ -144,8 +142,6 @@ class AndroidLintIntegTest extends AbstractIntegTestFixture {
144142
BuildResult secondRun = gradleRunner.build()
145143

146144
then:
147-
file('build/outputs/').list().each { println it }
148-
149145
firstRun.task(':lintDebug').outcome == SUCCESS
150146
secondRun.task(':lintDebug').outcome == UP_TO_DATE
151147

src/main/groovy/com/monits/gradle/sca/AndroidHelper.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final class AndroidHelper {
3434
private static final VersionNumber REPORT_PER_VARIANT_ANDROID_GRADLE_VERSION_MAX = VersionNumber.parse('2.2.9')
3535
private static final VersionNumber LINT_HAS_VARIANT_INFO = VersionNumber.parse('1.5.0')
3636
private static final VersionNumber USES_REPORTS_DIR = VersionNumber.parse(VERSION_2_3_0)
37+
private static final VersionNumber USES_JAVAC_TASK_OUTPUTS = VersionNumber.parse('3.2.0')
3738

3839
/**
3940
* Checks if the current Android Plugin produces a global report that matches a debuggable variant or not.
@@ -83,6 +84,14 @@ final class AndroidHelper {
8384
"${project.buildDir}/outputs/"
8485
}
8586

87+
static String getCompileOutputDir(final Project project, final String sourceSetName, final String sourceSetPath) {
88+
if (getCurrentVersion(project) >= USES_JAVAC_TASK_OUTPUTS) {
89+
return project.buildDir.absolutePath +
90+
"/intermediates/javac/${sourceSetName}/compile${sourceSetName.capitalize()}JavaWithJavac/classes/"
91+
}
92+
93+
project.buildDir.absolutePath + '/intermediates/classes/' + sourceSetPath + File.separator
94+
}
8695
/**
8796
* Retrieves the location of Android's build-cache directory.
8897
* @param project The project to analyze.

src/main/groovy/com/monits/gradle/sca/ClasspathAware.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ trait ClasspathAware {
188188
}
189189
}
190190

191-
project.buildDir.absolutePath + '/intermediates/classes/' + sourceSetOutputPath + File.separator
191+
AndroidHelper.getCompileOutputDir(project, sourceSetName, sourceSetOutputPath)
192192
}
193193

194194
/**

src/main/groovy/com/monits/gradle/sca/config/RemoteConfigLocator.groovy

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,32 @@ class RemoteConfigLocator {
4848
final String localFileName, final String taskName) {
4949
File destFile = getDestinationFile(project, localFileName)
5050

51-
DownloadTask download = getDownloadTaskIfExists(project, configLocation)
51+
// Make sure it doesn't already exist in the current project
52+
if (project.tasks.findByName(taskName) == null) {
53+
DownloadTask download = getDownloadTaskIfExists(project, configLocation)
5254

53-
if (download) {
54-
if (download.downloadedFile.absolutePath == destFile.absolutePath) {
55-
// Same file, so we create a NOOP task
56-
project.task(taskName, dependsOn:download.path)
57-
} else {
58-
// Already downloading, just wait for it to finish and copy it
59-
project.task(taskName, type:Copy) { Copy it ->
60-
it.from download.downloadedFile.parentFile
61-
it.into getDestinationDirectory(project)
62-
it.include download.downloadedFile.name
63-
it.rename download.downloadedFile.name, localFileName
64-
it.dependsOn download.path
55+
if (download) {
56+
if (download.downloadedFile.absolutePath == destFile.absolutePath) {
57+
// Same file, so we create a NOOP task
58+
project.task(taskName, dependsOn:download.path)
59+
} else {
60+
// Already downloading, just wait for it to finish and copy it
61+
project.task(taskName, type:Copy) { Copy it ->
62+
it.from download.downloadedFile.parentFile
63+
it.into getDestinationDirectory(project)
64+
it.include download.downloadedFile.name
65+
it.rename download.downloadedFile.name, localFileName
66+
it.dependsOn download.path
67+
}
6568
}
66-
}
67-
} else {
68-
download = project.task(taskName, type:DownloadTask) { DownloadTask it ->
69-
it.downloadedFile = destFile
70-
it.resourceUri = configLocation
71-
} as DownloadTask
69+
} else {
70+
download = project.task(taskName, type:DownloadTask) { DownloadTask it ->
71+
it.downloadedFile = destFile
72+
it.resourceUri = configLocation
73+
} as DownloadTask
7274

73-
DOWNLOAD_TASKS[configLocation] = download.path
75+
DOWNLOAD_TASKS[configLocation] = download.path
76+
}
7477
}
7578

7679
destFile

0 commit comments

Comments
 (0)