Class CoverageHtmlResources
Extracts CSS, JavaScript, images, and HTML templates from the compiler JAR to the coverage output directory. Templates support placeholder substitution for dynamic content generation.
Resources are loaded from:
/site/- Shared site resources (logo, favicon, base styles)/coverage/- Coverage-specific resources (coverage.css, coverage.js)/coverage/templates/- HTML templates with placeholders
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordPackage metadata extracted from EK9 source files. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum cognitive complexity before E11021 error.static final intMaximum cyclomatic complexity before E11010 error.static final intMaximum nesting depth before E11011 error.static final intMaximum readability score (ARI capped at 20). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionescapeHtml(String text) Escape HTML special characters in text.extractPackageInfo(String content) Extract package metadata from EK9 source content.extractPackageInfo(Path sourceFile) Extract package metadata from an EK9 source file.voidExtract all static resources to the output directory.generateDonutChart(double percentage, String color) Generate an SVG donut chart for coverage percentage.generateMetricDonutChart(double value, double limit, String displayValue) Generate a donut chart for code quality metrics.generateMiniDonutChart(double percentage, String color) Generate a smaller SVG donut chart for file summary cards.Generate HTML for package info display.getBarClass(double percentage) Get the CSS class for coverage bar fill.getChartColor(double percentage) Get the chart color based on coverage percentage.getCoverageClass(double percentage) Get the CSS class for coverage percentage styling.getMetricChartColor(double percentOfLimit) Get the chart color for a code quality metric based on percentage of limit.getMetricClass(double percentOfLimit) Get the CSS class for a metric value based on percentage of limit.loadResource(String resourcePath) Load a text resource from the classpath.loadTemplate(String templateName, Map<String, String> substitutions) Load an HTML template and substitute placeholders.toSafeFileName(String filePath) Convert a file path to a safe HTML file name.
-
Field Details
-
MAX_CYCLOMATIC_COMPLEXITY
public static final int MAX_CYCLOMATIC_COMPLEXITYMaximum cyclomatic complexity before E11010 error.- See Also:
-
MAX_COGNITIVE_COMPLEXITY
public static final int MAX_COGNITIVE_COMPLEXITYMaximum cognitive complexity before E11021 error.- See Also:
-
MAX_READABILITY
public static final int MAX_READABILITYMaximum readability score (ARI capped at 20).- See Also:
-
MAX_NESTING_DEPTH
public static final int MAX_NESTING_DEPTHMaximum nesting depth before E11011 error.- See Also:
-
-
Constructor Details
-
CoverageHtmlResources
public CoverageHtmlResources()
-
-
Method Details
-
extractTo
Extract all static resources to the output directory.Copies site resources (logo, favicon) and coverage-specific resources (CSS, JS) to the coverage report directory.
- Parameters:
outputDir- The directory to extract resources to- Throws:
IOException- if resource extraction fails
-
loadTemplate
public String loadTemplate(String templateName, Map<String, String> substitutions) throws IOExceptionLoad an HTML template and substitute placeholders.Templates use
{{PLACEHOLDER}}syntax for substitution. All placeholders in the substitutions map are replaced.- Parameters:
templateName- The template file name (e.g., "index.html.template")substitutions- Map of placeholder names to values- Returns:
- The processed template content
- Throws:
IOException- if template loading fails
-
loadResource
Load a text resource from the classpath.- Parameters:
resourcePath- The resource path (starting with /)- Returns:
- The resource content as a string
- Throws:
IOException- if the resource cannot be loaded
-
generateDonutChart
Generate an SVG donut chart for coverage percentage.Creates a pure SVG chart with no external dependencies. The chart shows coverage as a colored arc with the percentage in the center.
- Parameters:
percentage- The coverage percentage (0-100)color- The chart color (CSS color value)- Returns:
- SVG markup as a string
-
generateMiniDonutChart
Generate a smaller SVG donut chart for file summary cards.Creates a compact version of the donut chart suitable for mini chart cards in file summary pages.
- Parameters:
percentage- The coverage percentage (0-100)color- The chart color (CSS color value)- Returns:
- SVG markup as a string
-
getChartColor
Get the chart color based on coverage percentage.Color thresholds:
- 100%: Excellent (green)
- 80-99%: Good (light green)
- 50-79%: Warning (orange)
- 0-49%: Error (red)
- Parameters:
percentage- The coverage percentage- Returns:
- CSS color value
-
getCoverageClass
Get the CSS class for coverage percentage styling.- Parameters:
percentage- The coverage percentage- Returns:
- CSS class name (pct-excellent, pct-good, pct-warning, pct-error)
-
getBarClass
Get the CSS class for coverage bar fill.- Parameters:
percentage- The coverage percentage- Returns:
- CSS class name (bar-excellent, bar-good, bar-warning, bar-error)
-
escapeHtml
-
toSafeFileName
Convert a file path to a safe HTML file name.Replaces path separators and dots with underscores to create a flat file structure in the coverage output directory.
- Parameters:
filePath- The source file path (e.g., "src/main.ek9")- Returns:
- Safe file name (e.g., "src_main_ek9.html")
-
extractPackageInfo
Extract package metadata from an EK9 source file.Parses the
defines packageblock to extract description, version, license, and tags. ReturnsCoverageHtmlResources.PackageInfo.EMPTYif no package block is found or the file cannot be read.- Parameters:
sourceFile- Path to the EK9 source file- Returns:
- PackageInfo with extracted metadata, or EMPTY if not found
-
extractPackageInfo
Extract package metadata from EK9 source content.- Parameters:
content- The EK9 source content- Returns:
- PackageInfo with extracted metadata
-
generatePackageInfoHtml
Generate HTML for package info display.Creates a formatted section showing package metadata when available. Returns an empty string if no metadata is present.
- Parameters:
info- The package info to display- Returns:
- HTML string for the package info section
-
generateMetricDonutChart
Generate a donut chart for code quality metrics.Unlike coverage charts where higher is better, metric charts show "percentage of limit consumed" where LOWER is better. The chart fills up as you approach the compiler limit.
- Parameters:
value- The actual metric value (e.g., complexity = 10)limit- The compiler limit (e.g., 45)displayValue- The value to show in center (formatted string)- Returns:
- SVG markup as a string
-
getMetricChartColor
Get the chart color for a code quality metric based on percentage of limit.INVERSE of coverage colors - lower percentage is better:
- 0-49%: Green (safe headroom)
- 50-79%: Orange (warning - approaching limit)
- 80-100%+: Red (critical - near or at compiler error)
- Parameters:
percentOfLimit- The percentage of the compiler limit consumed- Returns:
- CSS color value
-
getMetricClass
Get the CSS class for a metric value based on percentage of limit.INVERSE of coverage classes - lower percentage is better.
- Parameters:
percentOfLimit- The percentage of the compiler limit consumed- Returns:
- CSS class name (metric-safe, metric-warning, metric-critical)
-