diff --git a/pmd-jdeveloper.10.1.3/etc/build.xml b/pmd-jdeveloper.10.1.3/etc/build.xml index 5674ec349b..c044d639bc 100644 --- a/pmd-jdeveloper.10.1.3/etc/build.xml +++ b/pmd-jdeveloper.10.1.3/etc/build.xml @@ -3,13 +3,13 @@ - - - - - + + + + + - + diff --git a/pmd-jdeveloper.10.1.3/etc/bundle.xml b/pmd-jdeveloper.10.1.3/etc/bundle.xml index bd18fcbbce..0f70ba201f 100644 --- a/pmd-jdeveloper.10.1.3/etc/bundle.xml +++ b/pmd-jdeveloper.10.1.3/etc/bundle.xml @@ -2,10 +2,10 @@ PMD JDeveloper Extension - 4.2.2.0.0 + 4.2.4.2.0 Torsten Kleiber http://pmd.sourceforge.net/ - Provides integrated support for PMD 4.2 in JDeveloper 10.1.3 - 11g Technology Preview 1. + Provides integrated support for PMD 4.2.4 in JDeveloper 10.1.3 - 11g Technology Preview 1. diff --git a/pmd-jdeveloper.10.1.3/etc/center.xml b/pmd-jdeveloper.10.1.3/etc/center.xml index 0648e01f69..cef0a5421b 100644 --- a/pmd-jdeveloper.10.1.3/etc/center.xml +++ b/pmd-jdeveloper.10.1.3/etc/center.xml @@ -2,24 +2,24 @@ PMD JDeveloper Extension - 4.2.2.0.0 + 4.2.4.2.0 Torsten Kleiber http://pmd.sourceforge.net - Provides integrated support for PMD 4.2 in JDeveloper 10.1.3 - 11g Technology Preview 1. - http://downloads.sourceforge.net/pmd/pmd-jdeveloper1013-bundle-4.2.2.0.0.zip + Provides integrated support for PMD 4.2.4 in JDeveloper 10.1.3 - 11g Technology Preview 1. + http://downloads.sourceforge.net/pmd/pmd-jdeveloper1013-bundle-4.2.4.2.0.zip PMD JDeveloper Extension - 4.1.3.0.0 + 4.2.4.3.0 Torsten Kleiber http://pmd.sourceforge.net - Provides integrated support for PMD 4.1 in JDeveloper 11g Technology Preview 2. - http://downloads.sourceforge.net/pmd/pmd-jdeveloper1111-bundle-4.1.3.0.0.zip + Provides integrated support for PMD 4.2.4 in JDeveloper 11g. + http://downloads.sourceforge.net/pmd/pmd-jdeveloper1111-bundle-4.2.4.3.0.zip - + \ No newline at end of file diff --git a/pmd-jdeveloper.10.1.3/etc/changelog.txt b/pmd-jdeveloper.10.1.3/etc/changelog.txt index 4323e7bff0..de97bde8c2 100644 --- a/pmd-jdeveloper.10.1.3/etc/changelog.txt +++ b/pmd-jdeveloper.10.1.3/etc/changelog.txt @@ -1,3 +1,6 @@ +October 21, 2008 - 4.2.4: +Updated PMD version to 4.2.4 for 9.0.5 to 11.1.1 + 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. diff --git a/pmd-jdeveloper.10.1.3/etc/extension.xml b/pmd-jdeveloper.10.1.3/etc/extension.xml index c22d9c1b83..cf5685c328 100644 --- a/pmd-jdeveloper.10.1.3/etc/extension.xml +++ b/pmd-jdeveloper.10.1.3/etc/extension.xml @@ -1,6 +1,6 @@ PMD JDeveloper Extension Torsten Kleiber @@ -8,10 +8,9 @@ oracle.jdeveloper - net.sourceforge.pmd.jdeveloper.4.2.2.0.0/lib/pmd-4.2.jar - net.sourceforge.pmd.jdeveloper.4.2.2.0.0/lib/jaxen-1.1.1.jar - net.sourceforge.pmd.jdeveloper.4.2.2.0.0/lib/asm-3.1.jar - C:/Oracle/10gJD10133/jdk/jre/lib/rt.jar + net.sourceforge.pmd.jdeveloper.4.2.4.2.0/lib/pmd-4.2.4.jar + net.sourceforge.pmd.jdeveloper.4.2.4.2.0/lib/jaxen-1.1.1.jar + net.sourceforge.pmd.jdeveloper.4.2.4.2.0/lib/asm-3.1.jar @@ -20,7 +19,7 @@ - Provides integrated support for PMD 4.1 in JDeveloper 10.1.3 - 11g Technology Preview 1. + Provides integrated support for PMD 4.2 in JDeveloper 10.1.3 - 11g Technology Preview 1. false diff --git a/pmd-jdeveloper.10.1.3/lib/pmd-4.2.jar b/pmd-jdeveloper.10.1.3/lib/pmd-4.2.4.jar similarity index 64% rename from pmd-jdeveloper.10.1.3/lib/pmd-4.2.jar rename to pmd-jdeveloper.10.1.3/lib/pmd-4.2.4.jar index f355ac4181..45face599c 100644 Binary files a/pmd-jdeveloper.10.1.3/lib/pmd-4.2.jar and b/pmd-jdeveloper.10.1.3/lib/pmd-4.2.4.jar differ diff --git a/pmd-jdeveloper.10.1.3/pmd-jdeveloper1013.jpr b/pmd-jdeveloper.10.1.3/pmd-jdeveloper1013.jpr index 7c8e08311b..9274aa7df9 100644 --- a/pmd-jdeveloper.10.1.3/pmd-jdeveloper1013.jpr +++ b/pmd-jdeveloper.10.1.3/pmd-jdeveloper1013.jpr @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + @@ -108,13 +108,13 @@ - + - + @@ -125,7 +125,7 @@ - + @@ -140,7 +140,7 @@ - + diff --git a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/CPDViolationPage.java b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/CPDViolationPage.java new file mode 100644 index 0000000000..7b2968bc06 --- /dev/null +++ b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/CPDViolationPage.java @@ -0,0 +1,87 @@ +package net.sourceforge.pmd.jdeveloper; + +import java.awt.Component; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreeSelectionModel; + +import net.sourceforge.pmd.cpd.Match; +import net.sourceforge.pmd.cpd.TokenEntry; + +import oracle.ide.ceditor.CodeEditor; +import oracle.ide.editor.EditorManager; +import oracle.ide.layout.ViewId; +import oracle.ide.log.AbstractLogPage; +import oracle.ide.model.Node; + + +public class CPDViolationPage extends AbstractLogPage implements TreeSelectionListener { + + private final transient JScrollPane scrollPane; + private final transient JTree tree; + private final transient DefaultMutableTreeNode top; + public final transient Map cpdFileToNodeMap = + new HashMap(); // whew, this is kludgey + + public CPDViolationPage() { + super(new ViewId("PMDPage", Plugin.CPD_TITLE), null, false); + top = new DefaultMutableTreeNode("CPD"); + tree = new JTree(top); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + tree.addTreeSelectionListener(this); + scrollPane = new JScrollPane(tree); + } + + public void valueChanged(final TreeSelectionEvent event) { + final DefaultMutableTreeNode node = + (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); + if (node != null && node.isLeaf()) { + final CPDViolationWrapper nodeInfo = + (CPDViolationWrapper)node.getUserObject(); + EditorManager.getEditorManager().openDefaultEditorInFrame(nodeInfo.file.getURL()); + ((CodeEditor)EditorManager.getEditorManager().getCurrentEditor()).gotoLine(nodeInfo.mark.getBeginLine(), + 0, + false); + } + } + + public void add(final Match match) { + final Node file1 = + (Node)cpdFileToNodeMap.get(match.getFirstMark().getTokenSrcID()); + final DefaultMutableTreeNode matchNode = + new DefaultMutableTreeNode(file1.getShortLabel() + " contains a " + + match.getLineCount() + + " line block of duplicated code", true); + top.add(matchNode); + for (final Iterator i = match.iterator(); i.hasNext(); ) { + final TokenEntry mark = (TokenEntry)i.next(); + final Node file = (Node)cpdFileToNodeMap.get(mark.getTokenSrcID()); + final DefaultMutableTreeNode markTreeNode = + new DefaultMutableTreeNode(new CPDViolationWrapper(mark, file, + file.getShortLabel() + + " has some at line " + + mark.getBeginLine()), + false); + matchNode.add(markTreeNode); + } + } + + public Component getGUI() { + return scrollPane; + } + + public void clearAll() { + top.removeAllChildren(); + tree.repaint(); + scrollPane.repaint(); + //tree.removeSelectionPath(new TreePath(new Object[] {top})); + } +} diff --git a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/CPDViolationWrapper.java b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/CPDViolationWrapper.java new file mode 100644 index 0000000000..26afd3f648 --- /dev/null +++ b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/CPDViolationWrapper.java @@ -0,0 +1,23 @@ +package net.sourceforge.pmd.jdeveloper; + +import net.sourceforge.pmd.cpd.TokenEntry; + +import oracle.ide.model.Node; + + +public class CPDViolationWrapper { + private final transient String label; + public transient Node file; + public transient TokenEntry mark; + + public CPDViolationWrapper(final TokenEntry mark, final Node file, + final String label) { + this.label = label; + this.mark = mark; + this.file = file; + } + + public String toString() { + return label; + } +} diff --git a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/FileStorage.java b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/FileStorage.java index a1c62a4f5a..7f39eeff04 100644 --- a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/FileStorage.java +++ b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/FileStorage.java @@ -2,7 +2,9 @@ package net.sourceforge.pmd.jdeveloper; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; import java.util.Date; import java.util.Iterator; @@ -38,9 +40,12 @@ public class FileStorage implements SettingsStorage { savedProperties.store(fos, "PMD-JDeveloper rule selections " + new Date()); fos.close(); - } catch (Exception e) { - e.printStackTrace(); - throw new SettingsException(e.getMessage()); + } catch (FileNotFoundException e) { + Util.logMessage(e.getStackTrace()); + Util.showError(e, Plugin.PMD_TITLE); + } catch (IOException e) { + Util.logMessage(e.getStackTrace()); + Util.showError(e, Plugin.PMD_TITLE); } } @@ -53,11 +58,11 @@ public class FileStorage implements SettingsStorage { fis.close(); return properties.getProperty(key); } - return "false"; - } catch (Exception e) { - e.printStackTrace(); - throw new SettingsException(e.getMessage()); + } catch (IOException e) { + Util.logMessage(e.getStackTrace()); + Util.showError(e, Plugin.PMD_TITLE); } + return "false"; } } diff --git a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Plugin.java b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Plugin.java index 811e7207e4..9eee67d423 100644 --- a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Plugin.java +++ b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Plugin.java @@ -1,7 +1,5 @@ package net.sourceforge.pmd.jdeveloper; -import java.awt.Component; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -14,22 +12,16 @@ import java.util.Map; import javax.swing.JMenuItem; import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.JTree; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeSelectionModel; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.PMDException; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.RuleSetNotFoundException; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.cpd.CPD; import net.sourceforge.pmd.cpd.LanguageFactory; import net.sourceforge.pmd.cpd.Match; -import net.sourceforge.pmd.cpd.TokenEntry; import oracle.ide.Addin; import oracle.ide.AddinManager; @@ -42,8 +34,6 @@ import oracle.ide.controller.ContextMenuListener; import oracle.ide.controller.Controller; import oracle.ide.controller.IdeAction; import oracle.ide.editor.EditorManager; -import oracle.ide.layout.ViewId; -import oracle.ide.log.AbstractLogPage; import oracle.ide.log.LogManager; import oracle.ide.log.LogPage; import oracle.ide.log.LogWindow; @@ -62,85 +52,6 @@ import oracle.jdeveloper.model.JavaSourceNode; public class Plugin implements Addin, Controller, ContextMenuListener { - public class CPDViolationPage extends AbstractLogPage implements TreeSelectionListener { - - private final transient JScrollPane scrollPane; - private final transient JTree tree; - private final transient DefaultMutableTreeNode top; - - public CPDViolationPage() { - super(new ViewId("PMDPage", Plugin.CPD_TITLE), null, false); - top = new DefaultMutableTreeNode("CPD"); - tree = new JTree(top); - tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - tree.addTreeSelectionListener(this); - scrollPane = new JScrollPane(tree); - } - - public void valueChanged(final TreeSelectionEvent event) { - final DefaultMutableTreeNode node = - (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); - if (node != null && node.isLeaf()) { - final CPDViolationWrapper nodeInfo = - (CPDViolationWrapper)node.getUserObject(); - EditorManager.getEditorManager().openDefaultEditorInFrame(nodeInfo.file.getURL()); - ((CodeEditor)EditorManager.getEditorManager().getCurrentEditor()).gotoLine(nodeInfo.mark.getBeginLine(), - 0, - false); - } - } - - public void add(final Match match) { - final Node file1 = - (Node)cpdFileToNodeMap.get(match.getFirstMark().getTokenSrcID()); - final DefaultMutableTreeNode matchNode = - new DefaultMutableTreeNode(file1.getShortLabel() + - " contains a " + - match.getLineCount() + - " line block of duplicated code", - true); - top.add(matchNode); - for (final Iterator i = match.iterator(); i.hasNext(); ) { - final TokenEntry mark = (TokenEntry)i.next(); - final Node file = (Node)cpdFileToNodeMap.get(mark.getTokenSrcID()); - final DefaultMutableTreeNode markTreeNode = - new DefaultMutableTreeNode(new CPDViolationWrapper(mark, - file, - file.getShortLabel() + - " has some at line " + - mark.getBeginLine()), - false); - matchNode.add(markTreeNode); - } - } - - public Component getGUI() { - return scrollPane; - } - - public void clearAll() { - top.removeAllChildren(); - tree.repaint(); - scrollPane.repaint(); - //tree.removeSelectionPath(new TreePath(new Object[] {top})); - } - } - - private static class CPDViolationWrapper { - private final transient String label; - public transient Node file; - public transient TokenEntry mark; - - public CPDViolationWrapper(final TokenEntry mark, final Node file, final String label) { - this.label = label; - this.mark = mark; - this.file = file; - } - - public String toString() { - return label; - } - } public static final String RUN_PMD_CMD = "net.sourceforge.pmd.jdeveloper.Check"; @@ -162,8 +73,8 @@ public class Plugin implements Addin, Controller, ContextMenuListener { private transient CPDViolationPage cpdViolationPage; private transient boolean added; - private final transient Map pmdFileToNodeMap = new HashMap(); // whew, this is kludgey - private final transient Map cpdFileToNodeMap = new HashMap(); // whew, this is kludgey + private final transient Map pmdFileToNodeMap = + new HashMap(); // whew, this is kludgey // Addin @@ -177,13 +88,16 @@ public class Plugin implements Addin, Controller, ContextMenuListener { pmdMenuItem.setText(PMD_TITLE); pmdMenuItem.setMnemonic('P'); - /* - IdeAction cpdAction = IdeAction.get(RUN_CPD_CMD_ID, AddinManager.getAddinManager().getCommand(RUN_CPD_CMD_ID, RUN_CPD_CMD), CPD_TITLE, CPD_TITLE, null, null, null, true); + /* TODO CPD plugin + IdeAction cpdAction = + IdeAction.get(RUN_CPD_CMD_ID, AddinManager.getAddinManager().getCommand(RUN_CPD_CMD_ID, + RUN_CPD_CMD), + CPD_TITLE, CPD_TITLE, null, null, null, true); cpdAction.addController(this); cpdMenuItem = Ide.getMenubar().createMenuItem(cpdAction); cpdMenuItem.setText(CPD_TITLE); cpdMenuItem.setMnemonic('C'); -*/ + */ NavigatorManager.getWorkspaceNavigatorManager().addContextMenuListener(this, null); @@ -219,128 +133,129 @@ public class Plugin implements Addin, Controller, ContextMenuListener { } - public boolean handleEvent(final IdeAction ideAction, final Context context) { + public boolean handleEvent(final IdeAction ideAction, + final Context context) { if (!added) { - LogManager.getLogManager().addPage(ruleViolationPage); - LogManager.getLogManager().showLog(); - added = true; + addLogPage(); } if (ideAction.getCommandId() == RUN_PMD_CMD_ID) { - try { - pmdFileToNodeMap.clear(); - final PMD pmd = new PMD(); - Version.setJavaVersion(context, pmd); - - final SelectedRules rules = - new SelectedRules(SettingsPanel.createSettingsStorage()); - final RuleContext ctx = new RuleContext(); - ctx.setReport(new Report()); - if (context.getElement() instanceof - RelativeDirectoryContextFolder) { - final RelativeDirectoryContextFolder folder = - (RelativeDirectoryContextFolder)context.getElement(); - checkTree(folder.getChildren(), pmd, rules, ctx); - } else if (context.getElement() instanceof Project) { - final Project project = (Project)context.getElement(); - checkTree(project.getChildren(), pmd, rules, ctx); - } else if (context.getElement() instanceof JavaSourceNode || - context.getView() instanceof CodeEditor) { - pmdFileToNodeMap.put(context.getNode().getLongLabel(), - context.getNode()); - ctx.setSourceCodeFilename(context.getNode().getLongLabel()); - pmd.processFile(context.getNode().getInputStream(), - rules.getSelectedRules(), ctx); - render(ctx); - } - return true; - } catch (PMDException e) { - // TODO reroute the whole printStackTrace to the IDE log window - e.printStackTrace(); - e.getCause().printStackTrace(); - JOptionPane.showMessageDialog(null, - "Error while running PMD: " + - "\n" + e.getMessage() + "\n" + - e.getCause().getMessage(), - PMD_TITLE, - JOptionPane.ERROR_MESSAGE); - } catch (Exception e) { - logMessage(e.getMessage()); - e.printStackTrace(); - JOptionPane.showMessageDialog(null, - "Error while running PMD: " + - "\n" + e.getMessage(), PMD_TITLE, - JOptionPane.ERROR_MESSAGE); - } + runPmd(context); } else if (ideAction.getCommandId() == RUN_CPD_CMD_ID) { - try { - cpdFileToNodeMap.clear(); - - // TODO get minimum tokens from prefs panel - final CPD cpd = - new CPD(100, new LanguageFactory().createLanguage("java")); - - // add all files to CPD - if (context.getElement() instanceof - RelativeDirectoryContextFolder) { - final RelativeDirectoryContextFolder folder = - (RelativeDirectoryContextFolder)context.getElement(); - glomToCPD(folder.getChildren(), cpd); - } else if (context.getElement() instanceof Project) { - final Project project = (Project)context.getElement(); - glomToCPD(project.getChildren(), cpd); - } else if (context.getElement() instanceof JavaSourceNode) { - cpd.add(new File(context.getNode().getLongLabel())); - cpdFileToNodeMap.put(context.getNode().getLongLabel(), - context.getNode()); - } - - cpd.go(); - - cpdViolationPage.show(); - cpdViolationPage.clearAll(); - if (!cpd.getMatches().hasNext()) { - JOptionPane.showMessageDialog(null, "No problems found", - CPD_TITLE, - JOptionPane.INFORMATION_MESSAGE); - final LogPage page = LogManager.getLogManager().getMsgPage(); - if (page instanceof LogWindow) { - ((LogWindow)page).show(); - } - } else { - for (final Iterator i = cpd.getMatches(); i.hasNext(); ) { - cpdViolationPage.add((Match)i.next()); - } - } - - - } catch (Exception e) { - e.printStackTrace(); - JOptionPane.showMessageDialog(null, - "Error while running CPD: " + - e.getMessage(), CPD_TITLE, - JOptionPane.ERROR_MESSAGE); - } + runCpd(context); } return true; } + private void runCpd(final Context context) { + try { + cpdViolationPage.cpdFileToNodeMap.clear(); + // TODO get minimum tokens from prefs panel + final CPD cpd = + new CPD(100, new LanguageFactory().createLanguage("java")); + + // add all files to CPD + if (context.getElement() instanceof + RelativeDirectoryContextFolder) { + final RelativeDirectoryContextFolder folder = + (RelativeDirectoryContextFolder)context.getElement(); + glomToCPD(folder.getChildren(), cpd); + } else if (context.getElement() instanceof Project) { + final Project project = (Project)context.getElement(); + glomToCPD(project.getChildren(), cpd); + } else if (context.getElement() instanceof JavaSourceNode) { + cpd.add(new File(context.getNode().getLongLabel())); + cpdViolationPage.cpdFileToNodeMap.put(context.getNode().getLongLabel(), + context.getNode()); + } + + cpd.go(); + + cpdViolationPage.show(); + cpdViolationPage.clearAll(); + if (cpd.getMatches().hasNext()) { + for (final Iterator i = cpd.getMatches(); i.hasNext(); ) { + cpdViolationPage.add((Match)i.next()); + } + } else { + JOptionPane.showMessageDialog(null, "No problems found", + CPD_TITLE, + JOptionPane.INFORMATION_MESSAGE); + final LogPage page = LogManager.getLogManager().getMsgPage(); + if (page instanceof LogWindow) { + ((LogWindow)page).show(); + } + } + + } catch (IOException e) { + Util.logMessage(e.getStackTrace()); + Util.showError(e, CPD_TITLE); + } + } + + private void runPmd(final Context context) { + try { + pmdFileToNodeMap.clear(); + final PMD pmd = new PMD(); + Version.setJavaVersion(context, pmd); + + final SelectedRules rules = + new SelectedRules(SettingsPanel.createSettingsStorage()); + final RuleContext ctx = new RuleContext(); + ctx.setReport(new Report()); + if (context.getElement() instanceof + RelativeDirectoryContextFolder) { + final RelativeDirectoryContextFolder folder = + (RelativeDirectoryContextFolder)context.getElement(); + checkTree(folder.getChildren(), pmd, rules, ctx); + } else if (context.getElement() instanceof Project) { + final Project project = (Project)context.getElement(); + checkTree(project.getChildren(), pmd, rules, ctx); + } else if (context.getElement() instanceof JavaSourceNode || + context.getView() instanceof CodeEditor) { + pmdFileToNodeMap.put(context.getNode().getLongLabel(), + context.getNode()); + ctx.setSourceCodeFilename(context.getNode().getLongLabel()); + pmd.processFile(context.getNode().getInputStream(), + rules.getSelectedRules(), ctx); + render(ctx); + } + } catch (IOException e) { + Util.logMessage(e.getStackTrace()); + Util.showError(e, PMD_TITLE); + } catch (PMDException e) { + Util.logMessage(e.getStackTrace()); + Util.showError(e, PMD_TITLE); + } catch (RuleSetNotFoundException e) { + Util.logMessage(e.getStackTrace()); + Util.showError(e, PMD_TITLE); + } + } + + private void addLogPage() { + LogManager.getLogManager().addPage(ruleViolationPage); + LogManager.getLogManager().showLog(); + added = true; + } + public boolean update(final IdeAction ideAction, final Context context) { return false; } - public void checkCommands(Context context, Controller controller) { + public void checkCommands(final Context context, + final Controller controller) { + // TODO don't know why plugin does not work after remove } // Controller // ContextMenuListener public void menuWillHide(final ContextMenu contextMenu) { - // Nothing to do + // Nothing to do } public void menuWillShow(final ContextMenu contextMenu) { final Element doc = contextMenu.getContext().getElement(); - View view = contextMenu.getContext().getView(); + final View view = contextMenu.getContext().getView(); // RelativeDirectoryContextFolder -> a package if (doc instanceof Project || doc instanceof JavaSourceNode || doc instanceof RelativeDirectoryContextFolder || @@ -372,9 +287,10 @@ public class Plugin implements Addin, Controller, ContextMenuListener { } } else { final List list = new ArrayList(); - for (final Iterator i = ctx.getReport().iterator(); i.hasNext(); ) { + for (Iterator i = ctx.getReport().iterator(); i.hasNext(); ) { final RuleViolation viol = (RuleViolation)i.next(); - final Node node = (Node)pmdFileToNodeMap.get(viol.getFilename()); + final Node node = + (Node)pmdFileToNodeMap.get(viol.getFilename()); list.add(new IdeLog.Message(Ide.getActiveWorkspace(), Ide.getActiveProject(), new IdeStorage(node), @@ -386,7 +302,8 @@ public class Plugin implements Addin, Controller, ContextMenuListener { } } - private void glomToCPD(final Iterator iter, final CPD cpd) throws IOException { + private void glomToCPD(final Iterator iter, + final CPD cpd) throws IOException { while (iter.hasNext()) { final Object obj = iter.next(); if (!(obj instanceof JavaSourceNode)) { @@ -395,14 +312,17 @@ public class Plugin implements Addin, Controller, ContextMenuListener { final JavaSourceNode candidate = (JavaSourceNode)obj; if (candidate.getLongLabel().endsWith(".java") && new File(candidate.getLongLabel()).exists()) { - cpdFileToNodeMap.put(candidate.getLongLabel(), candidate); + cpdViolationPage.cpdFileToNodeMap.put(candidate.getLongLabel(), + candidate); cpd.add(new File(candidate.getLongLabel())); } } } - private void checkTree(final Iterator iter, final PMD pmd, final SelectedRules rules, - final RuleContext ctx) throws IOException, PMDException { + private void checkTree(final Iterator iter, final PMD pmd, + final SelectedRules rules, + final RuleContext ctx) throws IOException, + PMDException { while (iter.hasNext()) { final Object obj = iter.next(); if (!(obj instanceof JavaSourceNode)) { @@ -422,8 +342,4 @@ public class Plugin implements Addin, Controller, ContextMenuListener { render(ctx); } - private static final void logMessage(final String msg) { - LogManager.getLogManager().showLog(); - LogManager.getLogManager().getMsgPage().log(msg + "\n"); - } } diff --git a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/RuleSetWriter.java b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/RuleSetWriter.java deleted file mode 100644 index 74d05c4310..0000000000 --- a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/RuleSetWriter.java +++ /dev/null @@ -1,287 +0,0 @@ -package net.sourceforge.pmd.jdeveloper; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.FactoryConfigurationError; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleReference; -import net.sourceforge.pmd.RuleSet; - -import net.sourceforge.pmd.RuleSetReference; - -import org.w3c.dom.CDATASection; -import org.w3c.dom.DOMException; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Text; - -/** - * This class represents a way to serialize a RuleSet to an XML configuration file. - * TODO Changed copy of net.sourceforge.pmd.RuleSetWriter - * because of errors in oracle - */ -public class RuleSetWriter { - private final OutputStream outputStream; - private Document document; - private Set ruleSetFileNames; - - public RuleSetWriter(OutputStream outputStream) { - this.outputStream = outputStream; - } - - public void close() throws IOException { - outputStream.flush(); - outputStream.close(); - } - - public void write(RuleSet ruleSet) { - try { - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - this.document = documentBuilder.newDocument(); - this.ruleSetFileNames = new HashSet(); - - Element ruleSetElement = createRuleSetElement(ruleSet); - document.appendChild(ruleSetElement); - - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - transformer.setOutputProperty(OutputKeys.METHOD, "xml"); - // This is as close to pretty printing as we'll get using standard Java APIs. - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - // TODO not working under oracle - // transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3"); - transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - transformer.transform(new DOMSource(document), new StreamResult(outputStream)); - } catch (DOMException e) { - throw new RuntimeException(e); - } catch (FactoryConfigurationError e) { - throw new RuntimeException(e); - } catch (ParserConfigurationException e) { - throw new RuntimeException(e); - } catch (TransformerException e) { - throw new RuntimeException(e); - } - } - - private Element createRuleSetElement(RuleSet ruleSet) { - Element ruleSetElement = document.createElement("ruleset"); - /* TODO not importable under oracle - ruleSetElement.setAttribute("xmlns", "http://pmd.sf.net/ruleset/1.0.0"); - ruleSetElement.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", - "http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"); - ruleSetElement.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation", - "http://pmd.sf.net/ruleset_xml_schema.xsd"); - */ - ruleSetElement.setAttribute("name", ruleSet.getName()); - - if (ruleSet.getLanguage() != null) { - ruleSetElement.setAttribute("language", ruleSet.getLanguage().getName()); - } - - Element descriptionElement = createDescriptionElement(ruleSet.getDescription()); - ruleSetElement.appendChild(descriptionElement); - - for (String excludePattern : ruleSet.getExcludePatterns()) { - Element excludePatternElement = createExcludePatternElement(excludePattern); - ruleSetElement.appendChild(excludePatternElement); - } - for (String includePattern : ruleSet.getIncludePatterns()) { - Element includePatternElement = createIncludePatternElement(includePattern); - ruleSetElement.appendChild(includePatternElement); - } - for (Rule rule : ruleSet.getRules()) { - Element ruleElement = createRuleElement(rule); - if (ruleElement != null) { - ruleSetElement.appendChild(ruleElement); - } - } - - return ruleSetElement; - } - - private Element createDescriptionElement(String description) { - return createTextElement("description", description); - } - - private Element createExcludePatternElement(String excludePattern) { - return createTextElement("exclude-pattern", excludePattern); - } - - private Element createIncludePatternElement(String includePattern) { - return createTextElement("include-pattern", includePattern); - } - - private Element createRuleElement(Rule rule) { - if (rule instanceof RuleReference) { - RuleReference ruleReference = (RuleReference)rule; - RuleSetReference ruleSetReference = ruleReference.getRuleSetReference(); - if (ruleSetReference.isAllRules()) { - if (!ruleSetFileNames.contains(ruleSetReference.getRuleSetFileName())) { - ruleSetFileNames.add(ruleSetReference.getRuleSetFileName()); - Element ruleSetReferenceElement = createRuleSetReferenceElement(ruleSetReference); - return ruleSetReferenceElement; - } else { - return null; - } - } else { - String name = ruleReference.getOverriddenName(); - String ref = ruleReference.getRuleSetReference().getRuleSetFileName() + "/" + ruleReference.getName(); - String message = ruleReference.getOverriddenMessage(); - String externalInfoUrl = ruleReference.getOverriddenExternalInfoUrl(); - String description = ruleReference.getOverriddenDescription(); - Integer priority = ruleReference.getOverriddenPriority(); - Properties properties = ruleReference.getOverriddenProperties(); - List examples = ruleReference.getOverriddenExamples(); - return createSingleRuleElement(name, null, ref, message, externalInfoUrl, null, null, null, - description, priority, properties, examples); - } - } else { - return createSingleRuleElement(rule.getName(), rule.getSince(), null, rule.getMessage(), - rule.getExternalInfoUrl(), rule.getRuleClass(), rule.usesDFA(), rule.usesTypeResolution(), - rule.getDescription(), rule.getPriority(), rule.getProperties(), rule.getExamples()); - } - } - - private Element createSingleRuleElement(String name, String since, String ref, String message, - String externalInfoUrl, String clazz, Boolean dfa, Boolean typeResolution, String description, - Integer priority, Properties properties, List examples) { - Element ruleElement = document.createElement("rule"); - if (name != null) { - ruleElement.setAttribute("name", name); - } - if (since != null) { - ruleElement.setAttribute("since", since); - } - if (ref != null) { - ruleElement.setAttribute("ref", ref); - } - if (message != null) { - ruleElement.setAttribute("message", message); - } - if (externalInfoUrl != null) { - ruleElement.setAttribute("externalInfoUrl", externalInfoUrl); - } - if (clazz != null) { - ruleElement.setAttribute("class", clazz); - } - if (dfa != null) { - ruleElement.setAttribute("dfa", dfa.toString()); - } - if (typeResolution != null) { - ruleElement.setAttribute("typeResolution", typeResolution.toString()); - } - - if (description != null) { - Element descriptionElement = createDescriptionElement(description); - ruleElement.appendChild(descriptionElement); - } - if (priority != null) { - Element priorityElement = createPriorityElement(priority); - ruleElement.appendChild(priorityElement); - } - if (properties != null) { - Element propertiesElement = createPropertiesElement(properties); - if (propertiesElement != null) { - ruleElement.appendChild(propertiesElement); - } - } - if (examples != null) { - for (String example : examples) { - Element exampleElement = createExampleElement(example); - ruleElement.appendChild(exampleElement); - } - } - return ruleElement; - } - - private Element createRuleSetReferenceElement(RuleSetReference ruleSetReference) { - Element ruleSetReferenceElement = document.createElement("rule"); - ruleSetReferenceElement.setAttribute("ref", ruleSetReference.getRuleSetFileName()); - for (String exclude : ruleSetReference.getExcludes()) { - Element excludeElement = createExcludeElement(exclude); - ruleSetReferenceElement.appendChild(excludeElement); - } - return ruleSetReferenceElement; - } - - private Element createExcludeElement(String exclude) { - return createTextElement("exclude", exclude); - } - - private Element createExampleElement(String example) { - return createCDATASectionElement("example", example); - } - - private Element createPriorityElement(Integer priority) { - return createTextElement("priority", priority.toString()); - } - - private Element createPropertiesElement(Properties properties) { - if (properties != null && !properties.isEmpty()) { - Element propertiesElement = document.createElement("properties"); - for (Map.Entry entry : properties.entrySet()) { - Element propertyElement = createPropertyElement(properties, (String)entry.getKey(), - (String)entry.getValue()); - if (propertyElement != null) { - propertiesElement.appendChild(propertyElement); - } - } - return propertiesElement; - } else { - return null; - } - } - - private Element createPropertyElement(Properties properties, String key, String value) { - Element propertyElement = document.createElement("property"); - propertyElement.setAttribute("name", key); - if ("xpath".equals(key)) { - if (properties.containsKey("pluginname")) { - propertyElement.setAttribute("pluginname", properties.getProperty("pluginname")); - } - Element valueElement = createCDATASectionElement("value", value); - propertyElement.appendChild(valueElement); - } else if ("pluginname".equals(key)) { - if (properties.containsKey("xpath")) { - return null; - } else { - propertyElement.setAttribute("value", value); - } - } else { - propertyElement.setAttribute("value", value); - } - - return propertyElement; - } - - private Element createTextElement(String name, String value) { - Element element = document.createElement(name); - Text text = document.createTextNode(value); - element.appendChild(text); - return element; - } - - private Element createCDATASectionElement(String name, String value) { - Element element = document.createElement(name); - CDATASection cdataSection = document.createCDATASection(value); - element.appendChild(cdataSection); - return element; - } -} diff --git a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/SelectedRules.java b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/SelectedRules.java index ee375058d5..8d7e734af6 100644 --- a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/SelectedRules.java +++ b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/SelectedRules.java @@ -46,8 +46,11 @@ public class SelectedRules { return rule; } } - throw new RuntimeException("Couldn't find a rule that mapped to the passed in JCheckBox " + - candidate); + final SettingsException exc = + new SettingsException("Couldn't find a rule that mapped to the passed in JCheckBox " + + candidate); + Util.showError(exc, Plugin.PMD_TITLE); + return null; } public JCheckBox get(final Object key) { @@ -77,12 +80,14 @@ public class SelectedRules { return newRuleSet; } - private JCheckBox createCheckBox(final String name, final SettingsStorage settings) { + private JCheckBox createCheckBox(final String name, + final SettingsStorage settings) { final JCheckBox box = new JCheckBox(name); try { box.setSelected(load(settings, name)); } catch (SettingsException se) { - System.out.println("Can't load settings so this rule will not be enabled"); + Util.logMessage(se.getStackTrace()); + Util.showError(se, Plugin.PMD_TITLE); } return box; } diff --git a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/SettingsPanel.java b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/SettingsPanel.java index d1a3b36e61..774c1ad2b5 100644 --- a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/SettingsPanel.java +++ b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/SettingsPanel.java @@ -37,7 +37,7 @@ import net.sourceforge.pmd.RuleSet; import net.sourceforge.pmd.RuleSetFactory; import net.sourceforge.pmd.RuleSetNotFoundException; import net.sourceforge.pmd.RuleSets; -import net.sourceforge.pmd.jdeveloper.RuleSetWriter; +import net.sourceforge.pmd.RuleSetWriter; import oracle.ide.panels.DefaultTraversablePanel; import oracle.ide.panels.TraversableContext; @@ -163,7 +163,8 @@ public class SettingsPanel extends DefaultTraversablePanel { try { rules = new SelectedRules(createSettingsStorage()); } catch (RuleSetNotFoundException rsne) { - rsne.printStackTrace(); + Util.logMessage(rsne.getStackTrace()); + Util.showError(rsne, Plugin.PMD_TITLE); } final JPanel mainPanel = new JPanel(new BorderLayout()); @@ -237,11 +238,11 @@ public class SettingsPanel extends DefaultTraversablePanel { try { ruleSets = factory.createRuleSets(fileLocation); } catch (RuleSetNotFoundException e) { - System.err.println("Error during reading ruleset : " + - e.getMessage()); + Util.logMessage(e.getStackTrace()); + Util.showError(e, Plugin.PMD_TITLE); } if (ruleSets == null) { - System.out.println("No rules to import"); + Util.logMessage("No rules to import"); } else { final ListModel model = rulesList.getModel(); final Set allRules = ruleSets.getAllRules(); @@ -271,26 +272,20 @@ public class SettingsPanel extends DefaultTraversablePanel { RuleSetWriter ruleSetWriter = null; try { outputStream = new FileOutputStream(fileLocation); - ruleSetWriter = new RuleSetWriter(outputStream); + ruleSetWriter = new RuleSetWriter(outputStream, false); ruleSetWriter.write(selectedRules); outputStream.flush(); -// } catch (RuntimeException e) { -// JOptionPane.showMessageDialog(null, -// "Can't save selected rules to the file " + -// e.getMessage(), -// "Can't save settings", -// JOptionPane.ERROR_MESSAGE); } catch (IOException e) { - System.err.println("Error during file transfer : " + - e.getMessage()); + Util.logMessage(e.getStackTrace()); + Util.showError(e, Plugin.PMD_TITLE); } finally { if (outputStream != null) { try { ruleSetWriter.close(); outputStream.close(); } catch (IOException e) { - System.err.println("Error during file transfer closing : " + - e.getMessage()); + Util.logMessage(e.getStackTrace()); + Util.showError(e, Plugin.PMD_TITLE); } } } diff --git a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Util.java b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Util.java new file mode 100644 index 0000000000..71671ca5f8 --- /dev/null +++ b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Util.java @@ -0,0 +1,35 @@ +package net.sourceforge.pmd.jdeveloper; + +import java.util.Arrays; + +import oracle.ide.Ide; +import oracle.ide.log.LogManager; + +import oracle.javatools.dialogs.ExceptionDialog; + + +final class Util { + private Util() { + } + + public static void logMessage(final String msg) { + LogManager.getLogManager().showLog(); + LogManager.getLogManager().getMsgPage().log(msg + "\n"); + } + + public static void logMessage(final StackTraceElement[] stack) { + LogManager.getLogManager().showLog(); + // TODO Output as Stack + LogManager.getLogManager().getMsgPage().log(Arrays.toString(stack) + + "\n"); + } + + public static void showError(final Exception exc, final String title) { + // JOptionPane.showMessageDialog(null, + // "Error while running " + title + ": " + + // "\n" + exc.getMessage(), title, + // JOptionPane.ERROR_MESSAGE); + ExceptionDialog.showExceptionDialog(Ide.getMainWindow(), exc); + } + +} diff --git a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Version.java b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Version.java index b49c7c823d..9559b59594 100644 --- a/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Version.java +++ b/pmd-jdeveloper.10.1.3/src/net/sourceforge/pmd/jdeveloper/Version.java @@ -7,24 +7,27 @@ import oracle.ide.Context; import oracle.jdeveloper.compiler.OjcConfiguration; -class Version { +final class Version { + private Version() { + } + public static void setJavaVersion(final Context context, final PMD pmd) { final OjcConfiguration config = OjcConfiguration.getInstance(context.getProject()); final String source = config.getSource(); - if (source.equals("1.6")) { + if ("1.6".equals(source)) { pmd.setJavaVersion(SourceType.JAVA_16); - } else if (source.equals("1.5")) { + } else if ("1.5".equals(source)) { pmd.setJavaVersion(SourceType.JAVA_15); - } else if (source.equals("1.4")) { + } else if ("1.4".equals(source)) { pmd.setJavaVersion(SourceType.JAVA_14); - } else if (source.equals("1.3")) { + } else if ("1.3".equals(source)) { pmd.setJavaVersion(SourceType.JAVA_13); } } public static String version() { - return "4.2.2.0.0"; + return "4.2.4.2.0"; } }