jaxb2ruby 0.0.1-java → 0.1.0-java

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: dc40239981acd3661e8242ccb2902b59ab764bf7
4
- data.tar.gz: af343089fe56230f70396608b57bb5c7165b11a1
2
+ SHA256:
3
+ metadata.gz: bb1fd551dd00e0f11c5af79ffa5958ee4b6116b68bcc56cd0781a11a08190bd7
4
+ data.tar.gz: 5c02c7b905a35092f6814195bdaf117437bdd35ceeb6c242d0938204fbdfd480
5
5
  SHA512:
6
- metadata.gz: 8bf71fe0df5b94ea3efe7ecd84dc076ada465b339dc20b1c3911ff6144e824329c621df25af4bfb54ca720f7d048aeb636e12eed8356bb52253b9c1bfe7d4efd
7
- data.tar.gz: b8b1c81d1c8896ff50a33f85e9df9213f265bbdff09e837bd556b1c8bed16ddf9b1e03190bc283c5ea0af9b4c3134faa562232827a186821b904d50afcd2c31a
6
+ metadata.gz: 4954e1af4ca3527efec5a9d6318587c0af5be537144d69dcda5286127c0749a0747b6cb96a7be7f89c3acf1b0c579c41b35770966a2160d1ab8b4f628ea1c5a4
7
+ data.tar.gz: '058c2bbe3b10b62e74e8e3649161d880ccd6764451cd9428797b8e8fc675491bcbe85a569f21ab9e7f14a9441dd89a567cc4d8781245729c59949af194136643'
data/bin/jaxb2ruby CHANGED
@@ -32,6 +32,10 @@ options = {}
32
32
  parser = OptionParser.new do |opts|
33
33
  opts.banner = "usage: #{File.basename($0)} [options] schema"
34
34
 
35
+ opts.on("-b", "--binding=FILE", "specify external bindings files (xjb). Each FILE must have its own -b.") do |opt|
36
+ (options[:bindings] ||= []).push(opt)
37
+ end
38
+
35
39
  opts.on("-c", "--classes=MAP1[,MAP2,...]", Array, "XML Schema type to Ruby class mappings", "MAP can be a string in the form type=class or a YAML file of type/class pairs") do |typemap|
36
40
  options[:typemap] = mapping_option(typemap)
37
41
  end
@@ -69,6 +73,10 @@ parser = OptionParser.new do |opts|
69
73
  opts.on("-w", "--wsdl", "Treat the schema as a WSDL", "Automatically set if the schema has a `.wsdl' extension") do
70
74
  options[:wsdl] = true
71
75
  end
76
+
77
+ opts.on("-x", "--xjc=PATH", "Path to the XJC executable to use; defaults to xjc") do |path|
78
+ options[:xjc] = path
79
+ end
72
80
  end
73
81
 
74
82
  parser.parse!
@@ -85,6 +93,5 @@ begin
85
93
  File.open(File.join(outdir, klass.path), "w") { |io| io.puts template.build(klass) }
86
94
  end
87
95
  rescue => e
88
- puts e.backtrace.join("\n")
89
96
  abort "class generation failed: #{e}"
90
97
  end
@@ -168,11 +168,6 @@ module JAXB2Ruby
168
168
  # Paths for all of this class's dependencies, for passing to +require+.
169
169
  #
170
170
  def requires
171
- # p @element
172
- # p @module
173
- # @dependencies.each { |e| p e }
174
- # p "-" * 20
175
-
176
171
  @requires ||= @dependencies.map { |e| make_path(e.split(RUBY_PKG_SEP)) }.sort.uniq
177
172
  end
178
173
 
@@ -16,7 +16,7 @@ module JAXB2Ruby
16
16
 
17
17
  def initialize(schema, options = {})
18
18
  raise ArgumentError, "cannot access schema: #{schema}" unless File.file?(schema) and File.readable?(schema)
19
- @xjc = XJC.new(schema, :wsdl => !!options[:wsdl], :jvm => options[:jvm])
19
+ @xjc = XJC.new(schema, :xjc => options[:xjc], :wsdl => !!options[:wsdl], :jvm => options[:jvm], bindings: options[:bindings])
20
20
 
21
21
  @namespace = options[:namespace] || {}
22
22
  raise ArgumentError, "namespace mapping must be a Hash" unless @namespace.is_a?(Hash)
@@ -72,7 +72,7 @@ module JAXB2Ruby
72
72
  end
73
73
 
74
74
  def find_namespace(klass)
75
- annot = klass.annotation(javax.xml.bind.annotation.XmlRootElement.java_class) || klass.annotation(javax.xml.bind.annotation.XmlType.java_class)
75
+ annot = klass.get_annotation(javax.xml.bind.annotation.XmlRootElement.java_class) || klass.get_annotation(javax.xml.bind.annotation.XmlType.java_class)
76
76
  return unless annot
77
77
 
78
78
  # if klass is an inner class the namespace will be on the outter class (enclosing_class).
@@ -83,7 +83,7 @@ module JAXB2Ruby
83
83
 
84
84
  def translate_type(klass)
85
85
  # Won't work for extract_class() as it expects an instance but this should be split anyways
86
- return "Object" if klass.java_kind_of?(java.lang.reflect.WildcardType)
86
+ return "Object" if klass.kind_of?(java.lang.reflect.WildcardType)
87
87
 
88
88
  type = @typemap.java2ruby(klass.name)
89
89
  return type if type
@@ -107,12 +107,12 @@ module JAXB2Ruby
107
107
  resolved_type = []
108
108
  type = field.generic_type
109
109
 
110
- if type.java_kind_of?(java.lang.reflect.ParameterizedType)
110
+ if type.kind_of?(java.lang.reflect.ParameterizedType)
111
111
  type = type.actual_type_arguments.first
112
112
 
113
- if type.java_kind_of?(java.lang.reflect.ParameterizedType)
113
+ if type.kind_of?(java.lang.reflect.ParameterizedType)
114
114
  resolved_type << translate_type(type.actual_type_arguments.first)
115
- # elsif type.java_kind_of?(java.lang.reflect.WildcardType)
115
+ # elsif type.kind_of?(java.lang.reflect.WildcardType)
116
116
  # type.get_upper_bounds.each do |lower|
117
117
  # end
118
118
  # type.get_lower_bounds.each do |upper|
@@ -149,7 +149,6 @@ module JAXB2Ruby
149
149
  # If a node's type isn't predefined, it must be an XML mapped class
150
150
  dependencies << node.type if !@typemap.schema_ruby_types.include?(node.type)
151
151
  end
152
- #p "-" * 20
153
152
 
154
153
  RubyClass.new(type, element, dependencies, superclass)
155
154
  end
@@ -196,7 +195,6 @@ module JAXB2Ruby
196
195
 
197
196
  # Create an element from a Java class, turning its fields into elements and attributes
198
197
  def extract_element(klass)
199
- #p klass
200
198
  options = extract_elements_nodes(klass)
201
199
 
202
200
  if annot = klass.get_annotation(javax.xml.bind.annotation.XmlRootElement.java_class)
@@ -204,9 +202,6 @@ module JAXB2Ruby
204
202
  options[:root] = true
205
203
  end
206
204
 
207
-
208
-
209
-
210
205
  if name.blank?
211
206
  annot = klass.get_annotation(javax.xml.bind.annotation.XmlType.java_class)
212
207
  name = annot.name
@@ -220,14 +215,7 @@ module JAXB2Ruby
220
215
  # element.elements.sort_by! { |e| annot.prop_order.index }
221
216
  options[:namespace] = extract_namespace(annot)
222
217
 
223
- #p "name2 #{name}"
224
- #p options
225
- e=Element.new(name, options)
226
- #p e.name
227
- #p e.local_name
228
- #p e.namespace
229
- #p "-" * 20
230
- e
218
+ Element.new(name, options)
231
219
  end
232
220
 
233
221
  def valid_class?(klass)
@@ -4,8 +4,7 @@ module JAXB2Ruby
4
4
  class Template # :nodoc:
5
5
  HEADING=<<HEAD
6
6
  #
7
- # Auto-generated by jaxb2ruby v<%= VERSION %> on <%= Time.now %>
8
- # https://github.com/sshaw/jaxb2ruby
7
+ # Auto-generated by jaxb2ruby https://github.com/sshaw/jaxb2ruby
9
8
  #
10
9
  HEAD
11
10
 
@@ -20,7 +19,7 @@ HEAD
20
19
  def initialize(name = nil)
21
20
  # If it's not a named template assume it's a path
22
21
  path = PATHS[name] || name || DEFAULT
23
- @__erb = ERB.new(HEADING + File.read(path), nil, "<>%-")
22
+ @__erb = ERB.new(HEADING + File.read(path), nil, "-")
24
23
  rescue => e
25
24
  raise Error, "cannot load class template: #{e}"
26
25
  end
@@ -1,3 +1,3 @@
1
1
  module JAXB2Ruby
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/jaxb2ruby/xjc.rb CHANGED
@@ -32,9 +32,11 @@ module JAXB2Ruby
32
32
 
33
33
  def xjc
34
34
  options = @schema.end_with?(".wsdl") || @options[:wsdl] ? "-wsdl " : ""
35
- options << "-extension -npa -d :sources :schema -b :config"
35
+ bindings = (@options[:bindings] || []).map { |binding| "-b #{binding}"}.join(" ")
36
+ options << "-extension -npa -d :sources :schema -b :config #{bindings}"
36
37
  options << @options[:jvm].map { |opt| " -J#{opt}" }.join(" ") if @options[:jvm]
37
- line = Cocaine::CommandLine.new("xjc", options)
38
+
39
+ line = Cocaine::CommandLine.new(@options[:xjc] || "xjc", options)
38
40
  line.run(:schema => @schema, :sources => @sources, :config => CONFIG)
39
41
  rescue Cocaine::ExitStatusError => e
40
42
  raise Error, "xjc execution failed: #{e}"
@@ -2,6 +2,29 @@ require "spec_helper"
2
2
  require "jaxb2ruby/type_util"
3
3
 
4
4
  describe JAXB2Ruby::Converter do
5
+ it "errors when there elements with names causing a collision" do
6
+ assert_raises do
7
+ convert("conflict")
8
+ end
9
+ end
10
+
11
+ it "optionally accepts xjb files for binding" do
12
+ path = File.expand_path("../fixtures/conflict_binding.xjb", __FILE__)
13
+ hash = class_hash(convert("conflict", bindings: [path]))
14
+
15
+ _(hash["A"]).must_be_instance_of(JAXB2Ruby::RubyClass)
16
+ element_a = hash['A'].element.children.first
17
+ _(element_a).must_be_instance_of(JAXB2Ruby::Element)
18
+ _(element_a.accessor).must_equal('value')
19
+ _(element_a.type).must_equal('String')
20
+
21
+ _(hash["B"]).must_be_instance_of(JAXB2Ruby::RubyClass)
22
+ element_b = hash['B'].element.children.first
23
+ _(element_b).must_be_instance_of(JAXB2Ruby::Element)
24
+ _(element_b.accessor).must_equal('value')
25
+ _(element_b.type).must_equal('Float')
26
+ end
27
+
5
28
  it "creates ruby classes" do
6
29
  classes = convert("address")
7
30
  classes.size.must_equal(2)
metadata CHANGED
@@ -1,57 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jaxb2ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: java
6
6
  authors:
7
7
  - Skye Shaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-13 00:00:00.000000000 Z
11
+ date: 2023-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - '>='
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
18
  version: '3.2'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '7'
19
22
  name: activesupport
20
23
  prerelease: false
21
24
  type: :runtime
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - '>='
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
27
33
  - !ruby/object:Gem::Dependency
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
- - - ~>
36
+ - - '='
31
37
  - !ruby/object:Gem::Version
32
- version: 0.5.4
38
+ version: 0.5.8
33
39
  name: cocaine
34
40
  prerelease: false
35
41
  type: :runtime
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - ~>
44
+ - - '='
39
45
  - !ruby/object:Gem::Version
40
- version: 0.5.4
46
+ version: 0.5.8
41
47
  - !ruby/object:Gem::Dependency
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
- - - ~>
50
+ - - "~>"
45
51
  - !ruby/object:Gem::Version
46
- version: '10.0'
52
+ version: '13.0'
47
53
  name: rake
48
54
  prerelease: false
49
55
  type: :development
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - ~>
58
+ - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '10.0'
60
+ version: '13.0'
55
61
  description: |2
56
62
  jaxb2ruby generates Java XML mappings via xjc, reads the resulting annotations, and passes the
57
63
  extracted info to an ERB template. This allows one to automatically map an XML schema to pure
@@ -87,27 +93,26 @@ licenses:
87
93
  metadata: {}
88
94
  post_install_message:
89
95
  rdoc_options:
90
- - -m
96
+ - "-m"
91
97
  - README.rd
92
98
  require_paths:
93
99
  - lib
94
100
  required_ruby_version: !ruby/object:Gem::Requirement
95
101
  requirements:
96
- - - <
102
+ - - ">"
97
103
  - !ruby/object:Gem::Version
98
- version: '2.0'
104
+ version: '2.6'
99
105
  required_rubygems_version: !ruby/object:Gem::Requirement
100
106
  requirements:
101
- - - '>='
107
+ - - ">="
102
108
  - !ruby/object:Gem::Version
103
109
  version: '0'
104
110
  requirements: []
105
- rubyforge_project:
106
- rubygems_version: 2.4.5
111
+ rubygems_version: 3.2.33
107
112
  signing_key:
108
113
  specification_version: 4
109
114
  summary: Generate pure Ruby classes from an XML schema using JAXB and JRuby
110
115
  test_files:
111
- - spec/converter_spec.rb
112
116
  - spec/spec_helper.rb
117
+ - spec/converter_spec.rb
113
118
  - spec/template_spec.rb