At the moment there is no simple api for doing this in an eclipse independent way. The actifsource Plugins using the
ProjectUtil#findFileFor-Methods to get an eclipse IFile. However there is a better way to archive this:
Knowing that an actifsource package lives in a scope (=project) and a package contains the information about the asrc-folder location and it's fullname, there is a relativly new method on the actifsource package returning it's folder.
Since all actifsource root resource stored directly in the package folder you can easily concat the folderURL and the fileName. For creating the filename use the static helper method
ResouceStore.createResourceFileName. However this helper always assumes that the resource passed is a root resource, this means you need to handle the case of aggregated resources by yourself. In the following snippet we always return the url of the root resource:
- Code: Select all
public java.lang.String ResourceFilePath(final ch.actifsource.core.javamodel.IResource resource) {
URL url = resource.getPackage().toFolder().getUrl();
if (url == null) throw new GenerationException("resource with unsupported folder type");
INode rootResource = Select.rootResource(resource.getReadJobExecutor(), resource.getResource());
String fileName = ResourceStore.createResourceFileName((Resource) rootResource);
return URLUtil.append(url, fileName).toExternalForm();
}
Be aware that the returned url from the folder may not be a file-url or the folder might not support getting an url at all. For example if the resource comes from an eclipse bundle such as ch.actifsource.core you will get an bundle url. The code above assumes the resource is available as a file.
Best regards
Heiko Böttger