Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Programmatically Import Project to Workspace (with copy)
Programmatically Import Project to Workspace (with copy) [message #1148592] Mon, 21 October 2013 16:11 Go to next message
Alan DW is currently offline Alan DWFriend
Messages: 108
Registered: March 2012
Senior Member
Hello everyone,

I'm building a Plug-In for Eclipse and for the purpose of Unit Testing I'd like to programmatically set up a workspace for my tests to run in. What I would like to do is to mimic the exact behaviour from the "File -> Import -> Existing Projects into Workspace" command with the "copy projects into workspace" option checked.

Here's the code I have so far:

	private static void importProject(final File baseDirectory, final String projectName) throws CoreException {
		IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(
				new Path(baseDirectory.getAbsolutePath() + "/.project"));
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
		project.create(description, null);
		project.open(null);
	}


... which works nicely, but unfortunately does not copy the project (it only links the location in the workspace .metadata). However, for my purposes, this is essential, because the Unit tests will do modifications on the data, and I must provide the same initial conditions to run automated tests.

Any ideas on this? Or do I really have to first recursively copy my project folder to a temporary directory, then import it from there, and then delete the temporary directory once the test is done? I'd like to avoid that if possible...

Thanks,


Alan
Re: Programmatically Import Project to Workspace (with copy) [message #1229173 is a reply to message #1148592] Wed, 08 January 2014 21:35 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1390
Registered: July 2009
Senior Member
On 21/10/2013 18:11, Alan DW wrote:
> Hello everyone,
>
> I'm building a Plug-In for Eclipse and for the purpose of Unit Testing
> I'd like to programmatically set up a workspace for my tests to run in.
> What I would like to do is to mimic the exact behaviour from the "File
> -> Import -> Existing Projects into Workspace" command with the "copy
> projects into workspace" option checked.
>
> Here's the code I have so far:
>
> private static void importProject(final File baseDirectory, final
> String projectName) throws CoreException {
> IProjectDescription description =
> ResourcesPlugin.getWorkspace().loadProjectDescription(
> new Path(baseDirectory.getAbsolutePath() + "/.project"));
> IProject project =
> ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
> project.create(description, null);
> project.open(null);
> }
>
> .. which works nicely, but unfortunately does not copy the project (it
> only links the location in the workspace .metadata). However, for my
> purposes, this is essential, because the Unit tests will do
> modifications on the data, and I must provide the same initial
> conditions to run automated tests.
>
> Any ideas on this? Or do I really have to first recursively copy my
> project folder to a temporary directory, then import it from there, and
> then delete the temporary directory once the test is done? I'd like to
> avoid that if possible...

Hi

since you do that for testing and you want to mimic what the user does,
you may want to have a look at SWTBot...

cheers
Lorenzo


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
Re: Programmatically Import Project to Workspace (with copy) [message #1229384 is a reply to message #1148592] Thu, 09 January 2014 10:36 Go to previous message
Alan DW is currently offline Alan DWFriend
Messages: 108
Registered: March 2012
Senior Member
Hi,

oh my, you've found a really old thread here, I've almost forgotten about it.
I solved the problem simply by using standard Java I/O means to copy and unzip an existing example project, then used the code I've mentioned in the initial post to import it. Worked out really well Smile

Thanks nontheless, I've never heard of SWTBot, sounds interesting - I'm going to check it out!


Alan
Previous Topic:Class of ParameterizedType
Next Topic:Using HTML to run a java command within plugin
Goto Forum:
  


Current Time: Sat Nov 22 15:38:56 GMT 2014

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

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