You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Twiggs, Glenn" <Gl...@bmc.com> on 1999/11/16 21:03:31 UTC
RE: cvs commit: jakarta-tools/ant/src/main/org/apache/tools/ant A
nt.java InvocationHelper.java Project.java Target.java Task.java XmlHelpe
r.java
There is an inconsistancy in method Ant.processArgs(...):
According to the usage message, the -D option is supposed to process an arg
of the form "-Darg=value" but the way it is coded it processes args of the
form "-Darg value". org.apache.tools.ant.Main.main(...) has the same
inconsistancy. I am guessing you copied the code? I vote that the "=" is
removed from the usage message. It's easier than making a code change.
-----Original Message-----
From: costin@hyperreal.org [mailto:costin@hyperreal.org]
Sent: Tuesday, November 16, 1999 12:54 PM
To: jakarta-tools-cvs@apache.org
Subject: cvs commit: jakarta-tools/ant/src/main/org/apache/tools/ant
Ant.java InvocationHelper.java Project.java Target.java Task.java
XmlHelper.java
costin 99/11/16 10:53:37
Modified: ant/src/main/org/apache/tools/ant InvocationHelper.java
Project.java Target.java Task.java XmlHelper.java
Added: ant/src/main/org/apache/tools/ant Ant.java
Log:
- Added a Ant.java - it does the same thing as Main.java, but
uses InvocationHelper and XMLHelper instead of ProjectHelper.
- Added few methods to Project, Task, etc - no change in existing methods.
( needed to make them work with XMLHelper)
Ant.java allows you to add new tasks without defining them in properties,
you can have more than 1 level ( i.e. tasks can have sub-elements), you
can use body ( will be usefull in Exec ).
( most of the changes are in different files to keep ant stable )
Revision Changes Path
1.2 +15 -14
jakarta-tools/ant/src/main/org/apache/tools/ant/InvocationHelper.java
Index: InvocationHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/InvocationHelper.j
ava,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InvocationHelper.java 1999/11/15 23:24:24 1.1
+++ InvocationHelper.java 1999/11/16 18:53:14 1.2
@@ -53,7 +53,7 @@
/** Set a property, using either the setXXX method or a generic
setProperty(name, value)
* @returns true if success
*/
- public static void setProperty( Object o, String name, String value )
throws BuildException {
+ public static void setProperty( Object o, String name, String value )
{
// System.out.println("Setting Property " + o.getClass() + " "
+ name + "=" + value);
try {
Method setMethod = (Method)getPropertySetter(o, name);
@@ -69,25 +69,25 @@
return;
}
- String msg = "Error setting " + name + " in " + o.getClass();
- throw new BuildException(msg);
+ // String msg = "Error setting " + name + " in " +
o.getClass();
+ //throw new BuildException(msg);
} catch (IllegalAccessException iae) {
String msg = "Error setting value for attrib: " + name;
System.out.println("WARNING " + msg);
iae.printStackTrace();
- throw new BuildException(msg);
+ // throw new BuildException(msg);
} catch (InvocationTargetException ie) {
String msg = "Error setting value for attrib: " +
name + " in " + o.getClass().getName();
ie.printStackTrace();
ie.getTargetException().printStackTrace();
- throw new BuildException(msg);
+ // throw new BuildException(msg);
}
}
/** Set an object property using setter or setAttribute(name).
*/
- public static void setAttribute( Object o, String name, Object v )
throws BuildException {
+ public static void setAttribute( Object o, String name, Object v ) {
// System.out.println("Set Attribute " + o.getClass() + " " +
name + " " + v );
try {
Method setMethod = getPropertySetter(o, name);
@@ -106,26 +106,27 @@
setMethod.invoke(o, new Object[] {name, v});
return;
}
-
- String msg = "Error setting " + name + " in " + o.getClass();
- throw new BuildException(msg);
+
+ // Silent
+ // String msg = "Error setting " + name + " in " +
o.getClass();
+ // throw new BuildException(msg);
} catch (IllegalAccessException iae) {
String msg = "Error setting value for attrib: " +
name;
iae.printStackTrace();
- throw new BuildException(msg);
+ // throw new BuildException(msg);
} catch (InvocationTargetException ie) {
String msg = "Error setting value for attrib: " +
name + " in " + o.getClass().getName();
ie.printStackTrace();
ie.getTargetException().printStackTrace();
- throw new BuildException(msg);
+ // throw new BuildException(msg);
}
}
/** Calls addXXX( v ) then setAttribute( name, v).
*/
- public static void addAttribute( Object o, String name, Object v )
throws BuildException {
+ public static void addAttribute( Object o, String name, Object v ) {
try {
Method setMethod = getMethod(o, "add" + capitalize( name ));
if( setMethod!= null ) {
@@ -144,13 +145,13 @@
String msg = "Error setting value for attrib: " +
name;
iae.printStackTrace();
- throw new BuildException(msg);
+ // throw new BuildException(msg);
} catch (InvocationTargetException ie) {
String msg = "Error setting value for attrib: " +
name + " in " + o.getClass().getName();
ie.printStackTrace();
ie.getTargetException().printStackTrace();
- throw new BuildException(msg);
+ // throw new BuildException(msg);
}
}
1.8 +30 -1
jakarta-tools/ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file:
/home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Project.java 1999/10/31 23:14:14 1.7
+++ Project.java 1999/11/16 18:53:16 1.8
@@ -102,11 +102,18 @@
public void setDefaultTarget(String defaultTarget) {
this.defaultTarget = defaultTarget;
}
-
+
+ // deprecated, use setDefault
public String getDefaultTarget() {
return defaultTarget;
}
+ // match the attribute name
+ public void setDefault(String defaultTarget) {
+ this.defaultTarget = defaultTarget;
+ }
+
+
public void setName(String name) {
this.name = name;
}
@@ -115,6 +122,17 @@
return name;
}
+ // match basedir attribute in xml
+ public void setBasedir( String baseD ) throws BuildException {
+ try {
+ setBaseDir(new File( new File(baseD).getCanonicalPath()));
+ } catch (IOException ioe) {
+ String msg = "Can't set basedir " + baseDir + " due to " +
+ ioe.getMessage();
+ throw new BuildException(msg);
+ }
+ }
+
public void setBaseDir(File baseDir) {
this.baseDir = baseDir;
String msg = "Project base dir set to: " + baseDir;
@@ -122,6 +140,11 @@
}
public File getBaseDir() {
+ if(baseDir==null) {
+ try {
+ setBasedir(".");
+ } catch(BuildException ex) {ex.printStackTrace();}
+ }
return baseDir;
}
@@ -161,6 +184,12 @@
taskClassDefinitions.put(taskName, taskClass);
}
+ public void addTarget(Target target) {
+ String msg = " +Target: " + target.getName();
+ log(msg, MSG_VERBOSE);
+ targets.put(target.getName(), target);
+ }
+
public void addTarget(String targetName, Target target) {
String msg = " +Target: " + targetName;
log(msg, MSG_VERBOSE);
1.2 +27 -0
jakarta-tools/ant/src/main/org/apache/tools/ant/Target.java
Index: Target.java
===================================================================
RCS file:
/home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/Target.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Target.java 1999/10/09 00:06:05 1.1
+++ Target.java 1999/11/16 18:53:17 1.2
@@ -2,6 +2,7 @@
import java.util.Enumeration;
import java.util.Vector;
+import java.util.StringTokenizer;
/**
*
@@ -14,7 +15,33 @@
private String name;
private Vector dependencies = new Vector();
private Vector tasks = new Vector();
+ Project project;
+
+ public void setProject( Project project) {
+ this.project=project;
+ }
+ public Project getProject() {
+ return project;
+ }
+
+ public void setDepends( String depS ) {
+ if (depS.length() > 0) {
+ StringTokenizer tok =
+ new StringTokenizer(depS, ",", false);
+ while (tok.hasMoreTokens()) {
+ addDependency(tok.nextToken().trim());
+ }
+ }
+ }
+
+ public void setAttribute(String name, Object value) {
+ // XXX
+ if( value instanceof Task)
+ addTask( (Task)value);
+
+ }
+
public void setName(String name) {
this.name = name;
}
1.4 +12 -0
jakarta-tools/ant/src/main/org/apache/tools/ant/Task.java
Index: Task.java
===================================================================
RCS file:
/home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/Task.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Task.java 1999/10/15 19:27:44 1.3
+++ Task.java 1999/11/16 18:53:18 1.4
@@ -17,6 +17,7 @@
public abstract class Task {
protected Project project = null;
+ Target target;
/**
* Sets the project object of this task. This method is used by
@@ -31,6 +32,17 @@
this.project = project;
}
+ public void setAttribute( String name, Object v) {
+ if("target".equals( name ) ) {
+ Target t=(Target)v;
+ target=t;
+ project=t.getProject();
+ return;
+ }
+ // System.out.println("Set Att " +name + " = " + v );
+ // if( v!=null) System.out.println(v.getClass());
+ }
+
/**
* Called by the project to let the task do it's work.
*
1.2 +5 -3
jakarta-tools/ant/src/main/org/apache/tools/ant/XmlHelper.java
Index: XmlHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/XmlHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XmlHelper.java 1999/11/16 00:40:56 1.1
+++ XmlHelper.java 1999/11/16 18:53:20 1.2
@@ -97,6 +97,8 @@
public XmlHelperHandler(Map mapper, Properties props) {
tagMapper=mapper;
this.props=props;
+ elemStack = new Object[100]; // depth of the xml doc
+ tagStack = new String[100];
}
public void setDocumentLocator (Locator locator)
@@ -107,8 +109,6 @@
public void startDocument () throws SAXException
{
- elemStack = new Object[100]; // depth of the xml doc
- tagStack = new String[100];
sp = 0;
}
@@ -206,7 +206,9 @@
throws SAXException
{
String value=new String(buf, offset, len );
- // System.out.println("XXXCH: " + value );
+ if( (sp > 0) && elemStack[sp]!=null ) {
+ InvocationHelper.addAttribute( elemStack[sp], "body", value );
+ }
}
1.1
jakarta-tools/ant/src/main/org/apache/tools/ant/Ant.java
Index: Ant.java
===================================================================
package org.apache.tools.ant;
import java.beans.*;
import java.io.*;
import java.io.IOException;
import java.lang.reflect.*;
import java.util.Hashtable;
import java.util.*;
import com.sun.xml.parser.Resolver;
import com.sun.xml.tree.XmlDocument;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.w3c.dom.*;
import org.apache.tools.ant.*;
/**
*
*
* @author duncan@x180.com
* @author costin@dnt.ro
*/
public class Ant {
public static final int MSG_ERR = 0;
public static final int MSG_WARN = 1;
public static final int MSG_INFO = 2;
public static final int MSG_VERBOSE = 3;
public int msgOutputLevel = MSG_INFO;
private Properties definedProps = new Properties();
public String usage="No usage help";
public String vopt[] = null;
Vector targets=new Vector();
static StringBuffer msg;
static {
String lSep = System.getProperty("line.separator");
msg = new StringBuffer();
msg.append("ant [options] [target]").append(lSep);
msg.append("Options: ").append(lSep);
msg.append(" -help print this message");
msg.append(lSep);
msg.append(" -quiet be extra quiet");
msg.append(lSep);
msg.append(" -verbose be extra verbose");
msg.append(lSep);
msg.append(" -buildfile <file> use given buildfile");
msg.append(lSep);
msg.append(" -D<property>=<value> use value for given
property");
msg.append(lSep);
}
public static void main(String args[] ) {
try {
Ant ant=new Ant();
ant.setValidOptions( new String[] { "buildfile" } );
if( ! ant.processArgs( args ) ) {
return;
}
Properties props=ant.getProperties();
String fname=props.getProperty("buildfile");
if(fname==null) fname=props.getProperty("file", "build.xml");
File f=new File(fname);
TagMap mapper=new TagMap( "org.apache.tools.ant.taskdefs");
mapper.addMap( "project", "org.apache.tools.ant.Project");
mapper.addMap( "target", "org.apache.tools.ant.Target");
Project project=(Project)XmlHelper.readXml(f, props, mapper,
null);
Enumeration e = props.keys();
while (e.hasMoreElements()) {
String arg = (String)e.nextElement();
String value = (String)props.get(arg);
project.setProperty(arg, value);
}
String args1[] = ant.getArgs();
String target = project.getDefaultTarget();
if( args1!=null && args1.length>0 )
target=args1[0];
project.executeTarget(target);
} catch(Exception ex ) {
ex.printStackTrace();
}
}
// -------------------- Argument processing --------------------
// XXX move it to a Helper class2
public void setValidOptions( String vopt[] ) {
this.vopt=vopt;
}
public Properties getProperties() {
return definedProps;
}
public String[] getArgs() {
String sa[]=new String[ targets.size() ];
for( int i=0; i< sa.length; i++ ) {
sa[i]=(String)targets.elementAt(i);
}
return sa;
}
public void printUsage() {
System.out.println(usage);
}
public boolean processArgs(String[] args) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.equals("-help") || arg.equals("help")) {
printUsage();
return false;
} else if (arg.equals("-quiet") || arg.equals("-q") ||
arg.equals("q")) {
msgOutputLevel = MSG_WARN;
} else if (arg.equals("-verbose") || arg.equals("-v") ||
arg.equals("v")) {
msgOutputLevel = MSG_VERBOSE;
} else if (arg.startsWith("-D")) {
arg = arg.substring(2, arg.length());
String value = args[++i];
definedProps.put(arg, value);
} else if (arg.startsWith("-")) {
String arg1=arg.substring(1);
int type=0;
if( vopt != null ) {
for( int j=0; j<vopt.length; i++ ) {
if( vopt[j].equalsIgnoreCase(arg1) ) {
type=1;
break;
}
}
if(type==0) {
// we don't have any more args to recognize!
String msg = "Unknown arg: " + arg;
System.out.println(msg);
printUsage();
return false;
}
}
if( i == args.length) {
System.out.println( "Missing argument");
printUsage();
return false;
}
String v=args[i+1];
i++;
definedProps.put( arg1, v);
} else {
// if it's no other arg, it may be the target
targets.addElement( arg );
}
}
return true;
}
}
/** Maps a tag name using a package prefix and a number of static
mappings.
*/
class TagMap implements Map {
String defaultPackage;
Hashtable maps=new Hashtable();
public TagMap(String defP) {
defaultPackage=defP + ".";
}
public void addMap( String tname, String jname ) {
maps.put( tname, jname );
}
public Object get( Object key ) {
String tname=(String)key;
String cName=(String)maps.get(tname);
if(cName!=null) return InvocationHelper.getInstance( cName );
// default
cName= defaultPackage + InvocationHelper.capitalize( tname );
return InvocationHelper.getInstance( cName);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-tools/ant/src/main/org/apache/tools/ant Ant.java
InvocationHelper.java Project.java Target.java Task.java XmlHelper.java
Posted by James Duncan Davidson <ja...@eng.sun.com>.
> According to the usage message, the -D option is supposed to process an arg
> of the form "-Darg=value" but the way it is coded it processes args of the
> form "-Darg value". org.apache.tools.ant.Main.main(...) has the same
> inconsistancy. I am guessing you copied the code? I vote that the "=" is
> removed from the usage message. It's easier than making a code change.
So Ant.java is Costin's temporary class. It was copied.
It should be using "=" for consistency. And, at least on JDK 1.2 and JDK
1.3, it is... When java reads in the command line arguments, it parses
-Dname=value into the arg array elements {"-Dname", "value"} -- so we
bust off the -D and read an argument ahead.
Unfortunatly, I don't have JDK 1.1 on my laptop (I'm remote right now)
so can't test out to make sure that it works this way on JDK 1.1 -- if
it works differently, then IX-Mozilla-Status: 0009code to make it work
either way.
.duncan
Re: cvs commit: jakarta-tools/ant/src/main/org/apache/tools/ant Ant.java
InvocationHelper.java Project.java Target.java Task.java XmlHelper.java
Posted by James Duncan Davidson <ja...@eng.sun.com>.
> According to the usage message, the -D option is supposed to process an arg
> of the form "-Darg=value" but the way it is coded it processes args of the
> form "-Darg value". org.apache.tools.ant.Main.main(...) has the same
> inconsistancy. I am guessing you copied the code? I vote that the "=" is
> removed from the usage message. It's easier than making a code change.
So Ant.java is Costin's temporary class. It was copied.
It should be using "=" for consistency. And, at least on JDK 1.2 and JDK
1.3, it is... When java reads in the command line arguments, it parses
-Dname=value into the arg array elements {"-Dname", "value"} -- so we
bust off the -D and read an argument ahead.
Unfortunatly, I don't have JDK 1.1 on my laptop (I'm remote right now)
so can't test out to make sure that it works this way on JDK 1.1 -- if
it works differently, then I'll lay in some patch code to make it work
either way.
.duncan
Re: cvs commit: jakarta-tools/ant/src/main/org/apache/tools/ant Ant.java
InvocationHelper.java Project.java Target.java Task.java XmlHelper.java
Posted by David Brownell <da...@pacbell.net>.
"Twiggs, Glenn" wrote:
>
> There is an inconsistancy in method Ant.processArgs(...):
>
> According to the usage message, the -D option is supposed to process an arg
> of the form "-Darg=value" but the way it is coded it processes args of the
> form "-Darg value". org.apache.tools.ant.Main.main(...) has the same
> inconsistancy. I am guessing you copied the code? I vote that the "=" is
> removed from the usage message. It's easier than making a code change.
Actually here's a case where I'd vote for consistency, and to fix
the code so it uses "-Darg=value" (like the "java" command) unless
there's a compelling reason to do otherwise.
Yes, even if this causes a few scripts to need changing. The hassles
of inconsistent "-D..." treatment will be subtle and ongoing, but they
are completely avoidable.
- Dave