diff --git a/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java b/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java index f7a3327f8a..7e2f29f7d1 100644 --- a/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java +++ b/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java @@ -172,7 +172,7 @@ public class CheckstyleReport * @parameter expression="${project.build.sourceDirectory}" * @required */ - private String sourceDirectory; + private File sourceDirectory; /** * @parameter expression="${project}" @@ -238,6 +238,11 @@ public class CheckstyleReport public void executeReport( Locale locale ) throws MavenReportException { + if ( !canGenerateReport() ) + { + throw new MavenReportException( "No source directory to process for style" ); + } + Map files = executeCheckstyle(); CheckstyleReportGenerator generator = new CheckstyleReportGenerator( getSink(), getBundle( locale ) ); @@ -396,7 +401,7 @@ public class CheckstyleReport try { - files = FileUtils.getFiles( new File( sourceDirectory ), includes, excludesStr.toString() ); + files = FileUtils.getFiles( sourceDirectory, includes, excludesStr.toString() ); } catch ( IOException ioe ) { @@ -526,4 +531,10 @@ public class CheckstyleReport { return ResourceBundle.getBundle( "checkstyle-report", locale, CheckstyleReport.class.getClassLoader() ); } + + public boolean canGenerateReport() + { + // TODO: would be good to scan the files here + return super.canGenerateReport() && sourceDirectory.exists(); + } } diff --git a/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java b/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java index e278da9e6b..be44cfefb1 100644 --- a/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java +++ b/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListener.java @@ -22,6 +22,10 @@ import com.puppycrawl.tools.checkstyle.api.AutomaticBean; import com.puppycrawl.tools.checkstyle.api.SeverityLevel; import java.util.LinkedList; import java.util.TreeMap; +import java.util.Map; +import java.util.List; +import java.io.File; + import org.codehaus.plexus.util.StringUtils; /** @@ -32,31 +36,31 @@ public class CheckstyleReportListener extends AutomaticBean implements AuditListener { - private String sourceDirectory; - - private TreeMap files; - + private File sourceDirectory; + + private Map files; + private String currentFile; - - private LinkedList events; - + + private List events; + private SeverityLevel severityLevel; - - public CheckstyleReportListener( String sourceDirectory ) + + public CheckstyleReportListener( File sourceDirectory ) { this.sourceDirectory = sourceDirectory; } - + public void setSeverityLevelFilter( SeverityLevel severityLevel ) { this.severityLevel = severityLevel; } - + public SeverityLevel getSeverityLevelFilter() { return severityLevel; } - + public void auditStarted( AuditEvent event ) { setFiles( new TreeMap() ); @@ -69,12 +73,12 @@ public class CheckstyleReportListener public void fileStarted( AuditEvent event ) { - currentFile = StringUtils.substring( event.getFileName(), sourceDirectory.length() + 1 ); + currentFile = StringUtils.substring( event.getFileName(), sourceDirectory.getPath().length() + 1 ); currentFile = StringUtils.replace( currentFile, "\\", "/" ); - + if ( !getFiles().containsKey( currentFile ) ) getFiles().put( currentFile, new LinkedList() ); - + events = (LinkedList) getFiles().get( currentFile ); } @@ -87,24 +91,24 @@ public class CheckstyleReportListener public void addError( AuditEvent event ) { if ( SeverityLevel.IGNORE.equals( event.getSeverityLevel() ) ) return; - + if ( severityLevel == null || severityLevel.equals( event.getSeverityLevel() ) ) { events.add( event ); } } - + public void addException( AuditEvent event, Throwable throwable ) { //Do Nothing } - public TreeMap getFiles() + public Map getFiles() { return files; } - public void setFiles( TreeMap files ) + public void setFiles( Map files ) { this.files = files; } diff --git a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java index c9803a2bbe..d487804f49 100644 --- a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java +++ b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java @@ -220,6 +220,8 @@ public class SiteMojo attributes.put( "outputEncoding", outputEncoding ); } + List reports = filterReports( this.reports ); + Map categories = categorizeReports( reports ); List projectInfos = (List) categories.get( MavenReport.CATEGORY_PROJECT_INFORMATION ); @@ -298,8 +300,8 @@ public class SiteMojo List generatedReportsFileName = Collections.EMPTY_LIST; if ( reports != null ) { - generatedReportsFileName = generateReportsPages( reports, locale, outputDirectory, defaultLocale, - siteDescriptor ); + generatedReportsFileName = + generateReportsPages( reports, locale, outputDirectory, defaultLocale, siteDescriptor ); } //Generate overview pages @@ -398,6 +400,20 @@ public class SiteMojo } } + private List filterReports( List reports ) + { + List filteredReports = new ArrayList( reports.size() ); + for ( Iterator i = reports.iterator(); i.hasNext(); ) + { + MavenReport report = (MavenReport) i.next(); + if ( report.canGenerateReport() ) + { + filteredReports.add( report ); + } + } + return filteredReports; + } + /** * Categorize reports by category name. * @@ -528,6 +544,7 @@ public class SiteMojo for ( Iterator i = reports.iterator(); i.hasNext(); ) { MavenReport report = (MavenReport) i.next(); + buffer.append( "