Class PackageRenamer

  • public class PackageRenamer
    extends Object
    This class performs package renaming. It demonstrates the following: a) Reading the properties file to be a reference for changing the package name from your source code. b) Traverse source root directory for creating a corresponding output directory and finding the java source file(s) to be changing the package name. c) Search and replace the old TopLink package name(s) with new one(s) according to the reference. You will be able to see the logging message at the command line window where the PackageRenamer is running.
    • Constructor Detail

      • PackageRenamer

        public PackageRenamer()
        The constructor of a PackageRenamer class.
      • PackageRenamer

        public PackageRenamer​(String propertiesFileName)
      • PackageRenamer

        public PackageRenamer​(String[] args)
    • Method Detail

      • bannerText

        protected String bannerText()
      • binaryCopy

        public void binaryCopy​(File inFile,
                               File outFile)
                        throws FileNotFoundException,
        Do a binary copy of the file byte buffer by byte buffer.
        inFile - The file to copy
        outFile - The destination file
        FileNotFoundException - if either of the two files does not exist
        IOException - if any other IO related error occurs
      • bufferContainsNullChar

        protected boolean bufferContainsNullChar​(byte[] buffer,
                                                 int bufferLength)
      • buildAndCheckDestinationFile

        public File buildAndCheckDestinationFile​(String aDirString)
        INTERNAL Creates a destination directory File object under the path passed, verifying correctness.
        aDirString - The path to the directory File object to create
        The destination directory File object
      • buildAndCheckExistingDirFile

        public File buildAndCheckExistingDirFile​(String aDirString)
      • buildAndCheckLogWriter

        public PrintWriter buildAndCheckLogWriter​(String logFileString)
      • cleanup

        protected void cleanup()
      • createDestinationDirectory

        public void createDestinationDirectory​(File aDirectory)
        This method creates an output directory for post-rename file(s).
        aDirectory - The output directory to create
      • directoryIsSubdirectory

        public static boolean directoryIsSubdirectory​(File directory1,
                                                      File directory2)
        Return true if directory2 is contained within directory1. Both directories must be absolute.
        directory1 - The higher level directory
        directory2 - The lower level directory
        TRUE if directory2 is a subdirectory of directory1
      • existingDirectoryFromPrompt

        public File existingDirectoryFromPrompt()
      • getDefaultPropertiesFileName

        public static String getDefaultPropertiesFileName()
      • isExtensionSupported

        public boolean isExtensionSupported​(String extension)
        Return true if the PackageRenamer should work on the given file extension.
        extension - The file extension to check for being supported
        TRUE if the extension is supported
      • logln

        public void logln​(String str)
        str - The String to log
      • main

        public static void main​(String[] args)
        Main method to run the PackageRenamer
        args - Command line arguments
      • parseFileExtension

        public String parseFileExtension​(File aFile)
        Returns the extension of the given file.
        aFile - The file of which to retrieve the extension
        The file extension or an empty string if none was found.
      • promptForDestinationDirectory

        protected File promptForDestinationDirectory()
        INTERNAL Prompt from for an empty or non-existent directory to use as the destination directory.
        The destination directory File object
      • readChangesFile

        public Properties readChangesFile​(String filename)
        This readChangesFile() method reads the given properties file to be a reference for renaming TopLink package name.
        filename - The input file to use for the renaming
        The Properties object containing the renaming information
      • run

        public void run()
        This run() method performs, reading the properties file into properties variable to be a reference for changing package name. creating an destination-root-direetory. and, calling traverseSourceDirectory() method.
      • streamForNonExistentFilePrompt

        protected PrintWriter streamForNonExistentFilePrompt()
      • runSearchAndReplacePackageName

        public void runSearchAndReplacePackageName​(File sourceFile)
        This runSearchAndReplacePackageName() reads a pre-rename source file all into string variable and replacing the old package names with the new ones according to the properties file.
        sourceFile - The source file to process
      • replace

        public static String replace​(String str,
                                     String oldChars,
                                     String newChars)
        Do a search and replace in a string.
        str - The original String
        oldChars - The character pattern to replace
        newChars - The character pattern to replace the existing with
        the modified String
      • returnNewFileNameIfRequired

        public String returnNewFileNameIfRequired​(String aSourceFileNameWithoutRoot)
        Renames a file based on the properties passed.
        aSourceFileNameWithoutRoot - The original filename
        The new filename, regardless of whether is has been changed
      • traverseSourceDirectory

        public void traverseSourceDirectory​(File aDirectoryString)
        This traverseSourceDirectory() traverse source-root-directory, creating an corresponding output directory, and calling another method for replacing old TopLink package name.
        aDirectoryString - The source root directory to traverse
      • usage

        public static void usage()