Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335711 - Investigate improvements to code generation support
Summary: Investigate improvements to code generation support
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: m2e (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Igor Fedorenko CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 348320 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-01-28 12:35 EST by Igor Fedorenko CLA
Modified: 2021-04-19 13:22 EDT (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Fedorenko CLA 2011-01-28 12:35:13 EST
As discussed on m2e-dev http://dev.eclipse.org/mhonarc/lists/m2e-users/msg00239.html, investigate possibility of providing standard project configuration that can be configured to support many maven code generation plugins. 

This seem to imply changes to lifecycle mapping metadata to allow passing parameters to project configurators.

Some additional unsupported code generation plugins used by opensource projects we've tested
https://docs.sonatype.org/display/M2ECLIPSE/Projects+%28codebases%29+tested+with+m2e+0.13.x
Comment 1 Igor Fedorenko CLA 2011-06-05 08:26:04 EDT
*** Bug 348320 has been marked as a duplicate of this bug. ***
Comment 2 David Carver CLA 2011-06-27 17:13:24 EDT
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.
Comment 3 Igor Fedorenko CLA 2011-06-28 02:36:02 EDT
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.
Comment 4 David Carver CLA 2011-06-28 11:13:08 EDT
(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.
Comment 5 Igor Fedorenko CLA 2011-06-28 12:00:44 EDT
(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? ;-)
Comment 6 Rafal Krzewski CLA 2011-07-06 20:39:13 EDT
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
Comment 7 Igor Fedorenko CLA 2011-10-17 17:43:39 EDT
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
Comment 8 Denis Roy CLA 2021-04-19 13:22:33 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/