Skip to content

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Oct 30, 2025

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)

protected File extractResources(String resourcePath) throws IOException
public File filterFile(String srcPath, String dstPath) throws IOException

After (Path-based)

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:

# 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 with guidance from the PR author

This commit migrates the Maven integration test infrastructure from java.io.File
to NIO2 Path API while maintaining full backward compatibility.

Changes in Verifier class:
- Added Path-based overloads for loadProperties(), loadFile(), filterFile()
- Migrated file operations to use Files.* methods instead of FileUtils
- Replaced FileUtils.deleteDirectory() with custom NIO2 implementation
- Updated file verification methods to use Path and DirectoryStream
- Removed dependency on org.codehaus.plexus.util.FileUtils

Changes in AbstractMavenIntegrationTestCase class:
- Added extractResourcesAsPath() method returning Path instead of File
- Updated settings file handling to use Path operations

Benefits:
- Better performance with NIO2 operations
- Improved error handling and cross-platform compatibility
- Modern API usage while maintaining backward compatibility
- Comprehensive test coverage for new functionality

All existing integration tests continue to work without modification.
New @SInCE 4.0.0 methods provide Path-based alternatives for modern usage.
This commit migrates all Maven integration tests from File-based operations
to the new NIO2 Path-based methods introduced in the previous commit.

Changes made:
- Replaced extractResources() with extractResourcesAsPath() in 704 test files
- Updated File variable declarations to Path where appropriate
- Replaced new File(dir, subpath) with dir.resolve(subpath) patterns
- Updated .getAbsolutePath() calls to .toString() for Path variables
- Fixed extractResources().toPath() patterns to use extractResourcesAsPath()

Migration statistics:
- 704 integration test files successfully migrated
- All tests compile successfully with new Path-based API
- Maintains full backward compatibility for any remaining File usage

The migration was performed using an automated script (migrate-its-to-nio2.py)
that identified and transformed common File-to-Path patterns while preserving
the original test logic and functionality.

Benefits:
- Modern NIO2 API usage throughout integration test suite
- Better performance with Path operations
- Improved cross-platform file handling
- Consistent API usage across all integration tests
This test verifies that all the common patterns used in integration tests
work correctly with the new NIO2 Path-based API:

- extractResourcesAsPath() method functionality
- Path.resolve() operations for subdirectories and files
- Path.toString() for verifier creation
- Backward compatibility with File-based extractResources()
- Complex path operations and parent-child relationships

All tests pass, confirming the NIO2 migration is working correctly.
The migrate-its-to-nio2.py script has served its purpose and is no longer
needed. All integration tests have been successfully migrated to use the
new NIO2 Path-based methods.
After successfully migrating all 704 integration tests to use the new
Path-based extractResourcesAsPath() method, the old File-based method
is no longer needed and has been removed.

Changes:
- Removed extractResources() method from AbstractMavenIntegrationTestCase
- Updated tests to verify Path-to-File conversion instead of backward compatibility
- All integration tests compile successfully without the deprecated method
- All unit tests pass

This completes the full migration to NIO2 Path API for integration tests.
The codebase now exclusively uses modern Path-based operations, providing
better performance, improved cross-platform compatibility, and cleaner code.
The loadFile(File, boolean) method is no longer needed as all callers
have been migrated to use the Path-based loadFile(Path, boolean) method
or the String-based convenience method.

This further reduces the File API surface in the integration test
infrastructure, completing the migration to NIO2 Path API.
The File import is no longer needed after removing the extractResources()
method. The class now exclusively uses Path for file operations.

All integration tests compile and run successfully.
This commit completes the NIO2 migration by:

1. Removing all File-based filterFile() methods from Verifier class
2. Making Path-based filterFile() methods return Path instead of File
3. Renaming extractResourcesAsPath() back to extractResources() in AbstractMavenIntegrationTestCase
4. Updating all 687 integration test files to use the renamed extractResources() method

The integration test infrastructure now uses NIO2 Path API as the primary API:
- extractResources() returns Path (was File)
- filterFile() methods return Path (were File)
- All File-based wrapper methods have been removed

This provides a clean, modern API surface while maintaining the familiar method names.
All integration tests compile and run successfully with the new Path-based API.
@gnodet gnodet marked this pull request as draft October 30, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant