Skip to content

Commit 8cdd8d0

Browse files
[MENFORCER-460] Deprecate display-info mojo
1 parent c69f513 commit 8cdd8d0

File tree

9 files changed

+45
-46
lines changed

9 files changed

+45
-46
lines changed

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireOS.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void execute() throws EnforcerRuleException {
9797
if (allParamsEmpty()) {
9898
throw new EnforcerRuleError("All parameters can not be empty. "
9999
+ "You must pick at least one of (family, name, version, arch), "
100-
+ "you can use mvn enforcer:display-info to see the current OS information.");
100+
+ "you can use mvn --version to see the current OS information.");
101101
}
102102

103103
if (isValidFamily(this.family)) {

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/AbstractVersionEnforcer.java

-5
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,4 @@ public final String getVersion() {
138138
public void setVersion(String theVersion) {
139139
this.version = theVersion;
140140
}
141-
142-
@Override
143-
public String toString() {
144-
return String.format("%s[message=%s, version=%s]", getClass().getSimpleName(), getMessage(), version);
145-
}
146141
}

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireJavaVersion.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public final class RequireJavaVersion extends AbstractVersionEnforcer {
4444

4545
private static final Pattern JDK8_VERSION_PATTERN = Pattern.compile("([\\[(,]?)(1\\.8|8)([]),]?)");
4646

47+
/**
48+
* Display the normalized JDK version.
49+
*/
50+
private boolean display = false;
51+
4752
@Override
4853
public void setVersion(String theVersion) {
4954

@@ -66,12 +71,16 @@ public void setVersion(String theVersion) {
6671
@Override
6772
public void execute() throws EnforcerRuleException {
6873
String javaVersion = SystemUtils.JAVA_VERSION;
74+
String javaVersionNormalized = normalizeJDKVersion(javaVersion);
75+
if (display) {
76+
getLog().info("Detected Java Version: '" + javaVersion + "'");
77+
getLog().info("Normalized Java Version: '" + javaVersionNormalized + "'");
78+
} else {
79+
getLog().debug("Detected Java Version: '" + javaVersion + "'");
80+
getLog().debug("Normalized Java Version: '" + javaVersionNormalized + "'");
81+
}
6982

70-
getLog().debug("Detected Java String: '" + javaVersion + "'");
71-
javaVersion = normalizeJDKVersion(javaVersion);
72-
getLog().debug("Normalized Java String: '" + javaVersion + "'");
73-
74-
ArtifactVersion detectedJdkVersion = new DefaultArtifactVersion(javaVersion);
83+
ArtifactVersion detectedJdkVersion = new DefaultArtifactVersion(javaVersionNormalized);
7584

7685
getLog().debug("Parsed Version: Major: " + detectedJdkVersion.getMajorVersion() + " Minor: "
7786
+ detectedJdkVersion.getMinorVersion() + " Incremental: " + detectedJdkVersion.getIncrementalVersion()
@@ -133,4 +142,11 @@ private void setCustomMessageIfNoneConfigured(ArtifactVersion detectedJdkVersion
133142
super.setMessage(message);
134143
}
135144
}
145+
146+
@Override
147+
public String toString() {
148+
return String.format(
149+
"%s[message=%s, version=%s, display=%b]",
150+
getClass().getSimpleName(), getMessage(), getVersion(), display);
151+
}
136152
}

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireMavenVersion.java

+5
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ public void execute() throws EnforcerRuleException {
5252
DefaultArtifactVersion detectedVersion = new DefaultArtifactVersion(mavenVersion);
5353
enforceVersion("Maven", getVersion(), detectedVersion);
5454
}
55+
56+
@Override
57+
public String toString() {
58+
return String.format("%s[message=%s, version=%s]", getClass().getSimpleName(), getMessage(), getVersion());
59+
}
5560
}

enforcer-rules/src/site/apt/requireJavaVersion.apt.vm

+7-12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Require Java Version
3333

3434
* <<version>> - {{{./versionRanges.html}range}} of allowed JDKs.
3535

36+
* <<display>> - flag to display the normalized JDK version.
37+
38+
3639
For JDK 1.8 you can also use simple <<<8>>> as <version> - it will be internally changed to <<<1.8>>>
3740

3841
[]
@@ -49,18 +52,10 @@ Require Java Version
4952

5053
[]
5154

52-
This preprocessing normalizes various JDK version strings into a standard x.y.z-b version number. Your required range should therefore use the x.y.z-b format for comparison.
53-
There is an easy way to see how your current JDK string will be normalized:
54-
55-
+---+
56-
mvn enforcer:display-info
57-
...
58-
[INFO] Maven Version: 3.8.7
59-
[INFO] JDK Version: 1.8.0_352 normalized as: 1.8.0-352
60-
[INFO] Java Vendor: Homebrew
61-
[INFO] OS Info - Arch: x86_64, Family: mac, Name: mac os x, Version: 12.6.1
62-
+---+
63-
55+
This preprocessing normalizes various JDK version strings into a standard x.y.z-b version number.
56+
Your required range should therefore use the x.y.z-b format for comparison.
57+
There is an easy way to see how your current JDK string will be normalized, you can enable <<display>> option.
58+
6459
Sample Plugin Configuration:
6560

6661
+---+

enforcer-rules/src/site/apt/requireOS.apt.vm

+7-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ Require OS Version
8989
information for the current system:
9090

9191
+---+
92-
mvn enforcer:display-info
93-
...
94-
[INFO] Maven Version: 3.8.7
95-
[INFO] JDK Version: 1.8.0_352 normalized as: 1.8.0-352
96-
[INFO] Java Vendor: Homebrew
97-
[INFO] OS Info - Arch: x86_64, Family: mac, Name: mac os x, Version: 12.6.1
92+
mvn --version
93+
94+
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
95+
Maven home: /usr/local/Cellar/maven/3.8.7/libexec
96+
Java version: 1.8.0_352, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk@8/1.8.0+352/libexec/openjdk.jdk/Contents/Home/jre
97+
Default locale: en_GB, platform encoding: UTF-8
98+
OS name: "mac os x", version: "12.6.1", arch: "x86_64", family: "mac"
9899
+---+
99100

100101
Sample Plugin Configuration:

maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/DisplayInfoMojo.java

+2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
* This goal displays the current platform information.
3030
*
3131
* @author <a href="mailto:[email protected]">Brian Fox</a>
32+
* @deprecated please use {@code mvn --version}
3233
*/
34+
@Deprecated
3335
@Mojo(name = "display-info", threadSafe = true)
3436
public class DisplayInfoMojo extends AbstractMojo {
3537

maven-enforcer-plugin/src/site/apt/index.apt

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ Maven Enforcer Plugin - The Loving Iron Fist of Maven\x99
2828
The Enforcer plugin provides goals to control certain environmental constraints such as Maven version, JDK version and OS family
2929
along with many more built-in rules and user created rules.
3030

31-
* Goals Overview
31+
* Goal Overview
3232

33-
The Enforcer plugin has two goals:
33+
The Enforcer plugin has a goal:
3434

3535
*{{{./enforce-mojo.html}enforcer:enforce}} executes rules for each project in a multi-project build.
3636

37-
*{{{./display-info-mojo.html}enforcer:display-info}} display the current information as detected by the built-in rules.
38-
3937
* Usage
4038

4139
General instructions on how to use the Enforcer Plugin can be found on the {{{./usage.html}usage page}}.

maven-enforcer-plugin/src/site/apt/usage.apt.vm

-13
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,4 @@ Usage
105105
[...]
106106
</project>
107107
+---+
108-
109-
* The <<<enforcer:display-info>>> mojo
110108

111-
This goal is used to determine the current information as detected by the standard rules:
112-
113-
+---+
114-
mvn enforcer:display-info
115-
...
116-
[enforcer:display-info]
117-
Maven Version: 2.0.6
118-
JDK Version: 1.5.0_11 normalized as: 1.5.0-11
119-
OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1
120-
+---+
121-

0 commit comments

Comments
 (0)