Class: AsProject::AsProject

Inherits:
AsProjectBase show all
Defined in:
lib/asproject.rb

Constant Summary collapse

@@ASPROJECT_FILE_NAME =
'AsProject'
@@TEMPLATE_TYPE =
'asproject'
@@DEFAULT_TEMPLATES =
['as2', 'config', 'asunit25', 'fdt']

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AsProjectBase

#capitalize, #finish, #out, #put_created, #uncapitalize

Constructor Details

#initialize(args = nil) ⇒ AsProject

Returns a new instance of AsProject.



51
52
53
# File 'lib/asproject.rb', line 51

def initialize(args=nil)
  execute(args)
end

Class Method Details

.ignore_file?(file) ⇒ Boolean

Do not copy files found in the ignore_files list

Returns:

  • (Boolean)


243
244
245
246
247
248
249
250
# File 'lib/asproject.rb', line 243

def AsProject.ignore_file? file
  @@COPY_IGNORE_FILES.each do |name|
    if(name == file)
      return true
    end
  end
  return false
end

Instance Method Details

#copy_templates(templates, target = nil, type = nil, render = true) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/asproject.rb', line 156

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

#copy_templates_to_project(type = nil) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/asproject.rb', line 190

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

#copy_templates_to_user_home(type = nil) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/asproject.rb', line 170

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

#create_projectObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/asproject.rb', line 129

def create_project
  if(File.exists? project_path)
    if(@arguments.force?)
      msg = <<EOF

Are you sure you want to replace the entire directory at:
#{project_path}?

(y)es or (n)o
EOF
      out msg
      response = gets.chomp!
      if(response == 'y')
        FileUtils.rm_rf(project_path)
        out '>> 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

#eclipse_project_nameObject



217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/asproject.rb', line 217

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

#execute(args = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/asproject.rb', line 55

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

#parse_args(args) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/asproject.rb', line 109

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

#presumed_project_nameObject



208
209
210
211
212
213
214
215
# File 'lib/asproject.rb', line 208

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

#project_nameObject



230
231
232
# File 'lib/asproject.rb', line 230

def project_name
  return @project_name
end

#project_pathObject



234
235
236
# File 'lib/asproject.rb', line 234

def project_path
  return File.join(@execution_dir, @arguments.project_name)
end