blufin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/bin/bf +5 -0
  3. data/bin/blufin +5 -0
  4. data/lib/blufin.rb +245 -0
  5. data/lib/core/code_scanners/common/scanner_common.rb +83 -0
  6. data/lib/core/code_scanners/common/scanner_java.rb +106 -0
  7. data/lib/core/code_scanners/scanner_java_embedded_objects.rb +386 -0
  8. data/lib/core/code_scanners/scanner_java_enums.rb +125 -0
  9. data/lib/core/code_scanners/scanner_java_source.rb +29 -0
  10. data/lib/core/code_scanners/scanner_java_tests.rb +157 -0
  11. data/lib/core/error_handling/schema_error.rb +9 -0
  12. data/lib/core/error_handling/sql_error.rb +21 -0
  13. data/lib/core/error_handling/sql_error_handler.rb +149 -0
  14. data/lib/core/error_handling/yml_error.rb +21 -0
  15. data/lib/core/error_handling/yml_error_handler.rb +437 -0
  16. data/lib/core/mysql.rb +347 -0
  17. data/lib/core/opt.rb +21 -0
  18. data/lib/core/site/site.rb +26 -0
  19. data/lib/core/site/site_auth.rb +88 -0
  20. data/lib/core/site/site_embedded.rb +27 -0
  21. data/lib/core/site/site_ports.rb +9 -0
  22. data/lib/core/site/site_resolver.rb +276 -0
  23. data/lib/core/site/site_services.rb +162 -0
  24. data/lib/core/site/site_ui.rb +16 -0
  25. data/lib/core/yml/config/yml_config_validator.rb +219 -0
  26. data/lib/core/yml/maven/yml_maven_validator.rb +1132 -0
  27. data/lib/core/yml/resource/yml_resource_validator.rb +154 -0
  28. data/lib/core/yml/schema/yml_schema_flags.rb +9 -0
  29. data/lib/core/yml/schema/yml_schema_validator.rb +1850 -0
  30. data/lib/core/yml/yml_cache_handler.rb +115 -0
  31. data/lib/core/yml/yml_common.rb +487 -0
  32. data/lib/core/yml/yml_meta_writer_base.rb +300 -0
  33. data/lib/core/yml/yml_outputter.rb +307 -0
  34. data/lib/core/yml/yml_validator_base.rb +630 -0
  35. data/lib/core/yml_writers/yml_configuration_writer.rb +40 -0
  36. data/lib/core/yml_writers/yml_java_api_resource_writer.rb +348 -0
  37. data/lib/core/yml_writers/yml_java_cron_type_writer.rb +113 -0
  38. data/lib/core/yml_writers/yml_java_css_dependency_writer.rb +59 -0
  39. data/lib/core/yml_writers/yml_java_dao_writer.rb +364 -0
  40. data/lib/core/yml_writers/yml_java_dto_writer.rb +251 -0
  41. data/lib/core/yml_writers/yml_java_embedded_object_writer.rb +968 -0
  42. data/lib/core/yml_writers/yml_java_enum_writer.rb +161 -0
  43. data/lib/core/yml_writers/yml_java_js_dependency_writer.rb +59 -0
  44. data/lib/core/yml_writers/yml_java_message_type_writer.rb +106 -0
  45. data/lib/core/yml_writers/yml_java_meta_writer.rb +173 -0
  46. data/lib/core/yml_writers/yml_java_model_writer.rb +510 -0
  47. data/lib/core/yml_writers/yml_java_pom_writer.rb +1050 -0
  48. data/lib/core/yml_writers/yml_java_resource_data_writer.rb +251 -0
  49. data/lib/core/yml_writers/yml_java_sdk_writer.rb +732 -0
  50. data/lib/core/yml_writers/yml_java_validator_writer.rb +280 -0
  51. data/lib/core/yml_writers/yml_java_worker_writer.rb +81 -0
  52. data/lib/core/yml_writers/yml_sql_structure_writer.rb +307 -0
  53. data/lib/core/yml_writers/yml_sql_template_writer.rb +243 -0
  54. data/lib/core/yml_writers/yml_vue_service_writer.rb +170 -0
  55. data/lib/core/yml_writers/yml_writer_base.rb +114 -0
  56. data/lib/routes/api_list.rb +35 -0
  57. data/lib/routes/api_meta.rb +59 -0
  58. data/lib/routes/build.rb +46 -0
  59. data/lib/routes/create/create_api.rb +35 -0
  60. data/lib/routes/create/create_ui.rb +84 -0
  61. data/lib/routes/export.rb +56 -0
  62. data/lib/routes/generate/generate_api.rb +225 -0
  63. data/lib/routes/generate/generate_img_favicon.rb +56 -0
  64. data/lib/routes/generate/generate_img_landing.rb +94 -0
  65. data/lib/routes/generate/generate_lambda.rb +43 -0
  66. data/lib/routes/lint.rb +35 -0
  67. data/lib/routes/mysql_reset.rb +43 -0
  68. data/lib/routes/release_blufin.rb +351 -0
  69. data/lib/routes/run.rb +35 -0
  70. data/lib/version.rb +1 -0
  71. data/opt/README.MD +2 -0
  72. data/opt/config/schema.yml +73 -0
  73. data/opt/config/template.yml +25 -0
  74. data/opt/sql/data/config/data-client.sql +7 -0
  75. data/opt/sql/data/config/data-db-configuration-property.sql +47 -0
  76. data/opt/sql/data/config/data-db-configuration.sql +9 -0
  77. data/opt/sql/data/config/data-db.sql +175 -0
  78. data/opt/sql/data/config/data-profile-api.sql +47 -0
  79. data/opt/sql/data/config/data-profile-cron.sql +0 -0
  80. data/opt/sql/data/config/data-profile-worker.sql +0 -0
  81. data/opt/sql/data/config/data-profile.sql +87 -0
  82. data/opt/sql/data/config/data-project.sql +95 -0
  83. data/opt/sql/structure/blufin-master-structure-fks.sql +65 -0
  84. data/opt/sql/structure/blufin-master-structure.sql +97 -0
  85. data/opt/sql/structure/blufin-mock-structure-fks.sql +38 -0
  86. data/opt/sql/structure/blufin-mock-structure.sql +98 -0
  87. data/opt/sql/templates/config/template-client.sql +7 -0
  88. data/opt/sql/templates/config/template-db-configuration-property.sql +11 -0
  89. data/opt/sql/templates/config/template-db-configuration.sql +9 -0
  90. data/opt/sql/templates/config/template-db.sql +21 -0
  91. data/opt/sql/templates/config/template-profile-api.sql +11 -0
  92. data/opt/sql/templates/config/template-profile-cron.sql +7 -0
  93. data/opt/sql/templates/config/template-profile-worker.sql +7 -0
  94. data/opt/sql/templates/config/template-profile.sql +21 -0
  95. data/opt/sql/templates/config/template-project.sql +23 -0
  96. data/opt/yml/api/schema/config/client.yml +14 -0
  97. data/opt/yml/api/schema/config/db.yml +45 -0
  98. data/opt/yml/api/schema/config/db_configuration.yml +22 -0
  99. data/opt/yml/api/schema/config/db_configuration_property.yml +22 -0
  100. data/opt/yml/api/schema/config/profile.yml +53 -0
  101. data/opt/yml/api/schema/config/profile_api.yml +22 -0
  102. data/opt/yml/api/schema/config/profile_cron.yml +14 -0
  103. data/opt/yml/api/schema/config/profile_worker.yml +14 -0
  104. data/opt/yml/api/schema/config/project.yml +48 -0
  105. data/opt/yml/api/schema/mock/mock.yml +99 -0
  106. data/opt/yml/api/schema/mock/mock_nested_if_enum.yml +16 -0
  107. data/opt/yml/api/schema/mock/mock_nested_if_enum_system.yml +16 -0
  108. data/opt/yml/api/schema/mock/mock_nested_linked.yml +43 -0
  109. data/opt/yml/api/schema/mock/mock_nested_multiple.yml +61 -0
  110. data/opt/yml/api/schema/mock/mock_nested_single.yml +67 -0
  111. data/opt/yml/api/schema/mock/mock_nested_single_super_deep.yml +32 -0
  112. data/opt/yml/api/schema/mock/mock_nested_single_super_super_deep.yml +17 -0
  113. metadata +240 -0
@@ -0,0 +1,56 @@
1
+ require 'mini_magick'
2
+
3
+ module AppCommand
4
+
5
+ class GenerateUIFavIcon < ::Convoy::ActionCommand::Base
6
+
7
+ ACCEPTED_IMG_FORMATS = %w(jpg jpeg png)
8
+
9
+ def execute
10
+
11
+ begin
12
+
13
+ @opts = command_options
14
+ @args = arguments
15
+
16
+ opts_validate
17
+ opts_routing
18
+
19
+ rescue => e
20
+
21
+ Blufin::Terminal::print_exception(e)
22
+
23
+ end
24
+
25
+ end
26
+
27
+ def opts_validate
28
+
29
+ # TODO - Validate
30
+
31
+ end
32
+
33
+ # Generates a favicon.ico file (using ImageMagick)
34
+ # @return void
35
+ def opts_routing
36
+
37
+ # TODO - FAVICON GENERATOR - https://medium.com/@morsetree/creating-a-favicon-command-line-8f6bf224e360
38
+
39
+ img = 'path-to-img.jpg|png'
40
+ cmd = <<TEMPLATE
41
+ convert #{img} -background white \
42
+ \( -clone 0 -resize 16x16 -extent 16x16 \) \
43
+ \( -clone 0 -resize 32x32 -extent 32x32 \) \
44
+ \( -clone 0 -resize 48x48 -extent 48x48 \) \
45
+ \( -clone 0 -resize 64x64 -extent 64x64 \) \
46
+ -delete 0 -alpha off -colors 256 favicon.ico
47
+ TEMPLATE
48
+
49
+ puts cmd
50
+ raise RuntimeError, 'Not yet implemented!'
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,94 @@
1
+ module AppCommand
2
+
3
+ class GenerateUIImageLanding < ::Convoy::ActionCommand::Base
4
+
5
+ ACCEPTED_IMG_FORMATS = %w(jpg jpeg png)
6
+
7
+ def execute
8
+
9
+ begin
10
+
11
+ @opts = command_options
12
+ @args = arguments
13
+
14
+ opts_validate
15
+ opts_routing
16
+
17
+ rescue => e
18
+
19
+ Blufin::Terminal::print_exception(e)
20
+
21
+ end
22
+
23
+ end
24
+
25
+ def opts_validate
26
+ if @args.nil? || @args.length < 2
27
+ Blufin::Terminal::arg_instructions(
28
+ [
29
+ 'Path to source image.',
30
+ "Prefix for new image name(s) \xe2\x80\x94 IE: #{Blufin::Terminal::format_highlight('logo')}\x1B[38;5;208m will produce \xe2\x86\x92 #{Blufin::Terminal::format_highlight('logo-375x250.jpg')}"
31
+ ])
32
+ exit
33
+ end
34
+ @file_source = File.expand_path(@args[0])
35
+ Blufin::Terminal::error("#{Blufin::Terminal::format_directory(@file_source)} file doesn't exist.") unless Blufin::Files::file_exists(@file_source)
36
+ fss = @file_source.split('/')
37
+ fss.pop
38
+ @path_target = fss.join('/')
39
+ @image_prefix = @args[1]
40
+ @quality = @opts[:quality]
41
+ Blufin::Terminal::error("#{Blufin::Terminal::format_directory(@path_target)} path doesn't exist.") unless Blufin::Files::path_exists(@path_target)
42
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight('Image prefix')} cannot be blank or nil.") if @image_prefix.nil? || @image_prefix.to_s.strip == ''
43
+ Blufin::Terminal::error("#{Blufin::Terminal::format_highlight('Quality')} must be integer between 0 - 100, instead got: #{@quality}") unless @quality.to_s =~ /^\d+$/ && @quality.to_i >= 0 && @quality.to_i <= 100
44
+ @image_ext = File.extname(@file_source).gsub(/^\./, '').strip.downcase
45
+ Blufin::Terminal::error("Unsupported file-extension #{Blufin::Terminal::format_highlight(@image_ext)}. Supported extensions are:", ACCEPTED_IMG_FORMATS, true) unless ACCEPTED_IMG_FORMATS.include?(@image_ext)
46
+ @image = Blufin::Image::info(@file_source)
47
+ Blufin::Terminal::custom('SCANNED', 4, "Source Image: #{Blufin::Terminal::format_directory(@file_source)}", [
48
+ "Type: \x1B[38;5;94m#{@image.type}\x1B[0m",
49
+ "Size: \x1B[38;5;94m#{@image.size}\x1B[0m",
50
+ "Dimensions: \x1B[38;5;94m#{@image.width}x#{@image.height}\x1B[0m",
51
+ "GCD: \x1B[38;5;94m#{Blufin::Image::gcd(@image.width, @image.height)}\x1B[0m",
52
+ "Aspect: \x1B[38;5;94m#{Blufin::Image::calc_aspect_ratio(@image.width, @image.height)}\x1B[0m"
53
+ ])
54
+
55
+ end
56
+
57
+ # Generates a Landing Page Image.
58
+ # See: https://www.rubyguides.com/2018/12/minimagick-gem/
59
+ # @return void
60
+ def opts_routing
61
+
62
+ # TODO REMOVE - $ my g b bl && my g b && bf g ui l ~/Repos/blufin-archetypes/nuxt/v1/static/img/bg/face.jpg testing -ys
63
+
64
+ target_images = [
65
+ {:side => 'width', :length => 2560, :ratio => '16:9', :quality => @quality},
66
+ {:side => 'width', :length => 1920, :ratio => '16:9', :quality => @quality},
67
+ {:side => 'width', :length => 1366, :ratio => '16:9', :quality => @quality},
68
+ {:side => 'width', :length => 414, :ratio => '9:18', :quality => @quality},
69
+ ]
70
+ target_output = ["Destination path: #{Blufin::Terminal::format_directory(@path_target)}", nil]
71
+ target_images.each { |ti| target_output << "\x1B[38;5;154m#{Blufin::Image::calc_file_name(@image_prefix, @image_ext, ti[:side], ti[:length], ti[:ratio])}\x1B[0m \xe2\x86\x92 #{ti.inspect}" }
72
+ if @opts[:skip_confirm] || Blufin::Terminal::prompt_yes_no("About to #{Blufin::Terminal::format_action('create')} the following images from #{Blufin::Terminal::format_directory(@file_source)}:", target_output)
73
+ # This runs the crop(s).
74
+ target_images.each { |ti|
75
+ target = "#{@path_target}/#{Blufin::Image::calc_file_name(@image_prefix, @image_ext, ti[:side], ti[:length], ti[:ratio])}"
76
+ Blufin::Image::crop_to_length_and_ratio(@file_source, target, ti[:side], ti[:length], ti[:ratio], ti[:quality])
77
+ if @opts[:add_size]
78
+ img = Blufin::Image::info(target)
79
+ Blufin::Image::add_text(target, target, "#{img.width}x#{img.height}")
80
+ end
81
+ }
82
+ end
83
+
84
+ end
85
+
86
+ # Standardized way of generating image-name.
87
+ # @return string
88
+ def image_name(suffix)
89
+ "#{@image_prefix}-#{suffix}.#{@image_ext}"
90
+ end
91
+
92
+ end
93
+
94
+ end
@@ -0,0 +1,43 @@
1
+ module AppCommand
2
+
3
+ class GenerateLambda < ::Convoy::ActionCommand::Base
4
+
5
+ def execute
6
+
7
+ begin
8
+
9
+ @opts = command_options
10
+ @args = arguments
11
+
12
+ opts_validate
13
+ opts_routing
14
+
15
+ rescue => e
16
+
17
+ Blufin::Terminal::print_exception(e)
18
+
19
+ end
20
+
21
+ end
22
+
23
+ def opts_validate
24
+
25
+ # TODO - Validate something?
26
+
27
+ end
28
+
29
+ # Generates a favicon.ico file (using ImageMagick)
30
+ # @return void
31
+ def opts_routing
32
+
33
+ # TODO - Figure out structure of configuration files.
34
+ # TODO - Scan configuration files + validate.
35
+ # TODO - Generate boiler-plate code.
36
+
37
+ raise RuntimeError, 'Not yet implemented!'
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,35 @@
1
+ module AppCommand
2
+
3
+ class Lint < ::Convoy::ActionCommand::Base
4
+
5
+ def execute
6
+
7
+ begin
8
+
9
+ @opts = command_options
10
+ @args = arguments
11
+
12
+ opts_validate
13
+ opts_routing
14
+
15
+ rescue => e
16
+
17
+ Blufin::Terminal::print_exception(e)
18
+
19
+ end
20
+
21
+ end
22
+
23
+ def opts_validate
24
+
25
+ end
26
+
27
+ def opts_routing
28
+
29
+ Blufin::Terminal::error('Not yet implemented!')
30
+
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,43 @@
1
+ module AppCommand
2
+
3
+ class MySQLReset < ::Convoy::ActionCommand::Base
4
+
5
+ def execute
6
+
7
+ begin
8
+
9
+ @opts = command_options
10
+ @args = arguments
11
+
12
+ @site = Blufin::SiteResolver::validate_site(@args[0])
13
+
14
+ opts_validate
15
+ opts_routing
16
+
17
+ rescue => e
18
+
19
+ Blufin::Terminal::print_exception(e)
20
+
21
+ end
22
+
23
+ end
24
+
25
+ def opts_validate
26
+
27
+ end
28
+
29
+ def opts_routing
30
+
31
+ reset_database
32
+
33
+ end
34
+
35
+ def reset_database
36
+
37
+ App::MySQL::reset_full_mock_data(@site, @opts[:skip_confirm], @opts[:verbose])
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,351 @@
1
+ module AppCommand
2
+
3
+ class ReleaseBlufin < ::Convoy::ActionCommand::Base
4
+
5
+ def execute
6
+
7
+
8
+ begin
9
+
10
+ @opts = command_options
11
+ @args = arguments
12
+
13
+ @threads = []
14
+
15
+ @version_release = nil
16
+ @version_current = '0.0.0'
17
+ @version_color = 33
18
+
19
+ @path_blufin_aws = Blufin::Config::get_path('Paths', 'BlufinAWS')
20
+ @path_blufin_java = Blufin::Config::get_path('Paths', 'BlufinJava')
21
+ @path_blufin_java_labs = Blufin::Config::get_path('Paths', 'BlufinJavaLabs')
22
+ @path_blufin_java_framework = Blufin::Config::get_path('Paths', 'BlufinJavaFramework') # TODO - DEPRECATE THIS!
23
+ @path_blufin_ruby = Blufin::Config::get_path('Paths', 'BlufinRuby')
24
+ @blufin_version_file = "#{@path_blufin_ruby}/blufin/lib/version.rb"
25
+ @blufin_java_version_file = "#{@path_blufin_java}/maven.yml"
26
+ @blufin_labs_version_file = "#{@path_blufin_java_labs}/app-infrastructure/maven.yml"
27
+
28
+ @minify_exclude_file = "#{@path_blufin_java}/minify-exclude.txt" # Does not copy across.
29
+ @minify_ignore_file = "#{@path_blufin_java}/minify-ignore.txt" # Copies across but does not alter file.
30
+
31
+ opts_validate
32
+ opts_routing
33
+
34
+ rescue => e
35
+
36
+ Blufin::Terminal::print_exception(e)
37
+
38
+ end
39
+
40
+ end
41
+
42
+ def opts_validate
43
+
44
+ system('clear')
45
+
46
+ # TODO - Check Maven installed with version above 3.6
47
+ # TODO - Check MySQL is running (required for integration testing)
48
+
49
+ # TODO - Uncomment.
50
+ [@path_blufin_aws,
51
+ # @path_blufin_java,
52
+ # @path_blufin_java_labs,
53
+ # @path_blufin_java_framework,
54
+ # @path_blufin_ruby
55
+ ].each do |path|
56
+
57
+ path = File.expand_path(path)
58
+ Blufin::Terminal::error('Path does not exist', path, true) unless Blufin::Files::path_exists(path)
59
+ git_status = Blufin::Terminal::command_capture('git status', path, false)[0]
60
+ clean_repo = git_status.to_s == "On branch master\nYour branch is up to date with 'origin/master'.\n\nnothing to commit, working tree clean\n"
61
+ Blufin::Terminal::error("#{Blufin::Terminal::format_directory(path)} is either not #{Blufin::Terminal::format_highlight('clean')} or not on #{Blufin::Terminal::format_highlight('master')}.", git_status.split("\n"), true) unless clean_repo
62
+
63
+ end
64
+
65
+ # Check that blufin-java/minify-exclude.txt file exists.
66
+ exists_exclude = Blufin::Files::file_exists(@minify_exclude_file)
67
+ exists_ignore = Blufin::Files::file_exists(@minify_ignore_file)
68
+ if !exists_exclude || !exists_ignore
69
+ Blufin::Terminal::error('Files required for release process are missing:', [
70
+ "#{exists_exclude ? "\x1B[38;5;46m Found\x1B[0m" : "\x1B[38;5;196mMissing\x1B[0m"} \xe2\x86\x92 #{Blufin::Terminal::format_directory(@minify_exclude_file)}",
71
+ "#{exists_ignore ? "\x1B[38;5;46m Found\x1B[0m" : "\x1B[38;5;196mMissing\x1B[0m"} \xe2\x86\x92 #{Blufin::Terminal::format_directory(@minify_ignore_file)}"
72
+ ], true)
73
+ end
74
+
75
+ # Gets Blufin Version from -> /Users/Albert/Repos/blufin/blufin/lib/version.rb
76
+ blufin_version = get_blufin_version(@blufin_version_file)
77
+ Blufin::Terminal::error("Could not extract valid version number from #{Blufin::Terminal::format_directory(@blufin_version_file)}", ["Found: #{blufin_version.inspect}"]) unless blufin_version =~ /^\d+\.\d+\.\d+(-SNAPSHOT)?$/i
78
+
79
+ # Gets Blufin-Java Version from -> /Users/Albert/Repos/blufin-java/maven.yml
80
+ blufin_java_version = get_blufin_java_version(@blufin_java_version_file)
81
+ Blufin::Terminal::error("Could not extract valid version number from #{Blufin::Terminal::format_directory(@blufin_java_version_file)}", ["Found: #{blufin_java_version.inspect}"]) unless blufin_java_version =~ /^\d+\.\d+\.\d+(-SNAPSHOT)?$/i
82
+
83
+ # Gets Blufin-Labs Version from -> /Users/Albert/Repos/repos-blufin/blufin-labs/app-infrastructure/maven.yml
84
+ blufin_labs_version = get_blufin_java_version(@blufin_java_version_file)
85
+ Blufin::Terminal::error("Could not extract valid version number from #{Blufin::Terminal::format_directory(@blufin_labs_version_file)}", ["Found: #{blufin_labs_version.inspect}"]) unless blufin_labs_version =~ /^\d+\.\d+\.\d+(-SNAPSHOT)?$/i
86
+
87
+ dir_max_length = [@blufin_version_file.length, @blufin_java_version_file.length, @blufin_labs_version_file.length].max
88
+
89
+ # Checks that all the versions are the same.
90
+ Blufin::Terminal::error('Version mismatch:', [
91
+ "#{Blufin::Terminal::format_directory(@blufin_version_file.ljust(dir_max_length, ' '))} \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{blufin_version}\x1B[0m",
92
+ "#{Blufin::Terminal::format_directory(@blufin_java_version_file.ljust(dir_max_length, ' '))} \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{blufin_java_version}\x1B[0m",
93
+ "#{Blufin::Terminal::format_directory(@blufin_labs_version_file.ljust(dir_max_length, ' '))} \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{blufin_labs_version}\x1B[0m"
94
+ ], true) unless [blufin_version, blufin_java_version, blufin_labs_version].uniq!.length == 1
95
+
96
+ @version_current = blufin_version.gsub(/(-SNAPSHOT)?$/i, '')
97
+
98
+ @site = Blufin::Site::DEFAULT_SITE
99
+
100
+ # Must go first because it contains the most important configuration data.
101
+ Blufin::SiteEmbedded::init(Blufin::ScannerJavaEmbeddedObjects::new(@site, @error_handler).get_data)
102
+
103
+ @error_handler = Blufin::YmlErrorHandler.new(@site)
104
+
105
+ @yml_maven = Blufin::YmlMavenValidator.new(@site, @error_handler)
106
+
107
+ @error_handler.display_errors_if_any(true)
108
+
109
+ end
110
+
111
+ def opts_routing
112
+
113
+ begin
114
+
115
+ # Get user to choose new version.
116
+ # @version_release = prompt_for_new_version
117
+
118
+ # Confirm new version.
119
+ # Blufin::Terminal::prompt_yes_no("New Blufin version is \x1B[38;5;240m\xe2\x86\x92\x1B[0m \x1B[38;5;#{@version_color}m#{@version_release}\x1B[0m")
120
+
121
+ # Change all the versions on all the repos to the new one.
122
+ # change_versions_on_files(@version_release)
123
+
124
+ # Build blufin-java/blufin-labs to regenerate the POMs with new version.
125
+ # execute_command('bf s g bf', @path_blufin_ruby)
126
+
127
+ # Copy all the files from blufin-java to public repository. This performs minor obfuscation and minification.
128
+ # Blufin::Terminal::execute_proc("Copying/obfuscating #{Blufin::Terminal::format_directory(@path_blufin_java)} to \xe2\x86\x92 #{Blufin::Terminal::format_directory(@path_blufin_java_framework)} (and removing tests).", Proc.new { |args|
129
+ # AppCommand::ReleaseBlufin::copy_blufin_java(@path_blufin_java, @path_blufin_java_framework, @minify_exclude_file, @minify_ignore_file)
130
+ # AppCommand::ReleaseBlufin::remove_tests(@path_blufin_java_framework)
131
+ # true
132
+ # })
133
+
134
+ # TODO - Writing POM files always includes blank + ebay...
135
+
136
+ yml_java_pom_writer = Blufin::YmlJavaPomWriter.new(@yml_maven.data_blufin)
137
+ yml_java_pom_writer.write_poms_blufin(@path_blufin_java_framework)
138
+
139
+ # TODO - REMOVE
140
+ # abort_the_mission(@path_blufin_aws, @path_blufin_java, @path_blufin_java_framework, @path_blufin_java_labs)
141
+
142
+ exit
143
+
144
+ Blufin::Files::get_dirs_in_dir(@path_blufin_java_framework).each do |path|
145
+
146
+ mod = path.split('/')[path.split('/').length - 1]
147
+ mod_path = "#{@path_blufin_java_framework}/#{mod}"
148
+ # mod_title = 'N/A'
149
+ #
150
+ # Blufin::Files::read_file("#{mod_path}/pom.xml").each do |line|
151
+ # if line =~ /^\s*<name>(.*)<\/name>\s*$/
152
+ # mod_title = line.gsub(/^\s*<name>/, '').gsub(/<\/name>\s*$/, '')
153
+ # end
154
+ # end
155
+
156
+ execute_command('mvn clean test', mod_path)
157
+
158
+ end
159
+
160
+ exit
161
+
162
+ # TODO - Build the final validation screen first, so you know what to aim for...
163
+ # Show final validation screen (after which is the point of no return).
164
+
165
+ # Run -> git commit "Release: v1.0.0"
166
+ # Run -> git tag v1.0.0
167
+
168
+ rescue => e
169
+
170
+ # TODO - Add Prompt.
171
+ # abort_the_mission(@path_blufin_aws, @path_blufin_java, @path_blufin_java_framework, @path_blufin_java_labs)
172
+
173
+ Blufin::Terminal::print_exception(e)
174
+
175
+ end
176
+
177
+ end
178
+
179
+ private
180
+
181
+ # Proxy function that bombs-out soon as an execution fails.
182
+ # @return void
183
+ def execute_command(command, path)
184
+ unless Blufin::Terminal::execute(command, path)
185
+ Blufin::Terminal::error('Something went wrong.', 'Please look at above failures.', true)
186
+ end
187
+ end
188
+
189
+ # This prompts the user to select a new version number.
190
+ # @return void
191
+ def prompt_for_new_version
192
+ puts
193
+ puts " \x1B[38;5;240m Last Blufin release version was \xe2\x86\x92\x1B[0m \x1B[38;5;33m#{@version_current}\x1B[0m"
194
+ puts
195
+ version = get_versions(@version_current)
196
+ version_choices = [
197
+ "\x1B[38;5;198m1)\x1B[0m Bump major version \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{version[:mj]}\x1B[0m",
198
+ "\x1B[38;5;198m2)\x1B[0m Bump minor version \x1B[38;5;246m(default)\x1B[0m \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{version[:mn]}\x1B[0m",
199
+ "\x1B[38;5;198m3)\x1B[0m Bump point-release version \xe2\x86\x92 \x1B[38;5;#{@version_color}m#{version[:pr]}\x1B[0m"
200
+ ]
201
+ validation_proc = Proc.new { |value| %w(1 2 3).include?(value.to_s.upcase) || value.strip == '' }
202
+ validation_message = "Value must either be \x1B[38;5;220m1, 2,\x1B[0m or \x1B[38;5;220m3\x1B[0m"
203
+ version_chosen = Blufin::Terminal::prompt_for_input('CHOOSE VERSION', 'Choose next Blufin release version:', version_choices, validation_proc, validation_message).to_s.upcase
204
+ case version_chosen
205
+ when '1'
206
+ return version[:mj]
207
+ when ''
208
+ return version[:mn]
209
+ when '2'
210
+ return version[:mn]
211
+ when '3'
212
+ return version[:pr]
213
+ else
214
+ raise RuntimeError, "Could not determine version from user input: #{version_chosen}"
215
+ end
216
+ end
217
+
218
+ # Calculate major, minor, point-release version numbers.
219
+ # @return array
220
+ def get_versions(current_version)
221
+ vs = current_version.split('.')
222
+ raise RuntimeError, "Expected version parts to be 3, got: #{vs.length} (#{vs.inspect})" unless vs.length == 3
223
+ mj = vs[0].to_i
224
+ mn = vs[1].to_i
225
+ pr = vs[2].to_i
226
+ {
227
+ :mj => "#{mj + 1}.0.0",
228
+ :mn => "#{mj}.#{mn + 1}.0",
229
+ :pr => "#{mj}.#{mn}.#{pr + 1}",
230
+ }
231
+ end
232
+
233
+ # If something goes wrong or we don't want to do the release, this will revert EVERYTHING!
234
+ # @return void
235
+ def abort_the_mission(path_blufin_aws, path_blufin_java, path_blufin_java_framework, path_blufin_java_labs)
236
+ Blufin::Terminal::info('Reverting the following repositories:', %w(blufin-aws blufin-java blufin-blufin-framework blufin-labs))
237
+ # Blufin::Terminal::execute('git reset --hard HEAD', path_blufin_aws)
238
+ Blufin::Terminal::execute('git reset --hard HEAD', path_blufin_java)
239
+ # Blufin::Terminal::execute('git reset --hard HEAD', path_blufin_java_framework)
240
+ Blufin::Terminal::execute('git reset --hard HEAD', path_blufin_java_labs)
241
+ end
242
+
243
+ # Gets the version number from Blufin ruby gem.
244
+ # @return string
245
+ def get_blufin_version(path_to_file)
246
+ Blufin::Files::read_file(path_to_file).each do |line|
247
+ if line.strip.length > 0
248
+ line = line.gsub("BLUFIN_VERSION = '", '')
249
+ line = line.chomp("'")
250
+ return line
251
+ end
252
+ end
253
+ end
254
+
255
+ # Gets the version number from Blufin ruby gem.
256
+ # @return string
257
+ def get_blufin_java_version(path_to_file)
258
+ previous_was_blufin = false
259
+ Blufin::Files::read_file(path_to_file).each do |line|
260
+ line = line.strip
261
+ if previous_was_blufin
262
+ if line.strip.length > 0
263
+ return line.gsub(/version:\s*/, '')
264
+ end
265
+ end
266
+ previous_was_blufin = true if line =~ /blufin:/
267
+ end
268
+ end
269
+
270
+ # Change all the places were the Blufin version is stored.
271
+ # @return void
272
+ def change_versions_on_files(version)
273
+ Blufin::Files::write_line_to_file(@blufin_version_file, "BLUFIN_VERSION = '#{version}'", /^\s*BLUFIN_VERSION\s*=\s*'0.0.0(-SNAPSHOT)?'\s*$/, false, true)
274
+ Blufin::Files::write_line_to_file(@blufin_java_version_file, " version: #{version}", /^\s+(version:)\s*#{@version_current}(-SNAPSHOT)?$/, false, true)
275
+ Blufin::Files::write_line_to_file(@blufin_labs_version_file, " version: #{version}", /^\s+(version:)\s*#{@version_current}(-SNAPSHOT)?$/, false, true)
276
+ end
277
+
278
+ # This method copies all of the blufin-java code into blufin-framework and performs various mutation/minification operations.
279
+ # @return void
280
+ def self.copy_blufin_java(path_blufin_java, path_blufin_java_framework, minify_exclude_file, minify_ignore_file, verbose = false, quick = false)
281
+ exclude_files = []
282
+ Blufin::Files::read_file(minify_exclude_file).each { |line| exclude_files << line.strip } if Blufin::Files::file_exists(minify_exclude_file)
283
+ ignore_files = []
284
+ Blufin::Files::read_file(minify_ignore_file).each { |line| ignore_files << line.strip } if Blufin::Files::file_exists(minify_ignore_file)
285
+ # Wipe out the framework path.
286
+ system("cd #{path_blufin_java_framework} && rm -r ./* >/dev/null 2>&1")
287
+ Blufin::Files::get_files_in_dir(path_blufin_java).each do |file|
288
+ # Skip POM files and .gitignore.
289
+ next if file.strip =~ /\/pom\.xml\s*$/
290
+ next if file.strip =~ /^\.gitignore$/
291
+ exclude = false
292
+ exclude_files.each do |exclude_file|
293
+ if file.strip =~ /(#{exclude_file.strip.gsub(/\*/, '')})/
294
+ exclude = true
295
+ break
296
+ end
297
+ end
298
+ next if exclude
299
+ ignore = false
300
+ ignore_files.each do |ignore_file|
301
+ if file.strip =~ /(#{ignore_file.strip.gsub(/\*/, '')})/
302
+ ignore = true
303
+ break
304
+ end
305
+ end
306
+ file_split = file.split('/')
307
+ unless file_split[6] == 'target'
308
+ file_target = file.gsub(path_blufin_java, path_blufin_java_framework)
309
+ begin
310
+ if !ignore && !quick && file.strip =~ /\.java$/ && file !~ /src\/test\/java\// && file !~ /ebay/ && file !~ /blufin-blank/
311
+ puts "\x1B[38;5;246m#{file}\x1B[0m" if verbose
312
+ Blufin::Files::write_file(file_target, [])
313
+
314
+ # TODO - Put this somehwere more reliable, like possibly in the OPT folder...
315
+ unless system("java -jar ~/Repos/blufin/assets/bin/blufin-minifier-1.0.0.jar --in #{file} --out #{file_target} --mode compact > /dev/null 2>&1")
316
+ write_framework_file(file, file_target)
317
+ end
318
+
319
+ else
320
+ puts "\x1B[38;5;240m#{file}\x1B[0m" if verbose
321
+ write_framework_file(file, file_target)
322
+ end
323
+ rescue
324
+ end
325
+ end
326
+ end
327
+ end
328
+
329
+ # This method removes all Tests from the blufin-framework repo.
330
+ # @return void
331
+ def self.remove_tests(path_blufin_java_framework, verbose = false)
332
+ Blufin::Files::get_dirs_in_dir(path_blufin_java_framework).each do |dir|
333
+ test_directory = "#{dir}/src/test"
334
+ puts "\x1B[38;5;198m Removing:\x1B[0m \x1B[38;5;240m#{test_directory}\x1B[0m" if verbose
335
+ system("rm -rf #{test_directory}") if Blufin::Files::path_exists(test_directory)
336
+ end
337
+ end
338
+
339
+ # Write a file without doing any conversions.
340
+ # @return void
341
+ def self.write_framework_file(source_file, target_file, lines = nil)
342
+ if lines.nil?
343
+ lines = Blufin::Files::read_file(source_file)
344
+ lines.map! { |n| n.gsub("\n", '') }
345
+ end
346
+ Blufin::Files::write_file(target_file, lines)
347
+ end
348
+
349
+ end
350
+
351
+ end