pmd: reintroducing check whether multi threading is support (bugfix for 3565001)

* created SystemUtils to check for multi-threading permission
Revert "pmd: Remove hack related to multithreading in jdk5 with Eclipse - no longer relevant today"

This reverts commit 720bb3d3b41e2590d6f0e4b8542244192a56e022.
This commit is contained in:
Andreas Dangel
2012-10-06 20:58:13 +02:00
parent 28b37d6767
commit 60c2af73fd
3 changed files with 44 additions and 1 deletions

View File

@ -39,6 +39,7 @@ Fixed bug 3496028: pmd-4.2.6: MissingBreakInSwitch fails to report violation
Fixed bug 3484404: Invalid NPath calculation in return statement. Thanks to Prabhjot Singh for the patch.
Fixed bug 3560464: c/c++ \ as a continuation character not supported
Fixed bug 3574133: False+ : SingularField
Fixed bug 3565001: Regression of Crash in PMDTask due to multithreading (Eclipse and Java 1.5)
Improved JSP parser to be less strict with not valid XML documents (like HTML). Thanks to Victor Bucutea.
Fixed bgastviewer not working. Thanks to Victor Bucutea.

View File

@ -33,6 +33,7 @@ import net.sourceforge.pmd.processor.MultiThreadProcessor;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.util.FileUtil;
import net.sourceforge.pmd.util.IOUtil;
import net.sourceforge.pmd.util.SystemUtils;
import net.sourceforge.pmd.util.datasource.DataSource;
import net.sourceforge.pmd.util.log.ConsoleLogHandler;
import net.sourceforge.pmd.util.log.ScopedLogHandlersManager;
@ -262,7 +263,7 @@ public class PMD {
* disabled if threadCount is not positive, e.g. using the "-threads 0"
* command line option.
*/
if (configuration.getThreads() > 0) {
if (SystemUtils.MT_SUPPORTED && configuration.getThreads() > 0) {
new MultiThreadProcessor(configuration).processFiles(ruleSetFactory, files, ctx, renderers);
} else {
new MonoThreadProcessor(configuration).processFiles(ruleSetFactory, files, ctx, renderers);

View File

@ -0,0 +1,41 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public final class SystemUtils {
private SystemUtils() {
// this is a utility class and cannot be instantiated
}
/**
* Do we have proper permissions to use multithreading?
*/
public static final boolean MT_SUPPORTED;
static {
boolean error = false;
try {
/*
* ant task ran from Eclipse with jdk 1.5.0 raises an AccessControlException
* when shutdown is called. Standalone pmd or ant from command line are fine.
*
* With jdk 1.6.0, ant task from Eclipse also works.
*
* Bugs related to this hack:
* 3565001
* 1701832
*/
ExecutorService executor = Executors.newFixedThreadPool(1);
executor.shutdown();
} catch (RuntimeException e) {
error = true;
System.err.println("Disabling multithreading - consider to upgrade to java 1.6");
System.err.println("See also: http://sourceforge.net/tracker/?func=detail&atid=479921&aid=1701832&group_id=56262");
}
MT_SUPPORTED = !error;
}
}