Class FileUtilities

java.lang.Object
org.netbeans.modules.maven.api.FileUtilities

public final class FileUtilities extends Object
Various File/FileObject related utilities.
  • Method Details

    • convertURItoFileObject

      @CheckForNull public static org.openide.filesystems.FileObject convertURItoFileObject(@NullAllowed URI uri)
    • convertStringToFileObject

      @CheckForNull public static org.openide.filesystems.FileObject convertStringToFileObject(@NullAllowed String str)
    • convertStringToFile

      @NullUnknown public static File convertStringToFile(@NullAllowed String str)
      converts a string representing a path to a normalized File instance
      Parameters:
      str -
      Returns:
    • convertStringToUri

      @NullUnknown public static URI convertStringToUri(@NullAllowed String str)
    • convertArtifactToLocalRepositoryFile

      public static File convertArtifactToLocalRepositoryFile(org.apache.maven.artifact.Artifact artifact)
      take any (even unresolved) Maven Arfifact instance and construct a local repository based File instance for it. The file does not have to exist though.
      Parameters:
      artifact -
      Returns:
    • resolveFilePath

      public static File resolveFilePath(File basedir, String filename)
      copied from netbeans.org's ant/project sources. will find out if path is relative or absolute
    • getDirURI

      public static URI getDirURI(@NonNull File root, @NonNull String path)
    • getDirURI

      public static URI getDirURI(@NonNull org.openide.filesystems.FileObject root, @NonNull String path)
    • getRelativePath

      public static String getRelativePath(File dir, File file)
      get relative path between file and it's child. if not child, return null.
      Parameters:
      dir -
      file -
      Returns:
    • relativizeFile

      public static String relativizeFile(File basedir, File file)
      Produce a machine-independent relativized version of a filename from a basedir. Unlike URI.relativize(java.net.URI) this will produce "../" sequences as needed.
      Parameters:
      basedir - a directory to resolve relative to (need not exist on disk)
      file - a file or directory to find a relative path for
      Returns:
      a relativized path (slash-separated), or null if it is not possible (e.g. different DOS drives); just . in case the paths are the same
      Throws:
      IllegalArgumentException - if the basedir is known to be a file and not a directory copied from project.ant's PropertyUtils
    • getPackageNames

      public static SortedSet<String> getPackageNames(org.netbeans.api.project.Project prj)
      Inspired by org.netbeans.modules.apisupport.project.Util.scanProjectForPackageNames Returns sorted set of given project's package names in x.y.z form. Result contains only packages which are valid as candidates for public packages - contains some *.class or *.java
      Parameters:
      prj - project to retrieve package names from
      Returns:
      Sorted set of package names
    • getBasePackageNames

      public static SortedSet<String> getBasePackageNames(org.netbeans.api.project.Project prj)
      Returns:
      Set of names of root packages containing some *.class or *.java. Result doesn't contain subfolders of such folders
    • getUserSettingsFile

      public static File getUserSettingsFile(boolean forceCreate)
      Get the user settings.xml file.
      Parameters:
      forceCreate - determines whether file should be created in case it does not exist
      Returns:
      either the settings.xml file or null if not available