use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties in project pmd-eclipse-plugin by pmd.
the class DetectCutAndPasteCmd method findCandidateFiles.
/**
* Finds all files in a project based on a language. Uses internally the
* CPDVisitor.
*
* @return List of files
* @throws PropertiesException
* @throws CoreException
*/
private List<File> findCandidateFiles() throws PropertiesException, CoreException {
final IProjectProperties properties = projectProperties();
final CPDVisitor visitor = new CPDVisitor();
visitor.setWorkingSet(properties.getProjectWorkingSet());
visitor.setIncludeDerivedFiles(properties.isIncludeDerivedFiles());
visitor.setLanguage(language);
visitor.setFiles(new ArrayList<File>());
visitProjectResourcesWith(visitor);
return visitor.getFiles();
}
use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties in project pmd-eclipse-plugin by pmd.
the class ReviewCmdTest method setUp.
/**
* @see junit.framework.TestCase#setUp()
*/
@Before
public void setUp() throws Exception {
// 1. Create a Java project
this.testProject = EclipseUtils.createJavaProject("PMDTestProject");
Assert.assertTrue("A test project cannot be created; the tests cannot be performed.", this.testProject != null && this.testProject.exists() && this.testProject.isAccessible());
// 2. Create a test source file inside that project
final IFile testFile = EclipseUtils.createTestSourceFile(this.testProject);
final InputStream is = EclipseUtils.getResourceStream(this.testProject, "/src/Test.java");
Assert.assertNotNull("Cannot find the test source file", is);
is.close();
// 3. Enable PMD for the test project
IProjectProperties properties = PMDPlugin.getDefault().getPropertiesManager().loadProjectProperties(testProject);
properties.setPmdEnabled(true);
}
use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties in project pmd-eclipse-plugin by pmd.
the class ReviewCodeCmd method processResource.
/**
* Review a single resource
*/
private void processResource(IResource resource) throws CommandException {
try {
final IProject project = resource.getProject();
final IProjectProperties properties = getProjectProperties(project);
if (!runAlways && !properties.isPmdEnabled()) {
return;
}
// properties.getProjectRuleSet();
final RuleSet ruleSet = rulesetFrom(resource);
// final PMDEngine pmdEngine = getPmdEngineForProject(project);
int targetCount = 0;
if (resource.exists()) {
targetCount = countResourceElement(resource);
}
// Could add a property that lets us set the max number to analyze
if (properties.isFullBuildEnabled() || isUserInitiated() || targetCount <= MAXIMUM_RESOURCE_COUNT) {
setStepCount(targetCount);
LOG.debug("Visiting resource " + resource.getName() + " : " + getStepCount());
if (resource.exists()) {
final ResourceVisitor visitor = new ResourceVisitor();
visitor.setMonitor(getMonitor());
visitor.setRuleSet(ruleSet);
// visitor.setPmdEngine(pmdEngine);
visitor.setAccumulator(markersByFile);
visitor.setUseTaskMarker(taskMarker);
visitor.setProjectProperties(properties);
resource.accept(visitor);
ruleCount = ruleSet.getRules().size();
fileCount += visitor.getProcessedFilesCount();
pmdDuration += visitor.getActualPmdDuration();
} else {
LOG.debug("Skipping resource " + resource.getName() + " because it doesn't exist.");
}
} else {
String message = "Skipping resource " + resource.getName() + " because of fullBuildEnabled flag and " + "targetCount is " + targetCount + ". This is more than " + MAXIMUM_RESOURCE_COUNT + "." + " If you want to execute PMD, please check \"Full build enabled\" in the project settings";
PMDPlugin.getDefault().logInformation(message);
}
// TODO - temp fix? BR
worked(1);
} catch (PropertiesException e) {
throw new CommandException(e);
} catch (CoreException e) {
throw new CommandException(e);
}
}
use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties in project pmd-eclipse-plugin by pmd.
the class ReviewCodeCmd method rulesetFromResourceDelta.
private RuleSet rulesetFromResourceDelta() throws PropertiesException, CommandException {
IResource resource = resourceDelta.getResource();
final IProject project = resource.getProject();
final IProjectProperties properties = getProjectProperties(project);
// properties.getProjectRuleSet();
return filteredRuleSet(properties);
}
use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties in project pmd-eclipse-plugin by pmd.
the class ReviewCodeCmd method processResourceDelta.
/**
* Review a resource delta
*/
private void processResourceDelta() throws CommandException {
try {
IResource resource = resourceDelta.getResource();
final IProject project = resource.getProject();
final IProjectProperties properties = getProjectProperties(project);
// properties.getProjectRuleSet();
RuleSet ruleSet = rulesetFromResourceDelta();
// PMDEngine pmdEngine = getPmdEngineForProject(project);
int targetCount = countDeltaElement(resourceDelta);
// Could add a property that lets us set the max number to analyze
if (properties.isFullBuildEnabled() || isUserInitiated() || targetCount <= MAXIMUM_RESOURCE_COUNT) {
setStepCount(targetCount);
LOG.debug("Visiting delta of resource " + resource.getName() + " : " + getStepCount());
DeltaVisitor visitor = new DeltaVisitor();
visitor.setMonitor(getMonitor());
visitor.setRuleSet(ruleSet);
// visitor.setPmdEngine(pmdEngine);
visitor.setAccumulator(markersByFile);
visitor.setUseTaskMarker(taskMarker);
visitor.setProjectProperties(properties);
resourceDelta.accept(visitor);
ruleCount = ruleSet.getRules().size();
fileCount += visitor.getProcessedFilesCount();
pmdDuration += visitor.getActualPmdDuration();
} else {
String message = "Skipping resourceDelta " + resource.getName() + " because of fullBuildEnabled flag and " + "targetCount is " + targetCount + ". This is more than " + MAXIMUM_RESOURCE_COUNT + "." + " If you want to execute PMD, please check \"Full build enabled\" in the project settings";
PMDPlugin.getDefault().logInformation(message);
LOG.debug(message);
}
} catch (PropertiesException e) {
throw new CommandException(e);
} catch (CoreException e) {
throw new CommandException(e);
}
}
Aggregations