Replaceable User Files

Revision as of 00:11, 26 September 2008 by Jfiat (Talk | contribs) (User Files)


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.

The advantages of such a mechanism are numerous; per-user configuration, user extensibility, customize/change an installation without touching the installation, augmenting the installation with additional files and folders, ...

User Files

User files and folders can replace or augment files found under the installation under $ISE_EIFFEL/studio. The following indicates the corresponding user paths to place installation user replacement/augment files (X.X indicates the Major.Minor version number of the compiler):

  • Under Windows the default location for Eiffel user files is %HOMEDRIVE%\%HOMEPATH%\My Documents\Eiffel X.X User Files\studio
  • Under Unix/Linux the default location is ~/.esXX/studio
  • Under Mac OS X the default location is ~/Eiffel X.X User Files/studio

If any of these location do not suit your needs, set the environment variable ISE_APP_DATA to point to the root user files folder. Defining ISE_APP_DATA means user replacement/augmented files will be located under $ISE_APP_DATA/studio.

To replace an install file with a user file simply mirror the directory structure found under $ISE_EIFFEL/studio in the user files folder, as explained above. Create or place a file with the same name in the user files respective folder and it will be utilized instead of the stock installed edition. It's that simple!

Information.png Note: If running a workbench version of EiffelStudio or the Eiffel compiler remember to place user files under the user file folder with a (workbench) suffix for Windows, and _wkbench" suffix for non Windows. I.E. Under Linux place user files under ~/.esXX_wkbench/studio instead of ~/.esXX/studio. If the $ISE_APP_DATA environment variable has been defined then the _wkbench suffix is not used because of the explicit use of an overriding the default value with an environment variable.

User Folders

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 in case of future changes.

Most classes can access a single per-process instance of EIFFEL_ENV through inheriting EIFFEL_LAYOUT and accessing eiffel_layout, or alternatively 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 the graphical EiffelStudio IDE or as a TTY compiler (b) there are performance overheads when 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 file or folder to a user file or folder; user_priority_file_name and user_priority_path for retrieving a user file location and a folder path respectively. These functions take an absolute 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 of utilizing user files as found in 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 from the installation. 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 instead of the replacing the content.