mattcasters opened a new pull request, #8256:
URL: https://github.com/apache/hop/pull/8256
Fixes #2402
### Description
In Apache Hop, specifying a path starting with `~` (e.g. `~/testenv` or
`~\testenv` on Windows) resulted in a folder literally named `~` created inside
the Hop installation base directory (`user.dir`), because neither standard Java
nor Apache Commons VFS expands tilde to the user's home directory.
This PR adds system-wide support for `~` (tilde) at the start of paths to
mean `${user.home}` across Apache Hop on all platforms (including Windows with
backslash `\` separators).
### Changes
- **Core Virtual File System (`hop-core`)**:
- Added `HopVfs.resolveHomeDirectory(String path, IVariables variables)`
and `HopVfs.resolveHomeDirectory(String path)`.
- Expands exact `~`, `~/...`, `~\...`, as well as `file://~...` and
`file:~...` to `${user.home}`.
- Preserves non-start occurrences (e.g. `/opt/hop/~`, `foo~bar`,
`s3://bucket/~/key`) and non-separator suffixes (e.g. `~username`, `~temp`).
- Uses `${user.home}` from `IVariables` when provided, falling back to
`System.getProperty("user.home")`.
- Integrated `resolveHomeDirectory` into `HopVfs.resolveWith()` so that
all file operations (`getFileObject`, `fileExists`, `getInputStream`, etc.)
resolve tilde paths transparently.
- Updated `HopVfs.isAbsolutePath()` to recognize tilde paths as absolute
so they are not treated as relative to the working directory.
- **Projects Plugin (`hop-misc-projects`)**:
- Updated `PathVariableReplacer.isCandidatePathValue()` to accept tilde
paths (`~`, `~/...`, `~\...`) for project variable rewriting.
- Updated `ProjectsMetadataExporter.resolveExportFilename()` to use
`HopVfs.isAbsolutePath()`.
- **Git Plugin (`hop-misc-git`)**:
- Delegated `CaseInsensitiveIgnores.replaceUserHome()` to
`HopVfs.resolveHomeDirectory()`.
- **Documentation**:
- Updated `vfs.adoc` documenting `~` under the `File` provider with POSIX
and Windows syntax rules and examples.
- Updated `variables.adoc` with a dedicated section on the `~` user home
shortcut.
- Updated `projects-environments.adoc` documenting that `~` can be used in
the project Home folder and environment variables.
- **Unit Tests**:
- Added unit test coverage in `HopVfsTest` and `PathVariableReplacerTest`.
--
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]