Class PathEnvironment


  • public class PathEnvironment
    extends java.lang.Object
    An environment for transparently making paths relative and absolute. All paths to be persisted shall be relative, all paths to be used within EASy shall be absolute. Basically, this class makes locations absolute and relative with respect to a given base folder (typically the workspace folder). Further, sets of paths may be given along with an identifying symbolic name, such as "classpath" and external classpath entires as path. In that case, the external folder will be stripped and replaced by "classpath:" while making a location relative and while making it absolute the local classpath will be considered (to map to a different user / machine). However, currently we only consider the file name in such mapping paths so that also the names of the files within one mapping must be unique.
    Author:
    Holger Eichelberger
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  PathEnvironment.Entry
      Defines a mapping entry consisting of an unique symbolic name and a set of paths.
    • Constructor Summary

      Constructors 
      Constructor Description
      PathEnvironment​(java.io.File baseFolder)
      Creates a new path environment.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addMapping​(java.lang.String name, java.lang.String... paths)
      Adds a set of paths to be made relative with the given name.
      void clear()
      Clears the mappings.
      java.io.File getBaseFolder()
      Returns the base folder.
      java.io.File makeAbsolute​(java.lang.String location)
      Makes a file location absolute with respect to the known paths in this instance.
      java.lang.String makeRelative​(java.io.File location)
      Makes a file location relative with respect to the known paths in this instance.
      void removeMapping​(java.lang.String name)
      Removes a specific mapping.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PathEnvironment

        public PathEnvironment​(java.io.File baseFolder)
        Creates a new path environment.
        Parameters:
        baseFolder - an optional folder to make locations relative
    • Method Detail

      • addMapping

        public void addMapping​(java.lang.String name,
                               java.lang.String... paths)
        Adds a set of paths to be made relative with the given name.
        Parameters:
        name - the name representing the paths
        paths - the paths to be made relative
      • removeMapping

        public void removeMapping​(java.lang.String name)
        Removes a specific mapping.
        Parameters:
        name - the name of the mapping to remove
      • clear

        public void clear()
        Clears the mappings.
      • getBaseFolder

        public java.io.File getBaseFolder()
        Returns the base folder.
        Returns:
        the base folder
      • makeRelative

        public java.lang.String makeRelative​(java.io.File location)
        Makes a file location relative with respect to the known paths in this instance.
        Parameters:
        location - the location to be turned into a relative location
        Returns:
        the relative location
      • makeAbsolute

        public java.io.File makeAbsolute​(java.lang.String location)
        Makes a file location absolute with respect to the known paths in this instance.
        Parameters:
        location - the location to be turned into an absolute location
        Returns:
        the absolute location