objctify 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5c95f59ad2258c5a663594fe4d89293c2d10c4a1
4
- data.tar.gz: 64dcaa5dc1daa4d32bc96c7a20875e54065252d4
2
+ SHA256:
3
+ metadata.gz: a011b3ca7aac11ee55f7bcf54f7b62d896a2a0921595c254436fb23e8aaf3c18
4
+ data.tar.gz: 44ac8c35c6f70190b0ff1d5adce484d3ccd1a8bf5fc0eee4dbbcc3b2df7736d5
5
5
  SHA512:
6
- metadata.gz: e908bb6677129073525dd2d72ce52e7cc1fc1022804c64b1fc9d17eba5e2dcb4b950278791d8126c748decfbc15759fd820a6db0919edc12a12ee3307174ff86
7
- data.tar.gz: 7a0ba46525cdead779f0b9c34a7f0c0d50f916f61377c24b879dfdb2c65e5e9db5576b855b4c70f979650592365b8e5b11f2d77200529e7a7e00e54c8ae2e402
6
+ metadata.gz: 4c788b1f4c6a0ab256b72a828179be752a46cb6ff83913494dc96e053804816dd40b178fe89cf64b4ae707d48c30e4cf3035cb8c4c628f960f00ed1f7de2ddee
7
+ data.tar.gz: 21eaf4feeb10e03c9942af02e56d2f89b736c0c723331bfbd422001724811a03e6a7dc331c60f693f4083cc211696bd2e61abfd444e70b987fbfea42ddaf7fa9
data/LICENSE CHANGED
@@ -370,4 +370,4 @@ Exhibit B - "Incompatible With Secondary Licenses" Notice
370
370
  ---------------------------------------------------------
371
371
 
372
372
  This Source Code Form is "Incompatible With Secondary Licenses", as
373
- defined by the Mozilla Public License, v. 2.0.
373
+ defined by the Mozilla Public License, v. 2.0.
@@ -16,7 +16,7 @@ module Objctify
16
16
  self.abstract_command = true
17
17
  self.command = 'objctify'
18
18
  self.version = Objctify::VERSION
19
- self.description = 'Make life easier' #TODO
20
- self.plugin_prefixes = %w(claide objctify)
19
+ self.description = 'A tool'
20
+ self.plugin_prefixes = %w[claide objctify]
21
21
  end
22
22
  end
@@ -8,8 +8,8 @@
8
8
  module Objctify
9
9
  class Command
10
10
  class Init < Command
11
- self.summary = 'Creates xcodeproj from java sources with j2objc' #TODO
12
- self.description = 'Creates xcodeproj from java source with j2objc using configuration from Objctifile' #TODO
11
+ self.summary = 'Initialises an Objctifile in the current directory.'
12
+ self.description = 'Initialises an Objctifile in the current directory from a default template.'
13
13
 
14
14
  def run
15
15
  template_path = "#{File.dirname(__FILE__)}/../templates/Objctifile-template"
@@ -14,35 +14,42 @@ module Objctify
14
14
  def run
15
15
  file_path = "#{Dir.pwd}/Objctifile"
16
16
 
17
- raise Objctify::Informative, "Couldn't find Objctifile" unless File.exists?(file_path)
17
+ unless File.exist?(file_path)
18
+ raise Objctify::Informative, "Couldn't find Objctifile"
19
+ end
18
20
 
19
21
  file_contents = File.read(file_path)
20
22
 
21
23
  project = Context.new
22
24
  project.instance_eval(file_contents, file_path)
23
25
 
24
- raise Objctify::Informative, "Project name is not provided in Objctifile" unless
25
- project.project_name_param != nil
26
- raise Objctify::Informative, "Path to Java sources is not provided in Objctifile" unless
27
- project.java_sources_param != nil
26
+ if project.project_name_param.nil?
27
+ raise Objctify::Informative, "Project name is not provided in Objctifile"
28
+ end
29
+ if project.java_sources_param.nil?
30
+ raise Objctify::Informative, "Path to Java sources is not provided in Objctifile"
31
+ end
28
32
  raise Objctify::Informative, "Provided Java sources directory does not exist: #{project.java_sources_param}" unless
29
- Dir.exists?(project.java_sources_param)
33
+ Dir.exist?(project.java_sources_param)
30
34
 
31
35
  framework_name = project.project_name_param
32
36
  java_sources = File.expand_path(project.java_sources_param)
33
37
  j2objc_home = File.expand_path(project.j2objc_config.distr_dir)
34
38
 
35
39
  raise Objctify::Informative, "J2ObjC home directory does not exist: #{j2objc_home}" unless
36
- Dir.exists?(j2objc_home)
40
+ Dir.exist?(j2objc_home)
37
41
  raise Objctify::Informative, "J2ObjC home directory doesn't contain j2objc: #{j2objc_home}" unless
38
- File.exists?("#{j2objc_home}/j2objc")
42
+ File.exist?("#{j2objc_home}/j2objc")
39
43
 
40
44
  unless project.j2objc_config.prefixes_file_path.nil?
41
- raise Objctify::Informative, "Specified prefixes files does not exist: #{project.j2objc_config.prefixes_file_path}" unless File.exists?(project.j2objc_config.prefixes_file_path)
45
+ unless File.exist?(project.j2objc_config.prefixes_file_path)
46
+ raise Objctify::Informative, "Specified prefixes files does not exist: #{project.j2objc_config.prefixes_file_path}"
47
+ end
48
+
42
49
  prefix_file_path = File.expand_path(project.j2objc_config.prefixes_file_path)
43
50
  end
44
51
 
45
- Objctify::translate_files(java_sources, prefix_file_path, j2objc_home, framework_name)
52
+ Objctify::translate_files(java_sources, prefix_file_path, j2objc_home, framework_name, project.j2objc_config.extra_cli_args)
46
53
  puts 'Cleaning'
47
54
  Objctify::fix_imports(framework_name, prefix_file_path)
48
55
  puts 'Plumbing'
@@ -8,14 +8,14 @@
8
8
  module Objctify
9
9
  class Context
10
10
  class J2ObjCSettings
11
- attr_accessor :distr_dir, :prefixes_file_path
11
+ attr_accessor :distr_dir, :prefixes_file_path, :extra_cli_args
12
12
  end
13
13
 
14
- attr_accessor :project_name_param, :java_sources_param, :j2objc_config
14
+ attr_accessor :project_name_param, :java_sources_param
15
15
 
16
16
  def initialize
17
17
  @j2objc_config = J2ObjCSettings.new
18
- @project_name = ""
18
+ @project_name = ''
19
19
  end
20
20
 
21
21
  def project_name(project_name)
@@ -10,35 +10,35 @@ module Objctify
10
10
  def self.fix_imports(framework_name, prefix_file_path)
11
11
  prefixes = J2ObjCPrefixes.new(prefix_file_path)
12
12
 
13
- header_map = Hash.new
13
+ header_map = {}
14
14
  Dir.chdir(framework_name) do
15
- Pathname(".").find do |path|
15
+ Pathname('.').find do |path|
16
16
  dir, base = path.split
17
17
 
18
- if path.file?
19
- prefix = prefixes.prefix_for(path.dirname.to_s)
20
- path.rename(dir.to_s + '/' + prefix + base.to_s)
21
- header_map[path.to_s.sub("./", "")] = prefix + base.to_s
22
- end
18
+ next unless path.file?
19
+
20
+ prefix = prefixes.prefix_for(path.dirname.to_s)
21
+ path.rename(dir.to_s + '/' + prefix + base.to_s)
22
+ header_map[path.to_s.sub('./', '')] = prefix + base.to_s
23
23
  end
24
24
  end
25
25
 
26
26
  Dir.chdir(framework_name) do
27
- Pathname(".").find do |path|
28
- if path.file?
29
- import_reg_exp = /(#[a-zA-Z]+\s+"([a-zA-Z_0-9\/]+.[hm]{1})")/
27
+ Pathname('.').find do |path|
28
+ next unless path.file?
30
29
 
31
- text = File.read(path)
32
- text.scan(import_reg_exp).each { |import|
30
+ import_reg_exp = %r{(#[a-zA-Z]+\s+"([a-zA-Z_0-9/]+.[hm]{1})")}
33
31
 
34
- if (mapped_import = header_map[import[1]]) and !mapped_import.nil?
35
- text = text.gsub(import[1], mapped_import)
36
- end
37
- }
32
+ text = File.read(path)
33
+ text.scan(import_reg_exp).each do |import|
34
+
35
+ if (mapped_import = header_map[import[1]]) && !mapped_import.nil?
36
+ text = text.gsub(import[1], mapped_import)
37
+ end
38
+ end
38
39
 
39
- File.open(path, "w") { |f|
40
- f.write(text)
41
- }
40
+ File.open(path, 'w') do |f|
41
+ f.write(text)
42
42
  end
43
43
  end
44
44
  end
@@ -16,7 +16,7 @@ module Objctify
16
16
  source_build_phase = target.source_build_phase
17
17
  headers_build_phase = target.headers_build_phase
18
18
 
19
- #add files
19
+ #add files
20
20
  Pathname(framework_name).find do |path|
21
21
  dir, base = path.split
22
22
  if path.directory?
@@ -35,7 +35,7 @@ module Objctify
35
35
 
36
36
  if new_ref.last_known_file_type == 'sourcecode.c.h'
37
37
  build_file = headers_build_phase.add_file_reference new_ref
38
- build_file.settings = {"ATTRIBUTES" => ['', 'Public']}
38
+ build_file.settings = { ATTRIBUTES: ['', 'Public'] }
39
39
  elsif new_ref.last_known_file_type == 'sourcecode.c.objc'
40
40
  source_build_phase.add_file_reference new_ref
41
41
  end
@@ -45,7 +45,7 @@ module Objctify
45
45
 
46
46
  header_file_path = Pathname("#{framework_name}/#{framework_name}.h")
47
47
 
48
- File.open(header_file_path, "w") do |header_file|
48
+ File.open(header_file_path, 'w') do |header_file|
49
49
  header_template = "//
50
50
  // #{framework_name}.h
51
51
  // #{framework_name}
@@ -63,32 +63,32 @@ FOUNDATION_EXPORT const unsigned char #{framework_name}VersionString[];
63
63
  "
64
64
 
65
65
  header_file.write(header_template)
66
- header_file.write(headers_build_phase.files_references.map(&:path).map { |header_file_name| "#include <#{framework_name}/" + header_file_name + ">" } * "\n")
66
+ header_file.write(headers_build_phase.files_references.map(&:path).map { |header_file_name| "#include <#{framework_name}/" + header_file_name + '>' } * "\n")
67
67
  end
68
68
 
69
69
  dir, base = header_file_path.split
70
70
 
71
71
  header_file_ref = project[dir.to_s].new_reference base
72
72
  header_build_file = headers_build_phase.add_file_reference header_file_ref
73
- header_build_file.settings = {"ATTRIBUTES" => ['', 'Public']}
73
+ header_build_file.settings = { ATTRIBUTES: ['', 'Public'] }
74
74
 
75
75
  project.targets.each do |target|
76
- target.add_system_library_tbd(%w{z iconv})
77
- target.add_system_framework("UIKit")
76
+ target.add_system_library_tbd(%w[z iconv])
77
+ target.add_system_framework('UIKit')
78
78
 
79
79
  path = File.expand_path("#{j2objc_home}/frameworks/JRE.framework")
80
- unless ref = project.frameworks_group.find_file_by_path(path)
80
+ unless (ref = project.frameworks_group.find_file_by_path(path))
81
81
  ref = project.frameworks_group.new_file(path, :absolute)
82
82
  end
83
83
  target.frameworks_build_phase.add_file_reference(ref, true)
84
84
 
85
85
  target.build_configurations.each do |config|
86
- config.build_settings["CLANG_ENABLE_OBJC_ARC"] = false
87
- config.build_settings["FRAMEWORK_SEARCH_PATHS"] = "#{j2objc_home}/frameworks"
88
- config.build_settings["HEADER_SEARCH_PATHS"] = "#{j2objc_home}/frameworks/JRE.framework/Headers"
86
+ config.build_settings['CLANG_ENABLE_OBJC_ARC'] = false
87
+ config.build_settings['FRAMEWORK_SEARCH_PATHS'] = "#{j2objc_home}/frameworks"
88
+ config.build_settings['HEADER_SEARCH_PATHS'] = "#{j2objc_home}/frameworks/JRE.framework/Headers"
89
89
 
90
90
  # Workaround
91
- config.build_settings["SUPPORTS_MACCATALYST"] = false
91
+ config.build_settings['SUPPORTS_MACCATALYST'] = false
92
92
  end
93
93
  end
94
94
 
@@ -10,34 +10,32 @@ module Objctify
10
10
  Prefix = Struct.new(:prefix, :wildcard)
11
11
 
12
12
  def initialize(prefix_file_path)
13
- @prefixes = Hash.new
14
-
15
- if !prefix_file_path.nil? && File.exists?(prefix_file_path)
16
- File.open(prefix_file_path).each do |line|
17
- if (res = line.match(/([a-zA-Z.*]+):\s+([A-Z]+)/))
18
- key = res[1]
19
- @prefixes[key.gsub(".*", "")] = Prefix.new(res[2], key.include?("*"))
20
- end
13
+ @prefixes = {}
14
+
15
+ return unless !prefix_file_path.nil? && File.exist?(prefix_file_path)
16
+
17
+ File.open(prefix_file_path).each do |line|
18
+ if (res = line.match(/([a-zA-Z.*]+):\s+([A-Z]+)/))
19
+ key = res[1]
20
+ @prefixes[key.gsub('.*', '')] = Prefix.new(res[2], key.include?('*'))
21
21
  end
22
22
  end
23
23
  end
24
24
 
25
- def prefix_for(path)
26
- key = path.gsub("/", ".")
27
-
28
- # searching for direct prefix
29
- # Fallback to looking for wildcard. if found a wildcard return it, else prefix from path
30
- while key.length != 0 do
31
- @prefixes.keys.each { |p|
32
- if key == p
33
- return @prefixes[p].prefix
34
- end
35
- }
36
- key, match, suffix = key.rpartition('.')
37
- end
25
+ def prefix_for(path)
26
+ key = path.gsub('/', '.')
38
27
 
39
- path.gsub("./", "").gsub("/", ".").split(".").map { |s| s.capitalize } * ""
28
+ # searching for direct prefix
29
+ # Fallback to looking for wildcard. if found a wildcard return it, else prefix from path
30
+ until key.empty?
31
+ @prefixes.keys.each do |p|
32
+ return @prefixes[p].prefix if key == p
33
+ end
34
+ key, = key.rpartition('.')
40
35
  end
41
36
 
37
+ path.gsub('./', '').gsub('/', '.').split('.').map(&:capitalize) * ''
42
38
  end
39
+
43
40
  end
41
+ end
@@ -10,4 +10,5 @@
10
10
  j2objc_config do |j2objc_config|
11
11
  j2objc_config.distr_dir = "path_to_j2objc_distributive"
12
12
  # j2objc_config.prefixes_file_path = "path_to/prefixes.properties"
13
+ # j2objc_config.extra_cli_args = "-Xno-source-headers --strip-reflection"
13
14
  end
@@ -8,26 +8,32 @@
8
8
  module Objctify
9
9
 
10
10
  def self.collect_files(java_source_path)
11
- files_to_translate = ""
12
- Dir.glob(java_source_path + "/**/*.java") do |item|
13
- files_to_translate = files_to_translate + item + " "
11
+ files_to_translate = ''
12
+ Dir.glob(java_source_path + '/**/*.java') do |item|
13
+ files_to_translate = files_to_translate + item + ' '
14
14
  end
15
15
  files_to_translate
16
16
  end
17
17
 
18
- def self.translate_files(java_sources, prefix_file_path, j2objc_home, result_path)
18
+ def self.translate_files(java_sources, prefix_file_path, j2objc_home, result_path, extra_cli_args)
19
19
  files_to_translate = collect_files(java_sources)
20
20
 
21
- raise Objctify::Informative, "No files to translate, check 'java_sources' parameter in Objctifile" unless files_to_translate.length > 0
21
+ raise Objctify::Informative, "No files to translate, check 'java_sources' parameter in Objctifile" if files_to_translate.empty?
22
22
 
23
- j2objcCall = "#{j2objc_home}/j2objc -source 8 --swift-friendly -Xno-source-headers -l --strip-reflection -d #{result_path} -classpath j2objc-dist/lib/jsr305-3.0.0.jar -sourcepath #{java_sources}"
24
- unless prefix_file_path.nil? || prefix_file_path == ""
25
- j2objcCall += " --prefixes #{prefix_file_path}"
23
+ j2objc_call = compose_j2objc_call(java_sources, j2objc_home, prefix_file_path, result_path, extra_cli_args) + ' ' + files_to_translate
24
+ call = system(j2objc_call)
25
+
26
+ raise Objctify::Informative, "J2Objc call is unsuccessful: #{j2objc_call}" unless call
27
+ end
28
+
29
+ def self.compose_j2objc_call(java_sources, j2objc_home, prefix_file_path, result_path, extra_cli_args)
30
+ j2objc_call = "#{j2objc_home}/j2objc -source 8 --swift-friendly -l #{extra_cli_args} -d #{result_path} -classpath #{j2objc_home}/lib/jsr305-3.0.0.jar -sourcepath #{java_sources}"
31
+
32
+ unless prefix_file_path.nil? || prefix_file_path == ''
33
+ j2objc_call += " --prefixes #{prefix_file_path}"
26
34
  end
27
- j2objcCall += " #{files_to_translate}"
28
- call = system(j2objcCall)
29
35
 
30
- raise Objctify::Informative, "J2Objc call is unsuccessful: #{j2objcCall}" unless call
36
+ j2objc_call
31
37
  end
32
38
 
33
39
  end
@@ -6,5 +6,5 @@
6
6
  # file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
7
 
8
8
  module Objctify
9
- VERSION = "0.3.1".freeze
9
+ VERSION = "0.4.0".freeze
10
10
  end
@@ -1,13 +1,13 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "objctify/version"
3
+ require 'objctify/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "objctify"
6
+ spec.name = 'objctify'
7
7
  spec.version = Objctify::VERSION
8
8
  spec.license = 'MPL-2.0'
9
- spec.authors = ["Devexperts"]
10
- spec.email = ["opensource@devexperts.com"]
9
+ spec.authors = ['Devexperts']
10
+ spec.email = ['opensource@devexperts.com']
11
11
 
12
12
  spec.summary = %q{Automates translation of Java sources into Objective-C using J2ObjC tool by Google}
13
13
  spec.description = %q{A gem which helps you literally use Java on iOS. It is a wrapper of J2ObjC tool by Google, which handles the most of
@@ -18,13 +18,13 @@ routine actions. Basically it turns your Java sources into an iOS framework read
18
18
  f.match(%r{^(test|spec|features|pkg|example)/})
19
19
  end
20
20
  spec.executables = %w(objctify)
21
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
22
22
 
23
23
  spec.required_ruby_version = '>= 2.0.0'
24
24
 
25
25
  spec.add_dependency 'claide', '< 2.0', '>= 0.9.1'
26
26
  spec.add_dependency 'xcodeproj', '< 2.0.0', '>= 1.3.0'
27
27
 
28
- spec.add_development_dependency "bundler", "~> 1.16"
29
- spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
30
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: objctify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devexperts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-09 00:00:00.000000000 Z
11
+ date: 2020-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
18
- - !ruby/object:Gem::Version
19
- version: '2.0'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 0.9.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "<"
28
- - !ruby/object:Gem::Version
29
- version: '2.0'
30
27
  - - ">="
31
28
  - !ruby/object:Gem::Version
32
29
  version: 0.9.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: xcodeproj
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "<"
38
- - !ruby/object:Gem::Version
39
- version: 2.0.0
40
37
  - - ">="
41
38
  - !ruby/object:Gem::Version
42
39
  version: 1.3.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 2.0.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "<"
48
- - !ruby/object:Gem::Version
49
- version: 2.0.0
50
47
  - - ">="
51
48
  - !ruby/object:Gem::Version
52
49
  version: 1.3.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 2.0.0
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: bundler
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -127,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  requirements: []
130
- rubyforge_project:
131
- rubygems_version: 2.5.2.3
130
+ rubygems_version: 3.0.3
132
131
  signing_key:
133
132
  specification_version: 4
134
133
  summary: Automates translation of Java sources into Objective-C using J2ObjC tool