Class: Objctify::Command::This

Inherits:
Objctify::Command show all
Defined in:
lib/objctify/command/this.rb

Instance Method Summary collapse

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/objctify/command/this.rb', line 14

def run
  file_path = "#{Dir.pwd}/Objctifile"

  unless File.exist?(file_path)
    raise Objctify::Informative, "Couldn't find Objctifile"
  end

  file_contents = File.read(file_path)

  project = Context.new
  project.instance_eval(file_contents, file_path)

  if project.project_name_param.nil?
    raise Objctify::Informative, "Project name is not provided in Objctifile"
  end
  if project.java_sources_param.nil?
    raise Objctify::Informative, "Path to Java sources is not provided in Objctifile"
  end
  raise Objctify::Informative, "Provided Java sources directory does not exist: #{project.java_sources_param}" unless
      Dir.exist?(project.java_sources_param)

  framework_name = project.project_name_param
  java_sources = File.expand_path(project.java_sources_param)
  j2objc_home = File.expand_path(project.j2objc_config.distr_dir)

  raise Objctify::Informative, "J2ObjC home directory does not exist: #{j2objc_home}" unless
      Dir.exist?(j2objc_home)
  raise Objctify::Informative, "J2ObjC home directory doesn't contain j2objc: #{j2objc_home}" unless
      File.exist?("#{j2objc_home}/j2objc")

  unless project.j2objc_config.prefixes_file_path.nil?
    unless File.exist?(project.j2objc_config.prefixes_file_path)
      raise Objctify::Informative, "Specified prefixes files does not exist: #{project.j2objc_config.prefixes_file_path}"
    end

    prefix_file_path = File.expand_path(project.j2objc_config.prefixes_file_path)
  end

  Objctify::translate_files(java_sources, prefix_file_path, j2objc_home, framework_name, project.j2objc_config.extra_cli_args)
  puts 'Cleaning'
  Objctify::fix_imports(framework_name, prefix_file_path)
  puts 'Plumbing'
  Objctify::generate_project(framework_name, j2objc_home)
  puts 'Done'
end