gnodet commented on code in PR #888:
URL: https://github.com/apache/maven/pull/888#discussion_r1037528525
##########
maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteChecker.java:
##########
@@ -18,26 +18,57 @@
*/
package org.apache.maven.plugin.internal;
+import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
-import org.apache.maven.model.profile.activation.JdkVersionProfileActivator;
import org.apache.maven.plugin.MavenPluginPrerequisitesChecker;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.aether.version.InvalidVersionSpecificationException;
+import org.eclipse.aether.version.Version;
+import org.eclipse.aether.version.VersionConstraint;
+import org.eclipse.aether.version.VersionScheme;
@Named
@Singleton
public class MavenPluginJavaPrerequisiteChecker implements
MavenPluginPrerequisitesChecker {
+ private final VersionScheme versionScheme;
+
+ @Inject
+ public MavenPluginJavaPrerequisiteChecker(final VersionScheme
versionScheme) {
+ this.versionScheme = versionScheme;
+ }
+
@Override
public void accept(PluginDescriptor pluginDescriptor) {
String requiredJavaVersion = pluginDescriptor.getRequiredJavaVersion();
if (StringUtils.isNotBlank(requiredJavaVersion)) {
String currentJavaVersion = System.getProperty("java.version");
- if
(!JdkVersionProfileActivator.isJavaVersionCompatible(requiredJavaVersion,
currentJavaVersion)) {
+ if (!matchesVersion(requiredJavaVersion, currentJavaVersion)) {
throw new IllegalStateException("Required Java version " +
requiredJavaVersion
+ " is not met by current version: " +
currentJavaVersion);
}
}
}
+
+ boolean matchesVersion(String requiredVersion, String currentVersion) {
+ VersionConstraint constraint;
+ try {
+ constraint = versionScheme.parseVersionConstraint(requiredVersion);
+ } catch (InvalidVersionSpecificationException e) {
+ throw new IllegalArgumentException(
+ "Invalid requiredJavaVersion given in plugin descriptor: "
+ e.getMessage(), e);
+ }
+ Version current;
+ try {
+ current = versionScheme.parseVersion(currentVersion);
+ } catch (InvalidVersionSpecificationException e) {
+ throw new IllegalStateException("Could not parse current Java
version: " + e.getMessage(), e);
Review Comment:
Why not ? For the record, I would argue that gives a hint to the cause
without having to read the full stack trace. Maybe even `("xxx" + e, e)` can be
useful some time...
##########
maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteChecker.java:
##########
@@ -18,26 +18,57 @@
*/
package org.apache.maven.plugin.internal;
+import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
-import org.apache.maven.model.profile.activation.JdkVersionProfileActivator;
import org.apache.maven.plugin.MavenPluginPrerequisitesChecker;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.aether.version.InvalidVersionSpecificationException;
+import org.eclipse.aether.version.Version;
+import org.eclipse.aether.version.VersionConstraint;
+import org.eclipse.aether.version.VersionScheme;
@Named
@Singleton
public class MavenPluginJavaPrerequisiteChecker implements
MavenPluginPrerequisitesChecker {
+ private final VersionScheme versionScheme;
+
+ @Inject
+ public MavenPluginJavaPrerequisiteChecker(final VersionScheme
versionScheme) {
+ this.versionScheme = versionScheme;
+ }
+
@Override
public void accept(PluginDescriptor pluginDescriptor) {
String requiredJavaVersion = pluginDescriptor.getRequiredJavaVersion();
if (StringUtils.isNotBlank(requiredJavaVersion)) {
String currentJavaVersion = System.getProperty("java.version");
- if
(!JdkVersionProfileActivator.isJavaVersionCompatible(requiredJavaVersion,
currentJavaVersion)) {
+ if (!matchesVersion(requiredJavaVersion, currentJavaVersion)) {
throw new IllegalStateException("Required Java version " +
requiredJavaVersion
+ " is not met by current version: " +
currentJavaVersion);
}
}
}
+
+ boolean matchesVersion(String requiredVersion, String currentVersion) {
+ VersionConstraint constraint;
+ try {
+ constraint = versionScheme.parseVersionConstraint(requiredVersion);
+ } catch (InvalidVersionSpecificationException e) {
+ throw new IllegalArgumentException(
+ "Invalid requiredJavaVersion given in plugin descriptor: "
+ e.getMessage(), e);
+ }
+ Version current;
+ try {
+ current = versionScheme.parseVersion(currentVersion);
+ } catch (InvalidVersionSpecificationException e) {
+ throw new IllegalStateException("Could not parse current Java
version: " + e.getMessage(), e);
Review Comment:
Why not ? For the record, I would argue that it gives a hint to the cause
without having to read the full stack trace. Maybe even `("xxx" + e, e)` can be
useful some time...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]