forked from phoedos/pmd
@@ -28,6 +28,8 @@ This is a bug fixing release.
|
||||
|
||||
### Fixed Issues
|
||||
|
||||
* all
|
||||
* [#1018](https://github.com/pmd/pmd/issues/1018): \[java] Performance degradation of 250% between 6.1.0 and 6.2.0
|
||||
* java
|
||||
* [#1077](https://github.com/pmd/pmd/issues/1077): \[java] Analyzing enum with lambda passed in constructor fails with "The enclosing scope must exist."
|
||||
* java-bestpractices
|
||||
|
||||
@@ -12,8 +12,6 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -271,8 +269,8 @@ public class PMDTaskImpl {
|
||||
}
|
||||
|
||||
public void execute() throws BuildException {
|
||||
final Handler antLogHandler = new AntLogHandler(project);
|
||||
final ScopedLogHandlersManager logManager = new ScopedLogHandlersManager(Level.FINEST, antLogHandler);
|
||||
final AntLogHandler antLogHandler = new AntLogHandler(project);
|
||||
final ScopedLogHandlersManager logManager = new ScopedLogHandlersManager(antLogHandler.getAntLogLevel(), antLogHandler);
|
||||
try {
|
||||
doTask();
|
||||
} finally {
|
||||
|
||||
@@ -6,12 +6,17 @@ package net.sourceforge.pmd.util.log;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
import org.apache.tools.ant.BuildListener;
|
||||
import org.apache.tools.ant.DefaultLogger;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.XmlLogger;
|
||||
import org.apache.tools.ant.taskdefs.RecorderEntry;
|
||||
|
||||
/**
|
||||
* AntLogHandler sends log messages to an Ant Task, so the regular Ant logging
|
||||
@@ -23,10 +28,43 @@ public class AntLogHandler extends Handler {
|
||||
private Project project;
|
||||
|
||||
private static final Formatter FORMATTER = new PmdLogFormatter();
|
||||
private static final Level[] LOG_LEVELS = {
|
||||
Level.SEVERE, Level.WARNING, Level.INFO, Level.CONFIG, Level.FINEST,
|
||||
};
|
||||
|
||||
public AntLogHandler(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public Level getAntLogLevel() {
|
||||
for (final BuildListener l : project.getBuildListeners()) {
|
||||
Field declaredField = null;
|
||||
try {
|
||||
if (l instanceof DefaultLogger) {
|
||||
declaredField = DefaultLogger.class.getDeclaredField("msgOutputLevel");
|
||||
} else if (l instanceof XmlLogger) {
|
||||
declaredField = XmlLogger.class.getDeclaredField("msgOutputLevel");
|
||||
} else if (l instanceof RecorderEntry) {
|
||||
declaredField = RecorderEntry.class.getDeclaredField("loglevel");
|
||||
} else {
|
||||
try {
|
||||
declaredField = l.getClass().getDeclaredField("logLevel");
|
||||
} catch (final NoSuchFieldException e) {
|
||||
project.log("Unsupported build listener: " + l.getClass(), Project.MSG_WARN);
|
||||
}
|
||||
}
|
||||
|
||||
if (declaredField != null) {
|
||||
declaredField.setAccessible(true);
|
||||
return LOG_LEVELS[declaredField.getInt(l)];
|
||||
}
|
||||
} catch (final NoSuchFieldException | IllegalArgumentException | IllegalAccessException ignored) {
|
||||
// Just ignore it
|
||||
}
|
||||
}
|
||||
|
||||
return Level.FINEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord logRecord) {
|
||||
|
||||
@@ -1321,14 +1321,11 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter {
|
||||
try {
|
||||
return pmdClassLoader.loadClass(fullClassName);
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
// ignored
|
||||
} catch (LinkageError e) {
|
||||
if (LOG.isLoggable(Level.FINE)) {
|
||||
LOG.log(Level.FINE, "Tried to load class " + fullClassName + " from on demand import, "
|
||||
+ "which apparently doesn't exist.", ignored);
|
||||
}
|
||||
} catch (LinkageError ignored) {
|
||||
if (LOG.isLoggable(Level.FINE)) {
|
||||
LOG.log(Level.FINE, "Tried to load class " + fullClassName + " from on demand import, "
|
||||
+ "which apparently doesn't exist.", ignored);
|
||||
+ "with an incomplete classpath.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user