[MNG-5612] avoid fully interpolated values for file based profile

activation values but effective values calculated during activation
This commit is contained in:
Hervé Boutemy 2014-03-30 23:46:03 +02:00
parent e7d8dad4b4
commit c175789747
2 changed files with 77 additions and 0 deletions

View File

@ -30,6 +30,8 @@ import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Properties; 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.Build;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.DependencyManagement;
@ -284,6 +286,9 @@ public class DefaultModelBuilder
profileSelector.getActiveProfiles( rawModel.getProfiles(), profileActivationContext, problems ); profileSelector.getActiveProfiles( rawModel.getProfiles(), profileActivationContext, problems );
currentData.setActiveProfiles( activePomProfiles ); currentData.setActiveProfiles( activePomProfiles );
Map<String, ActivationFile> interpolatedActivationFiles = getProfileActivationFiles( rawModel, false );
injectProfileActivationFiles( tmpModel, interpolatedActivationFiles );
for ( Profile activeProfile : activePomProfiles ) for ( Profile activeProfile : activePomProfiles )
{ {
profileInjector.injectProfile( tmpModel, activeProfile, request, problems ); profileInjector.injectProfile( tmpModel, activeProfile, request, problems );
@ -637,10 +642,72 @@ public class DefaultModelBuilder
} }
} }
private Map<String, ActivationFile> getProfileActivationFiles( Model model, boolean clone )
{
Map<String, ActivationFile> activationFiles = new HashMap<String, ActivationFile>();
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<String, ActivationFile> 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 ) private Model interpolateModel( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
{ {
// save profiles with file activation before interpolation, since they are evaluated with limited scope
Map<String, ActivationFile> originalActivationFiles = getProfileActivationFiles( model, true );
Model result = modelInterpolator.interpolateModel( model, model.getProjectDirectory(), request, problems ); Model result = modelInterpolator.interpolateModel( model, model.getProjectDirectory(), request, problems );
result.setPomFile( model.getPomFile() ); result.setPomFile( model.getPomFile() );
// restore profiles with file activation to their value before full interpolation
injectProfileActivationFiles( model, originalActivationFiles );
return result; return result;
} }

View File

@ -145,6 +145,16 @@ public class FileProfileActivator
path = pathTranslator.alignToBaseDirectory( path, basedir ); 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 ); File f = new File( path );
if ( !f.isAbsolute() ) if ( !f.isAbsolute() )