note description : "Performs the creation of a blank project" legal: "See notice at end of class." status: "See notice at end of class." author : "Arnaud PICHERY [aranud@mail.dotcom.fr]" date : "$Date$" revision : "$Revision$" class BLANK_PROJECT_BUILDER inherit EB_ERROR_MANAGER SYSTEM_CONSTANTS export {NONE} all end EIFFEL_LAYOUT export {NONE} all end create make feature {NONE} -- Implementation make (a_system_name, a_root_class_name, a_root_cluster_name, a_root_feature_name: STRING; a_project_directory: PATH; a_scoop: BOOLEAN) -- Set up the blank ace builder to work with a system named -- `a_system_name' and a project located in `a_project_directory'. -- `a_root_class_name', `a_root_cluster_name' and `a_root_feature_name' are the root attribute names. local l_rexp: RX_PCRE_REGULAR_EXPRESSION l_root_class_file_name: STRING do system_name := a_system_name root_class_name := a_root_class_name root_cluster_name := a_root_cluster_name root_feature_name := a_root_feature_name project_directory := a_project_directory is_scoop := a_scoop -- Create the pathname of the ace file ace_filename := project_directory.extended (system_name.as_lower + "." + {EIFFEL_CONSTANTS}.config_extension) -- Create the pathname of the root class. create l_rexp.make l_rexp.compile ("^([a-zA-Z][a-zA-Z0-9_]*).*$") l_rexp.match (a_root_class_name.as_lower) check l_rexp.has_matched -- should always match because we already checked for a valid class type end l_root_class_file_name := create {STRING}.make_empty l_rexp.append_captured_substring_to_string (l_root_class_file_name, 1) root_class_filename := project_directory.extended (l_root_class_file_name + "." + eiffel_extension) end feature -- Access ace_filename: PATH -- Filename of the ace file for this project. root_class_filename: PATH -- Filename of the root class file for this project. is_scoop: BOOLEAN -- Is project SCOOP-capable? feature -- Basic operations. create_blank_project -- Create the default ace file and the default root class local ace_file_content: STRING do -- Create the ace file ace_file_content := default_config_file_contents process_ace_file_content (ace_file_content) save_ace_file_content (ace_file_content) -- Create the root class file create_root_class end feature {NONE} -- Implementation process_ace_file_content (contents: STRING) -- Process `contents': Fill in the blank with `system_name' and `project_directory'. require valid_contents: contents /= Void and then not contents.is_empty valid_system_name: system_name /= Void and then not system_name.is_empty valid_project_directory: project_directory /= Void and then not project_directory.is_empty local l_uuid: UUID_GENERATOR do create l_uuid contents.replace_substring_all ("$uuid", l_uuid.generate_uuid.out) contents.replace_substring_all ("$system_name", system_name) contents.replace_substring_all ("$root_class_name", root_class_name) contents.replace_substring_all ("$root_class_feature", root_feature_name) contents.replace_substring_all ("$root_cluster_name", root_cluster_name) contents.replace_substring_all ("$root_cluster_location", project_directory.name.as_string_8) -- FIXME: Unicode end save_ace_file_content (contents: STRING) -- Save the ace file `content' in the filename `ace_filename'. require valid_contents: contents /= Void local new_file: PLAIN_TEXT_FILE char: CHARACTER do create new_file.make_with_path (ace_filename) -- Create the ace file and save the content in it. new_file.open_write if not contents.is_empty then contents.replace_substring_all ("%R", "") new_file.put_string (contents) char := contents.item (contents.count) if {PLATFORM}.is_unix and then char /= '%N' and then char /= '%R' -- Add a carriage return like vi if there's none at -- the end then new_file.put_new_line end end new_file.close rescue add_error_message ( {STRING_32} "Unable to create or overwrite the ace file '"+ace_filename.name+"'%N% %Check your write permissions in this directory") end default_config_file_contents: STRING -- Contents of the default ace file local a_file: RAW_FILE do create a_file.make_with_path (default_config_file_path) a_file.open_read a_file.read_stream (a_file.count) a_file.close Result := a_file.last_string rescue add_error_message ( {STRING_32} "Unable to read the template ace file '" + default_config_file_path.name + {STRING_32}"'%N% %Check that the file exists and that you are allowed to read it.") end default_config_file_path: PATH -- Path to the default configuration file. do if is_scoop then Result := eiffel_layout.default_scoop_config_file_name else Result := eiffel_layout.default_config_file_name end end create_root_class -- Create the file named `root_class_filename' and flush the content -- of the default root class in it. local new_class: PLAIN_TEXT_FILE do create new_class.make_with_path (root_class_filename) if not new_class.exists then new_class.open_write new_class.put_string ( "note%N% %%Tdescription: %"" + system_name + " application root class%"%N% %%Tdate: %"$"+ "Date" + "$%"%N% %%Trevision: %"$" + "Revision" + "$%"%N% %%N% %class%N% %%T" + root_class_name + "%N% %%N% %inherit%N% %%TARGUMENTS_32%N% %%N% %create%N% %%T" + root_feature_name + "%N% %%N% %feature {NONE} -- Initialization%N% %%N% %%T" + root_feature_name + "%N% %%T%T%T-- Run application.%N% %%T%Tdo%N% %%T%T%T--| Add your code here%N% %%T%T%Tprint (%"Hello Eiffel World!%%N%")%N% %%T%Tend%N% %%Nend% %%N") new_class.close end rescue add_error_message ( {STRING_32} "Unable to create the root class file '"+ root_class_filename.name +"'%N% %Check your write permissions on this file and on this directory") end feature {NONE} -- Private attributes system_name: STRING -- Name of the system of the project to build. root_class_name: STRING -- Name of the system of the project to build. root_cluster_name: STRING -- Name of the system of the project to build. root_feature_name: STRING -- Name of the system of the project to build. project_directory: PATH; -- Location of the project to build. note copyright: "Copyright (c) 1984-2018, Eiffel Software" license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)" licensing_options: "http://www.eiffel.com/licensing" copying: "[ This file is part of Eiffel Software's Eiffel Development Environment. Eiffel Software's Eiffel Development Environment is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License (available at the URL listed under "license" above). Eiffel Software's Eiffel Development Environment is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Eiffel Software's Eiffel Development Environment; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ]" source: "[ Eiffel Software 5949 Hollister Ave., Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Website http://www.eiffel.com Customer support http://support.eiffel.com ]" end -- class BLANK_PROJECT_BUILDER