Class ClassPath


  • public class ClassPath
    extends java.lang.Object
    Represents the classpath Consolidates all classpath manipulations
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassPath​(java.lang.String classPath)
      Creates the class path
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(java.util.function.Predicate<java.lang.String> predicate)
      Returns whether any elements of this classpath match the provided predicate.
      java.util.List<java.lang.String> filter​(java.util.function.Predicate<java.lang.String> predicate)
      Returns a list of strings consisting of the elements of this classpath that match the given predicate.
      java.util.List<java.io.File> getJars​(boolean includeClasses)
      Returns a list with all the jar files that are found in the classpath.
      <T> java.util.List<T> mapToList​(java.util.function.Function<java.lang.String,​T> mapper)
      Returns a List consisting of the results of applying the given function to the elements of this classpath.
      java.lang.String mapToString​(java.util.function.Function<java.lang.String,​java.lang.String> mapper)
      Returns a String classpath consisting of the results of applying the given function to the elements of this classpath.
      java.lang.String mapWithLibs​(java.nio.file.Path libsPath, java.lang.String... libNames)
      Returns a String classpath consisting of existing classes.
      java.lang.String mapWithLibs​(java.nio.file.Path libsPath, java.util.function.Function<java.lang.String,​java.lang.String> libMap, java.util.function.Predicate<java.nio.file.Path> pathPredicate, java.lang.String... libNames)
      Returns a String classpath consisting of existing classes.
      • Methods inherited from class java.lang.Object

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

      • ClassPath

        public ClassPath​(java.lang.String classPath)
        Creates the class path
        Parameters:
        classPath - standard java classpath, delimited with File.pathSeparator. Should not be null.
    • Method Detail

      • contains

        public boolean contains​(java.util.function.Predicate<java.lang.String> predicate)
        Returns whether any elements of this classpath match the provided predicate.
        Parameters:
        predicate - predicate to apply to elements of this classpath. Should not be null.
        Returns:
        true if any elements of the stream match the provided predicate, otherwise false
      • filter

        public java.util.List<java.lang.String> filter​(java.util.function.Predicate<java.lang.String> predicate)
        Returns a list of strings consisting of the elements of this classpath that match the given predicate.
        Parameters:
        predicate - predicate to apply to elements of this classpath. Should not be null.
        Returns:
        filtered list of elements of this classpath
      • mapToList

        public <T> java.util.List<T> mapToList​(java.util.function.Function<java.lang.String,​T> mapper)
        Returns a List consisting of the results of applying the given function to the elements of this classpath.
        Type Parameters:
        T - The element type of the resulting List
        Parameters:
        mapper - function to apply to each element. Should not be null.
        Returns:
        the list
      • mapToString

        public java.lang.String mapToString​(java.util.function.Function<java.lang.String,​java.lang.String> mapper)
        Returns a String classpath consisting of the results of applying the given function to the elements of this classpath.
        Parameters:
        mapper - function to apply to each element. Should not be null.
        Returns:
        the string classpath
      • mapWithLibs

        public java.lang.String mapWithLibs​(java.nio.file.Path libsPath,
                                            java.lang.String... libNames)
        Returns a String classpath consisting of existing classes. Tries to find libraries by name and replace them with full path to this library within the given library path
        Parameters:
        libsPath - library path
        libNames - library names to look for
        Returns:
        the string classpath
      • mapWithLibs

        public java.lang.String mapWithLibs​(java.nio.file.Path libsPath,
                                            java.util.function.Function<java.lang.String,​java.lang.String> libMap,
                                            java.util.function.Predicate<java.nio.file.Path> pathPredicate,
                                            java.lang.String... libNames)
        Returns a String classpath consisting of existing classes. Tries to find libraries by name and replace them with full path to this library within the given library path. A function can be used to map the library names, if the files in the library path follow a different pattern than those on the classpath A predicate can be used to verify certain conditions to the found libraries, for instance checking that the files actually exist. If the test fails, the original string will be returned unmapped
        Parameters:
        libsPath - library path
        libMap - a function that maps the library name, can be null
        pathPredicate - test to apply to the replaced libraries, can be null
        libNames - library names to look for
        Returns:
        the string classpath
      • getJars

        public java.util.List<java.io.File> getJars​(boolean includeClasses)
                                             throws java.io.IOException,
                                                    java.lang.InterruptedException
        Returns a list with all the jar files that are found in the classpath.
        Parameters:
        includeClasses - if true, a jar will be created and added to the list, containing the compiled classes and resources of the current project
        Returns:
        a list of jar files
        Throws:
        java.io.IOException
        java.lang.InterruptedException