-
Notifications
You must be signed in to change notification settings - Fork 53
#405 Fix "File name too long" error with deep paths in JUnit reports #426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Implement hierarchical directory structure for JUnit XML reports to solve filename length issues when checking HTML files in deeply nested directories. Changes: - Modify JUnitXmlReporter to create directory hierarchies mirroring source file structure instead of encoding paths into flat filenames - Add path normalization and security checks to prevent directory traversal - Update JUnitXmlReporterTest with 7 comprehensive tests for hierarchical structure, including edge cases for long paths and relative references - Add helper method findFirstXmlFile() for recursive XML file discovery - Fix tearDown() to handle directories when traversing file tree - Add AsciiDoc documentation in issue-405.adoc with code includes via tags - Update CLAUDE.md with AsciiDoc and commit message conventions - Add source code tags to JUnitXmlReporter.java for documentation includes The solution keeps individual filenames under OS limits while preserving full path information through directory structure. All 379 existing tests continue to pass. Resolves #405 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add configuration option to choose between flat and hierarchical JUnit XML output structures for backwards compatibility. - Move JunitOutputStyle enum as nested class in Configuration - Add junitOutputStyle field to Configuration (default: FLAT) - Refactor JUnitXmlReporter with getFlatOutputFile() and getHierarchicalOutputFile() methods - Update Gradle plugin to expose junitOutputStyle property - Update Maven plugin to expose junitOutputStyle parameter - Update CLI to add --junitOutputStyle/-o option - Add 7 comprehensive tests for HIERARCHICAL mode - Update documentation with configuration examples FLAT mode (default) maintains backwards compatibility with existing behavior. HIERARCHICAL mode solves filename length issues for deeply nested directory structures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add tests to improve code coverage for exception handling and both FLAT and HIERARCHICAL output modes. - testFlatModeCreatesEncodedFilename: Tests explicit FLAT mode - testFlatModeIsDefaultWhenNotSpecified: Tests default behavior - testHierarchicalModeFailsWhenCannotCreateDirectory: Tests exception when directory creation fails in HIERARCHICAL mode - Fix testInitReportWithNonWritableDirectory to properly test exception when output path cannot be created These tests address Sonar coverage gaps in: - Line 64: initReport() exception handling - Line 165: getHierarchicalOutputFile() directory creation error - getFlatOutputFile() method coverage Coverage improvements ensure both output modes and exception paths are properly tested. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes issue #405 by resolving "File name too long" errors when generating JUnit XML reports for HTML files in deeply nested directory structures. The solution introduces a configurable output style system that maintains backward compatibility while providing a new hierarchical mode to solve filename length issues.
- Adds
JunitOutputStyleenum with FLAT (default) and HIERARCHICAL modes - Refactors
JUnitXmlReporterto support both output strategies - Updates all three interfaces (Gradle plugin, Maven plugin, CLI) to expose the new configuration option
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/docs/development/design-discussions.adoc | Adds reference to new documentation for issue #405 |
| src/docs/development/_includes/issue-405.adoc | Comprehensive documentation explaining the problem, solution, and implementation |
| htmlSanityCheck-maven-plugin/src/main/java/org/aim42/htmlsanitycheck/maven/HtmlSanityCheckMojo.java | Adds junitOutputStyle parameter to Maven plugin |
| htmlSanityCheck-gradle-plugin/src/main/groovy/org/aim42/htmlsanitycheck/gradle/HtmlSanityCheckTask.groovy | Adds junitOutputStyle input property to Gradle plugin |
| htmlSanityCheck-core/src/test/groovy/org/aim42/htmlsanitycheck/report/JUnitXmlReporterTest.groovy | Adds comprehensive test coverage for both FLAT and HIERARCHICAL modes |
| htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/report/JUnitXmlReporter.java | Core implementation supporting both output styles with strategy pattern |
| htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/Configuration.java | Defines JunitOutputStyle enum and adds configuration field |
| htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/AllChecksRunner.java | Updates to pass configuration to JUnitXmlReporter |
| htmlSanityCheck-cli/src/main/groovy/org/aim42/htmlsanitycheck/cli/HscCommand.groovy | Adds CLI option for junitOutputStyle |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/report/JUnitXmlReporter.java
Outdated
Show resolved
Hide resolved
|
|
||
| // Ensure the directory exists | ||
| if (!testOutputDir.exists() && !testOutputDir.mkdirs()) { | ||
| throw new RuntimeException("Cannot create directory " + testOutputDir); //NOSONAR(S112) |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message should include more context about why directory creation failed. Consider including the original IOException details or system-specific error information to help with debugging.
| throw new RuntimeException("Cannot create directory " + testOutputDir); //NOSONAR(S112) | |
| StringBuilder errorMsg = new StringBuilder("Cannot create directory: ") | |
| .append(testOutputDir.getAbsolutePath()); | |
| errorMsg.append(" (exists: ").append(testOutputDir.exists()) | |
| .append(", canWrite: ").append(testOutputDir.getParentFile() != null ? testOutputDir.getParentFile().canWrite() : "unknown") | |
| .append(")"); | |
| throw new RuntimeException(errorMsg.toString()); //NOSONAR(S112) |
Test Results123 files ± 0 123 suites ±0 9m 2s ⏱️ - 3m 34s For more details on these failures, see this check. Results for commit bf8ce30. ± Comparison against base commit 9efca5e. This pull request removes 60 and adds 37 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
Address GitHub Copilot code review suggestions: 1. Enhanced path traversal security - Replace string-based startsWith() check with NIO Path API - Use Path.normalize() for more robust path validation - Prevent sophisticated path traversal attacks 2. Improved error diagnostics - Add detailed context to directory creation failures - Include directory existence status and parent permissions - Make debugging filesystem issues easier 3. Comprehensive test coverage - Add testPathTraversalAttackIsBlocked - Add testPathTraversalWithSymlinkStyleAttackIsBlocked - Add testEnhancedErrorMessageWhenDirectoryCreationFails - Add testEnhancedErrorMessageFormatIsCorrect - All 24 tests pass successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
@copilot Please review the latest changes addressing your previous security and error handling suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/report/JUnitXmlReporter.java
Show resolved
Hide resolved
|
|
@ascheman I have tried the fix and its working with the new I tried the instructions in the description but haven't been able to get it to work (it seems like the build on jitpack fails?). Thank you for your work! |
Thanks for trying this, @strido. I experienced similar problems on another branch/PR (cf. #429 / #431) with Jitpack meanwhile. Sorry for the inconvenience. |



Summary
Fixes #405 - Resolves "File name too long" error when generating JUnit XML reports for HTML files in deeply nested directory structures.
The solution introduces a configurable output style for JUnit XML reports:
Changes
Core Implementation
JunitOutputStyleenum as nested class inConfiguration(FLAT, HIERARCHICAL)JUnitXmlReporterto support both output modes with strategy patterngetHierarchicalOutputFile()with path normalization and security checksAllChecksRunnerto pass configuration to JUnitXmlReporterSecurity & Quality Improvements (from GitHub Copilot review)
Plugin/CLI Updates
junitOutputStyleinput propertyjunitOutputStyleparameter--junitOutputStyle/-ocommand-line optionTesting
Documentation
src/docs/development/_includes/issue-405.adocTesting with JitPack
You can test this fix before it's released by using JitPack to build from this branch:
Gradle
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
// For the Gradle plugin
classpath 'com.github.aim42.htmlSanityCheck:htmlSanityCheck-gradle-plugin:bugfix~405-enable-junit-results-per-dir-SNAPSHOT'
}
htmlSanityCheck {
junitOutputStyle = org.aim42.htmlsanitycheck.Configuration.JunitOutputStyle.HIERARCHICAL
}
```
Maven
```xml
com.github.aim42.htmlSanityCheck htmlSanityCheck-maven-plugin bugfix~405-enable-junit-results-per-dir-SNAPSHOT HIERARCHICAL \`\`\`jitpack.io
https://jitpack.io
Note: JitPack replaces
/with~in branch names, sobugfix/405-enable-junit-results-per-dirbecomesbugfix~405-enable-junit-results-per-dir-SNAPSHOTBackward Compatibility
✅ Fully backward compatible - The default value is
FLAT, maintaining existing behavior unless explicitly configured to useHIERARCHICALmode.CI Status
All workflows passing:
Related Commits