/**
   * Imports a WSDL file in the created project.
   *
   * @param monitor
   * @param jbiFile
   * @param resourceDirectory
   */
  public void importWSDLFileInProvideSUProject(
      IProgressMonitor monitor, IFile jbiFile, IFolder resourceDirectory) {

    File wsdlFile = null;
    monitor.subTask("Importing the WSDL...");
    this.finalWsdlFileLocation = getSelectedWSDLForProvide();
    if (this.finalWsdlFileLocation != null && this.jbiProvidePage.isImportWsdl()) {

      try {
        WsdlImportHelper helper = new WsdlImportHelper();
        Map<String, File> fileToUrl =
            helper.importWsdlOrXsdAndDependencies(
                resourceDirectory.getLocation().toFile(), getSelectedWSDLForProvide());

        wsdlFile = fileToUrl.get(getSelectedWSDLForProvide());
        this.finalWsdlFileLocation =
            IoUtils.getRelativeLocationToFile(jbiFile.getLocation().toFile(), wsdlFile);
        monitor.subTask("Updating the WSDL...");
        WsdlUtils.INSTANCE.updateEndpointNameInWsdl(
            wsdlFile,
            this.endpoint.getServiceName(),
            this.settings.soapOriginalPort,
            this.endpoint.getEndpointName());

      } catch (ParserConfigurationException e) {
        PetalsServicesPlugin.log(e, IStatus.ERROR);

      } catch (IOException e) {
        PetalsServicesPlugin.log(e, IStatus.ERROR);

      } catch (URISyntaxException e) {
        PetalsServicesPlugin.log(e, IStatus.ERROR);

      } catch (SAXException e) {
        PetalsServicesPlugin.log(e, IStatus.ERROR);
      }

      monitor.worked(1);
    }
  }
  /**
   * Imports the selected projects.
   *
   * @param monitor
   * @throws CoreException
   */
  protected void doFinish(IProgressMonitor monitor) throws CoreException {

    monitor.beginTask("Importing the Service Assembly...", IProgressMonitor.UNKNOWN);
    List<SaImportBean> importBeans = this.page.getImportsBeans();

    List<IProject> suDependencies = new ArrayList<IProject>();
    List<MavenBean> suMavenBeans = new ArrayList<MavenBean>();
    for (SaImportBean saBean : importBeans) {

      // Deal with the SU projects first
      for (SuImportBean suBean : saBean.getSuBeans()) {

        if (!suBean.isToCreate()) continue;

        try {
          // Delete the project?
          if (suBean.isToOverwrite()) {
            IProject p =
                ResourcesPlugin.getWorkspace().getRoot().getProject(suBean.getProjectName());
            if (p.exists()) p.delete(true, monitor);
          }

          IProject project = null;
          URI pLocUri = null;
          if (!this.page.isAtDefaultLocation())
            pLocUri = new File(this.page.getProjectLocation(), suBean.getProjectName()).toURI();

          project =
              PetalsServicesProjectUtils.createSuProject(
                  suBean.getProjectName(),
                  pLocUri,
                  suBean.getComponentName(),
                  suBean.getComponentVersion(),
                  suBean.getSuType(),
                  false,
                  monitor);
          suDependencies.add(project);

          // Create the POM artifacts for the SA
          // Elements match what is set in
          // PetalsServicesProjectUtils#createPetalsSuProjectStructure().
          MavenBean suMavenBean = new MavenBean();
          suMavenBean.setArtifactId(project.getName());
          suMavenBeans.add(suMavenBean);

          // Copy the resources
          File jbiXmlFile = new File(suBean.getJbiXmlLocation());
          File targetFile = project.getLocation().append(PetalsConstants.LOC_JBI_FILE).toFile();
          if (!jbiXmlFile.exists()) throw new IOException("The jbi.xml does not exist.");

          IoUtils.moveFileRobustly(jbiXmlFile, targetFile, true);
          IFolder resFolder = project.getFolder(PetalsConstants.LOC_RES_FOLDER);
          File resFile = resFolder.getLocation().toFile();

          for (File fileToCopy : jbiXmlFile.getParentFile().getParentFile().listFiles()) {
            if (!"meta-inf".equalsIgnoreCase(fileToCopy.getName()))
              IoUtils.copyFileInDirectory(fileToCopy, resFile, false);
          }

          // Keep the project to show it at the end
          this.resourcesToSelect.add(project);
          monitor.worked(5);
          project.refreshLocal(IResource.DEPTH_INFINITE, monitor);

        } catch (Exception e) {
          PetalsServicesPlugin.log(e, IStatus.ERROR);
        }
      }

      // Deal with the SA project then
      if (saBean.isToCreate()) {

        // Delete the existing project?
        if (saBean.isToOverwrite()) {
          IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(saBean.getProjectName());
          if (p.exists()) p.delete(true, monitor);
        }

        // Create the SA project
        URI pLocUri = null;
        if (!this.page.isAtDefaultLocation())
          pLocUri = new File(this.page.getProjectLocation(), saBean.getProjectName()).toURI();

        // Generate a basic POM
        MavenBean saMavenBean = new MavenBean();
        saMavenBean.setName(saBean.getProjectName());
        saMavenBean.setArtifactId(saMavenBean.getName());
        saMavenBean.dependencies.addAll(suMavenBeans);

        // Get the parent pom.xml
        MavenBean parentBean = MavenUtils.getPomParentElements();
        if (parentBean != null) {
          saMavenBean.setParentArtifactId(parentBean.getArtifactId());
          saMavenBean.setParentGroupId(parentBean.getGroupId());
          saMavenBean.setParentVersion(parentBean.getVersion());
        }

        try {
          // Create the project
          IProject saProject =
              PetalsServicesProjectUtils.createSaProject(
                  saBean.getProjectName(), pLocUri, saMavenBean, monitor);

          this.resourcesToSelect.add(saProject);

          // Copy the resources
          File jbiXmlFile = new File(saBean.getJbiXmlLocation());
          File targetFile = saProject.getLocation().append(PetalsConstants.LOC_JBI_FILE).toFile();
          if (!jbiXmlFile.exists()) throw new IOException("The jbi.xml does not exist.");

          IoUtils.moveFileRobustly(jbiXmlFile, targetFile, true);

          // Set the SU dependencies
          saProject.refreshLocal(IResource.DEPTH_INFINITE, monitor);
          IProjectDescription desc = saProject.getDescription();
          IProject[] projects = new IProject[suDependencies.size()];
          desc.setReferencedProjects(suDependencies.toArray(projects));
          saProject.setDescription(desc, null);

        } catch (CoreException e) {
          PetalsServicesPlugin.log(e, IStatus.ERROR);

        } catch (Exception e) {
          PetalsServicesPlugin.log(e, IStatus.ERROR);
        }
      }
    }

    monitor.worked(1);
  }