Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 346383

Summary: [M2x IDE Integration] Simplfy the implementation of org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil.getUnderlyingFile(String, ResourceLoader) method & Add JUnit and Integration tests for testing this method
Product: [Automotive] Sphinx Reporter: Idrissa Dieng <idydieng>
Component: CoreAssignee: Idrissa Dieng <idydieng>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: ali.akar82, idydieng, r.sezestre, stephaneberle9
Version: 0.7.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Idrissa Dieng CLA 2011-05-19 04:07:11 EDT
The implementation of the org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil.getUnderlyingFile(String, ResourceLoader) method should be simply in order to manage in the same way:
 - a linked file (located outsite of the workspace),
 - a file containing in a linked folder (located outsite of the workspace),
 - a file located in the workspace.

The nemwly code is:

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

	URL resourceURL = resourceLoader.getResource(qualifiedName);
	if (resourceURL != null) {
		try {
			IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	// Checks whether there given file store points to a file in the workspace
			IFileStore fileStore = EFS.getStore(resourceURL.toURI());
			if (fileStore != null) {
				IFile[] files = workspaceRoot.findFilesForLocationURI(fileStore.toURI());
				if (files != null && files.length > 0) {
				// Returns the first workspace file that match
					return files[0];
				}
			}
		} catch (Exception ex) {
			// Ignore exception
		}
	}
	return null;
}

We shoul add also JUnit and Integration tests for testing this method.
Comment 1 Stephan Eberle CLA 2011-05-19 04:49:55 EDT
(In reply to comment #0)
>  - a linked file (located outsite of the workspace),
>  - a file containing in a linked folder (located outsite of the workspace),
>  - a file located in the workspace.

Some JavaDoc should be added explaining these facts.

>             IFileStore fileStore = EFS.getStore(resourceURL.toURI());
>             if (fileStore != null) {
>                 IFile[] files =
> workspaceRoot.findFilesForLocationURI(fileStore.toURI());

Are you sure that we need the EFS.getStore() thing? We could try to pass the result of resourceURL.toURI() directly to workspaceRoot.findFilesForLocationURI().
Comment 2 Idrissa Dieng CLA 2011-05-19 05:14:17 EDT
(In reply to comment #1)
> (In reply to comment #0)
> >  - a linked file (located outsite of the workspace),
> >  - a file containing in a linked folder (located outsite of the workspace),
> >  - a file located in the workspace.
> 
> Some JavaDoc should be added explaining these facts.
> 
> >             IFileStore fileStore = EFS.getStore(resourceURL.toURI());
> >             if (fileStore != null) {
> >                 IFile[] files =
> > workspaceRoot.findFilesForLocationURI(fileStore.toURI());
> 
> Are you sure that we need the EFS.getStore() thing? We could try to pass the
> result of resourceURL.toURI() directly to
> workspaceRoot.findFilesForLocationURI().

yes you're right just following code is need:
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
				// Gets all files that are mapped in the current workspace to the given URI. The file search result
				// include files located in the current workspace and also linked files or files contained in a linked
				// folder that were located outside of the workspace.
				IFile[] files = workspaceRoot.findFilesForLocationURI(resourceURL.toURI());
Comment 3 Idrissa Dieng CLA 2011-07-28 05:29:21 EDT
Fixed but I leave the bug open until the availablity of JUnit and Integration tests for org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String,
ResourceLoader) method.
Comment 4 Idrissa Dieng CLA 2011-10-18 11:35:24 EDT
The JUnit test case for XtendXpandUtil#getUnderlyingFile(String,
ResourceLoader) method should be added for getting the underlying for following cases:

(1) linked file (located outsite of the current workspace)

(2) file located in the workspace.

Steps to do for (2):

* Copy the resource to be linked into working directory (using the org.eclipse.sphinx.testutils.TestFileAccessor.createWorkingCopyOfInputFile(String) method)

* Creates a linked file (from working directory) into transformXtendProject project

* Call XtendXpandUtil#getUnderlyingFile(String,
ResourceLoader) method and verify if every thing (e.g., path ect.) is OK
Comment 5 Idrissa Dieng CLA 2011-10-18 12:04:36 EDT
Fixed as bug description and comments
Comment 6 Balazs Grill CLA 2021-07-14 02:14:33 EDT
Mass-closing Resolved tickets