Here is a set of files I already sent to Christoph. I didn't want to clog the
list, but then
I realized it might be part of the community's informal group review process,
so belatedly
I am posting this to the list also:
======================
Hi Christoph --
This diff + the new files (see the package statements for their locations)
implement a PropertiesManager
and incidentally add an arg parsing framework. Both frameworks are from my own
open source corpus.
* The default properties file is
{user.home}/apache.ant.antidote.persistent.properties
* Using the new -p argument you can pass in a properties filename instead
* If the properties file does not exist, it is created.
If you like it, I will convert the Reopener to use this instead of writing its
own properties file.
After that, I will begin a GUI interface to persistent properties.
--
Jack J. Woehr # You measure democracy by the freedom it
Senior Consultant # gives its dissidents, not the freedom
Purematrix, Inc. # it gives its assimilated conformists.
www.purematrix.com # - Abbie Hoffman
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Ant" and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.gui.util;
/** Holds an argument parsed from a command line.
* If it's a plain argument, records the argument
* string and position. If it is a dash-option,
* records the option string (-a -b etc.) and
* the argument to the option, if any. In any
* case, records the position in the command
* line that the arg or opt-arg pair came in.
* @author $Author: jax $
* @version $Revision:$
* @see corg.apache.tools.ant.gui.util.GetArgs
*/
public class Argument {
/** The "option", that is, dash-letter, e.g., -a -b etc. */
public String option;
/** The argument to the option, e.g., "-o full" where
* "full" is the argument to the option "-o".
*/
public String argument;
/** The position among the options-and-arguments in which
* this option-and-argument appears.
*/
public int position;
/** Create an Argument from an option, argument and position.
* @param option The command-line option
* @param argument The command line arg
* @param position The nth-ity of the entity.
*/
public Argument(String option, String argument, int position) {
this.option = option;
this.argument = argument;
this.position = position;
}
/** Return the option and argument as a String.
* @return The string representation of the option and argument
*/
public String toString()
{return option + " " + argument;}
/** Return the option portion (if any) of the Argument.
* @return The option itself.
*/
public String getOption() {return option;}
/** Return the argument portion (if any) of the Argument.
* @return The argument itself.
*/
public String getArgument() {return argument;}
} /* End of Argument class*/
/* End of Argument.java */
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Ant" and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.gui.util;
import java.io.*;
import java.util.*;
/** Parses arguments and options from a string
* e.g., from a command line. GetArgs views
* the string as a series of blank-delimited
* lexemes which it interprets as either plain
* arguments or option-argument pairs as described
* below.
*
*<p> GetArgs breaks up the passed-in string
* into two lists, one of the plain arguments,
* and one of the option-argument pairs.
* GetArgs creates com.SoftWoehr.util.Argument
* objects of each of these entities.
*
* <p>Each option is identified by a single character
* preceded by an option introducer. Remaining characters
* in such a lexeme are regarded as the argument to
* the option, e.g.,
* <pre>
* -Djava.foo=bar
* </pre>
* where -D is the option and java.foo=bar is the argument.
*
*<p>The option introducer is any individual character
* in the string returned by <code>getOptionIntroducers()</code>,
* by default the sole character '-' "dash". This string of
* option introducers may be changed by
* <code>setOptionIntroducers()</code>.
*
* <p><b>NOTE</b> that all options are presumed to have option
* arguments, so if the lexeme recognized as an option consists
* only of the option introducer or an option introducer and
* one (1) following option character, the next lexeme
* in the command line following the option is regarded as
* the option argument <b>UNLESS</b> that next lexeme is itself
* an option, i.e., a string headed by a member of the current
* set of option introducers.
*
*<p>The position in which the command line argument or
* option-argument pair occurred is recorded in the Argument
* object also.
*
*<p>Derived from com.SoftWoehr.util.GetArgs by the author.
*
* @author $Author: jax $
* @version $Revision$
*
*/
public class GetArgs {
/** Holds the Argument objects, as many as parsed. */
private Vector optList, argList;
/** Option introducers. */
private String optionIntroducers = "-";
/** Arity/1 constructor. The arity/0 exists uselessly.
* If you must use GetArgs/0 be sure to call reinit/1.
* @param argv Arg string
*/
public GetArgs(String argv[]) { reinit(argv); }
/** Reinitialize the object, discarding previous state.
* Creates two arrays, one of options and their
* (possibly null) arguments, the other of plain arguments.
* The members of these lists are accessible via other methods.
* @param argv Arg string
*/
public void reinit(String argv[]) {
int i;
optList = new Vector();
argList = new Vector();
String tempOpt; /* A potential option while we're processing it.*/
String theOpt; /* The option marker_char + opt_letter, e.g., -x .*/
String tempArg; /* A potential argument. */
int position = 0; /* nthness in line */
for (i = 0; i < argv.length; i++) {
tempOpt = argv[i].trim();
if (isOptionIntroducer(tempOpt.charAt(0))) /* Is this an
option?*/ {
theOpt =/* Record option, introducer plus second char, if any.*/
tempOpt.substring(0,Math.min(2, tempOpt.length()));
if (tempOpt.length() > 2) /* Is the optarg in the option
itself?*/ {/* If so, extract that option argument.*/
tempArg = tempOpt.substring(2, tempOpt.length());
}
else /* No, optarg not included directly in opt
string.*/ {/* Look for it in next lexical element*/
if ((i+1) < argv.length) /* Do we have another lex elem
left?*/ {
tempArg = argv[i+1].trim();/* Next lex an option on its
own?*/
if (isOptionIntroducer(tempArg.charAt(0))) {
tempArg = null;/* Yup, so previous option is
null-arged.*/
}
else /* No, it's not an option, so must be arg to
previous opt.*/ {/* (We already read it into tempArg.)*/
i++; /* Bump index past this lexical element.*/
} /* End if*/
}
else /* Command line is
exhausted.*/ {
tempArg = null; /* No arg to the opt.*/
} /* End if*/
} /* Done looking for argument to option. */ /* End if*/
/* We can now store our option and its argument (if any). */
optList.addElement(new Argument(theOpt, tempArg, position));
} /* Done processing found option. */ /* End if*/
else /* Wasn't an option, must be just a plain
argument.*/ {
tempArg = tempOpt; /* Already have it in hand.*/
tempOpt = null; /* No option*/
/* Add to list of plain arguments */
argList.addElement(new Argument(tempOpt, tempArg, position));
} /* End if*/
position++;
} /* Done looping through string array of command line. *//* End for*/
} /* End of constructor*/
/** Return a string of all the options and arguments,
* options first, then arguments, but otherwise in order.
* @return string rep
*/
public String toString() {
Argument a;
String result = "";
/* Iterate through the option and argument lists */
for (int i = 0; i < optList.size() ; i++) {
a = nthOption(i);
result += "(" + a.position + ") ";
if (null != a.option) {
result += a.option + " ";
} /* End if*/
if (null != a.argument) {
result += a.argument + " ";
}
} /* End for*/
for (int i = 0; i < argList.size() ; i++) {
a = nthArgument(i);
result += "(" + a.position + ") ";
if (null != a.option) {
result += a.option + " ";
} /* End if*/
if (null != a.argument) {
result += a.argument + " ";
}
} /* End for*/
return result;
}
/** Return string of option introducers.
* @return string of option introducers.
*/
public String getOptionIntroducers() { return optionIntroducers; }
/** Set string of single-character option introducers.
* Any individual char in the list will be considered an intro
* to an option on the command line.
* @param s string of single-character option introducers.
*/
public void setOptionIntroducers(String s ) { optionIntroducers = s; }
/** Is the given char found in the string of option introducers?
* @param c char to test
* @return <CODE>true</CODE> if option introdcer.
*/
public boolean isOptionIntroducer(char c) {
int found = optionIntroducers.indexOf(c);
return (found != -1);
}
/** Return the nth option as an Argument object.
* Returns null if no such nth option.
* @param n nth 0-based opt to find
* @return the sought option or <CODE>null</CODE>.
*/
public Argument nthOption(int n) {
Argument a = null;
if (n < optList.size()) {
a = (Argument) (optList.elementAt(n));
}
return a;
}
/** Returns nth argument as Argument object.
* Returns null of no such nth argument.
* @param n nth 0-based argument
* @return sought Argument or <CODE>null</CODE>.
*/
public Argument nthArgument(int n) {
Argument a = null;
if (n < argList.size()) {
a = (Argument) (argList.elementAt(n));
}
return a;
}
/** Number of options parsed.
* @return num opts
*/
public int optionCount() {
return optList.size();
}
/** Number of plain arguments parsed.
* @return num args
*/
public int argumentCount() {
return argList.size();
}
/** Demo GetArgs by displaying any opts or args passed in.
* @param argv Args to use to test the GetArgs
*/
public static void main(String argv[]) {
int i;
Argument a;
GetArgs g = new GetArgs(argv);
boolean quitFlag = false;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringTokenizer st = new StringTokenizer("");/* Holds next pass of
input.*/
String ss[]; /* Holds next pass of input. */
/* GPL'ed SoftWoehr announces itself. */
System.out.println("GetArgs, Copyright (c) 1999, 2003 The Apache
Software Foundation. All rights reserved.");
if (0 == argv.length) {
System.err.println("Usage: GetArgs [-options args args -options
args ...]");
System.err.println(" ... Just analyzes the options, but there are
two special");
System.err.println(" ... options, -o and -q. -q quits. -o takes its
argument");
System.err.println(" ... and makes it the option introducers
string.");
return;
} /* End if*/
/* Loop taking arguments. */
while (!quitFlag) {
System.out.println("Entire command line, \"normalized\":\n");
System.out.println(g.toString() + "\n");
System.out.println("Options:");
System.out.println("--------");
for (i = 0; i < g.optionCount() ; i++) {
a = g.nthOption(i);
System.out.println(" option is " + a.option );
System.out.println(" argument is " + a.argument);
System.out.println(" position is " + a.position);
System.out.println("--------");
/* See if user wants to quit. */
if (a.option.length() > 1) {
if (a.option.substring(1,2).equals("q")) {
quitFlag = true;
} /* End if*/
}
/* See if user wants to change option string. */
if (a.option.length() > 1 &&
a.option.substring(1,2).equals("o")) {
if (a.argument != null) {
g.setOptionIntroducers(a.argument);
} /* End if*/
} /* End if*/
} /* End for*/
/* Now show the arguments. */
System.out.println("Arguments");
System.out.println("---------");
for (i = 0; i < g.argumentCount() ; i++) {
a = g.nthArgument(i);
System.out.println(" argument is " + a.argument);
System.out.println(" position is " + a.position);
System.out.println("---------");
} /* End for*/
/* Get another line from user if we're not done. */
if (!quitFlag) {
/* Get a new line. */
try {
st = new StringTokenizer(br.readLine());
} /* End try*/
catch (Exception e) {
e.printStackTrace(System.err);
} /* End catch*/
/* Process the line/ */
ss = new String [st.countTokens()];
for (int j = 0; j < ss.length; j++) {
ss[j] = st.nextToken();
}
g.reinit(ss); /* arg-ize new input*/
} /* End if*/
} /* End while*/
/* We're done, clean up. */
try {
br.close();
} /* End try*/
catch (Exception e) {
e.printStackTrace(System.err);
} /* End catch*/
} /* End of main*/
} /* End of GetArgs class*/
/* End of GetArgs.java */
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Ant" and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.gui.core;
/** A Properties management class which knows how to load and store Properties.
* Based on com.SoftWoehr.util.Properties from the
* <a href="http://www.softwoehr.com">SoftWoehr Class Libraries</a>.
* Add your default properties with add_default_property (String key, String
property);
* @author <a href="mailto:[EMAIL PROTECTED]">Jack J. Woehr</a>
* @version $Revision$
*/
public class PropertiesManager extends java.util.Properties {
/** Represents the default properties set. Use
default_properties.addProperty() to add
* a default property.
*/
private static java.util.Properties default_properties;
/** Set or add a default property
* @param key Name of property.
* @param property Value of property
*/
protected static void add_default_property (String key, String property) {
default_properties.setProperty(key, property);
}
/** To respond to requests */
public class NoSuchPropertyException extends java.lang.Exception {
NoSuchPropertyException(String property) {
super("Unknown property: " + property);
}
}
/** To respond to requests */
public class InvalidIntPropertyException extends java.lang.Exception {
InvalidIntPropertyException(String property) {
super("Invalid integer property: " + property);
}
}
/** Create the defaults
* Add any default properties you want to be hiding behind customized
properties
* to this static ctor using the set.Property method as illustrated below.
*/
static {
default_properties = new java.util.Properties ();
/* Set all the defaults */
default_properties.setProperty("org.apache.copyright", "Copyright (c) 1999,
2003 The Apache Software Foundation. All rights reserved");
/* NOTE that these defaults are *not* written to the persistent properties
file. D'oh, they're defaults! */
}
/** Creates new PropertiesManager possessing the default Properties */
public PropertiesManager() {
super(default_properties);
}
/** Load properties at creation
* @param filename Properties file on local file system.
*/
public PropertiesManager(String filename)
throws java.io.FileNotFoundException, java.io.IOException
{
this();
load_from_file(filename);
}
/** Reload saved properties from a local file
* @param filename Local file to fetch property strings from
* @throws FileNotFoundException Couldn't find that path.
* @throws IOException Couldn't read for some reason.
*/
public void load_from_file (String filename)
throws java.io.FileNotFoundException, java.io.IOException
{
java.io.FileInputStream fi = new java.io.FileInputStream(filename);
load(fi);
fi.close();
}
/** Return a header suitable for a props file.
* @return Text for header of a written properties file.
*/
protected String get_properties_header () {
return "Ant Antidote Properties loaded at Antidote start. This file is
generated and modified automatically, but it may be hand-edited (carefully!)";
}
/** Save the properties
* @param filename File on local file system to store props. to.
* @throws FileNotFoundException Couldn't find that path.
* @throws IOException Couldn't write for some reason.
*/
public void store_to_file (String filename)
throws java.io.FileNotFoundException, java.io.IOException
{
java.io.FileOutputStream fo = new java.io.FileOutputStream(filename);
store(fo, get_properties_header ());
}
/** Get a specific int property.
* @param property Name of property.
* @throws NoSuchPropertyException No such.
* @throws InvalidIntPropertyException Wasn't a base10 int.
* @return Int value base 10 of property value
*/
public int get_int_property (String property)
throws NoSuchPropertyException, InvalidIntPropertyException
{
int value = 0;
String prop = getProperty(property);
if (null == prop)
{
throw new NoSuchPropertyException(property);
}
try {
value = Integer.parseInt(prop);
}
catch (NumberFormatException e) {
throw new InvalidIntPropertyException(property);
}
return value;
}
}
Index: org/apache/tools/ant/gui/Args.java
===================================================================
RCS file:
/home/cvspublic/ant-antidote/src/java/org/apache/tools/ant/gui/Args.java,v
retrieving revision 1.2
diff -c -r1.2 Args.java
*** org/apache/tools/ant/gui/Args.java 10 Feb 2003 14:34:56 -0000 1.2
--- org/apache/tools/ant/gui/Args.java 26 Sep 2003 09:04:12 -0000
***************
*** 54,59 ****
--- 54,62 ----
package org.apache.tools.ant.gui;
import org.apache.tools.ant.gui.core.ResourceManager;
+ import org.apache.tools.ant.gui.util.Argument;
+ import org.apache.tools.ant.gui.util.GetArgs;
+ import java.lang.System;
/**
* Class encapsulating the parsing of command-line arguments for Antidote.
***************
*** 63,101 ****
*/
public class Args {
private ResourceManager _resources = null;
private boolean _wizardMode = false;
private String _fileName = null;
private boolean _debugMode = false;
/**
* Ctor for parsing command line arguments.
*
! * @param args Arguments to parse.
*/
public Args(String[] args) {
! for(int i = 0; i < args.length; i++) {
! String arg = args[i];
! if(i == args.length - 1 && !arg.startsWith("-")) {
! _fileName = arg;
! }
! else if(arg.startsWith("-h")) {
! System.out.println(getUsage());
! System.exit(0);
! }
! else if(arg.equals("-wizard")) {
! _wizardMode = true;
! }
! else if(arg.equals("-debug")) {
! _debugMode = true;
! }
! else {
! String msg = getResources().getMessage(
! "invalidArg", new Object[] { arg });
! abort(msg);
! }
}
! }
/**
* Get the resources, loading them if necessary.
--- 66,112 ----
*/
public class Args {
+ private GetArgs _getArgs = null;
private ResourceManager _resources = null;
private boolean _wizardMode = false;
private String _fileName = null;
+ private String _propertiesFileName = null;
private boolean _debugMode = false;
/**
* Ctor for parsing command line arguments.
*
! * @param args String of textual arguments to parse.
*/
public Args(String[] args) {
! GetArgs _getArgs = new GetArgs(args);
! Argument a;
!
! for (int i = 0; i < _getArgs.optionCount() ; i++) {
! a = _getArgs.nthOption(i);
! if (a.option.equals("-h"))
! {
! System.out.println(getUsage());
! System.exit(0);
! }
! if (a.option.equals("-w"))
! {
! if (a.argument.equals("izard")) {
! _wizardMode = true;
! }
! }
! if (a.option.equals("-d"))
! {
! if (a.argument.equals("ebug")) {
! _debugMode = true;
! }
! }
! if (a.option.equals("-p"))
! {
! _propertiesFileName=a.argument;
! }
}
! }
/**
* Get the resources, loading them if necessary.
***************
*** 137,142 ****
--- 148,162 ----
*/
public String getBuildFile() {
return _fileName;
+ }
+
+ /**
+ * Get the Properties filename.
+ *
+ * @return Properties file name.
+ */
+ public String getPropertiesFile() {
+ return _propertiesFileName;
}
/**
Index: org/apache/tools/ant/gui/Main.java
===================================================================
RCS file:
/home/cvspublic/ant-antidote/src/java/org/apache/tools/ant/gui/Main.java,v
retrieving revision 1.7
diff -c -r1.7 Main.java
*** org/apache/tools/ant/gui/Main.java 10 Feb 2003 14:34:56 -0000 1.7
--- org/apache/tools/ant/gui/Main.java 26 Sep 2003 09:04:12 -0000
***************
*** 99,104 ****
--- 99,121 ----
AppContext context = new AppContext(f);
f.setContext(context);
+ /* Doing this in a block to limit scope of temps */
+ {
+ String propertiesFileName = settings.getPropertiesFile();
+ if (propertiesFileName != null) {
+ context.setPropertiesFileName(propertiesFileName);
+ }
+ /* If the props file name wasn't passed on the command line
+ * and instanced in AppContext above, this will attempt to
load
+ * the default filename initialized in the AppContext
+ */
+ if (!context.loadProperties()) {
+ // System.err.println("Warning: Could not load properties
file " + context.getPropertiesFileName());
+ /* Not necessarily an error, e.g., first time Antidote
has run */
+ /* Anyway, this is fairly well handled in AppContext
already */
+ }
+ }
+
if(!settings.isWizardMode()) {
EventResponder resp = new EventResponder(context);
Antidote gui = new Antidote(context);
Index: org/apache/tools/ant/gui/core/AppContext.java
===================================================================
RCS file:
/home/cvspublic/ant-antidote/src/java/org/apache/tools/ant/gui/core/AppContext.java,v
retrieving revision 1.4
diff -c -r1.4 AppContext.java
*** org/apache/tools/ant/gui/core/AppContext.java 10 Sep 2003 10:08:22
-0000 1.4
--- org/apache/tools/ant/gui/core/AppContext.java 26 Sep 2003 09:04:13
-0000
***************
*** 75,80 ****
--- 75,84 ----
private ProjectManager _projectManager = new ProjectManager(this);
/** Thing that keeps track of the current selection state. */
private SelectionManager _selectionManager = new SelectionManager();
+ /** Properties read from and written to the Antidote user's .properties
file */
+ private PropertiesManager _propertiesManager = new PropertiesManager();
+ /** The file name we load properties from and save properties to */
+ private String _persistentPropertiesFilename =
System.getProperty("user.home") + "/apache.ant.antidote.persistent.properties";
/** Application actions. */
private ActionManager _actions =
***************
*** 159,164 ****
--- 163,252 ----
public SelectionManager getSelectionManager() {
return _selectionManager;
}
+
+ /**
+ * Get the Properties manager.
+ *
+ * @return Properties manager.
+ */
+ public PropertiesManager getPropertiesManager() {
+ return _propertiesManager;
+ }
+
+ /** Load whatever the props file name is already set as the properties file
+ * @return <code>true</code> iff file loaded okay.
+ */
+ public boolean loadProperties() {
+ boolean result = false;
+ boolean fileNotFound = false;
+
+ /* This filename is set explicitly or defaults as initialized above */
+ if (null != _persistentPropertiesFilename){
+ try {
+ // System.err.println("Properties file " +
_persistentPropertiesFilename + " being opened.");
+
_propertiesManager.load_from_file(_persistentPropertiesFilename);
+ result = true;
+ }
+ catch (java.io.FileNotFoundException e) {
+ fileNotFound = true;
+ }
+ catch (java.io.IOException e) {
+ // log this exception?
+ }
+ }
+
+ if (fileNotFound) {
+ /* Wasn't there? Write one for the user */
+ System.err.println("Properties file " +
_persistentPropertiesFilename + " not found, writing one for you.");
+ /* !!! I18N L10N !!! */
+
+ try {
+ saveProperties();
+ }
+ catch (java.io.FileNotFoundException e) {
+ /* Not there? Write one for the user */
+ System.err.println("Properties file " +
_persistentPropertiesFilename + " could not be located.");
+ /* !!! I18N L10N !!! */
+ }
+ catch(java.io.IOException e) {
+ /* Not there? Write one for the user */
+ System.err.println("Properties file " +
_persistentPropertiesFilename + " could not be written.");
+ /* !!! I18N L10N !!! */
+ }
+ }
+ return result;
+ }
+
+ /** Save the current set of persistent properties to the filename
+ * which the AppContext returns in getPropertiesFileName ().
+ * @throws FileNotFoundException Couldn't find that path.
+ * @throws IOException Couldn't write for some reason.
+ */
+ public boolean saveProperties()
+ throws java.io.FileNotFoundException, java.io.IOException
+ {
+ _propertiesManager.store_to_file (_persistentPropertiesFilename);
+ return true; /* If we didn't throw, it's okay. */
+ }
+
+ /**
+ * Get the file name that the Properties manager will load from and save
persistent properties to.
+ *
+ * @return The file name that the Properties manager will load from and
save persistent properties to.
+ */
+ public String getPropertiesFileName () {
+ return _persistentPropertiesFilename;
+ }
+
+ /**
+ * Set the file name that the Properties manager will load from and save
persistent properties to.
+ *
+ * @param fileName The file name that the Properties manager will load
from and save persistent properties to.
+ */
+ public void setPropertiesFileName (String fileName) {
+ _persistentPropertiesFilename = fileName;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]