Maven To WTP

Better approach

 The logic for the less noisy approach which works without any user interaction to transform a maven project into a WTP project is more or less ready.I have added here in this class  a cleaner logic to convert a Maven project into a WTP project.
 https://svn.sonatype.org/m2eclipse/branches/raghu/org.maven.ide.eclipse.wtp.facet/src/org/maven/ide/eclipse/wtp/facet/WTPFacetInstaller.java
 I tried it out using my analysis only "popup menu" for Maven to WTP via the action - https://svn.sonatype.org/m2eclipse/branches/raghu/org.maven.ide.eclipse.wtp.facet/src/org/maven/ide/eclipse/wtp/facet/MavenToWTPAction.java. In the end this popup menu will not be there and intstead this logic will be incorporated into a WTPProjectConfigurator built on m2eclipse's extensible project import framework.
 
Tried it on wicket-archetype-quickstart and struts2-archetype-starter. Worked nicely.

See the wicket screencast. 

Logic of the code:

Using WTP API just install the facets.

The facet versions: The code decides the Java and Dynamic Web Module versions based on the effective Java compiler compliance setting for the project using some properties files which contain a mapping of the facet versions against the java compiler versions.

Next Steps:

  • Introduce a GUI or a wizard page for selecting / modifying the target runtime because the version of the  Dynamic Web Module also depends on the target runtime version.
  • Introduce a wizard page with two drop-downs for  selecting the versions of the Java and Dynamic Web Module faets.
  • Validate the  versions of the two facets against the Java compiler settings and the target runtime.

Once the next steps are achieved this will be much better than the previous approach because in addition to being cleaner it will also allow the selection of the target runtime and the appropriate facet version.
Limitations:

  • The logic supports only single module projects. A lot of work needs to be completed before we can progress further.
  • Some maven2 war archetypes don't work well in WTP because the archetypes generate JSPs/XML that dont get validated properly by WTP.

Older approach 

This page is a work in progress. Here one is capturing the current state of WTP integration by converting a Maven m2eclipse project through a popup menu. However this is only for analysis and seeking suggestions. When completed it should actually be part of the create new maven project wizard itself rather than through a popup menu.

The following video (best viewed under full screen) demonstrates how a custom plugin code can be used to convert a Maven2 m2eclipse project into a  Maven2 project with WTP support.

m2eclipse struts2 To WTP

m2eclipse wicket To WTP

The following screen shots demonstrates how a custom plugin code can be used to convert a Maven2 m2eclipse project into a Maven2 project with WTP support.

m2eclipse struts2 to WTP screenshots

The screen shots are equally applicable to the wickets project scenario. 

Logic of the code:

At a very high level this is what happens: 

  1. Capture details of the classpath entry and project natures. [This step can be eliminated if and when this logic is incorporated into the original maven project creation wizard]
  2. Changes are done to the project natures notably we add the following natures and the corresponding builders-
    1. org.eclipse.wst.common.project.facet.core.nature,
    2. org.eclipse.wst.common.modulecore.ModuleCoreNature and
    3. org.eclipse.jem.workbench.JavaEMFNature
  3. Changes are done on the classapth. Classpath changes are scoped inside WorkspaceJobs along with corresponding changes to the component settings using the IVirtualComponent api.
  4. Create some temporary folders and move some files like web-xml temporarily. These temporary folders and files are restored to their correct state by the teime the action is completed.[This step will need to be eliminated with more understanding of WTP ]

Code Snippets: 

The code is available in sm2eclipse svn branch https://svn.sonatype.org/m2eclipse/branches/raghu/org.maven.ide.eclipse.wtp.facet/src/org/maven/ide/eclipse/wtp/facet/MavenToWTPAction.java;

Issues:

  • Noisy logic.  
  • In the "Modify Facet" wizard screen if the user were to press next instead of finish we shall encounter some text boxes. The values need to be currently left at their defaults. Any change to them can cause a problem. Could disable these fields through a hack but intend to find a hack-free implementation instead.
  • There is nothing in current logic to ensure that the user selects the correct facets.

Limitations:

  • The logic supports only single module projects. A lot of work needs to be completed before we can progress further.
  • Some maven2 war archetypes don't work well in WTP because the archetypes generate JSPs/XML that dont get validated properly by WTP.

Next Steps: 

  • This logic can actually be made less noisy by incorporating into the original m2eclipse create project wizard itself rather than have it as part of a separate menu. Would need Eugene to look at the code.
  • It should be possible to eliminate the "Modify Facet" wizard screen. Its after all just display logic which will finally invoke some code that installs the facets that are selected.
  • Involve the WTP team to get their suggestions 
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Aug 04, 2009

    Lavanya Konda says:

    Hi I am interested in adding WTP facets to a Maven project created with my cust...

    Hi

    I am interested in adding WTP facets to a Maven project created with my custom archetype. I installed 'Integration with WTP' , though the project is identified as a Faceted Project, my facets are not being installed.

    I would like to see your 'MavenToWTPAction.java' code but I am not able to access that.

    Thanks for any help in this regard.

    Lavanya.