You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Gilles Querret <g....@riverside-software.fr> on 2021/03/08 12:14:16 UTC

Selectors not executed on Zipfileset

Hello,


I think I've found an issue with selectors which are not executed on
Zipfileset. Here is a very small test case to reproduce the issue:

<project>
  <mkdir dir="target/d2" />
  <mkdir dir="target/d3" />

  <mkdir dir="src" />
  <echo file="src/test1.txt" message="abc" />
  <echo file="src/test2.txt" message="def" />
  <echo file="src/test3.txt" message="hij" />
  <zip destFile="target/f1.zip">
    <fileset dir="src" />
  </zip>

  <echo message="Standard fileset" />
  <copy toDir="target/d2">
    <fileset dir="src">
      <contains text="def" />
    </fileset>
  </copy>

  <echo message="ZIP fileset" />
  <copy toDir="target/d3">
    <zipfileset src="target/f1.zip">
      <contains text="def" />
    </zipfileset>
  </copy>
</project>
When executed, the first copy task only copies one file (test2.txt which
contains def), but the second copy task copies all three files. My original
problem was coming from the <different> selector, also not executed on
zipfileset, but it was easier to reproduce with <contains>.
Is that a known issue ? Or just the expected behavior ?

Gilles


-- 
Gilles QUERRET

Riverside Software
91 chemin des églantiers • 69440 Taluyers • France
Mob : +33 662.525.532

Re: Selectors not executed on Zipfileset

Posted by Stefan Bodewig <bo...@apache.org>.
On 2021-03-15, Gilles Querret wrote:

> I've used the <contains> selector in this example, but my use case is
> in fact similar to the <different> selector, where a comparison is
> done on both the source file and the target file. I assume that this
> is not possible within the restrict element ?

You are right, you cannot use it for non-file resources.

Every FileSelector is a ResourceSelector, so technically Ant might allow
such a construct, but it wouldn't work - as <different> restricts itself
to file-system resources.

It would probably be possible to generalize <different> to arbitrary
resources, but this hasn't happened so far.

If we were to allow a non-file-system target (like a target
ResourceCollection) the lookup "find the target resource if it exists"
could become expensive as our ResourceCollections are really only
iterators - so we'd do a linear search inside of the target
collection. In the case of a target ZIP archive, we'd re-open the ZIP
and scan it for each and every resource encountered by the selector..

Stefan

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


Re: Selectors not executed on Zipfileset

Posted by Gilles Querret <g....@riverside-software.fr>.
On Sat, Mar 13, 2021 at 1:03 PM Stefan Bodewig <bo...@apache.org> wrote:

> On 2021-03-08, Gilles Querret wrote:
>
> > I think I've found an issue with selectors which are not executed on
> > Zipfileset. Here is a very small test case to reproduce the issue:
>
> The selectors that can be nested directly into a fileset (and this into
> a zipfileset which inherits the behavior) are FileSelectors that can
> only be applied to real files. For non-File resources you'd need
> ResourceSelectors and they are not directly supported as nested elements
> of the zipfileset - rather you'd wrap the whole thing into a <restrict>
> container.
>
>
Thank you Stefan for the explanation ! I've used the <contains> selector in
this example, but my use case is in fact similar to the <different>
selector, where a comparison is done on both the source file and the target
file. I assume that this is not possible within the restrict element ?

Gilles
-- 
Gilles QUERRET

Riverside Software
91 chemin des églantiers • 69440 Taluyers • France
Mob : +33 662.525.532

Re: Selectors not executed on Zipfileset

Posted by Stefan Bodewig <bo...@apache.org>.
On 2021-03-08, Gilles Querret wrote:

> I think I've found an issue with selectors which are not executed on
> Zipfileset. Here is a very small test case to reproduce the issue:

The selectors that can be nested directly into a fileset (and this into
a zipfileset which inherits the behavior) are FileSelectors that can
only be applied to real files. For non-File resources you'd need
ResourceSelectors and they are not directly supported as nested elements
of the zipfileset - rather you'd wrap the whole thing into a <restrict>
container.

I.e instead of

>   <copy toDir="target/d3">
>     <zipfileset src="target/f1.zip">
>       <contains text="def" />
>     </zipfileset>
>   </copy>

you use

   <copy toDir="target/d3">
     <restrict>
       <zipfileset src="target/f1.zip"/>
       <contains text="def" />
     </restrict>
   </copy>

This could and should be documented more clearly. I'll try to do so.

Stefan

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


Re: Selectors not executed on Zipfileset

Posted by Gilles Querret <g....@riverside-software.fr>.
Hello,


I've ran some tests and I confirm that selectors are not executed on
ZipFilesets (at least in the copy task). Here is what happens:
* In Copy.java:490 (
https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/taskdefs/Copy.java#L490
), a DirectoryScanner is created when using a standard FileSet. This
DirectoryScanner will then execute selectors at line 1505 (
https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/DirectoryScanner.java#L1505
)
* However, a different behavior happens with ZipFileset (in Copy.java line
515
https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/taskdefs/Copy.java#L515
), where the resource is directly added to the list :
https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/taskdefs/Copy.java#L557

Is that specific to the copy task ? Or do all other tasks behave
identically ? And don't you think that selectors should be executed on
non-filesystem filesets ?

Gilles

On Mon, Mar 8, 2021 at 1:14 PM Gilles Querret <
g.querret@riverside-software.fr> wrote:

> Hello,
>
>
> I think I've found an issue with selectors which are not executed on
> Zipfileset. Here is a very small test case to reproduce the issue:
>
> <project>
>   <mkdir dir="target/d2" />
>   <mkdir dir="target/d3" />
>
>   <mkdir dir="src" />
>   <echo file="src/test1.txt" message="abc" />
>   <echo file="src/test2.txt" message="def" />
>   <echo file="src/test3.txt" message="hij" />
>   <zip destFile="target/f1.zip">
>     <fileset dir="src" />
>   </zip>
>
>   <echo message="Standard fileset" />
>   <copy toDir="target/d2">
>     <fileset dir="src">
>       <contains text="def" />
>     </fileset>
>   </copy>
>
>   <echo message="ZIP fileset" />
>   <copy toDir="target/d3">
>     <zipfileset src="target/f1.zip">
>       <contains text="def" />
>     </zipfileset>
>   </copy>
> </project>
> When executed, the first copy task only copies one file (test2.txt which
> contains def), but the second copy task copies all three files. My original
> problem was coming from the <different> selector, also not executed on
> zipfileset, but it was easier to reproduce with <contains>.
> Is that a known issue ? Or just the expected behavior ?
>
> Gilles
>
>
> --
> Gilles QUERRET
>
> Riverside Software
> 91 chemin des églantiers • 69440 Taluyers • France
> Mob : +33 662.525.532
>


-- 
Gilles QUERRET

Riverside Software
91 chemin des églantiers • 69440 Taluyers • France
Mob : +33 662.525.532