-
Notifications
You must be signed in to change notification settings - Fork 55
[MBUILDCACHE-46] Add maven.build.cache.remote.enabled parameter #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ public class CacheConfigImpl implements org.apache.maven.buildcache.xml.CacheCon | |
public static final String CONFIG_PATH_PROPERTY_NAME = "maven.build.cache.configPath"; | ||
public static final String CACHE_ENABLED_PROPERTY_NAME = "maven.build.cache.enabled"; | ||
public static final String CACHE_LOCATION_PROPERTY_NAME = "maven.build.cache.location"; | ||
public static final String REMOTE_ENABLED_PROPERTY_NAME = "maven.build.cache.remote.enabled"; | ||
public static final String SAVE_TO_REMOTE_PROPERTY_NAME = "maven.build.cache.remote.save.enabled"; | ||
public static final String SAVE_NON_OVERRIDEABLE_NAME = "maven.build.cache.remote.save.final"; | ||
public static final String FAIL_FAST_PROPERTY_NAME = "maven.build.cache.failFast"; | ||
|
@@ -124,13 +125,13 @@ public CacheState initialize() { | |
if (state == null) { | ||
synchronized (this) { | ||
if (state == null) { | ||
final String enabled = getProperty(CACHE_ENABLED_PROPERTY_NAME, "true"); | ||
final boolean enabled = getProperty(CACHE_ENABLED_PROPERTY_NAME, true); | ||
|
||
if (!rtInfo.isMavenVersion("[3.9.0,)")) { | ||
LOGGER.warn("Cache requires Maven >= 3.9, but version is " + rtInfo.getMavenVersion() | ||
+ ". Disabling cache."); | ||
state = CacheState.DISABLED; | ||
} else if (!Boolean.parseBoolean(enabled)) { | ||
} else if (!enabled) { | ||
LOGGER.info("Cache disabled by command line flag, project will be built fully and not cached"); | ||
state = CacheState.DISABLED; | ||
} else { | ||
|
@@ -163,12 +164,10 @@ public CacheState initialize() { | |
|
||
// `maven.build.cache.enabled` overrides the `enabled` of the XML file | ||
// to allow a disabled configuration to be enabled on the command line | ||
final String cacheEnabledProperty = getProperty(CACHE_ENABLED_PROPERTY_NAME, null); | ||
if (cacheEnabledProperty != null) { | ||
cacheConfig.getConfiguration().setEnabled(Boolean.parseBoolean(cacheEnabledProperty)); | ||
} | ||
boolean cacheEnabled = getProperty( | ||
CACHE_ENABLED_PROPERTY_NAME, getConfiguration().isEnabled()); | ||
|
||
if (!cacheConfig.getConfiguration().isEnabled()) { | ||
if (!cacheEnabled) { | ||
state = CacheState.DISABLED; | ||
} else { | ||
String hashAlgorithm = null; | ||
|
@@ -452,28 +451,29 @@ public boolean isEnabled() { | |
@Override | ||
public boolean isRemoteCacheEnabled() { | ||
checkInitializedState(); | ||
return getRemote().getUrl() != null && getRemote().isEnabled(); | ||
atsteffen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return getRemote().getUrl() != null | ||
&& getProperty(REMOTE_ENABLED_PROPERTY_NAME, getRemote().isEnabled()); | ||
} | ||
|
||
@Override | ||
public boolean isSaveToRemote() { | ||
checkInitializedState(); | ||
return Boolean.getBoolean(SAVE_TO_REMOTE_PROPERTY_NAME) || getRemote().isSaveToRemote(); | ||
return isRemoteCacheEnabled() | ||
&& getProperty(SAVE_TO_REMOTE_PROPERTY_NAME, getRemote().isSaveToRemote()); | ||
} | ||
|
||
@Override | ||
public boolean isSaveFinal() { | ||
return Boolean.getBoolean(SAVE_NON_OVERRIDEABLE_NAME); | ||
public boolean isSaveToRemoteFinal() { | ||
return isSaveToRemote() && getProperty(SAVE_NON_OVERRIDEABLE_NAME, false); | ||
} | ||
|
||
@Override | ||
public boolean isSkipCache() { | ||
return Boolean.getBoolean(CACHE_SKIP); | ||
return getProperty(CACHE_SKIP, false); | ||
} | ||
|
||
@Override | ||
public boolean isFailFast() { | ||
return Boolean.getBoolean(FAIL_FAST_PROPERTY_NAME); | ||
return getProperty(FAIL_FAST_PROPERTY_NAME, false); | ||
} | ||
|
||
@Override | ||
|
@@ -488,14 +488,12 @@ public String getBaselineCacheUrl() { | |
|
||
@Override | ||
public boolean isLazyRestore() { | ||
final String lazyRestore = getProperty(LAZY_RESTORE_PROPERTY_NAME, "false"); | ||
return Boolean.parseBoolean(lazyRestore); | ||
return getProperty(LAZY_RESTORE_PROPERTY_NAME, false); | ||
} | ||
|
||
@Override | ||
public boolean isRestoreGeneratedSources() { | ||
final String restoreGeneratedSources = getProperty(RESTORE_GENERATED_SOURCES_PROPERTY_NAME, "true"); | ||
return Boolean.parseBoolean(restoreGeneratedSources); | ||
return getProperty(RESTORE_GENERATED_SOURCES_PROPERTY_NAME, true); | ||
} | ||
|
||
@Override | ||
|
@@ -597,4 +595,15 @@ private String getProperty(String key, String defaultValue) { | |
} | ||
return value; | ||
} | ||
|
||
private boolean getProperty(String key, boolean defaultValue) { | ||
String value = session.getUserProperties().getProperty(key); | ||
if (value == null) { | ||
value = session.getSystemProperties().getProperty(key); | ||
if (value == null) { | ||
return defaultValue; | ||
} | ||
} | ||
return Boolean.parseBoolean(value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think with system properties this is redundant, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be accomplished any number of ways, but I decided to go with the micro-optimized form that does not require a string parse to handle the default case. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write integration tests for this flag. In pr #34, I added Wiremock-based integration tests to verify the remote cache behavior. The same approach could be reused here. It will be good to see a test that checks that remote is disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing flag and xml setting combinations, a lightweight unit test seems prudent. I went ahead and added a unit test for CacheConfigImpl. I tested the initialization and the remote parameters only, but structured it in a way that it should easily accommodate tests around other configurations. A couple integration tests make sense as well, but I thought i'd wait until PR [MBUILDCACHE-25] Fixes N+1 cache processings for forked executions #34 is merged to build off that approach. Tests are a great way to guide meaningful cleanups and refactors, and I feel I need some more time and context to do this at an integration level.
Remote configurations are now preconditioned on any meaningful encompassing configuration behind the CacheConfig interface.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the clarifications, I clicked it!