You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Michael Yates (JIRA)" <ji...@codehaus.org> on 2014/01/14 13:35:50 UTC

[jira] (MPMD-178) excludeRoots doesn't handle subdirectories (PMD doesn't isn't working nicely with Android projects)

Michael Yates created MPMD-178:
----------------------------------

             Summary: excludeRoots doesn't handle subdirectories (PMD doesn't isn't working nicely with Android projects)
                 Key: MPMD-178
                 URL: https://jira.codehaus.org/browse/MPMD-178
             Project: Maven PMD Plugin
          Issue Type: Bug
          Components: PMD
    Affects Versions: 3.0.1
         Environment: all
            Reporter: Michael Yates


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:
/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

So you would hope that the maven-pmd plugin could be configured as
<excludeRoots>
  <excludeRoot>target/generated-sources</excludeRoot>
  <excludeRoot>target/unpacked-libs</excludeRoot>
</excludeRoots>

However this doesn't work. 
The excludeRoots get compared directly for equality in the contains clause of

 if ( sourceDirectory.isDirectory() && !excludeRootFiles.contains( sourceDirectory ) ) 

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
---
    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;
    }
---

With the comparison line becoming
  if (sourceDirectory.isDirectory() && !isDirectoryExcluded(excludeRootFiles, sourceDirectory) )

This is working in my test project and doesn't fail any of the maven-pmd unit tests.





--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira