Skip to content

Commit

Permalink
[MENFORCER-460] Deprecate display-info mojo
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Jan 19, 2023
1 parent c69f513 commit 8cdd8d0
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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()
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
19 changes: 7 additions & 12 deletions enforcer-rules/src/site/apt/requireJavaVersion.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Require Java Version

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

* <<display>> - flag to display the normalized JDK version.


For JDK 1.8 you can also use simple <<<8>>> as <version> - it will be internally changed to <<<1.8>>>

[]
Expand All @@ -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 <<display>> option.

Sample Plugin Configuration:

+---+
Expand Down
13 changes: 7 additions & 6 deletions enforcer-rules/src/site/apt/requireOS.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
* This goal displays the current platform information.
*
* @author <a href="mailto:[email protected]">Brian Fox</a>
* @deprecated please use {@code mvn --version}
*/
@Deprecated
@Mojo(name = "display-info", threadSafe = true)
public class DisplayInfoMojo extends AbstractMojo {

Expand Down
6 changes: 2 additions & 4 deletions maven-enforcer-plugin/src/site/apt/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -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}}.
Expand Down
13 changes: 0 additions & 13 deletions maven-enforcer-plugin/src/site/apt/usage.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,4 @@ Usage
[...]
</project>
+---+

* The <<<enforcer:display-info>>> 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
+---+

0 comments on commit 8cdd8d0

Please sign in to comment.