optimizations, export improvements, bugfixes for new functionality
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7583 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin
CHANGELOG.txtmessages.properties
src/net/sourceforge/pmd/eclipse
plugin
runtime
cmd
AbstractDefaultCommand.javaBaseVisitor.javaDeleteMarkersCommand.javaDeltaVisitor.javaMarkerInfo.javaMarkerInfo2.javaReviewCodeCmd.java
preferences/impl
ui
filters
preferences/br
views/actions
@ -4,15 +4,18 @@ v4.0.0 - xxx 2011?
|
||||
. New integrated AST View and XPath test area
|
||||
. New rule creation wizard
|
||||
. New report preferences panel
|
||||
. New file filter panel for exclusion/inclusion entries
|
||||
. User-definable rule violation markers
|
||||
Highest priority markers also decorate folders & projects (selectable)
|
||||
. Colour syntax highlighting in code viewers/editors
|
||||
. Expanded rule import dialog to show incoming rules and any duplicates
|
||||
. Export rule function now only exports selected rules
|
||||
. Overhauled rule preferences screen
|
||||
. allows users to group/edit rules by multiple criteria
|
||||
. new ability to enable/disable rules without removing them from rulesets
|
||||
. larger editors for the various fields
|
||||
. support for non-Java languages
|
||||
. group editing of filter exclusion rules
|
||||
. group editing of rule exclusion filters
|
||||
. highlighting of non-default property values
|
||||
. colour-tagged expressions in shown in rule table
|
||||
. new property editors are fully type-aware
|
||||
|
@ -97,7 +97,7 @@ preference.ruleset.button.addrule = Add rule...
|
||||
preference.ruleset.button.removerule = Remove rule
|
||||
preference.ruleset.button.editrule = Edit rule...
|
||||
preference.ruleset.button.importruleset = Import rule set...
|
||||
preference.ruleset.button.exportruleset = Export rule set...
|
||||
preference.ruleset.button.exportruleset = Export selected rules...
|
||||
preference.ruleset.button.clearall = Clear all
|
||||
preference.ruleset.button.ruledesigner = Rule Designer
|
||||
preference.ruleset.button.addproperty = Add property...
|
||||
|
@ -46,6 +46,10 @@ import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||
import org.eclipse.core.resources.IResourceChangeListener;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
@ -68,7 +72,7 @@ import org.osgi.framework.BundleContext;
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class PMDPlugin extends AbstractUIPlugin {
|
||||
public class PMDPlugin extends AbstractUIPlugin implements IResourceChangeListener {
|
||||
|
||||
private static File pluginFolder;
|
||||
|
||||
@ -170,16 +174,35 @@ public class PMDPlugin extends AbstractUIPlugin {
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
configureLogs(loadPreferences());
|
||||
|
||||
IPreferences prefs = loadPreferences();
|
||||
configureLogs(prefs);
|
||||
registerStandardRuleSets();
|
||||
registerAdditionalRuleSets();
|
||||
fileChangeListenerEnabled(prefs.isCheckAfterSaveEnabled());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void fileChangeListenerEnabled(boolean flag) {
|
||||
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
|
||||
if (flag) {
|
||||
workspace.addResourceChangeListener(this);
|
||||
} else {
|
||||
workspace.removeResourceChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
|
||||
fileChangeListenerEnabled(false);
|
||||
|
||||
plugin = null;
|
||||
disposeResources();
|
||||
super.stop(context);
|
||||
@ -541,5 +564,14 @@ public class PMDPlugin extends AbstractUIPlugin {
|
||||
decorator.changed(changes);
|
||||
}
|
||||
|
||||
public void resourceChanged(IResourceChangeEvent event) {
|
||||
|
||||
// switch (event.getType()) {
|
||||
// case PRE_DELETE:
|
||||
// case POST_CHANGE:
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ package net.sourceforge.pmd.eclipse.runtime.cmd;
|
||||
import name.herlin.command.AbstractProcessableCommand;
|
||||
import name.herlin.command.CommandException;
|
||||
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
@ -70,11 +71,22 @@ public abstract class AbstractDefaultCommand extends AbstractProcessableCommand
|
||||
description = theDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @deprecated we support multiple languages now
|
||||
*/
|
||||
public static boolean isJavaFile(IFile file) {
|
||||
if (file == null) return false;
|
||||
return "JAVA".equalsIgnoreCase(file.getFileExtension());
|
||||
}
|
||||
|
||||
public static boolean isLanguageFile(IFile file, Language language) {
|
||||
if (file == null) return false;
|
||||
return language.hasExtension(file.getFileExtension());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the readOnly status.
|
||||
*/
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -57,11 +57,11 @@ public class DeleteMarkersCommand extends AbstractDefaultCommand {
|
||||
public DeleteMarkersCommand() {
|
||||
super("DeleteMarkersCommand", "Deletes a possible large number of markers");
|
||||
|
||||
this.setOutputProperties(true);
|
||||
this.setReadOnly(false);
|
||||
this.setTerminated(false);
|
||||
this.setMarkers(null);
|
||||
this.setUserInitiated(false);
|
||||
setOutputProperties(true);
|
||||
setReadOnly(false);
|
||||
setTerminated(false);
|
||||
setMarkers(null);
|
||||
setUserInitiated(false);
|
||||
}
|
||||
|
||||
public final void setMarkers(IMarker[] theMarkers) { // NOPMD by Sven on 13.11.06 11:43
|
||||
@ -95,4 +95,4 @@ public class DeleteMarkersCommand extends AbstractDefaultCommand {
|
||||
setMarkers(null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||
*
|
||||
*/
|
||||
public class DeltaVisitor extends BaseVisitor implements IResourceDeltaVisitor {
|
||||
|
||||
private static final Logger log = Logger.getLogger(DeltaVisitor.class);
|
||||
|
||||
/**
|
||||
@ -26,40 +27,43 @@ public class DeltaVisitor extends BaseVisitor implements IResourceDeltaVisitor {
|
||||
/**
|
||||
* Constructor with monitor
|
||||
*/
|
||||
public DeltaVisitor(final IProgressMonitor monitor) {
|
||||
public DeltaVisitor(IProgressMonitor monitor) {
|
||||
super();
|
||||
this.setMonitor(monitor);
|
||||
setMonitor(monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(IResourceDelta)
|
||||
*/
|
||||
public boolean visit(final IResourceDelta delta) throws CoreException {
|
||||
boolean fProcessChildren = true;
|
||||
public boolean visit(IResourceDelta delta) throws CoreException {
|
||||
|
||||
if (this.isCanceled()) {
|
||||
fProcessChildren = false;
|
||||
} else {
|
||||
if (delta.getKind() == IResourceDelta.ADDED) {
|
||||
log.debug("Visiting added resource " + delta.getResource().getName());
|
||||
visitAdded(delta.getResource());
|
||||
} else if (delta.getKind() == IResourceDelta.CHANGED) {
|
||||
log.debug("Visiting changed resource " + delta.getResource().getName());
|
||||
visitChanged(delta.getResource());
|
||||
} else { // other kinds are not visited
|
||||
log.debug("Resource " + delta.getResource().getName() + " not visited.");
|
||||
}
|
||||
}
|
||||
if (isCanceled()) return false;
|
||||
|
||||
return fProcessChildren;
|
||||
switch (delta.getKind()) {
|
||||
case IResourceDelta.ADDED : {
|
||||
log.debug("Visiting added resource " + delta.getResource().getName());
|
||||
visitAdded(delta.getResource());
|
||||
break;
|
||||
}
|
||||
case IResourceDelta.CHANGED : {
|
||||
log.debug("Visiting changed resource " + delta.getResource().getName());
|
||||
visitChanged(delta.getResource());
|
||||
break;
|
||||
}
|
||||
default : { // other kinds are not visited
|
||||
log.debug("Resource " + delta.getResource().getName() + " not visited.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit added resource
|
||||
* @param resource a new resource
|
||||
*/
|
||||
private void visitAdded(final IResource resource) {
|
||||
this.reviewResource(resource);
|
||||
private void visitAdded(IResource resource) {
|
||||
reviewResource(resource);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,7 +71,7 @@ public class DeltaVisitor extends BaseVisitor implements IResourceDeltaVisitor {
|
||||
* @param resource a changed resource
|
||||
*/
|
||||
private void visitChanged(final IResource resource) {
|
||||
this.reviewResource(resource);
|
||||
reviewResource(resource);
|
||||
}
|
||||
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* <copyright>
|
||||
* Copyright 1997-2003 PMD for Eclipse Development team
|
||||
* under sponsorship of the Defense Advanced Research Projects
|
||||
* Agency (DARPA).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the Cougaar Open Source License as published by
|
||||
* DARPA on the Cougaar Open Source Website (www.cougaar.org).
|
||||
*
|
||||
* THE COUGAAR SOFTWARE AND ANY DERIVATIVE SUPPLIED BY LICENSOR IS
|
||||
* PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, WHETHER EXPRESS OR
|
||||
* IMPLIED, INCLUDING (BUT NOT LIMITED TO) ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND WITHOUT
|
||||
* ANY WARRANTIES AS TO NON-INFRINGEMENT. IN NO EVENT SHALL COPYRIGHT
|
||||
* HOLDER BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT OR CONSEQUENTIAL
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE OF DATA OR PROFITS,
|
||||
* TORTIOUS CONDUCT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THE COUGAAR SOFTWARE.
|
||||
*
|
||||
* </copyright>
|
||||
*/
|
||||
package net.sourceforge.pmd.eclipse.runtime.cmd;
|
||||
|
||||
/**
|
||||
* This class is intended to hold informations for future marker creation.
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
*
|
||||
*/
|
||||
public class MarkerInfo {
|
||||
|
||||
private final String type;
|
||||
private String[] attributeNames;
|
||||
private Object[] attributeValues;
|
||||
|
||||
public MarkerInfo(String theType) {
|
||||
type = theType;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String[] getAttributeNames() {
|
||||
return attributeNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Object[] getAttributeValues() {
|
||||
return attributeValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param strings
|
||||
*/
|
||||
public void setAttributeNames(String[] strings) {
|
||||
attributeNames = strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param objects
|
||||
*/
|
||||
public void setAttributeValues(Object[] objects) {
|
||||
attributeValues = objects;
|
||||
}
|
||||
|
||||
}
|
40
pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/MarkerInfo2.java
Normal file
40
pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/MarkerInfo2.java
Normal file
@ -0,0 +1,40 @@
|
||||
package net.sourceforge.pmd.eclipse.runtime.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class MarkerInfo2 {
|
||||
|
||||
private final String type;
|
||||
private List<String> names;
|
||||
private List<Object> values;
|
||||
|
||||
public MarkerInfo2(String theType, int expectedSize) {
|
||||
type = theType;
|
||||
names = new ArrayList<String>(expectedSize);
|
||||
values = new ArrayList<Object>(expectedSize);
|
||||
}
|
||||
|
||||
public void add(String name, Object value) {
|
||||
names.add(name);
|
||||
values.add(value);
|
||||
}
|
||||
|
||||
public void add(String name, int value) {
|
||||
add(name, Integer.valueOf(value));
|
||||
}
|
||||
|
||||
public void addAsMarkerTo(IFile file) throws CoreException {
|
||||
|
||||
IMarker marker = file.createMarker(type);
|
||||
marker.setAttributes(names.toArray(new String[names.size()]), values.toArray());
|
||||
}
|
||||
}
|
@ -52,6 +52,7 @@ import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
|
||||
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
|
||||
import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
@ -91,7 +92,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
|
||||
private final List<ISchedulingRule> resources = new ArrayList<ISchedulingRule>();
|
||||
private IResourceDelta resourceDelta;
|
||||
private Map<IFile, Set<MarkerInfo>> markersByFile = new HashMap<IFile, Set<MarkerInfo>>();
|
||||
private Map<IFile, Set<MarkerInfo2>> markersByFile = new HashMap<IFile, Set<MarkerInfo2>>();
|
||||
private boolean taskMarker;
|
||||
private boolean openPmdPerspective;
|
||||
private int ruleCount;
|
||||
@ -231,7 +232,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
/**
|
||||
* @return Returns the file markers
|
||||
*/
|
||||
public Map<IFile, Set<MarkerInfo>> getMarkers() {
|
||||
public Map<IFile, Set<MarkerInfo2>> getMarkers() {
|
||||
return markersByFile;
|
||||
}
|
||||
|
||||
@ -284,7 +285,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
@Override
|
||||
public void reset() {
|
||||
resources.clear();
|
||||
markersByFile = new HashMap<IFile, Set<MarkerInfo>>();
|
||||
markersByFile = new HashMap<IFile, Set<MarkerInfo2>>();
|
||||
setTerminated(false);
|
||||
openPmdPerspective = false;
|
||||
onErrorIssue = null;
|
||||
@ -518,11 +519,10 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
if (isCanceled()) break;
|
||||
currentFile = file.getName();
|
||||
|
||||
Set<MarkerInfo> markerInfoSet = markersByFile.get(file);
|
||||
Set<MarkerInfo2> markerInfoSet = markersByFile.get(file);
|
||||
// MarkerUtil.deleteAllMarkersIn(file);
|
||||
for (MarkerInfo markerInfo : markerInfoSet) {
|
||||
IMarker marker = file.createMarker(markerInfo.getType());
|
||||
marker.setAttributes(markerInfo.getAttributeNames(), markerInfo.getAttributeValues());
|
||||
for (MarkerInfo2 markerInfo : markerInfoSet) {
|
||||
markerInfo.addAsMarkerTo(file);
|
||||
violationCount++;
|
||||
}
|
||||
|
||||
@ -537,7 +537,6 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
logInfo("" + violationCount + " markers applied on " + count + " files in " + timer.getDuration() + "ms.");
|
||||
log.info("End of processing marker directives. " + violationCount + " violations for " + count + " files.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -581,7 +580,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
*
|
||||
* @author SebastianRaffel ( 07.05.2005 )
|
||||
*/
|
||||
private void switchToPmdPerspective() {
|
||||
private static void switchToPmdPerspective() {
|
||||
final IWorkbench workbench = PlatformUI.getWorkbench();
|
||||
final IPerspectiveRegistry reg = workbench.getPerspectiveRegistry();
|
||||
final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
|
||||
@ -598,7 +597,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
|
||||
boolean fVisitChildren = true;
|
||||
count++;
|
||||
|
||||
if (resource instanceof IFile && isJavaFile((IFile) resource)) {
|
||||
if (resource instanceof IFile && isLanguageFile((IFile) resource, Language.JAVA)) {
|
||||
|
||||
fVisitChildren = false;
|
||||
}
|
||||
|
@ -515,17 +515,19 @@ class PreferencesManagerImpl implements IPreferencesManager {
|
||||
*/
|
||||
private void storeRuleSetInStateLocation(RuleSet ruleSet) {
|
||||
OutputStream out = null;
|
||||
PMDPlugin plugin = PMDPlugin.getDefault();
|
||||
|
||||
try {
|
||||
IPath ruleSetLocation = PMDPlugin.getDefault().getStateLocation().append(PREFERENCE_RULESET_FILE);
|
||||
IPath ruleSetLocation = plugin.getStateLocation().append(PREFERENCE_RULESET_FILE);
|
||||
out = new FileOutputStream(ruleSetLocation.toOSString());
|
||||
IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter();
|
||||
IRuleSetWriter writer = plugin.getRuleSetWriter();
|
||||
writer.write(out, ruleSet);
|
||||
out.flush();
|
||||
|
||||
} catch (IOException e) {
|
||||
PMDPlugin.getDefault().logError("IO Exception when storing ruleset in state location", e);
|
||||
plugin.logError("IO Exception when storing ruleset in state location", e);
|
||||
} catch (WriterException e) {
|
||||
PMDPlugin.getDefault().logError("General PMD Eclipse Exception when storing ruleset in state location", e);
|
||||
plugin.logError("General PMD Eclipse Exception when storing ruleset in state location", e);
|
||||
} finally {
|
||||
IOUtil.closeQuietly(out);
|
||||
}
|
||||
|
@ -68,7 +68,8 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements
|
||||
private Button pmdButt;
|
||||
private Text patternField;
|
||||
private BasicTableManager reportTableMgr;
|
||||
|
||||
private Collection<Control> editorWidgets = new ArrayList<Control>();
|
||||
|
||||
private static Image IncludeIcon;
|
||||
private static Image ExcludeIcon;
|
||||
|
||||
@ -172,11 +173,10 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements
|
||||
}
|
||||
|
||||
private void enableEditor(boolean flag) {
|
||||
cpdButt.setEnabled(flag);
|
||||
pmdButt.setEnabled(flag);
|
||||
excludeButt.setEnabled(flag);
|
||||
includeButt.setEnabled(flag);
|
||||
patternField.setEnabled(flag);
|
||||
|
||||
for (Control control : editorWidgets) {
|
||||
control.setEnabled(flag);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> tableFilters(boolean isInclude) {
|
||||
@ -229,9 +229,7 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements
|
||||
|
||||
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
IStructuredSelection selection = (IStructuredSelection)event.getSelection();
|
||||
selectedPatterns(filtersIn(selection.toList()));
|
||||
updateControls();
|
||||
patternsSelected();
|
||||
}
|
||||
});
|
||||
|
||||
@ -246,6 +244,12 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements
|
||||
return parent;
|
||||
}
|
||||
|
||||
private void patternsSelected() {
|
||||
IStructuredSelection selection = (IStructuredSelection)tableViewer.getSelection();
|
||||
selectedPatterns(filtersIn(selection.toList()));
|
||||
updateControls();
|
||||
}
|
||||
|
||||
private void selectedPatterns(Collection<FilterHolder> holders) {
|
||||
|
||||
setState(holders, includeButt, FilterHolder.IncludeAccessor);
|
||||
@ -304,7 +308,8 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements
|
||||
Label typeLabel = new Label(editorPanel, SWT.None);
|
||||
typeLabel.setLayoutData( new GridData());
|
||||
typeLabel.setText("Type:");
|
||||
|
||||
editorWidgets.add(typeLabel);
|
||||
|
||||
excludeButt = createButton(editorPanel, SWT.RADIO, excludeIcon(), "Exclude");
|
||||
excludeButt.addSelectionListener( new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent se) {
|
||||
@ -321,10 +326,14 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements
|
||||
}
|
||||
});
|
||||
|
||||
editorWidgets.add(excludeButt);
|
||||
editorWidgets.add(includeButt);
|
||||
|
||||
Label contextLabel = new Label(editorPanel, SWT.None);
|
||||
contextLabel.setLayoutData( new GridData());
|
||||
contextLabel.setText("Applies to:");
|
||||
|
||||
editorWidgets.add(contextLabel);
|
||||
|
||||
pmdButt = createButton(editorPanel, SWT.CHECK, "PMD");
|
||||
pmdButt.addSelectionListener( new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent se) {
|
||||
@ -341,10 +350,14 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements
|
||||
}
|
||||
});
|
||||
|
||||
editorWidgets.add(pmdButt);
|
||||
editorWidgets.add(cpdButt);
|
||||
|
||||
Label patternLabel = new Label(editorPanel, SWT.None);
|
||||
patternLabel.setLayoutData( new GridData());
|
||||
patternLabel.setText("Pattern:");
|
||||
|
||||
editorWidgets.add(patternLabel);
|
||||
|
||||
patternField = new Text(editorPanel, SWT.BORDER);
|
||||
patternField.setLayoutData( new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1) );
|
||||
patternField.addFocusListener(new FocusAdapter() {
|
||||
@ -353,6 +366,15 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements
|
||||
tableViewer.refresh();
|
||||
}
|
||||
});
|
||||
editorWidgets.add(patternField);
|
||||
|
||||
Label spacer = new Label(editorPanel, SWT.None);
|
||||
spacer.setLayoutData( new GridData() );
|
||||
Label description = new Label(editorPanel, SWT.None);
|
||||
description.setLayoutData( new GridData(GridData.FILL, GridData.BEGINNING, true, false, 2, 1) );
|
||||
description.setText("name or path pattern (* = any string, ? = any character)");
|
||||
|
||||
editorWidgets.add(description);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -535,7 +557,14 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements
|
||||
|
||||
private void addNewFilter() {
|
||||
FilterHolder newHolder = new FilterHolder(NewFilterPattern, true, false, false);
|
||||
tableViewer.setInput( tableFiltersWith(newHolder) );
|
||||
|
||||
FilterHolder[] holders = tableFiltersWith(newHolder);
|
||||
tableViewer.setInput( holders );
|
||||
|
||||
tableViewer.getTable().select(holders.length-1);
|
||||
patternsSelected();
|
||||
patternField.selectAll();
|
||||
patternField.forceFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +84,7 @@ public class RuleTableManager extends AbstractTreeTableManager<Rule> implements
|
||||
private MenuItem useDefaultsItem;
|
||||
private Button addRuleButton;
|
||||
private Button removeRuleButton;
|
||||
|
||||
private Button exportRuleSetButton;
|
||||
private RuleSelectionListener ruleSelectionListener;
|
||||
private ValueResetHandler resetHandler;
|
||||
|
||||
@ -312,22 +312,46 @@ public class RuleTableManager extends AbstractTreeTableManager<Rule> implements
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
FileDialog dialog = new FileDialog(parent.getShell(), SWT.SAVE);
|
||||
String fileName = dialog.open();
|
||||
if (fileName != null) {
|
||||
try {
|
||||
exportTo(fileName, parent.getShell());
|
||||
} catch (Exception e) {
|
||||
plugin.showError(getMessage(StringKeys.ERROR_EXPORTING_RULESET), e);
|
||||
}
|
||||
}
|
||||
exportSelectedRules();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private void exportSelectedRules() {
|
||||
|
||||
Shell shell = treeViewer.getTree().getShell();
|
||||
|
||||
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
|
||||
dialog.setText("Export " + ruleSelection.allRules().size() + " rules");
|
||||
|
||||
String fileName = dialog.open();
|
||||
if (StringUtil.isNotEmpty(fileName)) {
|
||||
try {
|
||||
exportTo(fileName, shell);
|
||||
} catch (Exception e) {
|
||||
plugin.showError(getMessage(StringKeys.ERROR_EXPORTING_RULESET), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RuleSet ruleSelectionAsRuleSet() {
|
||||
|
||||
RuleSet rs = new RuleSet();
|
||||
rs.setName( ruleSet.getName() );
|
||||
rs.setDescription( ruleSet.getDescription() );
|
||||
rs.setFileName( ruleSet.getFileName());
|
||||
rs.addExcludePatterns( ruleSet.getExcludePatterns() );
|
||||
rs.addIncludePatterns( ruleSet.getIncludePatterns() );
|
||||
|
||||
for (Rule rule : ruleSelection.allRules()) {
|
||||
rs.addRule(rule);
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
private void exportTo(String fileName, Shell shell) throws FileNotFoundException, WriterException, IOException {
|
||||
|
||||
File file = new File(fileName);
|
||||
@ -340,7 +364,12 @@ public class RuleTableManager extends AbstractTreeTableManager<Rule> implements
|
||||
}
|
||||
|
||||
InputDialog input = null;
|
||||
|
||||
RuleSet ruleSet = null;
|
||||
|
||||
if (flContinue) {
|
||||
ruleSet = ruleSelectionAsRuleSet();
|
||||
|
||||
input = new InputDialog(shell,
|
||||
getMessage(StringKeys.PREF_RULESET_DIALOG_TITLE),
|
||||
getMessage(StringKeys.PREF_RULESET_DIALOG_RULESET_DESCRIPTION),
|
||||
@ -466,6 +495,8 @@ public class RuleTableManager extends AbstractTreeTableManager<Rule> implements
|
||||
} catch (RuntimeException e) {
|
||||
plugin.showError(getMessage(StringKeys.ERROR_IMPORTING_RULESET), e);
|
||||
}
|
||||
|
||||
updateCheckControls();
|
||||
}
|
||||
|
||||
public Composite buildGroupCombo(Composite parent, String comboLabelKey, final Object[][] groupingChoices) {
|
||||
@ -541,7 +572,7 @@ public class RuleTableManager extends AbstractTreeTableManager<Rule> implements
|
||||
addRuleButton = buildAddRuleButton(composite);
|
||||
removeRuleButton = buildRemoveRuleButton(composite);
|
||||
Button importRuleSetButton = buildImportRuleSetButton(composite);
|
||||
Button exportRuleSetButton = buildExportRuleSetButton(composite);
|
||||
exportRuleSetButton = buildExportRuleSetButton(composite);
|
||||
Button ruleDesignerButton = buildRuleDesignerButton(composite);
|
||||
|
||||
GridData data = new GridData();
|
||||
@ -865,7 +896,10 @@ public class RuleTableManager extends AbstractTreeTableManager<Rule> implements
|
||||
ruleSelectionListener.selection(ruleSelection);
|
||||
}
|
||||
|
||||
if (removeRuleButton != null) removeRuleButton.setEnabled(items.length > 0);
|
||||
boolean hasSelections = items.length > 0;
|
||||
|
||||
if (removeRuleButton != null) removeRuleButton.setEnabled(hasSelections);
|
||||
if (exportRuleSetButton != null) exportRuleSetButton.setEnabled(hasSelections);
|
||||
}
|
||||
|
||||
private class SelectionStats {
|
||||
@ -892,7 +926,7 @@ public class RuleTableManager extends AbstractTreeTableManager<Rule> implements
|
||||
if (StringUtil.isNotEmpty(rule.dysfunctionReason())) dysfunctionCount++;
|
||||
}
|
||||
}
|
||||
return new SelectionStats(selectedCount , rules.length, dysfunctionCount) ;
|
||||
return new SelectionStats(selectedCount, rules.length, dysfunctionCount) ;
|
||||
}
|
||||
|
||||
protected void setAllItemsActive() {
|
||||
|
@ -12,6 +12,11 @@ import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
|
||||
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
|
||||
public class DisableRuleAction extends AbstractViolationSelectionAction {
|
||||
@ -53,21 +58,41 @@ public class DisableRuleAction extends AbstractViolationSelectionAction {
|
||||
System.out.println("Violations deleted: " + deletions);
|
||||
}
|
||||
|
||||
private List<Rule> disableRulesFor(IMarker[] markers) {
|
||||
|
||||
List<Rule> rules = MarkerUtil.rulesFor(markers);
|
||||
|
||||
for (Rule rule : rules) {
|
||||
preferences.isActive(rule.getName(), false);
|
||||
}
|
||||
|
||||
preferences.sync();
|
||||
return rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.action.IAction#run()
|
||||
*/
|
||||
public void run() {
|
||||
|
||||
final IMarker[] markers = getSelectedViolations();
|
||||
if (markers == null) return;
|
||||
if (markers == null) return;
|
||||
|
||||
List<Rule> rules = MarkerUtil.rulesFor(markers);
|
||||
for (Rule rule : rules) {
|
||||
preferences.isActive(rule.getName(), false);
|
||||
try {
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
workspace.run(new IWorkspaceRunnable() {
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
List<Rule> rules = disableRulesFor(markers);
|
||||
removeViolationsOf(rules, MarkerUtil.commonProjectsOf(markers) );
|
||||
}
|
||||
}, null);
|
||||
} catch (CoreException ce) {
|
||||
logErrorByKey(StringKeys.ERROR_CORE_EXCEPTION, ce);
|
||||
}
|
||||
|
||||
preferences.sync();
|
||||
|
||||
removeViolationsOf(rules, MarkerUtil.commonProjectsOf(markers) );
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import org.eclipse.swt.widgets.Shell;
|
||||
*
|
||||
*/
|
||||
public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
|
||||
private static final Logger log = Logger.getLogger(ReviewAction.class);
|
||||
private IProgressMonitor monitor;
|
||||
|
||||
@ -64,13 +65,7 @@ public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
|
||||
// Get confirmation if multiple markers are selected
|
||||
// Not necessary when using PMD style
|
||||
boolean go = true;
|
||||
if (markers.length > 1 && !reviewPmdStyle) {
|
||||
String title = getString(StringKeys.CONFIRM_TITLE);
|
||||
String message = getString(StringKeys.CONFIRM_REVIEW_MULTIPLE_MARKERS);
|
||||
Shell shell = Display.getCurrent().getActiveShell();
|
||||
go = MessageDialog.openConfirm(shell, title, message);
|
||||
}
|
||||
boolean go = confirmForMultiples(markers, reviewPmdStyle);
|
||||
|
||||
// If only one marker selected or user has confirmed, review violation
|
||||
if (go) {
|
||||
@ -92,6 +87,17 @@ public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean confirmForMultiples(IMarker[] markers, boolean reviewPmdStyle) {
|
||||
boolean go = true;
|
||||
if (markers.length > 1 && !reviewPmdStyle) {
|
||||
String title = getString(StringKeys.CONFIRM_TITLE);
|
||||
String message = getString(StringKeys.CONFIRM_REVIEW_MULTIPLE_MARKERS);
|
||||
Shell shell = Display.getCurrent().getActiveShell();
|
||||
go = MessageDialog.openConfirm(shell, title, message);
|
||||
}
|
||||
return go;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the insertion of the review comment
|
||||
*
|
||||
@ -111,11 +117,9 @@ public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
|
||||
monitorWorked();
|
||||
|
||||
if (reviewPmdStyle) {
|
||||
sourceCode = addPmdReviewComment(sourceCode, offset, marker);
|
||||
} else {
|
||||
sourceCode = addPluginReviewComment(sourceCode, offset, marker);
|
||||
}
|
||||
sourceCode = reviewPmdStyle ?
|
||||
addPmdReviewComment(sourceCode, offset, marker) :
|
||||
addPluginReviewComment(sourceCode, offset, marker);
|
||||
|
||||
monitorWorked();
|
||||
|
||||
@ -129,18 +133,8 @@ public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
}
|
||||
|
||||
}
|
||||
} catch (JavaModelException e) {
|
||||
IJavaModelStatus status = e.getJavaModelStatus();
|
||||
PMDPlugin.getDefault().logError(status);
|
||||
log.warn("Ignoring Java Model Exception : " + status.getMessage());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" code : " + status.getCode());
|
||||
log.debug(" severity : " + status.getSeverity());
|
||||
IJavaElement[] elements = status.getElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
log.debug(" element : " + elements[i].getElementName() + " (" + elements[i].getElementType() + ')');
|
||||
}
|
||||
}
|
||||
} catch (JavaModelException jme) {
|
||||
ignore(jme);
|
||||
} catch (CoreException e) {
|
||||
logErrorByKey(StringKeys.ERROR_CORE_EXCEPTION, e);
|
||||
} catch (IOException e) {
|
||||
@ -148,6 +142,21 @@ public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
}
|
||||
}
|
||||
|
||||
private static void ignore(JavaModelException jme) {
|
||||
|
||||
IJavaModelStatus status = jme.getJavaModelStatus();
|
||||
PMDPlugin.getDefault().logError(status);
|
||||
log.warn("Ignoring Java Model Exception : " + status.getMessage());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" code : " + status.getCode());
|
||||
log.debug(" severity : " + status.getSeverity());
|
||||
IJavaElement[] elements = status.getElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
log.debug(" element : " + elements[i].getElementName() + " (" + elements[i].getElementType() + ')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the monitor
|
||||
*
|
||||
@ -178,7 +187,7 @@ public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
/**
|
||||
* Renvoie la position dans le code source du début de la ligne du marqueur
|
||||
*/
|
||||
private int getMarkerLineStart(String sourceCode, int lineNumber) {
|
||||
private static int getMarkerLineStart(String sourceCode, int lineNumber) {
|
||||
int lineStart = 0;
|
||||
int currentLine = 1;
|
||||
for (lineStart = 0; lineStart < sourceCode.length(); lineStart++) {
|
||||
@ -209,7 +218,7 @@ public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
/**
|
||||
* Insert a review comment with the Plugin style
|
||||
*/
|
||||
private String addPluginReviewComment(String sourceCode, int offset, IMarker marker) {
|
||||
private static String addPluginReviewComment(String sourceCode, int offset, IMarker marker) {
|
||||
|
||||
// Copy the source code until the violation line not included
|
||||
StringBuilder sb = new StringBuilder(sourceCode.substring(0, offset));
|
||||
@ -230,7 +239,7 @@ public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
/**
|
||||
* Insert a review comment with the PMD style
|
||||
*/
|
||||
private String addPmdReviewComment(String sourceCode, int offset, IMarker marker) {
|
||||
private static String addPmdReviewComment(String sourceCode, int offset, IMarker marker) {
|
||||
String result = sourceCode;
|
||||
|
||||
// Find the end of line
|
||||
@ -297,4 +306,4 @@ public class ReviewAction extends AbstractViolationSelectionAction {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user