ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 17883] - Custom task containers don't share property state across subtasks
Date Wed, 12 Mar 2003 16:58:50 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17883>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17883

Custom task containers don't share property state across subtasks





------- Additional Comments From dlwhiteman@us.ibm.com  2003-03-12 16:58 -------
I agree with Pat... a new subclass to handle this for users would be nice.

Here's my contribution to how I worked around the problem.  I think you could 
create a subclass of TaskContainer to hold this stuff that Sequential could 
override.

BTW... I wonder why Bugzilla hasn't yet made it possible to edit existing 
comments - would allow folks to clean up typos or sensitive information that 
should never have been posted.

--- code below ---

//--------------------------------------------------------------------
/**
 * Use reflection to find any public or protected method in
 * the hierarchy of <CODE>starterClass</CODE>.
 */
public static Method findMethod(Class starterClass, String methodName, Class[] 
definedArgTypes) {
	Class currentClass = starterClass;
	while ((currentClass != null)) {
		try {
			return currentClass.getDeclaredMethod(methodName, 
definedArgTypes);
		} catch (NoSuchMethodException e) {
			currentClass = currentClass.getSuperclass();
		}
	}
	return null;
}

//--------------------------------------------------------------------
/**
 * Convenience method for the other findMethod() so that callers don't need
 * to send getClass().
 */
public static Method findMethod(Object receiver, String methodName, Class[] 
definedArgTypes) {
	return findMethod(receiver.getClass(), methodName, definedArgTypes);
}

//--------------------------------------------------------------------
/**
 * Workaround for design change in Ant 1.5.2 with preserving property state
 * between contained tasks.  In Ant 1.4.1, it won't find the isInvalid()
 * method, and will end up just calling the parent class maybeConfigure(),
 * so this approach is backward compatible.
 */
public void maybeConfigure() throws BuildException {
	Method isInvalidMethod = findMethod(this, "isInvalid", null);
	if (isInvalidMethod == null) {
		super.maybeConfigure();
		return;
	}
	Object isInvalidResult = null;
	try {
		isInvalidResult = isInvalidMethod.invoke(this, new Object[] {});
	} catch (IllegalAccessException e) {
	} catch (InvocationTargetException e) {
	}
    if (((Boolean) isInvalidResult).booleanValue()) {
        super.maybeConfigure();
    } else {
    	Method maybeConfigureTwoArgMethod = null;
		maybeConfigureTwoArgMethod =
			findMethod(getRuntimeConfigurableWrapper(),
				"maybeConfigure",
				new Class[] { Project.class, boolean.class });
		if (maybeConfigureTwoArgMethod == null) {
			// should not occur, since we already found isInvalid(),
			// which was made available in the same Ant version as
			// the 2-arg maybeConfigure()
			System.out.println("couldn't find method 
maybeConfigure");
			return;
		}
    	try {
			maybeConfigureTwoArgMethod.invoke
(getRuntimeConfigurableWrapper(), new Object[] {getProject(), Boolean.FALSE});
		} catch (IllegalAccessException e) {
		} catch (InvocationTargetException e) {
		}
    }
}

Mime
View raw message