ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Murdoch" <adammurdoch...@yahoo.com>
Subject RE: cvs commit: jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/property/test AbstractPropertyResolverTestCase.java
Date Thu, 21 Mar 2002 01:34:51 GMT


> -----Original Message-----
> From: darrell@apache.org [mailto:darrell@apache.org]
> Sent: Thursday, 21 March 2002 8:31 AM
> To: jakarta-ant-cvs@apache.org
> Subject: cvs commit:
> jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/componen
> ts/property/test AbstractPropertyResolverTestCase.java
>


>   Index: Ant1CompatProject.java
>   ===================================================================


>   +
>   +    /**
>   +     * Returns the value of a property, if it is set.
>   +     *
>   +     * @param name The name of the property.
>   +     *             May be <code>null</code>, in which case
>   +     *             the return value is also <code>null</code>.
>   +     * @return the property value, or <code>null</code> for no match
>   +     *         or if a <code>null</code> name is provided.
>   +     */
>   +    public String getProperty( String name )
>   +    {
>   +        Object value = m_context.getProperty( name );
>   +
>   +        // In Ant1, all properties are strings.
>   +        if( value instanceof String )
>   +        {
>   +            return (String)value;
>   +        }
>   +        else
>   +        {
>   +            return null;
>   +        }
>   +    }
>   +

How about:

public String getProperty( String name )
{
    Object value = m_context.getProperty( name );
    if ( value != null )
    {
        return value.toString();
    }
    else {
        return null;
    }
}

or, probably better:

public String getProperty( String name )
{
    Object value = m_context.getProperty( name );
    if ( value != null )
    {
        return getConverter().convert(value, String.class, m_context);
    }
    else {
        return null;
    }
}

Not so useful for an all-ant1 project, but definitely handy for bridging
between ant1 and and ant2 tasks.  For example, this could be a simple
solution for converting ant2 paths -> ant1 paths:

<project version="2.0">
  <my-dodgy-home-made-ant2-path-implementation id="classpath" ...>

  <ant1.javac classpath="${classpath}" ... >
</project>

Probably also less potential for confusion if we convert object properties
to string rather than ignoring them, so that non-string ant2 properties
don't mysteriously go missing.

Using the converter, rather than Object.toString() is probably a better
option for actually doing the object -> string conversion, since many ant2
data-types won't be able to toString() themselves without a TaskContext to
help.

If we went with using the converter, we'd want to change the property
resolvers to use the converter as well.  We'd also have to add a generic
ObjectToStringConverter.  Minor things.

Some other random comments about Ant1CompatProject:

* First up, this really is very cool.  Heaps simpler than I imagined a
compat layer looking (though I guess it's not done yet).

* You should push some of the refactoring down into Project in the ant 1
tree, to make sub-classing easier.  In particular, it seems unfortunate to
have to override things like setProperty(), setNewProperty(),
setUserProperty(), and all that.  Much better if you could simply override a
doSetProperty(), a doGetProperty() and a doGetPropertyNames() (or whatever,
you get the idea).  This would be healthy for the ant 1 tree, and would help
isolate Ant1CompatProject from changes to Project.  Though I guess this
stuff is still in prototype mode.

* You should re-contextualise the project at the start of each task's
execute() method (that is, reset the m_context field).  This is because the
context for a task is in no way guaranteed to be the same object for every
task in a project (though it just happens to be at the moment).  Nor is
there any guarantee that a context will remain usable once Task.execute()
has returned.


Adam


--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message