public void configureClasspath(
      IProject project,
      MavenProject mavenProject,
      IClasspathDescriptor classpath,
      IProgressMonitor monitor)
      throws CoreException {

    // Improve skinny war support by generating the manifest classpath
    // similar to mvn eclipse:eclipse
    // http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html
    WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project);
    IPackagingConfiguration opts =
        new PackagingConfiguration(config.getPackagingIncludes(), config.getPackagingExcludes());

    /*
     * Need to take care of three separate cases
     *
     * 1. remove any project dependencies (they are represented as J2EE module dependencies)
     * 2. add non-dependency attribute for entries originated by artifacts with
     *    runtime, system, test scopes or optional dependencies (not sure about the last one)
     * 3. make sure all dependency JAR files have unique file names, i.e. artifactId/version collisions
     */

    Set<String> dups = new LinkedHashSet<String>();
    Set<String> names = new HashSet<String>();
    FileNameMapping fileNameMapping = config.getFileNameMapping();
    String targetDir = mavenProject.getBuild().getDirectory();

    // first pass removes projects, adds non-dependency attribute and collects colliding filenames
    Iterator<IClasspathEntryDescriptor> iter = classpath.getEntryDescriptors().iterator();
    while (iter.hasNext()) {
      IClasspathEntryDescriptor descriptor = iter.next();
      IClasspathEntry entry = descriptor.toClasspathEntry();
      String scope = descriptor.getScope();
      Artifact artifact =
          ArtifactHelper.getArtifact(mavenProject.getArtifacts(), descriptor.getArtifactKey());

      ArtifactHelper.fixArtifactHandler(artifact.getArtifactHandler());

      String deployedName = fileNameMapping.mapFileName(artifact);

      boolean isDeployed =
          (Artifact.SCOPE_COMPILE.equals(scope) || Artifact.SCOPE_RUNTIME.equals(scope))
              && !descriptor.isOptionalDependency()
              && opts.isPackaged("WEB-INF/lib/" + deployedName)
              && !isWorkspaceProject(artifact);

      // add non-dependency attribute if this classpathentry is not meant to be deployed
      // or if it's a workspace project (projects already have a reference created in configure())
      if (!isDeployed) {
        descriptor.setClasspathAttribute(
            NONDEPENDENCY_ATTRIBUTE.getName(), NONDEPENDENCY_ATTRIBUTE.getValue());
      }

      // If custom fileName is used, then copy the artifact and rename the artifact under the build
      // dir
      String fileName = entry.getPath().lastSegment();
      if (!deployedName.equals(fileName)) {
        IPath newPath = renameArtifact(targetDir, entry.getPath(), deployedName);
        if (newPath != null) {
          descriptor.setPath(newPath);
        }
      }

      if (!names.add(deployedName)) {
        dups.add(deployedName);
      }
    }

    // second pass disambiguates colliding entry file names
    iter = classpath.getEntryDescriptors().iterator();
    while (iter.hasNext()) {
      IClasspathEntryDescriptor descriptor = iter.next();
      IClasspathEntry entry = descriptor.toClasspathEntry();

      if (dups.contains(entry.getPath().lastSegment())) {
        String newName = descriptor.getGroupId() + "-" + entry.getPath().lastSegment();
        IPath newPath = renameArtifact(targetDir, entry.getPath(), newName);
        if (newPath != null) {
          descriptor.setPath(newPath);
        }
      }
    }
  }
  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
        }
      }
    }
  }