Locating another project [message #522535] |
Mon, 22 March 2010 18:34  |
Eclipse User |
|
|
|
I've got several projects in my workspace in Eclipse 3.4.2. With my RCP code in project 1 I want to write some files into folders in project 2.
I cannot get a good resource for the second project.
My code is:
String outputProjectName = "/com.qualityeclipse.favorites";
IWorkspaceRoot wr =
ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = wr.getProjects();
System.out.println( "number of projects in workspace: "
+ projects.length );
for ( IProject proj : projects ) {
System.out.println( "a project is " + proj.getName() );
}
It always shows no projects in the workspace, even though Eclipse shows 15 projects in the workspace.
A (probably related) strangeness is that the WorkspaceRoot's getLocationURI() method returns a value
C:\runtime-EclipseApplication where there are no projects, instead of the location of the workspace which is
C:\EclipseTest\... where the 15 projects are located.
Thanks.
Dave Patterson
|
|
|
|
|
|
Re: Locating another project [message #522783 is a reply to message #522540] |
Tue, 23 March 2010 18:02   |
Eclipse User |
|
|
|
Rich,
Thanks for the info.
I've now added the right project to the Project Explorer for my execution environment and can locate a file in that area. The project I want to use for output is an SVN project, so I can update the files and then check them in from the execution environment and they show up (after a refresh) in the development environment.
An additional question. The data I want to put into a file is in my program as a String. Is there a recommended way to dump a String into a file?
What I have done is:
Path newFilePath = new Path( newFileName + ".java" );
IFile outFile = myPackage.getFile( newFilePath );
if ( outFile.exists() ) {
outFile.delete( true, new NullProgressMonitor() );
}
outFile.create( new StringBufferInputStream( newContents ),
IResource.FORCE,
new NullProgressMonitor() );
This gets complaints from the compiler because the StringBufferInputStream is deprecated. While the StringReader is what is recommended, I don't see how to get an InputStream from it.
Another approach I've considered (but have not been looking forward to implementing) would be to invoke a blank editor session, set my String contents into a Document, set that into the editor and then do a save.
When I run it in debug mode, it works fine, but there are some probems I see when I run it at full speed. It seems to hang up in the middle of an operation where I need to create 8-10 files in rapid succession.
Any help would be appreciated.
Dave Patterson
|
|
|
|
|
Powered by
FUDForum. Page generated in 1.05217 seconds