Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Eclipse 4 RCP Plugin. Programmatically import projects(Importing projects with a CLI triggered plugin while Eclipse is running)
Eclipse 4 RCP Plugin. Programmatically import projects [message #1817307] Wed, 20 November 2019 09:54 Go to next message
Hugo Maier is currently offline Hugo MaierFriend
Messages: 8
Registered: October 2019
Junior Member

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 #1817331 is a reply to message #1817307] Wed, 20 November 2019 15:37 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 876
Registered: January 2012
Senior Member

If I recall correctly, you need to call `IProject#create()`. Depending on what you're doing, you might want to use `org.eclipse.ui.ide.CreateProjectOperation`.

Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Eclipse 4 RCP Plugin. Programmatically import projects [message #1817363 is a reply to message #1817331] Thu, 21 November 2019 07:33 Go to previous messageGo to next message
Hugo Maier is currently offline Hugo MaierFriend
Messages: 8
Registered: October 2019
Junior Member
Hi,
thank you for your answer. I do call this:

project.create(description, null);


Is this not the same as the `IProject#create()` operation you mentioned?
Re: Eclipse 4 RCP Plugin. Programmatically import projects [message #1817377 is a reply to message #1817363] Thu, 21 November 2019 12:05 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 876
Registered: January 2012
Senior Member

Oops! I thought I did a search to check if you called ` create ()` :blush:. I believe create() and open () return values to indicate the success of the operation? I'll take another look when I'm in front of my computer.

Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Eclipse 4 RCP Plugin. Programmatically import projects [message #1817394 is a reply to message #1817377] Thu, 21 November 2019 15:20 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 876
Registered: January 2012
Senior Member

Ignore what I said about returns -- they're void.

You mention:
Quote:
But when I try to use my applicaation when Eclipse is allready running, the projects do not get imported properly.


How are you executing this code? I pulled your code in as a command handler and tried importing an existing project into an instance running on a fresh workspace, and the imported project indeed shows up in the package explorer. So your code seems ok. Are you sure you're using the same workspace between runs?


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Eclipse 4 RCP Plugin. Programmatically import projects [message #1817396 is a reply to message #1817394] Thu, 21 November 2019 15:39 Go to previous messageGo to next message
Hugo Maier is currently offline Hugo MaierFriend
Messages: 8
Registered: October 2019
Junior Member
Hi,
thank you for your answer.

I am using the CLI:

 
eclipsec -application <application name> -data <path to workspace> -import <path to project>


So how exactly did you used it?
Re: Eclipse 4 RCP Plugin. Programmatically import projects [message #1817426 is a reply to message #1817396] Thu, 21 November 2019 22:45 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 876
Registered: January 2012
Senior Member

I hooked up a command / handler and put it into the handler

Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Eclipse 4 RCP Plugin. Programmatically import projects [message #1817467 is a reply to message #1817426] Fri, 22 November 2019 16:15 Go to previous messageGo to next message
Hugo Maier is currently offline Hugo MaierFriend
Messages: 8
Registered: October 2019
Junior Member
OK.
But i do want to import my projects not into a fresh workspace, I would like to import them into the current running workspace.
Can someone help me with that?

[Updated on: Fri, 22 November 2019 16:15]

Report message to a moderator

Re: Eclipse 4 RCP Plugin. Programmatically import projects [message #1817468 is a reply to message #1817467] Fri, 22 November 2019 16:52 Go to previous message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 876
Registered: January 2012
Senior Member

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.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Previous Topic:close and reopen a view
Next Topic:Secondary IDs broken?
Goto Forum:
  


Current Time: Thu Oct 29 00:01:59 GMT 2020

Powered by FUDForum. Page generated in 0.02580 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top