Eclipse 4 RCP Plugin. Programmatically import projects [message #1817307] |
Wed, 20 November 2019 04:54  |
Eclipse User |
|
|
|
I am currently writing an Eclipse 4 RCP Plugin to import projects into Eclipse with the CLI. I found some code snippets that worked quiet well to import projects before launching Eclipse. But when I try to use my applicaation when Eclipse is allready running, the projects do not get imported properly.
Here is the code i use so far:
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription description = workspace.loadProjectDescription(new Path(projectFile.toString()));
IProject project =ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
if (project.isOpen() == false) {
project.create(description, null);
project.open(null)
IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
public String queryOverwrite(String file) {
return ALL; }
};
String baseDir = projectFile.getParent();
description.setLocation(new Path(projectFile.getAbsolutePath()));
ImportOperation importOperation = new ImportOperation(project.getFullPath(),
new File(baseDir), FileSystemStructureProvider.INSTANCE, overwriteQuery);
importOperation.setCreateContainerStructure(false);
try {
importOperation.run(null);
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
project.refreshLocal(IProject.DEPTH_INFINITE, null);
workspace.getRoot().refreshLocal(IProject.DEPTH_INFINITE, null);
System.out.println("Importing project " +description.getName());
So when i execute my application while Eclipse is running, all the projects are getting created and opened, but they do not show up in the Eclipse Package Explorer and when i exit Eclipse they are all lost.
Does anyone know what I am missign here?
|
|
|
|
|
|
|
|
|
|
Re: Eclipse 4 RCP Plugin. Programmatically import projects [message #1817468 is a reply to message #1817467] |
Fri, 22 November 2019 11:52  |
Eclipse User |
|
|
|
Ohhhh! I re-read your initial post again. You're trying to modify a workspace that's already in use. That's not supported: Eclipse actually locks the workspace and checks for the lock on startup. Eclipse maintains its own workspace metadata and does not take kindly to that information being modified from underneath it.
You'll need to communicate with the running process. You might be able to use your platform's URL handling with the `org.eclipse.urischeme.uriSchemeHandlers` extension point. You could define your own URI scheme (`x-import` like `x-import:///file/path`).
Brian.
|
|
|
Powered by
FUDForum. Page generated in 0.04738 seconds