Bug 31947 - War task should flatten files in <lib> element
Summary: War task should flatten files in <lib> element
Status: RESOLVED DUPLICATE of bug 4240
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.2
Hardware: Other other
: P2 enhancement with 4 votes (vote)
Target Milestone: 1.8.0
Assignee: Ant Notifications List
URL:
Keywords:
: 34830 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-10-28 21:17 UTC by Howard M. Lewis Ship
Modified: 2008-11-19 03:13 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Howard M. Lewis Ship 2004-10-28 21:17:51 UTC
When building a war file using the War task and the <lib> element, the files
specified by the <lib> should be automatically flattened as they are added to
the WAR file.

There is no reason to put a jar under WEB-INF/lib except to have it included in
the servlet classpath, but only files exactly inside WEB-INF/lib will be added.

In my build environment, I'm collecting a number of jar files spread over a few
different directories; the names of the JARs will be unique, but they are buried
one level deep (a structure based on the maven group id of the JAR).

Currenlty, I have to copy and flatten the files to a single directory and
include that.  This is somewhat haphazard I think and should be rolled directly
into the task.
Comment 1 Jose Alberto Fernandez 2004-10-29 09:58:41 UTC
Can't you use a mapper to flatten things if that is what you want?
Comment 2 Howard M. Lewis Ship 2004-10-29 10:51:11 UTC
Unless I'm missing something (entirely possible), the <mapper> functionality is
part of the Copy task, not the FileSet type.  The <lib> element of the War task
is a FileSet.
Comment 3 Matt Benson 2004-10-29 15:49:00 UTC
Right, no mapper, and no obvious/intuitive way to include one.  It's been a 
while since I've done webapps, WARs and so on, but I can't find any evidence 
that files stored in subdirectories of WEB-INF/lib would be used for anything.  
I think this may end up an entry in WHATSNEW under "Changes that could break 
older environments:" i.e. a bug for which our correct response is to break BC 
(highly unlikely in this case but theoretically so).
Comment 4 Jose Alberto Fernandez 2004-10-29 15:59:11 UTC
<mapper> is a generic concept. If <war/> does not support mappers in the 
different locations it should. I suggest you ask for them to be added.
But to request that <war/> be changed to start flattening is unreasonable.

There is no reason why my libraries cannot beorganized in several directories.
Even after deployment. Having a mapper will allow user to do whatever they may 
want. Actually, maybe the functionality should be added to <zipfileset/>

It will make a lot of sense. And you can always do the same as <lib/> using
a <zipfileset/>.

Comment 5 Dominique Devienne 2004-10-29 16:32:09 UTC
"but I can't find any evidence that files stored in subdirectories of WEB-
INF/lib would be used for anything"

Well, assuming it's expanded on disk and uses a "normal" URLClassLoader, yes, 
they would if any JARs in WEB-INF/lib had a Class-Path manifest entry pointing 
to them. --DD
Comment 6 Howard M. Lewis Ship 2004-10-29 16:40:04 UTC
I validated with Jetty (4.2.8) that the .jar files must be directly contained in
WEB-INF/lib.  I strongly doubt other servlet containers are more flexible and I
wouldn't doubt that the spec indicates that they should be directly contained.
Comment 7 Howard M. Lewis Ship 2004-10-29 16:41:33 UTC
Thanks for the pointer; the zipfileset is a good workaround for me that wasn't
obvious (to me).
Comment 8 Howard M. Lewis Ship 2004-10-29 16:50:04 UTC
Oh I see ... no that's not a workaround. No place to add a <mapper> to a
<zipfileset> (you were suggesting it).

I'm thiking that, in general, FileSets should support a nested Mapper.  Is this
feasible?
Comment 9 Alexey Solofnenko 2004-10-29 16:58:26 UTC
I agree with that. It would make my life easier too (for example with <sync> and multiple source filesets with different mappers).
Comment 10 Matt Benson 2004-10-29 17:07:07 UTC
Actually, on viewing the source you can see that <lib> actually IS a 
ZipFileSet; however its prefix attribute is explicitly set in War.  I can 
accept DD's argument here... albeit grudgingly.  ;)  Anyway, it really doesn't 
make a whole lot of sense add a <mapper> to <fileset>; it might make sense to 
add a <mapper> to <zipfileset>.  I haven't had enough sleep to think about the 
proper behavior for it right now though.  Also, if anyone can suggest a sane 
behavior for a <mapper> with regard to a plain <fileset> I'm all ears.

Howard:  I assume your <lib> entry has a dir attribute pointing to some 
directory, and you're including either the whole directory or "**/*.jar" or 
something.  Just checking, you do NOT know the names of the subdirectories 
ahead of time or you would just include multiple <lib> entries, correct?


Comment 11 Jose Alberto Fernandez 2004-10-29 17:32:55 UTC
<mapper>s talk about destinations. Since <filesets> are use for things that 
only read but do not write, this is not the right place for them.

On the other hand, <zipfileset>s are always written (into the Zipfile) hence 
it makes much more sense to have a mapper here.
Comment 12 Alexey Solofnenko 2004-10-29 17:35:24 UTC
It is a right place for them - they would create a virtual file system (view)
with file in correct places, so <copy>, <sync>, <war> would just copy files
from one file system into another.
Comment 13 Jose Alberto Fernandez 2004-10-29 17:43:31 UTC
What do you mean, that the files returned by the <fileset> will say they are 
in one place but they are actually comming from a different place? So when I 
find an error in some file, the class will write the wrong location because it 
thinks it is in a place where it is not?

Such thing will break 90% of the tasks that use <fileset>s. Most tasks do 
their own mapping given by its own rules (like javac). You cannt just change 
them any way you want and not expect concequences.

But I could agreed that we should have a more centralized concept for things 
that do read/write. Today read is expressed by <fileset> and write by <mapper>.
Much more tasks should support these two.
Comment 14 Alexey Solofnenko 2004-10-29 20:07:57 UTC
You are right. That would mean that some tasks will accept FileSet and some other tasks will accept VirtualFileSet and most ANT internal tasks (<copy>, <sync>, ...) will work just fine with virtual file sets. Plus it would also solve fileset/filelist differences.
Comment 15 Alexey Solofnenko 2004-10-29 20:09:33 UTC
when I start remembering to add newlines....

You are right. That would mean that some tasks will accept FileSet and some 
other tasks will accept VirtualFileSet and most ANT internal tasks (<copy>, <sync>, ...) 
will work just fine with virtual file sets. Plus it would also solve 
fileset/filelist differences.

Comment 16 Matt Benson 2004-10-29 20:23:12 UTC
Oh, no!  Not the virtual file debate again!  :)  Believe me, I was always PRO-
virtual files long before I became a committer... but I was forced to come to 
grips with the fact that Ant 1.x internals are just not what they would need to 
be to make this work.  :(
Comment 17 Alexey Solofnenko 2004-10-29 20:28:06 UTC
Is there ANT 2.0 in plans?
Comment 18 Alexey Solofnenko 2004-10-29 20:28:57 UTC
This bug just needs flatten="true" attribute for <lib> node.
Comment 19 Matt Benson 2004-10-29 21:00:00 UTC
Indeed that would solve this issue, but adding a <mapper> to <zipfileset> is 
potentially a more useful solution--i.e. it may prevent some other bugrep down 
the line.  Remains to be seen whether implementation is practical, however.  :)
Comment 20 Alexey Solofnenko 2004-10-29 21:26:30 UTC
It is dangerous, because it will be difficult to associate a mapper to 
a particular fileset. There are other filesets there, so unless you put 
a mapper within <lib> (a fileset!), it will create a confusion.
Comment 21 Matt Benson 2004-10-29 21:37:02 UTC
As stated above, the <lib> IS a <zipfileset>.  So adding the <mapper> to one 
adds it to the other.
Comment 22 Alexey Solofnenko 2005-05-10 02:02:36 UTC
*** Bug 34830 has been marked as a duplicate of this bug. ***
Comment 23 Herv 2007-05-29 10:05:01 UTC
Working on Maven Ant Tasks, flattening a fileset resolved by Maven would be a
great enhancement: see http://jira.codehaus.org/browse/MANTTASKS-39

I looked at o.a.t.a.tasks.War class:

public void addLib(ZipFileSet fs) {
        // We just set the prefix for this fileset, and pass it up.
        fs.setPrefix("WEB-INF/lib/");
        super.addFileset(fs);
    }

Instead of

// We just set the prefix for this fileset, and pass it up.
fs.setPrefix("WEB-INF/lib/");

I think

// We just set the full path for this fileset, and pass it up.
fs.setFullpath("WEB-INF/lib/");

would do what we are expecting.

WDYT?
Comment 24 Steve Loughran 2007-06-04 02:57:31 UTC
we havent been working on this as Ivy works differently...personally I think the
way to do it would be a new resource collection that includes mapping rules;
this could be reused more broadly than an inconsistent patch to one or two tasks..
Comment 25 Morten Lauritsen Khodabocus 2008-10-08 06:29:44 UTC
I can see that this is marked for "target milestone 1.8.0".

What exactly is going to be done?

I think adding a "flatten" attribute with default value "false" will have minimum impact on existing users, while providing an easy way out for those of us who have hierarchies that we don't really want in our "WEB-INF/lib"s.

I am not (by far) an ANT code contributor, so I don't know how hard this would be to implement - is the implementation of this feature already planned or would I increase the chances of it happening by diving into the ANT code and providing a fix?

Please note that not everybody use Ivy with ANT, it would be great to have a "pure" ANT solution for this problem.
Comment 26 Stefan Bodewig 2008-10-08 07:35:20 UTC
I can't say why Kev changed the target from unspecified to 1.8.0.

Sure it would help if a patch including tests was contributed, otherwise all people waiting for this feature simply have to wait until any committer feels like working on it, which doesn't seem to be too likely given the history of this report.
Comment 27 Stefan Bodewig 2008-11-19 03:13:14 UTC
svn trunk now contains a <mappedresources> collection that does the job.
From the manual

    <war destfile="${output}">
      <mappedresources>
        <restrict>
          <path path="${java.class.path}"/>
          <type type="file"/>
        </restrict>
        <chainedmapper>
          <flattenmapper/>
          <globmapper from="*" to="WEB-INF/lib/*"/>
        </chainedmapper>
      </mappedresources>
    </war>

this flattens all files from CLASSPATH and puts them into WEB-INF/lib

*** This bug has been marked as a duplicate of bug 4240 ***