capint
10/16/2015 - 4:30 PM

Eclipse >> Resource >> Project >> Import project into workspace

Eclipse >> Resource >> Project >> Import project into workspace

private void importProject(File baseDirectory){
  try {
    NullProgressMonitor nullProgressMonitor = new NullProgressMonitor();
    IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(
        new Path(baseDirectory.getAbsolutePath() + "/" + IProjectDescription.DESCRIPTION_FILE_NAME));
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
    if (project.exists()){
      project.delete(true, nullProgressMonitor);
    }
    project.create(description, nullProgressMonitor);
    project.open(nullProgressMonitor);
  } catch (CoreException e) {
    Activator.getLogger(getClass()).error("Error while importing project", e);
  }
}
private void importProject(String baseDir, IProject project) {
  IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
    @Override
    public String queryOverwrite(String file) {
      return ALL;
    }
  };

  ImportOperation importOperation = new ImportOperation(project.getFullPath(), new File(baseDir),
      FileSystemStructureProvider.INSTANCE, overwriteQuery);
  importOperation.setCreateContainerStructure(false);
  try {
    importOperation.run(new NullProgressMonitor());
  } catch (InvocationTargetException | InterruptedException e) {
    Activator.getLogger(getClass()).error("Error while importing project", e);
  }
}