Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically importing an existing project into Eclipse

I am trying to importing the project to eclipse through programmatically. I dont want to use UI mode.

Below is the code I used for importing the project:

IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(  new Path("PROJECT_PATH/.project"));
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
project.create(description, null);
project.open(null);

I'm getting only the project folder along with .location file, .markers.snap file and .syncinfo.snap files, but I am not getting the source folder and etc.

like image 997
user1584844 Avatar asked Sep 13 '12 07:09

user1584844


1 Answers

Use org.eclipse.ui.wizards.datatransfer.ImportOperation

Try something like this:

IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
        public String queryOverwrite(String file) { return ALL; }
};

String baseDir = // location of files to import
ImportOperation importOperation = new ImportOperation(project.getFullPath(),
        new File(baseDir), FileSystemStructureProvider.INSTANCE, overwriteQuery);
importOperation.setCreateContainerStructure(false);
importOperation.run(new NullProgressMonitor());
like image 163
Mike Kucera Avatar answered Oct 10 '22 10:10

Mike Kucera