Class DirectoryUtils


  • public final class DirectoryUtils
    extends java.lang.Object
    A utility class to calculate (and create if needed) paths backed by directories using configuration properties from repository system session and others.
    Since:
    1.9.0
    See Also:
    RepositorySystemSession.getConfigProperties(), RepositorySystemSession.getLocalRepository()
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.nio.file.Path resolveDirectory​(java.lang.String name, java.nio.file.Path base, boolean mayCreate)
      Creates Path instance out of passed in name parameter.
      static java.nio.file.Path resolveDirectory​(org.eclipse.aether.RepositorySystemSession session, java.lang.String defaultName, java.lang.String nameKey, boolean mayCreate)
      Creates Path instance out of session configuration, and (if relative) resolve it against local repository basedir.
      • Methods inherited from class java.lang.Object

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

      • resolveDirectory

        public static java.nio.file.Path resolveDirectory​(java.lang.String name,
                                                          java.nio.file.Path base,
                                                          boolean mayCreate)
                                                   throws java.io.IOException
        Creates Path instance out of passed in name parameter. May create a directory on resulting path, if not exist, when invoked with mayCreate being true. Never returns null.

        Following outcomes may happen:

        • name is absolute path - results in Path instance created directly from name.
        • name is relative path - results in Path instance resolved against base parameter.
        Resulting path is being checked is a directory, and if not, it will be created if mayCreate is true. If resulting path exist but is not a directory, this method will throw.
        Parameters:
        name - The name to create directory with, cannot be null.
        base - The base Path to resolve name, if it is relative path, cannot be null.
        mayCreate - If resulting path does not exist, should it create?
        Returns:
        The Path instance that is resolved and backed by existing directory.
        Throws:
        java.io.IOException - If some IO related errors happens.
      • resolveDirectory

        public static java.nio.file.Path resolveDirectory​(org.eclipse.aether.RepositorySystemSession session,
                                                          java.lang.String defaultName,
                                                          java.lang.String nameKey,
                                                          boolean mayCreate)
                                                   throws java.io.IOException
        Creates Path instance out of session configuration, and (if relative) resolve it against local repository basedir. Pre-populates values and invokes resolveDirectory(String, Path, boolean).

        For this method to work, LocalRepository.getBasedir() must return non-null value, otherwise NullPointerException is thrown.

        Parameters:
        session - The session, may not be null.
        defaultName - The default value if not present in session configuration, may not be null.
        nameKey - The key to look up for in session configuration to obtain user set value.
        mayCreate - If resulting path does not exist, should it create?
        Returns:
        The Path instance that is resolved and backed by existing directory.
        Throws:
        java.io.IOException - If some IO related errors happens.
        See Also:
        resolveDirectory(String, Path, boolean)