Programmatically Import Project to Workspace (with copy) [message #1148592] |
Mon, 21 October 2013 16:11 |
Alan DW Messages: 119 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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
|
Powered by
FUDForum. Page generated in 0.03637 seconds