Revision: 5312 http://jnode.svn.sourceforge.net/jnode/?rev=5312&view=rev Author: chrisboertien Date: 2009-04-19 17:25:18 +0000 (Sun, 19 Apr 2009)
Log Message: ----------- Cosmetic fixes to fs commands. Pulled strings out of code. Fixed up variable names. Signed-off-by: chrisboertien <chris.boert...@gmail.com> Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/command/CdCommand.java trunk/fs/src/fs/org/jnode/fs/command/CpCommand.java trunk/fs/src/fs/org/jnode/fs/command/DFCommand.java trunk/fs/src/fs/org/jnode/fs/command/DeleteCommand.java trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java trunk/fs/src/fs/org/jnode/fs/command/FindCommand.java trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java trunk/fs/src/fs/org/jnode/fs/command/Md5SumCommand.java trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java trunk/fs/src/fs/org/jnode/fs/command/PwdCommand.java trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java Modified: trunk/fs/src/fs/org/jnode/fs/command/CdCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CdCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/CdCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -37,12 +37,17 @@ */ public class CdCommand extends AbstractCommand { - private final FileArgument ARG_DIR = new FileArgument( - "directory", Argument.OPTIONAL | Argument.EXISTING, "the directory to change to"); + private static final String help_dir = "the directory to change to"; + private static final String help_super = "Change the current directory"; + private static final String err_home = "user.home is not set"; + private static final String err_dir_invalid = "%s is not a valid directory%n"; + + private final FileArgument argDir = new FileArgument( + "directory", Argument.OPTIONAL | Argument.EXISTING, help_dir); public CdCommand() { - super("Change the current directory"); - registerArguments(ARG_DIR); + super(help_super); + registerArguments(argDir); } public static void main(String[] args) throws Exception { @@ -51,13 +56,13 @@ public void execute() throws IOException { - File dir = ARG_DIR.getValue(); + File dir = argDir.getValue(); PrintWriter err = getError().getPrintWriter(); if (dir == null) { // If no directory argument was given, change to the "user.home" directory. String home = System.getProperty("user.home"); if (home == null || home.isEmpty()) { - err.println("user.home is not set"); + err.println(err_home); exit(1); } dir = new File(home); @@ -65,7 +70,7 @@ if (dir.exists() && dir.isDirectory()) { System.setProperty("user.dir", dir.getAbsoluteFile().getCanonicalPath()); } else { - err.println(dir + " is not a valid directory"); + err.format(err_dir_invalid, dir); exit(1); } } Modified: trunk/fs/src/fs/org/jnode/fs/command/CpCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CpCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/CpCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -43,33 +43,57 @@ */ public class CpCommand extends AbstractCommand { + private static final String help_source = "source files or directories"; + private static final String help_target = "target file or directory"; + private static final String help_force = "if set, force overwrite of existing files"; + private static final String help_interactive = "if set, ask before overwriting existing files"; + private static final String help_update = "if set, overwrite existing files older than their source"; + private static final String help_recurse = "if set, recursively copy source directories"; + private static final String help_verbose = "if set, output a line for each file copied"; + private static final String help_super = "Copy files and directories"; + private static final String err_no_source = "No source files or directories supplied"; + private static final String err_no_write = "Target directory is not writable"; + private static final String err_multi_dir = "Multi-file copy requires the target to be a directory"; + private static final String err_copy_dir_file = "Cannot copy a directory to a file"; + private static final String err_copy_dev = "Cannot copy to a device"; + private static final String fmt_verbose_copy = "File copied: %d, directories created: %d%n"; + private static final String err_mutex_flags = "The force, interactive and update flags are mutually exclusive"; + private static final String fmt_no_write = "directory '%s' is not writeable"; + private static final String fmt_dir_create = "Creating directory '%s'%n"; + private static final String fmt_dir_replace = "Replacing file '%s' with a directory%n"; + private static final String fmt_dir_skip = "not overwriting '%s' with a directory"; + private static final String fmt_is_dir = "'%s' is a directory"; + private static final String fmt_copy_file = "Copying file '%s' as '%s'%n"; + private static final String fmt_src_noexist = "'%s' does not exist"; + private static final String fmt_src_noread = "'%s' cannot be read"; + private static final String fmt_src_device = "'%s' is a device"; + private static final String fmt_copy_dir_self = "Cannot copy directory '%s' into itself"; + private static final String fmt_copy_file_self = "Cannot copy file '%s' to itself"; + private static final String fmt_copy_sub = "Cannot copy directory '%s' into a subdirectory ('%s')"; + private static final String fmt_no_copy_dir = "Cannot copy '%s' onto directory '%s'"; + private static final String fmt_no_copy_dev = "Cannot copy '%s' to device '%s'"; + private static final String fmt_exists = "'%s' already exists"; + private static final String fmt_newer = "'%s' is newer than '%s'"; + private static final String fmt_ask_overwrite = "Overwrite '%s' with '%s'? [y/n]%n"; + private static final String err_copy_eof = "EOF - abandoning copying"; + private static final String err_copy_ioex = "IO Error - abandoning copying"; + private static final String str_ask_again = "Answer 'y' or 'n'"; + private static final String fmt_skip = "%s: skipping%n"; + static final byte MODE_NORMAL = 0; static final byte MODE_INTERACTIVE = 1; static final byte MODE_FORCE = 2; static final byte MODE_UPDATE = 3; - private final FileArgument ARG_SOURCE = - new FileArgument("source", Argument.MANDATORY | Argument.MULTIPLE | Argument.EXISTING, - "source files or directories"); + private final FileArgument argSource = + new FileArgument("source", Argument.MANDATORY | Argument.MULTIPLE | Argument.EXISTING, help_source); + private final FileArgument argTarget = new FileArgument("target", Argument.MANDATORY, help_target); + private final FlagArgument argForce = new FlagArgument("force", Argument.OPTIONAL, help_force); + private final FlagArgument argInteractive = new FlagArgument("interactive", Argument.OPTIONAL, help_interactive); + private final FlagArgument argUpdate = new FlagArgument("update", Argument.OPTIONAL, help_update); + private final FlagArgument argRecursive = new FlagArgument("recursive", Argument.OPTIONAL, help_recurse); + private final FlagArgument argVerbose = new FlagArgument("verbose", Argument.OPTIONAL, help_verbose); - private final FileArgument ARG_TARGET = - new FileArgument("target", Argument.MANDATORY, "target file or directory"); - - private final FlagArgument FLAG_FORCE = - new FlagArgument("force", Argument.OPTIONAL, "if set, force overwrite of existing files"); - - private final FlagArgument FLAG_INTERACTIVE = - new FlagArgument("interactive", Argument.OPTIONAL, "if set, ask before overwriting existing files"); - - private final FlagArgument FLAG_UPDATE = - new FlagArgument("update", Argument.OPTIONAL, "if set, overwrite existing files older than their source"); - - private final FlagArgument FLAG_RECURSIVE = - new FlagArgument("recursive", Argument.OPTIONAL, "if set, recursively copy source directories"); - - private final FlagArgument FLAG_VERBOSE = - new FlagArgument("verbose", Argument.OPTIONAL, "if set, output a line for each file copied"); - private byte mode = MODE_NORMAL; private boolean recursive = false; private boolean verbose = false; @@ -81,9 +105,9 @@ private byte[] buffer = new byte[1024 * 8]; public CpCommand() { - super("Copy files or directories"); - registerArguments(ARG_SOURCE, ARG_TARGET, FLAG_FORCE, FLAG_INTERACTIVE, FLAG_RECURSIVE, - FLAG_UPDATE, FLAG_VERBOSE); + super(help_super); + registerArguments(argSource, argTarget, argForce, argInteractive, argRecursive, + argUpdate, argVerbose); } public static void main(String[] args) throws Exception { @@ -97,14 +121,14 @@ if (mode == MODE_INTERACTIVE) { this.in = new BufferedReader(getInput().getReader()); } - File[] sources = ARG_SOURCE.getValues(); - File target = ARG_TARGET.getValue(); + File[] sources = argSource.getValues(); + File target = argTarget.getValue(); if (sources.length == 0) { - error("No source files or directories supplied"); + error(err_no_source); } if (target.isDirectory()) { if (!target.canWrite()) { - error("Target directory is not writable"); + error(err_no_write); } for (File source : sources) { if (checkSafe(source, target)) { @@ -112,13 +136,13 @@ } } } else if (sources.length > 1) { - error("Multi-file copy requires the target to be a directory"); + error(err_multi_dir); } else { File source = sources[0]; if (source.isDirectory()) { - error("Cannot copy a directory to a file"); + error(err_copy_dir_file); } else if (target.exists() && !target.isFile()) { - error("Cannot copy to a device"); + error(err_copy_dev); } else { if (checkSafe(source, target)) { copyToFile(source, target); @@ -126,26 +150,26 @@ } } if (verbose) { - out.println("Files copied: " + filesCopied + ", directories created: " + directoriesCreated); + out.format(fmt_verbose_copy, filesCopied, directoriesCreated); } } - + private void processFlags() { - recursive = FLAG_RECURSIVE.isSet(); - verbose = FLAG_VERBOSE.isSet(); + recursive = argRecursive.isSet(); + verbose = argVerbose.isSet(); // The mode flags are mutually exclusive ... - if (FLAG_FORCE.isSet()) { + if (argForce.isSet()) { mode = MODE_FORCE; } - if (FLAG_INTERACTIVE.isSet()) { + if (argInteractive.isSet()) { if (mode != MODE_NORMAL) { - error("The 'force', 'interactive' and 'update' flags are mutually exclusive"); + error(err_mutex_flags); } mode = MODE_INTERACTIVE; } - if (FLAG_UPDATE.isSet()) { + if (argUpdate.isSet()) { if (mode != MODE_NORMAL) { - error("The 'force', 'interactive' and 'update' flags are mutually exclusive"); + error(err_mutex_flags); } mode = MODE_UPDATE; } @@ -160,26 +184,26 @@ */ private void copyIntoDirectory(File source, File targetDir) throws IOException { if (!targetDir.canWrite()) { - skip("directory '" + targetDir + "' is not writable"); + skip(String.format(fmt_no_write, targetDir)); } else if (source.isDirectory()) { if (recursive) { File newDir = new File(targetDir, source.getName()); if (!newDir.exists()) { if (verbose) { - out.println("Creating directory '" + newDir + "'"); + out.format(fmt_dir_create, newDir); } newDir.mkdir(); directoriesCreated++; } else if (!newDir.isDirectory()) { if (mode == MODE_FORCE) { if (verbose) { - out.println("Replacing file '" + newDir + "' with a directory"); + out.format(fmt_dir_replace, newDir); } newDir.delete(); newDir.mkdir(); directoriesCreated++; } else { - skip("not overwriting '" + newDir + "' with a directory"); + skip(String.format(fmt_dir_skip, newDir)); return; } } @@ -191,7 +215,7 @@ copyIntoDirectory(new File(source, name), newDir); } } else { - skip("'" + source + "' is a directory"); + skip(String.format(fmt_is_dir, source)); } } else { File newFile = new File(targetDir, source.getName()); @@ -213,7 +237,7 @@ return; } if (verbose) { - out.println("Copying file '" + sourceFile + "' as '" + targetFile + "'"); + out.format(fmt_copy_file, sourceFile, targetFile); } InputStream sin = null; @@ -256,11 +280,11 @@ */ private boolean checkSource(File source) { if (!source.exists()) { - return skip("'" + source + "' does not exist"); + return skip(String.format(fmt_src_noexist, source)); } else if (!source.canRead()) { - return skip("'" + source + "' cannot be read"); + return skip(String.format(fmt_src_noread, source)); } else if (!(source.isFile() || source.isDirectory())) { - return vskip("'" + source + "' is a device"); + return vskip(String.format(fmt_src_device, source)); } else { return true; } @@ -283,19 +307,18 @@ if (target.isDirectory()) { if (recursive && source.isDirectory()) { if (sourcePath.equals(targetPath)) { - return skip("Cannot copy directory '" + source + "' into itself"); + return skip(String.format(fmt_copy_dir_self, source)); } if (!sourcePath.endsWith(File.separator)) { sourcePath = sourcePath + File.separatorChar; } if (targetPath.startsWith(sourcePath)) { - return skip("Cannot copy directory '" + source + - "' into a subdirectory ('" + target + "')"); + return skip(String.format(fmt_copy_sub, source, target)); } } } else { if (sourcePath.equals(targetPath)) { - return skip("Cannot copy file '" + source + "' to itself"); + return skip(String.format(fmt_copy_file_self, source)); } } return true; @@ -317,26 +340,26 @@ return true; } if (target.isDirectory() && !source.isDirectory()) { - return skip("Cannot copy '" + source + "' onto directory '" + target + "'"); + return skip(String.format(fmt_no_copy_dir, source, target)); } if (!target.isFile()) { - return vskip("Cannot copy '" + source + "' to device '" + target + "'"); + return vskip(String.format(fmt_no_copy_dev, source, target)); } switch (mode) { case MODE_NORMAL: - return vskip("'" + target + "' already exists"); + return vskip(String.format(fmt_exists, target)); case MODE_FORCE: return true; case MODE_UPDATE: return (source.lastModified() > target.lastModified() || - vskip("'" + target + "' is newer than '" + source + "'")); + vskip(String.format(fmt_newer, target, source))); case MODE_INTERACTIVE: - out.print("Overwrite '" + target + "' with '" + source + "'? [y/n]"); + out.format(fmt_ask_overwrite, target, source); while (true) { try { String line = in.readLine(); if (line == null) { - error("EOF - abandoning copying"); + error(err_copy_eof); } if (line.length() > 0) { if (line.charAt(0) == 'y' || line.charAt(0) == 'Y') { @@ -345,9 +368,9 @@ return vskip("'" + target + "'"); } } - out.print("Answer 'y' or 'n'"); + out.print(str_ask_again); } catch (IOException ex) { - error("IO Error - abandoning copying"); + error(err_copy_ioex); } } } @@ -360,13 +383,13 @@ } private boolean skip(String msg) { - err.println(msg + ": skipping"); + err.format(fmt_skip, msg); return false; } private boolean vskip(String msg) { if (verbose) { - err.println(msg + ": skipping"); + err.format(fmt_skip, msg); } return false; } Modified: trunk/fs/src/fs/org/jnode/fs/command/DFCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/DFCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/DFCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -43,31 +43,41 @@ * @author Levente S\u00e1ntha */ public class DFCommand extends AbstractCommand { + + private static final String help_device = "The device for which disk usage information should be displayed"; + private static final String help_super = "Print file system usage information"; + private static final String str_id = "ID"; + private static final String str_size = "Size"; + private static final String str_used = "Used"; + private static final String str_free = "Free"; + private static final String str_mount = "Mount"; + private static final String str_no_fs = "No filesystem on device"; + private static final String str_unknown = "unknown"; + private static final String err_get_info = "\tError getting disk usage information for %s on %s : %s%n"; + + private final DeviceArgument argDevice + = new DeviceArgument("device", Argument.OPTIONAL | Argument.EXISTING, help_device); - private final DeviceArgument ARG_DEVICE = new DeviceArgument( - "device", Argument.OPTIONAL | Argument.EXISTING, - "The device for which disk usage inforrmation should be displayed"); - public DFCommand() { - super("Print file system usage information"); - registerArguments(ARG_DEVICE); + super(help_super); + registerArguments(argDevice); } public void execute() throws NameNotFoundException { final FileSystemService fss = InitialNaming.lookup(FileSystemService.NAME); final Map<String, String> mountPoints = fss.getDeviceMountPoints(); PrintWriter out = getOutput().getPrintWriter(false); - format(out, "ID", true); - format(out, "Size", false); - format(out, "Used", false); - format(out, "Free", false); - out.println("Mount"); + format(out, str_id, true); + format(out, str_size, false); + format(out, str_used, false); + format(out, str_free, false); + out.println(str_mount); out.println(); - if (ARG_DEVICE.isSet()) { - final Device dev = ARG_DEVICE.getValue(); + if (argDevice.isSet()) { + final Device dev = argDevice.getValue(); FileSystem<?> fs = fss.getFileSystem(dev); if (fs == null) { - out.println("No filesystem on device"); + out.println(str_no_fs); } else { displayInfo(out, dev, fs, mountPoints.get(fs.getDevice().getId())); } @@ -96,20 +106,19 @@ format(out, str, true); final long total = fs.getTotalSpace(); - str = total < 0 ? "unknown" : String.valueOf(total); + str = total < 0 ? str_unknown : String.valueOf(total); format(out, str, false); final long free = fs.getFreeSpace(); - str = total < 0 ? "unknown" : String.valueOf(total - free); + str = total < 0 ? str_unknown : String.valueOf(total - free); format(out, str, false); - str = free < 0 ? "unknown" : String.valueOf(free); + str = free < 0 ? str_unknown : String.valueOf(free); format(out, str, false); out.println(mountPoint); } catch (IOException ex) { - out.println("\tError getting disk usage information for " + mountPoint + " on " + dev.getId() + - " : " + ex.getLocalizedMessage()); + out.format(err_get_info, mountPoint, dev.getId(), ex.getLocalizedMessage()); } } Modified: trunk/fs/src/fs/org/jnode/fs/command/DeleteCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/DeleteCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/DeleteCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -50,13 +50,22 @@ private static final String help_force = "ignore non-existant files, never prompt"; private static final String help_interact = "prompt before every delete"; private static final String help_verbose = "give information on what is happening"; + private static final String help_super = "Delete files or directories"; + private static final String fmt_not_exist = "'%s' does not exist%n"; + private static final String fmt_is_dir = "Cannot remove '%s': Is a directory%n"; + private static final String fmt_ask_overwrite = "Remove regular file '%s'?"; + private static final String fmt_ask_descend = "Descend into directory '%s'?"; + private static final String fmt_ask_remove = "Remove directory '%s'?"; + private static final String fmt_removed_file = "Removed '%s'"; + private static final String fmt_removed_dir = "Removed directory '%s'"; + private static final String fmt_not_removed = "'%s' was not removed"; - private final FileArgument ArgPaths + private final FileArgument argPaths = new FileArgument("paths", Argument.MANDATORY | Argument.MULTIPLE | Argument.EXISTING, help_file); - private final FlagArgument FlagRecurse = new FlagArgument("recursive", Argument.OPTIONAL, help_recurse); - private final FlagArgument FlagForce = new FlagArgument("force", Argument.OPTIONAL, help_force); - private final FlagArgument FlagInteract = new FlagArgument("interactive", Argument.OPTIONAL, help_interact); - private final FlagArgument FlagVerbose = new FlagArgument("verbose", Argument.OPTIONAL, help_verbose); + private final FlagArgument flagRecurse = new FlagArgument("recursive", Argument.OPTIONAL, help_recurse); + private final FlagArgument flagForce = new FlagArgument("force", Argument.OPTIONAL, help_force); + private final FlagArgument flagInteract = new FlagArgument("interactive", Argument.OPTIONAL, help_interact); + private final FlagArgument flagVerbose = new FlagArgument("verbose", Argument.OPTIONAL, help_verbose); private FileSystemService fss; private boolean recursive; @@ -68,8 +77,8 @@ private Reader in; public DeleteCommand() { - super("delete files or directories"); - registerArguments(ArgPaths, FlagRecurse, FlagForce, FlagInteract, FlagVerbose); + super(help_super); + registerArguments(argPaths, flagRecurse, flagForce, flagInteract, flagVerbose); } public static void main(String[] args) throws Exception { @@ -80,11 +89,11 @@ // Lookup the Filesystem service fss = InitialNaming.lookup(FileSystemService.NAME); - recursive = FlagRecurse.isSet(); - force = FlagForce.isSet(); - interactive = FlagInteract.isSet(); - verbose = FlagVerbose.isSet(); - File[] paths = ArgPaths.getValues(); + recursive = flagRecurse.isSet(); + force = flagForce.isSet(); + interactive = flagInteract.isSet(); + verbose = flagVerbose.isSet(); + File[] paths = argPaths.getValues(); err = getError().getPrintWriter(); out = getOutput().getPrintWriter(); @@ -98,19 +107,19 @@ exit(1); } } - + private boolean deleteFile(File file) { if (!file.exists()) { if (!force) { - err.println(file + " does not exist"); + err.format(fmt_not_exist, file); } return false; } if (file.isDirectory() && !recursive) { - err.println("cannot remove " + file + ": Is a directory"); + err.format(fmt_is_dir, file); return false; } - if (file.isFile() && interactive && !prompt_yn("remove regular file " + file.getAbsolutePath() + "?")) { + if (file.isFile() && interactive && !prompt_yn(String.format(fmt_ask_overwrite, file))) { return false; } @@ -121,7 +130,7 @@ // give an error message and then refuse to delete the parent directory because // it cannot be emptied. if (file.isDirectory() && !fss.isMount(file.getAbsolutePath())) { - if (interactive && !prompt_yn("descend into directory " + file.getAbsolutePath() + "?")) { + if (interactive && !prompt_yn(String.format(fmt_ask_descend, file))) { return false; } for (File f : file.listFiles()) { @@ -131,7 +140,7 @@ deleteOk &= deleteFile(f); } } - if (deleteOk && interactive && !prompt_yn("remove directory " + file.getAbsolutePath() + "?")) { + if (deleteOk && interactive && !prompt_yn(String.format(fmt_ask_remove, file))) { return false; } } @@ -142,12 +151,12 @@ // FIXME ... this does not report the reason that the delete failed. // How should we do that? if (verbose) { - if (file.isFile()) out.println("removed " + file.getAbsolutePath()); - if (file.isDirectory()) out.println("removed directory " + file.getAbsolutePath()); + if (file.isFile()) out.format(fmt_removed_file, file); + if (file.isDirectory()) out.format(fmt_removed_dir, file); } deleteOk = file.delete(); if (!deleteOk) { - err.println(file + " was not deleted"); + err.format(fmt_not_removed, file); } } return deleteOk; Modified: trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -43,13 +43,16 @@ private static final int LEFT_MARGIN = 14; private static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd HH:mm"); - private final FileArgument ARG_PATH = new FileArgument( - "path", Argument.OPTIONAL | Argument.MULTIPLE | Argument.EXISTING, - "the file or directory to list"); + private static final String help_path = "the file or directory to list"; + private static final String help_super = "List files or directories"; + private static final String fmt_no_path = "No such path: %s%n"; + private final FileArgument argPath + = new FileArgument("path", Argument.OPTIONAL | Argument.MULTIPLE | Argument.EXISTING, help_path); + public DirCommand() { - super("List files or directories"); - registerArguments(ARG_PATH); + super(help_super); + registerArguments(argPath); } public static void main(String[] args) throws Exception { @@ -58,7 +61,7 @@ public void execute() throws IOException { - File[] paths = ARG_PATH.getValues(); + File[] paths = argPath.getValues(); if (paths.length == 0) { paths = new File[] {new File(System.getProperty("user.dir"))}; } @@ -66,7 +69,7 @@ PrintWriter err = getError().getPrintWriter(); for (File path : paths) { if (!path.exists()) { - err.println("No such path: " + path); + err.format(fmt_no_path, path); } else { if (paths.length > 1) { out.println(path + ":"); Modified: trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -35,13 +35,14 @@ */ public class EjectCommand extends AbstractCommand { - private final DeviceArgument ARG_DEVICE = new DeviceArgument( - "device", Argument.MANDATORY | Argument.EXISTING, "device to eject the medium from", - RemovableDeviceAPI.class); + private static final String help_device = "Device to eject the medium from"; + private static final String fmt_failed = "Eject failed for %s: %s"; + private final DeviceArgument argDevice + = new DeviceArgument("device", Argument.MANDATORY | Argument.EXISTING, help_device, RemovableDeviceAPI.class); public EjectCommand() { super("Eject the medium from a given device"); - registerArguments(ARG_DEVICE); + registerArguments(argDevice); } public static void main(String[] args) throws Exception { @@ -50,12 +51,12 @@ public void execute() throws ApiNotFoundException, IOException { - final Device dev = ARG_DEVICE.getValue(); + final Device dev = argDevice.getValue(); final RemovableDeviceAPI api = dev.getAPI(RemovableDeviceAPI.class); try { api.eject(); } catch (IOException ex) { - getError().getPrintWriter().println("eject failed for " + dev.getId() + ": " + ex.getMessage()); + getError().getPrintWriter().format(fmt_failed, dev.getId(), ex.getLocalizedMessage()); exit(1); } } Modified: trunk/fs/src/fs/org/jnode/fs/command/FindCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/FindCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/FindCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -59,31 +59,29 @@ out.println(f); } } + + private static final String help_name = "filter results to show only files that match a given pattern"; + private static final String help_iname = "same as name, but case insensitive"; + private static final String help_max_depth = "descend at most to the given level of directories"; + private static final String help_min_depth = "ignore files and directories below the given level"; + private static final String help_type = "filter results to show only files of a given type. Valid types are 'd' " + + "for directories and 'f' for files"; + private static final String help_dir = "directory to start searching from"; + private static final String help_super = "Find files and directories"; + + private final StringArgument nameArg = new StringArgument("name", Argument.OPTIONAL, help_name); + private final StringArgument inameArg = new StringArgument("iname", Argument.OPTIONAL, help_iname); + private final LongArgument maxdepthArg = new LongArgument("maxdepth", Argument.OPTIONAL, help_max_depth); + private final LongArgument mindepthArg = new LongArgument("mindepth", Argument.OPTIONAL, help_min_depth); + private final StringArgument typeArg = new StringArgument("type", Argument.OPTIONAL, help_type); + private final FileArgument dirArg + = new FileArgument("directory", Argument.OPTIONAL | Argument.MULTIPLE, help_dir); + + private PrintWriter out; + private PrintWriter err; - private final StringArgument nameArg = - new StringArgument("name", Argument.OPTIONAL, - "filter results to show only files that match given pattern"); - private final StringArgument inameArg = - new StringArgument("iname", Argument.OPTIONAL, "same like 'name', but case insensitive"); - private final LongArgument maxdepthArg = - new LongArgument("maxdepth", Argument.OPTIONAL, - "descent at most to given level of directories"); - private final LongArgument mindepthArg = - new LongArgument("mindepth", Argument.OPTIONAL, - "ignore files and directories at levels less than given level"); - private final StringArgument typeArg = - new StringArgument( - "type", - Argument.OPTIONAL, - "filter results to show only files of given type. valid types are 'd' for directory and 'f' for file"); - private final FileArgument dirArg = - new FileArgument("directory", Argument.OPTIONAL | Argument.MULTIPLE, - "directory to start searching from"); - private PrintWriter out = null; - private PrintWriter err = null; - public FindCommand() { - super("Find files and directories"); + super(help_super); registerArguments(dirArg, mindepthArg, maxdepthArg, inameArg, nameArg, typeArg); } Modified: trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -39,21 +39,25 @@ * @author craw...@jnode.org */ public class HexdumpCommand extends AbstractCommand { - private final FileArgument ARG_FILE = new FileArgument( - "file", Argument.OPTIONAL | Argument.EXISTING, "the file to print out"); + + private static final String help_file = "the file to print out"; + private static final String help_url = "the url to print out"; + private static final String help_super = "Print a hexadecimal dump of a given file (or URL)"; + private static final String fmt_cant_open = "Cannot open %s: %s%n"; + private static final String fmt_cant_open_url = "Cannot access URL %s: %s%n"; + + private final FileArgument argFile = new FileArgument("file", Argument.OPTIONAL | Argument.EXISTING, help_file); + private final URLArgument argURL = new URLArgument("url", Argument.OPTIONAL | Argument.EXISTING, help_url); - private final URLArgument ARG_URL = new URLArgument( - "url", Argument.OPTIONAL | Argument.EXISTING, "the url to print out"); - public HexdumpCommand() { - super("Print a hexadecimal dump of a given file (or URL)"); - registerArguments(ARG_FILE, ARG_URL); + super(help_super); + registerArguments(argFile, argURL); } public static void main(String[] args) throws Exception { new HexdumpCommand().execute(args); } - + public void execute() throws IOException { boolean myInput = false; InputStream is = null; @@ -61,20 +65,20 @@ PrintWriter err = getError().getPrintWriter(); try { // Set up the stream to be dumped. - File file = ARG_FILE.getValue(); - if (ARG_FILE.isSet()) { + File file = argFile.getValue(); + if (argFile.isSet()) { try { is = new FileInputStream(file); } catch (FileNotFoundException ex) { - err.println("Cannot open " + file + ": " + ex.getMessage()); + err.format(fmt_cant_open, file, ex.getLocalizedMessage()); exit(1); } - } else if (ARG_URL.isSet()) { - URL url = ARG_URL.getValue(); + } else if (argURL.isSet()) { + URL url = argURL.getValue(); try { is = url.openStream(); } catch (IOException ex) { - err.println("Cannot access URL '" + url + "': " + ex.getMessage()); + err.format(fmt_cant_open_url, url, ex.getLocalizedMessage()); exit(1); } } else { Modified: trunk/fs/src/fs/org/jnode/fs/command/Md5SumCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/Md5SumCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/Md5SumCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -49,15 +49,26 @@ */ public class Md5SumCommand extends AbstractCommand { - private final FileArgument ARG_PATHS = new FileArgument( - "paths", Argument.OPTIONAL | Argument.MULTIPLE | Argument.EXISTING, - "the files (or directories) to be calculate MD5 digests for"); - private final FlagArgument FLAG_RECURSIVE = new FlagArgument( - "recursive", Argument.OPTIONAL, - "if set, recursively calculate MD5 digests for the contents of any directory"); - private final FileArgument ARG_CHECKFILE = new FileArgument( - "checkfile", Argument.OPTIONAL | Argument.SINGLE | Argument.EXISTING, - "check MD5 digests for files listed in this file"); + private static final String help_paths = "the files (or directories) to calculate the MD5 digests for"; + private static final String help_recurse = "if set, recursively calculate the MD5 digests for the contents of " + + "a directory"; + private static final String help_check = "check the MD5 digests for files listed in this file"; + private static final String help_super = "Calculate or check MD5 digests"; + private static final String fmt_err_open = "Cannot open %s: %s%n"; + private static final String str_ok = "Ok"; + private static final String str_fail = "Failed"; + private static final String fmt_io_ex = "%s : IO Exception - %s%n"; + private static final String fmt_fail_count = "%d file(s) failed%n"; + private static final String fmt_err_read = "Problem reading file %s: %s"; + private static final String err_norecurse = "Cannot calculate MD5 on directory, use recurse flag"; + private static final String fmt_err_md5 = "%s was not processed: %s%n"; + private static final String str_input = "Input"; + + private final FileArgument argPaths + = new FileArgument("paths", Argument.OPTIONAL | Argument.MULTIPLE | Argument.EXISTING, help_paths); + private final FlagArgument flagRecursive = new FlagArgument("recursive", Argument.OPTIONAL, help_recurse); + private final FileArgument argCheckfile + = new FileArgument("checkfile", Argument.OPTIONAL | Argument.SINGLE | Argument.EXISTING, help_check); private static final int BUFFER_SIZE = 1048576; // 1Mb @@ -68,8 +79,8 @@ public Md5SumCommand() { - super("Calculate or check MD5 digests"); - registerArguments(ARG_PATHS, FLAG_RECURSIVE, ARG_CHECKFILE); + super(help_super); + registerArguments(argPaths, flagRecursive, argCheckfile); } public void execute() throws Exception { @@ -80,11 +91,11 @@ digestEngine = MessageDigest.getInstance("md5"); boolean ok = true; - if (ARG_CHECKFILE.isSet()) { - ok = checkFile(ARG_CHECKFILE.getValue()); - } else if (ARG_PATHS.isSet()) { - boolean recursive = FLAG_RECURSIVE.isSet(); - File[] paths = ARG_PATHS.getValues(); + if (argCheckfile.isSet()) { + ok = checkFile(argCheckfile.getValue()); + } else if (argPaths.isSet()) { + boolean recursive = flagRecursive.isSet(); + File[] paths = argPaths.getValues(); for (File file : paths) { ok &= processFile(file, recursive); } @@ -113,7 +124,7 @@ try { br = new BufferedReader(new FileReader(checkFile)); } catch (FileNotFoundException ex) { - err.println("Cannot open " + checkFile + ": " + ex.getMessage()); + err.format(fmt_err_open, checkFile, ex.getLocalizedMessage()); return false; } String readLine; @@ -131,17 +142,17 @@ failCount++; } } catch (IOException ex) { - out.println(line[1] + " : IO EXCEPTION - " + ex.getMessage()); + out.format(fmt_io_ex, line[1], ex.getLocalizedMessage()); failCount++; } } } if (failCount > 0) { - err.println(failCount + " file(s) failed"); + err.format(fmt_fail_count, failCount); return false; } } catch (IOException ex) { - err.println("problem reading file " + checkFile + ": " + ex.getMessage()); + err.format(fmt_err_read, checkFile, ex.getLocalizedMessage()); return false; } finally { if (br != null) { @@ -176,14 +187,14 @@ } } } else { - err.println("Cannot calculate md5sum on folder: " + file); + err.println(err_norecurse); res = false; } } else { try { out.println(toHexString(computeDigest(file)) + " " + file); } catch (IOException ex) { - err.println(file + " was not md5summed: " + ex.getMessage()); + err.format(fmt_err_md5, file, ex.getLocalizedMessage()); } } return res; @@ -198,7 +209,7 @@ out.println(toHexString(computeDigest(null))); return true; } catch (IOException ex) { - err.println("Input was not md5summed: " + ex.getMessage()); + err.format(fmt_err_md5, str_input, ex.getLocalizedMessage()); return false; } } Modified: trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -33,12 +33,17 @@ */ public class MkdirCommand extends AbstractCommand { - private final FileArgument ARG_DIR = new FileArgument( - "directory", Argument.MANDATORY | Argument.NONEXISTENT, "the directory to create"); + private static final String help_dir = "the directory to create"; + private static final String help_super = "Create a new directory"; + private static final String fmt_exists = "%s already exists%n"; + private static final String err_cant_create = "Cannot create directory"; + + private final FileArgument argDir + = new FileArgument("directory", Argument.MANDATORY | Argument.NONEXISTENT, help_dir); public MkdirCommand() { - super("Create a new directory"); - registerArguments(ARG_DIR); + super(help_super); + registerArguments(argDir); } public static void main(String[] args) throws Exception { @@ -46,14 +51,14 @@ } public void execute() { - File dir = ARG_DIR.getValue(); + File dir = argDir.getValue(); PrintWriter err = getError().getPrintWriter(); if (dir.exists()) { - err.println(dir.getPath() + " already exists."); + err.format(fmt_exists, dir); exit(1); } if (!dir.mkdir()) { - err.println("Can't create directory."); + err.println(err_cant_create); exit(1); } } Modified: trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -39,18 +39,21 @@ */ public class MountCommand extends AbstractCommand { - private final DeviceArgument ARG_DEV = new DeviceArgument("device", - Argument.OPTIONAL, "the device to mount", BlockDeviceAPI.class); + private static final String help_device = "the device to mount"; + private static final String help_dir = "the mount point"; + private static final String help_fspath = "the subdirectory within the filesystem to use as root"; + private static final String help_super = "Mount a filesystem"; + private static final String fmt_mount = "%s on %s type %s (%s)%n"; + private static final String fmt_err_nofs = "No filesystem found on %s%n"; + + private final DeviceArgument argDevice + = new DeviceArgument("device", Argument.OPTIONAL, help_device, BlockDeviceAPI.class); + private final FileArgument argDir = new FileArgument("directory", Argument.OPTIONAL, help_dir); + private final FileArgument argFspath = new FileArgument("fsPath", Argument.OPTIONAL, help_fspath); - private final FileArgument ARG_DIR = new FileArgument("directory", - Argument.OPTIONAL, "the mount point"); - - private final FileArgument ARG_FSPATH = new FileArgument("fsPath", - Argument.OPTIONAL, "the subdirectory within the filesystem to use as root"); - public MountCommand() { - super("Mount a filesystem"); - registerArguments(ARG_DEV, ARG_DIR, ARG_FSPATH); + super(help_super); + registerArguments(argDevice, argDir, argFspath); } public static void main(String[] args) throws Exception { @@ -62,7 +65,7 @@ final FileSystemService fss = InitialNaming.lookup(FileSystemService.NAME); PrintWriter out = getOutput().getPrintWriter(); PrintWriter err = getError().getPrintWriter(); - if (!ARG_DEV.isSet()) { + if (!argDevice.isSet()) { // List all mounted file systems Map<String, FileSystem<?>> filesystems = fss.getMountPoints(); for (String mountPoint : filesystems.keySet()) { @@ -70,18 +73,18 @@ Device device = fs.getDevice(); String mode = fs.isReadOnly() ? "ro" : "rw"; String type = fs.getType().getName(); - out.println(device.getId() + " on " + mountPoint + " type " + type + " (" + mode + ')'); + out.format(fmt_mount, device.getId(), mountPoint, type, mode); } } else { // Get the parameters - final Device dev = ARG_DEV.getValue(); - final File mountPoint = ARG_DIR.getValue(); - final File fsPath = ARG_FSPATH.getValue(); + final Device dev = argDevice.getValue(); + final File mountPoint = argDir.getValue(); + final File fsPath = argFspath.getValue(); // Find the filesystem final FileSystem<?> fs = fss.getFileSystem(dev); if (fs == null) { - err.println("No filesystem found on " + dev.getId()); + err.format(fmt_err_nofs, dev.getId()); exit(1); } else { // Mount it Modified: trunk/fs/src/fs/org/jnode/fs/command/PwdCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/PwdCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/PwdCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -28,8 +28,11 @@ * @author Martin Husted Hartvig (ha...@jnode.org) */ public class PwdCommand extends AbstractCommand { + + private static final String help_super = "Show the pathname of the current working directory"; + public PwdCommand() { - super("show the pathname of current working directory"); + super(help_super); } public static void main(String[] args) throws Exception { Modified: trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java 2009-04-19 15:10:43 UTC (rev 5311) +++ trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java 2009-04-19 17:25:18 UTC (rev 5312) @@ -36,12 +36,17 @@ */ public class TouchCommand extends AbstractCommand { - private final FileArgument ARG_FILE = new FileArgument( - "file", Argument.MANDATORY, "the file to touch"); + private static final String help_file = "the file to touch"; + private static final String help_super = "touch a file"; + private static final String err_parent_dir = "Cannot create parent directories"; + private static final String str_created = "File created"; + private static final String err_file = "Cannot create file"; + + private final FileArgument argFile = new FileArgument("file", Argument.MANDATORY, help_file); public TouchCommand() { - super("touch a file"); - registerArguments(ARG_FILE); + super(help_super); + registerArguments(argFile); } public static void main(String[] args) throws Exception { @@ -49,7 +54,7 @@ } public void execute() throws Exception { - File file = ARG_FILE.getValue(); + File file = argFile.getValue(); PrintWriter out = getOutput().getPrintWriter(); PrintWriter err = getError().getPrintWriter(); if (!file.exists()) { @@ -57,14 +62,14 @@ if (parentFile != null && !parentFile.exists()) { // FIXME ... this is wrong. Touch should not do this. if (!parentFile.mkdirs()) { - err.println("Cannot create parent directories"); + err.println(err_parent_dir); exit(2); } } if (file.createNewFile()) { - out.println("File created"); + out.println(str_created); } else { - err.println("Cannot create file"); + err.println(err_file); exit(1); } } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p _______________________________________________ Jnode-svn-commits mailing list Jnode-svn-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits