Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 345413 - [M2x IDE Integration] The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGroup#loadTemplate(IFile) method cannot load file not present in projects.
Summary: [M2x IDE Integration] The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGro...
Status: CLOSED FIXED
Alias: None
Product: Sphinx
Classification: Automotive
Component: Core (show other bugs)
Version: 0.7.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Idrissa Dieng CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-11 08:45 EDT by Idrissa Dieng CLA
Modified: 2021-07-14 02:17 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Idrissa Dieng CLA 2011-05-11 08:45:38 EDT
The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGroup#loadTemplate(IFile) method should allow loading files that are not in a project.
Comment 1 Idrissa Dieng CLA 2011-05-12 04:36:17 EDT
(In reply to comment #0)
> The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGroup#loadTemplate(IFile)
> method should allow loading files that are not in a project.

We have the same problem when loading external extension files with org.eclipse.sphinx.xtendxpand.ui.groups.ExtensionGroup#loadExtensionFile(IFile).

The root cause is we search only in workspace location in the org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String, ResourceLoader) method.
Comment 2 Idrissa Dieng CLA 2011-05-13 08:43:05 EDT
(In reply to comment #1)
> (In reply to comment #0)
> > The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGroup#loadTemplate(IFile)
> > method should allow loading files that are not in a project.
> 
> We have the same problem when loading external extension files with
> org.eclipse.sphinx.xtendxpand.ui.groups.ExtensionGroup#loadExtensionFile(IFile).
> 
> The root cause is we search only in workspace location in the
> org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String,
> ResourceLoader) method.

I propose to modify the org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String, ResourceLoader) method like this:

public static IFile getUnderlyingFile(String qualifiedName, ResourceLoader resourceLoader) {
Assert.isNotNull(resourceLoader);

		URL resourceURL = resourceLoader.getResource(qualifiedName);
		if (resourceURL != null) {
			try {
				Path location = new Path(resourceURL.toURI().getPath());
				if (ResourcesPlugin.getWorkspace().getRoot().getLocation().isPrefixOf(location)) {
					return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location);
				}
				return getWorkspaceFileFromFileSystem(EFS.getStore(resourceURL.toURI()));
			} catch (URISyntaxException ex) {
				// Ignore exception
			} catch (CoreException ex) {
				// Ignore exception
			}
		}
		return null;
	}
Comment 3 Idrissa Dieng CLA 2011-05-13 08:48:23 EDT
(In reply to comment #2)
> (In reply to comment #1)
> > (In reply to comment #0)
> > > The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGroup#loadTemplate(IFile)
> > > method should allow loading files that are not in a project.
> > 
> > We have the same problem when loading external extension files with
> > org.eclipse.sphinx.xtendxpand.ui.groups.ExtensionGroup#loadExtensionFile(IFile).
> > 
> > The root cause is we search only in workspace location in the
> > org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String,
> > ResourceLoader) method.
> 
> I propose to modify the
> org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String,
> ResourceLoader) method like this:
> 
> public static IFile getUnderlyingFile(String qualifiedName, ResourceLoader
> resourceLoader) {
> Assert.isNotNull(resourceLoader);
> 
>         URL resourceURL = resourceLoader.getResource(qualifiedName);
>         if (resourceURL != null) {
>             try {
>                 Path location = new Path(resourceURL.toURI().getPath());
>                 if
> (ResourcesPlugin.getWorkspace().getRoot().getLocation().isPrefixOf(location)) {
>                     return
> ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location);
>                 }
>                 return
> getWorkspaceFileFromFileSystem(EFS.getStore(resourceURL.toURI()));
>             } catch (URISyntaxException ex) {
>                 // Ignore exception
>             } catch (CoreException ex) {
>                 // Ignore exception
>             }
>         }
>         return null;
>     }

public static IFile getWorkspaceFileFromFileSystem(IFileStore fileStore) {
		Assert.isNotNull(fileStore);

		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
		IFile[] files = workspaceRoot.findFilesForLocationURI(fileStore.toURI());
		if (files != null && files.length == 1) {
			return files[0];
		}
		return null;
	}
Comment 4 Stephan Eberle CLA 2011-05-13 09:10:02 EDT
(In reply to comment #3)
> public static IFile getWorkspaceFileFromFileSystem(IFileStore fileStore) {
>         Assert.isNotNull(fileStore);
> 
>         IWorkspaceRoot workspaceRoot =
> ResourcesPlugin.getWorkspace().getRoot();
>         IFile[] files =
> workspaceRoot.findFilesForLocationURI(fileStore.toURI());
>         if (files != null && files.length == 1) {
>             return files[0];
>         }
>         return null;
>     }

Looks like an interesting approach. Let's try to use it!

I'd just say that we don't need an extra getWorkspaceFileFromFileSystem() method for that purpose but should place the code directly into getUnderlyingFile().

And, in getUnderlyingFile(), instead of catch URISyntaxException, catch CoreException we should just code catch Exception.
Comment 5 Idrissa Dieng CLA 2011-05-16 03:58:38 EDT
Fixed as in the bug description.
Comment 6 Balazs Grill CLA 2021-07-14 02:17:19 EDT
Mass-closing Resolved tickets