From: <cr...@us...> - 2008-08-02 07:00:00
|
Revision: 4384 http://jnode.svn.sourceforge.net/jnode/?rev=4384&view=rev Author: crawley Date: 2008-08-02 06:59:57 +0000 (Sat, 02 Aug 2008) Log Message: ----------- Added --verbose and --help options. The command now renames existing output files to <file>.bak Modified Paths: -------------- trunk/builder/src/configure/org/jnode/configure/Configure.java trunk/builder/src/configure/org/jnode/configure/PropertySet.java trunk/builder/src/configure/org/jnode/configure/Screen.java trunk/builder/src/configure/org/jnode/configure/ScriptParser.java Modified: trunk/builder/src/configure/org/jnode/configure/Configure.java =================================================================== --- trunk/builder/src/configure/org/jnode/configure/Configure.java 2008-08-02 04:36:03 UTC (rev 4383) +++ trunk/builder/src/configure/org/jnode/configure/Configure.java 2008-08-02 06:59:57 UTC (rev 4384) @@ -47,6 +47,29 @@ private final PrintStream err; private String scriptFile; private boolean debug; + private boolean verbose; + private boolean help; + + private static String USAGE = + "configure.sh [--debug] [--verbose] [--help] [<script>]"; + private static String[] DESCRIPTION = new String[] { + "Capture configuration properties based on the supplied <script>.", + " If no arguments or options are provided, defaults are supplied", + " by the wrapper script. A copy of the previous state of each", + " <file> updated is saved in '<file>.bak.'", + "Options:", + " --verbose output more information to help the user understand", + " what is happening.", + " --help output command help then exit", + " --debug enable debug output" + }; + private static String[] UI_HELP = new String[] { + "The program will prompt you for values for a series of properties,", + "showing a list of legal values or a regex. If there is a default", + "value, it will be shown in square brackets. At the prompt, type", + "an acceptable value for the property followed by ENTER. If you just", + "type ENTER, the default value (if any) will be used for the property." + }; private Configure() { this.in = new BufferedReader(new InputStreamReader(System.in)); @@ -57,10 +80,15 @@ private void run(String[] args) { try { parseArguments(args); + if (help) { + printHelp(); + return; + } ConfigureScript script = new ScriptParser(this).loadScript(scriptFile); for (PropertySet propFile : script.getPropsFiles()) { propFile.load(this); } + printUIHelp(); script.execute(this); for (PropertySet propFile : script.getPropsFiles()) { saveProperties(propFile); @@ -75,6 +103,28 @@ } } + private void printUIHelp() { + if (verbose) { + print(UI_HELP, out); + } + } + + private void printHelp() { + print(USAGE, err); + print(DESCRIPTION, err); + print(UI_HELP, err); + } + + private void print(String line, PrintStream stream) { + format(stream, line, DISPLAY_NORMAL); + } + + private void print(String[] lines, PrintStream stream) { + for (String line: lines) { + format(stream, line, DISPLAY_NORMAL); + } + } + /** * Parse the command line. * @@ -89,6 +139,11 @@ } if (arg.equals("--debug")) { debug = true; + } else if (arg.equals("--help")) { + help = true; + return; + } else if (arg.equals("--verbose")) { + verbose = true; } else { throw new ConfigureException("Unrecognized option: " + args[i]); } @@ -116,7 +171,7 @@ } public void output(String message) { - format(err, message, DISPLAY_NORMAL); + format(out, message, DISPLAY_NORMAL); } public void error(String message) { @@ -125,10 +180,16 @@ public void debug(String message) { if (debug) { - format(err, message, DISPLAY_NORMAL); + format(err, "[DEBUG] " + message, DISPLAY_NORMAL); } } + public void verbose(String message) { + if (verbose) { + format(out, "[VERBOSE] " + message, DISPLAY_NORMAL); + } + } + private void format(PrintStream stream, String text, int displayAttributes) { switch (displayAttributes) { case DISPLAY_PROMPT: Modified: trunk/builder/src/configure/org/jnode/configure/PropertySet.java =================================================================== --- trunk/builder/src/configure/org/jnode/configure/PropertySet.java 2008-08-02 04:36:03 UTC (rev 4383) +++ trunk/builder/src/configure/org/jnode/configure/PropertySet.java 2008-08-02 06:59:57 UTC (rev 4384) @@ -35,7 +35,7 @@ * @author cr...@jn... */ public class PropertySet { - public static class Property { + public class Property { private final String name; private final PropertyType type; private final String description; @@ -98,6 +98,14 @@ public void setDefaultValue(Value defaultValue) { this.defaultValue = defaultValue; } + + public boolean isControlProperty() { + return getPropertySet().getFile() == null; + } + + public PropertySet getPropertySet() { + return PropertySet.this; + } } public static class Value { @@ -171,7 +179,23 @@ } public void save(Configure configure) throws ConfigureException { + if (file.exists()) { + File file = this.file.getAbsoluteFile(); + File backup = new File(file.getParentFile(), file.getName() + ".bak"); + if (backup.exists()) { + if (!backup.delete()) { + throw new ConfigureException( + "Cannot delete existing '" + backup + "'"); + } + } + if (!file.renameTo(backup)) { + throw new ConfigureException( + "Cannot rename existing '" + file + "' as '" + backup + "'"); + } + configure.verbose("Renamed existing '" + file + "' as '" + backup + "'"); + } adapter.save(this, configure); + configure.verbose("Saved properties to '" + file + "'"); } public File getFile() { Modified: trunk/builder/src/configure/org/jnode/configure/Screen.java =================================================================== --- trunk/builder/src/configure/org/jnode/configure/Screen.java 2008-08-02 04:36:03 UTC (rev 4383) +++ trunk/builder/src/configure/org/jnode/configure/Screen.java 2008-08-02 06:59:57 UTC (rev 4384) @@ -166,6 +166,11 @@ configure.output(""); } } + if (!prop.isControlProperty()) { + configure.verbose( + "Setting property " + prop.getName() + " to " + + "\"" + value.getText() + "\""); + } } } } Modified: trunk/builder/src/configure/org/jnode/configure/ScriptParser.java =================================================================== --- trunk/builder/src/configure/org/jnode/configure/ScriptParser.java 2008-08-02 04:36:03 UTC (rev 4383) +++ trunk/builder/src/configure/org/jnode/configure/ScriptParser.java 2008-08-02 06:59:57 UTC (rev 4384) @@ -133,10 +133,12 @@ } public ConfigureScript loadScript(String fileName) throws ConfigureException { + configure.verbose("Loading configure script from " + fileName); final File file = new File(fileName); stack.add(new ParseContext(file)); try { final XMLElement root = loadXML(file); + configure.debug("Parsing script"); return parseScript(root, file); } finally { stack.removeLast(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |