|
1 | 1 | package com.gradle; |
2 | 2 |
|
3 | | -import com.gradle.develocity.agent.gradle.adapters.BuildCacheAdapter; |
| 3 | +import com.gradle.develocity.agent.gradle.adapters.BuildCacheConfigurationAdapter; |
| 4 | +import com.gradle.develocity.agent.gradle.adapters.BuildCacheConfigurationAdapter.LocalBuildCacheAdapter; |
| 5 | +import com.gradle.develocity.agent.gradle.adapters.BuildCacheConfigurationAdapter.RemoteBuildCacheAdapter; |
4 | 6 | import com.gradle.develocity.agent.gradle.adapters.DevelocityAdapter; |
5 | | -import com.gradle.develocity.agent.gradle.adapters.develocity.DevelocityBuildCacheAdapter; |
6 | | -import com.gradle.develocity.agent.gradle.adapters.enterprise.GradleEnterpriseBuildCacheAdapter; |
| 7 | + |
7 | 8 | import org.gradle.api.provider.ProviderFactory; |
8 | | -import org.gradle.caching.configuration.AbstractBuildCache; |
9 | | -import org.gradle.caching.configuration.BuildCacheConfiguration; |
10 | | -import org.gradle.caching.http.HttpBuildCache; |
11 | 9 |
|
12 | 10 | import java.time.Duration; |
13 | 11 | import java.util.Optional; |
@@ -51,43 +49,30 @@ void configureDevelocity(DevelocityAdapter develocity) { |
51 | 49 | firstAvailableBooleanSysPropertyOrEnvVariable(providers, DEVELOCITY_ALLOW_UNTRUSTED_SERVER, GRADLE_ENTERPRISE_ALLOW_UNTRUSTED_SERVER).ifPresent(develocity::setAllowUntrustedServer); |
52 | 50 | } |
53 | 51 |
|
54 | | - void configureBuildCache(BuildCacheConfiguration buildCache, Class<? extends AbstractBuildCache> develocityCacheClass) { |
55 | | - buildCache.local(local -> { |
56 | | - sysPropertyOrEnvVariable(LOCAL_CACHE_DIRECTORY, providers).ifPresent(local::setDirectory); |
57 | | - durationSysPropertyOrEnvVariable(LOCAL_CACHE_REMOVE_UNUSED_ENTRIES_AFTER_DAYS, providers).ifPresent(v -> local.setRemoveUnusedEntriesAfterDays((int) v.toDays())); |
58 | | - booleanSysPropertyOrEnvVariable(LOCAL_CACHE_ENABLED, providers).ifPresent(local::setEnabled); |
59 | | - booleanSysPropertyOrEnvVariable(LOCAL_CACHE_PUSH, providers).ifPresent(local::setPush); |
60 | | - }); |
61 | | - |
62 | | - // Only touch remote build cache configuration if it is already present and of type HttpBuildCache or DevelocityBuildCache |
63 | | - // Do nothing in case of another build cache type like AWS S3 being used |
64 | | - if (buildCache.getRemote() instanceof HttpBuildCache) { |
65 | | - buildCache.remote(HttpBuildCache.class, remote -> { |
66 | | - sysPropertyOrEnvVariable(REMOTE_CACHE_URL, providers).ifPresent(remote::setUrl); |
67 | | - booleanSysPropertyOrEnvVariable(REMOTE_CACHE_ALLOW_UNTRUSTED_SERVER, providers).ifPresent(remote::setAllowUntrustedServer); |
68 | | - booleanSysPropertyOrEnvVariable(REMOTE_CACHE_ALLOW_INSECURE_PROTOCOL, providers).ifPresent(remote::setAllowInsecureProtocol); |
69 | | - booleanSysPropertyOrEnvVariable(REMOTE_CACHE_ENABLED, providers).ifPresent(remote::setEnabled); |
70 | | - booleanSysPropertyOrEnvVariable(REMOTE_CACHE_PUSH, providers).ifPresent(remote::setPush); |
71 | | - }); |
72 | | - } else if (develocityCacheClass.isInstance(buildCache.getRemote())) { |
73 | | - buildCache.remote(develocityCacheClass, remote -> { |
74 | | - BuildCacheAdapter adapter = createBuildCacheAdapter(remote, develocityCacheClass); |
75 | | - sysPropertyOrEnvVariable(REMOTE_CACHE_SERVER, providers).ifPresent(adapter::setServer); |
76 | | - sysPropertyOrEnvVariable(REMOTE_CACHE_PATH, providers).ifPresent(adapter::setPath); |
77 | | - booleanSysPropertyOrEnvVariable(REMOTE_CACHE_ALLOW_UNTRUSTED_SERVER, providers).ifPresent(adapter::setAllowUntrustedServer); |
78 | | - booleanSysPropertyOrEnvVariable(REMOTE_CACHE_ALLOW_INSECURE_PROTOCOL, providers).ifPresent(adapter::setAllowInsecureProtocol); |
79 | | - booleanSysPropertyOrEnvVariable(REMOTE_CACHE_ENABLED, providers).ifPresent(adapter::setEnabled); |
80 | | - booleanSysPropertyOrEnvVariable(REMOTE_CACHE_PUSH, providers).ifPresent(adapter::setPush); |
81 | | - }); |
| 52 | + void configureBuildCache(BuildCacheConfigurationAdapter buildCache) { |
| 53 | + configureLocalBuildCache(buildCache.getLocal()); |
| 54 | + |
| 55 | + RemoteBuildCacheAdapter remote = buildCache.getRemote(); |
| 56 | + if (remote != null) { |
| 57 | + configureRemoteBuildCache(remote); |
82 | 58 | } |
83 | 59 | } |
84 | 60 |
|
85 | | - private static BuildCacheAdapter createBuildCacheAdapter(AbstractBuildCache cache, Class<? extends AbstractBuildCache> reportedCacheClass) { |
86 | | - if (reportedCacheClass.getName().toLowerCase().contains("develocity")) { |
87 | | - return new DevelocityBuildCacheAdapter(cache); |
88 | | - } |
| 61 | + private void configureLocalBuildCache(LocalBuildCacheAdapter local) { |
| 62 | + sysPropertyOrEnvVariable(LOCAL_CACHE_DIRECTORY, providers).ifPresent(local::setDirectory); |
| 63 | + durationSysPropertyOrEnvVariable(LOCAL_CACHE_REMOVE_UNUSED_ENTRIES_AFTER_DAYS, providers).ifPresent(v -> local.setRemoveUnusedEntriesAfterDays((int) v.toDays())); |
| 64 | + booleanSysPropertyOrEnvVariable(LOCAL_CACHE_ENABLED, providers).ifPresent(local::setEnabled); |
| 65 | + booleanSysPropertyOrEnvVariable(LOCAL_CACHE_PUSH, providers).ifPresent(local::setPush); |
| 66 | + } |
89 | 67 |
|
90 | | - return new GradleEnterpriseBuildCacheAdapter(cache); |
| 68 | + private void configureRemoteBuildCache(RemoteBuildCacheAdapter remote) { |
| 69 | + sysPropertyOrEnvVariable(REMOTE_CACHE_URL, providers).ifPresent(remote::setUrl); |
| 70 | + sysPropertyOrEnvVariable(REMOTE_CACHE_SERVER, providers).ifPresent(remote::setServer); |
| 71 | + sysPropertyOrEnvVariable(REMOTE_CACHE_PATH, providers).ifPresent(remote::setPath); |
| 72 | + booleanSysPropertyOrEnvVariable(REMOTE_CACHE_ALLOW_UNTRUSTED_SERVER, providers).ifPresent(remote::setAllowUntrustedServer); |
| 73 | + booleanSysPropertyOrEnvVariable(REMOTE_CACHE_ALLOW_INSECURE_PROTOCOL, providers).ifPresent(remote::setAllowInsecureProtocol); |
| 74 | + booleanSysPropertyOrEnvVariable(REMOTE_CACHE_ENABLED, providers).ifPresent(remote::setEnabled); |
| 75 | + booleanSysPropertyOrEnvVariable(REMOTE_CACHE_PUSH, providers).ifPresent(remote::setPush); |
91 | 76 | } |
92 | 77 |
|
93 | 78 | static Optional<String> firstAvailableSysPropertyOrEnvVariable(ProviderFactory providers, String... sysPropertyNames) { |
|
0 commit comments