cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Property.java
peterreilly2005/03/14 02:25:27 Modified:src/main/org/apache/tools/ant/taskdefs Property.java Log: javadoc Revision ChangesPath 1.74 +47 -1 ant/src/main/org/apache/tools/ant/taskdefs/Property.java Index: Property.java === RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v retrieving revision 1.73 retrieving revision 1.74 diff -u -r1.73 -r1.74 --- Property.java 12 Nov 2004 15:14:59 - 1.73 +++ Property.java 14 Mar 2005 10:25:27 - 1.74 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -81,11 +81,16 @@ protected boolean userProperty; // set read-only properties +/** + * Constructor for Property. + */ public Property() { this(false); } /** + * Constructor for Property. + * @param userProperty if true this is a user property * @since Ant 1.5 */ protected Property(boolean userProperty) { @@ -93,6 +98,10 @@ } /** + * Constructor for Property. + * @param userProperty if true this is a user property + * @param fallback a project to use to look for references if the reference is + * not in the current project * @since Ant 1.5 */ protected Property(boolean userProperty, Project fallback) { @@ -108,6 +117,10 @@ this.name = name; } +/** + * Get the property name. + * @return the property name + */ public String getName() { return name; } @@ -136,6 +149,10 @@ this.value = value; } +/** + * Get the property value. + * @return the property value + */ public String getValue() { return value; } @@ -150,6 +167,10 @@ this.file = file; } +/** + * Get the file attribute. + * @return the file attribute + */ public File getFile() { return file; } @@ -164,6 +185,10 @@ this.url = url; } +/** + * Get the url attribute. + * @return the url attribute + */ public URL getUrl() { return url; } @@ -183,6 +208,8 @@ } /** + * Get the prefix attribute. + * @return the prefix attribute * @since Ant 1.5 */ public String getPrefix() { @@ -202,6 +229,10 @@ this.ref = ref; } +/** + * Get the refid attribute. + * @return the refid attribute + */ public Reference getRefid() { return ref; } @@ -216,6 +247,10 @@ this.resource = resource; } +/** + * Get the resource attribute. + * @return the resource attribute + */ public String getResource() { return resource; } @@ -245,6 +280,8 @@ } /** + * Get the environment attribute. + * @return the environment attribute * @since Ant 1.5 */ public String getEnvironment() { @@ -265,6 +302,7 @@ /** * The classpath to use when looking up a resource. + * @return a path to be configured */ public Path createClasspath() { if (this.classpath == null) { @@ -276,12 +314,15 @@ /** * the classpath to use when looking up a resource, * given as reference to a lt;pathgt; defined elsewhere + * @param r a reference to a classpath */ public void setClasspathRef(Reference r) { createClasspath().setRefid(r); } /** + * Get the classpath used when looking up a resource. + * @return the classpath * @since Ant 1.5 */ public Path getClasspath() { @@ -289,6 +330,7 @@ } /** + * @param userProperty ignored * @deprecated This was never a supported feature and has been * deprecated without replacement * @ant.attribute ignore=true @@ -310,6 +352,7 @@ * set the property in the project to the value. * if the task was give a file, resource or env attribute * here is where it is loaded + * @throws BuildException on error */ public void execute() throws BuildException { if (getProject() == null) { @@ -373,6 +416,7 @@ /** * load properties from a url * @param url url to load from + * @throws BuildException on error */ protected void loadUrl(URL url) throws BuildException { Properties props = new
cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Property.java
bodewig 2003/07/24 01:09:34 Modified:src/main/org/apache/tools/ant/taskdefs Property.java Log: Resolve properties recursively to get a more robust handle on circular definitions Revision ChangesPath 1.66 +47 -37ant/src/main/org/apache/tools/ant/taskdefs/Property.java Index: Property.java === RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v retrieving revision 1.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- Property.java 23 Jul 2003 15:14:19 - 1.65 +++ Property.java 24 Jul 2003 08:09:34 - 1.66 @@ -61,6 +61,7 @@ import java.net.URL; import java.util.Enumeration; import java.util.Properties; +import java.util.Stack; import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -570,48 +571,57 @@ private void resolveAllProperties(Properties props) throws BuildException { for (Enumeration e = props.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); -String value = props.getProperty(name); +Stack referencesSeen = new Stack(); +resolve(props, name, referencesSeen); +} +} -boolean resolved = false; -Vector expandedReferences = new Vector(); -expandedReferences.addElement(name); -while (!resolved) { -Vector fragments = new Vector(); -Vector propertyRefs = new Vector(); -ProjectHelper.parsePropertyString(value, fragments, - propertyRefs); - -resolved = true; -if (propertyRefs.size() != 0) { -StringBuffer sb = new StringBuffer(); -Enumeration i = fragments.elements(); -Enumeration j = propertyRefs.elements(); -while (i.hasMoreElements()) { -String fragment = (String) i.nextElement(); -if (fragment == null) { -String propertyName = (String) j.nextElement(); -if (expandedReferences.contains(propertyName)) { -throw new BuildException(Property + name - + was circularly - + defined.); -} -expandedReferences.addElement(propertyName); -fragment = getProject().getProperty(propertyName); -if (fragment == null) { -if (props.containsKey(propertyName)) { -fragment = props.getProperty(propertyName); -resolved = false; -} else { -fragment = ${ + propertyName + }; -} -} +/** + * Recursively expand the named property using the project's + * reference table and the given set of properties - fail if a + * circular definition is detected. + * + * @param props properties object to resolve + * @param name of the property to resolve + * @param referencesSeen stack of all property names that have + * been tried to expand before coming here. + */ +private void resolve(Properties props, String name, Stack referencesSeen) +throws BuildException { +if (referencesSeen.contains(name)) { +throw new BuildException(Property + name + was circularly + + defined.); +} + +String value = props.getProperty(name); +Vector fragments = new Vector(); +Vector propertyRefs = new Vector(); +ProjectHelper.parsePropertyString(value, fragments, propertyRefs); + +if (propertyRefs.size() != 0) { +referencesSeen.push(name); +StringBuffer sb = new StringBuffer(); +Enumeration i = fragments.elements(); +Enumeration j = propertyRefs.elements(); +while (i.hasMoreElements()) { +String fragment = (String) i.nextElement(); +if (fragment == null) { +String propertyName = (String) j.nextElement(); +fragment = getProject().getProperty(propertyName); +if (fragment == null) { +if (props.containsKey(propertyName)) { +resolve(props, propertyName, referencesSeen); +
cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Property.java
jesse 2003/04/25 07:11:16 Modified:src/main/org/apache/tools/ant/taskdefs Property.java Log: Add some new @tags for xdocs Revision ChangesPath 1.61 +38 -23ant/src/main/org/apache/tools/ant/taskdefs/Property.java Index: Property.java === RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v retrieving revision 1.60 retrieving revision 1.61 diff -u -r1.60 -r1.61 --- Property.java 18 Apr 2003 23:40:22 - 1.60 +++ Property.java 25 Apr 2003 14:11:16 - 1.61 @@ -99,6 +99,9 @@ * @author a href=mailto:[EMAIL PROTECTED]Sam Ruby/a * @author a href=mailto:[EMAIL PROTECTED]Glenn McAllister/a * @since Ant 1.1 + * + * @ant.attribute.group name=name description=One of these, when using the name attribute + * @ant.attribute.group name=nonamedescription=One of these, when not using the name attribute */ public class Property extends Task { @@ -134,7 +137,7 @@ } /** - * sets the name of the property to set. + * The name of the property to set. * @param name property name */ public void setName(String name) { @@ -152,14 +155,18 @@ * current platforms conventions). Otherwise it is taken as a path * relative to the project's basedir and expanded. * @param location path to set + * + * @ant.attribute group=name */ public void setLocation(File location) { setValue(location.getAbsolutePath()); } /** - * Sets the value of the property. + * The value of the property. * @param value value to assign + * + * @ant.attribute group=name */ public void setValue(String value) { this.value = value; @@ -170,8 +177,10 @@ } /** - * the filename of a property file to load. - [EMAIL PROTECTED] file filename + * Filename of a property file to load. + * @param file filename + * + * @ant.attribute group=noname */ public void setFile(File file) { this.file = file; @@ -208,6 +217,8 @@ * Only yields reasonable results for references * PATH like structures or properties. * @param ref reference + * + * @ant.attribute group=name */ public void setRefid(Reference ref) { this.ref = ref; @@ -218,8 +229,10 @@ } /** - * the resource name of a property file to load + * The resource name of a property file to load * @param resource resource on classpath + * + * @ant.attribute group=noname */ public void setResource(String resource) { this.resource = resource; @@ -230,23 +243,25 @@ } /** -* the prefix to use when retrieving environment variables. -* Thus if you specify environment=quot;myenvquot; -* you will be able to access OS-specific -* environment variables via property names quot;myenv.PATHquot; or -* quot;myenv.TERMquot;. -* p -* Note that if you supply a property name with a final -* quot;.quot; it will not be doubled. ie environment=quot;myenv.quot; will still -* allow access of environment variables through quot;myenv.PATHquot; and -* quot;myenv.TERMquot;. This functionality is currently only implemented -* on select platforms. Feel free to send patches to increase the number of platforms -* this functionality is supported on ;).br -* Note also that properties are case sensitive, even if the -* environment variables on your operating system are not, e.g. it -* will be ${env.Path} not ${env.PATH} on Windows 2000. -* @param env prefix -*/ + * Prefix to use when retrieving environment variables. + * Thus if you specify environment=quot;myenvquot; + * you will be able to access OS-specific + * environment variables via property names quot;myenv.PATHquot; or + * quot;myenv.TERMquot;. + * p + * Note that if you supply a property name with a final + * quot;.quot; it will not be doubled. ie environment=quot;myenv.quot; will still + * allow access of environment variables through quot;myenv.PATHquot; and + * quot;myenv.TERMquot;. This functionality is currently only implemented + * on select platforms. Feel free to send patches to increase the number of platforms + * this functionality is supported on ;).br + * Note also that properties are case sensitive, even if the + * environment variables on your operating system are not, e.g. it + * will be ${env.Path} not ${env.PATH} on Windows 2000. + * @param env prefix + * + * @ant.attribute group=noname + */ public void setEnvironment(String env) {