Package org.eclipse.persistence.tools
Class PackageRenamer
java.lang.Object
org.eclipse.persistence.tools.PackageRenamer
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.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionThe constructor of a PackageRenamer class.PackageRenamer
(String propertiesFileName) PackageRenamer
(String[] args) -
Method Summary
Modifier and TypeMethodDescriptionprotected String
void
binaryCopy
(File inFile, File outFile) Do a binary copy of the file byte buffer by byte buffer.protected boolean
bufferContainsNullChar
(byte[] buffer, int bufferLength) buildAndCheckDestinationFile
(String aDirString) INTERNAL Creates a destination directory File object under the path passed, verifying correctness.buildAndCheckExistingDirFile
(String aDirString) buildAndCheckLogWriter
(String logFileString) protected void
cleanup()
void
createDestinationDirectory
(File aDirectory) This method creates an output directory for post-rename file(s).static boolean
directoryIsSubdirectory
(File directory1, File directory2) Return true if directory2 is contained within directory1.static String
boolean
isExtensionSupported
(String extension) Return true if the PackageRenamer should work on the given file extension.void
static void
Main method to run the PackageRenamerparseFileExtension
(File aFile) Returns the extension of the given file.protected File
INTERNAL Prompt from System.in for an empty or non-existent directory to use as the destination directory.readChangesFile
(String filename) This readChangesFile() method reads the given properties file to be a reference for renaming TopLink package name.static String
Do a search and replace in a string.returnNewFileNameIfRequired
(String aSourceFileNameWithoutRoot) Renames a file based on the properties passed.void
run()
This run() method performs, reading the properties file into properties variable to be a reference for changing package name.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.protected PrintWriter
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.static void
usage()
-
Field Details
-
SYSTEM_OUT
- See Also:
-
-
Constructor Details
-
PackageRenamer
public PackageRenamer()The constructor of a PackageRenamer class. -
PackageRenamer
-
PackageRenamer
-
-
Method Details
-
bannerText
-
binaryCopy
Do a binary copy of the file byte buffer by byte buffer.- Parameters:
inFile
- The file to copyoutFile
- The destination file- Throws:
FileNotFoundException
- if either of the two files does not existIOException
- if any other IO related error occurs
-
bufferContainsNullChar
protected boolean bufferContainsNullChar(byte[] buffer, int bufferLength) -
buildAndCheckDestinationFile
INTERNAL Creates a destination directory File object under the path passed, verifying correctness.- Parameters:
aDirString
- The path to the directory File object to create- Returns:
- The destination directory File object
-
buildAndCheckExistingDirFile
-
buildAndCheckLogWriter
-
cleanup
protected void cleanup() -
createDestinationDirectory
This method creates an output directory for post-rename file(s).- Parameters:
aDirectory
- The output directory to create
-
directoryIsSubdirectory
Return true if directory2 is contained within directory1. Both directories must be absolute.- Parameters:
directory1
- The higher level directorydirectory2
- The lower level directory- Returns:
- TRUE if directory2 is a subdirectory of directory1
-
existingDirectoryFromPrompt
-
getDefaultPropertiesFileName
-
getReader
-
isExtensionSupported
Return true if the PackageRenamer should work on the given file extension.- Parameters:
extension
- The file extension to check for being supported- Returns:
- TRUE if the extension is supported
-
logln
- Parameters:
str
- The String to log
-
main
Main method to run the PackageRenamer- Parameters:
args
- Command line arguments
-
parseFileExtension
Returns the extension of the given file.- Parameters:
aFile
- The file of which to retrieve the extension- Returns:
- The file extension or an empty string if none was found.
-
promptForDestinationDirectory
INTERNAL Prompt from System.in for an empty or non-existent directory to use as the destination directory.- Returns:
- The destination directory File object
-
readChangesFile
This readChangesFile() method reads the given properties file to be a reference for renaming TopLink package name.- Parameters:
filename
- The input file to use for the renaming- Returns:
- 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
-
runSearchAndReplacePackageName
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.- Parameters:
sourceFile
- The source file to process
-
replace
Do a search and replace in a string.- Parameters:
str
- The original StringoldChars
- The character pattern to replacenewChars
- The character pattern to replace the existing with- Returns:
- the modified String
-
returnNewFileNameIfRequired
Renames a file based on the properties passed.- Parameters:
aSourceFileNameWithoutRoot
- The original filename- Returns:
- The new filename, regardless of whether is has been changed
-
traverseSourceDirectory
This traverseSourceDirectory() traverse source-root-directory, creating an corresponding output directory, and calling another method for replacing old TopLink package name.- Parameters:
aDirectoryString
- The source root directory to traverse
-
usage
public static void usage()
-