You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Adam Jack <aj...@TrySybase.com> on 2003/06/03 16:25:19 UTC

Custom Path/FileSet types

I have a custom task that is currently implemented to generate
named/referencable Path & FileSet elements as it's output. The "user" of the
task is expected to know the refid's of the constructs this task creates.
This works, but seems a bit tad convoluted. The idea has arisen to re-work
this task as Path and/or FileSets.

[Basically the task (or soon to be type) takes a "project name" as input,
and downloads/returns the latest list of JARs for that project. The user
might wish to compile against those JARs, or copy them to a distribution, or
...]

Looking at the ant source code FileSet (with AbstractFileSet) seems quite
doable [clearly it is already subclassed], and Path.PathElement appear
either simpler, or figureoutable. That said, I don't know the concepts
behind "custom types" and http://ant.apache.org/manual/developlist.html
doesn't seem to have guidance for types.

Some questions:

1) Does what I am doing make sense as types verses tasks? What are the pros
and cons of each?
2) Can one construct a Path from a FileSet? [Meaning, do I need to write
code for both, or ought
I suspect I need a singleton factory to create my types,
3) I suspect I'll have a singleton factory (of sorts) to create my
constructs. That entity will probably want some per VM or per project
configuration (or perhaps not a real singleton). I see I can access the
project, so  I can access properties, but are there helpers for per project
instances? Do I need to roll my own?
4) How ought I handle logging? Can types log? Logging seems attached to the
Task, not ProjectComponent. If not, how might user tasks report debugging
information for types?
5) If I create a custom FileSet (say) can I add it to anything that takes a
FileSet (because I am a sub-class) or does the "container" need to
understand the XML tag? I.e. can I add <mypathelement to <classpath?

Some deeper ones (which I might just have to figure out from the code,
unless somebody is feeling overly generous w/ insight):

1) How do I figure out what introspection can do for me, in terms of
constructors? Looking at ZipFileSet I see a bunch of constructors, but I
don't really know how they map to the XML users can provide.
2) How do I get inside FileSet and AbstractFileSet? How can I determine what
methods I must provide, and what ones I can call? How do I select between
the two?
3) I see a bunch of helper methods that are getX(Project p) where a
ProjectComponent resolves answers based on itself within a project.
4) If I don't want PatternSets, do I need FileList not FileSet? Does this
limit what users can pass this to? Why do these two exist, what is the
reason for them not being able to be the same thing?

Thanks in advance for you assistance.

regards,

Adam
--
<http://www.try.sybase.com>
Experience Sybase Technology ...


Re: Custom Path/FileSet types

Posted by peter reilly <pe...@corvil.com>.
On Tuesday 03 June 2003 18:37, Adam Jack wrote:
> pros
>
> 	> and cons of each?
>
> 	It depends....,  It may be usefull to be both. In your case it looks like
> 	it should be a datatype.
>
> If I go down to DataType, aren't I cutting myself off from this being
> passed into existing tasks?

Currently yes. 

>
> 	> 3) I suspect I'll have a singleton factory (of sorts) to create my
> 	> constructs. That entity will probably want some per VM or per project
> 	> configuration (or perhaps not a real singleton). I see I can access the
> 	> project, so  I can access properties, but are there helpers for per
>
> project
>
> 	> instances? Do I need to roll my own?
>
> 	You should not use a singleton factory. A number of <typedefs/> should
> 	be enough.
>
> Not sure I follow that, but then I probably mis-explained my intentions (or
> just plain used the wrong word). Making an analogy --- I see the things I
> create as 'File Handles', and I need to create a 'File Sub-System' to
> create them (and that is heavier weight.) I need to configure that once
> (knowledge of remote repositories, etc) and then these "file references"
> can be found/downloaded/reference much easier. That clearer? Any concept
> like that exist?

I am not sure I follow. Ant uses references (id="x") to store bits of
information to be used later, maybe you could use that.

>
> 	> 4) How ought I handle logging? Can types log? Logging seems attached to
>
> the
>
> 	> Task, not ProjectComponent. If not, how might user tasks report
> 	> debugging information for types?
>
> 	A project componet has a setProject(Project) method that gets called when
> ant
> 	creates the object. Use project#log() for logging.
>
> Doh, didn't see logging down there.
>
> 	> 5) If I create a custom FileSet (say) can I add it to anything that
> 	> takes
>
> a
>
> 	> FileSet (because I am a sub-class) or does the "container" need to
> 	> understand the XML tag? I.e. can I add <mypathelement to <classpath?
>
> 	There is work ongoing that will allow you to do this. In fact in the
> current
> 	nightly build there is initial support for adding custom paths to the
> path.
>
> I am game for nightly, can you elaborate?

With the nightly one can do the following:

  <typedef name="mypath" classname="acme.MyPath"/>
  <path id="id.path">
    <mypath path="build.xml"/>
  </path>

see
http://issues.apache.org/bugzilla/show_bug.cgi?id=19897
for some more details ;-)

Peter


RE: Classpath construction (was Custom Path/FileSet types)

Posted by Adam Jack <aj...@TrySybase.com>.
Ever looked at Gump? It is what I use for inter project dependencies:

	http://jakarta.apache.org/gump.

I am not sure what you are attempting (deep inside the internal of ant) is
worth your investment when other are already trying it outside of ant.

regards

Adam
-----Original Message-----
From: Tim Gordon [mailto:tim.gordon@allustra.com]
Sent: Wednesday, June 04, 2003 2:31 AM
To: Ant Users List
Cc: ajack@trysybase.com; peter.reilly@corvil.com
Subject: Classpath construction (was Custom Path/FileSet types)


Hi

I'm having a horrible time trying to use ANT to construct a normalised
classpath based on the contribution of multiple projects - that is, the code
compiled in it and the jars upon which it depends.

Just to make things interesting, the project dependencies are resolved by
walking a graph:

the 'suite' project depends on 'projectA', 'projectB' and 'projectC', all of
which in turn depend on the 'core' project. Reading Adam Jack's original
message, I thought his proposal for a specialised FileSet which could return
a set of paths, jars, etc based off some kind of custom directive sounded
like just what I needed.

Then Peter Reilly suggested that there's already stuff in the CVS head for
ANT to do this.

I'm currently already using the import functionality (rudimentary, but seems
to be working) so I'm already using the head of CVS - what's all this about
'adding custom paths to the path'?

Thanks

Tim


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Classpath construction (was Custom Path/FileSet types)

Posted by Tim Gordon <ti...@allustra.com>.
Hi

I'm having a horrible time trying to use ANT to construct a normalised
classpath based on the contribution of multiple projects - that is, the code
compiled in it and the jars upon which it depends.

Just to make things interesting, the project dependencies are resolved by
walking a graph:

the 'suite' project depends on 'projectA', 'projectB' and 'projectC', all of
which in turn depend on the 'core' project. Reading Adam Jack's original
message, I thought his proposal for a specialised FileSet which could return
a set of paths, jars, etc based off some kind of custom directive sounded
like just what I needed.

Then Peter Reilly suggested that there's already stuff in the CVS head for
ANT to do this.

I'm currently already using the import functionality (rudimentary, but seems
to be working) so I'm already using the head of CVS - what's all this about
'adding custom paths to the path'?

Thanks

Tim


RE: Custom Path/FileSet types

Posted by Adam Jack <aj...@TrySybase.com>.
peter reilly [mailto:peter.reilly@corvil.com] wrote:

	I'll attempt to answer some of these.

Thanks, I appreciate that.

	First there is a big difference beween path and fileset.
	Path is a lot nicer to use, and can hold more
	files but fileset is used by more
	tasks that path.

Ok, thanks for that insight.

	Second, do not do things in the constructor - an empty
	constructor is best. Use set/add methods to set/add things.

Yup, works for me, I try to have lightweight constructors (and especially
none w/ content that throws exception that I might want to catch), I'll go
w/ empty...


	>
	> 1) Does what I am doing make sense as types verses tasks? What are the
pros
	> and cons of each?

	It depends....,  It may be usefull to be both. In your case it looks like
	it should be a datatype.

If I go down to DataType, aren't I cutting myself off from this being passed
into existing tasks?

	> 3) I suspect I'll have a singleton factory (of sorts) to create my
	> constructs. That entity will probably want some per VM or per project
	> configuration (or perhaps not a real singleton). I see I can access the
	> project, so  I can access properties, but are there helpers for per
project
	> instances? Do I need to roll my own?

	You should not use a singleton factory. A number of <typedefs/> should
	be enough.

Not sure I follow that, but then I probably mis-explained my intentions (or
just plain used the wrong word). Making an analogy --- I see the things I
create as 'File Handles', and I need to create a 'File Sub-System' to create
them (and that is heavier weight.) I need to configure that once (knowledge
of remote repositories, etc) and then these "file references" can be
found/downloaded/reference much easier. That clearer? Any concept like that
exist?

	> 4) How ought I handle logging? Can types log? Logging seems attached to
the
	> Task, not ProjectComponent. If not, how might user tasks report debugging
	> information for types?

	A project componet has a setProject(Project) method that gets called when
ant
	creates the object. Use project#log() for logging.

Doh, didn't see logging down there.

	> 5) If I create a custom FileSet (say) can I add it to anything that takes
a
	> FileSet (because I am a sub-class) or does the "container" need to
	> understand the XML tag? I.e. can I add <mypathelement to <classpath?

	There is work ongoing that will allow you to do this. In fact in the
current
	nightly build there is initial support for adding custom paths to the path.

I am game for nightly, can you elaborate?

Thanks for your help.

regards

Adam


Re: Custom Path/FileSet types

Posted by peter reilly <pe...@corvil.com>.
I'll attempt to answer some of these.

First there is a big difference beween path and fileset.
Path is a lot nicer to use, and can hold more
files but fileset is used by more
tasks that path.

Second, do not do things in the constructor - an empty
constructor is best. Use set/add methods to set/add things.


On Tuesday 03 June 2003 15:25, Adam Jack wrote:
> I have a custom task that is currently implemented to generate
> named/referencable Path & FileSet elements as it's output. The "user" of
> the task is expected to know the refid's of the constructs this task
> creates. This works, but seems a bit tad convoluted. The idea has arisen to
> re-work this task as Path and/or FileSets.
>
> [Basically the task (or soon to be type) takes a "project name" as input,
> and downloads/returns the latest list of JARs for that project. The user
> might wish to compile against those JARs, or copy them to a distribution,
> or ...]
>
> Looking at the ant source code FileSet (with AbstractFileSet) seems quite
> doable [clearly it is already subclassed], and Path.PathElement appear
> either simpler, or figureoutable. That said, I don't know the concepts
> behind "custom types" and http://ant.apache.org/manual/developlist.html
> doesn't seem to have guidance for types.
>
> Some questions:
>
> 1) Does what I am doing make sense as types verses tasks? What are the pros
> and cons of each?

It depends....,  It may be usefull to be both. In your case it looks like
it should be a datatype.

> 2) Can one construct a Path from a FileSet? [Meaning, do I need to write
> code for both, or ought
> I suspect I need a singleton factory to create my types,

one can use addFileSet() to a path.

> 3) I suspect I'll have a singleton factory (of sorts) to create my
> constructs. That entity will probably want some per VM or per project
> configuration (or perhaps not a real singleton). I see I can access the
> project, so  I can access properties, but are there helpers for per project
> instances? Do I need to roll my own?

You should not use a singleton factory. A number of <typedefs/> should
be enough.

> 4) How ought I handle logging? Can types log? Logging seems attached to the
> Task, not ProjectComponent. If not, how might user tasks report debugging
> information for types?

A project componet has a setProject(Project) method that gets called when ant
creates the object. Use project#log() for logging.

> 5) If I create a custom FileSet (say) can I add it to anything that takes a
> FileSet (because I am a sub-class) or does the "container" need to
> understand the XML tag? I.e. can I add <mypathelement to <classpath?

There is work ongoing that will allow you to do this. In fact in the current
nightly build there is initial support for adding custom paths to the path.

>
> Some deeper ones (which I might just have to figure out from the code,
> unless somebody is feeling overly generous w/ insight):
>
> 1) How do I figure out what introspection can do for me, in terms of
> constructors? Looking at ZipFileSet I see a bunch of constructors, but I
> don't really know how they map to the XML users can provide.

The introspection does some work on constructors - but it is FAR better
to use the empty constructor.

> 2) How do I get inside FileSet and AbstractFileSet? How can I determine
> what methods I must provide, and what ones I can call? How do I select
> between the two?
> 3) I see a bunch of helper methods that are getX(Project p) where a
> ProjectComponent resolves answers based on itself within a project.
> 4) If I don't want PatternSets, do I need FileList not FileSet? Does this
> limit what users can pass this to? Why do these two exist, what is the
> reason for them not being able to be the same thing?
>
> Thanks in advance for you assistance.
>
> regards,
>
> Adam

Peter.