Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ice-dev] Importing projects instead of recreating them in the tests

Yes, that is correct. Something like:

IPath projectPath = new Path(userHome + separator + "ICETests"
             + separator + projectName + separator + ".project");

Jay

On 01/26/2015 05:03 PM, Wojtowicz, Anna wrote:

Note about “projectPath” in the context of:

 

IProjectDescription desc = ResourcesPlugin.getWorkspace()
                    .loadProjectDescription(projectPath);

You need to point to the actual “.project” file, not just the directory.

 

Anna

 

From: ice-dev-bounces@xxxxxxxxxxx [mailto:ice-dev-bounces@xxxxxxxxxxx] On Behalf Of Jay Jay Billings
Sent: Monday, January 26, 2015 4:35 PM
To: ice developer discussions
Subject: [ice-dev] Importing projects instead of recreating them in the tests

 

Everyone,

I was working on a new CSV IOService today and trying to import the test project when I ran into a bug. When I was trying to figure out how to fix it I noticed that several of the test bundles were putting the data in their BeforeClass operations and then writing it to the project space instead of reading it in. Additionally, I noticed that some of our IO classes do this in read()

public void read(IFile file) {

        // Read in the ini file and create the iterator
        File file = new File(ifile.getFullPath().toOSString());
        BufferedReader reader = new BufferedReader(new FileReader(file));

        .....
}

 

when in reality all you need to do is this

public void read(IFile file) {
        BufferedReader reader = new BufferedReader(new InputStreamReader( file.getContents());
        .....
}

 

which is part of the beauty of using IFile.

I think this second part is to get around the fact that the file may not "exist" in the test workspace when the test is run, so you have to drop to File because IFile.getContents() fails. This made it clear to me why I was experiencing a similar bug: we have been creating projects instead of importing the ones that are already in ICETests!

 

To properly import a project, just do this:

      
// Create the project description
IProjectDescription desc = ResourcesPlugin.getWorkspace()
                    .loadProjectDescription(projectPath);
// Get the project handle and create it
project = workspaceRoot.getProject(desc.getName());
project.create(desc, new NullProgressMonitor());
// Open the project if it is not already open
if (project.exists() && !project.isOpen()) {
   project.open(new NullProgressMonitor());
}

I realize that most of the old workspace code is there because I wrote it begin with and it has been copied from test to test. I originally wrote it to test the Item's ability to *write* files to the project space, not read them, so it is easy to understand why I wrote it as such. What bothers me the most is that it took nearly three years for someone - that being me - to notice. So, I want to reiterate that if any of you have problems like this you need to let me know. Don't be timid and avoid asking your mean old boss why it breaks, especially if you are going to be passionate about things like extra    wh ites pace     or imPrOperLy SizeD WIdgEts.

I'll start cleaning them up this summer, but if you get to any of the cases where files should be read and they are being generated before me, please exchange what I originally wrote for the above and get rid of the generation code.

Jay


--

Jay Jay Billings

Oak Ridge National Laboratory

Twitter Handle: @jayjaybillings



_______________________________________________
ice-dev mailing list
ice-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/ice-dev

-- 
Jay Jay Billings
Oak Ridge National Laboratory
Twitter Handle: @jayjaybillings

Back to the top