Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 325733

Summary: Files linked in .component are not correctly deployed
Product: [WebTools] WTP Java EE Tools Reporter: Fred Bricon <fbricon>
Component: jst.j2eeAssignee: Rob Stryker <stryker>
Status: RESOLVED FIXED QA Contact: Chuck Bridgham <cbridgha>
Severity: normal    
Priority: P3 CC: ccc, gregory.amerson, jasonpet, vvandens
Version: 3.2Flags: cbridgha: review+
Target Milestone: 3.3.2   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
Test project
none
Patch for this change
none
An additional patch on top of the previous none

Description Fred Bricon CLA 2010-09-20 07:04:11 EDT
Build Identifier: Helios, WTP 3.1.2

Hi,

while trying to fix https://issues.sonatype.org/browse/MNGECLIPSE-2357 in m2eclipse-wtp, I've found an inconsistent behavior between export and deployment of linked files in org.eclipse.wst.common.component. Having :
  
 <wb-resource deploy-path="/META-INF/web.xml" source-path="/etc/resources/custom-web.xml"/>  

when exporting the web project as a war file, /etc/resources/custom-web.xml is correctly exported as /META-INF/web.xml. However, when deploying the workspace project to a Tomcat (6/7) or JBoss 5.1 server, the file is deployed as /META-INF/custom-web.xml

This is not restricted to web projects, doing the same thing for connector projects and ra.xml yields the same outcome.

I would understand that mapping files to a deploy-path that is not a directory may not be supported right now (the fact that export works would be a bug rather than a feature), but I believe export and deployment behaviors should be consistent, especially after all the refactoring Rob's done the last few months.

Reproducible: Always

Steps to Reproduce:
1.Create a web project (create the deployment descriptor)
2.Move WebContent/WEB-INF/web.xml to /etc/resources/custom-web.xml
3.Add  <wb-resource deploy-path="/META-INF/web.xml" source-path="/etc/resources/custom-web.xml"/>  to org.eclipse.wst.common.component (after the other <wb-resource> nodes)
4. deploy the project to a tomcat instance (or any other server)
5. Check the existence of /META-INF/web.xml under the deployed project. Its content should correspond to custom-web.xml
Comment 1 Fred Bricon CLA 2010-09-20 07:07:02 EDT
Created attachment 179236 [details]
Test project

- Import the CustomWebXml project, 
- deploy it to a server, 
- check the deployment descriptor is wrongly deployed.
Comment 2 Fred Bricon CLA 2010-09-20 07:20:15 EDT
(In reply to comment #0)
> Build Identifier: Helios, WTP 3.1.2

Oops, read WTP 3.2.1 instead.
Comment 3 Carl Anderson CLA 2010-09-20 12:27:31 EDT
Assigning to Rob for initial investigation.
Comment 4 Rob Stryker CLA 2010-09-20 13:33:37 EDT
As far as I know, there are no unit tests demonstrating this as a feature. I personally have never seen that usage before and so was not aware it was a feature. This explains why it is not functioning in the deployment model. I am not sure if it ever worked before, but it'd be interesting to see it tested on previous versions to see if the syntax worked then. 

Anyway, I'd like to see some discussion as to whether this would be a new feature or fixing a regression. It obviously applies.
Comment 5 Fred Bricon CLA 2010-09-20 17:23:59 EDT
Rob, 

I never tried that before either, just trying to implement a new feature in m2eclipse-wtp.
I'm pretty sure the fact that export is working is an accident -good for me-, I just want to emphasize the behavior discrepancy between export and deployment. I thought that was not supposed to happen anymore.

Now I really don't care if this issue is turned into a feature request. I don't see anything blocking here, 
m2eclipse users will still be able to deploy custom web.xml files, as long as they're named web.xml
Comment 6 Rob Stryker CLA 2010-09-20 22:37:53 EDT
fred:

I'm trying in the 3.2.x codebase and I can't get the file to be included at all in this fashion ;) I notice you're using WTP 3.1.2. In WTP 3.1.2, the flattened virtual component model doesn't exist. I believe this was added in wtp 3.2.0.  So unified behaviour should be more observable in wtp 3.2.0. 

However, as I said, in wtp 3.2.0, I don't see the file deployed at all so far (though it may just be a side-effect of some paths I'm using. I haven't figured it out yet despite spending a while tracing.)

Give it a go on wtp 3.2 and let me know what you find.
Comment 7 Fred Bricon CLA 2010-09-21 03:21:40 EDT
(In reply to comment #6)
> I notice you're using WTP 3.1.2. 
see my 2nd comment (https://bugs.eclipse.org/bugs/show_bug.cgi?id=325733#c2)
Eclipse Web Developer Tools
Version: 3.2.1.v201007071800-7O7CFbBEMf84nSIGRvUy2Pq4fbXf
Build id: 20100615235519

Works for me . Have you tried cleaning the server and publishing again?
Comment 8 Fred Bricon CLA 2010-09-28 07:16:29 EDT
Sorry, but I somehow mixed up META-INF and WEB-INF. Please read/test with :

<wb-resource deploy-path="/WEB-INF/web.xml" source-path="/etc/resources/custom-web.xml"/>  

One facepalm for Fred.
Comment 9 Rob Stryker CLA 2011-01-20 15:36:17 EST
retargeting to 3.3
Comment 10 Rob Stryker CLA 2011-06-02 04:03:05 EDT
Forcing to 3.3.1 due to schedule. Sorry.
Comment 11 Rob Stryker CLA 2012-01-17 05:01:28 EST
Created attachment 209608 [details]
Patch for this change
Comment 12 Rob Stryker CLA 2012-01-17 05:52:28 EST
The test for this will go in EarProjectCreationOperationTest.  The patch looks like this. Avoiding a .patch file right now since multiple new uncommitted tests are in the file. 


    public void testEAR_HardDeploymentMapping() throws Exception {
    	IDataModel dm = getEARDataModel("hardEAR", "ourContent", null, null, JavaEEFacetConstants.EAR_5, false);
    	OperationTestCase.runAndVerify(dm);
    	IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("hardEAR");
    	IFolder f = p.getFolder("test");
    	f.create(true, true, new NullProgressMonitor());
    	IFile file = f.getFile("silly.txt");
    	file.create(new ByteArrayInputStream("Silly String".getBytes()), true, new NullProgressMonitor());
    	
    	IVirtualComponent earComp = ComponentCore.createComponent(p);
    	IVirtualFolder rootFolder = earComp.getRootFolder();
    	IVirtualFile vfile = rootFolder.getFile(new Path("out/notsilly.txt"));
    	vfile.createLink(new Path("test/silly.txt"), 0, new NullProgressMonitor());
    	
		IModule module = ServerUtil.getModule(p);
		assertNotNull(module);
		ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, new NullProgressMonitor());
		IModuleResource[] resources = md.members();
    	assertTrue(resources.length == 1);
    	assertTrue(resources[0].getName().equals("out"));
    	IModuleFolder mf = (IModuleFolder)resources[0];
    	IModuleResource[] children = mf.members();
    	assertTrue(children.length == 1);
    	assertTrue(children[0].getName().equals("notsilly.txt"));
    }
Comment 13 Chuck Bridgham CLA 2012-01-17 14:16:55 EST
This change looks good go ahead, and add the test please
Comment 14 Rob Stryker CLA 2012-01-18 01:33:06 EST
Created attachment 209658 [details]
An additional patch on top of the previous

After running a fuller test suite, I found some other untested test cases failed. The issues were two:

  1) Sometimes, the IVirtualResource is null.  This should be guarded against
  2) Behaviour when the path is "/"  (as opposed to an empty path) caused incorrect behaviour and NPEs.

Item 1) is clearly caused by this bug's patch. Item 2 may be a long-standing issue that's been overlooked (?).  Either way, I'm committing the test case with this additional fix to guard against these issues.
Comment 15 Rob Stryker CLA 2012-01-18 02:34:17 EST
Committed and released to 3.3.2 and head