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 Sep 17, 2019
1 parent 1054540 commit 3be2594
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;
import org.apache.maven.model.building.ModelBuilder;
Expand Down Expand Up @@ -708,7 +709,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 @@ -719,6 +720,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 3be2594

Please sign in to comment.