Git Product home page Git Product logo

Comments (6)

acanda avatar acanda commented on September 24, 2024

PMD uses regular expressions to define the include and exclude pattern and (unfortunately) silently ignores an invalid pattern. In your case both the exclude and the includes pattern are invalid and that is why PMD analyses the SQL files in the first place. You might want to change your patterns to the following:

    <exclude-pattern>.*</exclude-pattern>
    <include-pattern>.*\.java$</include-pattern>

I tried to reproduce the problem with my own SQL files but was unable to do so. My currently best guess for the reason why mvn pmd:pmd runs without issue and eclipse-pmd hangs is that mvn pmd:pmd does not actually analyse the SQL files. Please make sure that

  • your maven configuration uses PMD 5.1.1. The maven-pmd-plugin currently uses PMD 5.0.5 and SQL support was only introduced with PMD 5.1.
  • your maven configuration includes all files. The maven-pmd-plugin default include pattern is */.java which excludes your SQL files.
  • you don't use any include/exclude patterns in your PMD rule set file.

Your maven configuration should look like this:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <targetJdk>1.7</targetJdk>
        <rulesets>
            <ruleset>${basedir}/pmd.xml</ruleset>
        </rulesets>
        <verbose>true</verbose>
        <includes>
          <include>**/*</include>
        </includes>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>net.sourceforge.pmd</groupId>
            <artifactId>pmd</artifactId>
            <version>5.1.1</version>
        </dependency>
    </dependencies>
  </plugin>

Please let me know if the above maven configuration also hangs when analysing your SQL files. This would help me find out if this is a problem with eclipse-pmd or PMD itself.

from eclipse-pmd.

ianbrandt avatar ianbrandt commented on September 24, 2024

Thanks for looking into this. Indeed I was mistakenly using Ant-like patterns in my rule set.

I've added the include to my maven-pmd-plugin configuration, leaving the rest as it was. Per mvn help:effective-pom:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
        <resource>
            <directory>src/main/sql</directory>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/it/resources</directory>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>3.1</version>
            <dependencies>
                <dependency>
                    <groupId>net.sourceforge.pmd</groupId>
                    <artifactId>pmd</artifactId>
                    <version>5.1.1</version>
                    <scope>compile</scope>
            </dependency>
        </dependencies>
        <configuration>
            <targetJdk>1.6</targetJdk>
            <rulesets>
                <ruleset>file:///Users/ibrandt/myproject/db/../pmd.xml</ruleset>
            </rulesets>
            <includes>
                <include>**/*</include>
            </includes>
            <includeTests>true</includeTests>
            <verbose>true</verbose>
        </configuration>
        </plugin>
        [...]

I removed the exclude and include from my rule set:

<?xml version="1.0" encoding="UTF-8" ?>
<ruleset name="myruleset" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">

    <description>My Ruleset</description>

    <rule ref="rulesets/java/basic.xml" />
    <rule ref="rulesets/java/braces.xml" />
    [...]

It doesn't seem to get hung up on the SQL:

$ mvn pmd:pmd
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building DB 7.2.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-pmd-plugin:3.1:pmd (default-cli) @ db ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.238s
[INFO] Finished at: Sun Jul 13 08:53:55 PDT 2014
[INFO] Final Memory: 18M/81M
[INFO] ------------------------------------------------------------------------

Of note the SQL files are in an added resource folder, "src/main/sql". This is also a source folder in Eclipse. Might the maven-pmd-plugin not scan added resource folders, where eclipse-pmd does on account of them being source folders?

from eclipse-pmd.

ianbrandt avatar ianbrandt commented on September 24, 2024

I added the correct exclude patterns to my rule set:

    <exclude-pattern>.*</exclude-pattern>
    <include-pattern>.*\.java$</include-pattern>

I can now enable the PMD nature on my DB project, and the build completes just fine.

from eclipse-pmd.

acanda avatar acanda commented on September 24, 2024

I don't know if the maven-pmd-plugin scans resource folders. You could run PMD from the command line and specify the resource folder explicitly with -d <path> to make sure the SQL files are included.

from eclipse-pmd.

ianbrandt avatar ianbrandt commented on September 24, 2024

I'm going to go ahead and close this as eclipse-pmd is now working fine for me with .sql files properly excluded. I assume the root performance issue is with the PLSQLParser upstream. I'll file an issue for that with PMD directly.

from eclipse-pmd.

sturton avatar sturton commented on September 24, 2024

The PLSQL Parser was inherited / migrated from PLDoc where it concentrates on PLSQL, but tries to support other commands that might be found in a SQL script file:- SQL*Plus, DDL, GRANTS, etc.

It does attempt to support Table and View DDL, but that support has not been maintained or updated, simply because other tools do Table and View documentation much, much better - I use maven-schemaspy-plugin .

I infer from a look at the stack trace that the parser is having problems parsing a View DDL statement
"
...
net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.View
...
"

I will have a look at the parser - it would help if you could post the problem View definition.

from eclipse-pmd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.