Bug 434495 - M2E-WTP does not honor maven-ear-plugin <dependencies>
Summary: M2E-WTP does not honor maven-ear-plugin <dependencies>
Status: NEW
Alias: None
Product: M2E-WTP
Classification: Technology
Component: Core (show other bugs)
Version: 1.0.1   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 434497
  Show dependency tree
 
Reported: 2014-05-09 08:55 EDT by Frédéric Chuong CLA
Modified: 2014-05-09 11:40 EDT (History)
4 users (show)

See Also:


Attachments
Sample project using custom file mapping strategy + custom file mapping strategy implementation (3.46 KB, application/octet-stream)
2014-05-09 11:40 EDT, Frédéric Chuong CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Frédéric Chuong CLA 2014-05-09 08:55:01 EDT
The following configuration doesn't work with M2E-WTP:

                <plugin>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>2.9</version>
                    <dependencies>
                        <dependency>
                            <!-- our custom naming scheme is defined here -->
                            <groupId>foo.company.maven.ext</groupId>
                            <artifactId>custom-ear-mapping</artifactId>
                            <version>1.0.0</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <!-- Use our custom naming scheme -->
                        <fileNameMapping>foo.company.maven.ext.CustomFileNameMapping</fileNameMapping>
                    </configuration>
                </plugin>

This results in the following error in M2E-WTP:

An internal error occurred during: "Updating Maven Project".
File name mapping implementation[foo.company.maven.ext.CustomFileNameMapping] was not found foo.company.maven.ext.CustomFileNameMapping cannot be found by org.eclipse.m2e.wtp_1.0.1.20130911-1545

Source code shows that dynamic class lookup is attempted but, for some reason, the class isn't found by the class loader:
http://git.eclipse.org/c/m2e-wtp/org.eclipse.m2e.wtp.git/tree/org.eclipse.m2e.wtp/src/org/eclipse/m2e/wtp/namemapping/FileNameMappingFactory.java?id=cc0322559a59dfafab9a357dfbb2e54ad9e10818


Moreover, should this classloading issue be fixed, the feature would not work since the interface package name don't match with https://maven.apache.org/plugins/maven-ear-plugin/xref/org/apache/maven/plugin/ear/output/FileNameMapping.html vs http://git.eclipse.org/c/m2e-wtp/org.eclipse.m2e.wtp.git/tree/org.eclipse.m2e.wtp/src/org/eclipse/m2e/wtp/namemapping/FileNameMapping.java?id=976c0227993c62c2ff0eb12bb2b002d8425e543c
(org.apache.maven.plugin.ear.output != org.eclipse.m2e.wtp.namemapping)
Comment 1 Fred Bricon CLA 2014-05-09 09:39:09 EDT
Can you please add a sample custom-ear-mapping plugin + test project reproducing the error?

This one is gonna be tricky to fix, as we don't load/depend on the maven-ear-plugin classes directly in Eclipse.
Comment 2 Fred Bricon CLA 2014-05-09 09:53:09 EDT
As a workaround, I suggest you use the following approach : 
...
<properties>
 <ear.fileNameMapping>foo.company.maven.ext.CustomFileNameMapping</ear.fileNameMapping>
</properties>
...
<plugin>
  <artifactId>maven-ear-plugin</artifactId>
  <version>2.9</version>
  <dependencies>
    <dependency>
      <!-- our custom naming scheme is defined here -->
      <groupId>foo.company.maven.ext</groupId>
      <artifactId>custom-ear-mapping</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>
  <configuration>
  <!-- Use our custom naming scheme -->
  <fileNameMapping>${ear.fileNameMapping}</fileNameMapping>
  </configuration>
</plugin>
...
<profiles>
 <profile>
   <id>m2e</id>
   <activation>
     <property>
       <name>m2e.version</name>
     </property>
   </activation>
   <properties>
     <!-- One of standard/full/no-version/no-version-for-ejb -->
     <ear.fileNameMapping>standard</ear.fileNameMapping>
   </properties>
 </profile>
</profiles>

Basically, all CLI builds will use your custom mapping, and builds inside m2e/eclipse will use an m2e-wtp compatible mapping.
Comment 3 Frédéric Chuong CLA 2014-05-09 11:40:51 EDT
Created attachment 242900 [details]
Sample project using custom file mapping strategy + custom file mapping strategy implementation

Attached 2 sample projects:
- Custom file mapping strategy implementation
- EAR project making use of that custom file mapping strategy