Bug 412213 - Cannot configure a new packaging type with an existing m2e-wtp Configurator due to the ProjectConfiguratorDelegateFactory
Summary: Cannot configure a new packaging type with an existing m2e-wtp Configurator d...
Status: NEW
Alias: None
Product: M2E-WTP
Classification: Technology
Component: Core (show other bugs)
Version: 1.0.0   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 449495
Blocks:
  Show dependency tree
 
Reported: 2013-07-03 10:03 EDT by Konrad Windszus CLA
Modified: 2014-10-31 20:09 EDT (History)
6 users (show)

See Also:


Attachments
Sample pom (7.14 KB, text/xml)
2013-07-03 10:03 EDT, Konrad Windszus CLA
no flags Details
proposed WebProjectConfigurator (6.15 KB, patch)
2013-07-24 03:54 EDT, Valdas Jasaitis CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Konrad Windszus CLA 2013-07-03 10:03:47 EDT
Created attachment 233038 [details]
Sample pom

I have a special packaging named "content-package" which from the Eclipse perspective is very similar to a WAR file. Unfortunately I cannot overwrite the lifecycle accordingly to make Eclipse import that as a Dynamic Web Project. What I did is I extended the pom.xml with the according lifecycle mapping (http://wiki.eclipse.org/M2E_plugin_execution_not_covered). Please see the attached pom, which in my regard should be a Dynamic Web Project once imported in Eclipse, but it is not working because within the ProjectConfiguratorDelegateFactory.java (http://git.eclipse.org/c/m2e-wtp/org.eclipse.m2e.wtp.git/tree/org.eclipse.m2e.wtp/src/org/eclipse/m2e/wtp/ProjectConfiguratorDelegateFactory.java) you check for the packaging from the POM again.

Please refactor that, so that the configurators can be reused. Probably the whole delegator should be removed, because that restricts usage of the m2e wtp configurators to the hardcoded packaging types.

Just try to import the attached pom. That should lead to a Dynamic Web Project, but currently it does not. Additionally I get a NPE during the import with the following stacktrace:
java.lang.NullPointerException
	at org.eclipse.m2e.wtp.WarPluginConfiguration.<init>(WarPluginConfiguration.java:86)
	at org.eclipse.m2e.wtp.internal.mavenarchiver.WarMavenArchiverConfigurator.getOutputDir(WarMavenArchiverConfigurator.java:36)
	at org.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator.mavenProjectChanged(AbstractMavenArchiverConfigurator.java:178)
	at org.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator.mavenProjectChanged(AbstractMavenArchiverConfigurator.java:170)
	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.mavenProjectChanged(ProjectConfigurationManager.java:965)
	at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.notifyProjectChangeListeners(ProjectRegistryManager.java:746)
	at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.applyMutableProjectRegistry(ProjectRegistryManager.java:865)
	at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:289)
	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.configureNewMavenProjects(ProjectConfigurationManager.java:216)
	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager$1.call(ProjectConfigurationManager.java:159)
	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager$1.call(ProjectConfigurationManager.java:1)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:161)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:137)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:89)
	at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1305)
	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.importProjects(ProjectConfigurationManager.java:134)
	at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizard$1.doCreateMavenProjects(MavenImportWizard.java:172)
	at org.eclipse.m2e.core.ui.internal.wizards.AbstractCreateMavenProjectsOperation.run(AbstractCreateMavenProjectsOperation.java:74)
	at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizard$3.runInWorkspace(MavenImportWizard.java:257)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Comment 1 Fred Bricon CLA 2013-07-03 10:21:29 EDT
I honestly don't like the existing, unique wtp configurator entry point approach, I've been tempted to rewrite it completely and have 1 pure configurator (not delegate) per project type. Unfortunately, for backward compatibility reasons, I couldn't break everything (other, 3rd party plugins, depend on that unique configurator id). Splitting everything would allow to reuse more easily each configurator outside its initial perimeter.

If we keep the current *delegate architecture, we'd need to introduce a new extension point, allowing 3rd party eclipse plugins to register new packaging types for the delegate they need.

I'll try to think of something
Comment 2 Valdas Jasaitis CLA 2013-07-24 03:54:43 EDT
Created attachment 233736 [details]
proposed WebProjectConfigurator

A WebProjectConfigurator sample based on WTPProjectConfigurator that ignores ProjectConfiguratorDelegateFactory and uses WebProjectConfiguratorDelegate directly.
Comment 3 Valdas Jasaitis CLA 2013-07-24 04:03:06 EDT
I added a simple patch that would fulfill our needs. But the NPE still remains because of the getPlugin method in WarPluginConfiguration.java:

public Plugin getPlugin() {
   return this.mavenProject.getPlugin("org.apache.maven.plugins:maven-war-plugin");
}

Of course it cannot find hardcoded "maven-war-plugin" because it's called with a different context. Any suggestions how to overcome this issue?
Comment 4 Fred Bricon CLA 2013-07-24 12:15:39 EDT
I'm currently away from computer/internet. Will check your patch in ~3 weeks.
Comment 5 Konrad Windszus CLA 2013-09-12 06:16:03 EDT
Any update so far? Not only about the proposed project configurator but also about the NPE. It is unclear to me why org.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator.mavenProjectChanged is calling org.eclipse.m2e.wtp.internal.mavenarchiver.WarMavenArchiverConfigurator.getOutputDir(WarMavenArchiverConfigurator.java:36). Basically the WTP Project configurators should support other packagings than only the WAR packaging.
Comment 6 Fred Bricon CLA 2013-09-12 07:16:26 EDT
(In reply to Konrad Windszus from comment #5)
> Any update so far? Not only about the proposed project configurator but also
> about the NPE. 
The NPE is fixed in master (m2e-wtp 1.1.0)

> It is unclear to me why
> org.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator.
> mavenProjectChanged is calling
> org.eclipse.m2e.wtp.internal.mavenarchiver.WarMavenArchiverConfigurator.
> getOutputDir(WarMavenArchiverConfigurator.java:36). 
It's to know where to generate the MANIFEST.MF, either in the target/m2e-wtp/web-resources/ directory or, if the user chose so in the preferences, under the web content directory. 

> Basically the WTP Project configurators should support other packagings than 
> only the WAR packaging.
Says who? That goes well beyond the original scope of m2e-wtp and will certainly require API changes.

As for Valdas' patch, I'm really not comfortable adding new unused configurators, just for the fun of it. If I were to add this configurator, that'd mean the m2e-wtp team would have to maintain it ad vitam aeternam, and I just can't commit to that (at least today, tomorrow's another day). The patch doesn't address the missing maven-war-plugin. How is the project supposed to be configured? Based on what pom settings?

A dedicated web configurator is certainly the approach I want to take, as I said already. But only once I'm certain I can address backward compatibility issues (that configurator replacing the generic, delegate-based WTP one).

So, for the time being, I suggest you fork the classes you need in you own, specific configurator plugin.
Comment 7 Konrad Windszus CLA 2013-09-24 09:38:34 EDT
Thanks for your feedback. Probably you are right and until the delegate pattern is removed in m2e-wtp, probably it is not a good idea to introduce a new (orphaned) project configurator. 

But since m2e-wtp does only export the package org.eclipse.m2e.wtp to the bundle org.eclipse.m2e.wtp.tests (via the x-friends directive) I cannot reuse anything from m2e-wtp in my own project configurator. Could you please at least export the package org.eclipse.m2e.wtp to all other bundles? I would like to reuse the WebProjectConfiguratorDelegate among others within that package.
Comment 8 Konrad Windszus CLA 2013-09-24 09:57:30 EDT
The real problem is that IProjectConfiguratorDelegate is not a public interface and WebProjectConfiguratorDelegate and the other delegates are not public either.
Comment 9 Konrad Windszus CLA 2013-10-16 09:00:21 EDT
Hi Fred, could you please respond to my last comment. Are you planning on making some of those classes public so that other plugins can access those? Currently all the delegator stuff is private, therefore noone can reuse the logic being provided by those classes except for bundle fragment being attached to m2e-wtp.
Comment 10 Fred Bricon CLA 2013-10-16 09:21:53 EDT
I'm really not thrilled at the idea of exposing classes I don't consider as public API, until I'm 100% confident they're mature enough.

But I grok your concerns so, if it can help, I'm ok to make these classes public, inside an *.internal package, and expose them to the world. As such, they won't be considered public API, so can break at any time without warning in future m2e-wtp versions.

I can't log any work on m2e-wtp until after EclipseCon Europe, so early november *at best*. If you want to provide a patch, you're welcome :-)

Make sure you sign Eclipse CLA (http://www.eclipse.org/legal/CLA.php)

{quote}
To complete and submit a CLA, log into the Eclipse projects forge[ https://projects.eclipse.org]- (you will need to create an account with the Eclipse Foundation if you have not already done so); click on "Contributor License Agreement"; and Complete the form. Be sure to use the same email address when you register for the account that you intend to use when you commit to Git.
{/quote}
Comment 11 Fred Bricon CLA 2014-10-31 13:39:25 EDT
Hopefully, I can start splitting and exposing configurators properly after bug #449495 is fixed.