PMD 5.0 conversion of eclipse plugin: temporary conversion of PMD calls
The only remaining errors are related to the property descriptors git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6609 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -42,7 +42,6 @@ import java.io.OutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
@ -97,12 +96,12 @@ public class RuleSetsManagerImpl implements IRuleSetsManager {
|
||||
try {
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
|
||||
for (int i = 0; i < ruleSetUrls.length; i++) {
|
||||
for (String ruleSetUrl : ruleSetUrls) {
|
||||
final RuleSetFactory factory = new RuleSetFactory(); // NOPMD by Herlin on 21/06/06 23:25
|
||||
final Collection<net.sourceforge.pmd.Rule> rules = factory.createSingleRuleSet(ruleSetUrls[i]).getRules();
|
||||
final Collection<net.sourceforge.pmd.Rule> rules = factory.createRuleSet(ruleSetUrl).getRules();
|
||||
for (final net.sourceforge.pmd.Rule pmdRule: rules) {
|
||||
final Rule rule = new Rule(); // NOPMD by Herlin on 21/06/06 23:29
|
||||
rule.setRef(ruleSetUrls[i] + '/' + pmdRule.getName());
|
||||
rule.setRef(ruleSetUrl + '/' + pmdRule.getName());
|
||||
rule.setPmdRule(pmdRule);
|
||||
ruleSet.addRule(rule);
|
||||
}
|
||||
|
@ -37,10 +37,10 @@ package net.sourceforge.pmd.eclipse.runtime.cmd;
|
||||
|
||||
import name.herlin.command.AbstractProcessableCommand;
|
||||
import name.herlin.command.CommandException;
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.SourceType;
|
||||
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
@ -73,6 +73,7 @@ public abstract class AbstractDefaultCommand extends AbstractProcessableCommand
|
||||
/**
|
||||
* @return Returns the readOnly.
|
||||
*/
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return readOnly;
|
||||
}
|
||||
@ -87,6 +88,7 @@ public abstract class AbstractDefaultCommand extends AbstractProcessableCommand
|
||||
/**
|
||||
* @return Returns the description.
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -101,6 +103,7 @@ public abstract class AbstractDefaultCommand extends AbstractProcessableCommand
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@ -122,6 +125,7 @@ public abstract class AbstractDefaultCommand extends AbstractProcessableCommand
|
||||
/**
|
||||
* @return Returns the outputProperties.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasOutputProperties() {
|
||||
return outputProperties;
|
||||
}
|
||||
@ -129,6 +133,7 @@ public abstract class AbstractDefaultCommand extends AbstractProcessableCommand
|
||||
/**
|
||||
* @return Returns the readyToExecute.
|
||||
*/
|
||||
@Override
|
||||
public boolean isReadyToExecute() {
|
||||
return readyToExecute;
|
||||
}
|
||||
@ -185,11 +190,13 @@ public abstract class AbstractDefaultCommand extends AbstractProcessableCommand
|
||||
/**
|
||||
* @see name.herlin.command.AbstractProcessableCommand#execute()
|
||||
*/
|
||||
@Override
|
||||
public abstract void execute() throws CommandException;
|
||||
|
||||
/**
|
||||
* @see name.herlin.command.Command#reset()
|
||||
*/
|
||||
@Override
|
||||
public abstract void reset();
|
||||
|
||||
/**
|
||||
@ -259,19 +266,20 @@ public abstract class AbstractDefaultCommand extends AbstractProcessableCommand
|
||||
* @param project
|
||||
* @return
|
||||
*/
|
||||
protected PMD getPmdEngineForProject(final IProject project) throws CommandException {
|
||||
protected PMDEngine getPmdEngineForProject(final IProject project) throws CommandException {
|
||||
final IJavaProject javaProject = JavaCore.create(project);
|
||||
final PMD pmdEngine = new PMD();
|
||||
final PMDEngine pmdEngine = new PMDEngine();
|
||||
|
||||
if (javaProject.exists()) {
|
||||
final String compilerCompliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
|
||||
log.debug("compilerCompliance = " + compilerCompliance);
|
||||
final SourceType s = SourceType.getSourceTypeForId("java " + compilerCompliance);
|
||||
if (s != null) {
|
||||
pmdEngine.setJavaVersion(s);
|
||||
} else {
|
||||
throw new CommandException("The target JDK, " + compilerCompliance + " is not yet supported"); // TODO NLS
|
||||
|
||||
LanguageVersion languageVersion = Language.JAVA.getVersion(compilerCompliance);
|
||||
if ( languageVersion == null ) {
|
||||
throw new CommandException("The target JDK, " + compilerCompliance + " is not supported"); // TODO NLS
|
||||
}
|
||||
pmdEngine.setLanguageVersion(languageVersion);
|
||||
|
||||
final IPreferences preferences = PMDPlugin.getDefault().loadPreferences();
|
||||
if (preferences.isProjectBuildPathEnabled()) {
|
||||
pmdEngine.setClassLoader(new JavaProjectClassLoader(pmdEngine.getClassLoader(), javaProject));
|
||||
|
@ -69,7 +69,7 @@ public class BaseVisitor {
|
||||
private IProgressMonitor monitor;
|
||||
private boolean useTaskMarker = false;
|
||||
private Map<IFile, Set<MarkerInfo>> accumulator;
|
||||
private PMD pmdEngine;
|
||||
private PMDEngine pmdEngine;
|
||||
private RuleSet ruleSet;
|
||||
private int filesCount;
|
||||
private long pmdDuration;
|
||||
@ -173,7 +173,7 @@ public class BaseVisitor {
|
||||
/**
|
||||
* @return Returns the pmdEngine.
|
||||
*/
|
||||
public PMD getPmdEngine() {
|
||||
public PMDEngine getPmdEngine() {
|
||||
return this.pmdEngine;
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ public class BaseVisitor {
|
||||
* @param pmdEngine
|
||||
* The pmdEngine to set.
|
||||
*/
|
||||
public void setPmdEngine(final PMD pmdEngine) {
|
||||
public void setPmdEngine(final PMDEngine pmdEngine) {
|
||||
this.pmdEngine = pmdEngine;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,48 @@
|
||||
package net.sourceforge.pmd.eclipse.runtime.cmd;
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
import net.sourceforge.pmd.Configuration;
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.PMDException;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSets;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
|
||||
/**
|
||||
* Temporary class to handle PMD 4.2.x compatibility issues.
|
||||
*
|
||||
* This should be removed once the Configuration class is working in PMD 5.0.
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class PMDEngine {
|
||||
|
||||
private Configuration configuration = new Configuration();
|
||||
|
||||
// FIXME: PMD 5.0
|
||||
private LanguageVersion languageVersion;
|
||||
|
||||
public void setLanguageVersion(LanguageVersion languageVersion) {
|
||||
this.languageVersion = languageVersion;
|
||||
}
|
||||
|
||||
public void setClassLoader(ClassLoader classLoader) {
|
||||
configuration.setClassLoader(classLoader);
|
||||
}
|
||||
|
||||
public ClassLoader getClassLoader() {
|
||||
return configuration.getClassLoader();
|
||||
}
|
||||
|
||||
public void processFile(Reader input, RuleSet ruleSet, RuleContext context) throws PMDException {
|
||||
RuleSets set = new RuleSets();
|
||||
set.addRuleSet(ruleSet);
|
||||
|
||||
PMD pmd = new PMD();
|
||||
pmd.setConfiguration(configuration);
|
||||
pmd.processFile(input, set, context);
|
||||
}
|
||||
|
||||
}
|
@ -44,7 +44,6 @@ import java.util.Set;
|
||||
|
||||
import name.herlin.command.CommandException;
|
||||
import name.herlin.command.Timer;
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
|
||||
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
|
||||
@ -112,6 +111,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
/**
|
||||
* @see name.herlin.command.AbstractProcessableCommand#execute()
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws CommandException {
|
||||
log.info("ReviewCode command starting.");
|
||||
try {
|
||||
@ -227,6 +227,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
/**
|
||||
* @see name.herlin.command.Command#reset()
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
this.resources.clear();
|
||||
this.markers = new HashMap<IFile, Set<MarkerInfo>>();
|
||||
@ -237,6 +238,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
/**
|
||||
* @see name.herlin.command.Command#isReadyToExecute()
|
||||
*/
|
||||
@Override
|
||||
public boolean isReadyToExecute() {
|
||||
return this.resources.size() != 0 || this.resourceDelta != null;
|
||||
}
|
||||
@ -289,7 +291,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
final IProject project = resource.getProject();
|
||||
final IProjectProperties properties = PMDPlugin.getDefault().loadProjectProperties(project);
|
||||
final RuleSet ruleSet = properties.getProjectRuleSet();
|
||||
final PMD pmdEngine = getPmdEngineForProject(project);
|
||||
final PMDEngine pmdEngine = getPmdEngineForProject(project);
|
||||
setStepsCount(countResourceElement(resource));
|
||||
log.debug("Visiting resource " + resource.getName() + " : " + getStepsCount());
|
||||
|
||||
@ -328,8 +330,8 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
|
||||
final IJavaProject javaProject = JavaCore.create(project);
|
||||
final IClasspathEntry[] entries = javaProject.getRawClasspath();
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
|
||||
for (IClasspathEntry entrie : entries) {
|
||||
if (entrie.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
|
||||
|
||||
// phherlin note: this code is ugly but I don't how to do otherwise.
|
||||
// The IWorkspaceRoot getContainerLocation(IPath) always return null.
|
||||
@ -337,12 +339,12 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
// to know if the entry is a folder or a project !
|
||||
IContainer sourceContainer = null;
|
||||
try {
|
||||
sourceContainer = ResourcesPlugin.getWorkspace().getRoot().getFolder(entries[i].getPath());
|
||||
sourceContainer = ResourcesPlugin.getWorkspace().getRoot().getFolder(entrie.getPath());
|
||||
} catch (IllegalArgumentException e) {
|
||||
sourceContainer = ResourcesPlugin.getWorkspace().getRoot().getProject(entries[i].getPath().toString());
|
||||
sourceContainer = ResourcesPlugin.getWorkspace().getRoot().getProject(entrie.getPath().toString());
|
||||
}
|
||||
if (sourceContainer == null) {
|
||||
log.warn("Source container " + entries[i].getPath() + " for project " + project.getName() + " is not valid");
|
||||
log.warn("Source container " + entrie.getPath() + " for project " + project.getName() + " is not valid");
|
||||
} else {
|
||||
processResource(sourceContainer);
|
||||
}
|
||||
@ -362,7 +364,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
final IProject project = this.resourceDelta.getResource().getProject();
|
||||
final IProjectProperties properties = PMDPlugin.getDefault().loadProjectProperties(project);
|
||||
final RuleSet ruleSet = properties.getProjectRuleSet();
|
||||
final PMD pmdEngine = getPmdEngineForProject(project);
|
||||
final PMDEngine pmdEngine = getPmdEngineForProject(project);
|
||||
this.setStepsCount(countDeltaElement(this.resourceDelta));
|
||||
log.debug("Visit of resource delta : " + getStepsCount());
|
||||
|
||||
|
@ -40,11 +40,9 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import name.herlin.command.CommandException;
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.PMDException;
|
||||
import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
@ -130,7 +128,7 @@ public class ReviewResourceForRuleCommand extends AbstractDefaultCommand {
|
||||
&& file.getFileExtension().equals("java")) {
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
ruleSet.addRule(rule);
|
||||
final PMD pmdEngine = getPmdEngineForProject(project);
|
||||
final PMDEngine pmdEngine = getPmdEngineForProject(project);
|
||||
|
||||
try {
|
||||
this.context = new RuleContext();
|
||||
|
@ -22,7 +22,7 @@ public class DataflowAnomalyTableContentProvider implements IStructuredContentPr
|
||||
public Object[] getElements(Object inputElement) {
|
||||
Object[] result = new Object[0];
|
||||
if (inputElement instanceof Iterator) {
|
||||
final Iterator<DaaRuleViolation> violationsIterator = (Iterator)inputElement;
|
||||
final Iterator<DaaRuleViolation> violationsIterator = (Iterator<DaaRuleViolation>)inputElement;
|
||||
final List<DaaRuleViolation> violations = new ArrayList<DaaRuleViolation>();
|
||||
for (int count = 0; violationsIterator.hasNext() && count < MAX_ROWS; count++) {
|
||||
final DaaRuleViolation violation = violationsIterator.next();
|
||||
|
@ -7,15 +7,14 @@ import java.util.List;
|
||||
|
||||
import name.herlin.command.CommandException;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.PMDException;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.dfa.DaaRule;
|
||||
import net.sourceforge.pmd.lang.dfa.DataFlowNode;
|
||||
import net.sourceforge.pmd.lang.java.rule.controversial.DataflowAnomalyAnalysisRule;
|
||||
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
|
||||
import net.sourceforge.pmd.eclipse.runtime.cmd.ReviewResourceForRuleCommand;
|
||||
import net.sourceforge.pmd.eclipse.runtime.cmd.PMDEngine;
|
||||
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.ui.model.FileRecord;
|
||||
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
|
||||
@ -271,7 +270,7 @@ public class DataflowViewPage extends Page implements IPropertyListener, ISelect
|
||||
|
||||
// run PMD using the DFAGraphRule
|
||||
// and the Text of the Resource
|
||||
new PMD().processFile(reader, rs, ctx);
|
||||
new PMDEngine().processFile(reader, rs, ctx);
|
||||
|
||||
// the Rule then can give us the Methods
|
||||
methodList.addAll(dfaGraphRule.getMethods());
|
||||
@ -423,7 +422,7 @@ public class DataflowViewPage extends Page implements IPropertyListener, ISelect
|
||||
this.isTableRefreshed = true;
|
||||
try {
|
||||
final ReviewResourceForRuleCommand cmd = new ReviewResourceForRuleCommand();
|
||||
final DaaRule rule = new DaaRule();
|
||||
final DataflowAnomalyAnalysisRule rule = new DataflowAnomalyAnalysisRule();
|
||||
rule.setUsesDFA();
|
||||
cmd.setUserInitiated(false);
|
||||
cmd.setRule(rule);
|
||||
|
Reference in New Issue
Block a user