Friday, December 14, 2007

Hot to get mad with the paths in rcp environments

How do I get to a folder with a relative path to my installation? If this and many other questions about what is where came to your mind, read on:


// 1
// get the file path from resources in a bundle
try {
URL fileURL = FileLocator.find(Platform.getBundle("eu.hydrologis.jgrass.hydrocare"),
new Path("/icons/extract.png"), null);
fileURL = FileLocator.toFileURL(fileURL);
String fileUrlPath = fileURL.getPath();
System.out.println(fileUrlPath);
} catch (Exception e1) {
e1.printStackTrace();
}
// get paths in eclipse
// 2
URL pluginInternalURL = Platform.getInstanceLocation().getURL();
System.out.println(pluginInternalURL.getPath());
// 3
pluginInternalURL = Platform.getInstallLocation().getURL();
System.out.println(pluginInternalURL.getPath());
// 4
pluginInternalURL = Platform.getConfigurationLocation().getURL();
System.out.println(pluginInternalURL.getPath());
// 5
pluginInternalURL = Platform.getUserLocation().getURL();
System.out.println(pluginInternalURL.getPath());
// 6
try {
pluginInternalURL = Platform.getLocation().toFile().toURL();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IllegalStateException e1) {
e1.printStackTrace();
}
System.out.println(pluginInternalURL.getPath());


/*
* in the case I launch it from inside eclipse the following appears
*/
// 1
// the path is correctly transformed in a local path
/Users/moovida/rcpdevelopment/WORKSPACES/jgrassudig33workspace/eu.hydrologis.jgrass.hydrocare/icons/extract.png
// 2
// instancelocation seems to be the workspace folder
/Users/moovida/rcpdevelopment/WORKSPACES/runtime-New_configuration/
// 3
// the install location is the path to the folder inside which I keep the target platform
/Users/moovida/rcpdevelopment/jgrass-udig-sdk-delta/
// 4
// configuration location is inside the metadata folder inside the eclipse
// ide workspace location I defined for my development
/Users/moovida/rcpdevelopment/WORKSPACES/jgrassudig33workspace/.metadata/.plugins/org.eclipse.pde.core/jgrassudig/
// 5
// the userlocation is a strange path that doesn't even exist
/Users/moovida/user/
// 6
// the platform location is the same as the workspace folder
/Users/moovida/rcpdevelopment/WORKSPACES/runtime-New_configuration/


/*
* in the case I launch it from an installed JGrass version
* (install folder is /Applications/jgrass3.0alpha/)
*/
// 1
// the path is correctly transformed in a local path
/Applications/jgrass3.0alpha/plugins/eu.hydrologis.jgrass.hydrocare_1.0.0/icons/extract.png
// 2
// instancelocation seems to be the workspace folder
/Applications/jgrass3.0alpha/jgrass.app/Contents/MacOS/workspace/
// 3
// the install location is infact the path inside which the application resides
/Applications/jgrass3.0alpha/
// 4
// configuration location is the configuration folder inside the installation
/Applications/jgrass3.0alpha/configuration/
// 5
// again the userlocation is a strange path that doesn't even exist
/Users/moovida/user/
// 6
// and again the platform location is the same as the workspace folder
/Applications/jgrass3.0alpha/jgrass.app/Contents/MacOS/workspace/

No comments: