Skip to content

Commit 48fec66

Browse files
committed
Merge branch 'pr-55'
2 parents 0823f58 + f2290e5 commit 48fec66

File tree

5 files changed

+55
-16
lines changed

5 files changed

+55
-16
lines changed

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public Color colorFor(RGB rgb) {
138138
return color;
139139
}
140140

141+
@Deprecated // use IProjectProperties#getAuxclasspath() instead
141142
public static void setJavaClassLoader(PMDConfiguration config, IProject project) {
142143

143144
IPreferences preferences = getDefault().loadPreferences();

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ protected final void reviewResource(IResource resource) {
288288
}
289289
LOG.debug("discovered language: " + languageVersion);
290290

291-
PMDPlugin.setJavaClassLoader(configuration(), resource.getProject());
291+
if (PMDPlugin.getDefault().loadPreferences().isProjectBuildPathEnabled()) {
292+
configuration().setClassLoader(projectProperties.getAuxClasspath());
293+
}
292294

293295
final File sourceCodeFile = file.getRawLocation().toFile();
294296
if (included && getRuleSet().applies(sourceCodeFile) && isFileInWorkingSet(file)

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCodeCmd.java

+21-15
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import java.util.ArrayList;
4040
import java.util.Collection;
4141
import java.util.HashMap;
42-
import java.util.Iterator;
42+
import java.util.HashSet;
4343
import java.util.List;
4444
import java.util.Map;
4545
import java.util.Set;
@@ -96,7 +96,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
9696

9797
private static final Logger LOG = Logger.getLogger(ReviewCodeCmd.class);
9898

99-
private final List<ISchedulingRule> resources = new ArrayList<ISchedulingRule>();
99+
private final List<IResource> resources = new ArrayList<IResource>();
100100
private IResourceDelta resourceDelta;
101101
private Map<IFile, Set<MarkerInfo2>> markersByFile = new HashMap<IFile, Set<MarkerInfo2>>();
102102
private boolean taskMarker;
@@ -138,7 +138,7 @@ public Set<IFile> markedFiles() {
138138

139139
/**
140140
* Easy way to refresh a set of files.
141-
*
141+
*
142142
* @param files
143143
* @throws CommandException
144144
*/
@@ -254,6 +254,7 @@ public void run(IProgressMonitor monitor) throws CoreException {
254254
// Switch to the PMD perspective if required
255255
if (openPmdPerspective) {
256256
Display.getDefault().asyncExec(new Runnable() {
257+
@Override
257258
public void run() {
258259
switchToPmdPerspective();
259260
}
@@ -263,7 +264,7 @@ public void run() {
263264
if (openPmdViolationsOverviewView) {
264265
PMDPlugin.getDefault().showView(PMDPlugin.VIOLATIONS_OVERVIEW_ID);
265266
}
266-
267+
267268
if (openPmdViolationsOutlineView) {
268269
PMDPlugin.getDefault().showView(PMDPlugin.VIOLATIONS_OUTLINE_ID);
269270
}
@@ -277,12 +278,12 @@ public void run() {
277278

278279
// Log performance information
279280
if (fileCount > 0 && ruleCount > 0) {
280-
logInfo("Review code command terminated. " + ruleCount + " rules were executed against " + fileCount
281+
logInfo("Review code command finished. " + ruleCount + " rules were executed against " + fileCount
281282
+ " files. Actual PMD duration is about " + pmdDuration + "ms, that is about "
282283
+ (float) pmdDuration / fileCount + " ms/file, " + (float) pmdDuration / ruleCount
283284
+ " ms/rule, " + (float) pmdDuration / ((long) fileCount * (long) ruleCount) + " ms/filerule");
284285
} else {
285-
logInfo("Review code command terminated. " + ruleCount + " rules were executed against " + fileCount
286+
logInfo("Review code command finished. " + ruleCount + " rules were executed against " + fileCount
286287
+ " files. PMD was not executed.");
287288
}
288289
}
@@ -351,19 +352,19 @@ public void setRunAlways(boolean runAlways) {
351352
public void setOpenPmdPerspective(boolean openPmdPerspective) {
352353
this.openPmdPerspective = openPmdPerspective;
353354
}
354-
355+
355356
/**
356357
* Set the open violations view to run after code review.
357-
*
358+
*
358359
* @param openPmdViolationsView should open
359360
*/
360361
public void setOpenPmdViolationsOverviewView(boolean openPmdViolationsView) {
361362
this.openPmdViolationsOverviewView = openPmdViolationsView;
362363
}
363-
364+
364365
/**
365366
* Set the open violations outline view to run after code review.
366-
*
367+
*
367368
* @param openPmdViolationsOutlineView should open
368369
*/
369370
public void setOpenPmdViolationsOutlineView(boolean openPmdViolationsOutlineView) {
@@ -420,10 +421,13 @@ private ISchedulingRule getSchedulingRule() {
420421
* @throws CommandException
421422
*/
422423
private void processResources() throws CommandException {
423-
final Iterator<ISchedulingRule> i = resources.iterator();
424-
while (i.hasNext()) {
425-
final IResource resource = (IResource) i.next();
424+
Set<String> projects = new HashSet<String>();
425+
for (IResource resource : resources) {
426+
projects.add(resource.getProject().getName());
427+
}
428+
logInfo("ReviewCodeCmd started with " + resources.size() + " selected resources on projects " + projects);
426429

430+
for (IResource resource : resources) {
427431
// if resource is a project, visit only its source folders
428432
if (resource instanceof IProject) {
429433
processProject((IProject) resource);
@@ -508,7 +512,8 @@ private void processResource(IResource resource) throws CommandException {
508512
private void processProject(IProject project) throws CommandException {
509513
try {
510514
setStepCount(countResourceElement(project));
511-
LOG.debug("Visiting project " + project.getName() + " : " + getStepCount());
515+
logInfo("ReviewCodeCmd: visiting project " + project.getName() + ": " + getStepCount() + " resources found.");
516+
LOG.debug("Visiting project " + project.getName() + " : " + getStepCount() + " resources found.");
512517

513518
if (project.hasNature(JavaCore.NATURE_ID)) {
514519
processJavaProject(project);
@@ -609,6 +614,7 @@ private void processResourceDelta() throws CommandException {
609614
IResource resource = resourceDelta.getResource();
610615
final IProject project = resource.getProject();
611616
final IProjectProperties properties = getProjectProperties(project);
617+
logInfo("ReviewCodeCmd started on resource delta " + resource.getName() + " in project " + project.getName());
612618

613619
RuleSet ruleSet = rulesetFromResourceDelta(); // properties.getProjectRuleSet();
614620

@@ -680,7 +686,7 @@ private void applyMarkers() {
680686
} finally {
681687
timer.stop();
682688
int count = markersByFile.size();
683-
logInfo("" + violationCount + " markers applied on " + count + " files in " + timer.getDuration() + "ms.");
689+
LOG.info("" + violationCount + " markers applied on " + count + " files in " + timer.getDuration() + "ms.");
684690
LOG.info("End of processing marker directives. " + violationCount + " violations for " + count + " files.");
685691
}
686692
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/properties/IProjectProperties.java

+9
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,13 @@ public interface IProjectProperties {
198198
* @return include patterns
199199
*/
200200
Set<String> getBuildPathIncludePatterns();
201+
202+
/**
203+
* Determines the auxiliary classpath needed for type resolution.
204+
* The classloader is cached and used for all PMD executions for the same project.
205+
* The classloader is not stored to the project properties file.
206+
*
207+
* @return the classpath or <code>null</code> if the project is not a java project
208+
*/
209+
ClassLoader getAuxClasspath();
201210
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/properties/impl/ProjectPropertiesImpl.java

+21
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@
5151
import org.eclipse.core.runtime.IPath;
5252
import org.eclipse.core.runtime.Path;
5353
import org.eclipse.jdt.core.IClasspathEntry;
54+
import org.eclipse.jdt.core.JavaCore;
5455
import org.eclipse.ui.IWorkingSet;
5556

57+
import net.sourceforge.pmd.PMD;
5658
import net.sourceforge.pmd.RuleSet;
5759
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
60+
import net.sourceforge.pmd.eclipse.runtime.cmd.JavaProjectClassLoader;
5861
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
5962
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager;
6063
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
@@ -89,6 +92,7 @@ public class ProjectPropertiesImpl implements IProjectProperties {
8992
private boolean fullBuildEnabled = true; // default in case didn't come from properties
9093
private Set<String> buildPathExcludePatterns = new HashSet<String>();
9194
private Set<String> buildPathIncludePatterns = new HashSet<String>();
95+
private ClassLoader auxclasspath;
9296

9397
/**
9498
* The default constructor takes a project as an argument
@@ -452,4 +456,21 @@ public Set<String> getBuildPathExcludePatterns() {
452456
public Set<String> getBuildPathIncludePatterns() {
453457
return buildPathIncludePatterns;
454458
}
459+
460+
@Override
461+
public ClassLoader getAuxClasspath() {
462+
try {
463+
if (project != null && project.hasNature(JavaCore.NATURE_ID)) {
464+
if (auxclasspath == null) {
465+
PMDPlugin.getDefault().logInformation("Creating new auxclasspath class loader for project " + project.getName());
466+
auxclasspath = new JavaProjectClassLoader(PMD.class.getClassLoader(), project);
467+
}
468+
return auxclasspath;
469+
}
470+
} catch (CoreException e) {
471+
LOG.error("Error determining aux classpath", e);
472+
PMDPlugin.getDefault().logError("Error determining aux classpath", e);
473+
}
474+
return null;
475+
}
455476
}

0 commit comments

Comments
 (0)