diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 09718eccfd..12b458ec45 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -30,6 +30,8 @@ import java.util.Map; import java.util.HashMap; import java.util.Properties; +import org.apache.maven.model.Activation; +import org.apache.maven.model.ActivationFile; import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -284,6 +286,9 @@ public class DefaultModelBuilder profileSelector.getActiveProfiles( rawModel.getProfiles(), profileActivationContext, problems ); currentData.setActiveProfiles( activePomProfiles ); + Map interpolatedActivationFiles = getProfileActivationFiles( rawModel, false ); + injectProfileActivationFiles( tmpModel, interpolatedActivationFiles ); + for ( Profile activeProfile : activePomProfiles ) { profileInjector.injectProfile( tmpModel, activeProfile, request, problems ); @@ -637,10 +642,72 @@ public class DefaultModelBuilder } } + private Map getProfileActivationFiles( Model model, boolean clone ) + { + Map activationFiles = new HashMap(); + for ( Profile profile : model.getProfiles() ) + { + Activation activation = profile.getActivation(); + + if ( activation == null ) + { + continue; + } + + ActivationFile file = activation.getFile(); + + if ( file == null ) + { + continue; + } + + if ( clone ) + { + file = file.clone(); + } + + activationFiles.put( profile.getId(), file ); + } + + return activationFiles; + } + + private void injectProfileActivationFiles( Model model, Map activationFiles ) + { + for ( Profile profile : model.getProfiles() ) + { + Activation activation = profile.getActivation(); + + if ( activation == null ) + { + continue; + } + + ActivationFile file = activation.getFile(); + + if ( file == null ) + { + continue; + } + + // restore file specification + ActivationFile originalFile = activationFiles.get( profile.getId() ); + file.setExists( originalFile.getExists() ); + file.setMissing( originalFile.getMissing() ); + } + } + private Model interpolateModel( Model model, ModelBuildingRequest request, ModelProblemCollector problems ) { + // save profiles with file activation before interpolation, since they are evaluated with limited scope + Map originalActivationFiles = getProfileActivationFiles( model, true ); + Model result = modelInterpolator.interpolateModel( model, model.getProjectDirectory(), request, problems ); result.setPomFile( model.getPomFile() ); + + // restore profiles with file activation to their value before full interpolation + injectProfileActivationFiles( model, originalActivationFiles ); + return result; } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java index c6d873a5d1..07ba79b4a4 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java @@ -145,6 +145,16 @@ public class FileProfileActivator path = pathTranslator.alignToBaseDirectory( path, basedir ); + // replace activation value with interpolated value + if ( missing ) + { + file.setMissing( path ); + } + else + { + file.setExists( path ); + } + File f = new File( path ); if ( !f.isAbsolute() )