mirror of https://github.com/apache/maven.git
PR: MNG-945
do not display reports that should not be generated in the navigation git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@312901 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e687b514a3
commit
23b2eeb0be
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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( " <item name=\"" );
|
||||
buffer.append( report.getName( locale ) );
|
||||
buffer.append( "\" href=\"/" );
|
||||
|
|
|
@ -53,4 +53,6 @@ public interface MavenReport
|
|||
File getReportOutputDirectory();
|
||||
|
||||
boolean isExternalReport();
|
||||
|
||||
boolean canGenerateReport();
|
||||
}
|
||||
|
|
|
@ -190,4 +190,9 @@ public abstract class AbstractMavenReport
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canGenerateReport()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue