Author: fgiust Date: Fri Dec 30 07:23:22 2005 New Revision: 360102 URL: http://svn.apache.org/viewcvs?rev=360102&view=rev Log: make project classes accessible to checkstyle during check (required for exception-related checks)
Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java?rev=360102&r1=360101&r2=360102&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java Fri Dec 30 07:23:22 2005 @@ -22,16 +22,21 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.net.MalformedURLException; import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.ResourceBundle; +import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.AbstractMavenReport; @@ -628,6 +633,35 @@ Checker checker = new Checker(); + // setup classloader, needed to avoid "Unable to get class information for ..." errors + List classPathStrings; + try + { + classPathStrings = this.project.getCompileClasspathElements(); + } + catch ( DependencyResolutionRequiredException e ) + { + throw new MavenReportException( e.getMessage(), e ); + } + + List URLs = new ArrayList( classPathStrings.size() ); + + Iterator iter = classPathStrings.iterator(); + while ( iter.hasNext() ) + { + try + { + URLs.add( new File( ( (String) iter.next() ) ).toURL() ); + } + catch ( MalformedURLException e ) + { + throw new MavenReportException( e.getMessage(), e ); + } + } + + URLClassLoader projectClassLoader = new URLClassLoader( (URL[]) URLs.toArray( new URL[URLs.size()] ), null ); + checker.setClassloader( projectClassLoader ); + if ( moduleFactory != null ) { checker.setModuleFactory( moduleFactory ); @@ -654,7 +688,7 @@ checker.addListener( sinkListener ); int nbErrors = checker.process( files ); - + checker.destroy(); if ( stringOutputStream != null )