Added option to run PMD on Buffer save

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2240 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Jiger Patel
2003-09-05 07:54:02 +00:00
parent 6e76579e93
commit c320915f4a
2 changed files with 29 additions and 12 deletions

View File

@ -22,7 +22,6 @@ import net.sourceforge.pmd.cpd.Mark;
import net.sourceforge.pmd.cpd.Match;
import org.gjt.sp.jedit.Buffer;
import org.gjt.sp.jedit.View;
import org.gjt.sp.jedit.EditPlugin;
import org.gjt.sp.jedit.jEdit;
import org.gjt.sp.jedit.browser.*;
import org.gjt.sp.jedit.io.*;
@ -42,14 +41,19 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.gjt.sp.jedit.EBPlugin;
import org.gjt.sp.jedit.EBMessage;
import org.gjt.sp.jedit.msg.BufferUpdate;
public class PMDJEditPlugin extends EditPlugin {
public class PMDJEditPlugin extends EBPlugin {
public static final String NAME = "PMD";
public static final String OPTION_RULES_PREFIX = "options.pmd.rules.";
public static final String OPTION_UI_DIRECTORY_POPUP = "options.pmd.ui.directorypopup";
public static final String DEFAULT_TILE_MINSIZE_PROPERTY = "pmd.cpd.defMinTileSize";
public static final String RUN_PMD_ON_SAVE = "pmd.runPMDOnSave";
public static final String CUSTOM_RULES_PATH_KEY = "pmd.customRulesPath";
//private static RE re = new UncheckedRE("Starting at line ([0-9]*) of (\\S*)");
private static PMDJEditPlugin instance;
@ -105,6 +109,21 @@ public class PMDJEditPlugin extends EditPlugin {
}
}
public void handleMessage(EBMessage ebmess)
{
if (ebmess instanceof BufferUpdate)
{
if(jEdit.getBooleanProperty(PMDJEditPlugin.RUN_PMD_ON_SAVE))
{
BufferUpdate bu = (BufferUpdate)ebmess;
if (bu.getWhat() == BufferUpdate.SAVED)
{
instance.check(bu.getBuffer(),bu.getView());
}
}
}
}
// check all open buffers
public static void checkAllOpenBuffers(View view) {
instance.instanceCheckAllOpenBuffers(view);
@ -428,8 +447,3 @@ public class PMDJEditPlugin extends EditPlugin {
}

View File

@ -76,7 +76,7 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
private SelectedRules rules;
private JTextArea exampleTextArea= new JTextArea(10, 50);
private JCheckBox directoryPopupBox;
private JCheckBox directoryPopupBox, chkRunPMDOnSave;
JTextField txtMinTileSize;
JTextField txtCustomRules;
@ -103,7 +103,7 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
//Custom Rule Panel Defination.
JPanel pnlCustomRules = new JPanel(new FlowLayout(FlowLayout.LEFT));
pnlCustomRules.add(new JLabel("Path to custom rules.xml files(seperated by comma)"));
pnlCustomRules.add((txtCustomRules = new JTextField(jEdit.getProperty("pmd.customRulesPath",""),30)));
pnlCustomRules.add((txtCustomRules = new JTextField(jEdit.getProperty(PMDJEditPlugin.CUSTOM_RULES_PATH_KEY,""),30)));
rulesPanel.add(pnlCustomRules, BorderLayout.CENTER);
@ -116,13 +116,14 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
}
directoryPopupBox = new JCheckBox("Ask for directory?", jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP));
chkRunPMDOnSave = new JCheckBox("Run PMD on Save", jEdit.getBooleanProperty(PMDJEditPlugin.RUN_PMD_ON_SAVE));
JPanel pnlSouth = new JPanel(new GridLayout(0,1));
JPanel pnlTileSize = new JPanel();
((FlowLayout)pnlTileSize.getLayout()).setAlignment(FlowLayout.LEFT);
JLabel lblMinTileSize = new JLabel("Minimum Tile Size :");
txtMinTileSize = new JTextField(jEdit.getProperty("pmd.cpd.defMinTileSize","100"),5);
txtMinTileSize = new JTextField(jEdit.getProperty(PMDJEditPlugin.DEFAULT_TILE_MINSIZE_PROPERTY,"100"),5);
pnlTileSize.add(lblMinTileSize);
pnlTileSize.add(txtMinTileSize);
@ -133,6 +134,7 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
mainPanel.add(textPanel, BorderLayout.CENTER);
pnlSouth.add(directoryPopupBox);
pnlSouth.add(chkRunPMDOnSave);
pnlSouth.add(pnlTileSize);
mainPanel.add(pnlSouth, BorderLayout.SOUTH);
addComponent(mainPanel);
@ -144,11 +146,12 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP, directoryPopupBox.isSelected());
}
jEdit.setIntegerProperty("pmd.cpd.defMinTileSize",(txtMinTileSize.getText().length() == 0)?100:Integer.parseInt(txtMinTileSize.getText()));
jEdit.setIntegerProperty(PMDJEditPlugin.DEFAULT_TILE_MINSIZE_PROPERTY,(txtMinTileSize.getText().length() == 0)?100:Integer.parseInt(txtMinTileSize.getText()));
jEdit.setBooleanProperty(PMDJEditPlugin.RUN_PMD_ON_SAVE,(chkRunPMDOnSave.isSelected()));
if(txtCustomRules != null)
{
jEdit.setProperty("pmd.customRulesPath",txtCustomRules.getText());
jEdit.setProperty(PMDJEditPlugin.CUSTOM_RULES_PATH_KEY,txtCustomRules.getText());
}
}
}