You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Matt Bertolini <vi...@gmail.com> on 2014/12/18 05:18:21 UTC
Parse jar:file prefix to Resource
Hi,
I am writing some custom ant tasks and I want to support files inside of
zip/jar files. I have noticed that some ant tasks use the
jar:file:/path/to/a.jar!/path/in/jar/file.xml syntax but I can't seem to
get it work. How do I use this pattern in my tasks and map them to a
Resource object like FileResource, URLResource, etc. Thanks.
Matt Bertolini
Re: Parse jar:file prefix to Resource
Posted by Antoine Levy Lambert <an...@gmx.de>.
Hello Matt,
The ZipFileSet type is something that you can use.
if you put in your custom task something like void addZipFileSet(ZipFileSet zfs) {
}
this will match with your custom task looking like
<mycustomtask>
<zipfileset src=“some/foo/bar.jar”>
<include name=“foo/baz/*.class”/>
</zipfileset>
<!— possibly add several zip filesets —>
</mycustomtask>
You can also download the sources of Ant to see how Ant is written and piggyback on that.
Hope this helps,
Antoine
>
>
> ______________________________________________
>
>
>
>> Date: Wed, 17 Dec 2014 23:18:21 -0500
>> Subject: Parse jar:file prefix to Resource
>> From: viper2843@gmail.com
>> To: user@ant.apache.org
>>
>> Hi,
>>
>> I am writing some custom ant tasks and I want to support files inside of
>> zip/jar files. I have noticed that some ant tasks use the
>> jar:file:/path/to/a.jar!/path/in/jar/file.xml syntax but I can't seem to
>> get it work. How do I use this pattern in my tasks and map them to a
>> Resource object like FileResource, URLResource, etc. Thanks.
>>
>> Matt Bertolini
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: Parse jar:file prefix to Resource
Posted by Martin Gainty <mg...@hotmail.com>.
Matt
At the Directory Level: You can grab all the filtered jars you need with <archives> and <zips> and <restrict> tags e.g.
<copy todir="${target}">
<archives>
<zips>
<restrict>
<path path="${java.class.path}"/>
<name name="*.jar"/>
</restrict>
</zips>
</archives>
</copy>looking inside a jar ...i think it might be best to leverage JarFileIterator
javap JarFileIterator.class produces:
public class org.apache.tools.ant.taskdefs.optional.depend.JarFileIterator implements org.apache.tools.ant.taskdefs.optional.depend.ClassFileIterator {
public org.apache.tools.ant.taskdefs.optional.depend.JarFileIterator(java.io.InputStream) throws java.io.IOException;
public org.apache.tools.ant.taskdefs.optional.depend.ClassFile getNextClassFile();
}
so as you can see if you already have one file and get an InputStream you can pass InputStream to JarFileIterator(InputStream)
then setup an iterator and continously get the next Class File using ClassFile getNextClassFile() method
this is clumsy and assumes you have a InputStream ready to go the alternate strategy might be to grab the source:
put test input jar in a "known location" e.g. /temp folder
modify the source constructor so that ctor will always read the jar file located in /temp (instead of InputStream)
create some sort of exportable Collection (ArrayList?)
toss in a while loop which reads the Jar file contents and populates a public static ArrayList
in the end reference the ArrayList that was exported... to get the list of Class Files
Does anyone have any ideas to help Matt?
Buona Fortuna
Martin
______________________________________________
> Date: Wed, 17 Dec 2014 23:18:21 -0500
> Subject: Parse jar:file prefix to Resource
> From: viper2843@gmail.com
> To: user@ant.apache.org
>
> Hi,
>
> I am writing some custom ant tasks and I want to support files inside of
> zip/jar files. I have noticed that some ant tasks use the
> jar:file:/path/to/a.jar!/path/in/jar/file.xml syntax but I can't seem to
> get it work. How do I use this pattern in my tasks and map them to a
> Resource object like FileResource, URLResource, etc. Thanks.
>
> Matt Bertolini