Skip to content

Commit 7c90865

Browse files
committed
[MNG-7803] Fix CLI options for update policy
1 parent 87b9b30 commit 7c90865

File tree

5 files changed

+93
-14
lines changed

5 files changed

+93
-14
lines changed

maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest {
159159
*/
160160
private boolean noSnapshotUpdates = false;
161161

162+
private String globalUpdatePolicy;
163+
162164
private boolean useLegacyLocalRepositoryManager = false;
163165

164166
private Map<String, Object> data;
@@ -204,6 +206,7 @@ public static MavenExecutionRequest copy(MavenExecutionRequest original) {
204206
copy.setExecutionListener(original.getExecutionListener());
205207
copy.setUseLegacyLocalRepository(original.isUseLegacyLocalRepository());
206208
copy.setBuilderId(original.getBuilderId());
209+
copy.setGlobalUpdatePolicy(original.getGlobalUpdatePolicy());
207210
return copy;
208211
}
209212

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

11141117
return data;
11151118
}
1119+
1120+
@Override
1121+
public MavenExecutionRequest setGlobalUpdatePolicy(String globalUpdatePolicy) {
1122+
this.globalUpdatePolicy = globalUpdatePolicy;
1123+
return this;
1124+
}
1125+
1126+
@Override
1127+
public String getGlobalUpdatePolicy() {
1128+
return globalUpdatePolicy;
1129+
}
11161130
}

maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,26 @@ public interface MavenExecutionRequest {
244244
int getLoggingLevel();
245245

246246
// Update snapshots
247+
/** @deprecated use {@link #setGlobalUpdatePolicy(String)} instead */
248+
@Deprecated
247249
MavenExecutionRequest setUpdateSnapshots(boolean updateSnapshots);
248250

251+
/** @deprecated use {@link #getGlobalUpdatePolicy()} instead */
252+
@Deprecated
249253
boolean isUpdateSnapshots();
250254

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

259+
/** @deprecated use {@link #getGlobalUpdatePolicy()} instead */
260+
@Deprecated
253261
boolean isNoSnapshotUpdates();
254262

263+
MavenExecutionRequest setGlobalUpdatePolicy(String globalUpdatePolicy);
264+
265+
String getGlobalUpdatePolicy();
266+
255267
// Checksum policy
256268
MavenExecutionRequest setGlobalChecksumPolicy(String globalChecksumPolicy);
257269

maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ public DefaultRepositorySystemSession newRepositorySession(MavenExecutionRequest
174174
session.setOffline(request.isOffline());
175175
session.setChecksumPolicy(request.getGlobalChecksumPolicy());
176176
session.setUpdatePolicy(
177-
request.isNoSnapshotUpdates()
178-
? RepositoryPolicy.UPDATE_POLICY_NEVER
179-
: request.isUpdateSnapshots() ? RepositoryPolicy.UPDATE_POLICY_ALWAYS : null);
177+
request.getGlobalUpdatePolicy() != null
178+
? request.getGlobalUpdatePolicy()
179+
: request.isNoSnapshotUpdates()
180+
? RepositoryPolicy.UPDATE_POLICY_NEVER
181+
: request.isUpdateSnapshots() ? RepositoryPolicy.UPDATE_POLICY_ALWAYS : null);
180182

181183
int errorPolicy = 0;
182184
errorPolicy |= request.isCacheNotFound()

maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,28 @@ public class CLIManager {
6262

6363
public static final char NON_RECURSIVE = 'N';
6464

65-
public static final char UPDATE_SNAPSHOTS = 'U';
66-
6765
public static final char ACTIVATE_PROFILES = 'P';
6866

67+
/**
68+
* @deprecated use {@link #UPDATE_ALWAYS_POLICY} or {@link #UPDATE_POLICY}
69+
*/
70+
@Deprecated
71+
public static final char UPDATE_SNAPSHOTS = 'U';
72+
73+
/**
74+
* @deprecated use {@link #UPDATE_NEVER_POLICY}
75+
*/
76+
@Deprecated
6977
public static final String SUPPRESS_SNAPSHOT_UPDATES = "nsu";
7078

79+
public static final char UPDATE_ALWAYS_POLICY = 'U';
80+
81+
public static final String UPDATE_NEVER_POLICY = "un";
82+
83+
public static final String UPDATE_DAILY_POLICY = "ud";
84+
85+
public static final String UPDATE_POLICY = "up";
86+
7187
public static final char CHECKSUM_FAILURE_POLICY = 'C';
7288

7389
public static final char CHECKSUM_WARNING_POLICY = 'c';
@@ -161,10 +177,6 @@ public CLIManager() {
161177
.desc(
162178
"Do not recurse into sub-projects. When used together with -pl, do not recurse into sub-projects of selected aggregators")
163179
.build());
164-
options.addOption(Option.builder(Character.toString(UPDATE_SNAPSHOTS))
165-
.longOpt("update-snapshots")
166-
.desc("Forces a check for missing releases and updated snapshots on remote repositories")
167-
.build());
168180
options.addOption(Option.builder(Character.toString(ACTIVATE_PROFILES))
169181
.longOpt("activate-profiles")
170182
.desc(
@@ -175,9 +187,22 @@ public CLIManager() {
175187
.longOpt("batch-mode")
176188
.desc("Run in non-interactive (batch) mode (disables output color)")
177189
.build());
178-
options.addOption(Option.builder(SUPPRESS_SNAPSHOT_UPDATES)
179-
.longOpt("no-snapshot-updates")
180-
.desc("Suppress SNAPSHOT updates")
190+
options.addOption(Option.builder(Character.toString(UPDATE_ALWAYS_POLICY))
191+
.longOpt("update-always")
192+
.desc("Forces a check for missing releases and updated snapshots on remote repositories")
193+
.build());
194+
options.addOption(Option.builder(UPDATE_NEVER_POLICY)
195+
.longOpt("update-never")
196+
.desc("Never checks for missing releases and updated snapshots on remote repositories")
197+
.build());
198+
options.addOption(Option.builder(UPDATE_DAILY_POLICY)
199+
.longOpt("update-daily")
200+
.desc("Daily checks for missing releases and updated snapshots on remote repositories")
201+
.build());
202+
options.addOption(Option.builder(UPDATE_POLICY)
203+
.longOpt("update-policy")
204+
.hasArg()
205+
.desc("Specifies the policy for missing releases and updated snapshots on remote repositories")
181206
.build());
182207
options.addOption(Option.builder(Character.toString(CHECKSUM_FAILURE_POLICY))
183208
.longOpt("strict-checksums")
@@ -301,6 +326,16 @@ public CLIManager() {
301326
.longOpt(DEBUG)
302327
.desc("Produce execution verbose output (deprecated; only kept for backward compatibility)")
303328
.build());
329+
options.addOption(Option.builder()
330+
.longOpt("update-snapshots")
331+
.desc(
332+
"Forces a check for missing releases and updated snapshots on remote repositories (deprecated; only kept for backward compatibility; use --update-always)")
333+
.build());
334+
options.addOption(Option.builder(SUPPRESS_SNAPSHOT_UPDATES)
335+
.longOpt("no-snapshot-updates")
336+
.desc(
337+
"Suppress SNAPSHOT updates (deprecated; only kept for backward compatibility; use --update-never)")
338+
.build());
304339
}
305340

306341
public CommandLine parse(String[] args) throws ParseException {

maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
import org.codehaus.plexus.util.StringUtils;
109109
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
110110
import org.eclipse.aether.DefaultRepositoryCache;
111+
import org.eclipse.aether.repository.RepositoryPolicy;
111112
import org.eclipse.aether.transfer.TransferListener;
112113
import org.slf4j.ILoggerFactory;
113114
import org.slf4j.Logger;
@@ -1243,12 +1244,13 @@ private MavenExecutionRequest populateRequest(CliRequest cliRequest, MavenExecut
12431244
File baseDirectory = new File(workingDirectory, "").getAbsoluteFile();
12441245

12451246
disableOnPresentOption(commandLine, CLIManager.BATCH_MODE, request::setInteractiveMode);
1246-
enableOnPresentOption(commandLine, CLIManager.SUPPRESS_SNAPSHOT_UPDATES, request::setNoSnapshotUpdates);
12471247
request.setGoals(commandLine.getArgList());
12481248
request.setReactorFailureBehavior(determineReactorFailureBehaviour(commandLine));
12491249
disableOnPresentOption(commandLine, CLIManager.NON_RECURSIVE, request::setRecursive);
12501250
enableOnPresentOption(commandLine, CLIManager.OFFLINE, request::setOffline);
1251-
enableOnPresentOption(commandLine, CLIManager.UPDATE_SNAPSHOTS, request::setUpdateSnapshots);
1251+
enableOnPresentOption(commandLine, CLIManager.SUPPRESS_SNAPSHOT_UPDATES, request::setNoSnapshotUpdates);
1252+
enableOnPresentOption(commandLine, CLIManager.UPDATE_ALWAYS_POLICY, request::setUpdateSnapshots);
1253+
request.setGlobalUpdatePolicy(determineGlobalUpdatePolicy(commandLine));
12521254
request.setGlobalChecksumPolicy(determineGlobalCheckPolicy(commandLine));
12531255
request.setBaseDirectory(baseDirectory);
12541256
request.setSystemProperties(cliRequest.systemProperties);
@@ -1460,6 +1462,20 @@ private String determineGlobalCheckPolicy(final CommandLine commandLine) {
14601462
}
14611463
}
14621464

1465+
private String determineGlobalUpdatePolicy(final CommandLine commandLine) {
1466+
if (commandLine.hasOption(CLIManager.UPDATE_POLICY)) {
1467+
return commandLine.getOptionValue(CLIManager.UPDATE_POLICY);
1468+
} else if (commandLine.hasOption(CLIManager.UPDATE_ALWAYS_POLICY)) {
1469+
return RepositoryPolicy.UPDATE_POLICY_ALWAYS;
1470+
} else if (commandLine.hasOption(CLIManager.UPDATE_NEVER_POLICY)) {
1471+
return RepositoryPolicy.UPDATE_POLICY_NEVER;
1472+
} else if (commandLine.hasOption(CLIManager.UPDATE_DAILY_POLICY)) {
1473+
return RepositoryPolicy.UPDATE_POLICY_DAILY;
1474+
} else {
1475+
return null;
1476+
}
1477+
}
1478+
14631479
private void disableOnPresentOption(
14641480
final CommandLine commandLine, final String option, final Consumer<Boolean> setting) {
14651481
if (commandLine.hasOption(option)) {

0 commit comments

Comments
 (0)