Skip to content

Commit

Permalink
Fix mojohaus#59: prevent NPE in Eclipse/m2e
Browse files Browse the repository at this point in the history
  • Loading branch information
famod committed May 2, 2019
1 parent 8d3ba52 commit 3141acf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

Expand Down Expand Up @@ -698,7 +699,7 @@ private ModelBuildingRequest createModelBuildingRequest( File pomFile )
{

FlattenModelResolver resolver = new FlattenModelResolver( this.localRepository, this.artifactFactory,
this.dependencyResolver, this.session.getProjectBuildingRequest(), this.session.getAllProjects() );
this.dependencyResolver, this.session.getProjectBuildingRequest(), getReactorModelsFromSession() );
Properties userProperties = this.session.getUserProperties();
List<String> activeProfiles = this.session.getRequest().getActiveProfiles();

Expand All @@ -709,6 +710,21 @@ private ModelBuildingRequest createModelBuildingRequest( File pomFile )
return buildingRequest;
}

private List<MavenProject> getReactorModelsFromSession()
{
// robust approach for 'special' environments like m2e (Eclipse plugin) which don't provide allProjects
List<MavenProject> models = this.session.getAllProjects();
if ( models == null )
{
models = this.session.getProjects();
}
if ( models == null )
{
models = Collections.emptyList();
}
return models;
}

/**
* Creates the effective POM for the given <code>pomFile</code> trying its best to match the core maven behaviour.
*
Expand Down

0 comments on commit 3141acf

Please sign in to comment.