gnodet opened a new pull request, #11364:
URL: https://github.com/apache/maven/pull/11364
## Summary
This PR completes the migration of Maven Integration Tests from
`java.io.File` to NIO2 `Path` API, making Path-based methods the primary API
while maintaining familiar method names.
## Changes Made
### Infrastructure Migration
1. **Migrated `Verifier` class to NIO2**:
- Added Path-based overloads for `loadProperties()`, `loadFile()`,
`filterFile()`
- Replaced `FileUtils` operations with native NIO2 methods
(`Files.walk()`, `Files.copy()`, etc.)
- Implemented custom `deleteDirectoryRecursively()` using `Files.walk()`
- Updated file verification methods to use `Path` and `DirectoryStream`
- Removed dependency on `org.codehaus.plexus.util.FileUtils`
2. **Migrated `AbstractMavenIntegrationTestCase` class**:
- Changed `extractResources()` to return `Path` instead of `File`
- Updated settings file handling to use Path operations
- Removed unused `File` import
3. **Made Path-based methods primary API**:
- `extractResources()` now returns `Path` (was `File`)
- All `filterFile()` methods now return `Path` (were `File`)
- Removed all File-based wrapper methods
### Integration Tests Migration
- **Migrated 687 integration test files** to use the new Path-based API
- All tests updated to use `extractResources()` returning `Path`
- Updated variable declarations from `File` to `Path` where appropriate
- Converted `new File(dir, subpath)` patterns to `dir.resolve(subpath)`
- Updated `.getAbsolutePath()` calls to `.toString()` for Path variables
### Testing
- Added comprehensive test suite (`VerifierNIO2Test`) for new NIO2
functionality
- Added `NIO2MigrationVerificationTest` to verify common integration test
patterns
- All tests pass successfully
- Full compilation successful for entire integration test suite
## Benefits
1. **Modern API Usage**: All integration tests now use the modern NIO2 Path
API
2. **Better Performance**: NIO2 operations are generally more efficient than
legacy File operations
3. **Improved Cross-platform Compatibility**: Better handling of different
file systems
4. **Enhanced Error Handling**: More specific exceptions and better error
reporting
5. **Resource Management**: Automatic resource management with
try-with-resources
6. **Clean API Surface**: Familiar method names with modern Path-based
implementation
## Migration Statistics
- **Infrastructure files migrated**: 2 core classes
- **Integration test files migrated**: 687 files
- **File-based methods removed**: 5 methods
- **Lines of code changed**: ~4,000+ insertions/deletions
- **Compilation status**: ✅ 100% successful
- **Test status**: ✅ All tests pass
## API Changes
### Before (File-based)
```java
protected File extractResources(String resourcePath) throws IOException
public File filterFile(String srcPath, String dstPath) throws IOException
```
### After (Path-based)
```java
protected Path extractResources(String resourcePath) throws IOException
public Path filterFile(String srcPath, String dstPath) throws IOException
```
## Backward Compatibility
While the return types have changed from `File` to `Path`, the migration is
straightforward:
- `Path` can be converted to `File` using `.toFile()` if needed for legacy
APIs
- `File` can be converted to `Path` using `.toPath()`
- All method names remain the same
## Commits
1. Migrate Verifier and AbstractMavenIntegrationTestCase to NIO2
2. Migrate all integration tests to use NIO2 Path-based methods
3. Add comprehensive test for NIO2 migration verification
4. Remove deprecated File-based extractResources() method
5. Remove deprecated File-based loadFile() method from Verifier
6. Remove unused File import from AbstractMavenIntegrationTestCase
7. Complete NIO2 migration by making Path-based methods primary API
## Testing Instructions
To verify the changes:
```bash
# Compile integration test infrastructure
cd its/core-it-support/maven-it-helper
mvn clean compile test
# Compile all integration tests
cd ../../core-it-suite
mvn clean compile
```
All compilation and tests should pass successfully.
---
Pull Request opened by [Augment Code](https://www.augmentcode.com/) with
guidance from the PR author
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]