[
https://issues.apache.org/jira/browse/MPMD-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15141555#comment-15141555
]
Hudson commented on MPMD-178:
-----------------------------
SUCCESS: Integrated in maven-plugins #5085 (See
[https://builds.apache.org/job/maven-plugins/5085/])
[MPMD-178] excludeRoots should handle subdirectories
Contributed by: Michael Yates (adangel:
[http://svn.apache.org/viewvc/?view=rev&rev=1729696])
*
maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdReport.java
* maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java
* maven-pmd-plugin/src/test/resources/unit/exclude-roots
* maven-pmd-plugin/src/test/resources/unit/exclude-roots/baseroot
* maven-pmd-plugin/src/test/resources/unit/exclude-roots/baseroot/src1
*
maven-pmd-plugin/src/test/resources/unit/exclude-roots/baseroot/src1/PMDViolationExample.java
* maven-pmd-plugin/src/test/resources/unit/exclude-roots/baseroot/src2
*
maven-pmd-plugin/src/test/resources/unit/exclude-roots/baseroot/src2/PMDViolationExample.java
* maven-pmd-plugin/src/test/resources/unit/exclude-roots/othersrc
*
maven-pmd-plugin/src/test/resources/unit/exclude-roots/othersrc/PMDViolationExample.java
*
maven-pmd-plugin/src/test/resources/unit/exclude-roots/pmd-exclude-roots-plugin-config.xml
* maven-pmd-plugin/src/test/resources/unit/exclude-roots/src
*
maven-pmd-plugin/src/test/resources/unit/exclude-roots/src/PMDViolationExample.java
> ExcludeRoots doesn't handle subdirectories (PMD isn't working nicely with
> Android projects)
> -------------------------------------------------------------------------------------------
>
> Key: MPMD-178
> URL: https://issues.apache.org/jira/browse/MPMD-178
> Project: Maven PMD Plugin
> Issue Type: Bug
> Components: PMD
> Affects Versions: 3.0.1
> Environment: all
> Reporter: Michael Yates
> Assignee: Andreas Dangel
> Fix For: 3.7
>
>
> We are using PMD to check an Android project. The pom file that "drives" the
> Android project uses android-maven-plugin (3.8.2).
> Our android project depends on a number of 3rd party libraries. Some of these
> libraries are apklibs. The android-maven-plugin handles apklibs by expanding
> them into a given directory before compiling.
> This results in a very long value being passed to maven-pmd in the
> compileSourceRoots variable. I understand you can't override
> compileSourceRoots so I turned to excludeRoots to exclude these 3rd parties
> libraries from analysis
> The target directories that contain source in an maven Android project would
> look something like:
> {code:xml}
> /target/generated-sources/extracted-dependencies/src/main/java
> /target/generated-sources/r
> /target/generated-sources/aidl
> /target/unpacked-libs/com.actionbarsherlock_actionbarsherlock_apklib_4.3.0/src
> /target/unpacked-libs/com.github.chrisbanes.pulltorefresh_library_apklib_2.1.2-SNAPSHOT/src
> /target/unpacked-libs/com.slidingmenu_slidingmenu_apklib_1.3-SNAPSHOT/src
> {code}
> So you would hope that the maven-pmd plugin could be configured as
> {code:xml}
> <excludeRoots>
> <excludeRoot>target/generated-sources</excludeRoot>
> <excludeRoot>target/unpacked-libs</excludeRoot>
> </excludeRoots>
> {code}
> However this doesn't work. The excludeRoots get compared directly for
> equality in the contains clause of
> {code:java}
> if ( sourceDirectory.isDirectory() && !excludeRootFiles.contains(
> sourceDirectory ) )
> {code}
> in {{AbstractPmdReport.java}}. This obviously doesn't work as
> {{unpacked-libs}} is the container for a whole host of source directories.
> I suggest that the comparison should look at the base path as
> {code:java}
> private boolean isDirectoryExcluded(Collection<File> excludeRootFiles,
> File sourceDirectoryToCheck)
> {
> boolean returnVal = false;
> for (File excludeDir : excludeRootFiles)
> {
> if
> (sourceDirectoryToCheck.getAbsolutePath().startsWith(excludeDir.getAbsolutePath()))
> {
> getLog().debug( "Directory "
> +sourceDirectoryToCheck.getAbsolutePath() + " has been excluded as it matches
> excludeRoot " + excludeDir.getAbsolutePath());
> returnVal = true;
> break;
> }
> }
> return returnVal;
> }
> {code}
> With the comparison line becoming
> {code:java}
> if (sourceDirectory.isDirectory() && !isDirectoryExcluded(excludeRootFiles,
> sourceDirectory) )
> {code}
> This is working in my test project and doesn't fail any of the maven-pmd unit
> tests.
> I tried uploading an attachment with the changes described above but to no
> avail - not sure what is happening there.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)