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

Bug 355820

Summary: [EGL] TemplateFactory#load changes the path from which templates are loaded
Product: [Modeling] Epsilon Reporter: Louis Rose <louis>
Component: CoreAssignee: Louis Rose <louis>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: dkolovos
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard: interim

Description Louis Rose CLA 2011-08-25 07:30:35 EDT
For the following directory structure:

Driver.egl
first/First.egl
second/Second.egl

where Driver.egl contains:

[%=TemplateFactory.load('first/First.egl').process()%]
[%=TemplateFactory.load('second/Second.egl').process()%]


EGL throws a FileNotFoundException, while trying to load 'second/Second.egl'. It appears that EGL is trying to load a template at 'first/second/Second.egl', which seems to indicate that TemplateFactory#load has the (counter-intuitive) side-effect of changing the location from which templates are loaded.
Comment 1 Louis Rose CLA 2011-08-25 07:32:32 EDT
This was caused by EglModule's execute method, which was calling TemplateFactory#setRoot whenever a template (or subtemplate) was executed. I've changed the execute method to only change the root of the TemplateFactory if it has not been set already (using a new method: TemplateFactory#initialiseRoot).

I've added a regression test to cover this: InvokingSubtemplates.java
Comment 2 Louis Rose CLA 2011-08-25 07:37:50 EDT
Fix committed to SVN.
Comment 3 Louis Rose CLA 2011-08-25 07:39:42 EDT
While this fix is in the oven, I think there is a workaround. At the very start of a main template, invoke the following operation to force EGL to resolve all templates relative to the directory containing the main template:

[% 
	operation ensureTemplatesAreResolvedRelativeToBaseTemplate() {
		// This is a temporary workaround, required for:
		//   - Epsilon 0.9.1.201107251201 (stable)
		//   - Epsilon 0.9.1.201107251210 (interim)
		// For more information, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=355820
		var baseUri = TemplateFactory.context.baseTemplate.uri;
		var baseDir = new Native("java.io.File")(baseUri).getParentFile();
		TemplateFactory.setTemplateRoot(baseDir.absolutePath);
	}
%]

This workaround won't be necessary once the fix makes it into the next interim / stable releases.
Comment 4 Dimitris Kolovos CLA 2012-11-08 16:19:43 EST
Fixed in 1.0