List of usage examples for org.apache.maven.model.profile ProfileSelector ProfileSelector
ProfileSelector
From source file:org.codehaus.mojo.flatten.FlattenMojo.java
License:Apache License
/** * Creates the effective POM for the given <code>pomFile</code> trying its best to match the core maven behaviour. * * @return the parsed and calculated effective POM. * @throws MojoExecutionException if anything goes wrong. */// w w w. ja va2 s . c om protected static Model createEffectivePom(ModelBuildingRequest buildingRequest, final boolean embedBuildProfileDependencies) throws MojoExecutionException { ModelBuildingResult buildingResult; try { ProfileInjector profileInjector = new ProfileInjector() { public void injectProfile(Model model, Profile profile, ModelBuildingRequest request, ModelProblemCollector problems) { // do nothing } }; ProfileSelector profileSelector = new ProfileSelector() { public List<Profile> getActiveProfiles(Collection<Profile> profiles, ProfileActivationContext context, ModelProblemCollector problems) { List<Profile> activeProfiles = new ArrayList<Profile>(profiles.size()); for (Profile profile : profiles) { Activation activation = profile.getActivation(); if (!embedBuildProfileDependencies || isBuildTimeDriven(activation)) { activeProfiles.add(profile); } } return activeProfiles; } }; DefaultModelBuilder defaultModelBuilder = new DefaultModelBuilderFactory().newInstance(); defaultModelBuilder.setProfileInjector(profileInjector).setProfileSelector(profileSelector); buildingResult = defaultModelBuilder.build(buildingRequest); } catch (ModelBuildingException e) { throw new MojoExecutionException(e.getMessage(), e); } Model effectivePom = buildingResult.getEffectiveModel(); // LoggingModelProblemCollector problems = new LoggingModelProblemCollector( getLog() ); // Model interpolatedModel = // this.modelInterpolator.interpolateModel( this.project.getOriginalModel(), // effectivePom.getProjectDirectory(), buildingRequest, problems ); // remove Repositories from super POM (central) effectivePom.setRepositories(createFlattenedRepositories(effectivePom.getRepositories())); return effectivePom; }