au.gov.tas.dpiwe.mr.tool
Class BatchFileCreator
java.lang.Object
au.gov.tas.dpiwe.mr.tool.BatchFileCreator
- Direct Known Subclasses:
- ObeyFileCreator
public class BatchFileCreator
- extends Object
This tool creates batch file versions of all shell scripts.
Shell scripts are turned into batch files as follows:
- file is copied as <script name>.bat with:
- first letter of script name capitalized
- script names ending in (j|w|e)ar(s) made to end in (J|W|E)ar(s)
- scripts names ending in on made to end in On, and those ending in
off made to end in Off
- scripts names beginning with make, docs, shift, push, distribute,
release, copy, tar, count or kill have next letter capitalized
- scripts names beginning with run, monitor, restart, status, heimlich
or flush have next letter capitalized
- scripts names beginning with create, rewrite, unstrip or strip have
next letter capitalized
- scripts names beginning with refresh, update, revert or commit have next
letter capitalized
- # comments become rem comments
- @echo off is added
- cp becomes copy
- mv becomes move
- rm becomes del
- commands expressed as paths are reduced to command filename only
- in parameters which are not quoted (this allows URLs
and passwords to be treated literally):
- / becomes \
- : becomes ;
- $ becomes %
- ~/Projects becomes \Projects
- Backticks are executed and their results are statically entered
as parameters in the resulting script. This means that if the
results change, you will need to recreate the batch file. The
backtick commands are not translated in any way, so if they contain
OS dependent stuff, then the conversion can only be performed in
the source operating system. Backticks which require parameter
substuitutions will not work, and will be converted to the string
"null"
- Piping is removed, so make sure you don't use pipes for
operational code intended for conversion to a batch scripts
This is all pretty simplistic. If your shell scripts are using full
pathnames as command paths, or a lot of switches or operational pipes, you
will have problems. Also, the above is the complete command set you can use
unless there is an equivalent executable in your DOS environment. e.g.
You can call java and javac provided you have installed these into your
DOS environment.
- Since:
- Mr Architecture 2.9
- Version:
- 1.0.0.8
- Author:
- Kade Hansson
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
returnCode
protected static ThreadLocal returnCode
BatchFileCreator
public BatchFileCreator()
main
public static void main(String[] argv)
throws Throwable
- Initiates the BatchFileCreator tool.
- The switch "-single" introduces the following parameters as single
filenames. If you don't specify a switch, "-single" is assumed.
- The switch "-multi" introduces the following parameters as directory
names, which are recursively searched for all ".sh" script files.
- Parameters:
argv - arguments are filenames, directory names or switches (one of
"-single" or "-multi").
- Throws:
IOException - if the input files could not be read or the output
files could not be written.
SecurityException - if the configured security policy is too
restrictive.
Throwable - if something else goes wrong.
createBatchFile
public static boolean createBatchFile(String toRewrite)
throws InterruptedException,
IOException,
SecurityException
- Produce a batch file copy of a shell script.
- Parameters:
toRewrite - the name of the file to be copied.
- Returns:
- true if the file was successfully rewritten, false if the file
remains unchanged.
- Throws:
SecurityException - if the configured security policy is too
restrictive.
IOException - if the input files could not be read or the output
file could not be written.
InterruptException - another thread interrupted us.
InterruptedException
translateLeaf
protected static String translateLeaf(String leaf)
rewriteAsBatch
public static void rewriteAsBatch(Reader input,
PrintWriter output,
File parentDir)
throws InterruptedException,
IOException
- Produce a batch file corresponding to a shell script file.
- Parameters:
input - the Reader from which the original shell script should be read.output - the PrintWriter to which the created batch file should
be written.parentDir - the directory containing the input file.
- Throws:
IOException - if the input file could not be read or the output
file could not be written.
InterruptException - another thread interrupted us.
InterruptedException
getBacktickProcess
protected static Process getBacktickProcess(String commandPath,
StringTokenizer newCommand,
File parentDir)
throws IOException
- Throws:
IOException