Skip to content
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 @@ -159,6 +159,8 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest {
*/
private boolean noSnapshotUpdates = false;

private String globalUpdatePolicy;

private boolean useLegacyLocalRepositoryManager = false;

private Map<String, Object> data;
Expand Down Expand Up @@ -204,6 +206,7 @@ public static MavenExecutionRequest copy(MavenExecutionRequest original) {
copy.setExecutionListener(original.getExecutionListener());
copy.setUseLegacyLocalRepository(original.isUseLegacyLocalRepository());
copy.setBuilderId(original.getBuilderId());
copy.setGlobalUpdatePolicy(original.getGlobalUpdatePolicy());
return copy;
}

Expand Down Expand Up @@ -1113,4 +1116,15 @@ public Map<String, Object> getData() {

return data;
}

@Override
public MavenExecutionRequest setGlobalUpdatePolicy(String globalUpdatePolicy) {
this.globalUpdatePolicy = globalUpdatePolicy;
return this;
}

@Override
public String getGlobalUpdatePolicy() {
return globalUpdatePolicy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,26 @@ public interface MavenExecutionRequest {
int getLoggingLevel();

// Update snapshots
/** @deprecated use {@link #setGlobalUpdatePolicy(String)} instead */
@Deprecated
MavenExecutionRequest setUpdateSnapshots(boolean updateSnapshots);

/** @deprecated use {@link #getGlobalUpdatePolicy()} instead */
@Deprecated
boolean isUpdateSnapshots();

/** @deprecated use {@link #setGlobalUpdatePolicy(String)} instead */
@Deprecated
MavenExecutionRequest setNoSnapshotUpdates(boolean noSnapshotUpdates);

/** @deprecated use {@link #getGlobalUpdatePolicy()} instead */
@Deprecated
boolean isNoSnapshotUpdates();

MavenExecutionRequest setGlobalUpdatePolicy(String globalUpdatePolicy);

String getGlobalUpdatePolicy();

// Checksum policy
MavenExecutionRequest setGlobalChecksumPolicy(String globalChecksumPolicy);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ public DefaultRepositorySystemSession newRepositorySession(MavenExecutionRequest
session.setOffline(request.isOffline());
session.setChecksumPolicy(request.getGlobalChecksumPolicy());
session.setUpdatePolicy(
request.isNoSnapshotUpdates()
? RepositoryPolicy.UPDATE_POLICY_NEVER
: request.isUpdateSnapshots() ? RepositoryPolicy.UPDATE_POLICY_ALWAYS : null);
request.getGlobalUpdatePolicy() != null
? request.getGlobalUpdatePolicy()
: request.isNoSnapshotUpdates()
? RepositoryPolicy.UPDATE_POLICY_NEVER
: request.isUpdateSnapshots() ? RepositoryPolicy.UPDATE_POLICY_ALWAYS : null);

int errorPolicy = 0;
errorPolicy |= request.isCacheNotFound()
Expand Down
53 changes: 44 additions & 9 deletions maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,28 @@ public class CLIManager {

public static final char NON_RECURSIVE = 'N';

public static final char UPDATE_SNAPSHOTS = 'U';

public static final char ACTIVATE_PROFILES = 'P';

/**
* @deprecated use {@link #UPDATE_ALWAYS_POLICY} or {@link #UPDATE_POLICY}
*/
@Deprecated
public static final char UPDATE_SNAPSHOTS = 'U';

/**
* @deprecated use {@link #UPDATE_NEVER_POLICY}
*/
@Deprecated
public static final String SUPPRESS_SNAPSHOT_UPDATES = "nsu";

public static final char UPDATE_ALWAYS_POLICY = 'U';

public static final String UPDATE_NEVER_POLICY = "un";

public static final String UPDATE_DAILY_POLICY = "ud";

public static final String UPDATE_POLICY = "up";

public static final char CHECKSUM_FAILURE_POLICY = 'C';

public static final char CHECKSUM_WARNING_POLICY = 'c';
Expand Down Expand Up @@ -165,10 +181,6 @@ public CLIManager() {
.desc(
"Do not recurse into sub-projects. When used together with -pl, do not recurse into sub-projects of selected aggregators")
.build());
options.addOption(Option.builder(Character.toString(UPDATE_SNAPSHOTS))
.longOpt("update-snapshots")
.desc("Forces a check for missing releases and updated snapshots on remote repositories")
.build());
options.addOption(Option.builder(Character.toString(ACTIVATE_PROFILES))
.longOpt("activate-profiles")
.desc(
Expand All @@ -188,9 +200,22 @@ public CLIManager() {
.desc(
"Run in interactive mode. Overrides, if applicable, the CI environment variable and --non-interactive/--batch-mode options")
.build());
options.addOption(Option.builder(SUPPRESS_SNAPSHOT_UPDATES)
.longOpt("no-snapshot-updates")
.desc("Suppress SNAPSHOT updates")
options.addOption(Option.builder(Character.toString(UPDATE_ALWAYS_POLICY))
.longOpt("update-always")
.desc("Forces a check for missing releases and updated snapshots on remote repositories")
.build());
options.addOption(Option.builder(UPDATE_NEVER_POLICY)
.longOpt("update-never")
.desc("Never checks for missing releases and updated snapshots on remote repositories")
.build());
options.addOption(Option.builder(UPDATE_DAILY_POLICY)
.longOpt("update-daily")
.desc("Daily checks for missing releases and updated snapshots on remote repositories")
.build());
options.addOption(Option.builder(UPDATE_POLICY)
.longOpt("update-policy")
.hasArg()
.desc("Specifies the policy for missing releases and updated snapshots on remote repositories")
.build());
options.addOption(Option.builder(Character.toString(CHECKSUM_FAILURE_POLICY))
.longOpt("strict-checksums")
Expand Down Expand Up @@ -314,6 +339,16 @@ public CLIManager() {
.longOpt(DEBUG)
.desc("Produce execution verbose output (deprecated; only kept for backward compatibility)")
.build());
options.addOption(Option.builder()
.longOpt("update-snapshots")
.desc(
"Forces a check for missing releases and updated snapshots on remote repositories (deprecated; only kept for backward compatibility; use --update-always)")
.build());
options.addOption(Option.builder(SUPPRESS_SNAPSHOT_UPDATES)
.longOpt("no-snapshot-updates")
.desc(
"Suppress SNAPSHOT updates (deprecated; only kept for backward compatibility; use --update-never)")
.build());
}

public CommandLine parse(String[] args) throws ParseException {
Expand Down
20 changes: 18 additions & 2 deletions maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.DefaultRepositoryCache;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.transfer.TransferListener;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
Expand Down Expand Up @@ -1249,12 +1250,13 @@ private MavenExecutionRequest populateRequest(CliRequest cliRequest, MavenExecut
File baseDirectory = new File(workingDirectory, "").getAbsoluteFile();

disableInteractiveModeIfNeeded(cliRequest, request);
enableOnPresentOption(commandLine, CLIManager.SUPPRESS_SNAPSHOT_UPDATES, request::setNoSnapshotUpdates);
request.setGoals(commandLine.getArgList());
request.setReactorFailureBehavior(determineReactorFailureBehaviour(commandLine));
disableOnPresentOption(commandLine, CLIManager.NON_RECURSIVE, request::setRecursive);
enableOnPresentOption(commandLine, CLIManager.OFFLINE, request::setOffline);
enableOnPresentOption(commandLine, CLIManager.UPDATE_SNAPSHOTS, request::setUpdateSnapshots);
enableOnPresentOption(commandLine, CLIManager.SUPPRESS_SNAPSHOT_UPDATES, request::setNoSnapshotUpdates);
enableOnPresentOption(commandLine, CLIManager.UPDATE_ALWAYS_POLICY, request::setUpdateSnapshots);
request.setGlobalUpdatePolicy(determineGlobalUpdatePolicy(commandLine));
request.setGlobalChecksumPolicy(determineGlobalCheckPolicy(commandLine));
request.setBaseDirectory(baseDirectory);
request.setSystemProperties(cliRequest.systemProperties);
Expand Down Expand Up @@ -1490,6 +1492,20 @@ private String determineGlobalCheckPolicy(final CommandLine commandLine) {
}
}

private String determineGlobalUpdatePolicy(final CommandLine commandLine) {
if (commandLine.hasOption(CLIManager.UPDATE_POLICY)) {
return commandLine.getOptionValue(CLIManager.UPDATE_POLICY);
} else if (commandLine.hasOption(CLIManager.UPDATE_ALWAYS_POLICY)) {
return RepositoryPolicy.UPDATE_POLICY_ALWAYS;
} else if (commandLine.hasOption(CLIManager.UPDATE_NEVER_POLICY)) {
return RepositoryPolicy.UPDATE_POLICY_NEVER;
} else if (commandLine.hasOption(CLIManager.UPDATE_DAILY_POLICY)) {
return RepositoryPolicy.UPDATE_POLICY_DAILY;
} else {
return null;
}
}

private void disableOnPresentOption(
final CommandLine commandLine, final String option, final Consumer<Boolean> setting) {
if (commandLine.hasOption(option)) {
Expand Down
Loading