slawekjaranowski commented on code in PR #700:
URL: https://github.com/apache/maven-pmd-plugin/pull/700#discussion_r3294151206


##########
src/main/java/org/apache/maven/plugins/pmd/PmdReport.java:
##########
@@ -371,11 +386,41 @@ private void executePmd() throws MavenReportException {
         request.setIncludeXmlInReports(includeXmlInReports);
         
request.setReportOutputDirectory(getReportOutputDirectory().getAbsolutePath());
         request.setJdkToolchain(getJdkToolchain());
+        if (executionThreads != null) {
+            request.setExecutionThreads(numThreadsConverter(executionThreads));
+        }
 
         getLog().info("PMD version: " + AbstractPmdReport.getPmdVersion());
         pmdResult = serviceExecutor.execute(request);
     }
 
+    /**
+     * Essentially per 
org.apache.maven.cli.MavenCli.calculateDegreeOfConcurrency(String).
+     * @return the (integer) number of threads, where a suffix of C means that 
a multiple of available cores is calculated.
+     */
+    private int numThreadsConverter(String executionThreadsString) {
+        boolean isCoreMultiplied = executionThreadsString.endsWith("C");
+        if (isCoreMultiplied) {
+            executionThreadsString =
+                    executionThreadsString.substring(0, 
executionThreadsString.length() - 1); // remove the C
+            try {
+                float f = Float.parseFloat(executionThreadsString);
+                if (f <= 0.0f) {
+                    throw new IllegalArgumentException(
+                            "Invalid threads core multiplier value: '" + f + 
"C'. Value must be positive.");
+                }
+                return (int) (f * Runtime.getRuntime().availableProcessors());

Review Comment:
   can be a `0` (zero) after case for small value?



-- 
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]

Reply via email to