Difference between revisions of "Replaceable User Files"

m (Working with User Files)
m (Implementing User File Replacement)
Line 33: Line 33:
 
   require
 
   require
 
     is_valid_environment: is_valid_environment
 
     is_valid_environment: is_valid_environment
  local
 
    l_user: like user_priority_file_name
 
 
   once
 
   once
 
     create Result.make_from_string (eifinit_path)
 
     create Result.make_from_string (eifinit_path)
Line 42: Line 40:
 
     if is_user_files_supported then
 
     if is_user_files_supported then
 
         -- Check user override file.
 
         -- Check user override file.
       l_user := user_priority_file_name (Result, True)
+
       if {l_user: like user_priority_file_name} user_priority_file_name (Result, True) then
      if l_user /= Void and then (create {RAW_FILE}.make (l_user)).exists then
+
         Result := l_user
         Result = l_user
+
 
       end
 
       end
 
     end
 
     end
Line 52: Line 49:
 
</e>
 
</e>
  
In the example the path to ''general.cfg'' is built, which will be the normal default file used. A check is done to ensure the notion of user files is supported and being so, a check to see if there is a user specific version under the user folder. In the event that there is a user ''general.cfg'' file then it will be taken over the installed ''general.cfg''. In the example above the first argument represents the string path to map to a specific user file and the second Boolean argument indicates if a user file name should only be returned if the file actually exists.
+
In the example the path to ''general.cfg'' is built, which will be the normal default file used. A check is done to ensure the notion of user files is supported and being so, a check to see if there is a user specific version under the user folder. In the event that there is a user ''general.cfg'' file then it will be taken over the installed ''general.cfg''. In the example above the first argument represents the string path to map to a specific user file and the second Boolean argument indicates if a user file name should only be returned if the file actually exist.
 +
 
 +
The use of <e>user_priority_path</e> is exactly the same way, but typically user folders are used to augment the contents of the respective installation folder.

Revision as of 09:59, 31 July 2008

Construction.png Not Ready for Review: This Page is Under Development!

With the release of EiffelStudio 6.2 came the notion of user files, or user replaceable files. These are configuration files and the like the end-user (that's you) can author to override a matching file found in the stock EiffelStudio installation.

Working with User Files

User Directories

In some cases, user files can be found in a user folder and will not be used to replace stock installation files but to augment a stock collection of files with a user set. This functionality can be found when working with code templates. Templates work a little differently because the folder under the installation does not have to be mirrored in the user files folder. Instead under the user folder there is a separate templates folder used to contain any and all code templates for tools like the contract tool and the editor.

Limitations

Not all files are currently supported with user files, just a select number of configuration files and template files. For all new developments, user files should be supported if applicable.

For now there is no support for those version of EiffelStudio built using the Unix Layout. Unix layouts distribute files across the system and prevent a clean and reliable means to replicate an EiffelStudio installation, required to detect and utilize user files/

Working with User Files

Most of the well know directories and files for the Eiffel compiler are located in a common class call EIFFEL_ENV, which is part of the environment library found in the EiffelStudio framework folder at $EIFFEL_SRC/framework/environment. There are effective implementations of EIFFEL_ENV; EC_EIFFEL_LAYOUT and ES_EIFFEL_LAYOUT used respectively in the Eiffel compiler and EiffelStudio.

Information.png Note: These classes need a little refactoring because most of the accessor functions live in EIFFEL_ENV instead of the more appropriate effective implementation class. It's just something to be aware of for future changes.

Most classes can access a single per-process instance of EIFFEL_ENV through inheriting EIFFEL_LAYOUT and accessing eiffel_layout or using it as a client. A single instance is used because (a) there are parts of the Eiffel system that have no idea if they are running inside EiffelStudio or as a TTY compiler (b) there are performance overheads of initializing EIFFEL_ENV so it's desirable to create and initialize the object once and once only.

EIFFEL_ENV contains the two necessary functions to map an installation path; user_priority_file_name and user_priority_path for retrieving a user file location and a folder path respectively. These functions take a path and return either an existing user based location or Void if no user specific file or folder was found.

Implementing User File Replacement

Here's an example from EIFFEL_ENV:

compiler_configuration: !FILE_NAME
    -- Platform specific system level resource specification file
  require
    is_valid_environment: is_valid_environment
  once
    create Result.make_from_string (eifinit_path)
    Result.set_file_name ("general")
    Result.add_extension ("cfg")
 
    if is_user_files_supported then
        -- Check user override file.
      if {l_user: like user_priority_file_name} user_priority_file_name (Result, True) then
        Result := l_user
      end
    end
  ensure
    not_result_is_empty: not Result.is_empty
  end

In the example the path to general.cfg is built, which will be the normal default file used. A check is done to ensure the notion of user files is supported and being so, a check to see if there is a user specific version under the user folder. In the event that there is a user general.cfg file then it will be taken over the installed general.cfg. In the example above the first argument represents the string path to map to a specific user file and the second Boolean argument indicates if a user file name should only be returned if the file actually exist.

The use of user_priority_path is exactly the same way, but typically user folders are used to augment the contents of the respective installation folder.