elharo commented on code in PR #394:
URL:
https://github.com/apache/maven-build-cache-extension/pull/394#discussion_r2581363153
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -138,33 +139,58 @@ public void execute(
boolean restorable = result.isSuccess() ||
result.isPartialSuccess();
boolean restored = false; // if partially restored need to save
increment
+
if (restorable) {
CacheRestorationStatus cacheRestorationStatus =
restoreProject(result, mojoExecutions,
mojoExecutionRunner, cacheConfig);
restored = CacheRestorationStatus.SUCCESS ==
cacheRestorationStatus;
executeExtraCleanPhaseIfNeeded(cacheRestorationStatus,
cleanPhase, mojoExecutionRunner);
}
- if (!restored) {
- for (MojoExecution mojoExecution : mojoExecutions) {
- if (source == Source.CLI
- || mojoExecution.getLifecyclePhase() == null
- ||
lifecyclePhasesHelper.isLaterPhaseThanClean(mojoExecution.getLifecyclePhase()))
{
- mojoExecutionRunner.run(mojoExecution);
+
+ try {
+ if (!restored && !forkedExecution) {
+ // Move pre-existing artifacts to staging directory to
prevent caching stale files
+ // from previous builds (e.g., after git branch switch, or
from cache restored
+ // with clock skew). This ensures save() only sees fresh
files built during this session.
+ // Skip for forked executions since they don't cache and
shouldn't modify artifacts.
+ try {
+ cacheController.stagePreExistingArtifacts(session,
project);
+ } catch (IOException e) {
+ LOGGER.warn("Failed to stage pre-existing artifacts:
{}", e.getMessage());
+ // Continue build - if staging fails, we'll just cache
what exists
Review Comment:
Then you don't need to warn. caching should be invisible to the user. move
this to debug
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -138,33 +139,58 @@ public void execute(
boolean restorable = result.isSuccess() ||
result.isPartialSuccess();
boolean restored = false; // if partially restored need to save
increment
+
if (restorable) {
CacheRestorationStatus cacheRestorationStatus =
restoreProject(result, mojoExecutions,
mojoExecutionRunner, cacheConfig);
restored = CacheRestorationStatus.SUCCESS ==
cacheRestorationStatus;
executeExtraCleanPhaseIfNeeded(cacheRestorationStatus,
cleanPhase, mojoExecutionRunner);
}
- if (!restored) {
- for (MojoExecution mojoExecution : mojoExecutions) {
- if (source == Source.CLI
- || mojoExecution.getLifecyclePhase() == null
- ||
lifecyclePhasesHelper.isLaterPhaseThanClean(mojoExecution.getLifecyclePhase()))
{
- mojoExecutionRunner.run(mojoExecution);
+
+ try {
+ if (!restored && !forkedExecution) {
+ // Move pre-existing artifacts to staging directory to
prevent caching stale files
+ // from previous builds (e.g., after git branch switch, or
from cache restored
+ // with clock skew). This ensures save() only sees fresh
files built during this session.
+ // Skip for forked executions since they don't cache and
shouldn't modify artifacts.
+ try {
+ cacheController.stagePreExistingArtifacts(session,
project);
+ } catch (IOException e) {
+ LOGGER.warn("Failed to stage pre-existing artifacts:
{}", e.getMessage());
+ // Continue build - if staging fails, we'll just cache
what exists
}
}
- }
- if (cacheState == INITIALIZED && (!result.isSuccess() ||
!restored)) {
- if (cacheConfig.isSkipSave()) {
- LOGGER.info("Cache saving is disabled.");
- } else if (cacheConfig.isMandatoryClean()
- && lifecyclePhasesHelper
- .getCleanSegment(project, mojoExecutions)
- .isEmpty()) {
- LOGGER.info("Cache storing is skipped since there was no
\"clean\" phase.");
- } else {
- final Map<String, MojoExecutionEvent> executionEvents =
mojoListener.getProjectExecutions(project);
- cacheController.save(result, mojoExecutions,
executionEvents);
+ if (!restored) {
+ for (MojoExecution mojoExecution : mojoExecutions) {
+ if (source == Source.CLI
+ || mojoExecution.getLifecyclePhase() == null
+ ||
lifecyclePhasesHelper.isLaterPhaseThanClean(mojoExecution.getLifecyclePhase()))
{
+ mojoExecutionRunner.run(mojoExecution);
+ }
+ }
+ }
+
+ if (cacheState == INITIALIZED && (!result.isSuccess() ||
!restored)) {
+ if (cacheConfig.isSkipSave()) {
+ LOGGER.info("Cache saving is disabled.");
Review Comment:
debug
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -138,33 +139,58 @@ public void execute(
boolean restorable = result.isSuccess() ||
result.isPartialSuccess();
boolean restored = false; // if partially restored need to save
increment
+
if (restorable) {
CacheRestorationStatus cacheRestorationStatus =
restoreProject(result, mojoExecutions,
mojoExecutionRunner, cacheConfig);
restored = CacheRestorationStatus.SUCCESS ==
cacheRestorationStatus;
executeExtraCleanPhaseIfNeeded(cacheRestorationStatus,
cleanPhase, mojoExecutionRunner);
}
- if (!restored) {
- for (MojoExecution mojoExecution : mojoExecutions) {
- if (source == Source.CLI
- || mojoExecution.getLifecyclePhase() == null
- ||
lifecyclePhasesHelper.isLaterPhaseThanClean(mojoExecution.getLifecyclePhase()))
{
- mojoExecutionRunner.run(mojoExecution);
+
+ try {
+ if (!restored && !forkedExecution) {
+ // Move pre-existing artifacts to staging directory to
prevent caching stale files
+ // from previous builds (e.g., after git branch switch, or
from cache restored
+ // with clock skew). This ensures save() only sees fresh
files built during this session.
+ // Skip for forked executions since they don't cache and
shouldn't modify artifacts.
+ try {
+ cacheController.stagePreExistingArtifacts(session,
project);
+ } catch (IOException e) {
+ LOGGER.warn("Failed to stage pre-existing artifacts:
{}", e.getMessage());
+ // Continue build - if staging fails, we'll just cache
what exists
}
}
- }
- if (cacheState == INITIALIZED && (!result.isSuccess() ||
!restored)) {
- if (cacheConfig.isSkipSave()) {
- LOGGER.info("Cache saving is disabled.");
- } else if (cacheConfig.isMandatoryClean()
- && lifecyclePhasesHelper
- .getCleanSegment(project, mojoExecutions)
- .isEmpty()) {
- LOGGER.info("Cache storing is skipped since there was no
\"clean\" phase.");
- } else {
- final Map<String, MojoExecutionEvent> executionEvents =
mojoListener.getProjectExecutions(project);
- cacheController.save(result, mojoExecutions,
executionEvents);
+ if (!restored) {
+ for (MojoExecution mojoExecution : mojoExecutions) {
+ if (source == Source.CLI
+ || mojoExecution.getLifecyclePhase() == null
+ ||
lifecyclePhasesHelper.isLaterPhaseThanClean(mojoExecution.getLifecyclePhase()))
{
+ mojoExecutionRunner.run(mojoExecution);
+ }
+ }
+ }
+
+ if (cacheState == INITIALIZED && (!result.isSuccess() ||
!restored)) {
+ if (cacheConfig.isSkipSave()) {
+ LOGGER.info("Cache saving is disabled.");
+ } else if (cacheConfig.isMandatoryClean()
+ && lifecyclePhasesHelper
+ .getCleanSegment(project, mojoExecutions)
+ .isEmpty()) {
+ LOGGER.info("Cache storing is skipped since there was
no \"clean\" phase.");
Review Comment:
debug
##########
src/main/mdo/build-cache-build.mdo:
##########
@@ -244,6 +244,12 @@ under the License.
<name>filePath</name>
<type>String</type>
</field>
+ <!--xs:element name="isDirectory" type="xs:boolean" minOccurs="0"/-->
Review Comment:
delete commented code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]