Class PathTool

java.lang.Object
org.apache.maven.shared.utils.PathTool

@Deprecated public class PathTool extends Object
Deprecated.

Path tool contains static methods to assist in determining path-related information such as relative paths.

This class originally got developed at Apache Anakia and later maintained in maven-utils of Apache Maven-1. Some external fixes by Apache Committers have been applied later.

  • Constructor Details

    • PathTool

      @Deprecated public PathTool()
      Deprecated.
      This is a utility class with only static methods. Don't create instances of it.
      The constructor.
  • Method Details

    • getRelativePath

      @Deprecated public static String getRelativePath(String basedir, String filename)
      Deprecated.
      use java.nio.file.Path.relativize() instead
      Determines the relative path of a filename from a base directory. This method is useful in building relative links within pages of a website. It provides similar functionality to Anakia's $relativePath context variable. The arguments to this method may contain either forward or backward slashes as file separators. The relative path returned is formed using forward slashes as it is expected this path is to be used as a link in a web page (again mimicking Anakia's behavior).

      This method is thread-safe.

       PathTool.getRelativePath( null, null )                                   = ""
       PathTool.getRelativePath( null, "/usr/local/java/bin" )                  = ""
       PathTool.getRelativePath( "/usr/local/", null )                          = ""
       PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin" )         = ".."
       PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "../.."
       PathTool.getRelativePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = ""
       
      Parameters:
      basedir - the base directory
      filename - the filename that is relative to the base directory
      Returns:
      the relative path of the filename from the base directory. This value is not terminated with a forward slash. A zero-length string is returned if: the filename is not relative to the base directory, basedir is null or zero-length, or filename is null or zero-length.
    • getRelativeFilePath

      @Deprecated public static String getRelativeFilePath(String oldPath, String newPath)
      Deprecated.
      use java.nio.file.Path.relativize() instead

      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: On Windows based system, the / character should be replaced by \ character.
      Parameters:
      oldPath - old path
      newPath - new path
      Returns:
      a relative file path from oldPath