-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from gradle/gh/7.0experimental
Change CompileLibraryResourcesWorkaround to warn when experimental flags are not used
- Loading branch information
Showing
8 changed files
with
179 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.gradle.android | ||
|
||
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_7_0 | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
enum Warnings { | ||
MAYBE_SUPPORTED_ANDROID_VERSION("WARNING: Android plugin ${Versions.CURRENT_ANDROID_VERSION} has not been tested with this version of the Android cache fix plugin, although it may work. We test against only the latest patch release versions of Android Gradle plugin: ${Versions.SUPPORTED_ANDROID_VERSIONS.join(", ")}. If ${Versions.CURRENT_ANDROID_VERSION} is newly released, we may not have had a chance to release a version tested against it yet. Proceed with caution. You can suppress this warning with with -D${Versions.IGNORE_VERSION_CHECK_PROPERTY}=true."), | ||
USE_COMPILE_LIBRARY_RESOURCES_EXPERIMENTAL("WARNING: Android plugin ${Versions.CURRENT_ANDROID_VERSION} has experimental support for using relative path sensitivity with CompileLibraryResourcesTask inputs which will provide more build cache hits and improve build speed. Set '${CompileLibraryResourcesWorkaround_7_0.CACHE_COMPILE_LIB_RESOURCES}=true' and '${CompileLibraryResourcesWorkaround_7_0.ENABLE_SOURCE_SET_PATHS_MAP}=true' in gradle.properties to enable this support.") | ||
|
||
final String warning | ||
private final AtomicBoolean warned = new AtomicBoolean() | ||
|
||
Warnings(String warning) { | ||
this.warning = warning | ||
} | ||
|
||
void warnOnce(org.gradle.api.logging.Logger logger) { | ||
if (!warned.getAndSet(true)) { | ||
logger.warn(warning) | ||
} | ||
} | ||
|
||
void reset() { | ||
warned.set(false) | ||
} | ||
|
||
static void resetAll() { | ||
values().each {it.reset() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.gradle.android | ||
|
||
import org.gradle.api.services.BuildService | ||
import org.gradle.api.services.BuildServiceParameters | ||
|
||
abstract class WarningsService implements BuildService<BuildServiceParameters.None>, AutoCloseable { | ||
@Override | ||
void close() throws Exception { | ||
Warnings.resetAll() | ||
} | ||
} |
27 changes: 20 additions & 7 deletions
27
src/main/groovy/org/gradle/android/workarounds/CompileLibraryResourcesWorkaround_7_0.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
package org.gradle.android.workarounds | ||
|
||
import org.gradle.android.AndroidIssue | ||
import org.gradle.android.Warnings | ||
import org.gradle.api.Project | ||
|
||
/** | ||
* Fixes the cacheability issue with CompileLibraryResourcesWorkaround where the inputDirectories field is | ||
* treated as an input with absolute path sensitivity. | ||
* This is the same as the {@link CompileLibraryResourcesWorkaround_4_0} but the field was renamed with a new type | ||
* in 4.2.0-alpha09. | ||
* Warns if the user is not using experimental support for relative path sensitivity that was added | ||
* with 7.0.0-alpha09. | ||
*/ | ||
@AndroidIssue(introducedIn = "7.0.0-alpha09", fixedIn = [], link = "https://issuetracker.google.com/issues/155218379") | ||
class CompileLibraryResourcesWorkaround_7_0 extends AbstractCompileLibraryResourcesWorkaround_4_2_orHigher { | ||
class CompileLibraryResourcesWorkaround_7_0 implements Workaround { | ||
public static final String ENABLE_SOURCE_SET_PATHS_MAP = "android.experimental.enableSourceSetPathsMap" | ||
public static final String CACHE_COMPILE_LIB_RESOURCES = "android.experimental.cacheCompileLibResources" | ||
|
||
@Override | ||
void apply(WorkaroundContext context) { | ||
boolean enableSourceSetPathsMap = Boolean.valueOf(context.project.findProperty(ENABLE_SOURCE_SET_PATHS_MAP) as String) | ||
boolean cacheCompileLibResources = Boolean.valueOf(context.project.findProperty(CACHE_COMPILE_LIB_RESOURCES) as String) | ||
|
||
if (!(enableSourceSetPathsMap && cacheCompileLibResources)) { | ||
Warnings.USE_COMPILE_LIBRARY_RESOURCES_EXPERIMENTAL.warnOnce(context.project.logger) | ||
} | ||
} | ||
|
||
@Override | ||
String getPropertyName() { | ||
return "inputDirectoriesAsAbsolute" | ||
boolean canBeApplied(Project project) { | ||
return true | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/test/groovy/org/gradle/android/CompileLibraryResourcesWorkaround_7_0Test.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package org.gradle.android | ||
|
||
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_7_0 | ||
import org.junit.Assume | ||
|
||
@MultiVersionTest | ||
class CompileLibraryResourcesWorkaround_7_0Test extends AbstractTest { | ||
def "warns when experimental flags are not provided"() { | ||
Assume.assumeTrue(TestVersions.latestAndroidVersionForCurrentJDK() >= Versions.android("7.0.0-alpha09")) | ||
|
||
SimpleAndroidApp.builder(temporaryFolder.root, cacheDir) | ||
.withAndroidVersion(TestVersions.latestAndroidVersionForCurrentJDK()) | ||
.withKotlinDisabled() | ||
.build() | ||
.writeProject() | ||
|
||
when: | ||
def result = withGradleVersion(TestVersions.latestGradleVersion().version) | ||
.withProjectDir(temporaryFolder.root) | ||
.withArguments( | ||
"-P${CompileLibraryResourcesWorkaround_7_0.ENABLE_SOURCE_SET_PATHS_MAP}=false", | ||
"-P${CompileLibraryResourcesWorkaround_7_0.CACHE_COMPILE_LIB_RESOURCES}=false", | ||
'assembleDebug' | ||
) | ||
.build() | ||
|
||
then: | ||
result.output.count(warningForAndroidVersion(TestVersions.latestAndroidVersionForCurrentJDK().toString())) == 1 | ||
|
||
when: | ||
result = withGradleVersion(TestVersions.latestGradleVersion().version) | ||
.withProjectDir(temporaryFolder.root) | ||
.withArguments( | ||
"-P${CompileLibraryResourcesWorkaround_7_0.ENABLE_SOURCE_SET_PATHS_MAP}=false", | ||
"-P${CompileLibraryResourcesWorkaround_7_0.CACHE_COMPILE_LIB_RESOURCES}=false", | ||
'assembleDebug' | ||
) | ||
.build() | ||
|
||
then: | ||
result.output.count(warningForAndroidVersion(TestVersions.latestAndroidVersionForCurrentJDK().toString())) == 1 | ||
} | ||
|
||
def "does not warn when experimental flags are provided"() { | ||
Assume.assumeTrue(TestVersions.latestAndroidVersionForCurrentJDK() >= Versions.android("7.0.0-alpha09")) | ||
|
||
SimpleAndroidApp.builder(temporaryFolder.root, cacheDir) | ||
.withAndroidVersion(TestVersions.latestAndroidVersionForCurrentJDK()) | ||
.withKotlinDisabled() | ||
.build() | ||
.writeProject() | ||
|
||
when: | ||
def result = withGradleVersion(TestVersions.latestGradleVersion().version) | ||
.withProjectDir(temporaryFolder.root) | ||
.withArguments( | ||
"-P${CompileLibraryResourcesWorkaround_7_0.ENABLE_SOURCE_SET_PATHS_MAP}=true", | ||
"-P${CompileLibraryResourcesWorkaround_7_0.CACHE_COMPILE_LIB_RESOURCES}=true", | ||
'assembleDebug' | ||
) | ||
.build() | ||
|
||
then: | ||
result.output.count(warningForAndroidVersion(TestVersions.latestAndroidVersionForCurrentJDK().toString())) == 0 | ||
} | ||
|
||
def "does not warn for versions that do not support experimental flag"() { | ||
Assume.assumeTrue(TestVersions.latestAndroidVersionForCurrentJDK() < Versions.android("7.0.0-alpha09")) | ||
|
||
SimpleAndroidApp.builder(temporaryFolder.root, cacheDir) | ||
.withAndroidVersion(TestVersions.latestAndroidVersionForCurrentJDK()) | ||
.withKotlinDisabled() | ||
.build() | ||
.writeProject() | ||
|
||
when: | ||
def result = withGradleVersion(TestVersions.latestGradleVersion().version) | ||
.withProjectDir(temporaryFolder.root) | ||
.withArguments( | ||
"-P${CompileLibraryResourcesWorkaround_7_0.ENABLE_SOURCE_SET_PATHS_MAP}=false", | ||
"-P${CompileLibraryResourcesWorkaround_7_0.CACHE_COMPILE_LIB_RESOURCES}=false", | ||
'assembleDebug' | ||
) | ||
.build() | ||
|
||
then: | ||
result.output.count(warningForAndroidVersion(TestVersions.latestAndroidVersionForCurrentJDK().toString())) == 0 | ||
} | ||
|
||
private static String warningForAndroidVersion(String androidVersion) { | ||
return Warnings.USE_COMPILE_LIBRARY_RESOURCES_EXPERIMENTAL.warning.replaceAll('Android plugin [^\\s]+', "Android plugin ${androidVersion}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters