You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by we...@apache.org on 2002/10/21 18:59:52 UTC
cvs commit: jakarta-commons-sandbox/grant/src/java/org/apache/commons/grant DefaultPropsHandler.java GrantProject.java PropsHandler.java
werken 2002/10/21 09:59:52
Modified: grant project.xml
grant/src/java/org/apache/commons/grant GrantProject.java
PropsHandler.java
Added: grant/src/java/org/apache/commons/grant
DefaultPropsHandler.java
Log:
Commit that got lost in a worm-hole.
Patches from Stephane Haberman to do whatever it was he was doing.
Variable resolution and such, I seem to recall. commons-dev archive
should have pointers.
Revision Changes Path
1.5 +1 -1 jakarta-commons-sandbox/grant/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/grant/project.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- project.xml 11 Aug 2002 16:44:14 -0000 1.4
+++ project.xml 21 Oct 2002 16:59:52 -0000 1.5
@@ -4,7 +4,7 @@
<pomVersion>3</pomVersion>
<name>commons-grant</name>
<id>commons-grant</id>
- <currentVersion>1.0-beta-3</currentVersion>
+ <currentVersion>1.0-beta-4</currentVersion>
<organization>
<name>Apache Software Foundation</name>
<url>http://www.apache.org</url>
1.3 +67 -17 jakarta-commons-sandbox/grant/src/java/org/apache/commons/grant/GrantProject.java
Index: GrantProject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/grant/src/java/org/apache/commons/grant/GrantProject.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GrantProject.java 11 Aug 2002 14:42:59 -0000 1.2
+++ GrantProject.java 21 Oct 2002 16:59:52 -0000 1.3
@@ -62,12 +62,14 @@
*/
import java.io.File;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Properties;
+import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
-import org.apache.tools.ant.BuildException;
-
+import org.apache.tools.ant.util.JavaEnvUtils;
/** A subclass of an ant <code>Project</code> which allows
* installation of delegators for particular functions.
@@ -88,7 +90,7 @@
// ------------------------------------------------------------
/** Properties delegate. */
- private PropsHandler propsHandler;
+ private PropsHandler propsHandler;
// ------------------------------------------------------------
// Constructors
@@ -145,30 +147,30 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public String replaceProperties(String value) throws BuildException {
- return ProjectHelper.replaceProperties(this, value, getProperties() );
+ return ProjectHelper.replaceProperties(this, value, getProperties());
}
- public void setProperty(String key, String value) {
+ public synchronized void setProperty(String key, String value) {
if (this.propsHandler == null) {
- super.setProperty(key,value);
+ super.setProperty(key, value);
}
else {
this.propsHandler.setProperty(key, value);
}
}
- public void setUserProperty(String key, String value) {
+ public synchronized void setUserProperty(String key, String value) {
if (this.propsHandler == null) {
- super.setUserProperty(key,value);
+ super.setUserProperty(key, value);
}
else {
this.propsHandler.setUserProperty(key, value);
}
}
- public void setNewProperty(String key, String value) {
+ public synchronized void setNewProperty(String key, String value) {
if (this.propsHandler == null) {
- super.setNewProperty(key,value);
+ super.setNewProperty(key, value);
}
else {
this.propsHandler.setNewProperty(key, value);
@@ -177,7 +179,7 @@
public void setInheritedProperty(String key, String value) {
if (this.propsHandler == null) {
- super.setInheritedProperty(key,value);
+ super.setInheritedProperty(key, value);
}
else {
this.propsHandler.setInheritedProperty(key, value);
@@ -208,9 +210,57 @@
return this.propsHandler.getUserProperties();
}
+ public Hashtable getProperties() {
+ if (this.propsHandler == null) {
+ return super.getProperties();
+ }
+
+ return this.propsHandler.getProperties();
+ }
+
+ public void copyUserProperties(Project other) {
+ if (this.propsHandler == null) {
+ super.copyUserProperties(other);
+ }
+ else {
+ this.propsHandler.copyUserProperties(other);
+ }
+ }
+
+ public void copyInheritedProperties(Project other) {
+ if (this.propsHandler == null) {
+ super.copyInheritedProperties(other);
+ }
+ else {
+ this.propsHandler.copyInheritedProperties(other);
+ }
+ }
+
+ public void setSystemProperties() {
+ if (this.propsHandler == null) {
+ super.setSystemProperties();
+ }
+ else {
+ this.propsHandler.setSystemProperties();
+ }
+ }
+
+ public void setJavaVersionProperty() throws BuildException {
+ // Always call the super, as they do some sanity checks
+ super.setJavaVersionProperty();
+
+ if (this.propsHandler != null) {
+ this.propsHandler.setJavaVersionProperty();
+ }
+ }
+
public void setBaseDir(File baseDir) throws BuildException {
- super.setBaseDir( baseDir );
- setProperty( "basedir" , baseDir.getPath() );
+ super.setBaseDir(baseDir);
+
+ if (this.propsHandler != null) {
+ this.propsHandler.setPropertyIfUndefinedByUser(
+ "basedir",
+ baseDir.getPath());
+ }
}
}
-
1.3 +47 -4 jakarta-commons-sandbox/grant/src/java/org/apache/commons/grant/PropsHandler.java
Index: PropsHandler.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/grant/src/java/org/apache/commons/grant/PropsHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PropsHandler.java 11 Aug 2002 14:42:59 -0000 1.2
+++ PropsHandler.java 21 Oct 2002 16:59:52 -0000 1.3
@@ -63,17 +63,27 @@
import java.util.Hashtable;
+import org.apache.tools.ant.Project;
+
/** Interface for delegates supporting property management
* for a<code>GrantProject</code>.
*
* @see GrantProject#setProperty
+ * @see GrantProject#setNewProperty
* @see GrantProject#setUserProperty
+ * @see GrantProject#setInheritedProperty
+ * @see GrantProject#setPropertyIfUndefinedByUser
* @see GrantProject#getProperty
* @see GrantProject#getUserProperty
* @see GrantProject#getProperties
* @see GrantProject#getUserProperties
+ * @see GrantProject#copyUserProperties
+ * @see GrantProject#copyInheritedProperties
+ * @see GrantProject#setSystemProperties
+ * @see GrantProject#setJavaVersionProperty
*
- * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
+ * @author <a href="mailto:bob@eng.werken.com">Bob McWhirter</a>
+ * @author <a href="mailto:stephenh@chase3000.com">Stephen Haberman</a>
*/
public interface PropsHandler {
@@ -104,6 +114,16 @@
* @param value The value.
*/
void setInheritedProperty(String key, String value);
+
+ /** Sets a property that is not a user property.
+ *
+ * Acts as the replacement for ant's private
+ * <code>setPropertyInternal</code> method.
+ *
+ * @param key The property key.
+ * @param value The value.
+ */
+ void setPropertyIfUndefinedByUser(String key, String value);
/** Retrieve a property.
*
@@ -132,4 +152,27 @@
* @return A <code>Hashtable</code> of all user properties.
*/
Hashtable getUserProperties();
+
+ /** Copy all of the user properties to the other <code>Project</code>.
+ *
+ * @param other The <code>Project</code> to copy the properties to.
+ */
+ void copyUserProperties(Project other);
+
+ /** Copy all of the inherited properties to the other <code>Project</code>.
+ *
+ * @param other The <code>Project</code> to copy the properties to.
+ */
+ void copyInheritedProperties(Project other);
+
+ /** Set the system variables for a <code>Project</code> that have
+ * not already been assigned as user properties.
+ */
+ void setSystemProperties();
+
+ /** Set the <code>ant.java.version</code> property.
+ */
+ void setJavaVersionProperty();
+
+
}
1.1 jakarta-commons-sandbox/grant/src/java/org/apache/commons/grant/DefaultPropsHandler.java
Index: DefaultPropsHandler.java
===================================================================
package org.apache.commons.grant;
/*
* $Header: /home/cvs/jakarta-commons-sandbox/grant/src/java/org/apache/commons/grant/DefaultPropsHandler.java,v 1.1 2002/10/21 16:59:52 werken Exp $
* $Revision: 1.1 $
* $Date: 2002/10/21 16:59:52 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 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 "The Jakarta Project", "Commons", 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 apache@apache.org.
*
* 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/>.
*
*/
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.JavaEnvUtils;
/** Implements the basic {@link PropsHandler} functionality
* against an existing map.
*
* <p>
* If extending <code>DefaultPropsHandler</code>, you can
* implement <code>setProperty</code>, <code>getProperty</code>,
* and <code>getProperties</code> to provide a complete
* implementation of <code>PropsHandler</code>.
*
* @author <a href="mailto:stephenh@chase3000.com">Stephen Haberman</a>
* @version $Revision: 1.1 $
*/
public class DefaultPropsHandler implements PropsHandler {
/** A map of all of the properties. */
protected Map properties;
/** A history of the properties marked as user properties. */
protected Map userProperties = new HashMap();
/** A history of the properties makred as inherited properties. */
protected Map inheritedProperties = new HashMap();
/** Initializes hte object with a blank set of properties.
*/
public DefaultPropsHandler() {
this.properties = new HashMap();
}
/** Initializes the object with a given <code>Map</code>
* implementation.
*
* @param properties The <code>Map</code> to use to store and retrieve properties.
*/
public DefaultPropsHandler(Map properties) {
this.properties = properties;
}
/**
* @see org.apache.commons.grant.PropsHandler#setProperty(String, String)
*/
public void setProperty(String key, String value) {
this.properties.put(key, value);
}
/**
* @see org.apache.commons.grant.PropsHandler#setUserProperty(String, String)
*/
public void setUserProperty(String key, String value) {
this.userProperties.put(key, value);
this.setProperty(key, value);
}
/**
* @see org.apache.commons.grant.PropsHandler#setNewProperty(String, String)
*/
public void setNewProperty(String key, String value) {
if (this.getProperty(key) == null) {
this.setProperty(key, value);
}
}
/**
* @see org.apache.commons.grant.PropsHandler#setInheritedProperty(String, String)
*/
public void setInheritedProperty(String key, String value) {
this.inheritedProperties.put(key, value);
this.setUserProperty(key, value);
}
/**
* @see org.apache.commons.grant.PropsHandler#setPropertyIfUndefinedByUser(String, String)
*/
public void setPropertyIfUndefinedByUser(String key, String value) {
if (!this.getUserProperties().contains(key)) {
this.setProperty(key, value);
}
}
/**
* @see org.apache.commons.grant.PropsHandler#getProperty(String)
*/
public String getProperty(String key) {
if (key == null) {
return null;
}
return (String) this.properties.get(key);
}
/**
* @see org.apache.commons.grant.PropsHandler#getUserProperty(String)
*/
public String getUserProperty(String key) {
if (key == null) {
return null;
}
return (String) this.userProperties.get(key);
}
/**
* @see org.apache.commons.grant.PropsHandler#getProperties()
*/
public Hashtable getProperties() {
return new Hashtable(this.properties);
}
/**
* @see org.apache.commons.grant.PropsHandler#getUserProperties()
*/
public Hashtable getUserProperties() {
return new Hashtable(this.userProperties);
}
public Hashtable getInheritedProperties() {
return new Hashtable(this.inheritedProperties);
}
/**
* @see org.apache.commons.grant.PropsHandler#copyUserProperties(Project)
*/
public void copyUserProperties(Project other) {
Hashtable userProps = this.getUserProperties();
Hashtable inheritedProps = this.getInheritedProperties();
Enumeration e = userProps.keys();
while (e.hasMoreElements()) {
Object name = e.nextElement();
if (inheritedProps.contains(name)) {
continue;
}
Object value = userProps.get(name);
other.setUserProperty(name.toString(), value.toString());
}
}
/**
* @see org.apache.commons.grant.PropsHandler#copyInheritedProperties(Project)
*/
public void copyInheritedProperties(Project other) {
Hashtable inheritedProps = this.getInheritedProperties();
Enumeration e = inheritedProps.keys();
while (e.hasMoreElements()) {
String name = e.nextElement().toString();
if (other.getUserProperty(name) != null) {
continue;
}
Object value = inheritedProps.get(name);
other.setInheritedProperty(name, value.toString());
}
}
/**
* @see org.apache.commons.grant.PropsHandler#setSystemProperties
*/
public void setSystemProperties() {
Properties systemProps = System.getProperties();
Enumeration e = systemProps.keys();
while (e.hasMoreElements()) {
Object name = e.nextElement();
String value = systemProps.get(name).toString();
this.setPropertyIfUndefinedByUser(name.toString(), value);
}
}
/**
* @see org.apache.commons.grant.PropsHandler#setJavaVersionProperty
*/
public void setJavaVersionProperty() {
String javaVersion = JavaEnvUtils.getJavaVersion();
this.setPropertyIfUndefinedByUser("ant.java.version", javaVersion);
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>