gavioto / m2e-extensions

Automatically exported from code.google.com/p/m2e-extensions
0 stars 0 forks source link

PMD generates RuleSets it cannot read. #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The PMD RuleSetWriter creates rule exclusions as elements 
(<exclude>Foo</exclude>), however, the RuleSetFactory expects them as an 
attribute named "name" (<exclude name="Foo"/>).  This appears to be a bug in 
PMD.

To work around this, we've done a regexp on the generated XML before saving it, 
changing writeRuleSet to be:

    private File writeRuleSet(
            final IFile rulesetFile, 
            final RuleSet ruleSet, 
            final IProgressMonitor monitor) throws CoreException {
        final PMDPlugin pmdPlugin = PMDPlugin.getDefault();

        BufferedOutputStream outputStream = null;
        ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
        try {
            outputStream = new BufferedOutputStream(new FileOutputStream(
                    rulesetFile.getLocation().toFile()));
            pmdPlugin.getRuleSetWriter().write(byteArrayStream, ruleSet);

            // ..and now we have two problems
            String fixedXml = byteArrayStream.toString().replaceAll("\\<exclude\\>(.*)\\</exclude\\>", "<exclude name=\"$1\"/>");

            outputStream.write(fixedXml.getBytes());
            outputStream.close();

            rulesetFile.refreshLocal(IResource.DEPTH_ZERO, monitor);
        } catch (IOException ex) {
            this.console.logError(String.format(
                    "[%s]: could not write ruleset, reason [%s]",
                    this.getLogPrefix(),
                    ex.getMessage()));
        } catch (WriterException ex) {
            this.console.logError(String.format(
                    "[%s]: could not write ruleset, reason [%s]",
                    this.getLogPrefix(),
                    ex.getMessage()));
        }
        return rulesetFile.getLocation().toFile();
    }

Original issue reported on code.google.com by jatw...@linuxstuff.org on 23 Sep 2010 at 5:11

GoogleCodeExporter commented 9 years ago
I've logged 
https://sourceforge.net/tracker/?func=detail&aid=3074231&group_id=56262&atid=479
921 against PMD.  I'd be surprised if it wasn't a duplicate of another issue.

Original comment by jatw...@linuxstuff.org on 23 Sep 2010 at 5:15

GoogleCodeExporter commented 9 years ago
applied as of f0453cdde3

Original comment by mr.id...@gmail.com on 20 Dec 2010 at 5:19