From 8cdd8d079e9bc2d410a4ded4c97144826a5888cb Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Wed, 18 Jan 2023 18:10:19 +0100 Subject: [PATCH] [MENFORCER-460] Deprecate display-info mojo --- .../maven/enforcer/rules/RequireOS.java | 2 +- .../version/AbstractVersionEnforcer.java | 5 ---- .../rules/version/RequireJavaVersion.java | 26 +++++++++++++++---- .../rules/version/RequireMavenVersion.java | 5 ++++ .../src/site/apt/requireJavaVersion.apt.vm | 19 +++++--------- enforcer-rules/src/site/apt/requireOS.apt.vm | 13 +++++----- .../plugins/enforcer/DisplayInfoMojo.java | 2 ++ maven-enforcer-plugin/src/site/apt/index.apt | 6 ++--- .../src/site/apt/usage.apt.vm | 13 ---------- 9 files changed, 45 insertions(+), 46 deletions(-) diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireOS.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireOS.java index 29738da1..eae734aa 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireOS.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequireOS.java @@ -97,7 +97,7 @@ public void execute() throws EnforcerRuleException { if (allParamsEmpty()) { throw new EnforcerRuleError("All parameters can not be empty. " + "You must pick at least one of (family, name, version, arch), " - + "you can use mvn enforcer:display-info to see the current OS information."); + + "you can use mvn --version to see the current OS information."); } if (isValidFamily(this.family)) { diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/AbstractVersionEnforcer.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/AbstractVersionEnforcer.java index 042bbc4a..946a58de 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/AbstractVersionEnforcer.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/AbstractVersionEnforcer.java @@ -138,9 +138,4 @@ public final String getVersion() { public void setVersion(String theVersion) { this.version = theVersion; } - - @Override - public String toString() { - return String.format("%s[message=%s, version=%s]", getClass().getSimpleName(), getMessage(), version); - } } diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireJavaVersion.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireJavaVersion.java index ad444061..dcaeb686 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireJavaVersion.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireJavaVersion.java @@ -44,6 +44,11 @@ public final class RequireJavaVersion extends AbstractVersionEnforcer { private static final Pattern JDK8_VERSION_PATTERN = Pattern.compile("([\\[(,]?)(1\\.8|8)([]),]?)"); + /** + * Display the normalized JDK version. + */ + private boolean display = false; + @Override public void setVersion(String theVersion) { @@ -66,12 +71,16 @@ public void setVersion(String theVersion) { @Override public void execute() throws EnforcerRuleException { String javaVersion = SystemUtils.JAVA_VERSION; + String javaVersionNormalized = normalizeJDKVersion(javaVersion); + if (display) { + getLog().info("Detected Java Version: '" + javaVersion + "'"); + getLog().info("Normalized Java Version: '" + javaVersionNormalized + "'"); + } else { + getLog().debug("Detected Java Version: '" + javaVersion + "'"); + getLog().debug("Normalized Java Version: '" + javaVersionNormalized + "'"); + } - getLog().debug("Detected Java String: '" + javaVersion + "'"); - javaVersion = normalizeJDKVersion(javaVersion); - getLog().debug("Normalized Java String: '" + javaVersion + "'"); - - ArtifactVersion detectedJdkVersion = new DefaultArtifactVersion(javaVersion); + ArtifactVersion detectedJdkVersion = new DefaultArtifactVersion(javaVersionNormalized); getLog().debug("Parsed Version: Major: " + detectedJdkVersion.getMajorVersion() + " Minor: " + detectedJdkVersion.getMinorVersion() + " Incremental: " + detectedJdkVersion.getIncrementalVersion() @@ -133,4 +142,11 @@ private void setCustomMessageIfNoneConfigured(ArtifactVersion detectedJdkVersion super.setMessage(message); } } + + @Override + public String toString() { + return String.format( + "%s[message=%s, version=%s, display=%b]", + getClass().getSimpleName(), getMessage(), getVersion(), display); + } } diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireMavenVersion.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireMavenVersion.java index 4dfb9e80..144f3651 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireMavenVersion.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireMavenVersion.java @@ -52,4 +52,9 @@ public void execute() throws EnforcerRuleException { DefaultArtifactVersion detectedVersion = new DefaultArtifactVersion(mavenVersion); enforceVersion("Maven", getVersion(), detectedVersion); } + + @Override + public String toString() { + return String.format("%s[message=%s, version=%s]", getClass().getSimpleName(), getMessage(), getVersion()); + } } diff --git a/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm b/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm index 39cd978f..f4acb712 100644 --- a/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm +++ b/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm @@ -33,6 +33,9 @@ Require Java Version * <> - {{{./versionRanges.html}range}} of allowed JDKs. + * <> - flag to display the normalized JDK version. + + For JDK 1.8 you can also use simple <<<8>>> as - it will be internally changed to <<<1.8>>> [] @@ -49,18 +52,10 @@ Require Java Version [] - 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. - There is an easy way to see how your current JDK string will be normalized: - -+---+ -mvn enforcer:display-info -... -[INFO] Maven Version: 3.8.7 -[INFO] JDK Version: 1.8.0_352 normalized as: 1.8.0-352 -[INFO] Java Vendor: Homebrew -[INFO] OS Info - Arch: x86_64, Family: mac, Name: mac os x, Version: 12.6.1 -+---+ - + 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. + There is an easy way to see how your current JDK string will be normalized, you can enable <> option. + Sample Plugin Configuration: +---+ diff --git a/enforcer-rules/src/site/apt/requireOS.apt.vm b/enforcer-rules/src/site/apt/requireOS.apt.vm index 85e6ddab..8c66d4ca 100644 --- a/enforcer-rules/src/site/apt/requireOS.apt.vm +++ b/enforcer-rules/src/site/apt/requireOS.apt.vm @@ -89,12 +89,13 @@ Require OS Version information for the current system: +---+ -mvn enforcer:display-info -... -[INFO] Maven Version: 3.8.7 -[INFO] JDK Version: 1.8.0_352 normalized as: 1.8.0-352 -[INFO] Java Vendor: Homebrew -[INFO] OS Info - Arch: x86_64, Family: mac, Name: mac os x, Version: 12.6.1 +mvn --version + +Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29) +Maven home: /usr/local/Cellar/maven/3.8.7/libexec +Java version: 1.8.0_352, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk@8/1.8.0+352/libexec/openjdk.jdk/Contents/Home/jre +Default locale: en_GB, platform encoding: UTF-8 +OS name: "mac os x", version: "12.6.1", arch: "x86_64", family: "mac" +---+ Sample Plugin Configuration: diff --git a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/DisplayInfoMojo.java b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/DisplayInfoMojo.java index eebb7fb2..9311fc21 100644 --- a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/DisplayInfoMojo.java +++ b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/DisplayInfoMojo.java @@ -29,7 +29,9 @@ * This goal displays the current platform information. * * @author Brian Fox + * @deprecated please use {@code mvn --version} */ +@Deprecated @Mojo(name = "display-info", threadSafe = true) public class DisplayInfoMojo extends AbstractMojo { diff --git a/maven-enforcer-plugin/src/site/apt/index.apt b/maven-enforcer-plugin/src/site/apt/index.apt index 1c5cf97d..c15c17bf 100644 --- a/maven-enforcer-plugin/src/site/apt/index.apt +++ b/maven-enforcer-plugin/src/site/apt/index.apt @@ -28,14 +28,12 @@ Maven Enforcer Plugin - The Loving Iron Fist of Maven\x99 The Enforcer plugin provides goals to control certain environmental constraints such as Maven version, JDK version and OS family along with many more built-in rules and user created rules. -* Goals Overview +* Goal Overview - The Enforcer plugin has two goals: + The Enforcer plugin has a goal: *{{{./enforce-mojo.html}enforcer:enforce}} executes rules for each project in a multi-project build. - *{{{./display-info-mojo.html}enforcer:display-info}} display the current information as detected by the built-in rules. - * Usage General instructions on how to use the Enforcer Plugin can be found on the {{{./usage.html}usage page}}. diff --git a/maven-enforcer-plugin/src/site/apt/usage.apt.vm b/maven-enforcer-plugin/src/site/apt/usage.apt.vm index f4a37902..5d050363 100644 --- a/maven-enforcer-plugin/src/site/apt/usage.apt.vm +++ b/maven-enforcer-plugin/src/site/apt/usage.apt.vm @@ -105,17 +105,4 @@ Usage [...] +---+ - -* The <<>> mojo - This goal is used to determine the current information as detected by the standard rules: - -+---+ - mvn enforcer:display-info - ... - [enforcer:display-info] - Maven Version: 2.0.6 - JDK Version: 1.5.0_11 normalized as: 1.5.0-11 - OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 -+---+ -