private IProject createNewProject() {
    if (newProject != null) {
      return newProject;
    }

    // get a project handle
    final IProject newProjectHandle = mainPage.getProjectHandle();
    // get a project descriptor
    URI location = null;
    if (!mainPage.useDefaults()) {
      location = mainPage.getLocationURI();
    }

    IProjectDescription description =
        ResourceUtil.getProjectDescription(
            mainPage.getLocationPath(), sample.getNatures(), ArrayUtil.NO_STRINGS);
    description.setName(newProjectHandle.getName());
    description.setLocationURI(location);

    try {
      if (sample.isRemote()) {
        cloneFromGit(sample.getLocation(), newProjectHandle, description);
      } else {
        doBasicCreateProject(newProjectHandle, description);

        // FIXME Move the logic for extracting/applying samples to IProjectSample! See
        // IProjectTemplate!
        ZipUtil.extract(
            new File(sample.getLocation()),
            newProjectHandle.getLocation(),
            ZipUtil.Conflict.PROMPT,
            new NullProgressMonitor());

        doPostProjectCreation(newProjectHandle);
      }
    } catch (IOException e) {
      return null;
    } catch (CoreException e) {
      return null;
    }

    newProject = newProjectHandle;
    return newProject;
  }
  private void cloneFromGit(
      String gitURL, final IProject projectHandle, final IProjectDescription projectDescription) {
    IPath path = mainPage.getLocationPath();
    // when default is used, getLocationPath() only returns the workspace root, so needs to append
    // the project name
    // to the path
    if (mainPage.useDefaults()) {
      path = path.append(projectDescription.getName());
    }

    // Wipe the destination directory if it already exists, or git clone will fail.
    File directory = path.toFile();
    if (directory.exists()) {
      FileUtil.deleteRecursively(directory);
    }

    // FIXME Run an IRunnableWithProgress in wizard container, have it just do job.run(monitor)!
    Job job = new CloneJob(gitURL, path.toOSString(), true, true);
    job.addJobChangeListener(
        new JobChangeAdapter() {

          @Override
          public void done(IJobChangeEvent event) {
            if (!event.getResult().isOK()) {
              return;
            }

            try {
              projectHandle.setDescription(projectDescription, null);
              projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
            } catch (CoreException e) {
              IdeLog.logError(SamplesUIPlugin.getDefault(), e);
            }

            doPostProjectCreation(newProject);
          }
        });
    job.schedule(500);
  }
Exemplo n.º 3
0
  @Override
  public boolean performFinish() {
    fNewRProject =
        new ProjectCreator(
            fFirstPage.getProjectName(),
            (fFirstPage.useDefaults()) ? null : fFirstPage.getLocationPath(),
            (fReferencePage != null) ? fReferencePage.getReferencedProjects() : null,
            fFirstPage.getSelectedWorkingSets()) {
          @Override
          protected void doConfigProject(final IProject project, final IProgressMonitor monitor)
              throws CoreException {
            RProjects.setupRProject(fNewRProject.getProjectHandle(), monitor);
          }
        };

    final boolean result = super.performFinish();

    if (result && fNewRProject.getProjectHandle() != null) {
      updatePerspective();
      selectAndReveal(fNewRProject.getProjectHandle());
    }

    return result;
  }