├── .classpath
├── .project
├── .settings
├── org.eclipse.jdt.core.prefs
└── org.eclipse.jdt.ui.prefs
├── JRubyForAndroid
├── AndroidManifest.xml
├── build.properties
├── build.xml
├── default.properties
├── libs
│ └── interpreter.jar
├── local.properties
├── res
│ ├── drawable
│ │ └── ruby_icon.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
├── ruboto-key.keystore
└── src
│ └── org
│ └── ruboto
│ └── sl4a
│ ├── JRubyDescriptor.java
│ ├── JRubyInstaller.java
│ ├── JRubyMain.java
│ ├── JRubyProvider.java
│ └── JRubyUninstaller.java
└── jruby-version-builder
├── README
├── Rakefile
├── android.rb
├── ase
└── scripts
│ ├── hello_world.rb
│ └── toggle_airplane.rb
├── current
├── VERSION.txt
├── jruby_extras.zip
└── jruby_scripts.zip
└── json
├── LICENSE
├── common.rb
├── json.rb
├── pure.rb
├── pure
├── generator.rb
└── parser.rb
└── version.rb
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | JRubyForAndroid
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Sat Jun 26 19:14:43 CEST 2010
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
4 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
5 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
6 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
7 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
8 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
9 | org.eclipse.jdt.core.formatter.alignment_for_assignment=16
10 | org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
11 | org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
12 | org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=16
13 | org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
14 | org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
15 | org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
16 | org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
17 | org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
18 | org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
19 | org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
20 | org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
21 | org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
22 | org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
23 | org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
24 | org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
25 | org.eclipse.jdt.core.formatter.blank_lines_after_package=1
26 | org.eclipse.jdt.core.formatter.blank_lines_before_field=0
27 | org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
28 | org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
29 | org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
30 | org.eclipse.jdt.core.formatter.blank_lines_before_method=1
31 | org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
32 | org.eclipse.jdt.core.formatter.blank_lines_before_package=0
33 | org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
34 | org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
35 | org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
36 | org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
37 | org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
38 | org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
39 | org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
40 | org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
41 | org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
42 | org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
43 | org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
44 | org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
45 | org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
46 | org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
47 | org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
48 | org.eclipse.jdt.core.formatter.comment.format_block_comments=true
49 | org.eclipse.jdt.core.formatter.comment.format_header=false
50 | org.eclipse.jdt.core.formatter.comment.format_html=true
51 | org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
52 | org.eclipse.jdt.core.formatter.comment.format_line_comments=true
53 | org.eclipse.jdt.core.formatter.comment.format_source_code=true
54 | org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
55 | org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
56 | org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
57 | org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
58 | org.eclipse.jdt.core.formatter.comment.line_length=100
59 | org.eclipse.jdt.core.formatter.compact_else_if=true
60 | org.eclipse.jdt.core.formatter.continuation_indentation=2
61 | org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=1
62 | org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
63 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
64 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
65 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
66 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
67 | org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
68 | org.eclipse.jdt.core.formatter.indent_empty_lines=false
69 | org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
70 | org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
71 | org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
72 | org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
73 | org.eclipse.jdt.core.formatter.indentation.size=8
74 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
75 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
76 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
77 | org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
78 | org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
79 | org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
80 | org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
81 | org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
82 | org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
83 | org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
84 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
85 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
86 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
87 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
88 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
89 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
90 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
91 | org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
92 | org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
93 | org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
94 | org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
95 | org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
96 | org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
97 | org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
98 | org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
99 | org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
100 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
101 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
102 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
103 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
104 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
105 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
106 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
107 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
108 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
109 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
110 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
111 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
112 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
113 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
114 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
115 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
116 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
117 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
118 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
119 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
120 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
121 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
122 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
123 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
124 | org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
125 | org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
126 | org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
127 | org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
128 | org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
129 | org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
130 | org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
131 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
132 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
133 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
134 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
135 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
136 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
137 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
138 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
139 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
140 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
141 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
142 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
143 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
144 | org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
145 | org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
146 | org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
147 | org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
148 | org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
149 | org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
150 | org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
151 | org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
152 | org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
153 | org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
154 | org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
155 | org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
156 | org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
157 | org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
158 | org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
159 | org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
160 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
161 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
162 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
163 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
164 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
165 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
166 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
167 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
168 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
169 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
170 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
171 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
172 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
173 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
174 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
175 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
176 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
177 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
178 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
179 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
180 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
181 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
182 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
183 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
184 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
185 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
186 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
187 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
188 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
189 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
190 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
191 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
192 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
193 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
194 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
195 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
196 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
197 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
198 | org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
199 | org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
200 | org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
201 | org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
202 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
203 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
204 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
205 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
206 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
207 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
208 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
209 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
210 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
211 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
212 | org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
213 | org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
214 | org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
215 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
216 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
217 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
218 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
219 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
220 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
221 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
222 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
223 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
224 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
225 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
226 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
227 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
228 | org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
229 | org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
230 | org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
231 | org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
232 | org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
233 | org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
234 | org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
235 | org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
236 | org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
237 | org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
238 | org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
239 | org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
240 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
241 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
242 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
243 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
244 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
245 | org.eclipse.jdt.core.formatter.join_lines_in_comments=true
246 | org.eclipse.jdt.core.formatter.join_wrapped_lines=true
247 | org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
248 | org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
249 | org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
250 | org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
251 | org.eclipse.jdt.core.formatter.lineSplit=100
252 | org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
253 | org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
254 | org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
255 | org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
256 | org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
257 | org.eclipse.jdt.core.formatter.tabulation.char=space
258 | org.eclipse.jdt.core.formatter.tabulation.size=2
259 | org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=true
260 | org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
261 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | #Thu Aug 19 21:59:19 CEST 2010
2 | cleanup.add_default_serial_version_id=true
3 | cleanup.add_generated_serial_version_id=false
4 | cleanup.add_missing_annotations=true
5 | cleanup.add_missing_deprecated_annotations=true
6 | cleanup.add_missing_methods=false
7 | cleanup.add_missing_nls_tags=false
8 | cleanup.add_missing_override_annotations=true
9 | cleanup.add_serial_version_id=false
10 | cleanup.always_use_blocks=true
11 | cleanup.always_use_parentheses_in_expressions=false
12 | cleanup.always_use_this_for_non_static_field_access=false
13 | cleanup.always_use_this_for_non_static_method_access=false
14 | cleanup.convert_to_enhanced_for_loop=false
15 | cleanup.correct_indentation=true
16 | cleanup.format_source_code=true
17 | cleanup.format_source_code_changes_only=false
18 | cleanup.make_local_variable_final=true
19 | cleanup.make_parameters_final=false
20 | cleanup.make_private_fields_final=true
21 | cleanup.make_type_abstract_if_missing_method=false
22 | cleanup.make_variable_declarations_final=false
23 | cleanup.never_use_blocks=false
24 | cleanup.never_use_parentheses_in_expressions=true
25 | cleanup.organize_imports=true
26 | cleanup.qualify_static_field_accesses_with_declaring_class=false
27 | cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
28 | cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
29 | cleanup.qualify_static_member_accesses_with_declaring_class=true
30 | cleanup.qualify_static_method_accesses_with_declaring_class=false
31 | cleanup.remove_private_constructors=true
32 | cleanup.remove_trailing_whitespaces=true
33 | cleanup.remove_trailing_whitespaces_all=true
34 | cleanup.remove_trailing_whitespaces_ignore_empty=false
35 | cleanup.remove_unnecessary_casts=true
36 | cleanup.remove_unnecessary_nls_tags=true
37 | cleanup.remove_unused_imports=true
38 | cleanup.remove_unused_local_variables=true
39 | cleanup.remove_unused_private_fields=true
40 | cleanup.remove_unused_private_members=false
41 | cleanup.remove_unused_private_methods=true
42 | cleanup.remove_unused_private_types=true
43 | cleanup.sort_members=false
44 | cleanup.sort_members_all=false
45 | cleanup.use_blocks=true
46 | cleanup.use_blocks_only_for_return_and_throw=false
47 | cleanup.use_parentheses_in_expressions=false
48 | cleanup.use_this_for_non_static_field_access=true
49 | cleanup.use_this_for_non_static_field_access_only_if_necessary=true
50 | cleanup.use_this_for_non_static_method_access=true
51 | cleanup.use_this_for_non_static_method_access_only_if_necessary=true
52 | cleanup_profile=_ASE
53 | cleanup_settings_version=2
54 | eclipse.preferences.version=1
55 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
56 | formatter_profile=_ASE
57 | formatter_settings_version=11
58 | org.eclipse.jdt.ui.ignorelowercasenames=true
59 | org.eclipse.jdt.ui.importorder=com;java;javax;org;
60 | org.eclipse.jdt.ui.ondemandthreshold=99
61 | org.eclipse.jdt.ui.staticondemandthreshold=99
62 | sp_cleanup.add_default_serial_version_id=true
63 | sp_cleanup.add_generated_serial_version_id=false
64 | sp_cleanup.add_missing_annotations=true
65 | sp_cleanup.add_missing_deprecated_annotations=true
66 | sp_cleanup.add_missing_methods=false
67 | sp_cleanup.add_missing_nls_tags=false
68 | sp_cleanup.add_missing_override_annotations=true
69 | sp_cleanup.add_serial_version_id=false
70 | sp_cleanup.always_use_blocks=true
71 | sp_cleanup.always_use_parentheses_in_expressions=false
72 | sp_cleanup.always_use_this_for_non_static_field_access=false
73 | sp_cleanup.always_use_this_for_non_static_method_access=false
74 | sp_cleanup.convert_to_enhanced_for_loop=false
75 | sp_cleanup.correct_indentation=true
76 | sp_cleanup.format_source_code=true
77 | sp_cleanup.format_source_code_changes_only=false
78 | sp_cleanup.make_local_variable_final=false
79 | sp_cleanup.make_parameters_final=false
80 | sp_cleanup.make_private_fields_final=true
81 | sp_cleanup.make_type_abstract_if_missing_method=false
82 | sp_cleanup.make_variable_declarations_final=false
83 | sp_cleanup.never_use_blocks=false
84 | sp_cleanup.never_use_parentheses_in_expressions=true
85 | sp_cleanup.on_save_use_additional_actions=true
86 | sp_cleanup.organize_imports=true
87 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
88 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
89 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
90 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
91 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
92 | sp_cleanup.remove_private_constructors=true
93 | sp_cleanup.remove_trailing_whitespaces=true
94 | sp_cleanup.remove_trailing_whitespaces_all=true
95 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
96 | sp_cleanup.remove_unnecessary_casts=true
97 | sp_cleanup.remove_unnecessary_nls_tags=false
98 | sp_cleanup.remove_unused_imports=true
99 | sp_cleanup.remove_unused_local_variables=true
100 | sp_cleanup.remove_unused_private_fields=true
101 | sp_cleanup.remove_unused_private_members=false
102 | sp_cleanup.remove_unused_private_methods=true
103 | sp_cleanup.remove_unused_private_types=true
104 | sp_cleanup.sort_members=false
105 | sp_cleanup.sort_members_all=false
106 | sp_cleanup.use_blocks=true
107 | sp_cleanup.use_blocks_only_for_return_and_throw=false
108 | sp_cleanup.use_parentheses_in_expressions=false
109 | sp_cleanup.use_this_for_non_static_field_access=true
110 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
111 | sp_cleanup.use_this_for_non_static_method_access=true
112 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
113 |
--------------------------------------------------------------------------------
/JRubyForAndroid/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/JRubyForAndroid/build.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked in Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 | key.store=ruboto-key.keystore
18 | key.alias=ruboto
19 | key.store.password=ruboto
20 | key.alias.password=ruboto
21 |
22 |
--------------------------------------------------------------------------------
/JRubyForAndroid/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
27 |
28 |
29 |
33 |
34 |
35 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
47 |
48 |
50 |
62 |
63 |
64 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/JRubyForAndroid/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-3
12 |
--------------------------------------------------------------------------------
/JRubyForAndroid/libs/interpreter.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruboto/sl4a_jruby_interpreter/6c14cc1c3139558faccf628e8c1f7ed4291d4d39/JRubyForAndroid/libs/interpreter.jar
--------------------------------------------------------------------------------
/JRubyForAndroid/local.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked in Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 |
7 | # location of the SDK. This is only used by Ant
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | sdk.dir=/usr/local/lib/android-sdk-linux_86
11 |
--------------------------------------------------------------------------------
/JRubyForAndroid/res/drawable/ruby_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruboto/sl4a_jruby_interpreter/6c14cc1c3139558faccf628e8c1f7ed4291d4d39/JRubyForAndroid/res/drawable/ruby_icon.png
--------------------------------------------------------------------------------
/JRubyForAndroid/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
--------------------------------------------------------------------------------
/JRubyForAndroid/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | JRuby for Android
4 |
5 |
--------------------------------------------------------------------------------
/JRubyForAndroid/ruboto-key.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruboto/sl4a_jruby_interpreter/6c14cc1c3139558faccf628e8c1f7ed4291d4d39/JRubyForAndroid/ruboto-key.keystore
--------------------------------------------------------------------------------
/JRubyForAndroid/src/org/ruboto/sl4a/JRubyDescriptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file was modified from a code in the SL4A project:
3 | * http://code.google.com/p/android-scripting/
4 | *
5 | * The modifications are designed to move maintenance for
6 | * JRuby's interpreter for SL4A over to the Rubot Community.
7 | *
8 | * The original license follows:
9 | *
10 | * Copyright (C) 2009 Google Inc.
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
13 | * use this file except in compliance with the License. You may obtain a copy of
14 | * the License at
15 | *
16 | * http://www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
21 | * License for the specific language governing permissions and limitations under
22 | * the License.
23 | */
24 |
25 | package org.ruboto.sl4a;
26 |
27 | import java.io.File;
28 | import java.util.Arrays;
29 | import java.util.HashMap;
30 | import java.util.List;
31 | import java.util.Map;
32 |
33 | import android.content.Context;
34 |
35 | import com.googlecode.android_scripting.interpreter.InterpreterUtils;
36 | import com.googlecode.android_scripting.interpreter.InterpreterConstants;
37 | import com.googlecode.android_scripting.interpreter.InterpreterDescriptor;
38 |
39 | public class JRubyDescriptor implements InterpreterDescriptor {
40 |
41 | private static final String JRUBY_PREFIX =
42 | "-e $LOAD_PATH.push('file:%1$s!/META-INF/jruby.home/lib/ruby/1.8'); require 'android'; %2$s";
43 | private static final String JRUBY_JAR = "jruby.jar";
44 | private static final String ENV_DATA = "ANDROID_DATA";
45 |
46 | public static final String BASE_INSTALL_URL = "https://github.com/ruboto/sl4a_jruby_interpreter/raw/master/jruby-version-builder/current/";
47 | public static final String DALVIKVM = "/system/bin/dalvikvm";
48 |
49 | public String getExtension() {
50 | return ".rb";
51 | }
52 |
53 | public String getName() {
54 | return "jruby";
55 | }
56 |
57 | public String getNiceName() {
58 | return "JRuby";
59 | }
60 |
61 | public boolean hasInterpreterArchive() {
62 | return false;
63 | }
64 |
65 | public boolean hasExtrasArchive() {
66 | return true;
67 | }
68 |
69 | public boolean hasScriptsArchive() {
70 | return true;
71 | }
72 |
73 | public boolean hasInteractiveMode() {
74 | return true;
75 | }
76 |
77 | public int getVersion() {
78 | return 3;
79 | }
80 |
81 | public int getInterpreterVersion() {
82 | return getVersion();
83 | }
84 |
85 | public int getExtrasVersion() {
86 | return getVersion();
87 | }
88 |
89 | public int getScriptsVersion() {
90 | return 1;
91 | }
92 |
93 | public String getInterpreterArchiveName() {
94 | return String.format("%s.zip", getName());
95 | }
96 |
97 | public String getExtrasArchiveName() {
98 | return String.format("%s_extras.zip", getName());
99 | }
100 |
101 | public String getScriptsArchiveName() {
102 | return String.format("%s_scripts.zip", getName());
103 | }
104 |
105 | public String getInterpreterArchiveUrl() {
106 | return BASE_INSTALL_URL + getInterpreterArchiveName();
107 | }
108 |
109 | public String getExtrasArchiveUrl() {
110 | return BASE_INSTALL_URL + getExtrasArchiveName();
111 | }
112 |
113 | public String getScriptsArchiveUrl() {
114 | return BASE_INSTALL_URL + getScriptsArchiveName();
115 | }
116 |
117 | public File getBinary(Context context) {
118 | return new File(DALVIKVM);
119 | }
120 |
121 | public String getInteractiveCommand(Context context) {
122 | String absolutePathToJar = new File(getExtrasPath(context), JRUBY_JAR).getAbsolutePath();
123 | return String.format(JRUBY_PREFIX, absolutePathToJar,
124 | "require 'irb'; IRB.conf[:USE_READLINE] = false; IRB.start");
125 | }
126 |
127 | public String getScriptCommand(Context context) {
128 | String absolutePathToJar = new File(getExtrasPath(context), JRUBY_JAR).getAbsolutePath();
129 | return String.format(JRUBY_PREFIX, absolutePathToJar, "load('%s')");
130 | }
131 |
132 | public List getArguments(Context context) {
133 | String absolutePathToJar = new File(getExtrasPath(context), JRUBY_JAR).getAbsolutePath();
134 | return Arrays.asList("-Xbootclasspath:/system/framework/core.jar", "-Xss128k", "-classpath",
135 | absolutePathToJar, "org.jruby.Main", "-X-C");
136 | }
137 |
138 | public Map getEnvironmentVariables(Context unused) {
139 | Map values = new HashMap(1);
140 | values.put(ENV_DATA, InterpreterConstants.SDCARD_ROOT + getClass().getPackage().getName());
141 | return values;
142 | }
143 |
144 | public File getExtrasPath(Context context) {
145 | if (!hasInterpreterArchive() && hasExtrasArchive()) {
146 | return new File(InterpreterConstants.SDCARD_ROOT + this.getClass().getPackage().getName()
147 | + InterpreterConstants.INTERPRETER_EXTRAS_ROOT, getName());
148 | }
149 | return InterpreterUtils.getInterpreterRoot(context, getName());
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/JRubyForAndroid/src/org/ruboto/sl4a/JRubyInstaller.java:
--------------------------------------------------------------------------------
1 | package org.ruboto.sl4a;
2 |
3 | import android.content.Context;
4 |
5 | import com.googlecode.android_scripting.AsyncTaskListener;
6 | import com.googlecode.android_scripting.InterpreterInstaller;
7 | import com.googlecode.android_scripting.Log;
8 | import com.googlecode.android_scripting.exception.Sl4aException;
9 | import com.googlecode.android_scripting.interpreter.InterpreterConstants;
10 | import com.googlecode.android_scripting.interpreter.InterpreterDescriptor;
11 |
12 | import java.io.File;
13 |
14 | public class JRubyInstaller extends InterpreterInstaller {
15 |
16 | public JRubyInstaller(InterpreterDescriptor descriptor, Context context,
17 | AsyncTaskListener listener) throws Sl4aException {
18 | super(descriptor, context, listener);
19 | }
20 |
21 | @Override
22 | protected boolean setup() {
23 | File dalvikCache = new File(mInterpreterRoot + InterpreterConstants.SL4A_DALVIK_CACHE_ROOT);
24 | if (!dalvikCache.isDirectory()) {
25 | try {
26 | dalvikCache.mkdir();
27 | } catch (SecurityException e) {
28 | Log.e(mContext, "Setup failed.", e);
29 | return false;
30 | }
31 | }
32 | return true;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JRubyForAndroid/src/org/ruboto/sl4a/JRubyMain.java:
--------------------------------------------------------------------------------
1 | package org.ruboto.sl4a;
2 |
3 | import android.content.Context;
4 |
5 |
6 | import com.googlecode.android_scripting.AsyncTaskListener;
7 | import com.googlecode.android_scripting.InterpreterInstaller;
8 | import com.googlecode.android_scripting.InterpreterUninstaller;
9 | import com.googlecode.android_scripting.activity.Main;
10 | import com.googlecode.android_scripting.exception.Sl4aException;
11 | import com.googlecode.android_scripting.interpreter.InterpreterDescriptor;
12 |
13 | public class JRubyMain extends Main {
14 |
15 | @Override
16 | protected InterpreterDescriptor getDescriptor() {
17 | return new JRubyDescriptor();
18 | }
19 |
20 | @Override
21 | protected InterpreterInstaller getInterpreterInstaller(InterpreterDescriptor descriptor,
22 | Context context, AsyncTaskListener listener) throws Sl4aException {
23 | return new JRubyInstaller(descriptor, context, listener);
24 | }
25 |
26 | @Override
27 | protected InterpreterUninstaller getInterpreterUninstaller(InterpreterDescriptor descriptor,
28 | Context context, AsyncTaskListener listener) throws Sl4aException {
29 | return new JRubyUninstaller(descriptor, context, listener);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/JRubyForAndroid/src/org/ruboto/sl4a/JRubyProvider.java:
--------------------------------------------------------------------------------
1 | package org.ruboto.sl4a;
2 |
3 | import com.googlecode.android_scripting.interpreter.InterpreterDescriptor;
4 | import com.googlecode.android_scripting.interpreter.InterpreterProvider;
5 |
6 | public class JRubyProvider extends InterpreterProvider {
7 | @Override
8 | protected InterpreterDescriptor getDescriptor() {
9 | return new JRubyDescriptor();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/JRubyForAndroid/src/org/ruboto/sl4a/JRubyUninstaller.java:
--------------------------------------------------------------------------------
1 | package org.ruboto.sl4a;
2 |
3 | import android.content.Context;
4 |
5 |
6 | import com.googlecode.android_scripting.AsyncTaskListener;
7 | import com.googlecode.android_scripting.InterpreterUninstaller;
8 | import com.googlecode.android_scripting.exception.Sl4aException;
9 | import com.googlecode.android_scripting.interpreter.InterpreterDescriptor;
10 |
11 | public class JRubyUninstaller extends InterpreterUninstaller {
12 |
13 | public JRubyUninstaller(InterpreterDescriptor descriptor, Context context,
14 | AsyncTaskListener listener) throws Sl4aException {
15 | super(descriptor, context, listener);
16 | }
17 |
18 | @Override
19 | protected boolean cleanup() {
20 | return true;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/jruby-version-builder/README:
--------------------------------------------------------------------------------
1 | This directory contains resources related to building a new version of JRuby for SL4A.
2 |
3 | json/ contains the JSON implementation for Ruby http://json.rubyforge.org/
4 | android.rb comes from the Scripting Language For Android (AL4A) project
5 |
6 | The latest JRuby version will be pulled from the jruby-jars gem
7 |
8 |
--------------------------------------------------------------------------------
/jruby-version-builder/Rakefile:
--------------------------------------------------------------------------------
1 | require 'net/http'
2 | require 'rake/clean'
3 | require 'rubygems'
4 | require 'jruby-jars'
5 |
6 | JRUBY_GEM_VERSION = JRubyJars::core_jar_path.split('/')[-1][11..-5]
7 | JRUBY_CURRENT_VERSION = File.exists?("current/VERSION.txt") ? File.read("current/VERSION.txt") : "none"
8 |
9 | CLEAN.include('jruby', 'working', 'current')
10 |
11 | task :default => :build_from_gem
12 |
13 | directory "current"
14 | directory "working/tmp"
15 | directory "jruby"
16 |
17 | ###########################################################################
18 | #
19 | # Copy latest JRuby from jruby-jars gem
20 | #
21 |
22 | file "working/tmp/jruby.jar" => ["working/tmp"] do
23 | abort("Current version and gem version are the same (#{JRUBY_GEM_VERSION}). 'gem update jruby-jars' or 'rake clean'") if
24 | JRUBY_GEM_VERSION == JRUBY_CURRENT_VERSION
25 |
26 | log_action("Copying #{JRubyJars::core_jar_path}") {FileUtils.copy JRubyJars::core_jar_path, "working/tmp/jruby.jar"}
27 | log_action("Copying #{JRubyJars::stdlib_jar_path}") {FileUtils.copy JRubyJars::stdlib_jar_path, "working/tmp/stdlib.jar"}
28 | end
29 |
30 | ###########################################################################
31 | #
32 | # Combine, add sl4a files, remove extra files
33 | #
34 |
35 | file "working/jruby.jar" => ["working/tmp/jruby.jar"] do
36 | log_action("Inflating jars") do
37 | Dir.chdir "working/tmp"
38 | `jar -xf jruby.jar`
39 | File.delete "jruby.jar"
40 | `jar -xf stdlib.jar`
41 | File.delete "stdlib.jar"
42 | end
43 |
44 | log_action("Adding android.rb and json") do
45 | FileUtils.cp_r "../../json", "META-INF/jruby.home/lib/ruby/1.8"
46 | FileUtils.copy "../../android.rb", "META-INF/jruby.home/lib/ruby/1.8"
47 | end
48 |
49 | log_action("Removing unneeded files") do
50 | ['jni', 'org/jruby/ant', 'org/jruby/compiler/ir', 'org/jruby/demo', 'org/jruby/embed/bsf',
51 | 'org/jruby/embed/jsr223', 'org/jruby/ext/ffi','org/jruby/javasupport/bsf',
52 | 'META-INF/jruby.home/bin', 'META-INF/maven', 'META-INF/services',
53 | 'META-INF/jruby.home/lib/ruby/gems', 'META-INF/jruby.home/lib/ruby/site_ruby'
54 | ].each {|i| FileUtils.remove_dir i, true}
55 | end
56 |
57 | log_action("Building new jar") {`jar -cf ../jruby.jar *`}
58 | Dir.chdir "../.."
59 | end
60 |
61 | ###########################################################################
62 | #
63 | # Dex and zipalign
64 | #
65 |
66 | file "jruby/jruby.jar" => ["jruby", "working/jruby.jar"] do
67 | Dir.chdir "working"
68 | log_action("Dexing") {`dx -JXms1024m -JXmx1024m --dex --output=jruby-dex.jar jruby.jar`}
69 | log_action("Zip aligning") {`zipalign 4 jruby-dex.jar jruby.zip`}
70 | Dir.chdir ".."
71 | FileUtils.copy "working/jruby.zip", "jruby/jruby.jar"
72 | end
73 |
74 | ###########################################################################
75 | #
76 | # Build archives
77 | #
78 |
79 | file "current/jruby_extras.zip" => ["current", "jruby/jruby.jar"] do
80 | log_action("Creating zip of jruby") {`zip -r current/jruby_extras.zip jruby/`}
81 | end
82 |
83 | file "current/jruby_scripts.zip" => ["current", "ase/scripts"] do
84 | log_action("Creating zip of scripts") {`zip -j current/jruby_scripts.zip ase/scripts/*`}
85 | end
86 |
87 | ###########################################################################
88 | #
89 | # Build and remove working file
90 | #
91 |
92 | task :build_from_gem => ["current/jruby_extras.zip", "current/jruby_scripts.zip"] do
93 | File.open("current/VERSION.txt", "w") {|f| f << JRUBY_GEM_VERSION}
94 | log_action("Remove working files and directories") do
95 | FileUtils.remove_dir "jruby"
96 | FileUtils.remove_dir "working"
97 | end
98 | end
99 |
100 | ###########################################################################
101 | #
102 | # log_action: put text to stdout around the execution of a block
103 | #
104 |
105 | def log_action(initial_text, final_text="Done.", &block)
106 | $stdout.sync = true
107 | print initial_text, "..."
108 | yield
109 | puts final_text
110 | end
111 |
112 |
--------------------------------------------------------------------------------
/jruby-version-builder/android.rb:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2009 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 |
15 | AP_PORT = ENV['AP_PORT']
16 | AP_HOST = ENV['AP_HOST']
17 | AP_HANDSHAKE = ENV['AP_HANDSHAKE']
18 |
19 | require 'json/pure'
20 | require 'socket'
21 |
22 |
23 | def trap(*ignore)
24 | # Trap does not work on Android.
25 | end
26 |
27 |
28 | class Android
29 |
30 | def initialize()
31 | @client = TCPSocket.new(AP_HOST, AP_PORT)
32 | @id = 0
33 | _authenticate(AP_HANDSHAKE)
34 | end
35 |
36 | def rpc(method, *args)
37 | @id += 1
38 | request = {'id' => @id, 'method' => method, 'params' => args}.to_json()
39 | @client.puts request
40 | response = @client.gets()
41 | return JSON.parse(response)
42 | end
43 |
44 | def method_missing(method, *args)
45 | rpc(method, *args)
46 | end
47 |
48 | end
49 |
50 |
51 |
--------------------------------------------------------------------------------
/jruby-version-builder/ase/scripts/hello_world.rb:
--------------------------------------------------------------------------------
1 | droid = Android.new
2 | droid.makeToast "Hello, Android!"
3 | puts "Hello, Android!"
4 |
--------------------------------------------------------------------------------
/jruby-version-builder/ase/scripts/toggle_airplane.rb:
--------------------------------------------------------------------------------
1 | # Toggle airplane mode twice to fix stuck GPS/networks...
2 | droid = Android.new
3 | droid.toggleAirplaneMode
4 | droid.toggleAirplaneMode
5 |
6 |
--------------------------------------------------------------------------------
/jruby-version-builder/current/VERSION.txt:
--------------------------------------------------------------------------------
1 | 1.5.5
--------------------------------------------------------------------------------
/jruby-version-builder/current/jruby_extras.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruboto/sl4a_jruby_interpreter/6c14cc1c3139558faccf628e8c1f7ed4291d4d39/jruby-version-builder/current/jruby_extras.zip
--------------------------------------------------------------------------------
/jruby-version-builder/current/jruby_scripts.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruboto/sl4a_jruby_interpreter/6c14cc1c3139558faccf628e8c1f7ed4291d4d39/jruby-version-builder/current/jruby_scripts.zip
--------------------------------------------------------------------------------
/jruby-version-builder/json/LICENSE:
--------------------------------------------------------------------------------
1 | Ruby is copyrighted free software by Yukihiro Matsumoto .
2 | You can redistribute it and/or modify it under either the terms of the GPL
3 | (see COPYING.txt file), or the conditions below:
4 |
5 | 1. You may make and give away verbatim copies of the source form of the
6 | software without restriction, provided that you duplicate all of the
7 | original copyright notices and associated disclaimers.
8 |
9 | 2. You may modify your copy of the software in any way, provided that
10 | you do at least ONE of the following:
11 |
12 | a) place your modifications in the Public Domain or otherwise
13 | make them Freely Available, such as by posting said
14 | modifications to Usenet or an equivalent medium, or by allowing
15 | the author to include your modifications in the software.
16 |
17 | b) use the modified software only within your corporation or
18 | organization.
19 |
20 | c) rename any non-standard executables so the names do not conflict
21 | with standard executables, which must also be provided.
22 |
23 | d) make other distribution arrangements with the author.
24 |
25 | 3. You may distribute the software in object code or executable
26 | form, provided that you do at least ONE of the following:
27 |
28 | a) distribute the executables and library files of the software,
29 | together with instructions (in the manual page or equivalent)
30 | on where to get the original distribution.
31 |
32 | b) accompany the distribution with the machine-readable source of
33 | the software.
34 |
35 | c) give non-standard executables non-standard names, with
36 | instructions on where to get the original software distribution.
37 |
38 | d) make other distribution arrangements with the author.
39 |
40 | 4. You may modify and include the part of the software into any other
41 | software (possibly commercial). But some files in the distribution
42 | are not written by the author, so that they are not under this terms.
43 |
44 | They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
45 | files under the ./missing directory. See each file for the copying
46 | condition.
47 |
48 | 5. The scripts and library files supplied as input to or produced as
49 | output from the software do not automatically fall under the
50 | copyright of the software, but belong to whomever generated them,
51 | and may be sold commercially, and may be aggregated with this
52 | software.
53 |
54 | 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55 | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 | PURPOSE.
58 |
59 |
--------------------------------------------------------------------------------
/jruby-version-builder/json/common.rb:
--------------------------------------------------------------------------------
1 | require 'json/version'
2 |
3 | module JSON
4 | class << self
5 | # If _object_ is string-like parse the string and return the parsed result
6 | # as a Ruby data structure. Otherwise generate a JSON text from the Ruby
7 | # data structure object and return it.
8 | #
9 | # The _opts_ argument is passed through to generate/parse respectively, see
10 | # generate and parse for their documentation.
11 | def [](object, opts = {})
12 | if object.respond_to? :to_str
13 | JSON.parse(object.to_str, opts => {})
14 | else
15 | JSON.generate(object, opts => {})
16 | end
17 | end
18 |
19 | # Returns the JSON parser class, that is used by JSON. This might be either
20 | # JSON::Ext::Parser or JSON::Pure::Parser.
21 | attr_reader :parser
22 |
23 | # Set the JSON parser class _parser_ to be used by JSON.
24 | def parser=(parser) # :nodoc:
25 | @parser = parser
26 | remove_const :Parser if const_defined? :Parser
27 | const_set :Parser, parser
28 | end
29 |
30 | # Return the constant located at _path_. The format of _path_ has to be
31 | # either ::A::B::C or A::B::C. In any case A has to be located at the top
32 | # level (absolute namespace path?). If there doesn't exist a constant at
33 | # the given path, an ArgumentError is raised.
34 | def deep_const_get(path) # :nodoc:
35 | path = path.to_s
36 | path.split(/::/).inject(Object) do |p, c|
37 | case
38 | when c.empty? then p
39 | when p.const_defined?(c) then p.const_get(c)
40 | else raise ArgumentError, "can't find const #{path}"
41 | end
42 | end
43 | end
44 |
45 | # Set the module _generator_ to be used by JSON.
46 | def generator=(generator) # :nodoc:
47 | @generator = generator
48 | generator_methods = generator::GeneratorMethods
49 | for const in generator_methods.constants
50 | klass = deep_const_get(const)
51 | modul = generator_methods.const_get(const)
52 | klass.class_eval do
53 | instance_methods(false).each do |m|
54 | m.to_s == 'to_json' and remove_method m
55 | end
56 | include modul
57 | end
58 | end
59 | self.state = generator::State
60 | const_set :State, self.state
61 | end
62 |
63 | # Returns the JSON generator modul, that is used by JSON. This might be
64 | # either JSON::Ext::Generator or JSON::Pure::Generator.
65 | attr_reader :generator
66 |
67 | # Returns the JSON generator state class, that is used by JSON. This might
68 | # be either JSON::Ext::Generator::State or JSON::Pure::Generator::State.
69 | attr_accessor :state
70 |
71 | # This is create identifier, that is used to decide, if the _json_create_
72 | # hook of a class should be called. It defaults to 'json_class'.
73 | attr_accessor :create_id
74 | end
75 | self.create_id = 'json_class'
76 |
77 | NaN = (-1.0) ** 0.5
78 |
79 | Infinity = 1.0/0
80 |
81 | MinusInfinity = -Infinity
82 |
83 | # The base exception for JSON errors.
84 | class JSONError < StandardError; end
85 |
86 | # This exception is raised, if a parser error occurs.
87 | class ParserError < JSONError; end
88 |
89 | # This exception is raised, if the nesting of parsed datastructures is too
90 | # deep.
91 | class NestingError < ParserError; end
92 |
93 | # This exception is raised, if a generator or unparser error occurs.
94 | class GeneratorError < JSONError; end
95 | # For backwards compatibility
96 | UnparserError = GeneratorError
97 |
98 | # If a circular data structure is encountered while unparsing
99 | # this exception is raised.
100 | class CircularDatastructure < GeneratorError; end
101 |
102 | # This exception is raised, if the required unicode support is missing on the
103 | # system. Usually this means, that the iconv library is not installed.
104 | class MissingUnicodeSupport < JSONError; end
105 |
106 | module_function
107 |
108 | # Parse the JSON string _source_ into a Ruby data structure and return it.
109 | #
110 | # _opts_ can have the following
111 | # keys:
112 | # * *max_nesting*: The maximum depth of nesting allowed in the parsed data
113 | # structures. Disable depth checking with :max_nesting => false, it defaults
114 | # to 19.
115 | # * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
116 | # defiance of RFC 4627 to be parsed by the Parser. This option defaults
117 | # to false.
118 | # * *create_additions*: If set to false, the Parser doesn't create
119 | # additions even if a matchin class and create_id was found. This option
120 | # defaults to true.
121 | def parse(source, opts = {})
122 | JSON.parser.new(source, opts).parse
123 | end
124 |
125 | # Parse the JSON string _source_ into a Ruby data structure and return it.
126 | # The bang version of the parse method, defaults to the more dangerous values
127 | # for the _opts_ hash, so be sure only to parse trusted _source_ strings.
128 | #
129 | # _opts_ can have the following keys:
130 | # * *max_nesting*: The maximum depth of nesting allowed in the parsed data
131 | # structures. Enable depth checking with :max_nesting => anInteger. The parse!
132 | # methods defaults to not doing max depth checking: This can be dangerous,
133 | # if someone wants to fill up your stack.
134 | # * *allow_nan*: If set to true, allow NaN, Infinity, and -Infinity in
135 | # defiance of RFC 4627 to be parsed by the Parser. This option defaults
136 | # to true.
137 | # * *create_additions*: If set to false, the Parser doesn't create
138 | # additions even if a matchin class and create_id was found. This option
139 | # defaults to true.
140 | def parse!(source, opts = {})
141 | opts = {
142 | :max_nesting => false,
143 | :allow_nan => true
144 | }.update(opts)
145 | JSON.parser.new(source, opts).parse
146 | end
147 |
148 | # Unparse the Ruby data structure _obj_ into a single line JSON string and
149 | # return it. _state_ is
150 | # * a JSON::State object,
151 | # * or a Hash like object (responding to to_hash),
152 | # * an object convertible into a hash by a to_h method,
153 | # that is used as or to configure a State object.
154 | #
155 | # It defaults to a state object, that creates the shortest possible JSON text
156 | # in one line, checks for circular data structures and doesn't allow NaN,
157 | # Infinity, and -Infinity.
158 | #
159 | # A _state_ hash can have the following keys:
160 | # * *indent*: a string used to indent levels (default: ''),
161 | # * *space*: a string that is put after, a : or , delimiter (default: ''),
162 | # * *space_before*: a string that is put before a : pair delimiter (default: ''),
163 | # * *object_nl*: a string that is put at the end of a JSON object (default: ''),
164 | # * *array_nl*: a string that is put at the end of a JSON array (default: ''),
165 | # * *check_circular*: true if checking for circular data structures
166 | # should be done (the default), false otherwise.
167 | # * *allow_nan*: true if NaN, Infinity, and -Infinity should be
168 | # generated, otherwise an exception is thrown, if these values are
169 | # encountered. This options defaults to false.
170 | # * *max_nesting*: The maximum depth of nesting allowed in the data
171 | # structures from which JSON is to be generated. Disable depth checking
172 | # with :max_nesting => false, it defaults to 19.
173 | #
174 | # See also the fast_generate for the fastest creation method with the least
175 | # amount of sanity checks, and the pretty_generate method for some
176 | # defaults for a pretty output.
177 | def generate(obj, state = nil)
178 | if state
179 | state = State.from_state(state)
180 | else
181 | state = State.new
182 | end
183 | obj.to_json(state)
184 | end
185 |
186 | # :stopdoc:
187 | # I want to deprecate these later, so I'll first be silent about them, and
188 | # later delete them.
189 | alias unparse generate
190 | module_function :unparse
191 | # :startdoc:
192 |
193 | # Unparse the Ruby data structure _obj_ into a single line JSON string and
194 | # return it. This method disables the checks for circles in Ruby objects, and
195 | # also generates NaN, Infinity, and, -Infinity float values.
196 | #
197 | # *WARNING*: Be careful not to pass any Ruby data structures with circles as
198 | # _obj_ argument, because this will cause JSON to go into an infinite loop.
199 | def fast_generate(obj)
200 | obj.to_json(nil)
201 | end
202 |
203 | # :stopdoc:
204 | # I want to deprecate these later, so I'll first be silent about them, and later delete them.
205 | alias fast_unparse fast_generate
206 | module_function :fast_unparse
207 | # :startdoc:
208 |
209 | # Unparse the Ruby data structure _obj_ into a JSON string and return it. The
210 | # returned string is a prettier form of the string returned by #unparse.
211 | #
212 | # The _opts_ argument can be used to configure the generator, see the
213 | # generate method for a more detailed explanation.
214 | def pretty_generate(obj, opts = nil)
215 | state = JSON.state.new(
216 | :indent => ' ',
217 | :space => ' ',
218 | :object_nl => "\n",
219 | :array_nl => "\n",
220 | :check_circular => true
221 | )
222 | if opts
223 | if opts.respond_to? :to_hash
224 | opts = opts.to_hash
225 | elsif opts.respond_to? :to_h
226 | opts = opts.to_h
227 | else
228 | raise TypeError, "can't convert #{opts.class} into Hash"
229 | end
230 | state.configure(opts)
231 | end
232 | obj.to_json(state)
233 | end
234 |
235 | # :stopdoc:
236 | # I want to deprecate these later, so I'll first be silent about them, and later delete them.
237 | alias pretty_unparse pretty_generate
238 | module_function :pretty_unparse
239 | # :startdoc:
240 |
241 | # Load a ruby data structure from a JSON _source_ and return it. A source can
242 | # either be a string-like object, an IO like object, or an object responding
243 | # to the read method. If _proc_ was given, it will be called with any nested
244 | # Ruby object as an argument recursively in depth first order.
245 | #
246 | # This method is part of the implementation of the load/dump interface of
247 | # Marshal and YAML.
248 | def load(source, proc = nil)
249 | if source.respond_to? :to_str
250 | source = source.to_str
251 | elsif source.respond_to? :to_io
252 | source = source.to_io.read
253 | else
254 | source = source.read
255 | end
256 | result = parse(source, :max_nesting => false, :allow_nan => true)
257 | recurse_proc(result, &proc) if proc
258 | result
259 | end
260 |
261 | def recurse_proc(result, &proc)
262 | case result
263 | when Array
264 | result.each { |x| recurse_proc x, &proc }
265 | proc.call result
266 | when Hash
267 | result.each { |x, y| recurse_proc x, &proc; recurse_proc y, &proc }
268 | proc.call result
269 | else
270 | proc.call result
271 | end
272 | end
273 | private :recurse_proc
274 | module_function :recurse_proc
275 |
276 | alias restore load
277 | module_function :restore
278 |
279 | # Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns
280 | # the result.
281 | #
282 | # If anIO (an IO like object or an object that responds to the write method)
283 | # was given, the resulting JSON is written to it.
284 | #
285 | # If the number of nested arrays or objects exceeds _limit_ an ArgumentError
286 | # exception is raised. This argument is similar (but not exactly the
287 | # same!) to the _limit_ argument in Marshal.dump.
288 | #
289 | # This method is part of the implementation of the load/dump interface of
290 | # Marshal and YAML.
291 | def dump(obj, anIO = nil, limit = nil)
292 | if anIO and limit.nil?
293 | anIO = anIO.to_io if anIO.respond_to?(:to_io)
294 | unless anIO.respond_to?(:write)
295 | limit = anIO
296 | anIO = nil
297 | end
298 | end
299 | limit ||= 0
300 | result = generate(obj, :allow_nan => true, :max_nesting => limit)
301 | if anIO
302 | anIO.write result
303 | anIO
304 | else
305 | result
306 | end
307 | rescue JSON::NestingError
308 | raise ArgumentError, "exceed depth limit"
309 | end
310 | end
311 |
312 | module ::Kernel
313 | # Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
314 | # one line.
315 | def j(*objs)
316 | objs.each do |obj|
317 | puts JSON::generate(obj, :allow_nan => true, :max_nesting => false)
318 | end
319 | nil
320 | end
321 |
322 | # Ouputs _objs_ to STDOUT as JSON strings in a pretty format, with
323 | # indentation and over many lines.
324 | def jj(*objs)
325 | objs.each do |obj|
326 | puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false)
327 | end
328 | nil
329 | end
330 |
331 | # If _object_ is string-like parse the string and return the parsed result as
332 | # a Ruby data structure. Otherwise generate a JSON text from the Ruby data
333 | # structure object and return it.
334 | #
335 | # The _opts_ argument is passed through to generate/parse respectively, see
336 | # generate and parse for their documentation.
337 | def JSON(object, opts = {})
338 | if object.respond_to? :to_str
339 | JSON.parse(object.to_str, opts)
340 | else
341 | JSON.generate(object, opts)
342 | end
343 | end
344 | end
345 |
346 | class ::Class
347 | # Returns true, if this class can be used to create an instance
348 | # from a serialised JSON string. The class has to implement a class
349 | # method _json_create_ that expects a hash as first parameter, which includes
350 | # the required data.
351 | def json_creatable?
352 | respond_to?(:json_create)
353 | end
354 | end
355 |
--------------------------------------------------------------------------------
/jruby-version-builder/json/json.rb:
--------------------------------------------------------------------------------
1 | require 'json/common'
2 | # = json - JSON for Ruby
3 | #
4 | # == Description
5 | #
6 | # This is a implementation of the JSON specification according to RFC 4627
7 | # (http://www.ietf.org/rfc/rfc4627.txt). Starting from version 1.0.0 on there
8 | # will be two variants available:
9 | #
10 | # * A pure ruby variant, that relies on the iconv and the stringscan
11 | # extensions, which are both part of the ruby standard library.
12 | # * The quite a bit faster C extension variant, which is in parts implemented
13 | # in C and comes with its own unicode conversion functions and a parser
14 | # generated by the ragel state machine compiler
15 | # (http://www.cs.queensu.ca/~thurston/ragel).
16 | #
17 | # Both variants of the JSON generator escape all non-ASCII an control
18 | # characters with \uXXXX escape sequences, and support UTF-16 surrogate pairs
19 | # in order to be able to generate the whole range of unicode code points. This
20 | # means that generated JSON text is encoded as UTF-8 (because ASCII is a subset
21 | # of UTF-8) and at the same time avoids decoding problems for receiving
22 | # endpoints, that don't expect UTF-8 encoded texts. On the negative side this
23 | # may lead to a bit longer strings than necessarry.
24 | #
25 | # All strings, that are to be encoded as JSON strings, should be UTF-8 byte
26 | # sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
27 | # encoded, please use the to_json_raw_object method of String (which produces
28 | # an object, that contains a byte array) and decode the result on the receiving
29 | # endpoint.
30 | #
31 | # == Author
32 | #
33 | # Florian Frank
34 | #
35 | # == License
36 | #
37 | # This software is distributed under the same license as Ruby itself, see
38 | # http://www.ruby-lang.org/en/LICENSE.txt.
39 | #
40 | # == Download
41 | #
42 | # The latest version of this library can be downloaded at
43 | #
44 | # * http://rubyforge.org/frs?group_id=953
45 | #
46 | # Online Documentation should be located at
47 | #
48 | # * http://json.rubyforge.org
49 | #
50 | # == Usage
51 | #
52 | # To use JSON you can
53 | # require 'json'
54 | # to load the installed variant (either the extension 'json' or the pure
55 | # variant 'json_pure'). If you have installed the extension variant, you can
56 | # pick either the extension variant or the pure variant by typing
57 | # require 'json/ext'
58 | # or
59 | # require 'json/pure'
60 | #
61 | # You can choose to load a set of common additions to ruby core's objects if
62 | # you
63 | # require 'json/add/core'
64 | #
65 | # After requiring this you can, e. g., serialise/deserialise Ruby ranges:
66 | #
67 | # JSON JSON(1..10) # => 1..10
68 | #
69 | # To find out how to add JSON support to other or your own classes, read the
70 | # Examples section below.
71 | #
72 | # To get the best compatibility to rails' JSON implementation, you can
73 | # require 'json/add/rails'
74 | #
75 | # Both of the additions attempt to require 'json' (like above) first, if it has
76 | # not been required yet.
77 | #
78 | # == Speed Comparisons
79 | #
80 | # I have created some benchmark results (see the benchmarks subdir of the
81 | # package) for the JSON-Parser to estimate the speed up in the C extension:
82 | #
83 | # JSON::Pure::Parser:: 28.90 calls/second
84 | # JSON::Ext::Parser:: 505.50 calls/second
85 | #
86 | # This is ca. 17.5 times the speed of the pure Ruby implementation.
87 | #
88 | # I have benchmarked the JSON-Generator as well. This generates a few more
89 | # values, because there are different modes, that also influence the achieved
90 | # speed:
91 | #
92 | # * JSON::Pure::Generator:
93 | # generate:: 35.06 calls/second
94 | # pretty_generate:: 34.00 calls/second
95 | # fast_generate:: 41.06 calls/second
96 | #
97 | # * JSON::Ext::Generator:
98 | # generate:: 492.11 calls/second
99 | # pretty_generate:: 348.85 calls/second
100 | # fast_generate:: 541.60 calls/second
101 | #
102 | # * Speedup Ext/Pure:
103 | # generate safe:: 14.0 times
104 | # generate pretty:: 10.3 times
105 | # generate fast:: 13.2 times
106 | #
107 | # The rails framework includes a generator as well, also it seems to be rather
108 | # slow: I measured only 23.87 calls/second which is slower than any of my pure
109 | # generator results. Here a comparison of the different speedups with the Rails
110 | # measurement as the divisor:
111 | #
112 | # * Speedup Pure/Rails:
113 | # generate safe:: 1.5 times
114 | # generate pretty:: 1.4 times
115 | # generate fast:: 1.7 times
116 | #
117 | # * Speedup Ext/Rails:
118 | # generate safe:: 20.6 times
119 | # generate pretty:: 14.6 times
120 | # generate fast:: 22.7 times
121 | #
122 | # To achieve the fastest JSON text output, you can use the
123 | # fast_generate/fast_unparse methods. Beware, that this will disable the
124 | # checking for circular Ruby data structures, which may cause JSON to go into
125 | # an infinite loop.
126 | #
127 | # == Examples
128 | #
129 | # To create a JSON text from a ruby data structure, you
130 | # can call JSON.generate (or JSON.unparse) like that:
131 | #
132 | # json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
133 | # # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
134 | #
135 | # To create a valid JSON text you have to make sure, that the output is
136 | # embedded in either a JSON array [] or a JSON object {}. The easiest way to do
137 | # this, is by putting your values in a Ruby Array or Hash instance.
138 | #
139 | # To get back a ruby data structure from a JSON text, you have to call
140 | # JSON.parse on it:
141 | #
142 | # JSON.parse json
143 | # # => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
144 | #
145 | # Note, that the range from the original data structure is a simple
146 | # string now. The reason for this is, that JSON doesn't support ranges
147 | # or arbitrary classes. In this case the json library falls back to call
148 | # Object#to_json, which is the same as #to_s.to_json.
149 | #
150 | # It's possible to add JSON support serialization to arbitrary classes by
151 | # simply implementing a more specialized version of the #to_json method, that
152 | # should return a JSON object (a hash converted to JSON with #to_json) like
153 | # this (don't forget the *a for all the arguments):
154 | #
155 | # class Range
156 | # def to_json(*a)
157 | # {
158 | # 'json_class' => self.class.name, # = 'Range'
159 | # 'data' => [ first, last, exclude_end? ]
160 | # }.to_json(*a)
161 | # end
162 | # end
163 | #
164 | # The hash key 'json_class' is the class, that will be asked to deserialise the
165 | # JSON representation later. In this case it's 'Range', but any namespace of
166 | # the form 'A::B' or '::A::B' will do. All other keys are arbitrary and can be
167 | # used to store the necessary data to configure the object to be deserialised.
168 | #
169 | # If a the key 'json_class' is found in a JSON object, the JSON parser checks
170 | # if the given class responds to the json_create class method. If so, it is
171 | # called with the JSON object converted to a Ruby hash. So a range can
172 | # be deserialised by implementing Range.json_create like this:
173 | #
174 | # class Range
175 | # def self.json_create(o)
176 | # new(*o['data'])
177 | # end
178 | # end
179 | #
180 | # Now it possible to serialise/deserialise ranges as well:
181 | #
182 | # json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
183 | # # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
184 | # JSON.parse json
185 | # # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
186 | #
187 | # JSON.generate always creates the shortest possible string representation of a
188 | # ruby data structure in one line. This good for data storage or network
189 | # protocols, but not so good for humans to read. Fortunately there's also
190 | # JSON.pretty_generate (or JSON.pretty_generate) that creates a more
191 | # readable output:
192 | #
193 | # puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
194 | # [
195 | # 1,
196 | # 2,
197 | # {
198 | # "a": 3.141
199 | # },
200 | # false,
201 | # true,
202 | # null,
203 | # {
204 | # "json_class": "Range",
205 | # "data": [
206 | # 4,
207 | # 10,
208 | # false
209 | # ]
210 | # }
211 | # ]
212 | #
213 | # There are also the methods Kernel#j for unparse, and Kernel#jj for
214 | # pretty_unparse output to the console, that work analogous to Core Ruby's p
215 | # and the pp library's pp methods.
216 | #
217 | # The script tools/server.rb contains a small example if you want to test, how
218 | # receiving a JSON object from a webrick server in your browser with the
219 | # javasript prototype library (http://www.prototypejs.org) works.
220 | #
221 | module JSON
222 | require 'json/version'
223 |
224 | if VARIANT_BINARY
225 | require 'json/ext'
226 | else
227 | begin
228 | require 'json/ext'
229 | rescue LoadError
230 | require 'json/pure'
231 | end
232 | end
233 |
234 | JSON_LOADED = true
235 | end
236 |
--------------------------------------------------------------------------------
/jruby-version-builder/json/pure.rb:
--------------------------------------------------------------------------------
1 | require 'json/common'
2 | require 'json/pure/parser'
3 | require 'json/pure/generator'
4 |
5 | module JSON
6 | begin
7 | require 'iconv'
8 | # An iconv instance to convert from UTF8 to UTF16 Big Endian.
9 | UTF16toUTF8 = Iconv.new('utf-8', 'utf-16be') # :nodoc:
10 | # An iconv instance to convert from UTF16 Big Endian to UTF8.
11 | UTF8toUTF16 = Iconv.new('utf-16be', 'utf-8') # :nodoc:
12 | UTF8toUTF16.iconv('no bom')
13 | rescue Errno::EINVAL, Iconv::InvalidEncoding
14 | # Iconv doesn't support big endian utf-16. Let's try to hack this manually
15 | # into the converters.
16 | begin
17 | old_verbose, $VERBSOSE = $VERBOSE, nil
18 | # An iconv instance to convert from UTF8 to UTF16 Big Endian.
19 | UTF16toUTF8 = Iconv.new('utf-8', 'utf-16') # :nodoc:
20 | # An iconv instance to convert from UTF16 Big Endian to UTF8.
21 | UTF8toUTF16 = Iconv.new('utf-16', 'utf-8') # :nodoc:
22 | UTF8toUTF16.iconv('no bom')
23 | if UTF8toUTF16.iconv("\xe2\x82\xac") == "\xac\x20"
24 | swapper = Class.new do
25 | def initialize(iconv) # :nodoc:
26 | @iconv = iconv
27 | end
28 |
29 | def iconv(string) # :nodoc:
30 | result = @iconv.iconv(string)
31 | JSON.swap!(result)
32 | end
33 | end
34 | UTF8toUTF16 = swapper.new(UTF8toUTF16) # :nodoc:
35 | end
36 | if UTF16toUTF8.iconv("\xac\x20") == "\xe2\x82\xac"
37 | swapper = Class.new do
38 | def initialize(iconv) # :nodoc:
39 | @iconv = iconv
40 | end
41 |
42 | def iconv(string) # :nodoc:
43 | string = JSON.swap!(string.dup)
44 | @iconv.iconv(string)
45 | end
46 | end
47 | UTF16toUTF8 = swapper.new(UTF16toUTF8) # :nodoc:
48 | end
49 | rescue Errno::EINVAL, Iconv::InvalidEncoding
50 | raise MissingUnicodeSupport, "iconv doesn't seem to support UTF-8/UTF-16 conversions"
51 | ensure
52 | $VERBOSE = old_verbose
53 | end
54 | rescue LoadError
55 | raise MissingUnicodeSupport,
56 | "iconv couldn't be loaded, which is required for UTF-8/UTF-16 conversions"
57 | end
58 |
59 | # Swap consecutive bytes of _string_ in place.
60 | def self.swap!(string) # :nodoc:
61 | 0.upto(string.size / 2) do |i|
62 | break unless string[2 * i + 1]
63 | string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
64 | end
65 | string
66 | end
67 |
68 | # This module holds all the modules/classes that implement JSON's
69 | # functionality in pure ruby.
70 | module Pure
71 | $DEBUG and warn "Using pure library for JSON."
72 | JSON.parser = Parser
73 | JSON.generator = Generator
74 | end
75 | end
76 |
--------------------------------------------------------------------------------
/jruby-version-builder/json/pure/generator.rb:
--------------------------------------------------------------------------------
1 | module JSON
2 | MAP = {
3 | "\x0" => '\u0000',
4 | "\x1" => '\u0001',
5 | "\x2" => '\u0002',
6 | "\x3" => '\u0003',
7 | "\x4" => '\u0004',
8 | "\x5" => '\u0005',
9 | "\x6" => '\u0006',
10 | "\x7" => '\u0007',
11 | "\b" => '\b',
12 | "\t" => '\t',
13 | "\n" => '\n',
14 | "\xb" => '\u000b',
15 | "\f" => '\f',
16 | "\r" => '\r',
17 | "\xe" => '\u000e',
18 | "\xf" => '\u000f',
19 | "\x10" => '\u0010',
20 | "\x11" => '\u0011',
21 | "\x12" => '\u0012',
22 | "\x13" => '\u0013',
23 | "\x14" => '\u0014',
24 | "\x15" => '\u0015',
25 | "\x16" => '\u0016',
26 | "\x17" => '\u0017',
27 | "\x18" => '\u0018',
28 | "\x19" => '\u0019',
29 | "\x1a" => '\u001a',
30 | "\x1b" => '\u001b',
31 | "\x1c" => '\u001c',
32 | "\x1d" => '\u001d',
33 | "\x1e" => '\u001e',
34 | "\x1f" => '\u001f',
35 | '"' => '\"',
36 | '\\' => '\\\\',
37 | '/' => '\/',
38 | } # :nodoc:
39 |
40 | # Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with
41 | # UTF16 big endian characters as \u????, and return it.
42 | def utf8_to_json(string) # :nodoc:
43 | string = string.gsub(/["\\\/\x0-\x1f]/) { MAP[$&] }
44 | string.gsub!(/(
45 | (?:
46 | [\xc2-\xdf][\x80-\xbf] |
47 | [\xe0-\xef][\x80-\xbf]{2} |
48 | [\xf0-\xf4][\x80-\xbf]{3}
49 | )+ |
50 | [\x80-\xc1\xf5-\xff] # invalid
51 | )/nx) { |c|
52 | c.size == 1 and raise GeneratorError, "invalid utf8 byte: '#{c}'"
53 | s = JSON::UTF8toUTF16.iconv(c).unpack('H*')[0]
54 | s.gsub!(/.{4}/n, '\\\\u\&')
55 | }
56 | string
57 | rescue Iconv::Failure => e
58 | raise GeneratorError, "Caught #{e.class}: #{e}"
59 | end
60 | module_function :utf8_to_json
61 |
62 | module Pure
63 | module Generator
64 | # This class is used to create State instances, that are use to hold data
65 | # while generating a JSON text from a a Ruby data structure.
66 | class State
67 | # Creates a State object from _opts_, which ought to be Hash to create
68 | # a new State instance configured by _opts_, something else to create
69 | # an unconfigured instance. If _opts_ is a State object, it is just
70 | # returned.
71 | def self.from_state(opts)
72 | case opts
73 | when self
74 | opts
75 | when Hash
76 | new(opts)
77 | else
78 | new
79 | end
80 | end
81 |
82 | # Instantiates a new State object, configured by _opts_.
83 | #
84 | # _opts_ can have the following keys:
85 | #
86 | # * *indent*: a string used to indent levels (default: ''),
87 | # * *space*: a string that is put after, a : or , delimiter (default: ''),
88 | # * *space_before*: a string that is put before a : pair delimiter (default: ''),
89 | # * *object_nl*: a string that is put at the end of a JSON object (default: ''),
90 | # * *array_nl*: a string that is put at the end of a JSON array (default: ''),
91 | # * *check_circular*: true if checking for circular data structures
92 | # should be done (the default), false otherwise.
93 | # * *check_circular*: true if checking for circular data structures
94 | # should be done, false (the default) otherwise.
95 | # * *allow_nan*: true if NaN, Infinity, and -Infinity should be
96 | # generated, otherwise an exception is thrown, if these values are
97 | # encountered. This options defaults to false.
98 | def initialize(opts = {})
99 | @seen = {}
100 | @indent = ''
101 | @space = ''
102 | @space_before = ''
103 | @object_nl = ''
104 | @array_nl = ''
105 | @check_circular = true
106 | @allow_nan = false
107 | configure opts
108 | end
109 |
110 | # This string is used to indent levels in the JSON text.
111 | attr_accessor :indent
112 |
113 | # This string is used to insert a space between the tokens in a JSON
114 | # string.
115 | attr_accessor :space
116 |
117 | # This string is used to insert a space before the ':' in JSON objects.
118 | attr_accessor :space_before
119 |
120 | # This string is put at the end of a line that holds a JSON object (or
121 | # Hash).
122 | attr_accessor :object_nl
123 |
124 | # This string is put at the end of a line that holds a JSON array.
125 | attr_accessor :array_nl
126 |
127 | # This integer returns the maximum level of data structure nesting in
128 | # the generated JSON, max_nesting = 0 if no maximum is checked.
129 | attr_accessor :max_nesting
130 |
131 | def check_max_nesting(depth) # :nodoc:
132 | return if @max_nesting.zero?
133 | current_nesting = depth + 1
134 | current_nesting > @max_nesting and
135 | raise NestingError, "nesting of #{current_nesting} is too deep"
136 | end
137 |
138 | # Returns true, if circular data structures should be checked,
139 | # otherwise returns false.
140 | def check_circular?
141 | @check_circular
142 | end
143 |
144 | # Returns true if NaN, Infinity, and -Infinity should be considered as
145 | # valid JSON and output.
146 | def allow_nan?
147 | @allow_nan
148 | end
149 |
150 | # Returns _true_, if _object_ was already seen during this generating
151 | # run.
152 | def seen?(object)
153 | @seen.key?(object.__id__)
154 | end
155 |
156 | # Remember _object_, to find out if it was already encountered (if a
157 | # cyclic data structure is if a cyclic data structure is rendered).
158 | def remember(object)
159 | @seen[object.__id__] = true
160 | end
161 |
162 | # Forget _object_ for this generating run.
163 | def forget(object)
164 | @seen.delete object.__id__
165 | end
166 |
167 | # Configure this State instance with the Hash _opts_, and return
168 | # itself.
169 | def configure(opts)
170 | @indent = opts[:indent] if opts.key?(:indent)
171 | @space = opts[:space] if opts.key?(:space)
172 | @space_before = opts[:space_before] if opts.key?(:space_before)
173 | @object_nl = opts[:object_nl] if opts.key?(:object_nl)
174 | @array_nl = opts[:array_nl] if opts.key?(:array_nl)
175 | @check_circular = !!opts[:check_circular] if opts.key?(:check_circular)
176 | @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan)
177 | if !opts.key?(:max_nesting) # defaults to 19
178 | @max_nesting = 19
179 | elsif opts[:max_nesting]
180 | @max_nesting = opts[:max_nesting]
181 | else
182 | @max_nesting = 0
183 | end
184 | self
185 | end
186 |
187 | # Returns the configuration instance variables as a hash, that can be
188 | # passed to the configure method.
189 | def to_h
190 | result = {}
191 | for iv in %w[indent space space_before object_nl array_nl check_circular allow_nan max_nesting]
192 | result[iv.intern] = instance_variable_get("@#{iv}")
193 | end
194 | result
195 | end
196 | end
197 |
198 | module GeneratorMethods
199 | module Object
200 | # Converts this object to a string (calling #to_s), converts
201 | # it to a JSON string, and returns the result. This is a fallback, if no
202 | # special method #to_json was defined for some object.
203 | def to_json(*) to_s.to_json end
204 | end
205 |
206 | module Hash
207 | # Returns a JSON string containing a JSON object, that is unparsed from
208 | # this Hash instance.
209 | # _state_ is a JSON::State object, that can also be used to configure the
210 | # produced JSON string output further.
211 | # _depth_ is used to find out nesting depth, to indent accordingly.
212 | def to_json(state = nil, depth = 0, *)
213 | if state
214 | state = JSON.state.from_state(state)
215 | state.check_max_nesting(depth)
216 | json_check_circular(state) { json_transform(state, depth) }
217 | else
218 | json_transform(state, depth)
219 | end
220 | end
221 |
222 | private
223 |
224 | def json_check_circular(state)
225 | if state and state.check_circular?
226 | state.seen?(self) and raise JSON::CircularDatastructure,
227 | "circular data structures not supported!"
228 | state.remember self
229 | end
230 | yield
231 | ensure
232 | state and state.forget self
233 | end
234 |
235 | def json_shift(state, depth)
236 | state and not state.object_nl.empty? or return ''
237 | state.indent * depth
238 | end
239 |
240 | def json_transform(state, depth)
241 | delim = ','
242 | delim << state.object_nl if state
243 | result = '{'
244 | result << state.object_nl if state
245 | result << map { |key,value|
246 | s = json_shift(state, depth + 1)
247 | s << key.to_s.to_json(state, depth + 1)
248 | s << state.space_before if state
249 | s << ':'
250 | s << state.space if state
251 | s << value.to_json(state, depth + 1)
252 | }.join(delim)
253 | result << state.object_nl if state
254 | result << json_shift(state, depth)
255 | result << '}'
256 | result
257 | end
258 | end
259 |
260 | module Array
261 | # Returns a JSON string containing a JSON array, that is unparsed from
262 | # this Array instance.
263 | # _state_ is a JSON::State object, that can also be used to configure the
264 | # produced JSON string output further.
265 | # _depth_ is used to find out nesting depth, to indent accordingly.
266 | def to_json(state = nil, depth = 0, *)
267 | if state
268 | state = JSON.state.from_state(state)
269 | state.check_max_nesting(depth)
270 | json_check_circular(state) { json_transform(state, depth) }
271 | else
272 | json_transform(state, depth)
273 | end
274 | end
275 |
276 | private
277 |
278 | def json_check_circular(state)
279 | if state and state.check_circular?
280 | state.seen?(self) and raise JSON::CircularDatastructure,
281 | "circular data structures not supported!"
282 | state.remember self
283 | end
284 | yield
285 | ensure
286 | state and state.forget self
287 | end
288 |
289 | def json_shift(state, depth)
290 | state and not state.array_nl.empty? or return ''
291 | state.indent * depth
292 | end
293 |
294 | def json_transform(state, depth)
295 | delim = ','
296 | delim << state.array_nl if state
297 | result = '['
298 | result << state.array_nl if state
299 | result << map { |value|
300 | json_shift(state, depth + 1) << value.to_json(state, depth + 1)
301 | }.join(delim)
302 | result << state.array_nl if state
303 | result << json_shift(state, depth)
304 | result << ']'
305 | result
306 | end
307 | end
308 |
309 | module Integer
310 | # Returns a JSON string representation for this Integer number.
311 | def to_json(*) to_s end
312 | end
313 |
314 | module Float
315 | # Returns a JSON string representation for this Float number.
316 | def to_json(state = nil, *)
317 | case
318 | when infinite?
319 | if !state || state.allow_nan?
320 | to_s
321 | else
322 | raise GeneratorError, "#{self} not allowed in JSON"
323 | end
324 | when nan?
325 | if !state || state.allow_nan?
326 | to_s
327 | else
328 | raise GeneratorError, "#{self} not allowed in JSON"
329 | end
330 | else
331 | to_s
332 | end
333 | end
334 | end
335 |
336 | module String
337 | # This string should be encoded with UTF-8 A call to this method
338 | # returns a JSON string encoded with UTF16 big endian characters as
339 | # \u????.
340 | def to_json(*)
341 | '"' << JSON.utf8_to_json(self) << '"'
342 | end
343 |
344 | # Module that holds the extinding methods if, the String module is
345 | # included.
346 | module Extend
347 | # Raw Strings are JSON Objects (the raw bytes are stored in an array for the
348 | # key "raw"). The Ruby String can be created by this module method.
349 | def json_create(o)
350 | o['raw'].pack('C*')
351 | end
352 | end
353 |
354 | # Extends _modul_ with the String::Extend module.
355 | def self.included(modul)
356 | modul.extend Extend
357 | end
358 |
359 | # This method creates a raw object hash, that can be nested into
360 | # other data structures and will be unparsed as a raw string. This
361 | # method should be used, if you want to convert raw strings to JSON
362 | # instead of UTF-8 strings, e. g. binary data.
363 | def to_json_raw_object
364 | {
365 | JSON.create_id => self.class.name,
366 | 'raw' => self.unpack('C*'),
367 | }
368 | end
369 |
370 | # This method creates a JSON text from the result of
371 | # a call to to_json_raw_object of this String.
372 | def to_json_raw(*args)
373 | to_json_raw_object.to_json(*args)
374 | end
375 | end
376 |
377 | module TrueClass
378 | # Returns a JSON string for true: 'true'.
379 | def to_json(*) 'true' end
380 | end
381 |
382 | module FalseClass
383 | # Returns a JSON string for false: 'false'.
384 | def to_json(*) 'false' end
385 | end
386 |
387 | module NilClass
388 | # Returns a JSON string for nil: 'null'.
389 | def to_json(*) 'null' end
390 | end
391 | end
392 | end
393 | end
394 | end
395 |
--------------------------------------------------------------------------------
/jruby-version-builder/json/pure/parser.rb:
--------------------------------------------------------------------------------
1 | require 'strscan'
2 |
3 | module JSON
4 | module Pure
5 | # This class implements the JSON parser that is used to parse a JSON string
6 | # into a Ruby data structure.
7 | class Parser < StringScanner
8 | STRING = /" ((?:[^\x0-\x1f"\\] |
9 | \\["\\\/bfnrt] |
10 | \\u[0-9a-fA-F]{4} |
11 | \\[\x20-\xff])*)
12 | "/nx
13 | INTEGER = /(-?0|-?[1-9]\d*)/
14 | FLOAT = /(-?
15 | (?:0|[1-9]\d*)
16 | (?:
17 | \.\d+(?i:e[+-]?\d+) |
18 | \.\d+ |
19 | (?i:e[+-]?\d+)
20 | )
21 | )/x
22 | NAN = /NaN/
23 | INFINITY = /Infinity/
24 | MINUS_INFINITY = /-Infinity/
25 | OBJECT_OPEN = /\{/
26 | OBJECT_CLOSE = /\}/
27 | ARRAY_OPEN = /\[/
28 | ARRAY_CLOSE = /\]/
29 | PAIR_DELIMITER = /:/
30 | COLLECTION_DELIMITER = /,/
31 | TRUE = /true/
32 | FALSE = /false/
33 | NULL = /null/
34 | IGNORE = %r(
35 | (?:
36 | //[^\n\r]*[\n\r]| # line comments
37 | /\* # c-style comments
38 | (?:
39 | [^*/]| # normal chars
40 | /[^*]| # slashes that do not start a nested comment
41 | \*[^/]| # asterisks that do not end this comment
42 | /(?=\*/) # single slash before this comment's end
43 | )*
44 | \*/ # the End of this comment
45 | |[ \t\r\n]+ # whitespaces: space, horicontal tab, lf, cr
46 | )+
47 | )mx
48 |
49 | UNPARSED = Object.new
50 |
51 | # Creates a new JSON::Pure::Parser instance for the string _source_.
52 | #
53 | # It will be configured by the _opts_ hash. _opts_ can have the following
54 | # keys:
55 | # * *max_nesting*: The maximum depth of nesting allowed in the parsed data
56 | # structures. Disable depth checking with :max_nesting => false|nil|0,
57 | # it defaults to 19.
58 | # * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
59 | # defiance of RFC 4627 to be parsed by the Parser. This option defaults
60 | # to false.
61 | # * *create_additions*: If set to false, the Parser doesn't create
62 | # additions even if a matchin class and create_id was found. This option
63 | # defaults to true.
64 | def initialize(source, opts = {})
65 | super
66 | if !opts.key?(:max_nesting) # defaults to 19
67 | @max_nesting = 19
68 | elsif opts[:max_nesting]
69 | @max_nesting = opts[:max_nesting]
70 | else
71 | @max_nesting = 0
72 | end
73 | @allow_nan = !!opts[:allow_nan]
74 | ca = true
75 | ca = opts[:create_additions] if opts.key?(:create_additions)
76 | @create_id = ca ? JSON.create_id : nil
77 | end
78 |
79 | alias source string
80 |
81 | # Parses the current JSON string _source_ and returns the complete data
82 | # structure as a result.
83 | def parse
84 | reset
85 | obj = nil
86 | until eos?
87 | case
88 | when scan(OBJECT_OPEN)
89 | obj and raise ParserError, "source '#{peek(20)}' not in JSON!"
90 | @current_nesting = 1
91 | obj = parse_object
92 | when scan(ARRAY_OPEN)
93 | obj and raise ParserError, "source '#{peek(20)}' not in JSON!"
94 | @current_nesting = 1
95 | obj = parse_array
96 | when skip(IGNORE)
97 | ;
98 | else
99 | raise ParserError, "source '#{peek(20)}' not in JSON!"
100 | end
101 | end
102 | obj or raise ParserError, "source did not contain any JSON!"
103 | obj
104 | end
105 |
106 | private
107 |
108 | # Unescape characters in strings.
109 | UNESCAPE_MAP = Hash.new { |h, k| h[k] = k.chr }
110 | UNESCAPE_MAP.update({
111 | ?" => '"',
112 | ?\\ => '\\',
113 | ?/ => '/',
114 | ?b => "\b",
115 | ?f => "\f",
116 | ?n => "\n",
117 | ?r => "\r",
118 | ?t => "\t",
119 | ?u => nil,
120 | })
121 |
122 | def parse_string
123 | if scan(STRING)
124 | return '' if self[1].empty?
125 | self[1].gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c|
126 | if u = UNESCAPE_MAP[$&[1]]
127 | u
128 | else # \uXXXX
129 | bytes = ''
130 | i = 0
131 | while c[6 * i] == ?\\ && c[6 * i + 1] == ?u
132 | bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
133 | i += 1
134 | end
135 | JSON::UTF16toUTF8.iconv(bytes)
136 | end
137 | end
138 | else
139 | UNPARSED
140 | end
141 | rescue Iconv::Failure => e
142 | raise GeneratorError, "Caught #{e.class}: #{e}"
143 | end
144 |
145 | def parse_value
146 | case
147 | when scan(FLOAT)
148 | Float(self[1])
149 | when scan(INTEGER)
150 | Integer(self[1])
151 | when scan(TRUE)
152 | true
153 | when scan(FALSE)
154 | false
155 | when scan(NULL)
156 | nil
157 | when (string = parse_string) != UNPARSED
158 | string
159 | when scan(ARRAY_OPEN)
160 | @current_nesting += 1
161 | ary = parse_array
162 | @current_nesting -= 1
163 | ary
164 | when scan(OBJECT_OPEN)
165 | @current_nesting += 1
166 | obj = parse_object
167 | @current_nesting -= 1
168 | obj
169 | when @allow_nan && scan(NAN)
170 | NaN
171 | when @allow_nan && scan(INFINITY)
172 | Infinity
173 | when @allow_nan && scan(MINUS_INFINITY)
174 | MinusInfinity
175 | else
176 | UNPARSED
177 | end
178 | end
179 |
180 | def parse_array
181 | raise NestingError, "nesting of #@current_nesting is to deep" if
182 | @max_nesting.nonzero? && @current_nesting > @max_nesting
183 | result = []
184 | delim = false
185 | until eos?
186 | case
187 | when (value = parse_value) != UNPARSED
188 | delim = false
189 | result << value
190 | skip(IGNORE)
191 | if scan(COLLECTION_DELIMITER)
192 | delim = true
193 | elsif match?(ARRAY_CLOSE)
194 | ;
195 | else
196 | raise ParserError, "expected ',' or ']' in array at '#{peek(20)}'!"
197 | end
198 | when scan(ARRAY_CLOSE)
199 | if delim
200 | raise ParserError, "expected next element in array at '#{peek(20)}'!"
201 | end
202 | break
203 | when skip(IGNORE)
204 | ;
205 | else
206 | raise ParserError, "unexpected token in array at '#{peek(20)}'!"
207 | end
208 | end
209 | result
210 | end
211 |
212 | def parse_object
213 | raise NestingError, "nesting of #@current_nesting is to deep" if
214 | @max_nesting.nonzero? && @current_nesting > @max_nesting
215 | result = {}
216 | delim = false
217 | until eos?
218 | case
219 | when (string = parse_string) != UNPARSED
220 | skip(IGNORE)
221 | unless scan(PAIR_DELIMITER)
222 | raise ParserError, "expected ':' in object at '#{peek(20)}'!"
223 | end
224 | skip(IGNORE)
225 | unless (value = parse_value).equal? UNPARSED
226 | result[string] = value
227 | delim = false
228 | skip(IGNORE)
229 | if scan(COLLECTION_DELIMITER)
230 | delim = true
231 | elsif match?(OBJECT_CLOSE)
232 | ;
233 | else
234 | raise ParserError, "expected ',' or '}' in object at '#{peek(20)}'!"
235 | end
236 | else
237 | raise ParserError, "expected value in object at '#{peek(20)}'!"
238 | end
239 | when scan(OBJECT_CLOSE)
240 | if delim
241 | raise ParserError, "expected next name, value pair in object at '#{peek(20)}'!"
242 | end
243 | if @create_id and klassname = result[@create_id]
244 | klass = JSON.deep_const_get klassname
245 | break unless klass and klass.json_creatable?
246 | result = klass.json_create(result)
247 | end
248 | break
249 | when skip(IGNORE)
250 | ;
251 | else
252 | raise ParserError, "unexpected token in object at '#{peek(20)}'!"
253 | end
254 | end
255 | result
256 | end
257 | end
258 | end
259 | end
260 |
--------------------------------------------------------------------------------
/jruby-version-builder/json/version.rb:
--------------------------------------------------------------------------------
1 | module JSON
2 | # JSON version
3 | VERSION = '1.1.3'
4 | VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5 | VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6 | VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
7 | VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
8 | VARIANT_BINARY = false
9 | end
10 |
--------------------------------------------------------------------------------