Skip to content

Migrate integration tests to NIO2 Path API#11364

Open
gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:feature/nio2-integration-tests
Open

Migrate integration tests to NIO2 Path API#11364
gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:feature/nio2-integration-tests

Conversation

@gnodet

@gnodet gnodet commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

Summary

Migrate Maven Integration Tests from java.io.File to NIO2 java.nio.file.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
    • Fixed wildcard path handling on Windows
    • Added InvalidPathException fallback to File API for paths NIO2 rejects (e.g., trailing spaces on Windows)
  2. Migrated AbstractMavenIntegrationTestCase class:

    • Changed extractResources() to return Path instead of File
    • Strips leading / from resource paths — Path.resolve("/child") replaces the base entirely (unlike new File(parent, "/child") which silently strips it)
    • Updated settings file handling to use Path operations
    • Removed unused File imports
  3. Centralized FileUtils usage into ItUtils:

    • copyDirectoryStructure(), deleteDirectory(), createFile(), lastModified(), canonicalPath()
    • Uses FileUtils.copyDirectoryStructure (preserves hierarchy), Files.createFile, Files.getLastModifiedTime with existence check, Files.deleteIfExists
  4. Updated HttpServer with source(Path) overload for file-based serving

  5. Made Path-based methods the 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 735+ 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
  • Converted new File(dir, subpath) patterns to dir.resolve(subpath)
  • Updated .getAbsolutePath() calls to .toString() for Path variables
  • Replaced FileReader with Files.newBufferedReader
  • Files.deleteIfExists() where old File.delete() was lenient about missing files
  • Platform-specific fixes:
    • Windows: Drive-relative paths require File.separator prefix after Path.subpath() (strips root entirely unlike File)
    • Unix: Skip drive-relative path manipulation — Path.subpath() creates plain relative paths resolved from CWD, not from filesystem root

Testing

  • Added VerifierNIO2Test for new NIO2 functionality
  • Added NIO2MigrationVerificationTest to verify common integration test patterns
  • Added AbstractMavenIntegrationTestCaseNIO2Test
  • Full CI green: all 18 jobs pass across Ubuntu, macOS, Windows × JDK 17, 21, 25

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

Migration Statistics

  • Infrastructure files migrated: 4 core classes (Verifier, AbstractMavenIntegrationTestCase, ItUtils, HttpServer)
  • Integration test files migrated: 735+ files
  • Total files changed: 749
  • Lines changed: ~4,400 insertions / ~4,200 deletions

Key NIO2 Behavioral Differences Addressed

java.io.File java.nio.file.Path Fix
new File(parent, "/child") strips leading / Path.resolve("/child") replaces base entirely Strip leading / in extractResources()
file.lastModified() returns 0L for missing files Files.getLastModifiedTime() throws NoSuchFileException Existence check returning 0L
file.delete() returns false for missing files Files.delete() throws NoSuchFileException Use Files.deleteIfExists()
new File(path) accepts any string Paths.get(path) validates (rejects trailing spaces on Windows) Catch InvalidPathException, fall back to File API
Drive-relative paths implicit on Windows Path.subpath() strips root entirely Prepend File.separator on Windows

@gnodet gnodet marked this pull request as draft October 30, 2025 14:42
@gnodet gnodet force-pushed the feature/nio2-integration-tests branch from ee35106 to b14e415 Compare November 18, 2025 13:45
@gnodet gnodet force-pushed the feature/nio2-integration-tests branch from c68efc7 to e16c71d Compare June 16, 2026 07:43
Migrate Maven Integration Tests from java.io.File to NIO2
java.nio.file.Path API, making Path-based methods the primary API
while maintaining familiar method names.

Infrastructure:
- Verifier: Path-based overloads, NIO2 file operations, custom
  deleteDirectoryRecursively using Files.walk(), InvalidPathException
  fallback to File API for Windows trailing-space paths
- AbstractMavenIntegrationTestCase: extractResources() returns Path,
  strips leading '/' for correct Path.resolve() behavior
- ItUtils: centralized FileUtils wrappers (copyDirectoryStructure,
  deleteDirectory, createFile, lastModified)
- HttpServer: source(Path) overload for file-based serving

Test migration:
- 735+ integration test files migrated to Path-based API
- File -> Path, new File(dir, sub) -> dir.resolve(sub)
- getAbsolutePath() -> toString(), FileReader -> Files.newBufferedReader
- Files.deleteIfExists() where old File.delete() was lenient
- Platform-specific fixes: Windows drive-relative paths (File.separator
  prefix for subpath), Unix Path.subpath() skip

New tests:
- VerifierNIO2Test, NIO2MigrationVerificationTest,
  AbstractMavenIntegrationTestCaseNIO2Test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet force-pushed the feature/nio2-integration-tests branch from b2766e8 to 6b47f1c Compare June 18, 2026 21:23
@gnodet gnodet marked this pull request as ready for review June 18, 2026 21:59
@gnodet gnodet requested review from cstamas and elharo June 18, 2026 21:59
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