Release 4.2.1.0.0

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5974 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Torsten Kleiber
2008-04-06 20:42:10 +00:00
parent de32cd758c
commit 50fca09d29
10 changed files with 249 additions and 243 deletions

View File

@ -1,5 +1,8 @@
April 08, 2008 - 4.2:
Updated PMD version to 4.2.
April 06, 2008 - 4.2:
Updated PMD version to 4.2 for 9.0.5 to 10.1.3.
11g version is not available because of classloading errors for jaxen lib.
Apply some pmd rules on the plugin.
Export/Import PMD preferences in 10.1.3 Version.
December 06, 2007 - 4.1:
Updated PMD version to 4.1.

View File

@ -10,6 +10,10 @@
<j2eeWebAppName>PMD 10-pmd-jdeveloper-webapp</j2eeWebAppName>
<j2eeWebContextRoot>PMD 10-pmd-jdeveloper-context-root</j2eeWebContextRoot>
<listOfChildren class="oracle.ide.model.DataList">
<Item class="oracle.ide.model.Reference">
<URL path="src/net/sourceforge/pmd/jdeveloper/Version.java"/>
<nodeClass>oracle.jdeveloper.model.JavaSourceNode</nodeClass>
</Item>
<Item class="oracle.ide.model.Reference">
<URL path="lib/asm-3.1.jar"/>
<nodeClass>oracle.jdevimpl.jar.JarFolder</nodeClass>
@ -90,10 +94,6 @@
<URL path="src/net/sourceforge/pmd/jdeveloper/SettingsStorage.java"/>
<nodeClass>oracle.jdeveloper.model.JavaSourceNode</nodeClass>
</Item>
<Item class="oracle.ide.model.Reference">
<URL path="src/net/sourceforge/pmd/jdeveloper/Version.java"/>
<nodeClass>oracle.jdeveloper.model.JavaSourceNode</nodeClass>
</Item>
</listOfChildren>
<ownerMap/>
<projectDocPath>

View File

@ -8,32 +8,33 @@ import java.util.Date;
import java.util.Iterator;
import java.util.Properties;
public class FileStorage implements SettingsStorage {
private File file;
private final transient File file;
public FileStorage(File file) {
public FileStorage(final File file) {
this.file = file;
}
public void save(Properties newProperties) throws SettingsException {
public void save(final Properties newProperties) throws SettingsException {
try {
Properties savedProperties = new Properties();
final Properties savedProperties = new Properties();
if (file.exists()) {
FileInputStream fis = new FileInputStream(file);
final FileInputStream fis = new FileInputStream(file);
savedProperties.load(fis);
fis.close();
}
for (Iterator i = newProperties.keySet().iterator(); i.hasNext();
for (final Iterator i = newProperties.keySet().iterator(); i.hasNext();
) {
String key = (String)i.next();
String value = newProperties.getProperty(key);
final String key = (String)i.next();
final String value = newProperties.getProperty(key);
savedProperties.setProperty(key, value);
}
FileOutputStream fos = new FileOutputStream(file);
final FileOutputStream fos = new FileOutputStream(file);
savedProperties.store(fos,
"PMD-JDeveloper rule selections " + new Date());
fos.close();
@ -43,11 +44,11 @@ public class FileStorage implements SettingsStorage {
}
}
public String load(String key) throws SettingsException {
public String load(final String key) throws SettingsException {
try {
if (file.exists()) {
Properties properties = new Properties();
FileInputStream fis = new FileInputStream(file);
final Properties properties = new Properties();
final FileInputStream fis = new FileInputStream(file);
properties.load(fis);
fis.close();
return properties.getProperty(key);

View File

@ -1,21 +1,22 @@
package net.sourceforge.pmd.jdeveloper;
import oracle.ide.Ide;
import java.util.Iterator;
import java.util.Properties;
import oracle.ide.Ide;
public class IDEStorage implements SettingsStorage {
public void save(Properties props) throws SettingsException {
for (Iterator i = props.keySet().iterator(); i.hasNext(); ) {
String key = (String)i.next();
String value = props.getProperty(key);
public void save(final Properties props) throws SettingsException {
for (final Iterator i = props.keySet().iterator(); i.hasNext(); ) {
final String key = (String)i.next();
final String value = props.getProperty(key);
Ide.setProperty(key, value);
}
}
public String load(String key) throws SettingsException {
public String load(final String key) throws SettingsException {
return Ide.getProperty(key);
}
}

View File

@ -1,8 +1,9 @@
package net.sourceforge.pmd.jdeveloper;
import java.util.List;
import oracle.jdeveloper.compiler.CompilerPage;
import java.util.List;
public class RuleViolationPage extends CompilerPage {
@ -10,7 +11,7 @@ public class RuleViolationPage extends CompilerPage {
super(Plugin.PMD_TITLE, Plugin.PMD_TITLE, null);
}
public void add(List list) {
public void add(final List list) {
super.logMsg(list);
}
}

View File

@ -1,35 +1,36 @@
package net.sourceforge.pmd.jdeveloper;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.RuleSetFactory;
import net.sourceforge.pmd.RuleSetNotFoundException;
import javax.swing.*;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import javax.swing.JCheckBox;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.RuleSetFactory;
import net.sourceforge.pmd.RuleSetNotFoundException;
public class SelectedRules {
// Rule -> JCheckBox
private Map rules = new TreeMap(new Comparator() {
public int compare(Object o1, Object o2) {
Rule r1 = (Rule)o1;
Rule r2 = (Rule)o2;
return r1.getName().compareTo(r2.getName());
private final transient Map rules = new TreeMap(new Comparator() {
public int compare(final Object obj1, final Object obj2) {
final Rule rul1 = (Rule)obj1;
final Rule rul2 = (Rule)obj2;
return rul1.getName().compareTo(rul2.getName());
}
});
public SelectedRules(SettingsStorage settings) throws RuleSetNotFoundException {
RuleSetFactory rsf = new RuleSetFactory();
for (Iterator i = rsf.getRegisteredRuleSets(); i.hasNext(); ) {
RuleSet rs = (RuleSet)i.next();
for (Iterator j = rs.getRules().iterator(); j.hasNext(); ) {
Rule rule = (Rule)j.next();
public SelectedRules(final SettingsStorage settings) throws RuleSetNotFoundException {
final RuleSetFactory rsf = new RuleSetFactory();
for (final Iterator i = rsf.getRegisteredRuleSets(); i.hasNext(); ) {
final RuleSet rset = (RuleSet)i.next();
for (final Iterator j = rset.getRules().iterator(); j.hasNext(); ) {
final Rule rule = (Rule)j.next();
rules.put(rule, createCheckBox(rule.getName(), settings));
}
}
@ -39,10 +40,10 @@ public class SelectedRules {
return rules.size();
}
public Rule getRule(JCheckBox candidate) {
for (Iterator i = rules.keySet().iterator(); i.hasNext(); ) {
Rule rule = (Rule)i.next();
JCheckBox box = (JCheckBox)rules.get(rule);
public Rule getRule(final JCheckBox candidate) {
for (final Iterator i = rules.keySet().iterator(); i.hasNext(); ) {
final Rule rule = (Rule)i.next();
final JCheckBox box = (JCheckBox)rules.get(rule);
if (box.equals(candidate)) {
return rule;
}
@ -51,24 +52,24 @@ public class SelectedRules {
candidate);
}
public JCheckBox get(Object key) {
public JCheckBox get(final Object key) {
return (JCheckBox)rules.get(key);
}
public Object[] getAllBoxes() {
Object[] foo = new Object[rules.size()];
int idx = 0;
for (Iterator i = rules.values().iterator(); i.hasNext(); ) {
for (final Iterator i = rules.values().iterator(); i.hasNext(); ) {
foo[idx] = i.next();
idx++;
}
return foo;
}
public void save(SettingsStorage settings) throws SettingsException {
Properties properties = new Properties();
for (Iterator i = rules.keySet().iterator(); i.hasNext(); ) {
Rule rule = (Rule)i.next();
public void save(final SettingsStorage settings) throws SettingsException {
final Properties properties = new Properties();
for (final Iterator i = rules.keySet().iterator(); i.hasNext(); ) {
final Rule rule = (Rule)i.next();
properties.setProperty("pmd.rule." + rule.getName(),
String.valueOf(get(rule).isSelected()));
}
@ -76,9 +77,9 @@ public class SelectedRules {
}
public RuleSet getSelectedRules() {
RuleSet newRuleSet = new RuleSet();
for (Iterator i = rules.keySet().iterator(); i.hasNext(); ) {
Rule rule = (Rule)i.next();
final RuleSet newRuleSet = new RuleSet();
for (final Iterator i = rules.keySet().iterator(); i.hasNext(); ) {
final Rule rule = (Rule)i.next();
if (get(rule).isSelected()) {
newRuleSet.addRule(rule);
}
@ -86,8 +87,8 @@ public class SelectedRules {
return newRuleSet;
}
private JCheckBox createCheckBox(String name, SettingsStorage settings) {
JCheckBox box = new JCheckBox(name);
private JCheckBox createCheckBox(final String name, final SettingsStorage settings) {
final JCheckBox box = new JCheckBox(name);
try {
box.setSelected(load(settings, name));
} catch (SettingsException se) {
@ -96,8 +97,8 @@ public class SelectedRules {
return box;
}
private boolean load(SettingsStorage settings,
String name) throws SettingsException {
private boolean load(final SettingsStorage settings,
final String name) throws SettingsException {
return Boolean.valueOf(settings.load("pmd.rule." +
name)).booleanValue();
}

View File

@ -1,7 +1,7 @@
package net.sourceforge.pmd.jdeveloper;
public class SettingsException extends Exception {
public SettingsException(String ex) {
super(ex);
public SettingsException(final String exc) {
super(exc);
}
}

View File

@ -27,29 +27,29 @@ import java.util.List;
public class SettingsPanel extends DefaultTraversablePanel {
private class FindListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
FileDialog fdlg =
public void actionPerformed(final ActionEvent evt) {
final FileDialog fdlg =
new FileDialog(new Frame(), "Find", FileDialog.LOAD);
fdlg.setVisible(true);
String selected = fdlg.getDirectory() + fdlg.getFile();
final String selected = fdlg.getDirectory() + fdlg.getFile();
if (fdlg.getFile() == null) {
return;
}
selectedRulesSeparateFileNameField.setText(selected);
sepFileName.setText(selected);
}
}
public class CheckboxList extends JList {
private class CheckboxList extends JList {
private class MyMouseAdapter extends MouseAdapter {
public void mouseEntered(MouseEvent e) {
public void mouseEntered(final MouseEvent evt) {
// No action needed when mouse is entered
}
public void mousePressed(MouseEvent e) {
int index = locationToIndex(e.getPoint());
public void mousePressed(final MouseEvent evt) {
final int index = locationToIndex(evt.getPoint());
if (index != -1) {
JCheckBox box = (JCheckBox)getModel().getElementAt(index);
final JCheckBox box = (JCheckBox)getModel().getElementAt(index);
box.setSelected(!box.isSelected());
repaint();
}
@ -58,16 +58,16 @@ public class SettingsPanel extends DefaultTraversablePanel {
private class MyMouseMotionListener implements MouseMotionListener {
public void mouseDragged(MouseEvent e) {
public void mouseDragged(final MouseEvent evt) {
// No dragging actions needed
}
public void mouseMoved(MouseEvent e) {
int index = locationToIndex(e.getPoint());
public void mouseMoved(final MouseEvent evt) {
final int index = locationToIndex(evt.getPoint());
if (index != -1) {
JCheckBox box = (JCheckBox)getModel().getElementAt(index);
List examples = rules.getRule(box).getExamples();
StringBuffer examplesBuffer = new StringBuffer();
final JCheckBox box = (JCheckBox)getModel().getElementAt(index);
final List examples = rules.getRule(box).getExamples();
final StringBuffer examplesBuffer = new StringBuffer();
if (!examples.isEmpty()) {
for (int i = 0; i < examples.size(); i++) {
examplesBuffer.append(examples.get(i));
@ -87,13 +87,13 @@ public class SettingsPanel extends DefaultTraversablePanel {
}
}
public class CheckboxListCellRenderer implements ListCellRenderer {
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
JCheckBox box = (JCheckBox)value;
private class CheckboxListCellRenderer implements ListCellRenderer {
public Component getListCellRendererComponent(final JList list,
final Object value,
final int index,
final boolean isSelected,
final boolean cellHasFocus) {
final JCheckBox box = (JCheckBox)value;
box.setEnabled(isEnabled());
box.setFont(getFont());
box.setFocusPainted(false);
@ -105,7 +105,7 @@ public class SettingsPanel extends DefaultTraversablePanel {
}
}
public CheckboxList(Object[] args) {
public CheckboxList(final Object[] args) {
super(args);
setCellRenderer(new CheckboxListCellRenderer());
addMouseListener(new MyMouseAdapter());
@ -113,25 +113,25 @@ public class SettingsPanel extends DefaultTraversablePanel {
}
}
public static final String RULE_SELECTIONS_STORED_SEPARATELY =
public static final String STORED_SEPARATELY =
"pmd.settings.separate";
public static final String RULE_SELECTIONS_FILENAME =
public static final String SEL_FILENAME =
"pmd.settings.separate.name";
private JTextArea exampleTextArea = new JTextArea(10, 50);
private JCheckBox selectedRulesStoredSeparatelyBox =
new JCheckBox("", Boolean.valueOf(Ide.getProperty(RULE_SELECTIONS_STORED_SEPARATELY)).booleanValue());
private JTextField selectedRulesSeparateFileNameField = new JTextField(30);
private SelectedRules rules;
private final transient JTextArea exampleTextArea = new JTextArea(10, 50);
private final transient JCheckBox storedSepBox =
new JCheckBox("", Boolean.valueOf(Ide.getProperty(STORED_SEPARATELY)).booleanValue());
private final transient JTextField sepFileName = new JTextField(30);
private transient SelectedRules rules;
public static SettingsStorage createSettingsStorage() {
if (Boolean.valueOf(Ide.getProperty(RULE_SELECTIONS_STORED_SEPARATELY)).booleanValue()) {
return new FileStorage(new File(Ide.getProperty(RULE_SELECTIONS_FILENAME)));
if (Boolean.valueOf(Ide.getProperty(STORED_SEPARATELY)).booleanValue()) {
return new FileStorage(new File(Ide.getProperty(SEL_FILENAME)));
}
return new IDEStorage();
}
public void onEntry(TraversableContext tc) {
public void onEntry(final TraversableContext tcon) {
removeAll();
try {
rules = new SelectedRules(createSettingsStorage());
@ -139,67 +139,67 @@ public class SettingsPanel extends DefaultTraversablePanel {
rsne.printStackTrace();
}
JPanel mainPanel = new JPanel(new BorderLayout());
final JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(createTopPanel(), BorderLayout.NORTH);
mainPanel.add(createRulesSelectionPanel(), BorderLayout.SOUTH);
add(mainPanel);
}
private JPanel createRulesSelectionPanel() {
JPanel checkBoxesPanel = new JPanel();
final JPanel checkBoxesPanel = new JPanel();
checkBoxesPanel.setBorder(BorderFactory.createTitledBorder("Rules"));
JList rulesList = new CheckboxList(rules.getAllBoxes());
final JList rulesList = new CheckboxList(rules.getAllBoxes());
rulesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
checkBoxesPanel.add(new JScrollPane(rulesList), BorderLayout.NORTH);
JPanel examplePanel = new JPanel();
final JPanel examplePanel = new JPanel();
examplePanel.setBorder(BorderFactory.createTitledBorder("Example"));
examplePanel.add(new JScrollPane(exampleTextArea));
JPanel rulesSelectionPanel = new JPanel();
rulesSelectionPanel.setLayout(new BorderLayout());
rulesSelectionPanel.add(checkBoxesPanel, BorderLayout.NORTH);
rulesSelectionPanel.add(examplePanel, BorderLayout.CENTER);
return rulesSelectionPanel;
final JPanel rulesSelPanel = new JPanel();
rulesSelPanel.setLayout(new BorderLayout());
rulesSelPanel.add(checkBoxesPanel, BorderLayout.NORTH);
rulesSelPanel.add(examplePanel, BorderLayout.CENTER);
return rulesSelPanel;
}
private JPanel createTopPanel() {
selectedRulesSeparateFileNameField.setText(Ide.getProperty(RULE_SELECTIONS_FILENAME));
selectedRulesStoredSeparatelyBox.setSelected(Boolean.valueOf(Ide.getProperty(RULE_SELECTIONS_STORED_SEPARATELY)).booleanValue());
sepFileName.setText(Ide.getProperty(SEL_FILENAME));
storedSepBox.setSelected(Boolean.valueOf(Ide.getProperty(STORED_SEPARATELY)).booleanValue());
JPanel topPanel = new JPanel(new BorderLayout());
final JPanel topPanel = new JPanel(new BorderLayout());
topPanel.add(new JLabel(" InfoEther(tm) PMD JDeveloper plugin"),
BorderLayout.NORTH);
JPanel customStoragePanel = new JPanel(new BorderLayout());
customStoragePanel.setBorder(BorderFactory.createTitledBorder("Settings storage"));
final JPanel custStorPanel = new JPanel(new BorderLayout());
custStorPanel.setBorder(BorderFactory.createTitledBorder("Settings storage"));
JPanel customStorageCheckBoxPanel = new JPanel();
customStorageCheckBoxPanel.add(new JLabel("Use centrally managed rule settings?"));
customStorageCheckBoxPanel.add(selectedRulesStoredSeparatelyBox);
customStoragePanel.add(customStorageCheckBoxPanel, BorderLayout.NORTH);
final JPanel custStorCbPanel = new JPanel();
custStorCbPanel.add(new JLabel("Use centrally managed rule settings?"));
custStorCbPanel.add(storedSepBox);
custStorPanel.add(custStorCbPanel, BorderLayout.NORTH);
JPanel customStorageTextFieldPanel = new JPanel();
customStorageTextFieldPanel.add(new JLabel("File:"));
customStorageTextFieldPanel.add(selectedRulesSeparateFileNameField);
JButton findButton = new JButton("Find file");
final JPanel custStorTfPanel = new JPanel();
custStorTfPanel.add(new JLabel("File:"));
custStorTfPanel.add(sepFileName);
final JButton findButton = new JButton("Find file");
findButton.addActionListener(new FindListener());
customStorageTextFieldPanel.add(findButton);
custStorTfPanel.add(findButton);
customStoragePanel.add(customStorageTextFieldPanel,
custStorPanel.add(custStorTfPanel,
BorderLayout.SOUTH);
topPanel.add(customStoragePanel, BorderLayout.CENTER);
topPanel.add(custStorPanel, BorderLayout.CENTER);
return topPanel;
}
public void onExit(TraversableContext tc) {
Ide.setProperty(RULE_SELECTIONS_STORED_SEPARATELY,
String.valueOf(selectedRulesStoredSeparatelyBox.isSelected()));
Ide.setProperty(RULE_SELECTIONS_FILENAME,
selectedRulesSeparateFileNameField.getText());
public void onExit(final TraversableContext tcon) {
Ide.setProperty(STORED_SEPARATELY,
String.valueOf(storedSepBox.isSelected()));
Ide.setProperty(SEL_FILENAME,
sepFileName.getText());
try {
rules.save(createSettingsStorage());
} catch (SettingsException se) {
JOptionPane.showMessageDialog(null,
"Can't save selected rules to the file " +
selectedRulesSeparateFileNameField.getText() +
sepFileName.getText() +
":" + se.getMessage(),
"Can't save settings",
JOptionPane.ERROR_MESSAGE);

View File

@ -9,9 +9,9 @@ import oracle.jdeveloper.model.JProject;
class Version {
public static void setJavaVersion(Context context, PMD pmd) {
JProject project = (JProject) context.getProject();
String source = project.getActiveConfiguration().getJdkVersionNumber().toString();
public static void setJavaVersion(final Context context, final PMD pmd) {
final JProject project = (JProject) context.getProject();
final String source = project.getActiveConfiguration().getJdkVersionNumber().toString();
if (source.startsWith("1.6")) {
pmd.setJavaVersion(SourceType.JAVA_16);
} else if (source.startsWith("1.5")) {