protected void configure(IProject project, MavenProject mavenProject, IProgressMonitor monitor)
      throws CoreException {
    IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
    IMavenProjectFacade facade =
        MavenPlugin.getMavenProjectRegistry()
            .create(project.getFile(IMavenConstants.POM_FILE_NAME), true, monitor);

    // make sure to update the main deployment folder
    WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project);
    String warSourceDirectory = config.getWarSourceDirectory();

    IFolder contentFolder = project.getFolder(warSourceDirectory);

    Set<Action> actions = new LinkedHashSet<Action>();

    installJavaFacet(actions, project, facetedProject);

    IVirtualComponent component = ComponentCore.createComponent(project, true);

    // MNGECLIPSE-2279 get the context root from the final name of the project, or artifactId by
    // default.
    String contextRoot = getContextRoot(mavenProject, config.getWarName());

    IProjectFacetVersion webFv = config.getWebFacetVersion(project);
    IDataModel webModelCfg = getWebModelConfig(warSourceDirectory, contextRoot);
    if (!facetedProject.hasProjectFacet(WebFacetUtils.WEB_FACET)) {
      removeConflictingFacets(facetedProject, webFv, actions);
      actions.add(
          new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, webFv, webModelCfg));
    } else {
      IProjectFacetVersion projectFacetVersion =
          facetedProject.getProjectFacetVersion(WebFacetUtils.WEB_FACET);
      if (webFv.getVersionString() != null
          && !webFv.getVersionString().equals(projectFacetVersion.getVersionString())) {
        actions.add(
            new IFacetedProject.Action(
                IFacetedProject.Action.Type.VERSION_CHANGE, webFv, webModelCfg));
      }
    }

    String customWebXml = config.getCustomWebXml(project);

    if (!actions.isEmpty()) {
      ResourceCleaner fileCleaner = new ResourceCleaner(project);
      try {
        addFilesToClean(fileCleaner, facade.getResourceLocations());
        addFilesToClean(fileCleaner, facade.getCompileSourceLocations());
        IFolder libDir = project.getFolder(warSourceDirectory).getFolder("WEB-INF/lib");
        fileCleaner.addFiles(
            contentFolder.getFile("META-INF/MANIFEST.MF").getProjectRelativePath());
        fileCleaner.addFolder(libDir, false);
        if (customWebXml != null) {
          IFile defaultWebXml = project.getFolder(warSourceDirectory).getFile("WEB-INF/web.xml");
          fileCleaner.addFiles(defaultWebXml.getProjectRelativePath());
        }

        facetedProject.modify(actions, monitor);
      } finally {
        // Remove any unwanted MANIFEST.MF the Facet installation has created
        fileCleaner.cleanUp();
      }
    }

    // MECLIPSEWTP-41 Fix the missing moduleCoreNature
    fixMissingModuleCoreNature(project, monitor);

    // MNGECLIPSE-632 remove test sources/resources from WEB-INF/classes
    removeTestFolderLinks(project, mavenProject, monitor, "/WEB-INF/classes");

    addContainerAttribute(project, DEPENDENCY_ATTRIBUTE, monitor);

    // MNGECLIPSE-2279 change the context root if needed
    if (!contextRoot.equals(J2EEProjectUtilities.getServerContextRoot(project))) {
      J2EEProjectUtilities.setServerContextRoot(project, contextRoot);
    }

    // If we have a custom web.xml but WTP created one against our will, we delete it
    if (customWebXml != null) {
      linkFileFirst(project, customWebXml, "/WEB-INF/web.xml", monitor);
    }

    component = ComponentCore.createComponent(project, true);
    if (component != null) {
      IPath warPath = new Path("/").append(contentFolder.getProjectRelativePath());
      List<IPath> sourcePaths = new ArrayList<IPath>();
      sourcePaths.add(warPath);
      if (!WTPProjectsUtil.hasLink(project, ROOT_PATH, warPath, monitor)) {
        component.getRootFolder().createLink(warPath, IVirtualResource.NONE, monitor);
      }
      // MECLIPSEWTP-22 support web filtered resources. Filtered resources directory must be
      // declared BEFORE
      // the regular web source directory. First resources discovered take precedence on deployment
      IPath filteredFolder =
          new Path("/")
              .append(WebResourceFilteringConfiguration.getTargetFolder(mavenProject, project));

      boolean useBuildDir =
          MavenWtpPlugin.getDefault()
              .getMavenWtpPreferencesManager()
              .getPreferences(project)
              .isWebMavenArchiverUsesBuildDirectory();
      boolean useWebresourcefiltering =
          config.getWebResources() != null && config.getWebResources().length > 0
              || config.isFilteringDeploymentDescriptorsEnabled();

      if (useBuildDir || useWebresourcefiltering) {

        if (!useBuildDir && useWebresourcefiltering) {
          mavenMarkerManager.addMarker(
              project,
              MavenWtpConstants.WTP_MARKER_CONFIGURATION_ERROR_ID,
              Messages.markers_mavenarchiver_output_settings_ignored_warning,
              -1,
              IMarker.SEVERITY_WARNING);
        }
        sourcePaths.add(filteredFolder);
        WTPProjectsUtil.insertLinkBefore(project, filteredFolder, warPath, new Path("/"), monitor);
      } else {
        component.getRootFolder().removeLink(filteredFolder, IVirtualResource.NONE, monitor);
      }

      WTPProjectsUtil.deleteLinks(project, ROOT_PATH, sourcePaths, monitor);

      WTPProjectsUtil.setDefaultDeploymentDescriptorFolder(
          component.getRootFolder(), warPath, monitor);

      addComponentExclusionPatterns(component, config);
    }

    WTPProjectsUtil.removeWTPClasspathContainer(project);

    // MECLIPSEWTP-214 : add (in|ex)clusion patterns as .component metadata
  }
  public void setModuleDependencies(
      IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException {
    IVirtualComponent component = ComponentCore.createComponent(project);
    // if the attempt to create dependencies happens before the project is actually created, abort.
    // this will be created again when the project exists.
    if (component == null) {
      return;
    }
    // MECLIPSEWTP-41 Fix the missing moduleCoreNature
    fixMissingModuleCoreNature(project, monitor);

    DebugUtilities.debug(
        "==============Processing " + project.getName() + " dependencies ===============");
    WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project);
    IPackagingConfiguration opts =
        new PackagingConfiguration(config.getPackagingIncludes(), config.getPackagingExcludes());
    FileNameMapping fileNameMapping = config.getFileNameMapping();

    List<AbstractDependencyConfigurator> depConfigurators =
        ExtensionReader.readDependencyConfiguratorExtensions(
            projectManager, MavenPlugin.getMavenRuntimeManager(), mavenMarkerManager);

    Set<IVirtualReference> references = new LinkedHashSet<IVirtualReference>();
    List<IMavenProjectFacade> exportedDependencies =
        getWorkspaceDependencies(project, mavenProject);
    for (IMavenProjectFacade dependency : exportedDependencies) {
      String depPackaging = dependency.getPackaging();
      if ("pom".equals(depPackaging) // MNGECLIPSE-744 pom dependencies shouldn't be deployed
          || "war".equals(depPackaging) // Overlays are dealt with the overlay configurator
          || "zip".equals(depPackaging)) {
        continue;
      }

      try {
        preConfigureDependencyProject(dependency, monitor);

        if (!ModuleCoreNature.isFlexibleProject(dependency.getProject())) {
          // Projects unsupported by WTP (ex. adobe flex projects) should not be added as references
          continue;
        }
        MavenProject depMavenProject = dependency.getMavenProject(monitor);

        IVirtualComponent depComponent = ComponentCore.createComponent(dependency.getProject());

        ArtifactKey artifactKey = ArtifactHelper.toArtifactKey(depMavenProject.getArtifact());
        // Get artifact using the proper classifier
        Artifact artifact = ArtifactHelper.getArtifact(mavenProject.getArtifacts(), artifactKey);
        if (artifact == null) {
          // could not map key to artifact
          artifact = depMavenProject.getArtifact();
        }
        ArtifactHelper.fixArtifactHandler(artifact.getArtifactHandler());
        String deployedName = fileNameMapping.mapFileName(artifact);

        boolean isDeployed =
            !artifact.isOptional() && opts.isPackaged("WEB-INF/lib/" + deployedName);

        // an artifact in mavenProject.getArtifacts() doesn't have the "optional" value as
        // depMavenProject.getArtifact();
        if (isDeployed) {
          IVirtualReference reference = ComponentCore.createReference(component, depComponent);
          IPath path = new Path("/WEB-INF/lib");
          reference.setArchiveName(deployedName);
          reference.setRuntimePath(path);
          references.add(reference);
        }
      } catch (RuntimeException ex) {
        // Should probably be NPEs at this point
        String dump =
            DebugUtilities.dumpProjectState(
                "An error occured while configuring a dependency of  "
                    + project.getName()
                    + DebugUtilities.SEP,
                dependency.getProject());
        LOG.error(dump);
        throw ex;
      }
    }

    IVirtualReference[] oldRefs = WTPProjectsUtil.extractHardReferences(component, false);

    IVirtualReference[] newRefs = references.toArray(new IVirtualReference[references.size()]);

    if (WTPProjectsUtil.hasChanged(oldRefs, newRefs)) {
      // Only write in the .component file if necessary
      IVirtualReference[] overlayRefs = WTPProjectsUtil.extractHardReferences(component, true);
      IVirtualReference[] allRefs = new IVirtualReference[overlayRefs.length + newRefs.length];
      System.arraycopy(newRefs, 0, allRefs, 0, newRefs.length);
      System.arraycopy(overlayRefs, 0, allRefs, newRefs.length, overlayRefs.length);
      component.setReferences(allRefs);
    }

    // TODO why a 2nd loop???
    for (IMavenProjectFacade dependency : exportedDependencies) {
      MavenProject depMavenProject = dependency.getMavenProject(monitor);
      Iterator<AbstractDependencyConfigurator> configurators = depConfigurators.iterator();
      while (configurators.hasNext()) {
        try {
          configurators
              .next()
              .configureDependency(
                  mavenProject, project, depMavenProject, dependency.getProject(), monitor);
        } catch (MarkedException ex) {
          // XXX handle this
        }
      }
    }
  }