Hi,

solved it with the code above:

  /**
   * Runs an action within the scope of mutable state of a project. This is
useful for example if
   * multiple mojo goals should be executed in the way that they share the
same project state.
   *
   * @param project
   *          The project that should have the mutable state.
   * @param action
   *          The action that should be executed.
   */
  @SuppressWarnings("restriction")
  public static void executeWithMutableProjectState(final MavenProject
project,
      final ICoreRunnable action, final IProgressMonitor monitor) throws
CoreException {

    LinkedHashSet<Artifact> artifacts = new
LinkedHashSet<>(project.getArtifacts());
    MavenProjectMutableState snapshot =
MavenProjectMutableState.takeSnapshot(project);

    try {
      action.run(monitor);
    } finally {
      project.setArtifactFilter(null);
      project.setResolvedArtifacts(null);
      project.setArtifacts(artifacts);
      snapshot.restore(project);
    }
  }

It would be nice to achieve the same goal with public stable API.

Kind regards,
*Balázs **Zsoldos*


On Sat, Oct 22, 2016 at 12:35 PM, Balázs Zsoldos <balazs.zsol...@everit.biz>
wrote:

> Hi,
>
> My issue is the following:
>
> I would like to execute multiple MojoExecutions in the way that one of
> them sets a mavenProject property and the other reads it.
>
> There are several examples to this with existing Mojos. E.g.:
>
>  - maven-scr-plugin sets a maven project property while
> maven-bundle-plugin reads it
>  - buildnumber-maven-plugin sets maven project property that is used
> during manifest generation by other mojo
>
> The issue is that there is no function where I can run multiple
> mojoExecutions and they use the share the same mavenProject. Every call
> goes through the following function:
>
>     org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenSession
> session, MojoExecution execution, IProgressMonitor monitor)
>
> This persists the project state and then restores it. So multiple mojos
> cannot share the same project properties.
>
> Do you know a workaround? I can imagine only one with the current API but
> it is pretty ugly:
>
>  - I develop a CallbackMojo. This mojo checks if there is a Runnable
> provided via MavenExecutionRequest data and if there is, it calls it.
>  - In my M2E based code, I execute this mojo and pass the calling of the
> real execution plan via a lambda expression.
>
> It would be nice if there was a function to execute multiple mojo-s in a
> row where mavenproject state is not persisted and restored between the mojo
> executions.
>
> Kind regards,
> *Zsoldos Balázs*
>
>
_______________________________________________
m2e-users mailing list
m2e-users@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/m2e-users

Reply via email to