haplo 2.4.4-java → 2.5.3-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/debuggers.rb ADDED
@@ -0,0 +1,109 @@
1
+ # Haplo Plugin Tool http://docs.haplo.org/dev/tool/plugin
2
+ # (c) Haplo Services Ltd 2006 - 2016 http://www.haplo-services.com
3
+ # This Source Code Form is subject to the terms of the Mozilla Public
4
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+
8
+ module PluginTool
9
+
10
+ @@profile_output = nil
11
+
12
+ def self.request_profile(options)
13
+ output_file = $stdout
14
+ close_output_file = false
15
+ if options.profile_file
16
+ output_file = File.open(options.profile_file, "a")
17
+ close_output_file = true
18
+ end
19
+
20
+ formatter = nil
21
+ case options.profile_format || 'tree'
22
+ when 'tree'
23
+ @@profile_output = ProfilerFormatterTree.new(output_file)
24
+ when 'raw'
25
+ @@profile_output = ProfilerFormatterRaw.new(output_file)
26
+ else
27
+ puts "Unknown profiler format: #{options.profile_format}"
28
+ exit 1
29
+ end
30
+
31
+ if 'OK' == PluginTool.post("/api/development-plugin-loader/debugger-profile-start", {:min => options.profile})
32
+ puts "JavaScript profiler started."
33
+ else
34
+ puts "Error starting JavaScript profiler."
35
+ exit 1
36
+ end
37
+ at_exit do
38
+ puts
39
+ puts "Disabling JavaScript profiler..."
40
+ PluginTool.post("/api/development-plugin-loader/debugger-profile-stop")
41
+ puts "JavaScript profiler disabled."
42
+ output_file.close if close_output_file
43
+ end
44
+ end
45
+
46
+ class ProfilerFormatter
47
+ def initialize(output_file)
48
+ @output_file = output_file
49
+ end
50
+ def format(report)
51
+ _format(report, @output_file)
52
+ @output_file.flush
53
+ end
54
+ end
55
+
56
+ class ProfilerFormatterRaw < ProfilerFormatter
57
+ def _format(report, output_file)
58
+ output_file.write(report)
59
+ end
60
+ end
61
+
62
+ class ProfilerFormatterTree < ProfilerFormatter
63
+ def _format(report, output_file)
64
+ report.split("\n").each do |line|
65
+ depth, time, percent, count, position = line.split("\t")
66
+ if depth == 'REPORT'
67
+ output_file.write("PROFILE -- #{Time.new(time)}\n")
68
+ elsif depth == 'OMIT'
69
+ output_file.write((" "*time.to_i)+"... children omitted\n")
70
+ else
71
+ output_file.write((" "*depth.to_i)+"#{percent} #{count} #{time.to_i / 1000000} #{position}\n")
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def self.profiler_handle_report(report)
78
+ if @@profile_output
79
+ @@profile_output.format(report)
80
+ end
81
+ end
82
+
83
+ # -------------------------------------------------------------------------
84
+
85
+ def self.request_coverage(options)
86
+
87
+ format = options.coverage_format || 'raw'
88
+ if format != 'raw'
89
+ puts "Unknown coverage format: #{format}"
90
+ exit 1
91
+ end
92
+
93
+ if 'OK' == PluginTool.post("/api/development-plugin-loader/debugger-coverage-start")
94
+ puts "Coverage capture started."
95
+ else
96
+ puts "Error starting coverage capture."
97
+ exit 1
98
+ end
99
+
100
+ at_exit do
101
+ coverage = PluginTool.post("/api/development-plugin-loader/debugger-coverage-stop")
102
+ # TODO: Check errors
103
+ File.open(options.coverage_file, "w") { |f| f.write coverage }
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+
Binary file
@@ -0,0 +1,46 @@
1
+
2
+ module PluginTool
3
+
4
+ def self.i18n_extract_text(plugins)
5
+ text = {}
6
+
7
+ # Get text from templates. This is exact, because each template is parsed.
8
+ parser_config = TemplateParserConfiguration.new
9
+ plugins.each do |plugin|
10
+ Dir.glob("#{plugin.plugin_dir}/template/**/*.hsvt").sort.each do |template|
11
+ template = Java::OrgHaploTemplateHtml::Parser.new(File.read(template), "extract", parser_config).parse()
12
+ template.extractTranslatedStrings().each do |string|
13
+ text[string] = string
14
+ end
15
+ end
16
+ end
17
+
18
+ # Get text from JS files, which isn't exact, because it just relies on convention and hopes for the best.
19
+ plugins.each do |plugin|
20
+ Dir.glob("#{plugin.plugin_dir}/js/**/*.js").sort.each do |js_file|
21
+ js = File.read(js_file)
22
+ [/\bi\['([^']+)'\]/, /\bi\["([^"]+)"\]/].each do |regexp|
23
+ js.scan(regexp) do
24
+ text[$1] = $1
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ # Last, add in any of the default locale's text, so where text is looked up by symbol, the translation is included.
31
+ plugins.each do |plugin|
32
+ ['global','local'].each do |scope|
33
+ maybe_strings = "#{plugin.plugin_dir}/i18n/#{scope}/#{plugin.default_locale_id}.template.json"
34
+ if File.exist?(maybe_strings)
35
+ strings = JSON.parse(File.read(maybe_strings))
36
+ strings.each do |k,v|
37
+ text[k] = v
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ puts JSON.pretty_generate(text)
44
+ end
45
+
46
+ end
data/lib/notifications.rb CHANGED
@@ -69,6 +69,9 @@ module PluginTool
69
69
  when 'log '
70
70
  # Output from console.log()
71
71
  puts "LOG:#{data}"
72
+ when 'prof'
73
+ # Profiler report
74
+ PluginTool.profiler_handle_report(data)
72
75
  when 'audt'
73
76
  decoded = JSON.parse(data)
74
77
  kind = decoded.find { |name,value| name == 'auditEntryType' }.last
data/lib/packing.rb CHANGED
@@ -50,7 +50,10 @@ module PluginTool
50
50
  end
51
51
  # Minimise file?
52
52
  unless filename =~ /\A(js|test)\//
53
- data = minimiser.process(data, filename)
53
+ # Is this file explicitly excluded from minimisation?
54
+ unless plugin.exclude_files_from_minimisation.include?(filename)
55
+ data = minimiser.process(data, filename)
56
+ end
54
57
  end
55
58
  hash = Digest::SHA256.hexdigest(data)
56
59
  # Make sure output directory exists, write file
data/lib/plugin.rb CHANGED
@@ -29,6 +29,11 @@ module PluginTool
29
29
  attr_accessor :depend
30
30
  attr_accessor :loaded_plugin_id
31
31
 
32
+ def default_locale_id
33
+ # TODO: Other default locales
34
+ 'en'
35
+ end
36
+
32
37
  # ---------------------------------------------------------------------------------------------------------
33
38
 
34
39
  @@pending_apply = []
@@ -97,6 +102,17 @@ module PluginTool
97
102
  end
98
103
  end
99
104
 
105
+ def exclude_files_from_minimisation
106
+ @exclude_files_from_minimisation ||= begin
107
+ # developer.json file might specify files which should skip minimisation when packing
108
+ if developer_json['excludeFromMinimisation'].kind_of?(Array)
109
+ developer_json['excludeFromMinimisation']
110
+ else
111
+ []
112
+ end
113
+ end
114
+ end
115
+
100
116
  # ---------------------------------------------------------------------------------------------------------
101
117
 
102
118
  def command(cmd, errors)
@@ -175,11 +191,16 @@ module PluginTool
175
191
  hash = action
176
192
  # Minimise file before uploading?
177
193
  if @options.minimiser != nil && filename =~ /\A(static|template)\//
178
- size_before = data.length
179
- data = @options.minimiser.process(data, filename)
180
- size_after = data.length
181
- hash = Digest::SHA256.hexdigest(data)
182
- puts " minimisation: #{size_before} -> #{size_after} (#{(size_after * 100) / size_before}%)"
194
+ # Is this file explicitly excluded from minimisation?
195
+ unless exclude_files_from_minimisation.include?(filename)
196
+ size_before = data.length
197
+ data = @options.minimiser.process(data, filename)
198
+ size_after = data.length
199
+ hash = Digest::SHA256.hexdigest(data)
200
+ puts " minimisation: #{size_before} -> #{size_after} (#{(size_after * 100) / size_before}%)"
201
+ else
202
+ puts " minimisation: skipped by developer.json, unmodified file uploaded"
203
+ end
183
204
  end
184
205
  r = PluginTool.post_with_json_response("/api/development-plugin-loader/put-file/#{@loaded_plugin_id}", params, {:file => [filename, data]})
185
206
  if r["result"] == 'success'
data/lib/plugin_tool.rb CHANGED
@@ -17,13 +17,13 @@ end
17
17
  PluginTool.try_load_custom
18
18
 
19
19
  WORKSPACE_FILE = 'workspace.json'
20
- LOCAL_ONLY_COMMANDS = {"license-key" => true, "pack" => true, "check" => true, "new" => true, "list" => true}
20
+ LOCAL_ONLY_COMMANDS = {"license-key" => true, "pack" => true, "check" => true, "new" => true, "list" => true, "extract-text" => true}
21
21
  NO_DEPENDENCY_COMMANDS = {"reset-db" => true}.merge(LOCAL_ONLY_COMMANDS)
22
22
  NO_DEPENDENCY_COMMANDS.delete('list')
23
23
  PLUGIN_SEARCH_PATH = ['.']
24
24
 
25
25
  # Options for passing to plugin objects
26
- options = Struct.new(:output, :minimiser, :no_dependency, :with_dependency, :exclude_with_prefix, :no_console, :show_system_audit, :args, :force, :turbo, :server_substring, :restrict_to_app_id).new
26
+ options = Struct.new(:output, :minimiser, :no_dependency, :with_dependency, :exclude_with_prefix, :no_console, :show_system_audit, :args, :force, :turbo, :profile, :profile_file, :profile_format, :coverage_file, :coverage_format, :server_substring, :restrict_to_app_id).new
27
27
 
28
28
  # Parse arguments
29
29
  show_help = false
@@ -37,6 +37,11 @@ opts = GetoptLong.new(
37
37
  ['--server', '-s', GetoptLong::REQUIRED_ARGUMENT],
38
38
  ['--force', GetoptLong::NO_ARGUMENT],
39
39
  ['--turbo', GetoptLong::NO_ARGUMENT],
40
+ ['--profile', GetoptLong::REQUIRED_ARGUMENT],
41
+ ['--profile-file', GetoptLong::REQUIRED_ARGUMENT],
42
+ ['--profile-format', GetoptLong::REQUIRED_ARGUMENT],
43
+ ['--coverage-file', GetoptLong::REQUIRED_ARGUMENT],
44
+ ['--coverage-format', GetoptLong::REQUIRED_ARGUMENT],
40
45
  ['--output', GetoptLong::REQUIRED_ARGUMENT],
41
46
  ['--pack-restrict-to-app-id', GetoptLong::REQUIRED_ARGUMENT],
42
47
  ['--no-console', '-n', GetoptLong::NO_ARGUMENT],
@@ -72,6 +77,16 @@ opts.each do |opt, argument|
72
77
  options.force = true
73
78
  when '--turbo'
74
79
  options.turbo = true
80
+ when '--profile'
81
+ options.profile = argument.to_f
82
+ when '--profile-file'
83
+ options.profile_file = argument
84
+ when '--profile-format'
85
+ options.profile_format = argument
86
+ when '--coverage-file'
87
+ options.coverage_file = argument
88
+ when '--coverage-format'
89
+ options.coverage_format = argument
75
90
  end
76
91
  end
77
92
  # Handle rest of command line -- first arg is the command, the rest are passed on
@@ -144,7 +159,7 @@ unless LOCAL_ONLY_COMMANDS[PLUGIN_TOOL_COMMAND]
144
159
  PluginTool.setup_auth(options)
145
160
  PluginTool.check_for_certificate_file
146
161
  application_info = PluginTool.get_application_info
147
- puts "Remote application name: #{(application_info["name"]||'').to_s.strip.gsub(/\s+/,' ')}"
162
+ STDERR.puts "Remote application name: #{(application_info["name"]||'').to_s.strip.gsub(/\s+/,' ')}"
148
163
  end
149
164
 
150
165
  if PLUGIN_TOOL_COMMAND == 'devtools'
@@ -171,6 +186,18 @@ if PLUGIN_TOOL_COMMAND == 'template-debugging'
171
186
  end
172
187
  end
173
188
 
189
+ if PLUGIN_TOOL_COMMAND == 'i18n-debugging'
190
+ disable = (ARGV[0] == 'disable')
191
+ puts disable ? "Disabling i18n debugging..." : "Enabling i18n debugging..."
192
+ if 'OK' == PluginTool.post("/api/development-plugin-loader/i18n-debugging?enable=#{disable ? '0' : '1'}")
193
+ puts "Done"
194
+ exit 0
195
+ else
196
+ puts "Error updating server"
197
+ exit 1
198
+ end
199
+ end
200
+
174
201
  # If the user didn't requested a plugin, try to use the application info to select the root plugin
175
202
  if requested_plugins.empty? && application_info
176
203
  application_root_plugin = application_info["config"]["applicationRootPlugin"]
@@ -291,7 +318,7 @@ if PLUGIN_TOOL_COMMAND == 'list'
291
318
  exit 0
292
319
  end
293
320
 
294
- puts "#{plugins.length} plugin#{plugins.length != 1 ? 's' : ''}"
321
+ STDERR.puts "#{plugins.length} plugin#{plugins.length != 1 ? 's' : ''}"
295
322
 
296
323
  # Custom behaviour for this repo?
297
324
  PluginTool.custom_behaviour.start(plugins, PLUGIN_TOOL_COMMAND, options, LOCAL_ONLY_COMMANDS[PLUGIN_TOOL_COMMAND])
@@ -304,12 +331,22 @@ when 'pack'
304
331
  when 'check'
305
332
  PluginTool.check_plugins(plugins)
306
333
  exit 0
334
+ when 'extract-text'
335
+ PluginTool.i18n_extract_text(plugins)
336
+ exit 0
307
337
  end
308
338
 
309
339
  # Set up local plugin objects against server
310
340
  unless LOCAL_ONLY_COMMANDS[PLUGIN_TOOL_COMMAND]
311
341
  PluginTool.custom_behaviour.server_ready(plugins, PLUGIN_TOOL_COMMAND, options)
312
342
  plugins.each { |p| p.setup_for_server }
343
+
344
+ if options.profile
345
+ PluginTool.request_profile(options)
346
+ end
347
+ if options.coverage_file
348
+ PluginTool.request_coverage(options)
349
+ end
313
350
  end
314
351
 
315
352
  # Run the command
data/lib/run.rb CHANGED
@@ -65,9 +65,11 @@ require "#{PLUGIN_TOOL_ROOT_DIR}/lib/syntax_checking.rb"
65
65
  require "#{PLUGIN_TOOL_ROOT_DIR}/lib/notifications.rb"
66
66
  require "#{PLUGIN_TOOL_ROOT_DIR}/lib/plugin.rb"
67
67
  require "#{PLUGIN_TOOL_ROOT_DIR}/lib/new_plugin.rb"
68
+ require "#{PLUGIN_TOOL_ROOT_DIR}/lib/debuggers.rb"
68
69
  require "#{PLUGIN_TOOL_ROOT_DIR}/lib/misc.rb"
69
70
  require "#{PLUGIN_TOOL_ROOT_DIR}/lib/watchers.rb"
70
71
  require "#{PLUGIN_TOOL_ROOT_DIR}/lib/minimise.rb"
71
72
  require "#{PLUGIN_TOOL_ROOT_DIR}/lib/check.rb"
72
73
  require "#{PLUGIN_TOOL_ROOT_DIR}/lib/custom.rb"
74
+ require "#{PLUGIN_TOOL_ROOT_DIR}/lib/i18n_extract_text.rb"
73
75
  require "#{PLUGIN_TOOL_ROOT_DIR}/lib/plugin_tool.rb"
data/lib/server.rb CHANGED
@@ -50,6 +50,7 @@ module PluginTool
50
50
  http.use_ssl = true
51
51
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
52
52
  http.cert_store = ssl_ca
53
+ http.read_timeout = 3600 # 1 hour, in case a test runs for a very long time
53
54
  http.start
54
55
  http
55
56
  end
data/lib/usage.txt CHANGED
@@ -68,6 +68,10 @@ Commands:
68
68
  Enable or disable template debugging, including adding comments in generated HTML
69
69
  to indicate which templates were used.
70
70
 
71
+ i18n-debugging [disable]
72
+ Enable or disable internationalisation debugging, including indicating which text
73
+ in the user interface is translated.
74
+
71
75
  auth [SERVER]
72
76
  Authorise with server. SERVER can optionally include a non-default port number.
73
77
 
@@ -93,6 +97,10 @@ Commands:
93
97
  check
94
98
  Perform checks on the plugin as a quick test before it's submitted for review.
95
99
 
100
+ extract-text
101
+ Extract translatable text from templates, and attempt to extract text from JavaScript
102
+ files, and output a JSON data structure suitable for translation.
103
+
96
104
  license-key <application-id>
97
105
  Generate a license key to allow plugin installation by a client. The numeric
98
106
  application ID is displayed during plugin installation.
data/lib/version.txt CHANGED
@@ -1 +1 @@
1
- ba15ef2
1
+ a60e0f9
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haplo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.4
4
+ version: 2.5.3
5
5
  platform: java
6
6
  authors:
7
7
  - Haplo Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-24 00:00:00.000000000 Z
11
+ date: 2021-07-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Development tools for developing Haplo plugins, see https://haplo.org
14
14
  email: client.services@haplo-services.com
@@ -24,9 +24,11 @@ files:
24
24
  - lib/auth.rb
25
25
  - lib/check.rb
26
26
  - lib/custom.rb
27
+ - lib/debuggers.rb
27
28
  - lib/haplo-templates.jar
28
29
  - lib/hmac.rb
29
30
  - lib/hsvt_parser_config.rb
31
+ - lib/i18n_extract_text.rb
30
32
  - lib/js.jar
31
33
  - lib/js_min.js
32
34
  - lib/js_syntax_test.js
@@ -69,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
71
  version: '0'
70
72
  requirements: []
71
73
  rubyforge_project:
72
- rubygems_version: 2.7.6
74
+ rubygems_version: 2.7.9
73
75
  signing_key:
74
76
  specification_version: 4
75
77
  summary: Haplo Plugin Tool