use of name.herlin.command.Timer in project pmd-eclipse-plugin by pmd.
the class JobCommandProcessor method processCommand.
/**
* @see name.herlin.command.CommandProcessor#processCommand(name.herlin.command.AbstractProcessableCommand)
*/
public void processCommand(final AbstractProcessableCommand aCommand) throws CommandException {
LOG.debug("Begining job command " + aCommand.getName());
if (!aCommand.isReadyToExecute()) {
throw new UnsetInputPropertiesException();
}
final Job job = new Job(aCommand.getName()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
if (aCommand instanceof AbstractDefaultCommand) {
((AbstractDefaultCommand) aCommand).setMonitor(monitor);
}
Timer timer = new Timer();
aCommand.execute();
timer.stop();
PMDPlugin.getDefault().logInformation("Command " + aCommand.getName() + " excecuted in " + timer.getDuration() + "ms");
} catch (CommandException e) {
PMDPlugin.getDefault().logError("Error executing command " + aCommand.getName(), e);
}
synchronized (outstanding) {
count.decrementAndGet();
Job job = outstanding.poll();
if (job != null) {
job.schedule();
}
}
return Status.OK_STATUS;
}
};
if (aCommand instanceof AbstractDefaultCommand) {
job.setUser(((AbstractDefaultCommand) aCommand).isUserInitiated());
}
synchronized (outstanding) {
if (count.incrementAndGet() > 10) {
// too many already running, put in a queue to run later
outstanding.add(job);
} else {
job.schedule();
}
}
this.addJob(aCommand, job);
LOG.debug("Ending job command " + aCommand.getName());
}
use of name.herlin.command.Timer in project pmd-eclipse-plugin by pmd.
the class ReviewCodeCmd method applyMarkers.
/**
* Apply PMD markers after the review
*/
private void applyMarkers() {
LOG.info("Processing marker directives");
int violationCount = 0;
final Timer timer = new Timer();
// for logging
String currentFile = "";
beginTask("PMD Applying markers", markersByFile.size());
try {
for (IFile file : markersByFile.keySet()) {
if (isCanceled()) {
break;
}
currentFile = file.getName();
Set<MarkerInfo2> markerInfoSet = markersByFile.get(file);
for (MarkerInfo2 markerInfo : markerInfoSet) {
markerInfo.addAsMarkerTo(file);
violationCount++;
}
worked(1);
}
} catch (CoreException e) {
// TODO: NLS
LOG.warn("CoreException when setting marker for file " + currentFile + " : " + e.getMessage());
} finally {
timer.stop();
int count = markersByFile.size();
logInfo("" + violationCount + " markers applied on " + count + " files in " + timer.getDuration() + "ms.");
LOG.info("End of processing marker directives. " + violationCount + " violations for " + count + " files.");
}
}
use of name.herlin.command.Timer in project pmd-eclipse-plugin by pmd.
the class BaseVisitor method reviewResource.
/**
* Run PMD against a resource
*
* @param resource
* the resource to process
*/
protected final void reviewResource(IResource resource) {
IFile file = (IFile) resource.getAdapter(IFile.class);
if (file == null || file.getFileExtension() == null) {
return;
}
Reader input = null;
try {
boolean included = isIncluded(file);
LOG.debug("Derived files included: " + projectProperties.isIncludeDerivedFiles());
LOG.debug("file " + file.getName() + " is derived: " + file.isDerived());
LOG.debug("file checked: " + included);
prepareMarkerAccumulator(file);
LanguageVersionDiscoverer languageDiscoverer = new LanguageVersionDiscoverer();
LanguageVersion languageVersion = languageDiscoverer.getDefaultLanguageVersionForFile(file.getName());
// in case it is java, select the correct java version
if (languageVersion != null && languageVersion.getLanguage() == LanguageRegistry.getLanguage(JavaLanguageModule.NAME)) {
languageVersion = PMDPlugin.javaVersionFor(file.getProject());
}
if (languageVersion != null) {
configuration().setDefaultLanguageVersion(languageVersion);
}
LOG.debug("discovered language: " + languageVersion);
PMDPlugin.setJavaClassLoader(configuration(), resource.getProject());
final File sourceCodeFile = file.getRawLocation().toFile();
if (included && getRuleSet().applies(sourceCodeFile) && isFileInWorkingSet(file) && languageVersion != null) {
subTask("PMD checking: " + file.getName());
Timer timer = new Timer();
RuleContext context = PMD.newRuleContext(file.getName(), sourceCodeFile);
context.setLanguageVersion(languageVersion);
input = new InputStreamReader(file.getContents(), file.getCharset());
// getPmdEngine().processFile(input, getRuleSet(), context);
// getPmdEngine().processFile(sourceCodeFile, getRuleSet(),
// context);
DataSource dataSource = new ReaderDataSource(input, file.getName());
RuleSetFactory ruleSetFactory = new RuleSetFactory() {
@Override
public synchronized RuleSets createRuleSets(String referenceString) throws RuleSetNotFoundException {
return new RuleSets(getRuleSet());
}
};
// need to disable multi threading, as the ruleset is
// not recreated and shared between threads...
// but as we anyway have only one file to process, it won't hurt
// here.
configuration().setThreads(0);
LOG.debug("PMD running on file " + file.getName());
final Report collectingReport = new Report();
Renderer collectingRenderer = new AbstractRenderer("collectingRenderer", "Renderer that collect violations") {
@Override
public void startFileAnalysis(DataSource dataSource) {
// TODO Auto-generated method stub
}
@Override
public void start() throws IOException {
// TODO Auto-generated method stub
}
@Override
public void renderFileReport(Report report) throws IOException {
for (RuleViolation v : report) {
collectingReport.addRuleViolation(v);
}
for (Iterator<ProcessingError> it = report.errors(); it.hasNext(); ) {
collectingReport.addError(it.next());
}
for (Iterator<ConfigurationError> it = report.configErrors(); it.hasNext(); ) {
collectingReport.addConfigError(it.next());
}
}
@Override
public void end() throws IOException {
// TODO Auto-generated method stub
}
@Override
public String defaultFileExtension() {
// TODO Auto-generated method stub
return null;
}
};
// PMD.processFiles(configuration(), ruleSetFactory,
// Arrays.asList(dataSource), context,
// Arrays.asList(collectingRenderer));
new MonoThreadProcessor(configuration()).processFiles(ruleSetFactory, Arrays.asList(dataSource), context, Arrays.asList(collectingRenderer));
LOG.debug("PMD run finished.");
timer.stop();
pmdDuration += timer.getDuration();
LOG.debug("PMD found " + collectingReport.size() + " violations for file " + file.getName());
if (collectingReport.hasConfigErrors()) {
StringBuilder message = new StringBuilder("There were configuration errors!\n");
Iterator<ConfigurationError> errors = collectingReport.configErrors();
while (errors.hasNext()) {
ConfigurationError error = errors.next();
message.append(error.rule().getName()).append(": ").append(error.issue()).append('\n');
}
PMDPlugin.getDefault().logWarn(message.toString());
LOG.warn(message);
}
if (collectingReport.hasErrors()) {
StringBuilder message = new StringBuilder("There were processing errors!\n");
Iterator<ProcessingError> errors = collectingReport.errors();
while (errors.hasNext()) {
ProcessingError error = errors.next();
message.append(error.getFile()).append(": ").append(error.getMsg()).append(' ').append(error.getDetail()).append("\n");
}
PMDPlugin.getDefault().logWarn(message.toString());
throw new PMDException(message.toString());
}
updateMarkers(file, collectingReport.iterator(), isUseTaskMarker());
worked(1);
fileCount++;
} else {
LOG.debug("The file " + file.getName() + " is not in the working set");
}
} catch (CoreException e) {
// TODO: complete message
LOG.error("Core exception visiting " + file.getName(), e);
} catch (PMDException e) {
// TODO: complete message
LOG.error("PMD exception visiting " + file.getName(), e);
} catch (IOException e) {
// TODO: complete message
LOG.error("IO exception visiting " + file.getName(), e);
} catch (PropertiesException e) {
// TODO: complete message
LOG.error("Properties exception visiting " + file.getName(), e);
} catch (IllegalArgumentException e) {
LOG.error("Illegal argument", e);
} finally {
IOUtil.closeQuietly(input);
}
}
Aggregations