Class FilteringUtils

java.lang.Object
org.apache.maven.shared.filtering.FilteringUtils

public final class FilteringUtils extends Object
Author:
Olivier Lamy, Dennis Lundberg
  • Field Details

  • Method Details

    • escapeWindowsPath

      public static String escapeWindowsPath(String val)
      Parameters:
      val - The value to be escaped.
      Returns:
      Escaped value
    • resolveFile

      public static Path resolveFile(Path baseFile, String filename)
      Resolve a file filename to its canonical form. If filename is relative (doesn't start with /), it is resolved relative to baseFile. Otherwise it is treated as a normal root-relative path.
      Parameters:
      baseFile - where to resolve filename from, if filename is relative
      filename - absolute or relative file path to resolve
      Returns:
      the canonical File of filename
    • getRelativeFilePath

      public static String getRelativeFilePath(String oldPath, String newPath)

      This method can calculate the relative path between two paths on a file system.

      PathTool.getRelativeFilePath( null, null )                                   = ""
      PathTool.getRelativeFilePath( null, "/usr/local/java/bin" )                  = ""
      PathTool.getRelativeFilePath( "/usr/local", null )                           = ""
      PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin" )          = "java/bin"
      PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin/" )         = "java/bin"
      PathTool.getRelativeFilePath( "/usr/local/java/bin", "/usr/local/" )         = "../.."
      PathTool.getRelativeFilePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "java/bin/java.sh"
      PathTool.getRelativeFilePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = "../../.."
      PathTool.getRelativeFilePath( "/usr/local/", "/bin" )                        = "../../bin"
      PathTool.getRelativeFilePath( "/bin", "/usr/local/" )                        = "../usr/local/"
      
      Note: The path separator is always /, regardless of the operating system.
      Parameters:
      oldPath - old path
      newPath - new path
      Returns:
      a relative file path from oldPath.
    • copyFile

      @Deprecated public static void copyFile(Path from, Path to, String encoding, FilterWrapper[] wrappers, boolean overwrite) throws IOException
      If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if overwrite is true.
      Parameters:
      from - the file to copy
      to - the destination file
      encoding - the encoding used for both reading and writing (only if wrappers is not empty)
      wrappers - array of FilterWrapper
      overwrite - if true, uses ChangeDetection.ALWAYS; if false, uses ChangeDetection.CONTENT
      Throws:
      IOException - if an IO error occurs during copying or filtering
    • copyFile

      public static boolean copyFile(Path from, Path to, String encoding, FilterWrapper[] wrappers, ChangeDetection changeDetection) throws IOException
      Copies a file from the source to the destination, applying the specified filters if provided.
      Parameters:
      from - the file to copy
      to - the destination file
      encoding - the file output encoding (only if wrappers is not empty)
      wrappers - array of FilterWrapper
      changeDetection - the strategy to apply if to is existing file
      Returns:
      true if the file was copied.
      Throws:
      IOException - if an IO error occurs during copying or filtering
      Since:
      4.0.0-beta-2
    • copyFile

      public static boolean copyFile(Path from, Path to, String inputEncoding, String outputEncoding, FilterWrapper[] wrappers, ChangeDetection changeDetection) throws IOException
      Copy and optionally filter a file using separate input and output encodings. This allows encoding conversion during resource filtering (e.g. reading ISO-8859-1 and writing UTF-8). If wrappers is null or empty, the file is copied as raw bytes — encoding parameters are ignored in that case.
      Parameters:
      from - the file to copy
      to - the destination file
      inputEncoding - the charset used to read from (only when wrappers is not empty)
      outputEncoding - the charset used to write to (only when wrappers is not empty)
      wrappers - array of FilterWrapper
      changeDetection - the strategy to apply if to is existing file
      Returns:
      true if the file was copied.
      Throws:
      IOException - if an IO error occurs during copying or filtering
      Since:
      4.0.0-beta-3