From 3141acfdc8f5398dcb08c6cb2984c756801d3d15 Mon Sep 17 00:00:00 2001 From: Falko Modler Date: Thu, 2 May 2019 21:31:13 +0200 Subject: [PATCH] Fix #59: prevent NPE in Eclipse/m2e --- .../org/codehaus/mojo/flatten/FlattenMojo.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java index 368bda02..e856802c 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java @@ -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; @@ -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 activeProfiles = this.session.getRequest().getActiveProfiles(); @@ -709,6 +710,21 @@ private ModelBuildingRequest createModelBuildingRequest( File pomFile ) return buildingRequest; } + private List getReactorModelsFromSession() + { + // robust approach for 'special' environments like m2e (Eclipse plugin) which don't provide allProjects + List 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 pomFile trying its best to match the core maven behaviour. *