beta_tools 0.0.4

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.
Files changed (97) hide show
  1. data/.gitignore +11 -0
  2. data/Capfile +2 -0
  3. data/Gemfile +4 -0
  4. data/README +7 -0
  5. data/Rakefile +7 -0
  6. data/beta_tools.gemspec +31 -0
  7. data/bin/deploy +9 -0
  8. data/bin/documentation_daemon +12 -0
  9. data/bin/loginToUrl +6 -0
  10. data/bin/onVpn +6 -0
  11. data/bin/pub +91 -0
  12. data/bin/query_solr +11 -0
  13. data/bin/solrWebApp +6 -0
  14. data/conf/schema.xml +220 -0
  15. data/config/deploy.rb +44 -0
  16. data/config.ru +2 -0
  17. data/docs/#next_design.mmd# +0 -0
  18. data/features/deploy.feature +9 -0
  19. data/features/git.feature +15 -0
  20. data/features/maven.feature +21 -0
  21. data/features/step_definitions/deploy_steps.rb +11 -0
  22. data/features/step_definitions/git_steps.rb +20 -0
  23. data/features/step_definitions/maven_steps.rb +35 -0
  24. data/features/support/env.rb +8 -0
  25. data/int/it_tools/suite_it_tools.rb +2 -0
  26. data/int/it_tools/test_integ1.rb +17 -0
  27. data/lib/beta_tools/version.rb +3 -0
  28. data/lib/beta_tools.rb +5 -0
  29. data/lib/it_tools/calc.rb +14 -0
  30. data/lib/it_tools/config.ru +2 -0
  31. data/lib/it_tools/environment.rb +86 -0
  32. data/lib/it_tools/git.rb +3 -0
  33. data/lib/it_tools/html_publish.rb +287 -0
  34. data/lib/it_tools/mail.rb +21 -0
  35. data/lib/it_tools/maven.rb +101 -0
  36. data/lib/it_tools/md5.rb +4 -0
  37. data/lib/it_tools/multipart.rb +78 -0
  38. data/lib/it_tools/network_tools.rb +72 -0
  39. data/lib/it_tools/options.rb +46 -0
  40. data/lib/it_tools/pub_driver.rb +188 -0
  41. data/lib/it_tools/publisher2.rb +232 -0
  42. data/lib/it_tools/sample.rb +9 -0
  43. data/lib/it_tools/shared.rb +22 -0
  44. data/lib/it_tools/solr.rb +157 -0
  45. data/lib/it_tools/views/search_results.erb +16 -0
  46. data/log/thin.log +177 -0
  47. data/spec/it_tools/deploy_spec.rb +20 -0
  48. data/spec/spec_helper.rb +0 -0
  49. data/test/bin/test_pub.rb +30 -0
  50. data/test/cleaner.rb +6 -0
  51. data/test/driver.rb +24 -0
  52. data/test/integration/tp.rb +107 -0
  53. data/test/it_tools/for_debugger.rb +4 -0
  54. data/test/it_tools/publisher2.rb +13 -0
  55. data/test/it_tools/suite_it_tools.rb +6 -0
  56. data/test/it_tools/suite_it_tools.rb~ +13 -0
  57. data/test/it_tools/test_deploy.rb +83 -0
  58. data/test/it_tools/test_html_publish.rb +54 -0
  59. data/test/it_tools/test_maven.rb +31 -0
  60. data/test/it_tools/test_multipart.rb +31 -0
  61. data/test/it_tools/test_network_tools.rb +14 -0
  62. data/test/it_tools/test_publisher2.rb +42 -0
  63. data/test/it_tools/test_publisher2_support.rb +16 -0
  64. data/test/it_tools/test_sample.rb +10 -0
  65. data/test/it_tools/test_shared.rb +36 -0
  66. data/test/it_tools/test_solr.rb +22 -0
  67. data/test/it_tools/test_solr2.rb +22 -0
  68. data/testdata/assembly_pom.xml +157 -0
  69. data/testdata/desir.txt +39 -0
  70. data/testdata/ear_pom.xml +82 -0
  71. data/testdata/java.html +524 -0
  72. data/testdata/pom.xml +174 -0
  73. data/testdata/publish/src_dir/#arch.mmd# +0 -0
  74. data/testdata/publish/src_dir/ajax-loader.gif +0 -0
  75. data/testdata/publish/src_dir/file1.mmd +5 -0
  76. data/testdata/publish/src_dir/file2.mmd +3 -0
  77. data/testdata/publish/src_dir/file3.abc +0 -0
  78. data/testdata/publish/src_dir/file4.mmd +3 -0
  79. data/testdata/publish/src_dir/help.png +0 -0
  80. data/testdata/publish/src_dir/images/linux.jpeg +0 -0
  81. data/testdata/publish/src_dir/inputStyles.css +0 -0
  82. data/testdata/publish/src_dir/search.html +0 -0
  83. data/testdata/publish/src_dir/search.js +0 -0
  84. data/testdata/publish/target_dir/.@arch.html +0 -0
  85. data/testdata/publish/target_dir/file1.html +7 -0
  86. data/testdata/publish/target_dir/file2.html +5 -0
  87. data/testdata/publish/target_dir/search.js +0 -0
  88. data/testdata/publish/target_dir_static/.@arch.html +1 -0
  89. data/testdata/publish/target_dir_static/file1.html +7 -0
  90. data/testdata/publish/target_dir_static/index.html +1 -0
  91. data/testdata/publish/target_dir_static/style.css +61 -0
  92. data/testdata/ruby.mmd +404 -0
  93. data/testdata/simple.mmd +3 -0
  94. data/testdata/simple.xml +3 -0
  95. data/testdata/small.txt +2 -0
  96. data/testdata/utf8_chars.txt +1 -0
  97. metadata +338 -0
@@ -0,0 +1,3 @@
1
+ module BetaTools
2
+ VERSION = "0.0.4"
3
+ end
data/lib/beta_tools.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "beta_tools/version"
2
+
3
+ module BetaTools
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,14 @@
1
+ class Calculator
2
+ def initialize
3
+ @stack = []
4
+ end
5
+ def enter( value )
6
+ @stack.push value
7
+ end
8
+ def screen
9
+ @stack[0]
10
+ end
11
+ def add
12
+ @stack.push( @stack.pop + @stack.pop )
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__) + '/solr'
2
+ run WebApp
@@ -0,0 +1,86 @@
1
+ require_relative 'options'
2
+
3
+ class Environment
4
+ attr_accessor :ops
5
+
6
+ def initialize(options = {})
7
+ defaults = { :jar_with_dependencies => false, :debug => true, :dry_run => false }
8
+ @ops = defaults.merge options
9
+ command_line_opts = Options.new
10
+ @ops = @ops.merge command_line_opts.options
11
+ end
12
+
13
+ def set_options(options = {})
14
+ @ops = @ops.merge(options)
15
+ end
16
+
17
+ def deploy(env, options = {})
18
+ defaults = { :jar_with_dependencies => false }
19
+ options = defaults.merge(options)
20
+ @ops = @ops.merge(options)
21
+ puts self.inspect if ops[:debug]
22
+ cmd = get_deploy_command(env)
23
+ puts "[Command]: " + cmd if ops[:debug]
24
+ unless ops[:dry_run]
25
+ system(cmd)
26
+ end
27
+ end
28
+
29
+ def get_deploy_command(env,file, options = {})
30
+ @ops = @ops.merge(options)
31
+ dd = get_deploy_dir(env)
32
+ dh = get_hostname(env)
33
+ du = get_deploy_user(env)
34
+ mvn = Maven.new(file, @ops)
35
+ an = mvn.get_artifact_name(file)
36
+ ban = mvn.get_built_artifact_name_with_version(file)
37
+ puts "[Built maven artifact]: " + ban if ops[:debug]
38
+ sc = get_scp_command(an, du, dh, dd, ban)
39
+ end
40
+
41
+ def get_scp_command(src_artifact_name, login_as_who, dest_hostname, dest_dir, dest_artifact_name = nil)
42
+ deploy_cmd = "rsync -avP --stats "
43
+ if @ops[:use_scp]
44
+ deploy_cmd = "scp "
45
+ end
46
+ deploy_cmd += "target/#{src_artifact_name} #{login_as_who}@#{dest_hostname}:#{dest_dir}"
47
+ if dest_dir
48
+ deploy_cmd += "/#{dest_artifact_name}"
49
+ end
50
+ return deploy_cmd;
51
+ end
52
+
53
+ def get_solr_base_url(env)
54
+ solr_base_url = {
55
+ 'loc' => 'http://localhost:8983/solr/'
56
+ }
57
+ return solr_base_url[env]
58
+ end
59
+ def get_deploy_dir(environment)
60
+ user = {
61
+ 'dev' => '/scratch/ngsp/hrmsToCrmod',
62
+ 'stg' => '/u02/webapps/myhelp/custom',
63
+ 'prod' => '/u01/app/oracle/ngsp/wls4/user_projects/domains/base_domain2/deployments'
64
+ }
65
+ return user[environment];
66
+ end
67
+ def get_deploy_user(environment)
68
+ f = 'ftravers'
69
+ user = {
70
+ 'dev' => f,
71
+ 'stg' => 'oracle',
72
+ 'prod' => f
73
+ }
74
+ return user[environment];
75
+ end
76
+ def get_hostname(environment)
77
+ domain = ".us.oracle.com"
78
+ hosts = {
79
+ 'loc' => 'localhost',
80
+ 'dev' => 'sta00418' + domain,
81
+ 'stg' => 'wd1125' + domain,
82
+ 'prod' => 'amtv1062' + domain
83
+ }
84
+ return hosts[environment]
85
+ end
86
+ end # class
@@ -0,0 +1,3 @@
1
+ class Git
2
+
3
+ end
@@ -0,0 +1,287 @@
1
+ require "pygments"
2
+ require "redcarpet"
3
+ require "RedCloth"
4
+ require 'pathname'
5
+ require 'fileutils'
6
+ require 'logger'
7
+
8
+ require_relative 'solr'
9
+ require_relative 'shared'
10
+
11
+ module Website
12
+ class HTMLwithPygments < Redcarpet::Render::HTML
13
+ attr_accessor :ops, :log
14
+
15
+ def initialize(options = {})
16
+ super
17
+ @ops = {}
18
+ @ops.merge! options
19
+ @log = Logger.new('log.txt')
20
+ if level = @ops[:debug_level]
21
+ @log.level = level
22
+ else
23
+ @log.level = Logger::INFO
24
+ end
25
+ $toc1 = ""
26
+ $last_header_level = 0
27
+ $last_header_count = 0
28
+ $header = Array.new()
29
+ 0.upto(6) { |i| $header[i] = 0 }
30
+ end
31
+
32
+ def block_code(code, language)
33
+ Pygments.highlight(code, :lexer => language)
34
+ end
35
+ def get_header_label( header_level )
36
+ index = header_level - 1
37
+ $header[index] = $header[index] + 1
38
+ header_level.upto($header.length - 1) { |i| $header[i] = 0 }
39
+ header_string = ""
40
+ 0.upto(header_level - 1) {
41
+ |i| if i == header_level - 1
42
+ header_string += $header[i].to_s
43
+ @log.debug "Header String: #{header_string}. Header Entry: #{$header[i]}"
44
+ else
45
+ header_string += $header[i].to_s + "."
46
+ end
47
+ }
48
+ return header_string
49
+ end
50
+ def set_less_significant_to_zero(header_level)
51
+ 10.times {|i| p i+1}
52
+ end
53
+ def header(text, header_level)
54
+ header_label = get_header_label(header_level)
55
+ id = text.gsub(" ", "_")
56
+ $toc1 += "<div class=\"toc#{header_level}\"><a href=\"##{id}\">#{header_label} - #{text}</a></div><br/>\n"
57
+ return "\n<h#{header_level} id=\"#{id}\">#{header_label} - #{text}</h#{header_level}>\n"
58
+ end
59
+ def postprocess(full_document)
60
+ temp = $toc1
61
+ $toc1 = ""
62
+ 0.upto(6) { |i| $header[i] = 0 }
63
+ return temp + full_document
64
+ end
65
+ end
66
+ class MarkdownConverter
67
+ attr_accessor :log, :ops, :markdown, :write_dir, :debug
68
+ def initialize(options = {})
69
+ @ops = {}
70
+ @defaults = { :debug => false }
71
+ unless options.nil?
72
+ @defaults = @defaults.merge(options)
73
+ end
74
+ @ops = @defaults.merge(@ops)
75
+ @debug = @ops[:debug]
76
+ @log = Logger.new('log.txt')
77
+ if level = @ops[:debug_level]
78
+ @log.level = level
79
+ else
80
+ @log.level = Logger::DEBUG
81
+ end
82
+ @markdown = Redcarpet::Markdown.new(HTMLwithPygments,
83
+ :fenced_code_blocks => true,
84
+ :tables => true,
85
+ :autolink => true,
86
+ :with_toc_data => true)
87
+ end
88
+ def set_options(options = {})
89
+ @ops = @ops.merge(options)
90
+ end
91
+ def to_markdown(content)
92
+ return markdown.render(content)
93
+ end
94
+ def convert_markdown_file(dir, file)
95
+ @log.debug "Converting file: #{file}"
96
+ contents = File.open(dir + "/" + file, "r").read
97
+ return convert_markdown_contents(contents)
98
+ end
99
+ def convert_markdown_contents(contents)
100
+ contents = contents.remove_non_ascii
101
+ html = @markdown.render(contents.force_encoding('US-ASCII'))
102
+ return html
103
+ end
104
+ def get_out_file(file, write_dir)
105
+ basename = File.basename(file, File.extname(file))
106
+ @log.debug "Filename without extension: #{basename}"
107
+ out_file = write_dir + "/" + basename + ".html"
108
+ return out_file
109
+ end
110
+ def get_file_basename(file)
111
+ basename = File.basename(file, File.extname(file))
112
+ end
113
+
114
+ def write_stylesheet(read_dir,write_dir)
115
+ contents = File.open(read_dir + "/inputStyles.css", "rb").read
116
+ css = Pygments.css
117
+ File.open(write_dir + "/style.css", 'w') {|f| f.write(css + "\n" + contents) }
118
+ end
119
+
120
+ def modded_since_last_publish(src_file, write_file)
121
+ src_file_ts = File.stat(src_file).mtime
122
+ if not File.exist?(write_file)
123
+ @log.debug "Target file doesn't exist, will copy source to dest: #{write_file}"
124
+ return true
125
+ end
126
+ write_file_ts = File.stat(write_file).mtime
127
+ @log.debug "[SRC]:#{src_file} - #{src_file_ts}"
128
+ @log.debug "[DEST]:#{write_file} - #{write_file_ts}"
129
+
130
+ # should return true or false depending on modification times...
131
+ if write_file_ts > src_file_ts
132
+ @log.debug "Source file older than output file, no need to regenerate."
133
+ return false
134
+ else
135
+ @log.debug "Source file more recent than output file, need to regenerate."
136
+ return true
137
+ end
138
+ end
139
+
140
+ def modified_since_last_publish(read_dir, file, write_dir)
141
+ basename = File.basename(file, File.extname(file))
142
+ write_file = write_dir + "/" + basename + ".html"
143
+ src_file = read_dir + "/" + file
144
+ return modded_since_last_publish src_file, write_file
145
+ end
146
+
147
+ def get_files_to_process(doc_dir, write_dir)
148
+ @log.debug "Begin processing directory: " + doc_dir
149
+ Dir.chdir(doc_dir)
150
+ all_mmd_files = []
151
+ files_to_process = []
152
+ Dir.foreach(doc_dir) do |file|
153
+ $last_header_level = 0
154
+ $last_header_count = 0
155
+ $header = Array.new
156
+ 0.upto(6) { |i| $header[i] = 0 }
157
+ convertedFile = false
158
+ if file == ".." or file == "."
159
+ @log.debug "Current entry is: #{file}, do nothing."
160
+ next;
161
+ end
162
+ if file.match(/^\.#/)
163
+ @log.debug "Do not process files that begin with .#. Filename: #{file}"
164
+ next;
165
+ end
166
+ if File.stat(doc_dir + "/" + file).directory?
167
+ @log.debug "#{file} is a directory, skip it."
168
+ next;
169
+ end
170
+ if File.extname(file) == ".mmd"
171
+ @log.debug "Found MultiMarkdown file: #{file}"
172
+ if modified_since_last_publish(doc_dir, file, write_dir)
173
+ files_to_process.push file
174
+ end
175
+ all_mmd_files.push(file);
176
+ next
177
+ end
178
+ @log.debug "File: #{file} is not a known format, skipping."
179
+ end
180
+ return files_to_process, all_mmd_files
181
+ end
182
+ def process_files(files_to_process, read_from_dir, write_dirs)
183
+ @log.debug write_dirs.inspect
184
+ @log.debug "files to process are:"
185
+ @log.debug files_to_process.inspect
186
+ @log.debug "number of files to process is: " + files_to_process.length.to_s
187
+ files_to_process.each do |file|
188
+ @log.debug "Current file is:"
189
+ @log.debug file.inspect
190
+ process_file file, read_from_dir, write_dirs
191
+ end
192
+ end
193
+ def process_file(file, read_dir, write_dirs)
194
+ @log.debug "Found file: "
195
+ @log.debug read_dir.inspect
196
+ @log.debug file.inspect
197
+ indexer_dir = write_dirs[:for_indexer_dir]
198
+ static_site_dir = write_dirs[:for_static_files_dir]
199
+ indexer_file_path = get_out_file(file, indexer_dir)
200
+ static_file_path = get_out_file(file, static_site_dir)
201
+ html = convert_markdown_file(read_dir, file)
202
+ write_contents_no_style(indexer_file_path, html)
203
+ write_contents_add_style(static_file_path,html)
204
+ send_to_indexer(indexer_file_path, html)
205
+ end
206
+ def send_to_indexer(file_path, html)
207
+ uploader = Solr::Upload.new(:solr_base_url => ops[:indexer_url])
208
+ file_name = get_file_basename(file_path)
209
+ uploader.upload_file( file_name, html, file_name )
210
+ end
211
+ def write_contents_no_style(out_file, html)
212
+ @log.debug "Writing file: #{out_file}"
213
+ File.open(out_file, 'w') {|f| f.write(html) }
214
+ end
215
+ def write_contents_add_style(out_file, html)
216
+ @log.debug "Writing file: #{out_file}"
217
+ style_info = '<head><LINK REL=StyleSheet HREF="style.css" TYPE="text/css"/></head>'
218
+ @log.debug "Writing html + style info to file: " + out_file
219
+ File.open(out_file, 'w') {|f| f.write(style_info + html) }
220
+ end
221
+ def create_index(index, write_dir)
222
+ index.sort! { |a,b| a.downcase <=> b.downcase }
223
+ file = File.open(write_dir + "/" +"index.html", 'w')
224
+ file.write("<html><body><ul>")
225
+ index.each { |filename|
226
+ basename = File.basename(filename, File.extname(filename))
227
+ file.write("<li/><a href=\"#{basename}.html\">#{basename}")
228
+ }
229
+ file.write("</ul></body></html>")
230
+ file.close()
231
+ end
232
+ def copy_search_files(from,to)
233
+ files = [ "search.html", "search.js", "ajax-loader.gif", "help.png" ]
234
+ files.each do |file|
235
+ FileUtils.cp from + "/" + file, to
236
+ end
237
+ end
238
+ def copy_images_dir(read_dir, write_dirs)
239
+ src_dir = read_dir + "/images/"
240
+ if not Dir.exists? src_dir
241
+ @log.debug "No images directory found."
242
+ return
243
+ end
244
+ @log.debug "Found images directory, will copy over now."
245
+ write_dirs.each do |write_dir|
246
+ files = Dir.glob(src_dir + '/*')
247
+ files.each do |file|
248
+ write_file = write_dir + "/" + (File.basename file).to_s
249
+ if modded_since_last_publish(file, write_file)
250
+ @log.debug "Copying image: " + file
251
+ FileUtils.cp_r file, write_dir
252
+ end
253
+ end
254
+ end
255
+ end
256
+
257
+ def go()
258
+ before = Time.now
259
+
260
+ read_dir = "/home/fenton/projects/documentation"
261
+ write_dir = "/home/fenton/bin/website/"
262
+ write_dir_static = "/home/fenton/bin/website_static"
263
+
264
+ files_to_process, all_mmd_files = get_files_to_process read_dir, write_dir
265
+ create_index all_mmd_files, write_dir_static
266
+ process_files files_to_process, read_dir, :for_indexer_dir => write_dir, :for_static_files_dir => write_dir_static
267
+ copy_images_dir read_dir, [write_dir,write_dir_static]
268
+ copy_search_files read_dir, write_dir
269
+ write_stylesheet read_dir, write_dir
270
+ write_stylesheet read_dir, write_dir_static
271
+
272
+ read_dir = "/home/fenton/projects/work-doco/docs"
273
+ write_dir = "/home/fenton/bin/work-doco/"
274
+ write_dir_static = "/home/fenton/bin/work-doco_static/"
275
+
276
+ files_to_process, all_mmd_files = get_files_to_process read_dir, write_dir
277
+ write_dirs = {
278
+ :for_indexer_dir => write_dir,
279
+ :for_static_files_dir => write_dir_static }
280
+ process_files files_to_process, read_dir, write_dirs
281
+ copy_images_dir read_dir, [write_dir,write_dir_static]
282
+ write_stylesheet read_dir, write_dir
283
+ write_stylesheet read_dir, write_dir_static
284
+ @log.debug "Elapsed time: #{Time.now - before}(s)"
285
+ end
286
+ end
287
+ end
@@ -0,0 +1,21 @@
1
+ require 'pony'
2
+
3
+ module ItTools
4
+ class MailTools
5
+ def sendSmtpSslMail(from,to,subject,body,user, password, host, port)
6
+ Pony.mail(:to => to, :from => from, :subject => subject, :body => body, :via => :smtp, :smtp => {
7
+ :host => host,
8
+ :port => port,
9
+ :user => user,
10
+ :password => password,
11
+ :auth => :login})
12
+ end
13
+ def sendMailToBeehive(from,to,subject,body,user, password)
14
+ sendSmtpSslMail(from,to,subject,body,user, password, "stbeehive.oracle.com", 465)
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+
21
+
@@ -0,0 +1,101 @@
1
+ require 'xmlsimple'
2
+ require_relative 'shared'
3
+ require 'logger'
4
+
5
+ class Maven
6
+ attr_accessor :ops, :pom, :re, :log
7
+ def initialize(xml_string, options = {})
8
+ defaults = { :jar_with_dependencies => false, :debug => true }
9
+ options = defaults.merge(options)
10
+ @ops = options
11
+ @pom = XmlSimple.xml_in xml_string
12
+ @re = SharedTool::RegularExpression.new
13
+ @log = Logger.new 'log.txt'
14
+ if level = @ops[:debug_level]
15
+ @log.level = level
16
+ else
17
+ @log.level = Logger::INFO
18
+ end
19
+ process_pom
20
+ end
21
+ def process_pom
22
+ @ops[:artifactId] = @pom['artifactId'][0]
23
+ @ops[:version] = @pom['version'][0]
24
+ @ops[:prev_version] = get_prev_version @ops[:version]
25
+ end
26
+
27
+ def build(options = {})
28
+ defaults = { :jar_with_dependencies => false, :environment_specific => false }
29
+ options = defaults.merge(options)
30
+ @ops = @ops.merge(options)
31
+ build_command = "mvn package"
32
+ if @ops[:jar_with_dependencies]
33
+ build_command = "mvn assembly:assembly"
34
+ end
35
+ if @ops[:env]
36
+ puts "WARNING: You are building an environment specific artifact, use caution."
37
+ profile = get_profile_name(@ops[:env])
38
+ build_command += " -P#{profile}"
39
+ end
40
+ if ops[:dry_run]
41
+ puts "[would run command]: " + build_command
42
+ else
43
+ system(build_command)
44
+ end
45
+ end
46
+
47
+ def get_profile_name(environment)
48
+ profile = {
49
+ 'loc' => 'loc',
50
+ 'dev' => 'dev',
51
+ 'stg' => 'stage',
52
+ 'prod' => 'prod'
53
+ }
54
+ return profile[environment]
55
+ end
56
+
57
+
58
+ def get_artifactId(xml_string)
59
+ artifactId = re.first_occurrence( xml_string, /<artifactId>(.*)<\/artifactId>/)
60
+ end
61
+
62
+ def get_packaging(xml_string)
63
+ packaging = re.first_occurrence( xml_string, /<packaging>(.*)<\/packaging>/)
64
+ end
65
+
66
+ def get_artifact_name(xml_string)
67
+ artifactId = get_artifactId(xml_string)
68
+ packaging = get_packaging(xml_string)
69
+ if ops[:jar_with_dependencies]
70
+ return artifactId + "-jar-with-dependencies." + packaging
71
+ else
72
+ return artifactId + "." + packaging
73
+ end
74
+ end
75
+
76
+ def has_assembly
77
+ plugins = @pom['build']['pluginManagement']['plugins']
78
+ plugins.each do |key,value|
79
+ p key
80
+ end
81
+ end
82
+ def get_built_artifact_name_with_version(xml_string)
83
+ version = @ops[:version]
84
+ prev_ver = get_prev_version(version)
85
+ artifactId = get_artifactId(xml_string)
86
+ packaging = get_packaging(xml_string)
87
+ # puts "Dumping class: " + self.inspect if ops[:debug]
88
+
89
+ if ops[:jar_with_dependencies]
90
+ return "#{artifactId}-jar-with-dependencies-#{prev_ver}.#{packaging}"
91
+ else
92
+ return "#{artifactId}-#{prev_ver}.#{packaging}"
93
+ end
94
+ end
95
+
96
+ def get_prev_version(curr_version)
97
+ m = /(\d+\.\d+\.)(\d+)/.match(curr_version)
98
+ m[1].to_s + (m[2].to_i - 1).to_s
99
+ end
100
+
101
+ end
@@ -0,0 +1,4 @@
1
+ # The following will print out the filename and md5 digest of all the
2
+ # files passed to it on the command line:
3
+ require 'digest/md5'
4
+ digest = Digest::MD5.hexdigest(File.read(f))
@@ -0,0 +1,78 @@
1
+ require 'rubygems'
2
+ require 'mime/types'
3
+ require 'cgi'
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ module Multipart
8
+ VERSION = "1.0.0" unless const_defined?(:VERSION)
9
+
10
+ # Formats a given hash as a multipart form post
11
+ # If a hash value responds to :string or :read messages, then it is
12
+ # interpreted as a file and processed accordingly; otherwise, it is assumed
13
+ # to be a string
14
+ attr_accessor :fp
15
+ class Post
16
+ # We have to pretend like we're a web browser...
17
+ USERAGENT = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/523.10.6 (KHTML, like Gecko) Version/3.0.4 Safari/523.10.6" unless const_defined?(:USERAGENT)
18
+ BOUNDARY = "0123456789ABLEWASIEREISAWELBA9876543210" unless const_defined?(:BOUNDARY)
19
+ CONTENT_TYPE = "multipart/form-data; boundary=#{ BOUNDARY }" unless const_defined?(:CONTENT_TYPE)
20
+ HEADER = { "Content-Type" => CONTENT_TYPE, "User-Agent" => USERAGENT } unless const_defined?(:HEADER)
21
+ def initialize
22
+ @fp = []
23
+ end
24
+ def add_file(filename, contents)
25
+ @fp.push(FileParam.new(filename, filename, contents))
26
+ end
27
+ def add_params(params = {})
28
+ params.each do |k, v|
29
+ @fp.push(StringParam.new(k, v))
30
+ end
31
+ end
32
+ def post(url = "http://something.com/uploads")
33
+ uri = URI.parse(url)
34
+ post_body = get_query
35
+ http = Net::HTTP.new(uri.host, uri.port)
36
+ request = Net::HTTP::Post.new(uri.request_uri)
37
+ request.body = post_body.join
38
+ request["Content-Type"] = "multipart/form-data, boundary=#{BOUNDARY}"
39
+ http.request(request)
40
+ end
41
+ def get_query
42
+ query = @fp.collect {|p| "--" + BOUNDARY + "\r\n" + p.to_multipart }.join("") + "--" + BOUNDARY + "--"
43
+ return query, HEADER
44
+ end
45
+ end
46
+ private
47
+ # Formats a basic string key/value pair for inclusion with a multipart post
48
+ class StringParam
49
+ attr_accessor :k, :v
50
+ def initialize(k, v)
51
+ @k = k
52
+ @v = v
53
+ end
54
+ def to_multipart
55
+ return "Content-Disposition: form-data; name=\"#{CGI::escape(k)}\"\r\n\r\n#{v}\r\n"
56
+ end
57
+ end
58
+ # Formats the contents of a file or string for inclusion with a multipart
59
+ # form post
60
+ class FileParam
61
+ attr_accessor :k, :filename, :content
62
+ def initialize(k, filename, content)
63
+ @k = k
64
+ @filename = filename
65
+ @content = content
66
+ end
67
+ def to_multipart
68
+ # If we can tell the possible mime-type from the filename, use the
69
+ # first in the list; otherwise, use "application/octet-stream"
70
+ mime_type = MIME::Types.type_for(filename)[0] || MIME::Types["application/octet-stream"][0]
71
+ return "Content-Disposition: form-data; name=\"#{CGI::escape(k)}\"; filename=\"#{ filename }\"\r\n" +
72
+ "Content-Type: #{ mime_type.simplified }\r\n\r\n#{ content }\r\n"
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+
@@ -0,0 +1,72 @@
1
+ require 'socket'
2
+ require 'timeout'
3
+ require 'net/http'
4
+
5
+ module NetworkTools
6
+ class VpnTools
7
+ def is_port_open?(ip, port)
8
+ begin
9
+ Timeout::timeout(1) do
10
+ begin
11
+ s = TCPSocket.new(ip, port)
12
+ s.close
13
+ return true
14
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
15
+ return false
16
+ end
17
+ end
18
+ rescue Timeout::Error
19
+ end
20
+ return false
21
+ end
22
+
23
+ # * *Args* :
24
+ # - ++ ->
25
+ # * *Returns* :
26
+ # - true if you are on the vpn or false if you are not on the vpn
27
+ # * *Raises* :
28
+ # - ++ ->
29
+ def on_vpn
30
+ if is_port_open?("spicevan.com", 22)
31
+ return false
32
+ else
33
+ return true
34
+ end
35
+ end
36
+
37
+ def login_to_url2(url, port, username, password, limit = 35)
38
+ puts "[URL]: " + url
39
+ puts "[PORT]: #{port}"
40
+ puts "[USERNAME]: " + username
41
+ puts "[PASSWORD]: " + password
42
+
43
+ # You should choose a better exception.
44
+ raise ArgumentError, 'too many HTTP redirects' if limit == 0
45
+
46
+ uri = URI(url)
47
+
48
+ req = Net::HTTP::Get.new(uri.request_uri)
49
+ req.basic_auth username, password
50
+
51
+ res = Net::HTTP.start(uri.host, port, :use_ssl => uri.scheme == 'https') {|http|
52
+ http.request(req)
53
+ }
54
+
55
+ case res
56
+ when Net::HTTPSuccess then
57
+ puts "Successfully logged in." # res.body
58
+ when Net::HTTPRedirection then
59
+ location = res['location']
60
+ warn "redirected to #{location}"
61
+ login_to_url2(location, port, username, password, limit - 1)
62
+ else
63
+ response.value
64
+ end
65
+ # File.open('out.html', 'w'){|f| f.write res.body}
66
+ puts res.body.to_s
67
+ end
68
+
69
+
70
+ end
71
+ end
72
+