You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Benjamin de Dardel <be...@gmail.com> on 2007/12/27 10:05:15 UTC

ProjectHelper : parsing from InputStream

Hi all,

I need to package ant files in a jar archive and then call these
ant files from the jar.

The ProjectHelperImpl class only uses an instance of File to parse
a file.

        Project project = new Project();
        ProjectHelperImpl helper = new ProjectHelperImpl();
        => helper.parse( project, new File( "build.xml" ) );
        project.init();
        project.executeTarget( "do" );

There are no possibilities to use an InputStream (from a jar for example) :

        JarFile jar = new JarFile( "myjar.jar" );
        ZipEntry xml = jar.getEntry( "build.xml" );
        InputStream stream = jar.getInputStream( xml );

        Project project = new Project();
        ProjectHelperImpl helper = new ProjectHelperImpl();
        => helper.parse( project, stream );
        project.init();
        project.executeTarget( "do" );

1: Should I copy and rewrite ProjectHelperImpl for my personal use
? Or is there another way (because I don't like to fork OpenSource code) ?
I notice that ProjectHelper2 class have an InputStream source which is
commented !!!

2: Do you need my contribution for refactoring helpers to accept
multiple sources ?

Best regards,
Benjamin de Dardel

Re: ProjectHelper : parsing from InputStream

Posted by Benjamin de Dardel <be...@gmail.com>.
Hi all,

Matt Benson a �crit :
> One concept that I had discussed with someone here
> (Kev?  Alexey?) was some kind of resource that would
> deliver a tempfile for another resource.  This might
> work in simple situations.  
I didn't expect that my question would re-open this discussion.
I think that it's possible to add some new sources without changing 
everything.

In class ProjectHelper2, there are some other sources : InputStream and 
InputSource, but they were commented.
As you can see in attachment, I implemented the InputStream one without 
changing the API.

For the basedir problem, the current directory seems to be use as 
default and it can be updated with project.setBaseDir method.

> It also occurs to me that
> certain resources might themselves implement
> ResourceFactory, e.g. files and urls, which can pretty
> easily return a relative file.  A buildfile specifying
> no basedir would, IMHO, seem to be fairly well
> represented by a FileResource that, as a
> ResourceFactory, would resolve relative paths against
> ".".  So that might provide some opportunities as
> well.
>
>   
Even if I'm interested in getting experience with ant, I don't have a 
global comprehension of the problem, as you have. So, I will follow this 
discussion and may be I will be abble to help you !

Regards,
Benjamin

> -Matt
>   

Re: AW: ProjectHelper : parsing from InputStream

Posted by Matt Benson <gu...@yahoo.com>.
--- Stefan Bodewig <bo...@apache.org> wrote:

> <Ja...@rzf.fin-nrw.de> writes:
> 
> >> -----Ursprüngliche Nachricht-----
> >> Von: Stefan Bodewig [mailto:bodewig@apache.org] 
> 
> >> The problem is a bit more complex than just
> allowing a different
> >> source.  The main problem are build files that do
> not specify a
> >> basedir attribute on the project tag since Ant
> then uses the directory
> >> holding the build file to resolve relative file
> references - which
> >> certainly doesn't work if it doesn't have a File
> reference pointing to
> >> the input.
> >
> >
> > Could the API require specifying the basedir?
> 
> It could.  Or instead require a ResourceFactory
> returning Resources
> that map to Files (like Matt suggests).
> 
> I really like the ResourceFactory idea but it can't
> be as generic as
> it sounds unless we change a lot of Ant tasks.
> 

True, I didn't think it through as far as you go
below.  :)

> Right now we need the basedir attribute to resolve
> relative file names
> for attribute setters that use the setFoo(File a)
> signature.
> 

Right, but all such _should_ be delegated to the
Project instance.  If not, sorry, can't help ya...

> If my build file doesn't contain any relative path
> at all, then there
> is no reason to set (or require) a basedir or a
> ResourceFactory at
> all.
> 

So would that be an error condition? 
IllegalStateException?

> If it does, then the resolved Resources must be
> Resources that can be
> turned into Files or I can't give the tasks what
> they are asking for.
> 
> The ResourceFactory approach would work great for
> setFoo(Resource a)
> attribute setters, but we don't haven them at all
> and we'd need to
> retrofit it into all existing tasks.
> 

One concept that I had discussed with someone here
(Kev?  Alexey?) was some kind of resource that would
deliver a tempfile for another resource.  This might
work in simple situations.  It also occurs to me that
certain resources might themselves implement
ResourceFactory, e.g. files and urls, which can pretty
easily return a relative file.  A buildfile specifying
no basedir would, IMHO, seem to be fairly well
represented by a FileResource that, as a
ResourceFactory, would resolve relative paths against
".".  So that might provide some opportunities as
well.

-Matt

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



      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping

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


Re: AW: ProjectHelper : parsing from InputStream

Posted by Stefan Bodewig <bo...@apache.org>.
<Ja...@rzf.fin-nrw.de> writes:

>> -----Ursprüngliche Nachricht-----
>> Von: Stefan Bodewig [mailto:bodewig@apache.org] 

>> The problem is a bit more complex than just allowing a different
>> source.  The main problem are build files that do not specify a
>> basedir attribute on the project tag since Ant then uses the directory
>> holding the build file to resolve relative file references - which
>> certainly doesn't work if it doesn't have a File reference pointing to
>> the input.
>
>
> Could the API require specifying the basedir?

It could.  Or instead require a ResourceFactory returning Resources
that map to Files (like Matt suggests).

I really like the ResourceFactory idea but it can't be as generic as
it sounds unless we change a lot of Ant tasks.

Right now we need the basedir attribute to resolve relative file names
for attribute setters that use the setFoo(File a) signature.

If my build file doesn't contain any relative path at all, then there
is no reason to set (or require) a basedir or a ResourceFactory at
all.

If it does, then the resolved Resources must be Resources that can be
turned into Files or I can't give the tasks what they are asking for.

The ResourceFactory approach would work great for setFoo(Resource a)
attribute setters, but we don't haven them at all and we'd need to
retrofit it into all existing tasks.

Stefan

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


Re: ProjectHelper : parsing from InputStream

Posted by Matt Benson <gu...@yahoo.com>.
Wait:  I think Gilles has just given me the spark I
needed...  ProjectHelper2 simply uses instanceof
checks to see what it can read from.  What if we
accept a ResourceFactory as a source, and request
Main.DEFAULT_BUILD_FILENAME (build.xml) for the
Resource to parse.  Then it's the implementation's
responsiblity to know how to provide other resources
"relative to the buildfile."

-Matt

--- Gilles Scokart <gs...@gmail.com> wrote:

> But If you want to  pass an input stream as
> parameter, it is to allow to
> read build file from an other source than a file. 
> In those case, there is
> not necessarily a File basedir, but it can be
> something else.
> 
> Maybe passing an URL instead of a File would be more
> flexible?
> 
> Gilles
> 
> 2008/1/10, Jan.Materne@rzf.fin-nrw.de
> <Ja...@rzf.fin-nrw.de>:
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Stefan Bodewig [mailto:bodewig@apache.org]
> > > Gesendet: Donnerstag, 10. Januar 2008 06:10
> > > An: dev@ant.apache.org
> > > Betreff: Re: ProjectHelper : parsing from
> InputStream
> > >
> > > "Benjamin de Dardel"
> <be...@gmail.com> writes:
> > >
> > > > 1: Should I copy and rewrite ProjectHelperImpl
> for my personal use
> > > > ?
> > >
> > > You can do that, if you want to 8-)
> > >
> > > > Or is there another way
> > >
> > > No, there isn't.  See below.
> > >
> > > > 2: Do you need my contribution for refactoring
> helpers to accept
> > > > multiple sources ?
> > >
> > > We've started discussing this more than once but
> never came to a
> > > solution that ended up in svn.  If you want to
> help us not dropping
> > > the ball, you are welcome.
> > >
> > > The problem is a bit more complex than just
> allowing a different
> > > source.  The main problem are build files that
> do not specify a
> > > basedir attribute on the project tag since Ant
> then uses the directory
> > > holding the build file to resolve relative file
> references - which
> > > certainly doesn't work if it doesn't have a File
> reference pointing to
> > > the input.
> >
> >
> > Could the API require specifying the basedir?
> >
> >   /**
> >    * Parses the given buildfile.
> >    * @param is InputStream providing the content
> of the buildfile
> >    * @param basedir The (absolute) basedir for use
> in the project
> >    *        if the parsed buildfile doesnt specify
> an absolute
> >    *        path.
> >    */
> >   parse(InputStream is, File basedir);
> >
> >   is(<project>) + basedir="C:/temp" --> c:/temp
> >   is(<project basedir=".") + basedir="C:/temp" -->
> c:/temp
> >   is(<project basedir="/") + basedir="C:/temp" -->
> C:/
> >   is(<project basedir="D:">) + basedir="C:/temp"
> --> D:
> >
> >   is(<project basedir="D:">) + basedir=null --> D:
> >   is(<project basedir=".">) + basedir=null -->
> exception
> >   is(<project basedir="/">) + basedir=null -->
> >     on windows: root directory of the system drive
> >     on unix   : root directory '/'
> >   is(<project>) + basedir=null --> exception
> >
> >
> >
> > Jan
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> dev-unsubscribe@ant.apache.org
> > For additional commands, e-mail:
> dev-help@ant.apache.org
> >
> >
> 



      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

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


Re: ProjectHelper : parsing from InputStream

Posted by Gilles Scokart <gs...@gmail.com>.
But If you want to  pass an input stream as parameter, it is to allow to
read build file from an other source than a file.  In those case, there is
not necessarily a File basedir, but it can be something else.

Maybe passing an URL instead of a File would be more flexible?

Gilles

2008/1/10, Jan.Materne@rzf.fin-nrw.de <Ja...@rzf.fin-nrw.de>:
>
> > -----Ursprüngliche Nachricht-----
> > Von: Stefan Bodewig [mailto:bodewig@apache.org]
> > Gesendet: Donnerstag, 10. Januar 2008 06:10
> > An: dev@ant.apache.org
> > Betreff: Re: ProjectHelper : parsing from InputStream
> >
> > "Benjamin de Dardel" <be...@gmail.com> writes:
> >
> > > 1: Should I copy and rewrite ProjectHelperImpl for my personal use
> > > ?
> >
> > You can do that, if you want to 8-)
> >
> > > Or is there another way
> >
> > No, there isn't.  See below.
> >
> > > 2: Do you need my contribution for refactoring helpers to accept
> > > multiple sources ?
> >
> > We've started discussing this more than once but never came to a
> > solution that ended up in svn.  If you want to help us not dropping
> > the ball, you are welcome.
> >
> > The problem is a bit more complex than just allowing a different
> > source.  The main problem are build files that do not specify a
> > basedir attribute on the project tag since Ant then uses the directory
> > holding the build file to resolve relative file references - which
> > certainly doesn't work if it doesn't have a File reference pointing to
> > the input.
>
>
> Could the API require specifying the basedir?
>
>   /**
>    * Parses the given buildfile.
>    * @param is InputStream providing the content of the buildfile
>    * @param basedir The (absolute) basedir for use in the project
>    *        if the parsed buildfile doesnt specify an absolute
>    *        path.
>    */
>   parse(InputStream is, File basedir);
>
>   is(<project>) + basedir="C:/temp" --> c:/temp
>   is(<project basedir=".") + basedir="C:/temp" --> c:/temp
>   is(<project basedir="/") + basedir="C:/temp" --> C:/
>   is(<project basedir="D:">) + basedir="C:/temp" --> D:
>
>   is(<project basedir="D:">) + basedir=null --> D:
>   is(<project basedir=".">) + basedir=null --> exception
>   is(<project basedir="/">) + basedir=null -->
>     on windows: root directory of the system drive
>     on unix   : root directory '/'
>   is(<project>) + basedir=null --> exception
>
>
>
> Jan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

AW: ProjectHelper : parsing from InputStream

Posted by Ja...@rzf.fin-nrw.de.
> -----Ursprüngliche Nachricht-----
> Von: Stefan Bodewig [mailto:bodewig@apache.org] 
> Gesendet: Donnerstag, 10. Januar 2008 06:10
> An: dev@ant.apache.org
> Betreff: Re: ProjectHelper : parsing from InputStream
> 
> "Benjamin de Dardel" <be...@gmail.com> writes:
> 
> > 1: Should I copy and rewrite ProjectHelperImpl for my personal use
> > ?
> 
> You can do that, if you want to 8-)
> 
> > Or is there another way
> 
> No, there isn't.  See below.
> 
> > 2: Do you need my contribution for refactoring helpers to accept
> > multiple sources ?
> 
> We've started discussing this more than once but never came to a
> solution that ended up in svn.  If you want to help us not dropping
> the ball, you are welcome.
> 
> The problem is a bit more complex than just allowing a different
> source.  The main problem are build files that do not specify a
> basedir attribute on the project tag since Ant then uses the directory
> holding the build file to resolve relative file references - which
> certainly doesn't work if it doesn't have a File reference pointing to
> the input.


Could the API require specifying the basedir?

  /**
   * Parses the given buildfile.
   * @param is InputStream providing the content of the buildfile
   * @param basedir The (absolute) basedir for use in the project
   *        if the parsed buildfile doesnt specify an absolute
   *        path. 
   */
  parse(InputStream is, File basedir);

  is(<project>) + basedir="C:/temp" --> c:/temp
  is(<project basedir=".") + basedir="C:/temp" --> c:/temp
  is(<project basedir="/") + basedir="C:/temp" --> C:/
  is(<project basedir="D:">) + basedir="C:/temp" --> D:

  is(<project basedir="D:">) + basedir=null --> D:
  is(<project basedir=".">) + basedir=null --> exception
  is(<project basedir="/">) + basedir=null --> 
    on windows: root directory of the system drive
    on unix   : root directory '/'
  is(<project>) + basedir=null --> exception



Jan

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


Re: ProjectHelper : parsing from InputStream

Posted by Stefan Bodewig <bo...@apache.org>.
"Benjamin de Dardel" <be...@gmail.com> writes:

> 1: Should I copy and rewrite ProjectHelperImpl for my personal use
> ?

You can do that, if you want to 8-)

> Or is there another way

No, there isn't.  See below.

> 2: Do you need my contribution for refactoring helpers to accept
> multiple sources ?

We've started discussing this more than once but never came to a
solution that ended up in svn.  If you want to help us not dropping
the ball, you are welcome.

The problem is a bit more complex than just allowing a different
source.  The main problem are build files that do not specify a
basedir attribute on the project tag since Ant then uses the directory
holding the build file to resolve relative file references - which
certainly doesn't work if it doesn't have a File reference pointing to
the input.

Stefan

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