Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [m2e-users] Maven plugin and calling buildContext.refresh(File)



On 2/18/2014, 4:07, Grzegorz Słowikowski wrote:
Hi Igor

Thanks for your response. I've learned something from Adrien, and
something from you. Cool.
More inline.

Grzegorz

On 2014-02-17 18:40, Igor Fedorenko wrote:


On 2/17/2014, 11:24, Grzegorz Słowikowski wrote:
Hi All

I have Maven plugin defining custom "play" packaging (for Play!
Framework 1.x http://www.playframework.com/) applications.
In latest release I added M2Eclipse integration
(see
http://maven-play-plugin.googlecode.com/svn/tags/plugin-1.0.0-beta7/play-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml)

I've read about BuildContext usage here:
https://wiki.eclipse.org/M2E_compatible_maven_plugins , but I have some
questions related to this functionality.

1. I wanted to test/debug "buildContext.refresh( someFile )" so I ran
Maven builds inside Eclipse, but I've always had the default
"org.sonatype.plexus.build.incremental.DefaultBuildContext"
implementation when I've debugged my code.
What should I do to get M2Eclipse implementation of BuildContext
interface:
org.eclipse.m2e.core.internal.builder.EclipseBuildContext
org.eclipse.m2e.core.internal.builder.EclipseIncrementalBuildContext
?

How do you inject BuildContext instance in your mojo? Using plugin-tools
@Component, plexus @Requirement or jsr330 @Inject all should inject
instance of EclipseBuildContext inside m2e.
     @org.apache.maven.plugins.annotations.Component
     private BuildContext buildContext;


This is expected to work. Please provide small standalone example that
shows this does not work and exact steps to reproduce the problem and I
will have a look.



2. Sources and resources are processed by M2E completely differently. Is
calling "refresh" important for sources, resources or both, and why
(why not calling "refresh()" can lead to infinite rebuilds)?

During project import and configuration update m2e needs to configure
workspace project sources and resources folders. To do this, m2e runs
maven build with empty resource delta and expects mojos do not produce
any outputs.
And it it produces any output, like in my case now, because I don't use
BuildContext
in recently released version yet?
I have two mojos in my lifecycle-mapping-metadata.xml:
http://maven-play-plugin.googlecode.com/svn/tags/plugin-1.0.0-beta7/play-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
They are similar. They unpack some dependencies' contents and add some
of its folders
as new source roots. If during project import there is empty delta, my
mojos still need to be executed
Actually they are not executed on incremental builds, only on full
builds (import and Maven update, right?).


This should be fine, as long as the mojo only runs during full workspace
build. Running it during every incremental build will kill your
workspace performance.


If your mojo does not properly use BuildContext API it will
do more work than necessary, will create filesystem resources that may
confuse other Eclipse workspace builders.
If mojo does more work, I don't worry, it can be improved later. What
worries me is
how can it confuse other builders. I would like to be able to test it,
and see the situations
when it does not work properly to be able to better understand and fix it.

Some Eclipse workspace API throw exceptions when what workspace thinks
about filesystem state is out of sync actual filesystem state. Unless
you fully control your Eclipse distribution, you just have to assume the
worst case and always keep the workspace and filesystem in sync.


Mojo execution may actually
fail if it depends on outputs of other mojo executions.

During workspace build mojo needs to check if its inputs have changed.
Eclipse runs build on every workspace file modification, so if the mojo
generates its outputs unconditionally, this will trigger new build,
which will result in unconditional generation of mojo outputs and so on.

Calling "refresh" also makes mojo outputs visible to eclipse workspace
and other builders. Eclipse java compiler, for example, will not see
sources generated by the mojo if they are not refreshed in the workspace.
OK, I think what I need most now is knowledge, how to debug all this.
I'm quite experienced Maven developer (from Maven plugin author point of
view),
but completely new to Eclipse development. Give me some documentation links,
please. I don't know, if I need to learn all, maybe only about things I
need to
test/debug my plugin BuildContext usage.

I am sorry, you will have google/bing/yandex/etc for eclipse plugin
development tutorial yourself. m2e specific instructions are explained
in [1] and [2]

[1] https://wiki.eclipse.org/M2E_extension_development_environment
[2] https://wiki.eclipse.org/M2E_Development_Environment

--
Regards,
Igor


Back to the top