Bug 359385 - [API] Add the ability to specify the deployed archiveName for Jars/projects defined in a classpath library
Summary: [API] Add the ability to specify the deployed archiveName for Jars/projects d...
Status: RESOLVED FIXED
Alias: None
Product: WTP Java EE Tools
Classification: WebTools
Component: jst.j2ee (show other bugs)
Version: 3.3   Edit
Hardware: PC Linux
: P3 enhancement with 1 vote (vote)
Target Milestone: 3.5   Edit
Assignee: Chuck Bridgham CLA
QA Contact: Chuck Bridgham CLA
URL:
Whiteboard: Maven PMC
Keywords: plan
Depends on:
Blocks: 407100
  Show dependency tree
 
Reported: 2011-09-29 05:41 EDT by Fred Bricon CLA
Modified: 2013-08-22 10:53 EDT (History)
3 users (show)

See Also:
stryker: pmc_approved? (david_williams)
stryker: pmc_approved? (raghunathan.srinivasan)
stryker: pmc_approved? (naci.dai)
stryker: pmc_approved? (neil.hauge)
stryker: pmc_approved? (kaloyan)
stryker: pmc_approved?
cbridgha: review+


Attachments
Add support for an archiveName classpath attribute (5.71 KB, patch)
2013-05-02 10:07 EDT, Fred Bricon CLA
no flags Details | Diff
Add support for an archiveName classpath attribute (5.33 KB, patch)
2013-05-02 10:15 EDT, Fred Bricon CLA
no flags Details | Diff
Add support for an archiveName classpath attribute (5.42 KB, patch)
2013-05-02 10:19 EDT, Fred Bricon CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fred Bricon CLA 2011-09-29 05:41:52 EDT
Build Identifier: 

m2e-wtp configures the Maven Classpath Library for export, when dealing with Web projects. When jars from a classpath library are exported /published, the original file name is used. 
When using pure maven, you have the possibility to export referenced jars under a different name. For instance, my web app references some-external-library-x.y.z.jar but I want to deploy it under WEB-INF/lib/some-external-library.jar instead.

Current workaround in m2e-wtp is to copy some-external-library-x.y.z.jar from the original local maven repository to a temporary location (project/target/some-external-library.jar), change the path directly in the classpath entry in the maven library, so that the source file name is the same as the deployed name. Not very elegant right?

What I would like to see is the ability for WTP to use an extra classpath attribute, such as deployedName="some-external-library.jar", that would be used during export/deployment on a server.
Even better, we could attach a IFileNameMappingStrategy implementation to the library itself. But that probably requires more changes, since it'd require some new API. 

Obviously, the same would go for projects (if they were to be supported)


Reproducible: Always
Comment 1 Fred Bricon CLA 2013-05-02 09:03:22 EDT
I have a patch that I tested with tomcat 7.0 and jboss as 7.1.1 : https://github.com/fbricon/webtools.javaee/compare/359385-archive-name

(or in git patch format https://github.com/fbricon/webtools.javaee/compare/359385-archive-name.patch)

I can attach it here, if you think it's good enough. Otherwise, comments are welcome. I couldn't figure out were to add Unit/Integration tests for that one. But I'm confident the patch is harmless as it doesn't change existing behavior.

Adding IClasspathDependencyConstants.CLASSPATH_ARCHIVENAME_ATTRIBUTE makes it an API change. This part could easily be ommitted from the patch, if that poses any problem.

I'd very much like that bug to be fixed for Kepler M7 as that would help m2e-wtp solve a number of file locking issues on windows (see bug 406173).
Comment 2 Rob Stryker CLA 2013-05-02 09:34:42 EDT
I have reviewed the patch, and it looks very safe. The addition of the constant does make it an API change, and thus requires PMC approval for m7. Even if the constant was not in an interface, it would still technically count as supported API since .classpath files with this flag would be expected to maintain their behaviour indefinitely.  So this must be treated as an API change. 

I vote +1.
Comment 3 Fred Bricon CLA 2013-05-02 10:07:48 EDT
Created attachment 230406 [details]
Add support for an archiveName classpath attribute

Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug" (requested by an adopter) please document it as such.  

m2e-wtp configures the Maven Classpath Library for export, when dealing with Web projects. When jars from a classpath library are exported /published, the original file name is used. 
When using pure maven, you have the possibility to export referenced jars under a different name. For instance, my web app references some-external-library-x.y.z.jar but I want to deploy it under WEB-INF/lib/some-external-library.jar instead. Because of the workaround explained below causes file handle leaks, a proper solution is needed.

Is there a work-around? If so, why do you believe the work-around is insufficient?  
 
Current workaround in m2e-wtp is to copy some-external-library-x.y.z.jar from the original local maven repository to a temporary location (project/target/some-external-library.jar), change the path directly in the classpath entry in the maven library, so that the source file name is the same as the deployed name. Unfortunately, this workaround causes file handle leaks on windows, under certain conditions. 

How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added?  
The fix was tested locally. No JUnit was added 

Give a brief technical overview. Who has reviewed this fix?  
The fix adds a new IClasspathDependencyConstants.CLASSPATH_ARCHIVENAME_ATTRIBUTE constant (org.eclipse.jst.component.archivename). Then ClasspathDependencyUtil.getArchiveName(entry) checks for the presence of that key in the classpath entry attributes. If the key is found, the value is returned as the entry's archive name, else the usual archive name is returned. 
The fix was reviewed by Rob Stryker.
 
What is the risk associated with this fix?
The risk is low. Existing behavior is unchanged when the new attribute is unused.
Comment 4 Fred Bricon CLA 2013-05-02 10:15:04 EDT
Created attachment 230407 [details]
Add support for an archiveName classpath attribute

new patch without the html garbage
Comment 5 Fred Bricon CLA 2013-05-02 10:19:27 EDT
Created attachment 230409 [details]
Add support for an archiveName classpath attribute

I seem to be unable to correctly attach a patch to BZ...sigh. New try.
Comment 6 Chuck Bridgham CLA 2013-05-02 10:36:29 EDT
approved
Comment 7 Rob Stryker CLA 2013-05-02 10:44:31 EDT
Not to belabor the point, but this is technically an api change ;)
Comment 8 Chuck Bridgham CLA 2013-05-02 13:34:30 EDT
Yes - thanks for following the process!   I approve its an api change, but non-breaking - and safe....
Comment 9 Carl Anderson CLA 2013-05-02 13:47:58 EDT
Removing the hotbug_request, as per WTP's hotbug policy.  I am also bumping the priority to P1, since this is deemed extremely important by the committers.
Comment 10 Rob Stryker CLA 2013-05-02 14:07:40 EDT
I've committed this, but, as usual, am not capable of releasing / tagging.
Comment 11 Fred Bricon CLA 2013-05-02 14:43:26 EDT
If there are plans to do a 3.4.next release, any chance this bugfix can be backported?
Comment 12 Fred Bricon CLA 2013-05-30 10:11:53 EDT
Chuck, this is already committed and available since Kepler M7.
I was wondering if a backport was in order.
Comment 13 Chuck Bridgham CLA 2013-05-30 10:49:25 EDT
We don't have plans on a new release, but do public patch builds from time to time...    We can nominate this for that.
Comment 14 Chuck Bridgham CLA 2013-08-22 10:53:33 EDT
We don't have plans to backport this fix...   already in the Kepler stream..  resolving for now.. please reopen if you have further plans.