Does JSP support work at all???

2006-04-11
2012-10-07
  • Dani Palacios

    Dani Palacios - 2006-04-11

    Hi there,

    I've been giving the new JSP rules in PMD 3.6 a try and I just couldn't make it work.

    I wrote a JSP file that should result in a bunch of errors (I actually copied the examples that trigger the rules from the documentation) but to no avail.

    I can see that the JSP gets parsed (since the process fails when I make my JSP non-XHTML) and that the rules gets loaded (thanks to the -debug option), but for some reason I always get a no-errors report (using both an ant script and from the command line with the -jsp option).

    I noticed there's a blog entry about JSP support not working via Ant but I'm afraid I can't make it work from the command-line either. Is there something I am missing?

    Thank you very much,

    Dani Palacios
    Java developer

    PS. Please find below the extra info

    The JSP file (test.jsp):

    <%@ page import="gov.inss.atrium.constantes.Constantes"%>
    <HTML>
    <HEAD>
    <%
    response.setHeader("Pragma", "No-cache");
    %>
    </HEAD>

    <jsp:forward page='UnderConstruction.jsp'/>

    &lt;!-- Esto es para que salte la regla de los comentarios HTML --&gt;
    
    &lt;BODY&gt;
        &lt;jsp:scriptlet&gt;String title = &quot;Hello world!&quot;;&lt;/jsp:scriptlet&gt;
    
        &lt;p align='center'&gt;&lt;b&gt;text&lt;/b&gt;&lt;/p&gt;
    &lt;/BODY&gt;
    
    &lt;br/&gt;
    

    </HTML>

    The rules (calidad_java.xml):

    <?xml version="1.0"?>

    <ruleset name="CalidadJava" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../etc/ruleset_xml_schema.xml">
    <description>
    Reglas de Calidad Java </description>

    <rule ref="rulesets/basic-jsp.xml/NoScriptlets">
    <priority>2</priority>
    </rule>
    <rule ref="rulesets/basic-jsp.xml/NoInlineStyleInformation">
    <priority>3</priority>
    </rule>
    <rule ref="rulesets/basic-jsp.xml/NoJspForward">
    <priority>3</priority>
    </rule>
    <rule ref="rulesets/basic-jsp.xml/NoHtmlComments">
    <priority>3</priority>
    </rule>

    </ruleset>

    The command-line:

    C:\PMD\pmd-3.6\bin>pmd C:\PMD\dani\test.jsp text C:\PMD\bin\calidad_java.xml -jsp -debug

    The output:

    In JDK 1.4 mode
    Loaded rule NoJspForward
    Loaded rule NoScriptlets
    Loaded rule NoHtmlComments
    Loaded rule NoInlineStyleInformation
    Processing C:\PMD\dani\test.jsp
    No problems found!

     
    • Allan Caplan

      Allan Caplan - 2006-04-20

      Figured this out. Fix shouldn't be difficult, but there's an easy to use workaround. If you're referencing the JSP rules, add the language attribute to your ruleset.

      language=&quot;jsp&quot;
      

      If you check the bug filed for this issue I show the full ruleset for an example.

       
    • Tom Copeland

      Tom Copeland - 2006-04-11

      Hi Dani -

      Hm, try the "-jsponly" flag:

      =============================
      $ cat test.jsp
      <HTML>
      <HEAD>
      </HEAD>
      <!-- Esto es para que salte la regla de los comentarios HTML -->
      </HTML>
      $ ./pmd.sh test.jsp text jsp -jsponly
      /home/tom/pmd/pmd/bin/test.jsp:4 Use JSP comments instead of HTML comments
      =============================

      Yours,

      Tom
      Using PMD? Get the book! http://pmdapplied.com/

       
    • Dani Palacios

      Dani Palacios - 2006-04-11

      Hi Tom,

      Even though the -jsponly option makes no difference your solution works fine because it references the JSP rules directly by using 'jsp' instead of my xml ruleset file (that in turn referenced the basic-jsp.xml file) 'calidad_java.xml'.

      I posted a bug accordingly:
      [ 1468689 ] 'ref' attribute doesn't work when it points to basic-jsp.xml
      http://sourceforge.net/tracker/index.php?func=detail&aid=1468689&group_id=56262&atid=479921

      Thanks a lot for your quick reply!!

       
      • Tom Copeland

        Tom Copeland - 2006-04-11

        Hi Dani -

        Ah, OK... that's interesting, hm. OK, I will try to check it out, thanks for filing the bug!

        Yours,

        Tom

         
    • Dani Palacios

      Dani Palacios - 2006-04-11

      Ooops! I forgot to add that this way it works both from the command line and via Ant.
      Hope this helps.

      Dani

       

Log in to post a comment.