You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2024/02/26 06:11:24 UTC

(maven-plugin-tools) branch MPLUGIN-510 created (now 0a8cf94a)

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a change to branch MPLUGIN-510
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git


      at 0a8cf94a [MPLUGIN-510] move requirement detection code

This branch includes the following new commits:

     new 0a8cf94a [MPLUGIN-510] move requirement detection code

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-plugin-tools) 01/01: [MPLUGIN-510] move requirement detection code

Posted by hb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch MPLUGIN-510
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git

commit 0a8cf94a968e0790f84dd29775a8fa928276d01b
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Mon Feb 26 07:11:09 2024 +0100

    [MPLUGIN-510] move requirement detection code
---
 .../plugin/report/PluginOverviewRenderer.java      |  99 +------------------
 .../plugin/plugin/report/RequirementsHistory.java  | 106 +++++++++++++++++++++
 2 files changed, 108 insertions(+), 97 deletions(-)

diff --git a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginOverviewRenderer.java b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginOverviewRenderer.java
index a601bd50..376c420b 100644
--- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginOverviewRenderer.java
+++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginOverviewRenderer.java
@@ -185,13 +185,13 @@ class PluginOverviewRenderer extends AbstractPluginReportRenderer {
 
         startTable();
 
-        String maven = discoverMavenRequirement(project, pluginDescriptor);
+        String maven = RequirementsHistory.discoverMavenRequirement(project, pluginDescriptor);
         sink.tableRow();
         tableCell(getI18nString("systemrequirements.maven"));
         tableCell((maven != null ? maven : getI18nString("systemrequirements.nominimum")));
         sink.tableRow_();
 
-        String jdk = discoverJdkRequirement(project, pluginDescriptor);
+        String jdk = RequirementsHistory.discoverJdkRequirement(project, pluginDescriptor);
         sink.tableRow();
         tableCell(getI18nString("systemrequirements.jdk"));
         tableCell((jdk != null ? jdk : getI18nString("systemrequirements.nominimum")));
@@ -320,101 +320,6 @@ class PluginOverviewRenderer extends AbstractPluginReportRenderer {
         endSection();
     }
 
-    /**
-     * Tries to determine the Maven requirement from either the plugin descriptor or (if not set) from the
-     * Maven prerequisites element in the POM.
-     *
-     * @param project      not null
-     * @param pluginDescriptor the plugin descriptor (not null)
-     * @return the Maven version or null if not specified
-     */
-    private static String discoverMavenRequirement(MavenProject project, PluginDescriptor pluginDescriptor) {
-        if (StringUtils.isNotBlank(pluginDescriptor.getRequiredMavenVersion())) {
-            return pluginDescriptor.getRequiredMavenVersion();
-        }
-        return Optional.ofNullable(project.getPrerequisites())
-                .map(Prerequisites::getMaven)
-                .orElse(null);
-    }
-
-    /**
-     * Tries to determine the JDK requirement from the following sources (until one is found)
-     * <ol>
-     * <li>use JDK requirement from plugin descriptor</li>
-     * <li>use {@code release} configuration of {@code org.apache.maven.plugins:maven-compiler-plugin}</li>
-     * <li>use {@code maven.compiler.release<} property</li>
-     * <li>use {@code target} configuration of {@code org.apache.maven.plugins:maven-compiler-plugin}</li>
-     * <li>use {@code maven.compiler.target} property</li>
-     * </ol>
-     *
-     * @param project      not null
-     * @param pluginDescriptor the plugin descriptor (not null)
-     * @return the JDK version
-     */
-    private static String discoverJdkRequirement(MavenProject project, PluginDescriptor pluginDescriptor) {
-        String jdk = null;
-        if (pluginDescriptor instanceof ExtendedPluginDescriptor) {
-            ExtendedPluginDescriptor extPluginDescriptor = (ExtendedPluginDescriptor) pluginDescriptor;
-            jdk = extPluginDescriptor.getRequiredJavaVersion();
-        }
-        if (jdk != null) {
-            return jdk;
-        }
-        Plugin compiler = getCompilerPlugin(project.getBuild().getPluginsAsMap());
-        if (compiler == null) {
-            compiler = getCompilerPlugin(project.getPluginManagement().getPluginsAsMap());
-        }
-
-        jdk = getPluginParameter(compiler, "release");
-        if (jdk != null) {
-            return jdk;
-        }
-
-        jdk = project.getProperties().getProperty("maven.compiler.release");
-        if (jdk != null) {
-            return jdk;
-        }
-
-        jdk = getPluginParameter(compiler, "target");
-        if (jdk != null) {
-            return jdk;
-        }
-
-        // default value
-        jdk = project.getProperties().getProperty("maven.compiler.target");
-        if (jdk != null) {
-            return jdk;
-        }
-
-        String version = (compiler == null) ? null : compiler.getVersion();
-
-        if (version != null) {
-            return "Default target for maven-compiler-plugin version " + version;
-        }
-
-        return null;
-    }
-
-    private static Plugin getCompilerPlugin(Map<String, Plugin> pluginsAsMap) {
-        return pluginsAsMap.get("org.apache.maven.plugins:maven-compiler-plugin");
-    }
-
-    private static String getPluginParameter(Plugin plugin, String parameter) {
-        if (plugin != null) {
-            Xpp3Dom pluginConf = (Xpp3Dom) plugin.getConfiguration();
-
-            if (pluginConf != null) {
-                Xpp3Dom target = pluginConf.getChild(parameter);
-
-                if (target != null) {
-                    return target.getValue();
-                }
-            }
-        }
-
-        return null;
-    }
-
     @Override
     protected String getI18nSection() {
         return "plugin";
diff --git a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/RequirementsHistory.java b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/RequirementsHistory.java
index 4e08a6a6..ce8dae01 100644
--- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/RequirementsHistory.java
+++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/RequirementsHistory.java
@@ -18,6 +18,17 @@
  */
 package org.apache.maven.plugin.plugin.report;
 
+import org.apache.commons.lang3.StringUtils;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.Prerequisites;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.tools.plugin.ExtendedPluginDescriptor;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+import java.util.Map;
+import java.util.Optional;
+
 /**
  * Plugin requirements history.
  *
@@ -60,4 +71,99 @@ public class RequirementsHistory {
         sb.append('}');
         return sb.toString();
     }
+
+    /**
+     * Tries to determine the Maven requirement from either the plugin descriptor or (if not set) from the
+     * Maven prerequisites element in the POM.
+     *
+     * @param project      not null
+     * @param pluginDescriptor the plugin descriptor (not null)
+     * @return the Maven version or null if not specified
+     */
+    public static String discoverMavenRequirement(MavenProject project, PluginDescriptor pluginDescriptor) {
+        if (StringUtils.isNotBlank(pluginDescriptor.getRequiredMavenVersion())) {
+            return pluginDescriptor.getRequiredMavenVersion();
+        }
+        return Optional.ofNullable(project.getPrerequisites())
+                .map(Prerequisites::getMaven)
+                .orElse(null);
+    }
+
+    /**
+     * Tries to determine the JDK requirement from the following sources (until one is found)
+     * <ol>
+     * <li>use JDK requirement from plugin descriptor</li>
+     * <li>use {@code release} configuration of {@code org.apache.maven.plugins:maven-compiler-plugin}</li>
+     * <li>use {@code maven.compiler.release<} property</li>
+     * <li>use {@code target} configuration of {@code org.apache.maven.plugins:maven-compiler-plugin}</li>
+     * <li>use {@code maven.compiler.target} property</li>
+     * </ol>
+     *
+     * @param project      not null
+     * @param pluginDescriptor the plugin descriptor (not null)
+     * @return the JDK version
+     */
+    public static String discoverJdkRequirement(MavenProject project, PluginDescriptor pluginDescriptor) {
+        String jdk = null;
+        if (pluginDescriptor instanceof ExtendedPluginDescriptor) {
+            ExtendedPluginDescriptor extPluginDescriptor = (ExtendedPluginDescriptor) pluginDescriptor;
+            jdk = extPluginDescriptor.getRequiredJavaVersion();
+        }
+        if (jdk != null) {
+            return jdk;
+        }
+        Plugin compiler = getCompilerPlugin(project.getBuild().getPluginsAsMap());
+        if (compiler == null) {
+            compiler = getCompilerPlugin(project.getPluginManagement().getPluginsAsMap());
+        }
+
+        jdk = getPluginParameter(compiler, "release");
+        if (jdk != null) {
+            return jdk;
+        }
+
+        jdk = project.getProperties().getProperty("maven.compiler.release");
+        if (jdk != null) {
+            return jdk;
+        }
+
+        jdk = getPluginParameter(compiler, "target");
+        if (jdk != null) {
+            return jdk;
+        }
+
+        // default value
+        jdk = project.getProperties().getProperty("maven.compiler.target");
+        if (jdk != null) {
+            return jdk;
+        }
+
+        String version = (compiler == null) ? null : compiler.getVersion();
+
+        if (version != null) {
+            return "Default target for maven-compiler-plugin version " + version;
+        }
+
+        return null;
+    }
+
+    private static Plugin getCompilerPlugin(Map<String, Plugin> pluginsAsMap) {
+        return pluginsAsMap.get("org.apache.maven.plugins:maven-compiler-plugin");
+    }
+
+    private static String getPluginParameter(Plugin plugin, String parameter) {
+        if (plugin != null) {
+            Xpp3Dom pluginConf = (Xpp3Dom) plugin.getConfiguration();
+
+            if (pluginConf != null) {
+                Xpp3Dom target = pluginConf.getChild(parameter);
+
+                if (target != null) {
+                    return target.getValue();
+                }
+            }
+        }
+
+        return null;
+    }
 }