Class FileAndAspectsUtils


  • public final class FileAndAspectsUtils
    extends Object
    Utility class for aspects and files.
    • Method Detail

      • createDirectory

        public static void createDirectory​(String targetDirectoryPath)
        Method that creates a directory on the specified path (or does nothing if it already exists)
        Parameters:
        targetDirectoryPath - the directory path
      • deleteFolderContent

        public static void deleteFolderContent​(File folder)
        This function deletes the files inside the folder provided
        Parameters:
        folder - Folder containing files to delete
      • checkIfSomeFileExists

        public static boolean checkIfSomeFileExists​(File folder)
        This function checks if there is any file in folder provided
        Parameters:
        folder - Folder containing files to delete
        Returns:
        TRUE if folder is empty
      • storeClass

        public static String storeClass​(String targetDirectoryPath,
                                        String className,
                                        byte[] bs)
        Method that stores a class represented by the provided array of bytes with a certain name into a specific directory
        Parameters:
        targetDirectoryPath - the directory path
        className - the file name for the class
        bs - Bytecode of the class to store
        Returns:
        Path if it succeeds, null otherwise
      • copyFolder

        public static void copyFolder​(File src,
                                      File dest)
                               throws IOException
        Copy folder
        Parameters:
        src - Source folder
        dest - Dest folder
        Throws:
        IOException - if some exception occurs
      • find

        public static List<Class<?>> find​(String scannedPackage)
        Get all classes in package
        Parameters:
        scannedPackage - Package being scanned
        Returns:
        List of classes in package
      • weaveAspects

        public static void weaveAspects​(String binPath,
                                        String aspectpath,
                                        String[] classPath,
                                        String destPath)
        Apply aspects
        Parameters:
        binPath - Path of classes to be weaved
        aspectpath - Aspects path
        classPath - Class path (aspects are not applied here)
        destPath - Destination path of the class with aspects
      • executeCommand

        public static String executeCommand​(String[] command,
                                            boolean isWindows,
                                            boolean printOutput,
                                            Path redirectedOutput,
                                            String redirectedInput,
                                            Map<String,​String> envVariables)
        Execute command
        Parameters:
        command - Command to execute
        isWindows - Indicates if windows or Linux
        printOutput - Print output
        redirectedOutput - Path to file in which to store output of the command
        redirectedInput - TODO
        envVariables - Environment variables for the command.
      • compileClasses

        public static void compileClasses​(String srcPath,
                                          String destPath,
                                          String[] classPath,
                                          String excludePackages)
                                   throws Exception
        Compile classes
        Parameters:
        srcPath - Source path
        destPath - Destination path
        classPath - Class path
        excludePackages - Packages to exclude
        Throws:
        Exception - if some exception occurs
      • compileClassesExcluding

        public static void compileClassesExcluding​(String srcPath,
                                                   String destPath,
                                                   String[] classPath,
                                                   Set<String> excludePackages)
                                            throws Exception
        Compile classes
        Parameters:
        srcPath - Source path
        destPath - Destination path
        classPath - Class path
        excludePackages - Packages to exclude
        Throws:
        Exception - if some exception occurs
      • compileClass

        public static void compileClass​(String srcPath,
                                        String destPath,
                                        String[] classPath)
                                 throws Exception
        Compile class
        Parameters:
        srcPath - Source path
        destPath - Destination path
        classPath - Class path
        Throws:
        Exception - if some exception occurs
      • getClassNamesFromSourcePath

        public static ArrayList<String> getClassNamesFromSourcePath​(String dir,
                                                                    boolean isRoot)
        This function return a list of class names in a source path
        Parameters:
        dir - Source path to analyze
        isRoot - Must be true, used for recursive analysis
        Returns:
        List of classes found in source path