/** For each project in the current build set, reset the version if using project.version */
  @Override
  public Set<Project> applyChanges(final List<Project> projects, final ManipulationSession session)
      throws ManipulationException {
    final ProjectVersionEnforcingState state = session.getState(ProjectVersionEnforcingState.class);
    if (!session.isEnabled()
        || !session.anyStateEnabled(State.activeByDefault)
        || state == null
        || !state.isEnabled()) {
      logger.debug("Project version enforcement is disabled.");
      return Collections.emptySet();
    }

    final Set<Project> changed = new HashSet<Project>();

    for (final Project project : projects) {
      final Model model = project.getModel();

      if (model.getPackaging().equals("pom")) {
        enforceProjectVersion(project, model.getDependencies(), changed);

        if (model.getDependencyManagement() != null) {
          enforceProjectVersion(
              project, model.getDependencyManagement().getDependencies(), changed);
        }

        final List<Profile> profiles = model.getProfiles();
        if (profiles != null) {
          for (final Profile profile : model.getProfiles()) {
            enforceProjectVersion(project, profile.getDependencies(), changed);
            if (profile.getDependencyManagement() != null) {
              enforceProjectVersion(
                  project, profile.getDependencyManagement().getDependencies(), changed);
            }
          }
        }
      }
    }
    if (changed.size() > 0) {
      logger.warn(
          "Using ${project.version} in pom files may lead to unexpected errors with inheritance.");
    }
    return changed;
  }
 /**
  * Adds information about defined profile.
  *
  * @param pomDescriptor The descriptor for the current POM.
  * @param model The Maven Model.
  * @param scannerContext The scanner context.
  */
 private void addProfiles(
     MavenPomDescriptor pomDescriptor, Model model, ScannerContext scannerContext) {
   List<Profile> profiles = model.getProfiles();
   Store store = scannerContext.getStore();
   for (Profile profile : profiles) {
     MavenProfileDescriptor mavenProfileDescriptor = store.create(MavenProfileDescriptor.class);
     pomDescriptor.getProfiles().add(mavenProfileDescriptor);
     mavenProfileDescriptor.setId(profile.getId());
     addProperties(mavenProfileDescriptor, profile.getProperties(), store);
     addModules(mavenProfileDescriptor, profile.getModules(), store);
     addPlugins(mavenProfileDescriptor, profile.getBuild(), scannerContext);
     addManagedPlugins(mavenProfileDescriptor, profile.getBuild(), scannerContext);
     addManagedDependencies(
         mavenProfileDescriptor,
         profile.getDependencyManagement(),
         scannerContext,
         ProfileManagesDependencyDescriptor.class);
     addProfileDependencies(mavenProfileDescriptor, profile.getDependencies(), scannerContext);
     addActivation(mavenProfileDescriptor, profile.getActivation(), store);
   }
 }