$:.push(File.dirname(__FILE__)) require 'rubygems' require 'rake/clean' require 'rake/tasklib' require 'zip/zipfilesystem' require 'net/http' require 'yaml' require 'optparse' require 'fileutils' require 'erb' require 'ftools' require 'uri' require 'asproject/version' require 'asproject_base' require 'platform.rb' require 'asproject_utils' require 'template_resolver' require 'path_finder' require 'project' require 'eclipse_project' require 'asproject_arguments' require 'asclass' require 'asclass_arguments' require 'test_suite_generator' require 'tasks/simple_resolver' require 'tasks/remote_file_task' require 'tasks/flash_log' require 'tasks/mtasc' require 'tasks/hamtasc' require 'tasks/flash_player' require 'tasks/swfmill_input_resolver' require 'tasks/swfmill_input' require 'tasks/swfmill' module AsProject class AsProject < AsProjectBase @@ASPROJECT_FILE_NAME = 'AsProject' @@TEMPLATE_TYPE = 'asproject' @@DEFAULT_TEMPLATES = ['as2', 'config', 'asunit25', 'fdt'] def initialize(args=nil) execute(args) end def execute(args=nil) begin @should_create_project = true @created_files = [] if(args.nil?) @execution_dir = Dir.pwd else @execution_dir = args.execution_dir @project_name = args.project_name end @path_finder = PathFinder.new(@execution_dir) parse_args(args) @resolver = AsProjectResolver.new(self) if(@arguments.copy_to_home) copy_templates_to_user_home end out '---------------------------' begin project = @path_finder.current_project @should_create_project = false msg = ">> Working in existing project #{project_name} at: " + project rescue if(@arguments.project_name == '') finish exit end msg = ">> Creating a new project at: #{@execution_dir}#{File::SEPARATOR}#{@project_name}" end out msg if(@arguments.project_name == '') @execution_dir = File.expand_path(@path_finder.current_project) @path_finder.execution_dir = @execution_dir @arguments.execution_dir = @execution_dir else create_project end if(@arguments.copy_to_project) copy_templates_to_project end copy_templates(@arguments.selected_templates) finish rescue ProjectError => e out e.message exit end end def parse_args args if(args.nil?) @arguments = ProjectArguments.new @arguments.should_create = @should_create_project @arguments.path_finder = @path_finder @arguments.default_templates = @@DEFAULT_TEMPLATES @arguments.project_templates = @path_finder.get_available_templates(@@TEMPLATE_TYPE) @arguments.execution_dir = @execution_dir @arguments.parse!(ARGV) if(@should_create_project) @project_name = @arguments.project_name end else @execution_dir = args.execution_dir @project_name = args.project_name @path_finder = PathFinder.new(@execution_dir) @arguments = args end end def create_project if(File.exists? project_path) if(@arguments.force?) msg = <> Deleted: [' + project_path + ']' else raise ProjectError.new('Was unable to create the project at: ' + project_path) end else raise ProjectError.new('Directory at ' + project_path + ' already exists, use -f (--force) option to clobber.') end end Dir.mkdir(project_path) @created_files << project_path # create_config_yaml end def copy_templates(templates, target=nil, type=nil, render=true) if(target.nil?) target = project_path end if(type.nil?) type = @@TEMPLATE_TYPE end templates.each do |template| @resolver.copy_files(@path_finder.get_template(type, template), target, render).each do |file| @created_files << file end end end def copy_templates_to_user_home(type=nil) if(type.nil?) copy_templates_to_user_home('asproject') copy_templates_to_user_home('asclass') return end user_templates = File.join(@path_finder.user_asproject_home, 'templates', type) templates = @path_finder.get_children(@path_finder.get_gem_template(type, '')) templates.each do |template| target = File.join(user_templates, template) if(!File.exists?(target)) File.makedirs(target) end @created_files << target @resolver.copy_files(@path_finder.get_gem_template(type, template), target, false).each do |file| @created_files << file end end end def copy_templates_to_project(type=nil) if(type.nil?) copy_templates_to_project('asproject') copy_templates_to_project('asclass') return end project_templates = File.join(project_path, 'config', 'templates', type) templates = @path_finder.get_available_templates(type) templates.each do |template| template_target = File.join(project_templates, template) if(!File.exists?(template_target)) File.makedirs(template_target) @created_files << template_target copy_templates(template, template_target, type, false) end end end def presumed_project_name e_project_name = eclipse_project_name if(!e_project_name.nil?) return e_project_name else return File.basename(@execution_dir) end end def eclipse_project_name if(File.exists?(File.join(@execution_dir, '.project'))) begin @eclipse_project = EclipseProject.new(@execution_dir) if(!@eclipse_project.project_name.nil?) return @eclipse_project.project_name end rescue return nil end end end def project_name return @project_name end def project_path return File.join(@execution_dir, @arguments.project_name) end end ####################################### # ignore_file? @@COPY_IGNORE_FILES = ['.', '..', '.svn', '.DS_Store', 'CVS', '.cvs' 'Thumbs.db', '.crap_file'] # Do not copy files found in the ignore_files list def AsProject.ignore_file? file @@COPY_IGNORE_FILES.each do |name| if(name == file) return true end end return false end ####################################### # AsProjectResolver class AsProjectResolver < TemplateResolver def initialize(context) super() @context = context end def instance_name return @context.uncapitalize(project_name) end def project_name @context.project_name end def project_path return @context.project_path end end end