| Summary: | Investigate improvements to code generation support | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Igor Fedorenko <igor> |
| Component: | m2e | Assignee: | Igor Fedorenko <igor> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | anders.g.hammar, d_a_carver, gael.lalire, juergen.zimmermann, pascal, rafal, topolog, vladt |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
|
Description
Igor Fedorenko
*** Bug 348320 has been marked as a duplicate of this bug. *** Or, just add some elements to the Lifecycle Mapping to specify the configuration within the xml. <sources> <source>...</source> </sources> <resources> <resource>..</resource> </resources> After the plugin is finished executing, have m2eclipse add the sources and resources items to the build classpath/sourcefolders. Also, allow a preference page to store the various mappings. Adding source folders after each build is rather tricky. I would like to limit metadata-driven code generation support to the cases where source folders can be calculated from maven plugin execution configuration without actually executing any parts of maven build. (In reply to comment #3) > Adding source folders after each build is rather tricky. I would like to limit > metadata-driven code generation support to the cases where source folders can > be calculated from maven plugin execution configuration without actually > executing any parts of maven build. How do we handle those maven plugins which correctly add their generated sources to the maven build cycle, but don't necessarily have a Configuration option that is specified where those sources are to be generated? An example is the turmeric-maven-plugin. We always generate the code to: target/generated-sources/codegen target/generated-resources/codegen And these are added to the maven build cycle by the turmeric-maven-plugin. Right now m2e is expecting to find a configuration parameter value, and in this case one does not exist. (In reply to comment #4) > (In reply to comment #3) > > Adding source folders after each build is rather tricky. I would like to limit > > metadata-driven code generation support to the cases where source folders can > > be calculated from maven plugin execution configuration without actually > > executing any parts of maven build. > > How do we handle those maven plugins which correctly add their generated > sources to the maven build cycle, but don't necessarily have a Configuration > option that is specified where those sources are to be generated? > > An example is the turmeric-maven-plugin. We always generate the code to: > > target/generated-sources/codegen > target/generated-resources/codegen > > And these are added to the maven build cycle by the turmeric-maven-plugin. > Right now m2e is expecting to find a configuration parameter value, and in this > case one does not exist. All java code generation plugins I've seen so far have output directory configurable via plugin configuration parameters, so turmeric-maven-plugin appears to be an exception, not the common case. To support it, one will have to develop a project configurator, which executes turmeric-maven-plugin as part of its #configure method, then collects source folders from MavenProject instance... or just has generation output folders hardcoded (why complicate things?). Or maybe we implement this logic in the core... not sure yet. Anyone wants to contribute a quality patch to help us decide? ;-) I've run into this problem while developing maven-scm-plugin connector.
Consider the following POM fragment:
<build>
<sourceDirectory>target/checkout/src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>fetch-source</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
<configuration>
<connectionUrl>scm:...</connectionUrl>
<checkoutDirectory>target/checkout</checkoutDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
When project project is imported into the workspace the following happens:
* SCM configurator is executed, it does nothing in configure method.
* JDT configurator is executed, it does not add target/checkout/src folder because it does not exist at this point
* initial build starts
* SCM build participant executes maven-scm-plugin:checkout, and schedules refresh target/checkout
* JDT build participant executed and does nothing in this particular project. If there were any sources in src/main/java depending on the checked out sources, compilation errors would be reported
Here's how I've solved it at SCM build participant level:
* SCM build participant inspects plugin's working directory and records the names of contained directories (possibly empty if the checkout directory is not there yet - eg. on initial checkout or after cleaning)
* SCM Mojo is invoked
* working directory structure is inspected again
* if directory structure has changed a) working directory is refreshed immediately b) IProjectConfigurationManager().updateProjectConfiguration is called
* if directory structure has not changed, lazy refresh of working directory is scheduled through the BuildContext
After this change all project configurators are given a chance to react to directories being created / removed as the result of SCM checkout / update.
Here's the code: https://github.com/objectledge/maven-extensions/blob/master/connectors/modules/scm/plugin/src/org/objectledge/maven/connectors/scm/ScmBuildParticipant.java
Ability to execute maven plugins as part of m2e project configuration was introduced as part bug 349586. Additionally, commit [1] (and corresponding tests [2]). Together, this allows compatible maven plugins to supply lifecycle mapping metadata without the need to develop external project configurator or configure lifecycle mapping in project pom.xml. Wiki [3] provides more information about maven plugin compatibility with Eclipse workspace build. [1] http://git.eclipse.org/c/m2e/m2e-core.git/commit/?id=00d08e894558e0f081bb136b50b6b567234e4d06 [2] https://github.com/sonatype/m2e-core-tests/commit/83b2ba889d54ddcf6e2bde23442856b9cebb94cf [3] http://wiki.eclipse.org/M2E_compatible_maven_plugins |