Skip to content
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

Add option: maven.build.cache.forceRenew #137

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
@SessionScoped
@Named
@Priority(10)
@SuppressWarnings("unused")
public class BuildCacheMojosExecutionStrategy implements MojosExecutionStrategy {

private static final Logger LOGGER = LoggerFactory.getLogger(BuildCacheMojosExecutionStrategy.class);
Expand All @@ -79,7 +78,7 @@ public class BuildCacheMojosExecutionStrategy implements MojosExecutionStrategy
private final MojoParametersListener mojoListener;
private final LifecyclePhasesHelper lifecyclePhasesHelper;
private final MavenPluginManager mavenPluginManager;
private MojoExecutionScope mojoExecutionScope;
private final MojoExecutionScope mojoExecutionScope;

@Inject
public BuildCacheMojosExecutionStrategy(
Expand All @@ -97,6 +96,7 @@ public BuildCacheMojosExecutionStrategy(
this.mojoExecutionScope = mojoExecutionScope;
}

@Override
public void execute(
List<MojoExecution> mojoExecutions, MavenSession session, MojoExecutionRunner mojoExecutionRunner)
throws LifecycleExecutionException {
Expand Down Expand Up @@ -137,7 +137,8 @@ public void execute(
restored = CacheRestorationStatus.SUCCESS == cacheRestorationStatus;
executeExtraCleanPhaseIfNeeded(cacheRestorationStatus, cleanPhase, mojoExecutionRunner);
}
if (!restored) {

if (!restored || MavenProjectInput.isForceRenew(project)) {
for (MojoExecution mojoExecution : mojoExecutions) {
if (source == Source.CLI
|| mojoExecution.getLifecyclePhase() == null
Expand Down Expand Up @@ -222,12 +223,10 @@ private CacheRestorationStatus restoreProject(
for (MojoExecution cacheCandidate : cachedSegment) {
if (cacheController.isForcedExecution(project, cacheCandidate)) {
forcedExecutionMojos.add(cacheCandidate);
} else {
if (!verifyCacheConsistency(
cacheCandidate, build, project, session, mojoExecutionRunner, cacheConfig)) {
LOGGER.info("A cached mojo is not consistent, continuing with non cached build");
return CacheRestorationStatus.FAILURE;
}
} else if (!verifyCacheConsistency(
cacheCandidate, build, project, session, mojoExecutionRunner, cacheConfig)) {
LOGGER.info("A cached mojo is not consistent, continuing with non cached build");
return CacheRestorationStatus.FAILURE;
}
}

Expand All @@ -250,13 +249,13 @@ private CacheRestorationStatus restoreProject(
mojoExecutionScope.seed(MojoExecution.class, cacheCandidate);
// need maven 4 as minumum
// mojoExecutionScope.seed(
// org.apache.maven.api.plugin.Log.class,
// new DefaultLog(LoggerFactory.getLogger(
// cacheCandidate.getMojoDescriptor().getFullGoalName())));
// org.apache.maven.api.plugin.Log.class,
// new DefaultLog(LoggerFactory.getLogger(
// cacheCandidate.getMojoDescriptor().getFullGoalName())));
// mojoExecutionScope.seed(Project.class, ((DefaultSession)
// session.getSession()).getProject(project));
// mojoExecutionScope.seed(
// org.apache.maven.api.MojoExecution.class, new DefaultMojoExecution(cacheCandidate));
// org.apache.maven.api.MojoExecution.class, new DefaultMojoExecution(cacheCandidate));
mojoExecutionRunner.run(cacheCandidate);
} else {
LOGGER.info(
Expand Down Expand Up @@ -365,7 +364,7 @@ boolean isParamsMatched(
currentValue = normalizedPath(path, baseDirPath);
} else if (value instanceof Path) {
Path baseDirPath = project.getBasedir().toPath();
currentValue = normalizedPath(((Path) value), baseDirPath);
currentValue = normalizedPath((Path) value, baseDirPath);
} else if (value != null && value.getClass().isArray()) {
currentValue = ArrayUtils.toString(value);
} else {
Expand All @@ -384,13 +383,12 @@ boolean isParamsMatched(
expectedValue,
currentValue);
return false;
} else {
LOGGER.warn(
"Cache contains plugin execution with skip flag and might be incomplete. "
+ "Property: {}, execution {}",
propertyName,
mojoExecutionKey(mojoExecution));
}
LOGGER.warn(
"Cache contains plugin execution with skip flag and might be incomplete. "
+ "Property: {}, execution {}",
propertyName,
mojoExecutionKey(mojoExecution));
}
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import static org.apache.maven.buildcache.CacheUtils.isPom;
import static org.apache.maven.buildcache.CacheUtils.isSnapshot;
import static org.apache.maven.buildcache.xml.CacheConfigImpl.CACHE_ENABLED_PROPERTY_NAME;
import static org.apache.maven.buildcache.xml.CacheConfigImpl.CACHE_FORCE_RENEW_PROPERTY_NAME;
import static org.apache.maven.buildcache.xml.CacheConfigImpl.CACHE_SKIP;
import static org.apache.maven.buildcache.xml.CacheConfigImpl.RESTORE_GENERATED_SOURCES_PROPERTY_NAME;

Expand Down Expand Up @@ -419,11 +420,9 @@ private void startWalk(
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
if (!exclusionResolver.excludesPath(normalized)) {
LOGGER.debug("Adding: {}", normalized);
collectedFiles.add(normalized);
}
} else if (!exclusionResolver.excludesPath(normalized)) {
LOGGER.debug("Adding: {}", normalized);
collectedFiles.add(normalized);
}
}

Expand Down Expand Up @@ -556,7 +555,7 @@ private Path getPathOrNull(String text) {
// do not even bother logging about blank/null values
} else if (equalsAnyIgnoreCase(text, "true", "false", "utf-8", "null", "\\") // common values
|| contains(text, "*") // tag value is a glob or regex - unclear how to process
|| (contains(text, ":") && !contains(text, ":\\")) // artifactId
|| contains(text, ":") && !contains(text, ":\\") // artifactId
|| startsWithAny(text, "com.", "org.", "io.", "java.", "javax.") // java packages
|| startsWithAny(text, "${env.") // env variables in maven notation
|| startsWithAny(
Expand Down Expand Up @@ -720,7 +719,7 @@ public static boolean isSkipCache(MavenProject project) {
* Allow skipping generated sources restoration on a per-project level via a property (which defaults to true)
* e.g. {@code <maven.build.cache.restoreGeneratedSources>false<maven.build.cache.restoreGeneratedSources/>}.
*
* @param project
* @param project
* @return
*/
public static boolean isRestoreGeneratedSources(MavenProject project) {
Expand All @@ -738,4 +737,8 @@ public static boolean isRestoreGeneratedSources(MavenProject project) {
public static boolean isCacheDisabled(MavenProject project) {
return !Boolean.parseBoolean(project.getProperties().getProperty(CACHE_ENABLED_PROPERTY_NAME, "true"));
}

public static boolean isForceRenew(MavenProject project) {
return !Boolean.parseBoolean(project.getProperties().getProperty(CACHE_FORCE_RENEW_PROPERTY_NAME, "false"));
}
}
17 changes: 6 additions & 11 deletions src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
*/
@SessionScoped
@Named
@SuppressWarnings("unused")
public class CacheConfigImpl implements org.apache.maven.buildcache.xml.CacheConfig {

public static final String CONFIG_PATH_PROPERTY_NAME = "maven.build.cache.configPath";
Expand All @@ -92,6 +91,7 @@ public class CacheConfigImpl implements org.apache.maven.buildcache.xml.CacheCon
public static final String LAZY_RESTORE_PROPERTY_NAME = "maven.build.cache.lazyRestore";
public static final String RESTORE_GENERATED_SOURCES_PROPERTY_NAME = "maven.build.cache.restoreGeneratedSources";
public static final String ALWAYS_RUN_PLUGINS = "maven.build.cache.alwaysRunPlugins";
public static final String CACHE_FORCE_RENEW_PROPERTY_NAME = "maven.build.cache.forceRenew";

/**
* Flag to control if we should skip lookup for cached artifacts globally or for a particular project even if
Expand Down Expand Up @@ -219,9 +219,8 @@ public List<TrackedProperty> getTrackedProperties(MojoExecution mojoExecution) {
final GoalReconciliation reconciliationConfig = findReconciliationConfig(mojoExecution);
if (reconciliationConfig != null) {
return reconciliationConfig.getReconciles();
} else {
return Collections.emptyList();
}
return Collections.emptyList();
}

@Override
Expand Down Expand Up @@ -267,9 +266,8 @@ public List<PropertyName> getLoggedProperties(MojoExecution mojoExecution) {
final GoalReconciliation reconciliationConfig = findReconciliationConfig(mojoExecution);
if (reconciliationConfig != null) {
return reconciliationConfig.getLogs();
} else {
return Collections.emptyList();
}
return Collections.emptyList();
}

@Nonnull
Expand All @@ -279,9 +277,8 @@ public List<PropertyName> getNologProperties(MojoExecution mojoExecution) {
final GoalReconciliation reconciliationConfig = findReconciliationConfig(mojoExecution);
if (reconciliationConfig != null) {
return reconciliationConfig.getNologs();
} else {
return Collections.emptyList();
}
return Collections.emptyList();
}

@Nonnull
Expand Down Expand Up @@ -546,9 +543,8 @@ public boolean adjustMetaInfVersion() {
return Optional.ofNullable(getConfiguration().getProjectVersioning())
.map(ProjectVersioning::isAdjustMetaInf)
.orElse(false);
} else {
return false;
}
return false;
}

@Override
Expand All @@ -557,9 +553,8 @@ public boolean calculateProjectVersionChecksum() {
return Optional.ofNullable(getConfiguration().getProjectVersioning())
.map(ProjectVersioning::isCalculateProjectVersionChecksum)
.orElse(false);
} else {
return false;
}
return false;
}

@Nonnull
Expand Down
6 changes: 6 additions & 0 deletions src/main/mdo/build-cache-config.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ under the License.
<description>FileHash (causes file hash is saved in build metadata) or
EffectivePom (causes effective pom info is saved in build metadata)</description>
</field>
<field>
<name>forceRenew</name>
<type>boolean</type>
<defaultValue>false</defaultValue>
<description>Force the reconstruction of the Cache</description>
</field>
</fields>
</class>

Expand Down
Loading