2626import org .eclipse .core .commands .ExecutionEvent ;
2727import org .eclipse .core .resources .IFile ;
2828import org .eclipse .core .runtime .CoreException ;
29+ import org .eclipse .core .runtime .IPath ;
2930import org .eclipse .core .runtime .IStatus ;
3031import org .eclipse .core .runtime .Platform ;
3132import org .eclipse .core .runtime .QualifiedName ;
@@ -82,7 +83,9 @@ public void run() {
8283 }
8384
8485 private void registerCustomGenerationVariables (ExecutionEvent event ) {
85- generator .registerCustomModelProperty ("projectname" , getSelectedFile (event ).getProject ().getName ());
86+ String projectName = getSelectedFile (event ).getProject ().getName ();
87+ generator .registerCustomModelProperty ("projectname" , projectName ); // for backwards compatibility
88+ generator .registerCustomModelProperty ("projectName" , projectName );
8689 Bundle contextMapperBundle = Platform .getBundle ("org.contextmapper.dsl.ui" );
8790 if (contextMapperBundle != null )
8891 generator .registerCustomModelProperty ("contextMapperVersion" , contextMapperBundle .getVersion ().toString ());
@@ -94,7 +97,8 @@ private GenerateGenericTextFileContext getLastStoredContext(ExecutionEvent event
9497 Map <QualifiedName , String > properties = selectedCmlFile .getPersistentProperties ();
9598 if (!properties .containsKey (getQualifiedName4File (selectedCmlFile , LAST_SELECTED_TEMPLATE_PROPERTY )))
9699 return context ;
97- IFile templateFile = findFileInContainer (selectedCmlFile .getProject (), properties .get (getQualifiedName4File (selectedCmlFile , LAST_SELECTED_TEMPLATE_PROPERTY )));
100+ IFile templateFile = findFileInContainer (selectedCmlFile .getWorkspace ().getRoot (),
101+ properties .get (getQualifiedName4File (selectedCmlFile , LAST_SELECTED_TEMPLATE_PROPERTY )));
98102 context .setFreemarkerTemplateFile (templateFile );
99103 if (properties .containsKey (getQualifiedName4File (selectedCmlFile , LAST_TARGET_FILE_NAME_PROPERTY )))
100104 context .setTargetFileName (properties .get (getQualifiedName4File (selectedCmlFile , LAST_TARGET_FILE_NAME_PROPERTY )));
@@ -106,8 +110,9 @@ private GenerateGenericTextFileContext getLastStoredContext(ExecutionEvent event
106110
107111 private void persistContext (GenerateGenericTextFileContext context ) {
108112 try {
113+ IFile templateFile = context .getFreemarkerTemplateFile ();
109114 selectedCmlFile .setPersistentProperty (getQualifiedName4File (selectedCmlFile , LAST_SELECTED_TEMPLATE_PROPERTY ),
110- context . getFreemarkerTemplateFile () .getProjectRelativePath ().toString ());
115+ templateFile . getProject (). getName () + IPath . SEPARATOR + templateFile .getProjectRelativePath ().toString ());
111116 selectedCmlFile .setPersistentProperty (getQualifiedName4File (selectedCmlFile , LAST_TARGET_FILE_NAME_PROPERTY ), context .getTargetFileName ());
112117 } catch (CoreException e ) {
113118 StatusManager .getManager ().handle (new Status (IStatus .ERROR , DslActivator .PLUGIN_ID , "Could not persist template file location." , e ));
0 commit comments