Menu

PLDoc PMD Integration - pldoc-pmd-plugin

PLSQL support was incorporated in PMD 5.1.0 - the PLDoc project has just published a minimal fork of maven-pmd-plugin: pldoc-pmd-plugin has the ability to read the database and generate JXR-like links to source code scraped by the maven-pldoc-plugin.

The pldoc-pmd-plugin can create CPD and PMD reports and so supersedes the current PLDoc CPD plugin - however as that plugin is entirely under the PLDoc project's control, so can add changes and fixed faster.

The default rules cover common code problems such as ignored WHEN OTHERS exception handlers, implicit date conversions, etc. More rules may be added.

Caveats

  1. Linking from the PMD and CPD reports only works if the POM file is configured using the classic reports configuration.
  2. In order to be compatible with the JXR plugin, the landing links for each line in scraped PLSQL source have changed from "line-number" to Lline-number.
  3. Currently, the database is read each time that the PLDoc, PMD, or CPD reports are run: it would be more efficient if the source code was extracted from the database, then processed locally by each plugin.

POM Example (New Configuration)

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>
  <build>
    <plugins>
          <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0</version>
        <dependencies>
          <dependency>
           <groupId>com.oracle</groupId>
           <artifactId>ojdbc14</artifactId>
           <version>10.2.0.3</version>
          </dependency>
        </dependencies>
        <configuration>
          <xdocDirectory>src/site/xdocs</xdocDirectory>
        <reportPlugins>
          <plugin>
            <groupId>net.sourceforge.pldoc</groupId>
            <artifactId>maven-pldoc-plugin</artifactId>
            <version>LATEST</version>
            <configuration>
              <name>Maven Site PLDoc Enterprise Example</name>
              <applicationTitle>Maven Site PLDoc Enterprise Example</applicationTitle>
              <destDir>pldoc</destDir>
              <showSkippedPackages>true</showSkippedPackages>
              <plscope>true</plscope>
              <savesourcecode>true</savesourcecode>
              <dbUrl>jdbc:oracle:thin:@//192.168.0.161:1521/orcl.localdomain</dbUrl>
              <dbUser>system</dbUser>
              <dbPassword>oracle</dbPassword>
              <inputTypes>PROCEDURE,FUNCTION,TRIGGER,PACKAGE,TYPE,PACKAGE BODY,TYPE BODY</inputTypes>
              <inputObjects>APEX_040200.%</inputObjects>
            </configuration>                    
          </plugin>
          <plugin>
            <groupId>net.sourceforge.pldoc</groupId>
            <artifactId>pldoc-pmd-plugin</artifactId>
            <version>3.2.1</version>
            <configuration>
              <format>xml</format>
              <linkXRef>true</linkXRef>
              <!--xrefLocation should be equal to PLDoc DestDir -->
              <xrefLocation>pldoc</xrefLocation>
              <minimumTokens>10</minimumTokens>
              <rulesets>
                  <ruleset>plsql-codesize</ruleset>
                  <ruleset>plsql-TomKytesDespair</ruleset>
                  <ruleset>plsql-dates</ruleset>
              </rulesets>
              <language>plsql</language>
              <excludes>
                  <excludes>**/global_block.sql</excludes>
              </excludes>
              <sourceEncoding>UTF-8</sourceEncoding>
              <uri>jdbc:oracle:thin:@//192.168.0.161:1521/orcl.localdomain?characterset=utf8&amp;schemas=APEX_040200&amp;sourcecodetypes=PROCEDURE,PACKAGE_BODY,TYPE_BODY,TRIGGER,FUNCTION&amp;sourcecodenames=%25&amp;user=system&amp;password=oracle</uri>
            </configuration>
          </plugin>
        </reportPlugins>
        </configuration>
        </plugin>
    </plugins>
  </build>
</project>

POM Example (Classic Configuration)

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>

  <!--
       The permissbile configuration for reports changes for Maven 3.0.
       As well as the "Classic Configuration" where the report plugins were defined at the project level,
       the site reports could be specified within the site plugin declaration 
       This change was reversed in Maven 3.3
       http://maven.apache.org/plugins/maven-site-plugin/maven-3.html
  -->
  <build>
    <plugins>
    <plugin>
      <groupId>net.sourceforge.pldoc</groupId>
      <artifactId>maven-pldoc-plugin</artifactId>
      <version>3.0.11</version>
      <dependencies>
        <dependency>
         <groupId>com.oracle</groupId>
         <artifactId>ojdbc14</artifactId>
         <version>10.2.0.3</version>
        </dependency>
      </dependencies>
      <configuration>
        <name>Maven Site PLDoc Enterprise Example</name>
        <applicationTitle>Maven Site PLDoc Enterprise Example</applicationTitle>
        <destDir>Site-Enterprise</destDir>
        <showSkippedPackages>true</showSkippedPackages>
        <plscope>true</plscope>
        <savesourcecode>true</savesourcecode>
        <dbUrl>jdbc:oracle:thin:@//192.168.0.161:1521/orcl.localdomain</dbUrl>
        <dbUser>system</dbUser>
        <dbPassword>oracle</dbPassword>
        <inputTypes>PROCEDURE,FUNCTION,TRIGGER,PACKAGE,TYPE,PACKAGE BODY,TYPE BODY</inputTypes>
        <inputObjects>APEX_040200.%</inputObjects>
      </configuration>                    
    </plugin>
    <plugin>
      <groupId>net.sourceforge.pldoc</groupId>
      <artifactId>pldoc-pmd-plugin</artifactId>
      <version>3.2.1</version>
      <dependencies>
        <dependency>
         <groupId>com.oracle</groupId>
         <artifactId>ojdbc14</artifactId>
         <version>10.2.0.3</version>
        </dependency>
      </dependencies>
      <configuration>
        <format>xml</format>
        <linkXRef>true</linkXRef>
        <xrefLocation>Site-Enterprise</xrefLocation>
        <minimumTokens>10</minimumTokens>
        <rulesets>
            <ruleset>plsql-codesize</ruleset>
            <ruleset>plsql-TomKytesDespair</ruleset>
            <ruleset>plsql-dates</ruleset>
        </rulesets>

        <language>plsql</language>
        <excludes>
            <excludes>**/global_block.sql</excludes>
        </excludes>
        <sourceEncoding>UTF-8</sourceEncoding>
        <uri>jdbc:oracle:thin:@//192.168.0.161:1521/orcl.localdomain?characterset=utf8&amp;schemas=HR,PLDOC,PLS,FLOWS_FILES,APEX_040200,PHPDEMO&amp;sourcecodetypes=PROCEDURE,PACKAGE_BODY,TYPE_BODY,TRIGGER,FUNCTION&amp;sourcecodenames=%25&amp;user=system&amp;password=oracle</uri>
      </configuration>
    </plugin>
          <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <xdocDirectory>src/site/xdocs</xdocDirectory>
        </configuration>
        </plugin>
    </plugins>
  </build>
  <reporting>
    <excludeDefaults>true</excludeDefaults>
    <outputDirectory>${project.build.directory}/site</outputDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.7</version>
      </plugin>
    <plugin>
      <groupId>net.sourceforge.pldoc</groupId>
      <artifactId>maven-pldoc-plugin</artifactId>
      <version>LATEST</version>
      <configuration>
        <name>Maven Site PLDoc Enterprise Example</name>
        <applicationTitle>Maven Site PLDoc Enterprise Example</applicationTitle>
        <destDir>pldoc</destDir>
        <!-- use reportOutputDirectory for Site Report wth Classic Configuration- reportin tags -->
        <reportOutputDirectory>target/site</reportOutputDirectory>
        <showSkippedPackages>true</showSkippedPackages>
        <plscope>true</plscope>
        <savesourcecode>true</savesourcecode>
        <dbUrl>jdbc:oracle:thin:@//192.168.0.161:1521/orcl.localdomain</dbUrl>
        <dbUser>system</dbUser>
        <dbPassword>oracle</dbPassword>
        <inputTypes>PROCEDURE,FUNCTION,TRIGGER,PACKAGE,TYPE,PACKAGE BODY,TYPE BODY</inputTypes>
        <inputObjects>APEX_040200.%</inputObjects>
      </configuration>                    
    </plugin>
    <plugin>
      <groupId>net.sourceforge.pldoc</groupId>
      <artifactId>pldoc-pmd-plugin</artifactId>
      <version>3.2.1</version>
      <configuration>
        <targetDirectory>${basedir}/target/test/unit/plsql-configuration/target</targetDirectory-->
        <format>xml</format>
        <linkXRef>true</linkXRef>
        <xrefLocation>target/site/pldoc-Enterprise</xrefLocation>
        <minimumTokens>5</minimumTokens>
        <rulesets>
            <ruleset>plsql-codesize</ruleset>
            <ruleset>plsql-TomKytesDespair</ruleset>
            <ruleset>plsql-dates</ruleset>
        </rulesets>

        <language>plsql</language>
        <excludes>
            <excludes>**/global_block.sql</excludes>
        </excludes>
        <sourceEncoding>UTF-8</sourceEncoding>
        <uri>jdbc:oracle:thin:@//192.168.0.161:1521/orcl.localdomain?characterset=utf8&amp;schemas=HR,PLDOC,PLS,FLOWS_FILES,APEX_040200,PHPDEMO&amp;sourcecodetypes=PROCEDURE,PACKAGE_BODY,TYPE_BODY,TRIGGER,FUNCTION&amp;sourcecodenames=%25&amp;user=system&amp;password=oracle</uri>
      </configuration>
    </plugin>
    </plugins>
  </reporting>
</project>
Posted by Stuart Turton 2014-08-17 Labels: pldoc pmd

Log in to post a comment.